mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-02-01 04:51:32 +01:00
Implement /trait clearsaves [traitnames] and change itemstack syntax to match minecraft's
This commit is contained in:
parent
ad91fd7e4d
commit
e7010e9035
@ -189,6 +189,10 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
|
||||
return commands;
|
||||
}
|
||||
|
||||
public NPCDataStore getDefaultNPCDataStore() {
|
||||
return saves;
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.citizensnpcs.api.npc.NPCSelector getDefaultNPCSelector() {
|
||||
return selector;
|
||||
|
@ -1,6 +1,8 @@
|
||||
package net.citizensnpcs.commands;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -9,6 +11,7 @@ import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import net.citizensnpcs.Citizens;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.command.Command;
|
||||
import net.citizensnpcs.api.command.CommandContext;
|
||||
@ -24,6 +27,12 @@ import net.citizensnpcs.util.StringHelper;
|
||||
|
||||
@Requirements(selected = true, ownership = true)
|
||||
public class TraitCommands {
|
||||
private final Citizens plugin;
|
||||
|
||||
public TraitCommands(Citizens plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "trait" },
|
||||
usage = "add [trait name]...",
|
||||
@ -65,6 +74,20 @@ public class TraitCommands {
|
||||
Bukkit.getPluginManager().callEvent(new NPCTraitCommandAttachEvent(npc, clazz, sender));
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "trait" },
|
||||
usage = "clearsaves [trait name]",
|
||||
desc = "",
|
||||
modifiers = { "clearsaves" },
|
||||
min = 2,
|
||||
permission = "citizens.npc.trait.clearsaves")
|
||||
public void clearsaves(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
List<String> added = Splitter.on(',').splitToStream(args.getJoinedStrings(1))
|
||||
.map(s -> s.toLowerCase(Locale.ROOT)).collect(Collectors.toList());
|
||||
plugin.getDefaultNPCDataStore().clearTraitData(added);
|
||||
Messaging.sendTr(sender, Messages.TRAIT_DATA_CLEARED, Joiner.on(", ").join(added));
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "trait" },
|
||||
usage = "remove [trait names]...",
|
||||
|
@ -715,9 +715,9 @@ public class HologramTrait extends Trait {
|
||||
protected NPC createNPC(Entity base, String name, Vector3d offset) {
|
||||
Matcher itemMatcher = ITEM_MATCHER.matcher(name);
|
||||
itemMatcher.find();
|
||||
Material item = SpigotUtil.isUsing1_13API() ? Material.matchMaterial(itemMatcher.group(1), false)
|
||||
Material material = SpigotUtil.isUsing1_13API() ? Material.matchMaterial(itemMatcher.group(1), false)
|
||||
: Material.matchMaterial(itemMatcher.group(1));
|
||||
ItemStack itemStack = new ItemStack(item, 1);
|
||||
ItemStack itemStack = new ItemStack(material, 1);
|
||||
NPC npc = registry().createNPCUsingItem(EntityType.ITEM_DISPLAY, "", itemStack);
|
||||
npc.data().setPersistent(NPC.Metadata.NAMEPLATE_VISIBLE, false);
|
||||
if (itemMatcher.group(2) != null) {
|
||||
@ -728,8 +728,8 @@ public class HologramTrait extends Trait {
|
||||
return npc;
|
||||
}
|
||||
}
|
||||
Bukkit.getUnsafe().modifyItemStack(itemStack, modify);
|
||||
npc.setItemProvider(() -> itemStack.clone());
|
||||
ItemStack stack = Bukkit.getItemFactory().createItemStack(material + "[" + modify + "]");
|
||||
npc.setItemProvider(() -> stack.clone());
|
||||
}
|
||||
return npc;
|
||||
}
|
||||
@ -760,9 +760,9 @@ public class HologramTrait extends Trait {
|
||||
mount.getOrAddTrait(ArmorStandTrait.class).setAsPointEntity();
|
||||
Matcher itemMatcher = ITEM_MATCHER.matcher(name);
|
||||
itemMatcher.find();
|
||||
Material item = SpigotUtil.isUsing1_13API() ? Material.matchMaterial(itemMatcher.group(1), false)
|
||||
Material material = SpigotUtil.isUsing1_13API() ? Material.matchMaterial(itemMatcher.group(1), false)
|
||||
: Material.matchMaterial(itemMatcher.group(1));
|
||||
ItemStack itemStack = new ItemStack(item, 1);
|
||||
ItemStack itemStack = new ItemStack(material, 1);
|
||||
itemNPC = registry().createNPCUsingItem(Util.getFallbackEntityType("ITEM", "DROPPED_ITEM"), "", itemStack);
|
||||
itemNPC.data().setPersistent(NPC.Metadata.NAMEPLATE_VISIBLE, false);
|
||||
if (itemMatcher.group(2) != null) {
|
||||
@ -776,8 +776,8 @@ public class HologramTrait extends Trait {
|
||||
}
|
||||
}
|
||||
if (matched == null) {
|
||||
Bukkit.getUnsafe().modifyItemStack(itemStack, modify);
|
||||
itemNPC.setItemProvider(() -> itemStack.clone());
|
||||
ItemStack stack = Bukkit.getItemFactory().createItemStack(material + "[" + modify + "]");
|
||||
itemNPC.setItemProvider(() -> stack.clone());
|
||||
}
|
||||
}
|
||||
itemNPC.spawn(base.getLocation());
|
||||
@ -992,7 +992,6 @@ public class HologramTrait extends Trait {
|
||||
}
|
||||
|
||||
private static final Pattern ITEM_MATCHER = Pattern.compile("<item:((?:minecraft:)?[a-zA-Z0-9_ ]*?)(:.*?)?>");
|
||||
|
||||
private static boolean SUPPORTS_DISPLAY = true;
|
||||
|
||||
static {
|
||||
|
@ -150,7 +150,8 @@ public class ItemAction extends NPCShopAction {
|
||||
|
||||
private boolean matches(ItemStack a, ItemStack b) {
|
||||
if (Messaging.isDebugging()) {
|
||||
Messaging.debug("Shop filter: comparing " + NMS.getComponentMap(a) + " to " + NMS.getComponentMap(b));
|
||||
Messaging.debug("Shop filter: comparing " + NMS.getComponentMap(a) + " to " + NMS.getComponentMap(b) + " ("
|
||||
+ metaFilter + ")");
|
||||
}
|
||||
if (a.getType() != b.getType() || metaFilter.size() > 0 && !metaMatches(a, b, metaFilter))
|
||||
return false;
|
||||
|
@ -446,6 +446,7 @@ public class Messages {
|
||||
public static final String TPTO_ENTITY_NOT_FOUND = "citizens.commands.npc.tpto.to-not-found";
|
||||
public static final String TPTO_SUCCESS = "citizens.commands.npc.tpto.success";
|
||||
public static final String TRACKING_RANGE_SET = "citizens.commands.npc.trackingrange.set";
|
||||
public static final String TRAIT_DATA_CLEARED = "citizens.commands.trait.clearsaves.cleared";
|
||||
public static final String TRAIT_LOAD_FAILED = "citizens.notifications.trait-load-failed";
|
||||
public static final String TRAIT_ONSPAWN_FAILED = "citizens.notifications.trait-onspawn-failed";
|
||||
public static final String TRAITS_ADDED = "citizens.commands.trait.added";
|
||||
|
@ -18,6 +18,9 @@
|
||||
"citizens.commands.invalid.class" : "Invalid external commands class.",
|
||||
"citizens.commands.npc.activationrange.description" : "Sets the activation range",
|
||||
"citizens.commands.npc.activationrange.help" : "",
|
||||
"citizens.commands.trait.clearsaves.cleared": "Cleared [[{0}]] from saves.",
|
||||
"citizens.commands.trait.clearsaves.description": "Clears trait information from saves",
|
||||
"citizens.commands.trait.clearsaves.help": "",
|
||||
"citizens.commands.npc.activationrange.set" : "Activation range set to [[{0}]].",
|
||||
"citizens.commands.npc.age.cannot-be-aged" : "The mob type {0} cannot be aged.",
|
||||
"citizens.commands.npc.age.description" : "Set the age of an NPC",
|
||||
|
Loading…
Reference in New Issue
Block a user