mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-12-22 09:07:56 +01:00
Use parseItemstack
This commit is contained in:
parent
ce41609139
commit
8d492ff0b2
@ -170,6 +170,8 @@ import net.citizensnpcs.trait.TargetableTrait;
|
||||
import net.citizensnpcs.trait.WitherTrait;
|
||||
import net.citizensnpcs.trait.WolfModifiers;
|
||||
import net.citizensnpcs.trait.shop.StoredShops;
|
||||
import net.citizensnpcs.trait.waypoint.WanderWaypointProvider;
|
||||
import net.citizensnpcs.trait.waypoint.WaypointProvider;
|
||||
import net.citizensnpcs.trait.waypoint.Waypoints;
|
||||
import net.citizensnpcs.util.Anchor;
|
||||
import net.citizensnpcs.util.Messages;
|
||||
@ -842,7 +844,7 @@ public class NPCCommands {
|
||||
registry = temporaryRegistry;
|
||||
}
|
||||
if (item != null) {
|
||||
ItemStack stack = Util.parseItemStack(null, item);
|
||||
ItemStack stack = SpigotUtil.parseItemStack(null, item);
|
||||
npc = registry.createNPCUsingItem(type, name, stack);
|
||||
} else {
|
||||
npc = registry.createNPC(type, name);
|
||||
@ -1570,7 +1572,7 @@ public class NPCCommands {
|
||||
throw new CommandException(CommandMessages.REQUIREMENTS_INVALID_MOB_TYPE, Util.prettyEnum(type));
|
||||
ItemStack stack = args.hasFlag('h') ? ((Player) sender).getItemInHand() : new ItemStack(mat, 1);
|
||||
if (modify != null) {
|
||||
stack = Util.parseItemStack(stack, modify);
|
||||
stack = SpigotUtil.parseItemStack(stack, modify);
|
||||
}
|
||||
if (mat == null && !args.hasFlag('h'))
|
||||
throw new CommandException(Messages.UNKNOWN_MATERIAL);
|
||||
@ -3659,19 +3661,39 @@ public class NPCCommands {
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "wander",
|
||||
usage = "wander (add x y z world)",
|
||||
desc = "",
|
||||
modifiers = { "wander" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
max = 6,
|
||||
permission = "citizens.npc.wander")
|
||||
public void wander(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
public void wander(CommandContext args, CommandSender sender, NPC npc, @Arg(1) String command)
|
||||
throws CommandException {
|
||||
Waypoints trait = npc.getOrAddTrait(Waypoints.class);
|
||||
if (args.argsLength() == 1) {
|
||||
if (sender instanceof Player && Editor.hasEditor((Player) sender)) {
|
||||
Editor.leave((Player) sender);
|
||||
}
|
||||
trait.setWaypointProvider(trait.getCurrentProviderName().equals("wander") ? "linear" : "wander");
|
||||
Messaging.sendTr(sender, Messages.WAYPOINT_PROVIDER_SET, trait.getCurrentProviderName());
|
||||
} else if (command.equals("add")) {
|
||||
if (args.argsLength() < 5)
|
||||
throw new CommandUsageException();
|
||||
|
||||
WaypointProvider provider = trait.getCurrentProvider();
|
||||
if (!(provider instanceof WanderWaypointProvider)) {
|
||||
trait.setWaypointProvider("wander");
|
||||
provider = trait.getCurrentProvider();
|
||||
}
|
||||
World world = args.argsLength() > 5 ? Bukkit.getWorld(args.getString(5))
|
||||
: npc.getStoredLocation().getWorld();
|
||||
if (world == null)
|
||||
throw new CommandException(Messages.WORLD_NOT_FOUND);
|
||||
|
||||
Location loc = new Location(world, args.getInteger(2), args.getInteger(3), args.getInteger(4));
|
||||
((WanderWaypointProvider) provider).addRegionCentre(loc);
|
||||
Messaging.sendTr(sender, Messages.WAYPOINT_ADDED, Util.prettyPrintLocation(loc));
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
|
@ -41,10 +41,8 @@ import org.bukkit.util.Vector;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.google.common.primitives.Ints;
|
||||
|
||||
import net.citizensnpcs.Settings.Setting;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
@ -425,32 +423,6 @@ public class Util {
|
||||
throw new NumberFormatException();
|
||||
}
|
||||
|
||||
public static ItemStack parseItemStack(ItemStack stack, String item) {
|
||||
if (stack == null || stack.getType() == Material.AIR) {
|
||||
stack = new ItemStack(Material.STONE, 1);
|
||||
}
|
||||
if (item.contains("{")) {
|
||||
try {
|
||||
Bukkit.getUnsafe().modifyItemStack(stack, item);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
} else if (!item.isEmpty()) {
|
||||
String[] parts = Iterables.toArray(Splitter.on(',').split(item), String.class);
|
||||
if (parts.length == 0)
|
||||
return stack;
|
||||
stack.setType(Material.matchMaterial(parts[0]));
|
||||
if (parts.length > 1) {
|
||||
stack.setAmount(Ints.tryParse(parts[1]));
|
||||
}
|
||||
if (parts.length > 2) {
|
||||
Integer durability = Ints.tryParse(parts[2]);
|
||||
stack.setDurability(durability.shortValue());
|
||||
}
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
||||
public static int parseTicks(String raw) {
|
||||
Duration duration = SpigotUtil.parseDuration(raw, null);
|
||||
return duration == null ? -1 : toTicks(duration);
|
||||
|
@ -12,5 +12,18 @@
|
||||
"citizens.commands.id-not-found" : "Δεν μπόρεσα να βρώ κανένα NPC με αναγνωριστικό [[{0}]].",
|
||||
"citizens.commands.invalid.class" : "Μη έγκυρη κλάση εξωτερικών εντολών.",
|
||||
"citizens.commands.invalid-mobtype" : "Το [[{0}]] δεν είναι έγκυρος τύπος mob.",
|
||||
"citizens.commands.invalid-number" : "Αυτό δεν είναι ένας έγκυρος αριθμός."
|
||||
"citizens.commands.invalid-number" : "Αυτό δεν είναι ένας έγκυρος αριθμός.",
|
||||
"citizens.commands.npc.activationrange.description" : "Ρυθμίζει το εύρος ενεργοποίησης.",
|
||||
"citizens.commands.npc.activationrange.set" : "Το εύρος ενεργοποίησης ορίστηκε σε [[{0}]].",
|
||||
"citizens.commands.npc.age.cannot-be-aged" : "Ο τύπος mob {0} δεν μπορεί να μεγαλώσει ηλικιακά.",
|
||||
"citizens.commands.npc.age.description" : "Ορίστε την ηλικία ενός NPC.",
|
||||
"citizens.commands.npc.age.help" : "Μπορεί να χρησιμοποιηθεί μόνο σε οντότητες που μπορούν να γίνουν μωρά. Χρησιμοποιήστε τη σημαία [[-l]] για να κλειδώσετε την ηλικία με την πάροδο του χρόνου (σημείωση: ενδέχεται να απαιτούνται επανεγγραφές για να το δείτε).",
|
||||
"citizens.commands.npc.age.invalid-age" : "Μη έγκυρη ηλικία. Οι ηλικίες που ισχύουν είναι ενήλικας, μωρό, αριθμός μεταξύ -24000 και 0\n",
|
||||
"citizens.commands.npc.age.locked" : "Η ηλικία κλειδώθηκε.",
|
||||
"citizens.commands.npc.age.set" : "Το [[{0}]] είναι τώρα [[{1}]].",
|
||||
"citizens.commands.npc.age.set-adult" : "Ο [[{0}]] είναι πλέον ενήλικας.",
|
||||
"citizens.commands.npc.age.set-baby" : "Ο [[{0}]] είναι πλέον μωρό.",
|
||||
"citizens.commands.npc.age.unlocked" : "Η ηλικία ξεκλειδώθηκε.",
|
||||
"citizens.commands.npc.aggressive.description" : "Ορίζει την επιθετική κατάσταση της οντότητας",
|
||||
"citizens.commands.npc.ai.description" : "Ρυθμίζει εάν το NPC πρέπει να χρησιμοποιεί vanilla AI"
|
||||
}
|
@ -345,6 +345,7 @@
|
||||
"citizens.commands.npc.pathopt.use-new-finder" : "[[{0}]] 使用新寻路器的设置更改为 [[{1}]].",
|
||||
"citizens.commands.npc.pathto.description" : "开始到指定位置的寻路",
|
||||
"citizens.commands.npc.pausepathfinding.description" : "设置是否暂停寻路",
|
||||
"citizens.commands.npc.pausepathfinding.lockout-duration-set" : "[[{0}} 现在会在下一次暂停前等待 [[{1}]] 个游戏刻。",
|
||||
"citizens.commands.npc.pausepathfinding.pause-range-set" : "[{0}]] 将在 [[{1}]] 格内有玩家时暂停寻路.",
|
||||
"citizens.commands.npc.pausepathfinding.pause-ticks-set" : "[[{0}]] 现在将一次暂停 [[{1}]] tick 的寻路.",
|
||||
"citizens.commands.npc.pausepathfinding.rightclick-set" : "[[{0}]] 将在被右键时暂停寻路.",
|
||||
@ -402,8 +403,11 @@
|
||||
"citizens.commands.npc.respawn.describe" : "当前重生延迟是 [[{0}]].",
|
||||
"citizens.commands.npc.respawn.description" : "设置 NPC 的重生延迟",
|
||||
"citizens.commands.npc.rotate.description" : "旋转 NPC",
|
||||
"citizens.commands.npc.scaledmaxhealth.description" : "控制 NPC 的生命值上限,可以使用大数字。",
|
||||
"citizens.commands.npc.scaledmaxhealth.set" : "生命值上限设置为 [[(0}]] 。",
|
||||
"citizens.commands.npc.select.already-selected" : "你已经选择了这个 NPC.",
|
||||
"citizens.commands.npc.select.description" : "根据提供的 ID 或名称选取一个 NPC",
|
||||
"citizens.commands.npc.setequipment.cosmetic-set" : "设置 [[{0}]] (饰品) 为 [[{1}]] 。",
|
||||
"citizens.commands.npc.setequipment.description" : "通过命令设置装备",
|
||||
"citizens.commands.npc.setequipment.set" : "设置 [[{0}]] 为 [[{1}]].",
|
||||
"citizens.commands.npc.sheep.color-set" : "羊的颜色设置为 [[{0}]].",
|
||||
|
Loading…
Reference in New Issue
Block a user