mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-02-18 21:32:48 +01:00
Remove scoreboards
This commit is contained in:
parent
b44788510f
commit
ca89aa1003
@ -42,7 +42,6 @@ import net.citizensnpcs.trait.CurrentLocation;
|
||||
import net.citizensnpcs.trait.Gravity;
|
||||
import net.citizensnpcs.trait.HorseModifiers;
|
||||
import net.citizensnpcs.trait.LookClose;
|
||||
import net.citizensnpcs.trait.NPCScoreboard;
|
||||
import net.citizensnpcs.trait.NPCSkeletonType;
|
||||
import net.citizensnpcs.trait.OcelotModifiers;
|
||||
import net.citizensnpcs.trait.Poses;
|
||||
@ -80,11 +79,6 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Skeleton.SkeletonType;
|
||||
import org.bukkit.entity.Villager.Profession;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
import org.bukkit.scoreboard.DisplaySlot;
|
||||
import org.bukkit.scoreboard.Objective;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.Iterables;
|
||||
@ -1128,48 +1122,6 @@ public class NPCCommands {
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "scoreboard [objective] [criteria] --team [team] --score [score] --display [slot]",
|
||||
desc = "Sets an NPC's scoreboard",
|
||||
modifiers = { "scoreboard" },
|
||||
min = 3,
|
||||
max = 3,
|
||||
permission = "citizens.npc.scoreboard")
|
||||
@Requirements(selected = true, ownership = true, types = EntityType.PLAYER)
|
||||
public void scoreboard(CommandContext args, CommandSender sender, NPC npc) {
|
||||
Iterable<MetadataValue> itr = npc.getEntity().getMetadata("citizens.scoreboard");
|
||||
Scoreboard main;
|
||||
if (!itr.iterator().hasNext()) {
|
||||
main = Bukkit.getScoreboardManager().getNewScoreboard();
|
||||
npc.getEntity().setMetadata("citizens.scoreboard", new FixedMetadataValue(CitizensAPI.getPlugin(), main));
|
||||
} else {
|
||||
main = (Scoreboard) itr.iterator().next().value();
|
||||
}
|
||||
String objective = Colorizer.parseColors(args.getString(1));
|
||||
String criteria = Colorizer.parseColors(args.getString(2));
|
||||
Objective obj = main.getObjective(objective);
|
||||
if (obj == null) {
|
||||
obj = main.registerNewObjective(objective, criteria);
|
||||
}
|
||||
Player entity = (Player) npc.getEntity();
|
||||
if (args.hasValueFlag("team")) {
|
||||
String team = Colorizer.parseColors(args.getFlag("team"));
|
||||
if (main.getPlayerTeam(entity) != null)
|
||||
main.getPlayerTeam(entity).removePlayer(entity);
|
||||
if (main.getTeam(team) == null)
|
||||
main.registerNewTeam(team);
|
||||
main.getTeam(team).addPlayer(entity);
|
||||
}
|
||||
if (args.hasValueFlag("display")) {
|
||||
obj.setDisplaySlot(Util.matchEnum(DisplaySlot.values(), args.getFlag("display")));
|
||||
}
|
||||
if (args.hasValueFlag("score")) {
|
||||
obj.getScore(entity).setScore(args.getFlagInteger("score"));
|
||||
}
|
||||
npc.getTrait(NPCScoreboard.class).persistObjective(obj);
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "select|sel [id|name] (--r range)",
|
||||
|
@ -24,7 +24,6 @@ import net.citizensnpcs.trait.CurrentLocation;
|
||||
import net.citizensnpcs.trait.Gravity;
|
||||
import net.citizensnpcs.trait.HorseModifiers;
|
||||
import net.citizensnpcs.trait.LookClose;
|
||||
import net.citizensnpcs.trait.NPCScoreboard;
|
||||
import net.citizensnpcs.trait.NPCSkeletonType;
|
||||
import net.citizensnpcs.trait.OcelotModifiers;
|
||||
import net.citizensnpcs.trait.Poses;
|
||||
@ -64,7 +63,6 @@ public class CitizensTraitFactory implements TraitFactory {
|
||||
registerTrait(TraitInfo.create(Powered.class).withName("powered"));
|
||||
registerTrait(TraitInfo.create(Saddle.class).withName("saddle"));
|
||||
registerTrait(TraitInfo.create(Sheared.class).withName("sheared"));
|
||||
registerTrait(TraitInfo.create(NPCScoreboard.class).withName("npcscoreboard"));
|
||||
registerTrait(TraitInfo.create(NPCSkeletonType.class).withName("skeletontype"));
|
||||
registerTrait(TraitInfo.create(SlimeSize.class).withName("slimesize"));
|
||||
registerTrait(TraitInfo.create(Spawned.class).withName("spawned"));
|
||||
|
@ -1,112 +0,0 @@
|
||||
package net.citizensnpcs.trait;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.trait.Trait;
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.scoreboard.DisplaySlot;
|
||||
import org.bukkit.scoreboard.Objective;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
public class NPCScoreboard extends Trait {
|
||||
private final Set<Objective> objectives = Sets.newHashSet();
|
||||
private Scoreboard scoreboard;
|
||||
private String team;
|
||||
|
||||
public NPCScoreboard() {
|
||||
super("npcscoreboard");
|
||||
}
|
||||
|
||||
private void checkScoreboard() {
|
||||
if (scoreboard == null) {
|
||||
if (npc.isSpawned() && !npc.getEntity().getMetadata("citizens.scoreboard").isEmpty()) {
|
||||
scoreboard = (Scoreboard) npc.getEntity().getMetadata("citizens.scoreboard").iterator().next().value();
|
||||
} else {
|
||||
scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
|
||||
}
|
||||
}
|
||||
if (npc.getEntity() instanceof Player && npc.getEntity().getMetadata("citizens.scoreboard").isEmpty()) {
|
||||
npc.getEntity().setMetadata("citizens.scoreboard",
|
||||
new FixedMetadataValue(CitizensAPI.getPlugin(), scoreboard));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(DataKey root) {
|
||||
checkScoreboard();
|
||||
if (root.keyExists("team")) {
|
||||
team = root.getString("team");
|
||||
}
|
||||
if (!root.keyExists("objectives"))
|
||||
return;
|
||||
for (DataKey sub : root.getRelative("objectives").getSubKeys()) {
|
||||
String objName = sub.name();
|
||||
Objective objective;
|
||||
if (scoreboard.getObjective(objName) != null) {
|
||||
objective = scoreboard.getObjective(objName);
|
||||
} else {
|
||||
objective = scoreboard.registerNewObjective(objName, root.getString("criteria"));
|
||||
}
|
||||
objective.setDisplaySlot(DisplaySlot.valueOf(sub.getString("display")));
|
||||
objectives.add(objective);
|
||||
if (npc.isSpawned() && npc.getEntity() instanceof Player) {
|
||||
objective.getScore((Player) npc.getEntity()).setScore(sub.getInt("score"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSpawn() {
|
||||
if (npc.getEntity() instanceof Player && team != null) {
|
||||
checkScoreboard();
|
||||
scoreboard.getTeam(team).addPlayer((Player) npc.getEntity());
|
||||
}
|
||||
}
|
||||
|
||||
public void persistObjective(Objective objective) {
|
||||
if (!objectives.contains(objective)) {
|
||||
objectives.add(objective);
|
||||
}
|
||||
Team playerTeam = objectives.iterator().next().getScoreboard().getPlayerTeam((Player) npc.getEntity());
|
||||
if (team == null && playerTeam != null) {
|
||||
team = playerTeam.getName();
|
||||
}
|
||||
if (scoreboard == null) {
|
||||
scoreboard = objective.getScoreboard();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(DataKey root) {
|
||||
root.removeKey("objectives");
|
||||
root.removeKey("team");
|
||||
if (objectives.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
for (Objective objective : objectives) {
|
||||
DataKey key = root.getRelative("objectives." + objective.getName());
|
||||
key.setString("criteria", objective.getCriteria());
|
||||
key.setString("display", objective.getDisplaySlot().name());
|
||||
if (npc.getEntity() instanceof Player) {
|
||||
key.setInt("score", objective.getScore((Player) npc.getEntity()).getScore());
|
||||
}
|
||||
}
|
||||
if (npc.getEntity() instanceof Player && team == null) {
|
||||
Team playerTeam = objectives.iterator().next().getScoreboard().getPlayerTeam((Player) npc.getEntity());
|
||||
if (playerTeam != null) {
|
||||
team = playerTeam.getName();
|
||||
}
|
||||
}
|
||||
if (team != null) {
|
||||
root.setString("team", team);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user