diff --git a/pom.xml b/pom.xml index b660daa..208a541 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 dk.lockfuglsang.wolfencraft holographic-scoreboard - 1.3.11 + 1.4.0 HolographicScoreboard @@ -17,6 +17,11 @@ Plugin Metrics http://repo.mcstats.org/content/repositories/public + + + uSkyBlock-mvn-repo + https://raw.github.com/rlf/uSkyBlock/mvn-repo/ + @@ -48,6 +53,10 @@ org.mcstats dk.lockfuglsang.wolfencraft.mcstats + + dk.lockfuglsang.minecraft + dk.lockfuglsang.hgs.minecraft + @@ -65,9 +74,14 @@ org.bukkit bukkit - LATEST + 1.9-R0.1-SNAPSHOT provided + + dk.lockfuglsang.minecraft + bukkit-utils + 1.2 + junit junit diff --git a/src/main/java/dk/lockfuglsang/wolfencraft/HolographicScoreboard.java b/src/main/java/dk/lockfuglsang/wolfencraft/HolographicScoreboard.java index 3224676..5a0a1f6 100644 --- a/src/main/java/dk/lockfuglsang/wolfencraft/HolographicScoreboard.java +++ b/src/main/java/dk/lockfuglsang/wolfencraft/HolographicScoreboard.java @@ -1,25 +1,23 @@ package dk.lockfuglsang.wolfencraft; +import dk.lockfuglsang.wolfencraft.commands.HGSCommand; import dk.lockfuglsang.wolfencraft.config.ConfigWriter; import dk.lockfuglsang.wolfencraft.config.Scoreboard; import dk.lockfuglsang.wolfencraft.stats.CommandPlotter; -import dk.lockfuglsang.wolfencraft.util.LocationUtil; import dk.lockfuglsang.wolfencraft.util.ResourceManager; import dk.lockfuglsang.wolfencraft.util.TimeUtil; import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.command.Command; import org.bukkit.command.CommandSender; -import org.bukkit.command.ConsoleCommandSender; import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitTask; import org.mcstats.Metrics; import java.io.IOException; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; import java.util.concurrent.CopyOnWriteArraySet; /** @@ -42,6 +40,7 @@ public void onEnable() { this.setEnabled(false); return; } + getCommand("holographicscoreboard").setExecutor(new HGSCommand(this)); try { metrics = new Metrics(this); cmdGraph = metrics.createGraph("Commands"); @@ -104,7 +103,7 @@ private void scheduleAll() { } } - private void scheduleUpdater(final Scoreboard scoreboard) { + public void scheduleUpdater(final Scoreboard scoreboard) { final String scoreBoardId = scoreboard.getId(); BukkitTask oldTask = tasks.put(scoreBoardId, Bukkit.getScheduler().runTaskTimer(this, new Runnable() { @Override @@ -154,189 +153,7 @@ public void saveConfig() { super.saveConfig(); } - @java.lang.Override - public boolean onCommand(CommandSender sender, Command command, java.lang.String label, java.lang.String[] args) { - if (command.getName().equalsIgnoreCase(CMD_HGS)) { - if (isAllowed(sender)) { - if (args.length == 0) { - return false; - } - switch (args[0]) { - case "list": - return showList(sender); - case "create": - return createScoreboard(sender, args); - case "remove": - return removeScoreboard(sender, args); - case "save": - return saveConfig(sender); - case "reload": - return reloadConfig(sender); - case "refresh": - return refreshScoreboards(sender, args); - case "move": - return moveScoreboard(sender, args); - case "edit": - return editScoreboard(sender, args); - } - } else { - sender.sendMessage(rm.format("error.noaccess")); - return true; - } - } - return false; - } - - private boolean editScoreboard(CommandSender sender, String[] args) { - String scoreboardId = args.length > 1 ? args[1] : null; - String key = args.length > 2 ? args[2] : null; - String value = args.length > 3 ? args[3] : null; - if (args.length > 4) { - for (int i = 4; i < args.length; i++) { - value += " " + args[i]; - } - } - Scoreboard scoreboard = getScoreboard(scoreboardId); - if (scoreboard != null && key != null) { - if (key.equals("filter")) { - scoreboard.setFilter(value); - } else if (key.equals("addfilter")) { - List filter = scoreboard.getFilter(); - filter.add(value); - scoreboard.setFilter(filter); - } else if (key.equals("location")) { - Location location = LocationUtil.getLocation(value); - if (location == null) { - sender.sendMessage(rm.format("error.wrong.location")); - return false; - } else { - scoreboard.setLocation(location); - } - } else if (key.equals("delay") || key.equals("interval")) { - int time = TimeUtil.getTimeAsTicks(value); - if (time == 0) { - sender.sendMessage(rm.format("error.wrong." + key)); - return false; - } else if (key.equals("delay")) { - scoreboard.setDelay(value); - } else if (key.equals("interval")) { - scoreboard.setInterval(value); - } - } else { - return false; - } - sender.sendMessage(rm.format("msg.scoreboard.edit", key, scoreboardId, value)); - return true; - } - return false; - } - - private boolean isAllowed(CommandSender sender) { - return sender instanceof ConsoleCommandSender || sender.hasPermission("holographicscoreboard.admin") || sender.isOp(); - } - - private boolean moveScoreboard(CommandSender sender, String[] args) { - Scoreboard scoreboard = getScoreboard(args[1]); - if (scoreboard != null) { - Location location = null; - try { - if (args.length == 2 && sender instanceof Player) { - location = ((Player) sender).getEyeLocation(); - } else if (args.length == 3) { - location = LocationUtil.getLocation(args[2]); - } - if (location == null) { - throw new IllegalArgumentException("No valid location was found"); - } - } catch (IllegalArgumentException e) { - sender.sendMessage(rm.format("msg.usage.move")); - return true; - } - scoreboard.setLocation(location); - scoreboard.refreshView(this); - sender.sendMessage(rm.format("msg.scoreboard.moved", args[1], location.getX(), location.getY(), location.getZ(), location.getWorld().getName())); - return true; - } - sender.sendMessage(rm.format("error.scoreboard.notfound", args[1])); - return false; - } - - private List getSuggestions(String cmd, List possibleSuggestions) { - List suggestions = new ArrayList<>(); - for (String suggestion : possibleSuggestions) { - if (suggestion.startsWith(cmd)) { - suggestions.add(suggestion); - } - } - return suggestions; - } - - @Override - public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { - // TODO: Refactor this to be "smarter" - if (command.getName().equalsIgnoreCase(CMD_HGS)) { - List suggestions = new ArrayList<>(); - if (args.length == 1) { - // Complete on the first-level commands - String arg = args[0].toLowerCase(); - suggestions.addAll(getSuggestions(arg, Arrays.asList("list", "create", "remove", "info", "save", "reload", "refresh", "move", "edit"))); - } else if (args.length == 2) { - // Complete on 2nd level - if ("remove".equals(args[0]) || "move".equals(args[0]) || "edit".equals(args[0])) { - suggestions.addAll(getScoreboards(args[1])); - } else if ("refresh".equals(args[0])) { - suggestions.addAll(getScoreboards(args[1])); - } - } else if (args.length == 3) { - if ("create".equals(args[0])) { - // interval - we could suggest something here... - suggestions.addAll(getSuggestions(args[2].toLowerCase(), Arrays.asList("10s", "30s", "5m", "10m", "30m", "1h"))); - } else if ("edit".equals(args[0])) { - suggestions.addAll(Arrays.asList("filter", "delay", "interval", "location")); - } - } else if (args.length == 4) { - if ("create".equals(args[0])) { - suggestions.addAll(getSuggestions(args[3].toLowerCase(), Arrays.asList("player", "console"))); - } - } - return suggestions; - } - return null; - } - - private List getScoreboards(String arg) { - String lowerArg = arg.toLowerCase(); - List suggestions = new ArrayList<>(); - for (Scoreboard scoreboard : scoreboards) { - if (scoreboard.getId().toLowerCase().startsWith(lowerArg)) { - suggestions.add(scoreboard.getId()); - } - } - return suggestions; - } - - private boolean refreshScoreboards(CommandSender sender, String[] args) { - if (args.length == 2) { - if (args[1].equals("*")) { - return refreshAll(sender); - } else { - Scoreboard scoreboard = getScoreboard(args[1]); - if (scoreboard != null) { - scoreboard.refreshView(this); - sender.sendMessage(rm.format("msg.scoreboard.refresh", args[1])); - return true; - } else { - sender.sendMessage(rm.format("error.scoreboard.notfound", args[1])); - return false; - } - } - } else if (args.length == 1) { - return refreshAll(sender); - } - return false; - } - - private boolean refreshAll(CommandSender sender) { + public boolean refreshAll(CommandSender sender) { for (Scoreboard scoreboard : scoreboards) { scoreboard.refreshView(this); } @@ -344,38 +161,7 @@ private boolean refreshAll(CommandSender sender) { return true; } - private boolean reloadConfig(CommandSender sender) { - reloadConfig(); - sender.sendMessage(rm.format("msg.reload")); - return true; - } - - private boolean saveConfig(CommandSender sender) { - saveConfig(); - sender.sendMessage(rm.format("msg.saved")); - return true; - } - - private boolean removeScoreboard(CommandSender sender, String[] args) { - if (args.length != 2) { - sender.sendMessage(rm.format("msg.usage.remove")); - return true; - } - String scoreName = args[1]; - Scoreboard scoreboard = getScoreboard(scoreName); - if (scoreboard == null) { - sender.sendMessage(rm.format("error.scoreboard.notfound", scoreName)); - return false; - } - if (removeScoreboard(scoreboard)) { - sender.sendMessage(rm.format("msg.scoreboard.removed", scoreName)); - saveConfig(); - return true; - } - return false; - } - - private boolean removeScoreboard(Scoreboard scoreboard) { + public boolean removeScoreboard(Scoreboard scoreboard) { synchronized (scoreboards) { BukkitTask bukkitTask = tasks.remove(scoreboard.getId()); if (bukkitTask != null) { @@ -386,7 +172,7 @@ private boolean removeScoreboard(Scoreboard scoreboard) { } } - private Scoreboard getScoreboard(String scoreName) { + public Scoreboard getScoreboard(String scoreName) { for (Scoreboard scoreboard : scoreboards) { if (scoreboard.getId().equals(scoreName)) { return scoreboard; @@ -395,66 +181,15 @@ private Scoreboard getScoreboard(String scoreName) { return null; } - private boolean showList(CommandSender sender) { - StringBuilder sb = new StringBuilder(); - if (scoreboards == null || scoreboards.isEmpty()) { - sb.append(rm.format("msg.scoreboards.empty")); - } else { - YamlConfiguration config = new YamlConfiguration(); - ConfigWriter.save(config, scoreboards); - sb.append(config.saveToString()); - } - sender.sendMessage(sb.toString().split("\n")); - return true; + public void addScoreboard(Scoreboard scoreboard) { + scoreboards.add(scoreboard); } - private boolean createScoreboard(CommandSender sender, String[] args) { - if (args.length < 5) { - sender.sendMessage(rm.format("msg.usage.create")); - return true; - } - String id = args[1]; - String refresh = args[2]; - int interval = TimeUtil.getTimeAsTicks(refresh); - if (interval < 200) { - sender.sendMessage(rm.format("error.wrong.interval")); - return false; - } - Scoreboard.Sender senderType; - try { - senderType = Scoreboard.Sender.valueOf(args[3].toUpperCase()); - } catch (IllegalArgumentException ignored) { - sender.sendMessage(rm.format("error.wrong.sender")); - return false; - } - int ix = 4; - Location location = LocationUtil.getLocation(args[ix]); - if (location == null) { - if (!(sender instanceof Player)) { - sender.sendMessage(rm.format("msg.usage.create.console")); - return true; - } else { - Player player = (Player) sender; - location = player.getEyeLocation(); - } - } else { - ix++; - } - String cmd = args[ix++]; - for (int i = ix; i < args.length; i++) { - cmd += " " + args[i]; - } - Scoreboard scoreboard = getScoreboard(id); - if (scoreboard != null) { - removeScoreboard(scoreboard); - } - scoreboard = new Scoreboard(id, refresh, senderType, cmd, location); - scoreboards.add(scoreboard); - YamlConfiguration config = new YamlConfiguration(); - ConfigWriter.save(config, scoreboard); - sender.sendMessage(rm.format("msg.scoreboard.created", id, config.saveToString()).split("\n")); - scheduleUpdater(scoreboard); - saveConfig(); - return true; + public ResourceManager getRM() { + return rm; + } + + public static Set getScoreboards() { + return scoreboards; } } diff --git a/src/main/java/dk/lockfuglsang/wolfencraft/commands/CreateCommand.java b/src/main/java/dk/lockfuglsang/wolfencraft/commands/CreateCommand.java new file mode 100644 index 0000000..126cd40 --- /dev/null +++ b/src/main/java/dk/lockfuglsang/wolfencraft/commands/CreateCommand.java @@ -0,0 +1,78 @@ +package dk.lockfuglsang.wolfencraft.commands; + +import dk.lockfuglsang.minecraft.command.AbstractCommand; +import dk.lockfuglsang.wolfencraft.HolographicScoreboard; +import dk.lockfuglsang.wolfencraft.config.ConfigWriter; +import dk.lockfuglsang.wolfencraft.config.Scoreboard; +import dk.lockfuglsang.wolfencraft.util.LocationUtil; +import dk.lockfuglsang.wolfencraft.util.ResourceManager; +import dk.lockfuglsang.wolfencraft.util.TimeUtil; +import org.bukkit.Location; +import org.bukkit.command.CommandSender; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; + +import java.util.Map; + +public class CreateCommand extends AbstractCommand { + + private final HolographicScoreboard plugin; + private final ResourceManager rm; + + public CreateCommand(HolographicScoreboard plugin) { + super("create|c", null, "id interval player|console cmd", "creates a hologram"); + this.plugin = plugin; + rm = plugin.getRM(); + } + + @Override + public boolean execute(CommandSender sender, String s, Map map, String... args) { + if (args.length < 4) { + sender.sendMessage(rm.format("msg.usage.create")); + return true; + } + String id = args[0]; + String refresh = args[1]; + int interval = TimeUtil.getTimeAsTicks(refresh); + if (interval < 200) { + sender.sendMessage(rm.format("error.wrong.interval")); + return false; + } + Scoreboard.Sender senderType; + try { + senderType = Scoreboard.Sender.valueOf(args[2].toUpperCase()); + } catch (IllegalArgumentException ignored) { + sender.sendMessage(rm.format("error.wrong.sender")); + return false; + } + int ix = 3; + Location location = LocationUtil.getLocation(args[ix]); + if (location == null) { + if (!(sender instanceof Player)) { + sender.sendMessage(rm.format("msg.usage.create.console")); + return true; + } else { + Player player = (Player) sender; + location = player.getEyeLocation(); + } + } else { + ix++; + } + String cmd = args[ix++]; + for (int i = ix; i < args.length; i++) { + cmd += " " + args[i]; + } + Scoreboard scoreboard = plugin.getScoreboard(id); + if (scoreboard != null) { + plugin.removeScoreboard(scoreboard); + } + scoreboard = new Scoreboard(id, refresh, senderType, cmd, location); + plugin.addScoreboard(scoreboard); + YamlConfiguration config = new YamlConfiguration(); + ConfigWriter.save(config, scoreboard); + sender.sendMessage(rm.format("msg.scoreboard.created", id, config.saveToString()).split("\n")); + plugin.scheduleUpdater(scoreboard); + plugin.saveConfig(); + return true; + } +} diff --git a/src/main/java/dk/lockfuglsang/wolfencraft/commands/EditCommand.java b/src/main/java/dk/lockfuglsang/wolfencraft/commands/EditCommand.java new file mode 100644 index 0000000..8a2de87 --- /dev/null +++ b/src/main/java/dk/lockfuglsang/wolfencraft/commands/EditCommand.java @@ -0,0 +1,88 @@ +package dk.lockfuglsang.wolfencraft.commands; + +import dk.lockfuglsang.minecraft.command.CompositeCommand; +import dk.lockfuglsang.wolfencraft.HolographicScoreboard; +import dk.lockfuglsang.wolfencraft.config.Scoreboard; +import dk.lockfuglsang.wolfencraft.util.LocationUtil; +import dk.lockfuglsang.wolfencraft.util.TimeUtil; +import org.bukkit.Location; +import org.bukkit.command.CommandSender; + +import java.util.List; +import java.util.Map; + +public class EditCommand extends CompositeCommand { + private final HolographicScoreboard plugin; + + public EditCommand(final HolographicScoreboard plugin) { + super("edit|e", null, "id", "edits a scoreboard"); + this.plugin = plugin; + add(new RequireScoreboardCommand(plugin, "filter", "reg-ex", "sets the filter") { + @Override + protected boolean doExecute(CommandSender sender, String alias, Map map, Scoreboard scoreboard, String... args) { + scoreboard.setFilter(args.length > 0 ? args[0] : null); + return true; + } + }); + add(new RequireScoreboardCommand(plugin, "addfilter", "reg-ex", "adds a filter") { + @Override + protected boolean doExecute(CommandSender sender, String alias, Map map, Scoreboard scoreboard, String... args) { + String value = args.length > 0 ? args[0] : null; + if (value != null) { + List filter = scoreboard.getFilter(); + filter.add(value); + scoreboard.setFilter(filter); + return true; + } else { + return false; + } + } + }); + add(new RequireScoreboardCommand(plugin, "location", "location", "sets the location of the scoreboard") { + @Override + protected boolean doExecute(CommandSender sender, String alias, Map map, Scoreboard scoreboard, String... args) { + String value = args.length > 0 ? args[0] : null; + Location location = LocationUtil.getLocation(value); + if (location == null) { + sender.sendMessage(plugin.getRM().format("error.wrong.location")); + return false; + } else { + scoreboard.setLocation(location); + } + return true; + } + }); + add(new RequireScoreboardCommand(plugin, "delay|interval", "interval", "sets the delay or interval of the scoreboard") { + @Override + protected boolean doExecute(CommandSender sender, String alias, Map map, Scoreboard scoreboard, String... args) { + String value = args.length > 0 ? args[0] : null; + int time = TimeUtil.getTimeAsTicks(value); + if (time == 0) { + sender.sendMessage(plugin.getRM().format("error.wrong." + alias)); + return false; + } else if (alias.equals("delay")) { + scoreboard.setDelay(value); + } else if (alias.equals("interval")) { + scoreboard.setInterval(value); + } + return true; + } + }); + } + + @Override + public boolean execute(CommandSender sender, String alias, Map data, String... args) { + String scoreName = args.length > 0 ? args[0] : ""; + Scoreboard scoreboard = plugin.getScoreboard(scoreName); + if (scoreboard != null) { + data.put("scoreboard", scoreboard); + if (super.execute(sender, alias, data, args) && args.length > 2) { + sender.sendMessage(plugin.getRM().format("msg.scoreboard.edit", args[1], scoreName, args[2])); + return true; + } + return false; + } + sender.sendMessage(plugin.getRM().format("error.scoreboard.notfound", scoreName)); + return false; + } +} diff --git a/src/main/java/dk/lockfuglsang/wolfencraft/commands/HGSCommand.java b/src/main/java/dk/lockfuglsang/wolfencraft/commands/HGSCommand.java new file mode 100644 index 0000000..fa0d0d3 --- /dev/null +++ b/src/main/java/dk/lockfuglsang/wolfencraft/commands/HGSCommand.java @@ -0,0 +1,53 @@ +package dk.lockfuglsang.wolfencraft.commands; + +import dk.lockfuglsang.minecraft.command.AbstractCommandExecutor; +import dk.lockfuglsang.minecraft.command.completion.AbstractTabCompleter; +import dk.lockfuglsang.wolfencraft.HolographicScoreboard; +import dk.lockfuglsang.wolfencraft.config.Scoreboard; +import org.bukkit.command.CommandSender; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/** + * Commands from the uSkyBlock common bukkit utils + */ +public class HGSCommand extends AbstractCommandExecutor { + public HGSCommand(final HolographicScoreboard plugin) { + super("hgs", "holographicscoreboard.admin", "main hgs command"); + addTab("id", new AbstractTabCompleter() { + @Override + protected List getTabList(CommandSender commandSender, String s) { + List ids = new ArrayList<>(); + for (Scoreboard scoreboard : plugin.getScoreboards()) { + ids.add(scoreboard.getId()); + } + Collections.sort(ids); + return ids; + } + }); + addTab("player|console", new AbstractTabCompleter() { + @Override + protected List getTabList(CommandSender commandSender, String s) { + return Arrays.asList("console", "player"); + } + }); + addTab("interval", new AbstractTabCompleter() { + @Override + protected List getTabList(CommandSender commandSender, String s) { + return Arrays.asList("10s", "30s", "5m", "10m", "30m", "1h"); + } + }); + add(new CreateCommand(plugin)); + add(new ListCommand(plugin)); + add(new RemoveCommand(plugin)); + add(new MoveCommand(plugin)); + add(new RefreshCommand(plugin)); + add(new InfoCommand(plugin)); + add(new SaveCommand(plugin)); + add(new ReloadCommand(plugin)); + add(new EditCommand(plugin)); + } +} diff --git a/src/main/java/dk/lockfuglsang/wolfencraft/commands/InfoCommand.java b/src/main/java/dk/lockfuglsang/wolfencraft/commands/InfoCommand.java new file mode 100644 index 0000000..d23c2b3 --- /dev/null +++ b/src/main/java/dk/lockfuglsang/wolfencraft/commands/InfoCommand.java @@ -0,0 +1,31 @@ +package dk.lockfuglsang.wolfencraft.commands; + +import dk.lockfuglsang.minecraft.command.AbstractCommand; +import dk.lockfuglsang.wolfencraft.HolographicScoreboard; +import dk.lockfuglsang.wolfencraft.config.ConfigWriter; +import dk.lockfuglsang.wolfencraft.config.Scoreboard; +import org.bukkit.command.CommandSender; +import org.bukkit.configuration.file.YamlConfiguration; + +import java.util.Map; + +public class InfoCommand extends AbstractCommand { + private final HolographicScoreboard plugin; + + public InfoCommand(HolographicScoreboard plugin) { + super("info|i", null, "id", "shows information about a scoreboard"); + this.plugin = plugin; + } + + @Override + public boolean execute(CommandSender sender, String s, Map map, String... args) { + Scoreboard scoreboard = plugin.getScoreboard(args != null && args.length > 0 ? args[0] : null); + if (scoreboard != null) { + YamlConfiguration c = new YamlConfiguration(); + ConfigWriter.save(c, scoreboard); + sender.sendMessage(c.saveToString()); + return true; + } + return false; + } +} diff --git a/src/main/java/dk/lockfuglsang/wolfencraft/commands/ListCommand.java b/src/main/java/dk/lockfuglsang/wolfencraft/commands/ListCommand.java new file mode 100644 index 0000000..5a6d02a --- /dev/null +++ b/src/main/java/dk/lockfuglsang/wolfencraft/commands/ListCommand.java @@ -0,0 +1,37 @@ +package dk.lockfuglsang.wolfencraft.commands; + +import dk.lockfuglsang.minecraft.command.AbstractCommand; +import dk.lockfuglsang.wolfencraft.HolographicScoreboard; +import dk.lockfuglsang.wolfencraft.config.Scoreboard; +import org.bukkit.command.CommandSender; + +import java.util.Map; +import java.util.Set; + +public class ListCommand extends AbstractCommand { + private static final String[] STRIPES = {"\u00a77", "\u00a7f"}; + private final HolographicScoreboard plugin; + + public ListCommand(HolographicScoreboard plugin) { + super("list", "lists the holograms"); + this.plugin = plugin; + } + + @Override + public boolean execute(CommandSender sender, String s, Map map, String... args) { + StringBuilder sb = new StringBuilder(); + Set scoreboards = plugin.getScoreboards(); + if (scoreboards == null || scoreboards.isEmpty()) { + sb.append(plugin.getRM().format("msg.scoreboards.empty")); + } else { + int cnt = 0; + for (Scoreboard scoreboard : scoreboards) { + sb.append(STRIPES[(cnt++ % 2)]); + sb.append(scoreboard.getId()); + sb.append(" "); + } + sender.sendMessage(sb.toString().trim()); + } + return true; + } +} diff --git a/src/main/java/dk/lockfuglsang/wolfencraft/commands/MoveCommand.java b/src/main/java/dk/lockfuglsang/wolfencraft/commands/MoveCommand.java new file mode 100644 index 0000000..fa1fd72 --- /dev/null +++ b/src/main/java/dk/lockfuglsang/wolfencraft/commands/MoveCommand.java @@ -0,0 +1,54 @@ +package dk.lockfuglsang.wolfencraft.commands; + +import dk.lockfuglsang.minecraft.command.AbstractCommand; +import dk.lockfuglsang.wolfencraft.HolographicScoreboard; +import dk.lockfuglsang.wolfencraft.config.Scoreboard; +import dk.lockfuglsang.wolfencraft.util.LocationUtil; +import dk.lockfuglsang.wolfencraft.util.ResourceManager; +import org.bukkit.Location; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.util.Map; + +public class MoveCommand extends AbstractCommand { + private final HolographicScoreboard plugin; + private final ResourceManager rm; + + public MoveCommand(HolographicScoreboard plugin) { + super("move|mv", null, "id ?location", "moves a scoreboard"); + this.plugin = plugin; + rm = plugin.getRM(); + } + + @Override + public boolean execute(CommandSender sender, String s, Map map, String... args) { + if (args == null || args.length == 0) { + sender.sendMessage(rm.format("msg.usage.move")); + return true; + } + Scoreboard scoreboard = plugin.getScoreboard(args[0]); + if (scoreboard != null) { + Location location = null; + try { + if (args.length == 1 && sender instanceof Player) { + location = ((Player) sender).getEyeLocation(); + } else if (args.length == 2) { + location = LocationUtil.getLocation(args[1]); + } + if (location == null) { + throw new IllegalArgumentException("No valid location was found"); + } + } catch (IllegalArgumentException e) { + sender.sendMessage(rm.format("msg.usage.move")); + return true; + } + scoreboard.setLocation(location); + scoreboard.refreshView(plugin); + sender.sendMessage(rm.format("msg.scoreboard.moved", args[1], location.getX(), location.getY(), location.getZ(), location.getWorld().getName())); + return true; + } + sender.sendMessage(rm.format("error.scoreboard.notfound", args[1])); + return false; + } +} diff --git a/src/main/java/dk/lockfuglsang/wolfencraft/commands/RefreshCommand.java b/src/main/java/dk/lockfuglsang/wolfencraft/commands/RefreshCommand.java new file mode 100644 index 0000000..c870871 --- /dev/null +++ b/src/main/java/dk/lockfuglsang/wolfencraft/commands/RefreshCommand.java @@ -0,0 +1,42 @@ +package dk.lockfuglsang.wolfencraft.commands; + +import dk.lockfuglsang.minecraft.command.AbstractCommand; +import dk.lockfuglsang.wolfencraft.HolographicScoreboard; +import dk.lockfuglsang.wolfencraft.config.Scoreboard; +import dk.lockfuglsang.wolfencraft.util.ResourceManager; +import org.bukkit.command.CommandSender; + +import java.util.Map; + +public class RefreshCommand extends AbstractCommand { + private final HolographicScoreboard plugin; + private final ResourceManager rm; + + public RefreshCommand(HolographicScoreboard plugin) { + super("refresh", null, "?id", "refreshes all or specific scoreboards"); + this.plugin = plugin; + rm = plugin.getRM(); + } + + @Override + public boolean execute(CommandSender sender, String s, Map map, String... args) { + if (args.length == 1) { + if (args[0].equals("*")) { + return plugin.refreshAll(sender); + } else { + Scoreboard scoreboard = plugin.getScoreboard(args[0]); + if (scoreboard != null) { + scoreboard.refreshView(plugin); + sender.sendMessage(rm.format("msg.scoreboard.refresh", args[0])); + return true; + } else { + sender.sendMessage(rm.format("error.scoreboard.notfound", args[0])); + return false; + } + } + } else if (args.length == 0) { + return plugin.refreshAll(sender); + } + return false; + } +} diff --git a/src/main/java/dk/lockfuglsang/wolfencraft/commands/ReloadCommand.java b/src/main/java/dk/lockfuglsang/wolfencraft/commands/ReloadCommand.java new file mode 100644 index 0000000..54fa635 --- /dev/null +++ b/src/main/java/dk/lockfuglsang/wolfencraft/commands/ReloadCommand.java @@ -0,0 +1,23 @@ +package dk.lockfuglsang.wolfencraft.commands; + +import dk.lockfuglsang.minecraft.command.AbstractCommand; +import dk.lockfuglsang.wolfencraft.HolographicScoreboard; +import org.bukkit.command.CommandSender; + +import java.util.Map; + +public class ReloadCommand extends AbstractCommand { + private final HolographicScoreboard plugin; + + public ReloadCommand(HolographicScoreboard plugin) { + super("reload", "reloads the config"); + this.plugin = plugin; + } + + @Override + public boolean execute(CommandSender sender, String s, Map map, String... strings) { + plugin.reloadConfig(); + sender.sendMessage(plugin.getRM().format("msg.reload")); + return true; + } +} diff --git a/src/main/java/dk/lockfuglsang/wolfencraft/commands/RemoveCommand.java b/src/main/java/dk/lockfuglsang/wolfencraft/commands/RemoveCommand.java new file mode 100644 index 0000000..ee04f95 --- /dev/null +++ b/src/main/java/dk/lockfuglsang/wolfencraft/commands/RemoveCommand.java @@ -0,0 +1,40 @@ +package dk.lockfuglsang.wolfencraft.commands; + +import dk.lockfuglsang.minecraft.command.AbstractCommand; +import dk.lockfuglsang.wolfencraft.HolographicScoreboard; +import dk.lockfuglsang.wolfencraft.config.Scoreboard; +import dk.lockfuglsang.wolfencraft.util.ResourceManager; +import org.bukkit.command.CommandSender; + +import java.util.Map; + +public class RemoveCommand extends AbstractCommand { + private final HolographicScoreboard plugin; + private final ResourceManager rm; + + public RemoveCommand(HolographicScoreboard plugin) { + super("remove|rm", null, "id", "removes a scoreboard"); + this.plugin = plugin; + rm = plugin.getRM(); + } + + @Override + public boolean execute(CommandSender sender, String s, Map map, String... args) { + if (args.length != 1) { + sender.sendMessage(rm.format("msg.usage.remove")); + return true; + } + String scoreName = args[0]; + Scoreboard scoreboard = plugin.getScoreboard(scoreName); + if (scoreboard == null) { + sender.sendMessage(rm.format("error.scoreboard.notfound", scoreName)); + return false; + } + if (plugin.removeScoreboard(scoreboard)) { + sender.sendMessage(rm.format("msg.scoreboard.removed", scoreName)); + plugin.saveConfig(); + return true; + } + return false; + } +} diff --git a/src/main/java/dk/lockfuglsang/wolfencraft/commands/RequireScoreboardCommand.java b/src/main/java/dk/lockfuglsang/wolfencraft/commands/RequireScoreboardCommand.java new file mode 100644 index 0000000..ba226a1 --- /dev/null +++ b/src/main/java/dk/lockfuglsang/wolfencraft/commands/RequireScoreboardCommand.java @@ -0,0 +1,28 @@ +package dk.lockfuglsang.wolfencraft.commands; + +import dk.lockfuglsang.minecraft.command.AbstractCommand; +import dk.lockfuglsang.wolfencraft.HolographicScoreboard; +import dk.lockfuglsang.wolfencraft.config.Scoreboard; +import org.bukkit.command.CommandSender; + +import java.util.Map; + +public abstract class RequireScoreboardCommand extends AbstractCommand { + private final HolographicScoreboard plugin; + + public RequireScoreboardCommand(HolographicScoreboard plugin, String name, String parms, String description) { + super(name, null, parms, description); + this.plugin = plugin; + } + + @Override + public final boolean execute(CommandSender sender, String alias, Map map, String... args) { + Object scoreboard = map.get("scoreboard"); + if (!(scoreboard instanceof Scoreboard)) { + return false; + } + return doExecute(sender, alias, map, (Scoreboard) scoreboard, args); + } + + protected abstract boolean doExecute(CommandSender sender, String alias, Map map, Scoreboard scoreboard, String... args); +} diff --git a/src/main/java/dk/lockfuglsang/wolfencraft/commands/SaveCommand.java b/src/main/java/dk/lockfuglsang/wolfencraft/commands/SaveCommand.java new file mode 100644 index 0000000..d979d58 --- /dev/null +++ b/src/main/java/dk/lockfuglsang/wolfencraft/commands/SaveCommand.java @@ -0,0 +1,23 @@ +package dk.lockfuglsang.wolfencraft.commands; + +import dk.lockfuglsang.minecraft.command.AbstractCommand; +import dk.lockfuglsang.wolfencraft.HolographicScoreboard; +import org.bukkit.command.CommandSender; + +import java.util.Map; + +public class SaveCommand extends AbstractCommand { + private final HolographicScoreboard plugin; + + public SaveCommand(HolographicScoreboard plugin) { + super("save", "saves the scoreboards to the config"); + this.plugin = plugin; + } + + @Override + public boolean execute(CommandSender sender, String s, Map map, String... strings) { + plugin.saveConfig(); + sender.sendMessage(plugin.getRM().format("msg.saved")); + return true; + } +} diff --git a/src/main/java/dk/lockfuglsang/wolfencraft/config/Scoreboard.java b/src/main/java/dk/lockfuglsang/wolfencraft/config/Scoreboard.java index 8d2ab05..8f4a611 100644 --- a/src/main/java/dk/lockfuglsang/wolfencraft/config/Scoreboard.java +++ b/src/main/java/dk/lockfuglsang/wolfencraft/config/Scoreboard.java @@ -158,12 +158,11 @@ private BufferedSender createBufferedSender(final Plugin plugin) { } else { Player nearestPlayer = LocationUtil.getNearestPlayer(location); if (nearestPlayer == null) { - nearestPlayer = Bukkit.getOnlinePlayers().length > 0 ? Bukkit.getOnlinePlayers()[0] : null; + nearestPlayer = !Bukkit.getOnlinePlayers().isEmpty() ? Bukkit.getOnlinePlayers().iterator().next() : null; } if (nearestPlayer != null) { // TODO: This would be "the best" solution currently, but not possible atm (1.7.9). - //bufferedSender = new BufferedPlayerSender(nearestPlayer); - return new ProxyPlayer(nearestPlayer); + return new BufferedPlayerSender(nearestPlayer); } } return null; diff --git a/src/main/java/dk/lockfuglsang/wolfencraft/util/ProxyPlayer.java b/src/main/java/dk/lockfuglsang/wolfencraft/util/ProxyPlayer.java deleted file mode 100644 index b50c8e9..0000000 --- a/src/main/java/dk/lockfuglsang/wolfencraft/util/ProxyPlayer.java +++ /dev/null @@ -1,1193 +0,0 @@ -package dk.lockfuglsang.wolfencraft.util; - -import org.bukkit.*; -import org.bukkit.block.Block; -import org.bukkit.command.CommandSender; -import org.bukkit.conversations.Conversation; -import org.bukkit.conversations.ConversationAbandonedEvent; -import org.bukkit.entity.*; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent; -import org.bukkit.inventory.*; -import org.bukkit.map.MapView; -import org.bukkit.metadata.MetadataValue; -import org.bukkit.permissions.Permission; -import org.bukkit.permissions.PermissionAttachment; -import org.bukkit.permissions.PermissionAttachmentInfo; -import org.bukkit.plugin.Plugin; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; -import org.bukkit.scoreboard.Scoreboard; -import org.bukkit.util.Vector; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.io.UnsupportedEncodingException; -import java.net.InetSocketAddress; -import java.util.*; - -/** - * Stupid Proxy object, only needed until BufferedPlayerSender works again - * - * @see dk.lockfuglsang.wolfencraft.util.BufferedPlayerSender - */ -public class ProxyPlayer implements Player, BufferedSender { - private ByteArrayOutputStream baos = new ByteArrayOutputStream(); - private PrintStream ps; - private Player player; - - public ProxyPlayer(Player player) { - this.player = player; - try { - ps = new PrintStream(baos, true, "UTF-8"); - } catch (UnsupportedEncodingException e) { - throw new IllegalStateException("WTH! Your operating system doesn't support UTF-8, get real!"); - } - } - - @Override - public String getStdout() { - try { - return baos.toString("UTF-8"); - } catch (UnsupportedEncodingException e) { - throw new IllegalStateException("WTH! Your operating system doesn't support UTF-8, get real!"); - } - } - - @Override - public CommandSender getSender() { - return this; - } - - @Override - public void sendMessage(String s) { - ps.println(s); - } - - @Override - public void sendMessage(String[] strings) { - for (String s : strings) { - ps.println(s); - } - } - - @Override - public void sendRawMessage(String s) { - ps.println(s); - } - - // ------------------------------------------------------------------------ - // STUPID CODE BELOW - // ------------------------------------------------------------------------ - @Override - public String getDisplayName() { - return player.getDisplayName(); - } - - @Override - public void setDisplayName(String s) { - player.setDisplayName(s); - } - - @Override - public String getPlayerListName() { - return player.getPlayerListName(); - } - - @Override - public void setPlayerListName(String s) { - player.setPlayerListName(s); - } - - @Override - public void setCompassTarget(Location location) { - player.setCompassTarget(location); - } - - @Override - public Location getCompassTarget() { - return player.getCompassTarget(); - } - - @Override - public InetSocketAddress getAddress() { - return player.getAddress(); - } - - @Override - public boolean isConversing() { - return player.isConversing(); - } - - @Override - public void acceptConversationInput(String s) { - player.acceptConversationInput(s); - } - - @Override - public boolean beginConversation(Conversation conversation) { - return player.beginConversation(conversation); - } - - @Override - public void abandonConversation(Conversation conversation) { - player.abandonConversation(conversation); - } - - @Override - public void abandonConversation(Conversation conversation, ConversationAbandonedEvent conversationAbandonedEvent) { - player.abandonConversation(conversation, conversationAbandonedEvent); - } - - @Override - public void kickPlayer(String s) { - player.kickPlayer(s); - } - - @Override - public void chat(String s) { - player.chat(s); - } - - @Override - public boolean performCommand(String s) { - return false; - } - - @Override - public boolean isSneaking() { - return player.isSneaking(); - } - - @Override - public void setSneaking(boolean b) { - } - - @Override - public boolean isSprinting() { - return player.isSprinting(); - } - - @Override - public void setSprinting(boolean b) { - } - - @Override - public void saveData() { - player.saveData(); - } - - @Override - public void loadData() { - player.loadData(); - } - - @Override - public void setSleepingIgnored(boolean b) { - } - - @Override - public boolean isSleepingIgnored() { - return player.isSleepingIgnored(); - } - - @Override - public void playNote(Location location, byte b, byte b2) { - } - - @Override - public void playNote(Location location, Instrument instrument, Note note) { - } - - @Override - public void playSound(Location location, Sound sound, float v, float v2) { - } - - @Override - public void playSound(Location location, String s, float v, float v2) { - } - - @Override - public void playEffect(Location location, Effect effect, int i) { - } - - @Override - public void playEffect(Location location, Effect effect, T t) { - } - - @Override - public void sendBlockChange(Location location, Material material, byte b) { - } - - @Override - public boolean sendChunkChange(Location location, int i, int i2, int i3, byte[] bytes) { - return false; - } - - @Override - public void sendBlockChange(Location location, int i, byte b) { - } - - @Override - public void sendSignChange(Location location, String[] strings) throws IllegalArgumentException { - } - - @Override - public void sendMap(MapView mapView) { - } - - @Override - public void updateInventory() { - player.updateInventory(); - } - - @Override - public void awardAchievement(Achievement achievement) { - } - - @Override - public void removeAchievement(Achievement achievement) { - } - - @Override - public boolean hasAchievement(Achievement achievement) { - return player.hasAchievement(achievement); - } - - @Override - public void incrementStatistic(Statistic statistic) throws IllegalArgumentException { - } - - @Override - public void decrementStatistic(Statistic statistic) throws IllegalArgumentException { - } - - @Override - public void incrementStatistic(Statistic statistic, int i) throws IllegalArgumentException { - } - - @Override - public void decrementStatistic(Statistic statistic, int i) throws IllegalArgumentException { - } - - @Override - public void setStatistic(Statistic statistic, int i) throws IllegalArgumentException { - } - - @Override - public int getStatistic(Statistic statistic) throws IllegalArgumentException { - return 0; - } - - @Override - public void incrementStatistic(Statistic statistic, Material material) throws IllegalArgumentException { - } - - @Override - public void decrementStatistic(Statistic statistic, Material material) throws IllegalArgumentException { - } - - @Override - public int getStatistic(Statistic statistic, Material material) throws IllegalArgumentException { - return 0; - } - - @Override - public void incrementStatistic(Statistic statistic, Material material, int i) throws IllegalArgumentException { - } - - @Override - public void decrementStatistic(Statistic statistic, Material material, int i) throws IllegalArgumentException { - } - - @Override - public void setStatistic(Statistic statistic, Material material, int i) throws IllegalArgumentException { - } - - @Override - public void incrementStatistic(Statistic statistic, EntityType entityType) throws IllegalArgumentException { - } - - @Override - public void decrementStatistic(Statistic statistic, EntityType entityType) throws IllegalArgumentException { - } - - @Override - public int getStatistic(Statistic statistic, EntityType entityType) throws IllegalArgumentException { - return 0; - } - - @Override - public void incrementStatistic(Statistic statistic, EntityType entityType, int i) throws IllegalArgumentException { - } - - @Override - public void decrementStatistic(Statistic statistic, EntityType entityType, int i) { - } - - @Override - public void setStatistic(Statistic statistic, EntityType entityType, int i) { - } - - @Override - public void setPlayerTime(long l, boolean b) { - } - - @Override - public long getPlayerTime() { - return player.getPlayerTime(); - } - - @Override - public long getPlayerTimeOffset() { - return player.getPlayerTimeOffset(); - } - - @Override - public boolean isPlayerTimeRelative() { - return player.isPlayerTimeRelative(); - } - - @Override - public void resetPlayerTime() { - player.resetPlayerTime(); - } - - @Override - public void setPlayerWeather(WeatherType weatherType) { - } - - @Override - public WeatherType getPlayerWeather() { - return player.getPlayerWeather(); - } - - @Override - public void resetPlayerWeather() { - player.resetPlayerWeather(); - } - - @Override - public void giveExp(int i) { - } - - @Override - public void giveExpLevels(int i) { - } - - @Override - public float getExp() { - return player.getExp(); - } - - @Override - public void setExp(float v) { - } - - @Override - public int getLevel() { - return player.getLevel(); - } - - @Override - public void setLevel(int i) { - } - - @Override - public int getTotalExperience() { - return player.getTotalExperience(); - } - - @Override - public void setTotalExperience(int i) { - } - - @Override - public float getExhaustion() { - return player.getExhaustion(); - } - - @Override - public void setExhaustion(float v) { - } - - @Override - public float getSaturation() { - return player.getSaturation(); - } - - @Override - public void setSaturation(float v) { - } - - @Override - public int getFoodLevel() { - return player.getFoodLevel(); - } - - @Override - public void setFoodLevel(int i) { - } - - @Override - public Location getBedSpawnLocation() { - return player.getBedSpawnLocation(); - } - - @Override - public void setBedSpawnLocation(Location location) { - } - - @Override - public void setBedSpawnLocation(Location location, boolean b) { - } - - @Override - public boolean getAllowFlight() { - return false; - } - - @Override - public void setAllowFlight(boolean b) { - } - - @Override - public void hidePlayer(Player player) { - } - - @Override - public void showPlayer(Player player) { - } - - @Override - public boolean canSee(Player player) { - return false; - } - - @Override - public Location getLocation() { - return player.getLocation(); - } - - @Override - public Location getLocation(Location location) { - return null; - } - - @Override - public void setVelocity(Vector vector) { - } - - @Override - public Vector getVelocity() { - return player.getVelocity(); - } - - @Override - public boolean isOnGround() { - return player.isOnGround(); - } - - @Override - public World getWorld() { - return player.getWorld(); - } - - @Override - public boolean teleport(Location location) { - return false; - } - - @Override - public boolean teleport(Location location, PlayerTeleportEvent.TeleportCause teleportCause) { - return false; - } - - @Override - public boolean teleport(Entity entity) { - return false; - } - - @Override - public boolean teleport(Entity entity, PlayerTeleportEvent.TeleportCause teleportCause) { - return false; - } - - @Override - public List getNearbyEntities(double v, double v2, double v3) { - return null; - } - - @Override - public int getEntityId() { - return player.getEntityId(); - } - - @Override - public int getFireTicks() { - return player.getFireTicks(); - } - - @Override - public int getMaxFireTicks() { - return player.getMaxFireTicks(); - } - - @Override - public void setFireTicks(int i) { - } - - @Override - public void remove() { - player.remove(); - } - - @Override - public boolean isDead() { - return player.isDead(); - } - - @Override - public boolean isValid() { - return player.isValid(); - } - - @Override - public Server getServer() { - return player.getServer(); - } - - @Override - public Entity getPassenger() { - return player.getPassenger(); - } - - @Override - public boolean setPassenger(Entity entity) { - return false; - } - - @Override - public boolean isEmpty() { - return player.isEmpty(); - } - - @Override - public boolean eject() { - return false; - } - - @Override - public float getFallDistance() { - return player.getFallDistance(); - } - - @Override - public void setFallDistance(float v) { - } - - @Override - public void setLastDamageCause(EntityDamageEvent entityDamageEvent) { - } - - @Override - public EntityDamageEvent getLastDamageCause() { - return player.getLastDamageCause(); - } - - @Override - public UUID getUniqueId() { - return player.getUniqueId(); - } - - @Override - public boolean isBanned() { - return player.isBanned(); - } - - @Override - public void setBanned(boolean b) { - } - - @Override - public boolean isWhitelisted() { - return player.isWhitelisted(); - } - - @Override - public void setWhitelisted(boolean b) { - } - - @Override - public Player getPlayer() { - return player.getPlayer(); - } - - @Override - public long getFirstPlayed() { - return player.getFirstPlayed(); - } - - @Override - public long getLastPlayed() { - return player.getLastPlayed(); - } - - @Override - public boolean hasPlayedBefore() { - return player.hasPlayedBefore(); - } - - @Override - public int getTicksLived() { - return player.getTicksLived(); - } - - @Override - public void setTicksLived(int i) { - } - - @Override - public void playEffect(EntityEffect entityEffect) { - } - - @Override - public EntityType getType() { - return player.getType(); - } - - @Override - public boolean isInsideVehicle() { - return player.isInsideVehicle(); - } - - @Override - public boolean leaveVehicle() { - return false; - } - - @Override - public Entity getVehicle() { - return player.getVehicle(); - } - - @Override - public boolean isFlying() { - return player.isFlying(); - } - - @Override - public void setFlying(boolean b) { - } - - @Override - public void setFlySpeed(float v) throws IllegalArgumentException { - } - - @Override - public void setWalkSpeed(float v) throws IllegalArgumentException { - } - - @Override - public float getFlySpeed() { - return player.getFlySpeed(); - } - - @Override - public float getWalkSpeed() { - return player.getWalkSpeed(); - } - - @Override - public void setTexturePack(String s) { - } - - @Override - public void setResourcePack(String s) { - } - - @Override - public Scoreboard getScoreboard() { - return player.getScoreboard(); - } - - @Override - public void setScoreboard(Scoreboard scoreboard) throws IllegalArgumentException, IllegalStateException { - } - - @Override - public boolean isHealthScaled() { - return player.isHealthScaled(); - } - - @Override - public void setHealthScaled(boolean b) { - } - - @Override - public void setHealthScale(double v) throws IllegalArgumentException { - } - - @Override - public double getHealthScale() { - return player.getHealthScale(); - } - - @Override - public Map serialize() { - return null; - } - - @Override - public boolean isOnline() { - return player.isOnline(); - } - - @Override - public String getName() { - return player.getName(); - } - - @Override - public PlayerInventory getInventory() { - return player.getInventory(); - } - - @Override - public Inventory getEnderChest() { - return player.getEnderChest(); - } - - @Override - public boolean setWindowProperty(InventoryView.Property property, int i) { - return false; - } - - @Override - public InventoryView getOpenInventory() { - return player.getOpenInventory(); - } - - @Override - public InventoryView openInventory(Inventory itemStacks) { - return null; - } - - @Override - public InventoryView openWorkbench(Location location, boolean b) { - return null; - } - - @Override - public InventoryView openEnchanting(Location location, boolean b) { - return null; - } - - @Override - public void openInventory(InventoryView inventoryView) { - } - - @Override - public void closeInventory() { - player.closeInventory(); - } - - @Override - public ItemStack getItemInHand() { - return player.getItemInHand(); - } - - @Override - public void setItemInHand(ItemStack itemStack) { - } - - @Override - public ItemStack getItemOnCursor() { - return player.getItemOnCursor(); - } - - @Override - public void setItemOnCursor(ItemStack itemStack) { - } - - @Override - public boolean isSleeping() { - return player.isSleeping(); - } - - @Override - public int getSleepTicks() { - return player.getSleepTicks(); - } - - @Override - public GameMode getGameMode() { - return player.getGameMode(); - } - - @Override - public void setGameMode(GameMode gameMode) { - } - - @Override - public boolean isBlocking() { - return player.isBlocking(); - } - - @Override - public int getExpToLevel() { - return player.getExpToLevel(); - } - - @Override - public double getEyeHeight() { - return player.getEyeHeight(); - } - - @Override - public double getEyeHeight(boolean b) { - return 0; - } - - @Override - public Location getEyeLocation() { - return player.getEyeLocation(); - } - - @Override - public List getLineOfSight(HashSet bytes, int i) { - return null; - } - - @Override - public Block getTargetBlock(HashSet bytes, int i) { - return null; - } - - @Override - public List getLastTwoTargetBlocks(HashSet bytes, int i) { - return null; - } - - @Override - public Egg throwEgg() { - return null; - } - - @Override - public Snowball throwSnowball() { - return null; - } - - @Override - public Arrow shootArrow() { - return null; - } - - @Override - public int getRemainingAir() { - return player.getRemainingAir(); - } - - @Override - public void setRemainingAir(int i) { - } - - @Override - public int getMaximumAir() { - return player.getMaximumAir(); - } - - @Override - public void setMaximumAir(int i) { - } - - @Override - public int getMaximumNoDamageTicks() { - return player.getMaximumNoDamageTicks(); - } - - @Override - public void setMaximumNoDamageTicks(int i) { - } - - @Override - public double getLastDamage() { - return player.getLastDamage(); - } - - @Override - public int _INVALID_getLastDamage() { - return player._INVALID_getLastDamage(); - } - - @Override - public void setLastDamage(double v) { - } - - @Override - public void _INVALID_setLastDamage(int i) { - } - - @Override - public int getNoDamageTicks() { - return player.getNoDamageTicks(); - } - - @Override - public void setNoDamageTicks(int i) { - } - - @Override - public Player getKiller() { - return player.getKiller(); - } - - @Override - public boolean addPotionEffect(PotionEffect potionEffect) { - return false; - } - - @Override - public boolean addPotionEffect(PotionEffect potionEffect, boolean b) { - return false; - } - - @Override - public boolean addPotionEffects(Collection potionEffects) { - return false; - } - - @Override - public boolean hasPotionEffect(PotionEffectType potionEffectType) { - return player.hasPotionEffect(potionEffectType); - } - - @Override - public void removePotionEffect(PotionEffectType potionEffectType) { - } - - @Override - public Collection getActivePotionEffects() { - return player.getActivePotionEffects(); - } - - @Override - public boolean hasLineOfSight(Entity entity) { - return player.hasLineOfSight(entity); - } - - @Override - public boolean getRemoveWhenFarAway() { - return false; - } - - @Override - public void setRemoveWhenFarAway(boolean b) { - } - - @Override - public EntityEquipment getEquipment() { - return player.getEquipment(); - } - - @Override - public void setCanPickupItems(boolean b) { - } - - @Override - public boolean getCanPickupItems() { - return false; - } - - @Override - public void setCustomName(String s) { - } - - @Override - public String getCustomName() { - return player.getCustomName(); - } - - @Override - public void setCustomNameVisible(boolean b) { - } - - @Override - public boolean isCustomNameVisible() { - return player.isCustomNameVisible(); - } - - @Override - public boolean isLeashed() { - return player.isLeashed(); - } - - @Override - public Entity getLeashHolder() throws IllegalStateException { - return null; - } - - @Override - public boolean setLeashHolder(Entity entity) { - return false; - } - - @Override - public void damage(double v) { - } - - @Override - public void _INVALID_damage(int i) { - } - - @Override - public void damage(double v, Entity entity) { - } - - @Override - public void _INVALID_damage(int i, Entity entity) { - } - - @Override - public double getHealth() { - return player.getHealth(); - } - - @Override - public int _INVALID_getHealth() { - return player._INVALID_getHealth(); - } - - @Override - public void setHealth(double v) { - } - - @Override - public void _INVALID_setHealth(int i) { - } - - @Override - public double getMaxHealth() { - return player.getMaxHealth(); - } - - @Override - public int _INVALID_getMaxHealth() { - return player._INVALID_getMaxHealth(); - } - - @Override - public void setMaxHealth(double v) { - } - - @Override - public void _INVALID_setMaxHealth(int i) { - } - - @Override - public void resetMaxHealth() { - player.resetMaxHealth(); - } - - @Override - public void setMetadata(String s, MetadataValue metadataValue) { - } - - @Override - public List getMetadata(String s) { - return null; - } - - @Override - public boolean hasMetadata(String s) { - return false; - } - - @Override - public void removeMetadata(String s, Plugin plugin) { - } - - @Override - public boolean isPermissionSet(String s) { - return player.isPermissionSet(s); - } - - @Override - public boolean isPermissionSet(Permission permission) { - return player.isPermissionSet(permission); - } - - @Override - public boolean hasPermission(String s) { - return player.hasPermission(s); - } - - @Override - public boolean hasPermission(Permission permission) { - return player.hasPermission(permission); - } - - @Override - public PermissionAttachment addAttachment(Plugin plugin, String s, boolean b) { - return null; - } - - @Override - public PermissionAttachment addAttachment(Plugin plugin) { - return null; - } - - @Override - public PermissionAttachment addAttachment(Plugin plugin, String s, boolean b, int i) { - return null; - } - - @Override - public PermissionAttachment addAttachment(Plugin plugin, int i) { - return null; - } - - @Override - public void removeAttachment(PermissionAttachment permissionAttachment) { - } - - @Override - public void recalculatePermissions() { - player.recalculatePermissions(); - } - - @Override - public Set getEffectivePermissions() { - return player.getEffectivePermissions(); - } - - @Override - public void sendPluginMessage(Plugin plugin, String s, byte[] bytes) { - } - - @Override - public Set getListeningPluginChannels() { - return player.getListeningPluginChannels(); - } - - @Override - public T launchProjectile(Class aClass) { - return null; - } - - @Override - public T launchProjectile(Class aClass, Vector vector) { - return null; - } - - @Override - public boolean isOp() { - return player.isOp(); - } - - @Override - public void setOp(boolean b) { - } -} - diff --git a/src/main/java/dk/lockfuglsang/wolfencraft/view/hologram/HologramsView.java b/src/main/java/dk/lockfuglsang/wolfencraft/view/hologram/HologramsView.java index 6f75c9a..5cc4bdb 100644 --- a/src/main/java/dk/lockfuglsang/wolfencraft/view/hologram/HologramsView.java +++ b/src/main/java/dk/lockfuglsang/wolfencraft/view/hologram/HologramsView.java @@ -1,6 +1,6 @@ package dk.lockfuglsang.wolfencraft.view.hologram; -import com.sainttx.holograms.data.Hologram; +import com.sainttx.holograms.api.Hologram; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.plugin.Plugin; @@ -15,13 +15,13 @@ public class HologramsView extends AbstractView { @Override public void updateView(Plugin plugin, String output) { - Bukkit.getScheduler().callSyncMethod(plugin, new SyncCallable(plugin, getLines(output))); + Bukkit.getScheduler().callSyncMethod(plugin, new SyncCallable(getLines(output))); } @Override public void removeView() { if (hologram != null) { - hologram.delete(); + hologram.despawn(); } } @@ -34,25 +34,19 @@ public void setLocation(Location location) { } private class SyncCallable implements Callable { - private final Plugin plugin; private final String[] lines; - public SyncCallable(Plugin plugin, String[] lines) { - this.plugin = plugin; + public SyncCallable(String[] lines) { this.lines = lines; } @Override public Void call() throws Exception { - if (hologram == null) { - hologram = new Hologram(getId(), location, false, lines); - } else { - hologram.clearLines(); - for (String line : lines) { - hologram.addLine(line); - } + if (hologram != null) { + hologram.despawn(); } - hologram.refreshAll(); + hologram = new Hologram(getId(), location, false, lines); + hologram.refresh(); return null; } }