flags + meta

This commit is contained in:
boy0001 2015-05-04 19:52:37 +10:00
parent f1a7e0d73f
commit 1ad65122b7
8 changed files with 50 additions and 19 deletions

View File

@ -23,6 +23,7 @@ package com.intellectualcrafters.plot.commands;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.UUID; import java.util.UUID;
import java.util.regex.Matcher;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
@ -189,7 +190,7 @@ public class Info extends SubCommand {
info = info.replaceAll("%trusted%", trusted); info = info.replaceAll("%trusted%", trusted);
info = info.replaceAll("%denied%", denied); info = info.replaceAll("%denied%", denied);
info = info.replaceAll("%rating%", rating); 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("%build%", build + "");
info = info.replaceAll("%desc%", "No description set."); info = info.replaceAll("%desc%", "No description set.");
return info; return info;

View File

@ -187,7 +187,7 @@ public enum C {
/* /*
* Core Stuff * Core Stuff
*/ */
PREFIX("$3[$1P2$3] "), PREFIX("$3[$1P2$3] $2"),
ENABLED("$1PlotSquared is now enabled"), ENABLED("$1PlotSquared is now enabled"),
EXAMPLE_MESSAGE("$2This is an example message &k!!!"), EXAMPLE_MESSAGE("$2This is an example message &k!!!"),
/* /*

View File

@ -909,7 +909,7 @@ public class SQLManager implements AbstractDB {
} }
final Set<Flag> flags = new HashSet<Flag>(); final Set<Flag> flags = new HashSet<Flag>();
boolean exception = false; boolean exception = false;
for (final String element : flags_string) { for (String element : flags_string) {
if (element.contains(":")) { if (element.contains(":")) {
final String[] split = element.split(":"); final String[] split = element.split(":");
try { try {
@ -921,7 +921,13 @@ public class SQLManager implements AbstractDB {
exception = true; exception = true;
} }
} else { } 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) { if (exception) {

View File

@ -36,13 +36,8 @@ public class Flag {
* @throws IllegalArgumentException if you provide inadequate inputs * @throws IllegalArgumentException if you provide inadequate inputs
*/ */
public Flag(final AbstractFlag key, final String value) { public Flag(final AbstractFlag key, final String value) {
final char[] allowedCharacters = new char[] { '[', ']', '(', ')', ',', '_', '-', '.', ',', '?', '!', '&', ':', '\u00A7' }; if (!StringUtils.isAsciiPrintable(value)) {
String tempValue = value; throw new IllegalArgumentException("Flag must be ascii");
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 (value.length() > 128) { if (value.length() > 128) {
throw new IllegalArgumentException("Value must be <= 128 characters"); throw new IllegalArgumentException("Value must be <= 128 characters");

View File

@ -329,6 +329,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
if (plot.isDenied(pp.getUUID())) { if (plot.isDenied(pp.getUUID())) {
if (!Permissions.hasPermission(pp, "plots.admin.entry.denied")) { if (!Permissions.hasPermission(pp, "plots.admin.entry.denied")) {
MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.entry.denied"); MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.entry.denied");
player.teleport(event.getFrom());
event.setCancelled(true); event.setCancelled(true);
return; return;
} }

View File

@ -1,5 +1,6 @@
package com.intellectualcrafters.plot.object; package com.intellectualcrafters.plot.object;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.UUID; import java.util.UUID;
@ -14,10 +15,12 @@ public class BukkitPlayer implements PlotPlayer {
public final Player player; public final Player player;
UUID uuid; UUID uuid;
String name; String name;
public HashSet<String> hasPerm = new HashSet<>();
public HashSet<String> noPerm = new HashSet<>();
private int op = 0; private int op = 0;
private long last = 0; private long last = 0;
public HashSet<String> hasPerm = new HashSet<>();
public HashSet<String> noPerm = new HashSet<>();
private HashMap<String, Object> meta;
/** /**
* Please do not use this method. Instead use BukkitUtil.getPlayer(Player), as it caches player objects. * 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() { public Location getLocationFull() {
return BukkitUtil.getLocationFull(this.player); return BukkitUtil.getLocationFull(this.player);
} }
@Override
public void setMeta(String key, Object value) {
if (this.meta == null) {
this.meta = new HashMap<String, Object>();
}
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);
}
}
} }

View File

@ -30,4 +30,8 @@ public interface PlotPlayer {
public String getName(); public String getName();
public void setCompassTarget(Location loc); public void setCompassTarget(Location loc);
public void setMeta(String key, Object value);
public Object getMeta(String key);
public void deleteMeta(String key);
} }

View File

@ -110,10 +110,8 @@ public class UUIDHandler {
if (CACHED) { if (CACHED) {
return; return;
} }
PlotSquared.log(C.PREFIX.s() + "&6Starting player data caching"); PlotSquared.log(C.PREFIX.s() + "&6Starting player data caching: " + world);
long start = System.currentTimeMillis();
UUIDHandler.CACHED = true; UUIDHandler.CACHED = true;
if (Settings.TWIN_MODE_UUID) { if (Settings.TWIN_MODE_UUID) {
HashSet<UUID> all = getAllUUIDS(); HashSet<UUID> all = getAllUUIDS();
final File playerdataFolder = new File(world + File.separator + "playerdata"); final File playerdataFolder = new File(world + File.separator + "playerdata");
@ -123,12 +121,13 @@ public class UUIDHandler {
return s.endsWith(".dat"); return s.endsWith(".dat");
} }
}); });
boolean check = all.size() == 0;
if (dat != null) { if (dat != null) {
for (final String current : dat) { for (final String current : dat) {
final String s = current.replaceAll(".dat$", ""); final String s = current.replaceAll(".dat$", "");
try { try {
final UUID uuid = UUID.fromString(s); final UUID uuid = UUID.fromString(s);
if (all.contains(uuid)) { if (check || all.contains(uuid)) {
OfflinePlayer op = Bukkit.getOfflinePlayer(uuid); OfflinePlayer op = Bukkit.getOfflinePlayer(uuid);
add(new StringWrapper(op.getName()), 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"); PlotSquared.log(C.PREFIX.s() + "&6Cached a total of: " + UUIDHandler.uuidMap.size() + " UUIDs");
return; return;
} }
final HashSet<String> worlds = new HashSet<>(); final HashSet<String> worlds = new HashSet<>();
worlds.add(world); worlds.add(world);
worlds.add("world"); worlds.add("world");