From c55faaec8d9e663ad4f073dc1120b93b40646ee3 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Tue, 21 Oct 2014 20:58:52 +1100 Subject: [PATCH] Fixes --- .../src/com/intellectualcrafters/plot/C.java | 4 +- .../plot/PlotGenerator.java | 1 - .../plot/StringWrapper.java | 34 +++++++++ .../plot/UUIDHandler.java | 57 +++++++------- .../plot/commands/CommandPermission.java | 2 +- .../plot/commands/Denied.java | 74 ++++++++----------- .../plot/commands/Helpers.java | 71 ++++++++---------- .../plot/commands/MainCommand.java | 8 +- .../plot/commands/Set.java | 6 +- .../plot/commands/Trusted.java | 72 ++++++++---------- .../plot/listeners/PlayerEvents.java | 42 +++++------ .../plot/uuid/PlotUUIDSaver.java | 6 +- .../plot/uuid/UUIDSaver.java | 3 +- 13 files changed, 192 insertions(+), 188 deletions(-) create mode 100644 PlotSquared/src/com/intellectualcrafters/plot/StringWrapper.java diff --git a/PlotSquared/src/com/intellectualcrafters/plot/C.java b/PlotSquared/src/com/intellectualcrafters/plot/C.java index 0cb5a1eb6..8183487c1 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/C.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/C.java @@ -110,7 +110,7 @@ public enum C { * Permission */ NO_SCHEMATIC_PERMISSION("&cYou don't have the permission required to use schematic &6%s"), - NO_PERMISSION("&cYou don't have the permissions required to use this command."), + NO_PERMISSION("&cYou are lacking the permission node: &6%s"), NO_PLOT_PERMS("&cYou don't have the permissions to do that in this plot"), CANT_CLAIM_MORE_PLOTS("&cYou can't claim more plots."), YOU_BE_DENIED("&cYou are not allowed to enter this plot"), @@ -216,7 +216,7 @@ public enum C { /* * Claiming */ - PLOT_NOT_CLAIMED("&cCannot claim plot"), + PLOT_NOT_CLAIMED("&cPlot not claimed"), PLOT_IS_CLAIMED("&cThis plot is already claimed"), CLAIMED("&6You successfully claimed the plot"), /* diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlotGenerator.java b/PlotSquared/src/com/intellectualcrafters/plot/PlotGenerator.java index 7d28a4470..d485975f9 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlotGenerator.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlotGenerator.java @@ -6,7 +6,6 @@ public abstract class PlotGenerator extends ChunkGenerator { public PlotGenerator(String world) { PlotMain.loadWorld(world, this); - System.out.print("LOADED"); } public abstract PlotWorld getNewPlotWorld(String world); diff --git a/PlotSquared/src/com/intellectualcrafters/plot/StringWrapper.java b/PlotSquared/src/com/intellectualcrafters/plot/StringWrapper.java new file mode 100644 index 000000000..e393885e6 --- /dev/null +++ b/PlotSquared/src/com/intellectualcrafters/plot/StringWrapper.java @@ -0,0 +1,34 @@ +package com.intellectualcrafters.plot; + +public class StringWrapper { + public String value; + + public StringWrapper(String value) { + this.value = value; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + StringWrapper other = (StringWrapper) obj; + return other.value.toLowerCase().equals(this.value.toLowerCase()); + } + + @Override + public String toString() { + return this.value; + } + + @Override + public int hashCode() { + return this.value.toLowerCase().hashCode(); + } +} diff --git a/PlotSquared/src/com/intellectualcrafters/plot/UUIDHandler.java b/PlotSquared/src/com/intellectualcrafters/plot/UUIDHandler.java index 440659316..01e319dcc 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/UUIDHandler.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/UUIDHandler.java @@ -6,11 +6,13 @@ import com.google.common.collect.HashBiMap; import com.intellectualcrafters.plot.uuid.NameFetcher; import com.intellectualcrafters.plot.uuid.UUIDFetcher; import com.intellectualcrafters.plot.uuid.UUIDSaver; + import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; import java.util.Arrays; +import java.util.HashMap; import java.util.UUID; /** @@ -35,9 +37,9 @@ public class UUIDHandler { private static boolean online = Bukkit.getServer().getOnlineMode(); - private static BiMap uuidMap = HashBiMap.create(); + private static BiMap uuidMap = HashBiMap.create(new HashMap()); - public static BiMap getUuidMap() { + public static BiMap getUuidMap() { return uuidMap; } @@ -45,42 +47,45 @@ public class UUIDHandler { return uuidMap.containsValue(uuid); } - public static boolean nameExists(String name) { + public static boolean nameExists(StringWrapper name) { return uuidMap.containsKey(name); } - public static void add(String name, UUID uuid) { + public static void add(StringWrapper name, UUID uuid) { uuidMap.put(name, uuid); } - /** * @param name * @return uuid */ public static UUID getUUID(String name) { - if (nameExists(name)) { - return uuidMap.get(name); + StringWrapper nameWrap = new StringWrapper(name); + if (uuidMap.containsKey(nameWrap)) { + return uuidMap.get(nameWrap); + } + Player player = Bukkit.getPlayer(name); + if (player!=null) { + UUID uuid = player.getUniqueId(); + uuidMap.put(nameWrap, uuid); + return uuid; } UUID uuid; - if ((uuid = getUuidOnlinePlayer(name)) != null) { - return uuid; - } - if ((uuid = getUuidOfflinePlayer(name)) != null) { - return uuid; - } if (online) { + if ((uuid = getUuidOnlinePlayer(nameWrap)) != null) { + return uuid; + } try { UUIDFetcher fetcher = new UUIDFetcher(Arrays.asList(name)); uuid = fetcher.call().get(name); - add(name, uuid); + add(nameWrap, uuid); } catch (Exception e) { e.printStackTrace(); } } else { - return getUuidOfflineMode(name); + return getUuidOfflineMode(nameWrap); } return null; } @@ -89,7 +94,7 @@ public class UUIDHandler { * @param uuid * @return name (cache) */ - private static String loopSearch(UUID uuid) { + private static StringWrapper loopSearch(UUID uuid) { return uuidMap.inverse().get(uuid); } @@ -99,7 +104,7 @@ public class UUIDHandler { */ public static String getName(UUID uuid) { if (uuidExists(uuid)) { - return loopSearch(uuid); + return loopSearch(uuid).value; } String name; if ((name = getNameOnlinePlayer(uuid)) != null) { @@ -112,7 +117,7 @@ public class UUIDHandler { try { NameFetcher fetcher = new NameFetcher(Arrays.asList(uuid)); name = fetcher.call().get(uuid); - add(name, uuid); + add(new StringWrapper(name), uuid); return name; } catch (Exception e) { @@ -129,7 +134,7 @@ public class UUIDHandler { * @param name * @return UUID (name hash) */ - private static UUID getUuidOfflineMode(String name) { + private static UUID getUuidOfflineMode(StringWrapper name) { UUID uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8)); add(name, uuid); return uuid; @@ -145,7 +150,7 @@ public class UUIDHandler { return null; } String name = player.getName(); - add(name, uuid); + add(new StringWrapper(name), uuid); return name; } @@ -159,7 +164,7 @@ public class UUIDHandler { return null; } String name = player.getName(); - add(name, uuid); + add(new StringWrapper(name), uuid); return name; } @@ -167,9 +172,9 @@ public class UUIDHandler { * @param name * @return UUID */ - private static UUID getUuidOnlinePlayer(String name) { - Player player = Bukkit.getPlayer(name); - if (player == null || !player.isOnline()) { + private static UUID getUuidOnlinePlayer(StringWrapper name) { + Player player = Bukkit.getPlayer(name.value); + if (player == null) { return null; } UUID uuid = player.getUniqueId(); @@ -181,8 +186,8 @@ public class UUIDHandler { * @param name * @return UUID (username hash) */ - private static UUID getUuidOfflinePlayer(String name) { - UUID uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8)); + private static UUID getUuidOfflinePlayer(StringWrapper name) { + UUID uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + name.value).getBytes(Charsets.UTF_8)); add(name, uuid); return uuid; } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/CommandPermission.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/CommandPermission.java index 78714f228..f33105782 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/CommandPermission.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/CommandPermission.java @@ -23,7 +23,7 @@ public class CommandPermission { /** * */ - private String permission; + public String permission; /** * @param permission diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Denied.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Denied.java index 9d9aca4db..1d6885aec 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Denied.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Denied.java @@ -42,61 +42,49 @@ public class Denied extends SubCommand { } Plot plot = PlayerFunctions.getCurrentPlot(plr); if ((plot.owner == null) || !plot.hasRights(plr)) { - PlayerFunctions.sendMessage(plr, C.NO_PERMISSION); + PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS); return true; } if (args[0].equalsIgnoreCase("add")) { + UUID uuid; if (args[1].equalsIgnoreCase("*")) { - UUID uuid = DBFunc.everyone; - if (!plot.denied.contains(uuid)) { - if (plot.owner == uuid) { - PlayerFunctions.sendMessage(plr, C.ALREADY_OWNER); - return false; - } - if (plot.trusted.contains(uuid)) { - plot.trusted.remove(uuid); - DBFunc.removeTrusted(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(uuid)); - } - if (plot.helpers.contains(uuid)) { - plot.helpers.remove(uuid); - DBFunc.removeHelper(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(uuid)); - } - plot.addDenied(uuid); - DBFunc.setDenied(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1])); - PlayerPlotDeniedEvent event = new PlayerPlotDeniedEvent(plr, plot, uuid, true); - Bukkit.getPluginManager().callEvent(event); - } - else { - PlayerFunctions.sendMessage(plr, C.ALREADY_ADDED); + uuid = DBFunc.everyone; + + } + else { + uuid = UUIDHandler.getUUID(args[1]); + } + if (!plot.denied.contains(uuid)) { + if (plot.owner == uuid) { + PlayerFunctions.sendMessage(plr, C.ALREADY_OWNER); return false; } - PlayerFunctions.sendMessage(plr, C.DENIED_ADDED); - return true; - } - /* - * if (!hasBeenOnServer(args[1])) { PlayerFunctions.sendMessage(plr, - * C.PLAYER_HAS_NOT_BEEN_ON); return true; } UUID uuid = null; if - * ((Bukkit.getPlayer(args[1]) != null)) { uuid = - * Bukkit.getPlayer(args[1]).getUniqueId(); } else { uuid = - * Bukkit.getOfflinePlayer(args[1]).getUniqueId(); } if (uuid == - * null) { PlayerFunctions.sendMessage(plr, - * C.PLAYER_HAS_NOT_BEEN_ON); return true; } - */ - UUID uuid = UUIDHandler.getUUID(args[1]); - if (!plot.denied.contains(uuid)) { - plot.addDenied(uuid); - DBFunc.setDenied(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1])); - PlayerPlotDeniedEvent event = new PlayerPlotDeniedEvent(plr, plot, uuid, true); - Bukkit.getPluginManager().callEvent(event); - } - PlayerFunctions.sendMessage(plr, C.DENIED_ADDED); - if ((Bukkit.getPlayer(uuid) != null) && Bukkit.getPlayer(uuid).isOnline()) { + if (plot.trusted.contains(uuid)) { + plot.trusted.remove(uuid); + DBFunc.removeTrusted(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(uuid)); + } + if (plot.helpers.contains(uuid)) { + plot.helpers.remove(uuid); + DBFunc.removeHelper(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(uuid)); + } + plot.addDenied(uuid); + DBFunc.setDenied(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1])); + PlayerPlotDeniedEvent event = new PlayerPlotDeniedEvent(plr, plot, uuid, true); + Bukkit.getPluginManager().callEvent(event); + } + else { + PlayerFunctions.sendMessage(plr, C.ALREADY_ADDED); + return false; + } + if (!uuid.equals(DBFunc.everyone) && (Bukkit.getPlayer(uuid) != null) && Bukkit.getPlayer(uuid).isOnline()) { Plot pl = PlayerFunctions.getCurrentPlot(Bukkit.getPlayer((uuid))); if (pl.id == plot.id) { PlayerFunctions.sendMessage(Bukkit.getPlayer(uuid), C.YOU_BE_DENIED); Bukkit.getPlayer(uuid).teleport(Bukkit.getPlayer(uuid).getWorld().getSpawnLocation()); } } + PlayerFunctions.sendMessage(plr, C.DENIED_ADDED); + return true; } else if (args[0].equalsIgnoreCase("remove")) { diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Helpers.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Helpers.java index 9f54a800d..707d7de2c 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Helpers.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Helpers.java @@ -39,54 +39,41 @@ public class Helpers extends SubCommand { } Plot plot = PlayerFunctions.getCurrentPlot(plr); if ((plot.owner == null) || !plot.hasRights(plr)) { - PlayerFunctions.sendMessage(plr, C.NO_PERMISSION); + PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS); return true; } if (args[0].equalsIgnoreCase("add")) { + UUID uuid; if (args[1].equalsIgnoreCase("*")) { - UUID uuid = DBFunc.everyone; - if (!plot.helpers.contains(uuid)) { - if (plot.owner == uuid) { - PlayerFunctions.sendMessage(plr, C.ALREADY_OWNER); - return false; - } - if (plot.trusted.contains(uuid)) { - plot.trusted.remove(uuid); - DBFunc.removeTrusted(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(uuid)); - } - if (plot.denied.contains(uuid)) { - plot.denied.remove(uuid); - DBFunc.removeDenied(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(uuid)); - } - plot.addHelper(uuid); - DBFunc.setHelper(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1])); - PlayerPlotHelperEvent event = new PlayerPlotHelperEvent(plr, plot, uuid, true); - Bukkit.getPluginManager().callEvent(event); - } - else { - PlayerFunctions.sendMessage(plr, C.ALREADY_ADDED); + uuid = DBFunc.everyone; + } + else { + uuid = UUIDHandler.getUUID(args[1]); + } + if (!plot.helpers.contains(uuid)) { + if (plot.owner == uuid) { + PlayerFunctions.sendMessage(plr, C.ALREADY_OWNER); return false; } - PlayerFunctions.sendMessage(plr, C.HELPER_ADDED); - return true; - } - /* - * if (!hasBeenOnServer(args[1])) { PlayerFunctions.sendMessage(plr, - * C.PLAYER_HAS_NOT_BEEN_ON); return true; } UUID uuid = null; if - * ((Bukkit.getPlayer(args[1]) != null)) { uuid = - * Bukkit.getPlayer(args[1]).getUniqueId(); } else { uuid = - * Bukkit.getOfflinePlayer(args[1]).getUniqueId(); } if (uuid == - * null) { PlayerFunctions.sendMessage(plr, - * C.PLAYER_HAS_NOT_BEEN_ON); return true; } - */ - UUID uuid = UUIDHandler.getUUID(args[1]); - if (!plot.helpers.contains(uuid)) { - plot.addHelper(uuid); - DBFunc.setHelper(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1])); - PlayerPlotHelperEvent event = new PlayerPlotHelperEvent(plr, plot, uuid, true); - Bukkit.getPluginManager().callEvent(event); - } - PlayerFunctions.sendMessage(plr, C.HELPER_ADDED); + if (plot.trusted.contains(uuid)) { + plot.trusted.remove(uuid); + DBFunc.removeTrusted(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(uuid)); + } + if (plot.denied.contains(uuid)) { + plot.denied.remove(uuid); + DBFunc.removeDenied(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(uuid)); + } + plot.addHelper(uuid); + DBFunc.setHelper(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1])); + PlayerPlotHelperEvent event = new PlayerPlotHelperEvent(plr, plot, uuid, true); + Bukkit.getPluginManager().callEvent(event); + } + else { + PlayerFunctions.sendMessage(plr, C.ALREADY_ADDED); + return false; + } + PlayerFunctions.sendMessage(plr, C.HELPER_ADDED); + return true; } else if (args[0].equalsIgnoreCase("remove")) { diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/MainCommand.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/MainCommand.java index fb0f3bdd0..10de9fad9 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/MainCommand.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/MainCommand.java @@ -38,8 +38,8 @@ public class MainCommand implements CommandExecutor { } }; - public static boolean no_permission(Player player) { - PlayerFunctions.sendMessage(player, C.NO_PERMISSION); + public static boolean no_permission(Player player, String permission) { + PlayerFunctions.sendMessage(player, C.NO_PERMISSION, permission); return false; } @@ -53,7 +53,7 @@ public class MainCommand implements CommandExecutor { player = null; } if (!PlotMain.hasPermission(player, "plots.use")) { - return no_permission(player); + return no_permission(player, "plots.use"); } if ((args.length < 1) || ((args.length >= 1) && (args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("he")))) { @@ -109,7 +109,7 @@ public class MainCommand implements CommandExecutor { } } else { - return no_permission(player); + return no_permission(player, command.permission.permission.toLowerCase()); } } } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Set.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Set.java index 8bac5d403..73617c98f 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Set.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Set.java @@ -48,7 +48,7 @@ public class Set extends SubCommand { Plot plot = PlayerFunctions.getCurrentPlot(plr); if(!plot.hasOwner()) { sendMessage(plr, C.PLOT_NOT_CLAIMED); - return true; + return false; } if (!plot.hasRights(plr) && !plr.hasPermission("plots.admin")) { PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS); @@ -71,7 +71,7 @@ public class Set extends SubCommand { boolean advanced_permissions = true; if (advanced_permissions) { if (!plr.hasPermission("plots.set." + args[0].toLowerCase())) { - PlayerFunctions.sendMessage(plr, C.NO_PERMISSION); + PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.set."+args[0].toLowerCase()); return false; } } @@ -104,7 +104,7 @@ public class Set extends SubCommand { PlayerFunctions.sendMessage(plr, C.NOT_VALID_FLAG); return false; } - if (!plr.hasPermission("plots.set.flag." + args[1].toLowerCase())) { + if (!PlotMain.hasPermission(plr, "plots.set.flag." + args[1].toLowerCase())) { PlayerFunctions.sendMessage(plr, C.NO_PERMISSION); return false; } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Trusted.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Trusted.java index ed9255e5c..abf53854a 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Trusted.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Trusted.java @@ -39,54 +39,42 @@ public class Trusted extends SubCommand { } Plot plot = PlayerFunctions.getCurrentPlot(plr); if ((plot.owner == null) || !plot.hasRights(plr)) { - PlayerFunctions.sendMessage(plr, C.NO_PERMISSION); + PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS); return true; } if (args[0].equalsIgnoreCase("add")) { + UUID uuid; if (args[1].equalsIgnoreCase("*")) { - UUID uuid = DBFunc.everyone; - if (!plot.trusted.contains(uuid)) { - if (plot.owner == uuid) { - PlayerFunctions.sendMessage(plr, C.ALREADY_OWNER); - return false; - } - if (plot.helpers.contains(uuid)) { - plot.helpers.remove(uuid); - DBFunc.removeHelper(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(uuid)); - } - if (plot.denied.contains(uuid)) { - plot.denied.remove(uuid); - DBFunc.removeDenied(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(uuid)); - } - plot.addTrusted(uuid); - DBFunc.setTrusted(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1])); - PlayerPlotTrustedEvent event = new PlayerPlotTrustedEvent(plr, plot, uuid, true); - Bukkit.getPluginManager().callEvent(event); - } - else { - PlayerFunctions.sendMessage(plr, C.ALREADY_ADDED); - return false; - } - PlayerFunctions.sendMessage(plr, C.TRUSTED_ADDED); - return true; + uuid = DBFunc.everyone; + + } + else { + uuid = UUIDHandler.getUUID(args[1]); } - /* - * if (!hasBeenOnServer(args[1])) { PlayerFunctions.sendMessage(plr, - * C.PLAYER_HAS_NOT_BEEN_ON); return true; } UUID uuid = null; if - * ((Bukkit.getPlayer(args[1]) != null)) { uuid = - * Bukkit.getPlayer(args[1]).getUniqueId(); } else { uuid = - * Bukkit.getOfflinePlayer(args[1]).getUniqueId(); } if (uuid == - * null) { PlayerFunctions.sendMessage(plr, - * C.PLAYER_HAS_NOT_BEEN_ON); return true; } - */ - UUID uuid = UUIDHandler.getUUID(args[1]); if (!plot.trusted.contains(uuid)) { - plot.addTrusted(uuid); - DBFunc.setTrusted(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1])); - PlayerPlotTrustedEvent event = new PlayerPlotTrustedEvent(plr, plot, uuid, true); - Bukkit.getPluginManager().callEvent(event); - } - PlayerFunctions.sendMessage(plr, C.TRUSTED_ADDED); + if (plot.owner == uuid) { + PlayerFunctions.sendMessage(plr, C.ALREADY_OWNER); + return false; + } + if (plot.helpers.contains(uuid)) { + plot.helpers.remove(uuid); + DBFunc.removeHelper(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(uuid)); + } + if (plot.denied.contains(uuid)) { + plot.denied.remove(uuid); + DBFunc.removeDenied(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(uuid)); + } + plot.addTrusted(uuid); + DBFunc.setTrusted(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1])); + PlayerPlotTrustedEvent event = new PlayerPlotTrustedEvent(plr, plot, uuid, true); + Bukkit.getPluginManager().callEvent(event); + } + else { + PlayerFunctions.sendMessage(plr, C.ALREADY_ADDED); + return false; + } + PlayerFunctions.sendMessage(plr, C.TRUSTED_ADDED); + return true; } else if (args[0].equalsIgnoreCase("remove")) { diff --git a/PlotSquared/src/com/intellectualcrafters/plot/listeners/PlayerEvents.java b/PlotSquared/src/com/intellectualcrafters/plot/listeners/PlayerEvents.java index 99976f6d9..e5e1c137d 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/listeners/PlayerEvents.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/listeners/PlayerEvents.java @@ -676,18 +676,18 @@ public class PlayerEvents implements Listener { Block b = e.getBlockClicked().getLocation().add(bf.getModX(), bf.getModY(), bf.getModZ()).getBlock(); if (isPlotWorld(b.getLocation())) { if (!isInPlot(b.getLocation())) { - PlayerFunctions.sendMessage(e.getPlayer(), C.NO_PERMISSION); + PlayerFunctions.sendMessage(e.getPlayer(), C.NO_PLOT_PERMS); e.setCancelled(true); } else { Plot plot = getCurrentPlot(b.getLocation()); if (plot == null) { - PlayerFunctions.sendMessage(e.getPlayer(), C.NO_PERMISSION); + PlayerFunctions.sendMessage(e.getPlayer(), C.NO_PLOT_PERMS); e.setCancelled(true); } else if (!plot.hasRights(e.getPlayer())) { - PlayerFunctions.sendMessage(e.getPlayer(), C.NO_PERMISSION); + PlayerFunctions.sendMessage(e.getPlayer(), C.NO_PLOT_PERMS); e.setCancelled(true); } } @@ -720,18 +720,18 @@ public class PlayerEvents implements Listener { Block b = e.getBlockClicked(); if (isPlotWorld(b.getLocation())) { if (!isInPlot(b.getLocation())) { - PlayerFunctions.sendMessage(e.getPlayer(), C.NO_PERMISSION); + PlayerFunctions.sendMessage(e.getPlayer(), C.NO_PLOT_PERMS); e.setCancelled(true); } else { Plot plot = getCurrentPlot(b.getLocation()); if (plot == null) { - PlayerFunctions.sendMessage(e.getPlayer(), C.NO_PERMISSION); + PlayerFunctions.sendMessage(e.getPlayer(), C.NO_PLOT_PERMS); e.setCancelled(true); } else if (!plot.hasRights(e.getPlayer())) { - PlayerFunctions.sendMessage(e.getPlayer(), C.NO_PERMISSION); + PlayerFunctions.sendMessage(e.getPlayer(), C.NO_PLOT_PERMS); e.setCancelled(true); } } @@ -747,7 +747,7 @@ public class PlayerEvents implements Listener { Player p = e.getPlayer(); if (!isInPlot(b.getLocation())) { if (!p.hasPermission("plots.admin")) { - PlayerFunctions.sendMessage(p, C.NO_PERMISSION); + PlayerFunctions.sendMessage(p, C.NO_PLOT_PERMS); e.setCancelled(true); } } @@ -755,14 +755,14 @@ public class PlayerEvents implements Listener { Plot plot = getCurrentPlot(b.getLocation()); if (plot == null) { if (!p.hasPermission("plots.admin")) { - PlayerFunctions.sendMessage(p, C.NO_PERMISSION); + PlayerFunctions.sendMessage(p, C.NO_PLOT_PERMS); e.setCancelled(true); } } else if (!plot.hasRights(p)) { if (!p.hasPermission("plots.admin")) { - PlayerFunctions.sendMessage(p, C.NO_PERMISSION); + PlayerFunctions.sendMessage(p, C.NO_PLOT_PERMS); e.setCancelled(true); } } @@ -780,7 +780,7 @@ public class PlayerEvents implements Listener { if (isPlotWorld(l)) { if (!isInPlot(l)) { if (!p.hasPermission("plots.admin")) { - PlayerFunctions.sendMessage(p, C.NO_PERMISSION); + PlayerFunctions.sendMessage(p, C.NO_PLOT_PERMS); e.setCancelled(true); } } @@ -788,14 +788,14 @@ public class PlayerEvents implements Listener { Plot plot = getCurrentPlot(l); if (plot == null) { if (!p.hasPermission("plots.admin")) { - PlayerFunctions.sendMessage(p, C.NO_PERMISSION); + PlayerFunctions.sendMessage(p, C.NO_PLOT_PERMS); e.setCancelled(true); } } else if (!plot.hasRights(p)) { if (!p.hasPermission("plots.admin")) { - PlayerFunctions.sendMessage(p, C.NO_PERMISSION); + PlayerFunctions.sendMessage(p, C.NO_PLOT_PERMS); e.setCancelled(true); } } @@ -812,7 +812,7 @@ public class PlayerEvents implements Listener { Player p = e.getPlayer(); if (!isInPlot(l)) { if (!p.hasPermission("plots.admin")) { - PlayerFunctions.sendMessage(p, C.NO_PERMISSION); + PlayerFunctions.sendMessage(p, C.NO_PLOT_PERMS); e.setCancelled(true); } } @@ -820,14 +820,14 @@ public class PlayerEvents implements Listener { Plot plot = getCurrentPlot(l); if (plot == null) { if (!p.hasPermission("plots.admin")) { - PlayerFunctions.sendMessage(p, C.NO_PERMISSION); + PlayerFunctions.sendMessage(p, C.NO_PLOT_PERMS); e.setCancelled(true); } } else if (!plot.hasRights(p)) { if (!p.hasPermission("plots.admin")) { - PlayerFunctions.sendMessage(p, C.NO_PERMISSION); + PlayerFunctions.sendMessage(p, C.NO_PLOT_PERMS); e.setCancelled(true); } } @@ -853,7 +853,7 @@ public class PlayerEvents implements Listener { } if (!isInPlot(l)) { if (!p.hasPermission("plots.admin")) { - PlayerFunctions.sendMessage(p, C.NO_PERMISSION); + PlayerFunctions.sendMessage(p, C.NO_PLOT_PERMS); e.setCancelled(true); } } @@ -861,14 +861,14 @@ public class PlayerEvents implements Listener { Plot plot = getCurrentPlot(l); if (plot == null) { if (!p.hasPermission("plots.admin")) { - PlayerFunctions.sendMessage(p, C.NO_PERMISSION); + PlayerFunctions.sendMessage(p, C.NO_PLOT_PERMS); e.setCancelled(true); } } else if (!plot.hasRights(p)) { if (!p.hasPermission("plots.admin")) { - PlayerFunctions.sendMessage(p, C.NO_PERMISSION); + PlayerFunctions.sendMessage(p, C.NO_PLOT_PERMS); e.setCancelled(true); } } @@ -885,7 +885,7 @@ public class PlayerEvents implements Listener { Player p = e.getPlayer(); if (!isInPlot(l)) { if (!p.hasPermission("plots.admin")) { - PlayerFunctions.sendMessage(p, C.NO_PERMISSION); + PlayerFunctions.sendMessage(p, C.NO_PLOT_PERMS); e.setHatching(false); } } @@ -893,14 +893,14 @@ public class PlayerEvents implements Listener { Plot plot = getCurrentPlot(l); if (plot == null) { if (!p.hasPermission("plots.admin")) { - PlayerFunctions.sendMessage(p, C.NO_PERMISSION); + PlayerFunctions.sendMessage(p, C.NO_PLOT_PERMS); e.setHatching(false); } } else if (!plot.hasRights(p)) { if (!p.hasPermission("plots.admin")) { - PlayerFunctions.sendMessage(p, C.NO_PERMISSION); + PlayerFunctions.sendMessage(p, C.NO_PLOT_PERMS); e.setHatching(false); } } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/uuid/PlotUUIDSaver.java b/PlotSquared/src/com/intellectualcrafters/plot/uuid/PlotUUIDSaver.java index d5bf55d7c..546d5bb88 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/uuid/PlotUUIDSaver.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/uuid/PlotUUIDSaver.java @@ -2,7 +2,9 @@ package com.intellectualcrafters.plot.uuid; import com.google.common.collect.BiMap; import com.intellectualcrafters.plot.PlotMain; +import com.intellectualcrafters.plot.StringWrapper; import com.intellectualcrafters.plot.UUIDHandler; + import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.plugin.java.JavaPlugin; @@ -28,7 +30,7 @@ public class PlotUUIDSaver extends UUIDSaver { uuid = player.getUniqueId(); if (!UUIDHandler.uuidExists(uuid)) { name = player.getName(); - UUIDHandler.add(name, uuid); + UUIDHandler.add(new StringWrapper(name), uuid); } } @@ -49,7 +51,7 @@ public class PlotUUIDSaver extends UUIDSaver { }); } - public void globalSave(BiMap map) { + public void globalSave(BiMap map) { } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/uuid/UUIDSaver.java b/PlotSquared/src/com/intellectualcrafters/plot/uuid/UUIDSaver.java index 860441e5b..cb4e54d52 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/uuid/UUIDSaver.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/uuid/UUIDSaver.java @@ -1,6 +1,7 @@ package com.intellectualcrafters.plot.uuid; import com.google.common.collect.BiMap; +import com.intellectualcrafters.plot.StringWrapper; import java.util.UUID; @@ -9,7 +10,7 @@ import java.util.UUID; */ public abstract class UUIDSaver { public abstract void globalPopulate(); - public abstract void globalSave(BiMap map); + public abstract void globalSave(BiMap biMap); public abstract void save(UUIDSet set); public abstract UUIDSet get(String name); public abstract UUIDSet get(UUID uuid);