From 1ad65122b77ff9bef781dac8f439662c697963e4 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Mon, 4 May 2015 19:52:37 +1000 Subject: [PATCH] flags + meta --- .../plot/commands/Info.java | 5 ++-- .../intellectualcrafters/plot/config/C.java | 2 +- .../plot/database/SQLManager.java | 10 +++++-- .../intellectualcrafters/plot/flag/Flag.java | 9 ++---- .../plot/listeners/PlayerEvents.java | 1 + .../plot/object/BukkitPlayer.java | 30 +++++++++++++++++-- .../plot/object/PlotPlayer.java | 4 +++ .../plot/util/bukkit/UUIDHandler.java | 8 ++--- 8 files changed, 50 insertions(+), 19 deletions(-) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Info.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Info.java index 7b357d131..732a1a682 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Info.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Info.java @@ -23,6 +23,7 @@ package com.intellectualcrafters.plot.commands; import java.util.ArrayList; import java.util.Collection; import java.util.UUID; +import java.util.regex.Matcher; import org.apache.commons.lang.StringUtils; @@ -94,7 +95,7 @@ public class Info extends SubCommand { } } if ((args.length == 1) && args[0].equalsIgnoreCase("inv")) { - new InfoInventory(plot, player).build().display(); + new InfoInventory(plot, player).build().display(); return true; } final boolean hasOwner = plot.hasOwner(); @@ -189,7 +190,7 @@ public class Info extends SubCommand { info = info.replaceAll("%trusted%", trusted); info = info.replaceAll("%denied%", denied); info = info.replaceAll("%rating%", rating); - info = info.replaceAll("%flags%", flags); + info = info.replaceAll("%flags%", Matcher.quoteReplacement(flags)); info = info.replaceAll("%build%", build + ""); info = info.replaceAll("%desc%", "No description set."); return info; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java index 3ac10f838..4bb2abe49 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java @@ -187,7 +187,7 @@ public enum C { /* * Core Stuff */ - PREFIX("$3[$1P2$3] "), + PREFIX("$3[$1P2$3] $2"), ENABLED("$1PlotSquared is now enabled"), EXAMPLE_MESSAGE("$2This is an example message &k!!!"), /* diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java index 37e4ae648..0c7aa2447 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -909,7 +909,7 @@ public class SQLManager implements AbstractDB { } final Set flags = new HashSet(); boolean exception = false; - for (final String element : flags_string) { + for (String element : flags_string) { if (element.contains(":")) { final String[] split = element.split(":"); try { @@ -921,7 +921,13 @@ public class SQLManager implements AbstractDB { exception = true; } } else { - flags.add(new Flag(FlagManager.getFlag(element, true), "")); + element = element.replaceAll("\u00AF", ":").replaceAll("\u00B4", ","); + if (StringUtils.isAlpha(element.replaceAll("_", "").replaceAll("-", ""))) { + flags.add(new Flag(FlagManager.getFlag(element, true), "")); + } + else { + System.out.print("INVALID FLAG: " + element); + } } } if (exception) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/Flag.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/Flag.java index bee4a7270..b8504cbce 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/Flag.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/Flag.java @@ -36,13 +36,8 @@ public class Flag { * @throws IllegalArgumentException if you provide inadequate inputs */ public Flag(final AbstractFlag key, final String value) { - final char[] allowedCharacters = new char[] { '[', ']', '(', ')', ',', '_', '-', '.', ',', '?', '!', '&', ':', '\u00A7' }; - String tempValue = value; - for (final char c : allowedCharacters) { - tempValue = tempValue.replace(c, 'c'); - } - if (!StringUtils.isAlphanumericSpace(tempValue)) { - throw new IllegalArgumentException("Flag must be alphanumerical (colours and some special characters are allowed)"); + if (!StringUtils.isAsciiPrintable(value)) { + throw new IllegalArgumentException("Flag must be ascii"); } if (value.length() > 128) { throw new IllegalArgumentException("Value must be <= 128 characters"); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java index 815e914c5..2c76f6318 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java @@ -329,6 +329,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi if (plot.isDenied(pp.getUUID())) { if (!Permissions.hasPermission(pp, "plots.admin.entry.denied")) { MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.entry.denied"); + player.teleport(event.getFrom()); event.setCancelled(true); return; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitPlayer.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitPlayer.java index 5fa4db1f9..3832ed22e 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitPlayer.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitPlayer.java @@ -1,5 +1,6 @@ package com.intellectualcrafters.plot.object; +import java.util.HashMap; import java.util.HashSet; import java.util.UUID; @@ -14,10 +15,12 @@ public class BukkitPlayer implements PlotPlayer { public final Player player; UUID uuid; String name; - public HashSet hasPerm = new HashSet<>(); - public HashSet noPerm = new HashSet<>(); private int op = 0; private long last = 0; + public HashSet hasPerm = new HashSet<>(); + public HashSet noPerm = new HashSet<>(); + + private HashMap meta; /** * Please do not use this method. Instead use BukkitUtil.getPlayer(Player), as it caches player objects. @@ -118,4 +121,27 @@ public class BukkitPlayer implements PlotPlayer { public Location getLocationFull() { return BukkitUtil.getLocationFull(this.player); } + + @Override + public void setMeta(String key, Object value) { + if (this.meta == null) { + this.meta = new HashMap(); + } + this.meta.put(key, value); + } + + @Override + public Object getMeta(String key) { + if (this.meta != null) { + return this.meta.get(key); + } + return null; + } + + @Override + public void deleteMeta(String key) { + if (this.meta != null) { + this.meta.remove(key); + } + } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java index cb75aa726..d33f972da 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java @@ -30,4 +30,8 @@ public interface PlotPlayer { public String getName(); public void setCompassTarget(Location loc); + + public void setMeta(String key, Object value); + public Object getMeta(String key); + public void deleteMeta(String key); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/UUIDHandler.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/UUIDHandler.java index a07bb44f4..2d8125751 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/UUIDHandler.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/UUIDHandler.java @@ -110,10 +110,8 @@ public class UUIDHandler { if (CACHED) { return; } - PlotSquared.log(C.PREFIX.s() + "&6Starting player data caching"); - long start = System.currentTimeMillis(); + PlotSquared.log(C.PREFIX.s() + "&6Starting player data caching: " + world); UUIDHandler.CACHED = true; - if (Settings.TWIN_MODE_UUID) { HashSet all = getAllUUIDS(); final File playerdataFolder = new File(world + File.separator + "playerdata"); @@ -123,12 +121,13 @@ public class UUIDHandler { return s.endsWith(".dat"); } }); + boolean check = all.size() == 0; if (dat != null) { for (final String current : dat) { final String s = current.replaceAll(".dat$", ""); try { final UUID uuid = UUID.fromString(s); - if (all.contains(uuid)) { + if (check || all.contains(uuid)) { OfflinePlayer op = Bukkit.getOfflinePlayer(uuid); add(new StringWrapper(op.getName()), uuid); } @@ -140,7 +139,6 @@ public class UUIDHandler { PlotSquared.log(C.PREFIX.s() + "&6Cached a total of: " + UUIDHandler.uuidMap.size() + " UUIDs"); return; } - final HashSet worlds = new HashSet<>(); worlds.add(world); worlds.add("world");