From 0324458efb97016e70dade374e1def00b985c5d8 Mon Sep 17 00:00:00 2001 From: Teriuihi Date: Thu, 6 Jul 2023 23:14:07 +0200 Subject: [PATCH] Prevent players from entering a negative value for xp --- .../commands/playerutils_subcommands/XPCheque.java | 5 +++++ src/main/java/com/alttd/playerutils/config/Messages.java | 2 ++ 2 files changed, 7 insertions(+) diff --git a/src/main/java/com/alttd/playerutils/commands/playerutils_subcommands/XPCheque.java b/src/main/java/com/alttd/playerutils/commands/playerutils_subcommands/XPCheque.java index ac9c8f6..3c9602b 100644 --- a/src/main/java/com/alttd/playerutils/commands/playerutils_subcommands/XPCheque.java +++ b/src/main/java/com/alttd/playerutils/commands/playerutils_subcommands/XPCheque.java @@ -44,6 +44,11 @@ public class XPCheque extends SubCommand { return false; } + if ((xpValue <= 0)) { + commandSender.sendMiniMessage(Messages.XP_CHEQUE.NEGATIVE, null); + return true; + } + int totalExperience = player.getTotalExperience(); if (totalExperience < xpValue) { commandSender.sendMiniMessage(Messages.XP_CHEQUE.NOT_ENOUGH_XP, Placeholder.parsed("xp", String.valueOf(totalExperience))); diff --git a/src/main/java/com/alttd/playerutils/config/Messages.java b/src/main/java/com/alttd/playerutils/config/Messages.java index 94f9d60..97d1bc1 100644 --- a/src/main/java/com/alttd/playerutils/config/Messages.java +++ b/src/main/java/com/alttd/playerutils/config/Messages.java @@ -66,6 +66,7 @@ public class Messages extends AbstractConfig { private static final String prefix = "pu-command.xp-cheque."; public static String FAILED_STORAGE = "Unable to create custom item for xp cheque"; + public static String NEGATIVE = "You cannot enter a negative value for xp."; public static String NOT_ENOUGH_XP = "Not enough xp, you have "; public static String NOT_HOLDING_BOTTLE = "You need to hold an empty glass bottle while executing this command"; public static String DISPLAY_NAME = "Xp bottle containing xp"; @@ -74,6 +75,7 @@ public class Messages extends AbstractConfig { @SuppressWarnings("unused") private static void load() { FAILED_STORAGE = config.getString(prefix, "failed-storage", FAILED_STORAGE); + NEGATIVE = config.getString(prefix, "negative", NEGATIVE); NOT_ENOUGH_XP = config.getString(prefix, "not-enough-xp", NOT_ENOUGH_XP); NOT_HOLDING_BOTTLE = config.getString(prefix, "not-holding-bottle", NOT_HOLDING_BOTTLE); DISPLAY_NAME = config.getString(prefix, "display-name", DISPLAY_NAME);