Remove /npc scoreboard and make scoreboard trait just persist entity tags
This commit is contained in:
parent
db6058bbd0
commit
63ef3cdc73
|
@ -2578,35 +2578,6 @@ public class NPCCommands {
|
|||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "scoreboard --addtag [tags] --removetag [tags]",
|
||||
desc = "Controls an NPC's scoreboard",
|
||||
modifiers = { "scoreboard" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "citizens.npc.scoreboard")
|
||||
public void scoreboard(CommandContext args, CommandSender sender, NPC npc, @Flag("addtag") String addTag,
|
||||
@Flag("removetag") String removeTag) {
|
||||
ScoreboardTrait trait = npc.getOrAddTrait(ScoreboardTrait.class);
|
||||
String output = "";
|
||||
if (addTag != null) {
|
||||
for (String tag : addTag.split(",")) {
|
||||
trait.addTag(tag);
|
||||
}
|
||||
output += " " + Messaging.tr(Messages.ADDED_SCOREBOARD_TAGS, addTag);
|
||||
}
|
||||
if (removeTag != null) {
|
||||
for (String tag : removeTag.split(",")) {
|
||||
trait.removeTag(tag);
|
||||
}
|
||||
output += " " + Messaging.tr(Messages.REMOVED_SCOREBOARD_TAGS, removeTag);
|
||||
}
|
||||
if (!output.isEmpty()) {
|
||||
Messaging.send(sender, output.trim());
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "script --add [files] --remove [files]",
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package net.citizensnpcs.trait;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
@ -13,6 +12,8 @@ import org.bukkit.scoreboard.Team;
|
|||
import org.bukkit.scoreboard.Team.Option;
|
||||
import org.bukkit.scoreboard.Team.OptionStatus;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import net.citizensnpcs.Settings.Setting;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.LocationLookup.PerPlayerMetadata;
|
||||
|
@ -33,7 +34,7 @@ public class ScoreboardTrait extends Trait {
|
|||
private final PerPlayerMetadata<Boolean> metadata;
|
||||
private ChatColor previousGlowingColor;
|
||||
@Persist
|
||||
private final Set<String> tags = new HashSet<String>();
|
||||
private Set<String> tags = new HashSet<String>();
|
||||
|
||||
public ScoreboardTrait() {
|
||||
super("scoreboardtrait");
|
||||
|
@ -51,10 +52,6 @@ public class ScoreboardTrait extends Trait {
|
|||
});
|
||||
}
|
||||
|
||||
public void addTag(String tag) {
|
||||
tags.add(tag);
|
||||
}
|
||||
|
||||
private void clearClientTeams(Team team) {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (metadata.remove(player.getUniqueId(), team.getName())) {
|
||||
|
@ -81,10 +78,6 @@ public class ScoreboardTrait extends Trait {
|
|||
return color;
|
||||
}
|
||||
|
||||
public Set<String> getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
private Team getTeam() {
|
||||
String teamName = npc.data().get(NPC.Metadata.SCOREBOARD_FAKE_TEAM_NAME, "");
|
||||
if (teamName.isEmpty())
|
||||
|
@ -128,10 +121,15 @@ public class ScoreboardTrait extends Trait {
|
|||
@Override
|
||||
public void onSpawn() {
|
||||
changed = true;
|
||||
if (SUPPORT_TAGS) {
|
||||
try {
|
||||
npc.getEntity().getScoreboardTags().clear();
|
||||
npc.getEntity().getScoreboardTags().addAll(tags);
|
||||
} catch (NoSuchMethodError e) {
|
||||
SUPPORT_TAGS = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void removeTag(String tag) {
|
||||
tags.remove(tag);
|
||||
}
|
||||
|
||||
public void setColor(ChatColor color) {
|
||||
|
@ -162,21 +160,10 @@ public class ScoreboardTrait extends Trait {
|
|||
: npc.getUniqueId().toString();
|
||||
}
|
||||
|
||||
Set<String> newTags = new HashSet<String>(tags);
|
||||
if (SUPPORT_TAGS) {
|
||||
try {
|
||||
if (!npc.getEntity().getScoreboardTags().equals(tags)) {
|
||||
changed = true;
|
||||
for (Iterator<String> iterator = npc.getEntity().getScoreboardTags().iterator(); iterator
|
||||
.hasNext();) {
|
||||
String oldTag = iterator.next();
|
||||
if (!newTags.remove(oldTag)) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
for (String tag : newTags) {
|
||||
npc.getEntity().addScoreboardTag(tag);
|
||||
}
|
||||
tags = Sets.newHashSet(npc.getEntity().getScoreboardTags());
|
||||
}
|
||||
} catch (NoSuchMethodError e) {
|
||||
SUPPORT_TAGS = false;
|
||||
|
|
|
@ -2,7 +2,6 @@ package net.citizensnpcs.util;
|
|||
|
||||
public class Messages {
|
||||
public static final String ACTIVATION_RANGE_SET = "citizens.commands.npc.activationrange.set";
|
||||
public static final String ADDED_SCOREBOARD_TAGS = "citizens.commands.npc.scoreboard.added-tags";
|
||||
public static final String ADDED_TO_PLAYERLIST = "citizens.commands.npc.playerlist.added";
|
||||
public static final String AGE_LOCKED = "citizens.commands.npc.age.locked";
|
||||
public static final String AGE_SET_ADULT = "citizens.commands.npc.age.set-adult";
|
||||
|
@ -360,7 +359,6 @@ public class Messages {
|
|||
public static final String REMOVE_INCORRECT_SYNTAX = "citizens.commands.npc.remove.incorrect-syntax";
|
||||
public static final String REMOVED_ALL_NPCS = "citizens.commands.npc.remove.removed-all";
|
||||
public static final String REMOVED_FROM_PLAYERLIST = "citizens.commands.npc.playerlist.removed";
|
||||
public static final String REMOVED_SCOREBOARD_TAGS = "citizens.commands.npc.scoreboard.removed-tags";
|
||||
public static final String RESPAWN_DELAY_DESCRIBE = "citizens.commands.npc.respawn.describe";
|
||||
public static final String RESPAWN_DELAY_SET = "citizens.commands.npc.respawn.delay-set";
|
||||
public static final String SADDLED_SET = "citizens.editors.equipment.saddled-set";
|
||||
|
|
|
@ -279,8 +279,6 @@ citizens.commands.npc.respawn.describe=Respawn delay is currently [[{0}]] ticks.
|
|||
citizens.commands.npc.setequipment.set=Set [[{0}]] to [[{1}]].
|
||||
citizens.commands.npc.select.already-selected=You already have that NPC selected.
|
||||
citizens.commands.npc.script.invalid-file=Unknown or unavailable script ''[[{0}]]''.
|
||||
citizens.commands.npc.scoreboard.added-tags=Added these tags: [[{0}]].
|
||||
citizens.commands.npc.scoreboard.removed-tags=Removed these tags: [[{0}]].
|
||||
citizens.commands.npc.sheep.color-set=The sheep''s color was set to [[{0}]].
|
||||
citizens.commands.npc.sheep.invalid-color=Invalid sheep color given. Valid colors are: [[{0}]].
|
||||
citizens.commands.npc.script.current-scripts=[[{0}]]''s current scripts are [[{1}]].
|
||||
|
|
Loading…
Reference in New Issue