Added xp calc command
This commit is contained in:
parent
95b98ef462
commit
1663498080
|
|
@ -2,6 +2,7 @@ package com.alttd.playerutils.commands;
|
||||||
|
|
||||||
import com.alttd.playerutils.PlayerUtils;
|
import com.alttd.playerutils.PlayerUtils;
|
||||||
import com.alttd.playerutils.commands.playerutils_subcommands.Glow;
|
import com.alttd.playerutils.commands.playerutils_subcommands.Glow;
|
||||||
|
import com.alttd.playerutils.commands.playerutils_subcommands.XPCalc;
|
||||||
import com.alttd.playerutils.commands.playerutils_subcommands.XPCheque;
|
import com.alttd.playerutils.commands.playerutils_subcommands.XPCheque;
|
||||||
import com.alttd.playerutils.config.Messages;
|
import com.alttd.playerutils.config.Messages;
|
||||||
import com.alttd.playerutils.util.Logger;
|
import com.alttd.playerutils.util.Logger;
|
||||||
|
|
@ -30,7 +31,8 @@ public class PlayerUtilsCommand implements CommandExecutor, TabExecutor {
|
||||||
|
|
||||||
subCommands = Arrays.asList(
|
subCommands = Arrays.asList(
|
||||||
new Glow(logger),
|
new Glow(logger),
|
||||||
new XPCheque(playerUtils)
|
new XPCheque(playerUtils),
|
||||||
|
new XPCalc()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,73 @@
|
||||||
|
package com.alttd.playerutils.commands.playerutils_subcommands;
|
||||||
|
|
||||||
|
import com.alttd.playerutils.commands.SubCommand;
|
||||||
|
import com.alttd.playerutils.config.Messages;
|
||||||
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class XPCalc extends SubCommand {
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender commandSender, String[] args) {
|
||||||
|
if (args.length != 3) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Optional<Integer> optionalFrom = getInt(args[1]);
|
||||||
|
Optional<Integer> optionalTo = getInt(args[2]);
|
||||||
|
|
||||||
|
if (optionalFrom.isEmpty() || optionalTo.isEmpty())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
long totalXpNeeded = 0;
|
||||||
|
int startingLevel = optionalFrom.get();
|
||||||
|
int endingLevel = optionalTo.get();
|
||||||
|
if (endingLevel < startingLevel) {
|
||||||
|
int tmp = startingLevel;
|
||||||
|
startingLevel = endingLevel;
|
||||||
|
endingLevel = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (startingLevel < endingLevel) {
|
||||||
|
totalXpNeeded += getExpToNext(startingLevel);
|
||||||
|
startingLevel++;
|
||||||
|
}
|
||||||
|
|
||||||
|
commandSender.sendMiniMessage(Messages.XP_CALC.XP_NEEDED, Placeholder.parsed("xp_needed", String.valueOf(totalXpNeeded)));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "xpcalc";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getTabComplete(CommandSender commandSender, String[] args) {
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHelpMessage() {
|
||||||
|
return Messages.HELP.XP_CALC;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Optional<Integer> getInt(String arg) {
|
||||||
|
try {
|
||||||
|
return Optional.of(Integer.parseInt(arg));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getExpToNext(int level) {
|
||||||
|
if (level <= 15) {
|
||||||
|
return 2 * level + 7;
|
||||||
|
} else if (level <= 30) {
|
||||||
|
return 5 * level - 38;
|
||||||
|
} else {
|
||||||
|
return 9 * level - 158;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -10,7 +10,7 @@ public class Messages extends AbstractConfig {
|
||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
|
|
||||||
Messages(PlayerUtils playerUtils, Logger logger) {
|
Messages(PlayerUtils playerUtils, Logger logger) {
|
||||||
super(playerUtils, "config.yml", logger);
|
super(playerUtils, "messages.yml", logger);
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -26,6 +26,7 @@ public class Messages extends AbstractConfig {
|
||||||
public static String HELP_MESSAGE = "<green>Show this menu: <gold>/pu help</gold></green>";
|
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 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 <amount></gold></green>";
|
||||||
|
public static String XP_CALC = "<green>Calculate the amount of xp between levels: <gold>/pu xpcalc <from> <to></gold></green>";
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private static void load() {
|
private static void load() {
|
||||||
|
|
@ -33,6 +34,7 @@ public class Messages extends AbstractConfig {
|
||||||
HELP_MESSAGE = config.getString(prefix, "help", HELP_MESSAGE);
|
HELP_MESSAGE = config.getString(prefix, "help", HELP_MESSAGE);
|
||||||
GLOW = config.getString(prefix, "glow", GLOW);
|
GLOW = config.getString(prefix, "glow", GLOW);
|
||||||
XP_CHEQUE = config.getString(prefix, "xp-cheque", XP_CHEQUE);
|
XP_CHEQUE = config.getString(prefix, "xp-cheque", XP_CHEQUE);
|
||||||
|
XP_CALC = config.getString(prefix, "xp-calc", XP_CALC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -84,4 +86,15 @@ public class Messages extends AbstractConfig {
|
||||||
LORE = config.getStringList(prefix, "lore", LORE);
|
LORE = config.getStringList(prefix, "lore", LORE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class XP_CALC {
|
||||||
|
private static final String prefix = "pu-command.xp-cheque.";
|
||||||
|
|
||||||
|
public static String XP_NEEDED = "<green>Xp needed <gold><xp_needed></gold>.</green>";
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
private static void load() {
|
||||||
|
XP_NEEDED = config.getString(prefix, "xp-needed", XP_NEEDED);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user