ivy collective's review acknowledged

This commit is contained in:
XTerPL 2025-01-22 02:07:27 +01:00
parent 31c881aa41
commit add229be89
5 changed files with 27 additions and 14 deletions

View file

@ -62,7 +62,7 @@ public class CustomGiveCommand implements CommandExecutor, TabCompleter {
count = Integer.parseInt(strings[1]);
}
String unparsedContext = "";
String rawContext = "";
if(strings.length > 2)
{
@ -70,11 +70,11 @@ public class CustomGiveCommand implements CommandExecutor, TabCompleter {
contextStrings.removeFirst();
contextStrings.removeFirst();
unparsedContext = String.join(" ", contextStrings);
rawContext = String.join(" ", contextStrings);
}
try {
ItemStack item = itemType.createWithUnparsed(p, unparsedContext);
ItemStack item = itemType.createWithRawContext(p, rawContext);
item.setAmount(count);
p.getInventory().addItem(item);
@ -85,9 +85,9 @@ public class CustomGiveCommand implements CommandExecutor, TabCompleter {
+ " at " + parsingException.getErrorOffset())
.color(NamedTextColor.RED));
}
catch(NumberFormatException numberException) {
commandSender.sendMessage(Component.text("Number Format Exception: "
+ numberException.getMessage())
catch(Exception exception) {
commandSender.sendMessage(Component.text(exception.getClass().getName() + ": "
+ exception.getMessage())
.color(NamedTextColor.RED));
}

View file

@ -84,7 +84,7 @@ public class DeathCrateKey extends CustomItem<DeathCrateKey.DeathCrateKeyContext
}
@Override
protected DeathCrateKeyContext parseContext(Player player, String string) throws ParseException {
protected DeathCrateKeyContext parseRawContext(Player player, String string) throws ParseException {
return DeathCrateKeyContext.parse(player, string);
}
@ -105,17 +105,30 @@ public class DeathCrateKey extends CustomItem<DeathCrateKey.DeathCrateKeyContext
String[] split = string.split(":", 2);
switch (split[0]) {
switch (split[0].toLowerCase()) {
case "ulid" -> {
if (!ULID.isValid(split[1])) {
throw new ParseException("Invalid ULID!", string.length());
}
if(CrateManager.readCrate(split[1]) == null) {
throw new ParseException("Crate does not exist!", string.length());
}
return new DeathCrateKeyContext(split[1]);
}
case "loc" -> {
Location loc = TextLocation.deserializeUserInput(player.getWorld(), split[1]);
return new DeathCrateKeyContext(CrateManager.getKeyULID(loc));
if(loc == null) {
throw new ParseException("Location could not be parsed!", string.length());
}
String ulid = CrateManager.getKeyULID(loc);
if(ulid == null) {
throw new ParseException("A crate does not exist at this location!", string.length());
}
return new DeathCrateKeyContext(ulid);
}
}

View file

@ -17,7 +17,7 @@ public abstract class ContextlessItem extends CustomItem<EmptyItemContext> {
}
@Override
protected EmptyItemContext parseContext(Player player, String string) throws ParseException {
protected EmptyItemContext parseRawContext(Player player, String string) throws ParseException {
return EmptyItemContext.parse(player, string);
}

View file

@ -96,8 +96,8 @@ public abstract class CustomItem<T extends ItemContext> implements RecipeProvide
return ItemChangeProviders.update(result);
}
public final @NotNull ItemStack createWithUnparsed(Player player, String string) throws ParseException {
return create(parseContext(player, string));
public final @NotNull ItemStack createWithRawContext(Player player, String string) throws ParseException {
return create(parseRawContext(player, string));
}
public ItemStack update(ItemStack stack) {
@ -136,5 +136,5 @@ public abstract class CustomItem<T extends ItemContext> implements RecipeProvide
return List.of();
}
protected abstract T parseContext(Player player, String string) throws ParseException;
protected abstract T parseRawContext(Player player, String string) throws ParseException;
}

View file

@ -41,7 +41,7 @@ commands:
permission: blazinggames.customenchant
customgive:
description: "Gives you a specific custom item with a specified count"
usage: /customgive <custom item> [count]
usage: /customgive <custom item> [count] [context]
permission: blazinggames.customgive
killme:
description: "Kills you. Painfully."