Allow players to specify how many xp cheque's to create in one go
This commit is contained in:
parent
9234f870c6
commit
b7920b2ffb
|
|
@ -35,9 +35,23 @@ public class XPCheque extends SubCommand {
|
|||
return true;
|
||||
}
|
||||
|
||||
if (args.length != 2)
|
||||
if (args.length != 2 && args.length != 3)
|
||||
return false;
|
||||
|
||||
int amount = 1;
|
||||
if (args.length == 3) {
|
||||
try {
|
||||
amount = Integer.parseInt(args[2]);
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (amount > 64 || amount < 1) {
|
||||
commandSender.sendMiniMessage(Messages.XP_CHEQUE.INVALID_AMOUNT, null);
|
||||
return true;
|
||||
}
|
||||
|
||||
int xpValue;
|
||||
try {
|
||||
xpValue = Integer.parseInt(args[1]);
|
||||
|
|
@ -51,7 +65,7 @@ public class XPCheque extends SubCommand {
|
|||
}
|
||||
|
||||
int totalExperience = player.getTotalExperience();
|
||||
if (totalExperience < xpValue) {
|
||||
if (totalExperience < (xpValue * amount)) {
|
||||
commandSender.sendMiniMessage(Messages.XP_CHEQUE.NOT_ENOUGH_XP, Placeholder.parsed("xp", String.valueOf(totalExperience)));
|
||||
return true;
|
||||
}
|
||||
|
|
@ -62,21 +76,27 @@ public class XPCheque extends SubCommand {
|
|||
return true;
|
||||
}
|
||||
|
||||
if (heldItem.getAmount() < amount) {
|
||||
commandSender.sendMiniMessage(Messages.XP_CHEQUE.NOT_ENOUGH_BOTTLE, Placeholder.parsed("amount", String.valueOf(amount)));
|
||||
return true;
|
||||
}
|
||||
|
||||
Optional<ItemStack> optionalItemStack = getExpBottleItem(player, xpValue);
|
||||
if (optionalItemStack.isEmpty())
|
||||
return true;
|
||||
|
||||
ItemStack xpBottle = optionalItemStack.get();
|
||||
xpBottle.setAmount(amount);
|
||||
|
||||
decreaseExperience(player, xpValue);
|
||||
decreaseExperience(player, xpValue * amount);
|
||||
|
||||
if (heldItem.getAmount() == 1) {
|
||||
if (heldItem.getAmount() == amount) {
|
||||
player.getInventory().setItemInMainHand(xpBottle);
|
||||
player.updateInventory();
|
||||
return true;
|
||||
}
|
||||
|
||||
heldItem.setAmount(heldItem.getAmount() - 1);
|
||||
heldItem.setAmount(heldItem.getAmount() - amount);
|
||||
player.getInventory().addItem(xpBottle).values()
|
||||
.forEach(item -> player.getWorld().dropItemNaturally(player.getLocation(), item));
|
||||
player.updateInventory();
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ public class Messages extends AbstractConfig {
|
|||
public static String HELP_MESSAGE_WRAPPER = "<gold>PlayerUtils help:\n<commands></gold>";
|
||||
public static String HELP_MESSAGE = "<green>Show this menu: <gold>/pu help</gold></green>";
|
||||
public static String GLOW = "<green>Glow in a specified color: <gold>/pu glow <color></gold></green>";
|
||||
public static String XP_CHEQUE = "<green>Create an XP cheque: <gold>/pu xpcheque <amount></gold></green>";
|
||||
public static String XP_CHEQUE = "<green>Create an XP cheque: <gold>/pu xpcheque <xp_value> [amount]</gold></green>";
|
||||
public static String XP_CALC = "<green>Calculate the amount of XP between levels: <gold>/pu xpcalc <from> <to></gold></green>";
|
||||
public static String RELOAD = "<green>Reload the configs for PlayerUtils: <gold>/pu reload</gold></green>";
|
||||
public static String ROTATE_BLOCK = "<green>Enable rotating blocks with a blaze rod: <gold>/pu rotateblock</gold></green>";
|
||||
|
|
@ -88,6 +88,8 @@ public class Messages extends AbstractConfig {
|
|||
public static String NOT_HOLDING_BOTTLE = "<red>You need to hold an empty glass bottle while executing this command</red>";
|
||||
public static String DISPLAY_NAME = "<yellow>XP bottle containing <xp> XP</yellow>";
|
||||
public static List<String> LORE = List.of("Issued by <name>", "Throw to retrieve <xp> XP");
|
||||
public static String NOT_ENOUGH_BOTTLE = "<red>You need to be holding <amount> glass bottles</red>";
|
||||
public static String INVALID_AMOUNT = "<red>You can only create between 1 and 64 xp cheque's at a time</red>";
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static void load() {
|
||||
|
|
@ -97,6 +99,8 @@ public class Messages extends AbstractConfig {
|
|||
NOT_HOLDING_BOTTLE = config.getString(prefix, "not-holding-bottle", NOT_HOLDING_BOTTLE);
|
||||
DISPLAY_NAME = config.getString(prefix, "display-name", DISPLAY_NAME);
|
||||
LORE = config.getStringList(prefix, "lore", LORE);
|
||||
NOT_ENOUGH_BOTTLE = config.getString(prefix, "not-enough-bottle", NOT_ENOUGH_BOTTLE);
|
||||
INVALID_AMOUNT = config.getString(prefix, "invalid-amount", INVALID_AMOUNT);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ import org.bukkit.inventory.ItemStack;
|
|||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class RotateBlockEvent implements Listener {
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user