mirror of
https://github.com/BlazingGames/blazing-games-plugin.git
synced 2025-02-03 21:26:41 -05:00
ivy collective's review #2 acknowledged
This commit is contained in:
parent
add229be89
commit
3e4c611552
5 changed files with 20 additions and 18 deletions
|
@ -84,11 +84,13 @@ public class CustomGiveCommand implements CommandExecutor, TabCompleter {
|
|||
+ parsingException.getMessage()
|
||||
+ " at " + parsingException.getErrorOffset())
|
||||
.color(NamedTextColor.RED));
|
||||
BlazingGames.get().debugLog(parsingException);
|
||||
}
|
||||
catch(Exception exception) {
|
||||
commandSender.sendMessage(Component.text(exception.getClass().getName() + ": "
|
||||
+ exception.getMessage())
|
||||
.color(NamedTextColor.RED));
|
||||
BlazingGames.get().debugLog(exception);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -84,8 +84,8 @@ public class DeathCrateKey extends CustomItem<DeathCrateKey.DeathCrateKeyContext
|
|||
}
|
||||
|
||||
@Override
|
||||
protected DeathCrateKeyContext parseRawContext(Player player, String string) throws ParseException {
|
||||
return DeathCrateKeyContext.parse(player, string);
|
||||
protected DeathCrateKeyContext parseRawContext(Player player, String raw) throws ParseException {
|
||||
return DeathCrateKeyContext.parse(player, raw);
|
||||
}
|
||||
|
||||
public static String getKeyULID(ItemStack item) {
|
||||
|
@ -98,20 +98,20 @@ public class DeathCrateKey extends CustomItem<DeathCrateKey.DeathCrateKeyContext
|
|||
}
|
||||
|
||||
public record DeathCrateKeyContext(String crateId) implements ItemContext {
|
||||
public static DeathCrateKeyContext parse(Player player, String string) throws ParseException {
|
||||
if (!string.contains(":")) {
|
||||
string = "ulid:" + string;
|
||||
public static DeathCrateKeyContext parse(Player player, String raw) throws ParseException {
|
||||
if (!raw.contains(":")) {
|
||||
raw = "ulid:" + raw;
|
||||
}
|
||||
|
||||
String[] split = string.split(":", 2);
|
||||
String[] split = raw.split(":", 2);
|
||||
|
||||
switch (split[0].toLowerCase()) {
|
||||
case "ulid" -> {
|
||||
if (!ULID.isValid(split[1])) {
|
||||
throw new ParseException("Invalid ULID!", string.length());
|
||||
throw new ParseException("Invalid ULID!", raw.length());
|
||||
}
|
||||
if(CrateManager.readCrate(split[1]) == null) {
|
||||
throw new ParseException("Crate does not exist!", string.length());
|
||||
throw new ParseException("Crate does not exist!", raw.length());
|
||||
}
|
||||
return new DeathCrateKeyContext(split[1]);
|
||||
}
|
||||
|
@ -119,13 +119,13 @@ public class DeathCrateKey extends CustomItem<DeathCrateKey.DeathCrateKeyContext
|
|||
Location loc = TextLocation.deserializeUserInput(player.getWorld(), split[1]);
|
||||
|
||||
if(loc == null) {
|
||||
throw new ParseException("Location could not be parsed!", string.length());
|
||||
throw new ParseException("Location could not be parsed!", raw.length());
|
||||
}
|
||||
|
||||
String ulid = CrateManager.getKeyULID(loc);
|
||||
|
||||
if(ulid == null) {
|
||||
throw new ParseException("A crate does not exist at this location!", string.length());
|
||||
throw new ParseException("A crate does not exist at this location!", raw.length());
|
||||
}
|
||||
|
||||
return new DeathCrateKeyContext(ulid);
|
||||
|
|
|
@ -17,8 +17,8 @@ public abstract class ContextlessItem extends CustomItem<EmptyItemContext> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected EmptyItemContext parseRawContext(Player player, String string) throws ParseException {
|
||||
return EmptyItemContext.parse(player, string);
|
||||
protected EmptyItemContext parseRawContext(Player player, String raw) throws ParseException {
|
||||
return EmptyItemContext.parse(player, raw);
|
||||
}
|
||||
|
||||
protected @NotNull ItemStack modifyMaterial(ItemStack stack) {
|
||||
|
|
|
@ -96,8 +96,8 @@ public abstract class CustomItem<T extends ItemContext> implements RecipeProvide
|
|||
return ItemChangeProviders.update(result);
|
||||
}
|
||||
|
||||
public final @NotNull ItemStack createWithRawContext(Player player, String string) throws ParseException {
|
||||
return create(parseRawContext(player, string));
|
||||
public final @NotNull ItemStack createWithRawContext(Player player, String raw) throws ParseException {
|
||||
return create(parseRawContext(player, raw));
|
||||
}
|
||||
|
||||
public ItemStack update(ItemStack stack) {
|
||||
|
@ -136,5 +136,5 @@ public abstract class CustomItem<T extends ItemContext> implements RecipeProvide
|
|||
return List.of();
|
||||
}
|
||||
|
||||
protected abstract T parseRawContext(Player player, String string) throws ParseException;
|
||||
protected abstract T parseRawContext(Player player, String raw) throws ParseException;
|
||||
}
|
||||
|
|
|
@ -23,12 +23,12 @@ import java.text.ParseException;
|
|||
public class EmptyItemContext implements ItemContext {
|
||||
public static EmptyItemContext instance = new EmptyItemContext();
|
||||
|
||||
public static EmptyItemContext parse(Player player, String string) throws ParseException {
|
||||
if(string.isBlank())
|
||||
public static EmptyItemContext parse(Player player, String raw) throws ParseException {
|
||||
if(raw.isBlank())
|
||||
{
|
||||
return instance;
|
||||
}
|
||||
|
||||
throw new ParseException("Do mention that this item's context is empty.", string.length());
|
||||
throw new ParseException("Do mention that this item's context is empty.", raw.length());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue