This commit is contained in:
parent
1380e7479a
commit
5ffb921150
7 changed files with 174 additions and 78 deletions
|
@ -1,8 +1,7 @@
|
|||
package me.unurled.sacredrealms.sr.commands.admin;
|
||||
|
||||
import static me.unurled.sacredrealms.sr.utils.Component.comp;
|
||||
import static me.unurled.sacredrealms.sr.utils.NumberParser.format;
|
||||
import static me.unurled.sacredrealms.sr.utils.NumberParser.parse;
|
||||
import static me.unurled.sacredrealms.sr.utils.SRPlayerUtils.syncSRToPlayer;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
@ -81,7 +80,7 @@ public class AttributeCommand implements TabExecutor {
|
|||
|
||||
if (args[0].equalsIgnoreCase("set")) {
|
||||
try {
|
||||
double value = parse(args[3]);
|
||||
double value = Double.parseDouble(args[3]);
|
||||
if (value < attribute.getMinValue() || value > attribute.getMaxValue()) {
|
||||
sender.sendMessage(
|
||||
"Value out of bounds. Min: "
|
||||
|
@ -94,7 +93,10 @@ public class AttributeCommand implements TabExecutor {
|
|||
if (player == null) return true;
|
||||
player.setHandItemAttribute(attribute, value);
|
||||
sender.sendMessage(
|
||||
"Set " + attribute.getName() + " to " + format(value) + " for " + target.getName());
|
||||
"Set " + attribute.getName() + " to " + value + " for " + target.getName());
|
||||
// update player
|
||||
player.setItemAttributes(attribute, target.getInventory().getItemInMainHand(), value);
|
||||
syncSRToPlayer(player, target);
|
||||
} catch (NumberFormatException e) {
|
||||
sender.sendMessage("Invalid value.");
|
||||
}
|
||||
|
@ -113,6 +115,8 @@ public class AttributeCommand implements TabExecutor {
|
|||
SRPlayer player = getSrPlayer(sender, target);
|
||||
if (player == null) return true;
|
||||
player.removeHandItemAttribute(attribute);
|
||||
player.removeItemAttributes(attribute, target.getInventory().getItemInMainHand());
|
||||
|
||||
sender.sendMessage("Removed " + attribute.getName() + " for " + target.getName());
|
||||
} else {
|
||||
sender.sendMessage("Usage: /attribute <set|get|remove> <player> <attribute> [value]");
|
||||
|
@ -135,7 +139,7 @@ public class AttributeCommand implements TabExecutor {
|
|||
|
||||
if (args[0].equalsIgnoreCase("set")) {
|
||||
try {
|
||||
double value = parse(args[3]);
|
||||
double value = Double.parseDouble(args[3]);
|
||||
if (value < attribute.getMinValue() || value > attribute.getMaxValue()) {
|
||||
sender.sendMessage(
|
||||
"Value out of bounds. Min: "
|
||||
|
@ -148,7 +152,9 @@ public class AttributeCommand implements TabExecutor {
|
|||
if (player == null) return true;
|
||||
player.setAttribute(attribute, value);
|
||||
sender.sendMessage(
|
||||
"Set " + attribute.getName() + " to " + format(value) + " for " + target.getName());
|
||||
"Set " + attribute.getName() + " to " + value + " for " + target.getName());
|
||||
player.setItemAttributes(attribute, target.getInventory().getItemInMainHand(), value);
|
||||
syncSRToPlayer(player, target);
|
||||
} catch (NumberFormatException e) {
|
||||
sender.sendMessage("Invalid value.");
|
||||
}
|
||||
|
@ -166,6 +172,8 @@ public class AttributeCommand implements TabExecutor {
|
|||
SRPlayer player = getSrPlayer(sender, target);
|
||||
if (player == null) return true;
|
||||
player.removeAttribute(attribute);
|
||||
player.removeItemAttributes(attribute, target.getInventory().getItemInMainHand());
|
||||
syncSRToPlayer(player, target);
|
||||
sender.sendMessage("Removed " + attribute.getName() + " for " + target.getName());
|
||||
} else {
|
||||
sender.sendMessage("Usage: /attribute <set|get|remove> <player> <attribute> [value]");
|
||||
|
@ -211,29 +219,6 @@ public class AttributeCommand implements TabExecutor {
|
|||
attributes.removeIf(s -> !s.startsWith(args[2]));
|
||||
return attributes;
|
||||
}
|
||||
if (args.length == 4 && args[0].equalsIgnoreCase("set")) {
|
||||
Attribute attribute;
|
||||
try {
|
||||
attribute = Attribute.valueOf(args[2].toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
if (parse(args[3]) > attribute.getMaxValue() || parse(args[3]) < attribute.getMinValue()) {
|
||||
return null;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<String> values = new java.util.ArrayList<>();
|
||||
double currentValue = attribute.getMinValue();
|
||||
while (currentValue <= attribute.getMaxValue()) {
|
||||
values.add(String.valueOf(format(currentValue)));
|
||||
currentValue *= 10;
|
||||
}
|
||||
return values;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue