Seems to work for 1.7.2 (which doesn't have UUIDs)

This commit is contained in:
boy0001 2014-12-14 00:30:29 +11:00
parent 7b203261a3
commit 760041607e
21 changed files with 109 additions and 35 deletions

View File

@ -52,6 +52,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
@ -74,7 +75,7 @@ import java.util.concurrent.TimeUnit;
*/
@SuppressWarnings("unused")
public class PlotMain extends JavaPlugin {
private static PlotMain main = null;
/**
* Permission that allows for "everything"
*/
@ -681,7 +682,7 @@ public class PlotMain extends JavaPlugin {
* @return (this class)
*/
public static PlotMain getMain() {
return JavaPlugin.getPlugin(PlotMain.class);
return PlotMain.main;
}
/**
@ -718,7 +719,7 @@ public class PlotMain extends JavaPlugin {
return 0;
}
OfflinePlayer player;
if (((player = Bukkit.getOfflinePlayer(uuid)) == null) || !player.hasPlayedBefore()) {
if (((player = UUIDHandler.uuidWrapper.getOfflinePlayer(uuid)) == null) || !player.hasPlayedBefore()) {
return 0;
}
return player.getLastPlayed();
@ -1388,6 +1389,7 @@ public class PlotMain extends JavaPlugin {
@Override
@SuppressWarnings("deprecation")
final public void onEnable() {
PlotMain.main = this;
// Setup the logger mechanics
setupLogger();
// Setup translations

View File

@ -124,7 +124,7 @@ public class PlotAPI {
* @see com.intellectualcrafters.plot.PlotMain
*/
public PlotAPI(@NotNull final JavaPlugin plugin) {
this.plotMain = JavaPlugin.getPlugin(PlotMain.class);
this.plotMain = PlotMain.getMain();
if (plotMain == null) {
throw new PlotSquaredException(PlotSquaredException.PlotError.PLOTMAIN_NULL, "Failed to fetch the plotmain instance, Plot API for " + plugin.getName() + " will be disabled");
}

View File

@ -6,6 +6,8 @@ import com.intellectualcrafters.plot.database.SQLManager;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.util.PlayerFunctions;
import com.intellectualcrafters.plot.util.StringComparison;
import com.intellectualcrafters.plot.util.UUIDHandler;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
@ -36,7 +38,7 @@ public class Database extends SubCommand {
if (uuid == null) {
PlotMain.sendConsoleSenderMessage(msg);
} else {
Player p = Bukkit.getPlayer(uuid);
Player p = UUIDHandler.uuidWrapper.getPlayer(uuid);
if (p != null && p.isOnline())
return PlayerFunctions.sendMessage(p, msg);
else
@ -46,7 +48,7 @@ public class Database extends SubCommand {
}
public static void insertPlots(final SQLManager manager, final UUID requester, final Connection c) {
Plugin p = PlotMain.getPlugin(PlotMain.class);
Plugin p = PlotMain.getMain();
final java.util.Set<Plot> plots = PlotMain.getPlots();
p.getServer().getScheduler().runTaskAsynchronously(p, new Runnable() {
@Override
@ -100,7 +102,7 @@ public class Database extends SubCommand {
Connection n;
try {
n = new MySQL(
PlotMain.getPlugin(PlotMain.class),
PlotMain.getMain(),
host,
port,
database,

View File

@ -30,6 +30,7 @@ import com.intellectualcrafters.plot.util.PlayerFunctions;
import com.intellectualcrafters.plot.util.UUIDHandler;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import java.util.UUID;
@ -70,13 +71,18 @@ public class Denied extends SubCommand {
PlayerFunctions.sendMessage(plr, C.ALREADY_OWNER);
return false;
}
OfflinePlayer player = null;
if (plot.trusted.contains(uuid)) {
plot.trusted.remove(uuid);
DBFunc.removeTrusted(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(uuid));
player = UUIDHandler.uuidWrapper.getOfflinePlayer(uuid);
DBFunc.removeTrusted(plr.getWorld().getName(), plot, player);
}
if (plot.helpers.contains(uuid)) {
plot.helpers.remove(uuid);
DBFunc.removeHelper(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(uuid));
if (player == null) {
player = UUIDHandler.uuidWrapper.getOfflinePlayer(uuid);
}
DBFunc.removeHelper(plr.getWorld().getName(), plot, player);
}
plot.addDenied(uuid);
DBFunc.setDenied(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1]));
@ -86,11 +92,12 @@ public class Denied extends SubCommand {
PlayerFunctions.sendMessage(plr, C.ALREADY_ADDED);
return false;
}
if (!uuid.equals(DBFunc.everyone) && (Bukkit.getPlayer(uuid) != null) && Bukkit.getPlayer(uuid).isOnline()) {
final Plot pl = PlayerFunctions.getCurrentPlot(Bukkit.getPlayer((uuid)));
Player player = UUIDHandler.uuidWrapper.getPlayer(uuid);
if (!uuid.equals(DBFunc.everyone) && (player != null) && player.isOnline()) {
final Plot pl = PlayerFunctions.getCurrentPlot(player);
if ((pl != null) && pl.id.equals(plot.id)) {
PlayerFunctions.sendMessage(Bukkit.getPlayer(uuid), C.YOU_BE_DENIED);
Bukkit.getPlayer(uuid).teleport(Bukkit.getPlayer(uuid).getWorld().getSpawnLocation());
PlayerFunctions.sendMessage(player, C.YOU_BE_DENIED);
player.teleport(player.getWorld().getSpawnLocation());
}
}
PlayerFunctions.sendMessage(plr, C.DENIED_ADDED);

View File

@ -30,6 +30,7 @@ import com.intellectualcrafters.plot.util.PlayerFunctions;
import com.intellectualcrafters.plot.util.UUIDHandler;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import java.util.UUID;
@ -68,13 +69,18 @@ public class Helpers extends SubCommand {
PlayerFunctions.sendMessage(plr, C.ALREADY_OWNER);
return false;
}
OfflinePlayer player = null;
if (plot.trusted.contains(uuid)) {
plot.trusted.remove(uuid);
DBFunc.removeTrusted(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(uuid));
player = UUIDHandler.uuidWrapper.getOfflinePlayer(uuid);
DBFunc.removeTrusted(plr.getWorld().getName(), plot, player);
}
if (plot.denied.contains(uuid)) {
plot.denied.remove(uuid);
DBFunc.removeDenied(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(uuid));
if (player == null) {
player = UUIDHandler.uuidWrapper.getOfflinePlayer(uuid);
}
DBFunc.removeDenied(plr.getWorld().getName(), plot, player);
}
plot.addHelper(uuid);
DBFunc.setHelper(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1]));

View File

@ -115,7 +115,7 @@ public class Info extends SubCommand {
String owner = "none";
if (plot.owner != null) {
owner = Bukkit.getOfflinePlayer(plot.owner).getName();
owner = UUIDHandler.uuidWrapper.getOfflinePlayer(plot.owner).getName();
}
if (owner == null) {
owner = plot.owner.toString();
@ -179,7 +179,7 @@ public class Info extends SubCommand {
String owner = "none";
if (plot.owner != null) {
owner = Bukkit.getOfflinePlayer(plot.owner).getName();
owner = UUIDHandler.uuidWrapper.getOfflinePlayer(plot.owner).getName();
}
if (owner == null) {
owner = plot.owner.toString();

View File

@ -30,6 +30,7 @@ import com.intellectualcrafters.plot.util.PlayerFunctions;
import com.intellectualcrafters.plot.util.UUIDHandler;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import java.util.UUID;
@ -69,13 +70,18 @@ public class Trusted extends SubCommand {
PlayerFunctions.sendMessage(plr, C.ALREADY_OWNER);
return false;
}
OfflinePlayer player = null;
if (plot.helpers.contains(uuid)) {
plot.helpers.remove(uuid);
DBFunc.removeHelper(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(uuid));
player = UUIDHandler.uuidWrapper.getOfflinePlayer(uuid);
DBFunc.removeHelper(plr.getWorld().getName(), plot, player);
}
if (plot.denied.contains(uuid)) {
plot.denied.remove(uuid);
DBFunc.removeDenied(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(uuid));
if (player == null) {
player = UUIDHandler.uuidWrapper.getOfflinePlayer(uuid);
}
DBFunc.removeDenied(plr.getWorld().getName(), plot, player);
}
plot.addTrusted(uuid);
DBFunc.setTrusted(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1]));

View File

@ -91,7 +91,7 @@ public class plugin extends SubCommand {
@Override
public boolean execute(final Player plr, final String... args) {
Bukkit.getScheduler().runTaskAsynchronously(JavaPlugin.getPlugin(PlotMain.class), new Runnable() {
Bukkit.getScheduler().runTaskAsynchronously(PlotMain.getMain(), new Runnable() {
@Override
public void run() {
final ArrayList<String> strings = new ArrayList<String>() {

View File

@ -439,7 +439,7 @@ public enum C {
manager = new TranslationManager();
}
if (defaultFile == null) {
defaultFile = new YamlTranslationFile(BukkitTranslation.getParent(PlotMain.getPlugin(PlotMain.class)), lang, "PlotSquared", manager)
defaultFile = new YamlTranslationFile(BukkitTranslation.getParent(PlotMain.getMain()), lang, "PlotSquared", manager)
.read();
}
// register everything in this class

View File

@ -177,7 +177,8 @@ public class PlotPlusListener extends PlotListener implements Listener {
}
if (booleanFlag(plot, "notify-enter")) {
if (plot.hasOwner()) {
final Player player = Bukkit.getPlayer(plot.getOwner());
final Player player = UUIDHandler.uuidWrapper.getPlayer(plot.getOwner());
if (player == null) {
return;
}
@ -216,7 +217,7 @@ public class PlotPlusListener extends PlotListener implements Listener {
}
if (booleanFlag(plot, "notify-leave")) {
if (plot.hasOwner()) {
final Player player = Bukkit.getPlayer(plot.getOwner());
final Player player = UUIDHandler.uuidWrapper.getPlayer(plot.getOwner());
if (player == null) {
return;
}

View File

@ -31,6 +31,7 @@ import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.util.PWE;
import com.intellectualcrafters.plot.util.PlayerFunctions;
import com.intellectualcrafters.plot.util.PlotHelper;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.bukkit.selections.Selection;
@ -77,7 +78,7 @@ public class WorldEditListener implements Listener {
if ((plot == null) || (plot.owner == null)) {
return;
}
final Player player = Bukkit.getPlayer(plot.owner);
final Player player = UUIDHandler.uuidWrapper.getPlayer(plot.owner);
if (player == null) {
return;
}

View File

@ -76,10 +76,10 @@ public class WorldGuardListener implements Listener {
// requester.setOp(true);
// 10 ticks should be enough
final PermissionAttachment add = requester.addAttachment(JavaPlugin.getPlugin(PlotMain.class), 10);
final PermissionAttachment add = requester.addAttachment(PlotMain.getMain(), 10);
add.setPermission("worldguard.region.addowner.own.*", true);
final PermissionAttachment remove = requester.addAttachment(JavaPlugin.getPlugin(PlotMain.class), 10);
final PermissionAttachment remove = requester.addAttachment(PlotMain.getMain(), 10);
remove.setPermission("worldguard.region.removeowner.own.*", true);
try {

View File

@ -214,7 +214,7 @@ public class Plot implements Cloneable {
* @return true if the player is added as a helper or is the owner
*/
public boolean hasRights(final Player player) {
return PlotMain.hasPermission(player, "plots.admin") || ((this.helpers != null) && this.helpers.contains(DBFunc.everyone)) || ((this.helpers != null) && this.helpers.contains(UUIDHandler.getUUID(player))) || ((this.owner != null) && this.owner.equals(UUIDHandler.getUUID(player))) || ((this.owner != null) && (this.trusted != null) && (Bukkit.getPlayer(this.owner) != null) && (this.trusted.contains(UUIDHandler.getUUID(player)) || this.trusted.contains(DBFunc.everyone)));
return PlotMain.hasPermission(player, "plots.admin") || ((this.helpers != null) && this.helpers.contains(DBFunc.everyone)) || ((this.helpers != null) && this.helpers.contains(UUIDHandler.getUUID(player))) || ((this.owner != null) && this.owner.equals(UUIDHandler.getUUID(player))) || ((this.owner != null) && (this.trusted != null) && (UUIDHandler.uuidWrapper.getPlayer(this.owner) != null) && (this.trusted.contains(UUIDHandler.getUUID(player)) || this.trusted.contains(DBFunc.everyone)));
}
/**

View File

@ -2,6 +2,7 @@ package com.intellectualcrafters.plot.util;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
@ -16,5 +17,15 @@ public class DefaultUUIDWrapper extends UUIDWrapper {
public UUID getUUID(OfflinePlayer player) {
return player.getUniqueId();
}
@Override
public OfflinePlayer getOfflinePlayer(UUID uuid) {
return Bukkit.getOfflinePlayer(uuid);
}
@Override
public Player getPlayer(UUID uuid) {
return Bukkit.getPlayer(uuid);
}
}

View File

@ -2,10 +2,13 @@ package com.intellectualcrafters.plot.util;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import com.google.common.base.Charsets;
import com.google.common.collect.BiMap;
import com.intellectualcrafters.plot.object.StringWrapper;
public class OfflineUUIDWrapper extends UUIDWrapper {
@ -18,5 +21,34 @@ public class OfflineUUIDWrapper extends UUIDWrapper {
public UUID getUUID(OfflinePlayer player) {
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8));
}
@Override
public OfflinePlayer getOfflinePlayer(UUID uuid) {
BiMap<UUID, StringWrapper> map = UUIDHandler.getUuidMap().inverse();
String name = map.get(uuid).value;
if (name != null) {
return Bukkit.getOfflinePlayer(name);
}
else {
for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
if (getUUID(player).equals(uuid)) {
return player;
}
}
}
return Bukkit.getOfflinePlayer(uuid.toString());
}
@Override
public Player getPlayer(UUID uuid) {
for (Player player : Bukkit.getOnlinePlayers()) {
if (getUUID(player).equals(uuid)) {
return player;
}
}
return null;
}
}

View File

@ -55,7 +55,7 @@ public class PlayerFunctions {
* @return
*/
public static boolean hasExpired(final Plot plot) {
final OfflinePlayer player = Bukkit.getOfflinePlayer(plot.owner);
final OfflinePlayer player = UUIDHandler.uuidWrapper.getOfflinePlayer(plot.owner);
final long lp = player.getLastPlayed();
final long cu = System.currentTimeMillis();
return (lp - cu) > 30l;

View File

@ -273,7 +273,7 @@ public class PlotHelper {
if (uuid == null) {
return "unknown";
}
final OfflinePlayer plr = Bukkit.getOfflinePlayer(uuid);
final OfflinePlayer plr = UUIDHandler.uuidWrapper.getOfflinePlayer(uuid);
if (plr == null) {
return "unknown";
}

View File

@ -122,14 +122,14 @@ public class SchematicHandler {
*/
public static Schematic getSchematic(final String name) {
{
final File parent = new File(JavaPlugin.getPlugin(PlotMain.class).getDataFolder() + File.separator + "schematics");
final File parent = new File(PlotMain.getMain().getDataFolder() + File.separator + "schematics");
if (!parent.exists()) {
if (!parent.mkdir()) {
throw new RuntimeException("Could not create schematic parent directory");
}
}
}
final File file = new File(JavaPlugin.getPlugin(PlotMain.class).getDataFolder() + File.separator + "schematics" + File.separator + name + ".schematic");
final File file = new File(PlotMain.getMain().getDataFolder() + File.separator + "schematics" + File.separator + name + ".schematic");
if (!file.exists()) {
PlotMain.sendConsoleSenderMessage(file.toString() + " doesn't exist");
return null;

View File

@ -194,7 +194,7 @@ public class UUIDHandler {
if ((name = getNameOfflinePlayer(uuid)) != null) {
return name;
}
if (online) {
if (online && !Settings.OFFLINE_MODE) {
if (!Settings.CUSTOM_API) {
try {
final NameFetcher fetcher = new NameFetcher(Arrays.asList(uuid));
@ -251,7 +251,7 @@ public class UUIDHandler {
* @return String - name
*/
private static String getNameOnlinePlayer(final UUID uuid) {
final Player player = Bukkit.getPlayer(uuid);
final Player player = uuidWrapper.getPlayer(uuid);
if ((player == null) || !player.isOnline()) {
return null;
}
@ -259,13 +259,15 @@ public class UUIDHandler {
add(new StringWrapper(name), uuid);
return name;
}
/**
* @param uuid to use as key
* @return String - name
*/
private static String getNameOfflinePlayer(final UUID uuid) {
final OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
final OfflinePlayer player = uuidWrapper.getOfflinePlayer(uuid);
if ((player == null) || !player.hasPlayedBefore()) {
return null;
}

View File

@ -9,4 +9,8 @@ public abstract class UUIDWrapper {
public abstract UUID getUUID(Player player);
public abstract UUID getUUID(OfflinePlayer player);
public abstract OfflinePlayer getOfflinePlayer(UUID uuid);
public abstract Player getPlayer(UUID uuid);
}

View File

@ -46,7 +46,7 @@ public class PlotUUIDSaver implements UUIDSaver {
@Override
public void globalPopulate() {
JavaPlugin.getPlugin(PlotMain.class).getServer().getScheduler().runTaskAsynchronously(JavaPlugin.getPlugin(PlotMain.class), new Runnable() {
Bukkit.getServer().getScheduler().runTaskAsynchronously(PlotMain.getMain(), new Runnable() {
@Override
public void run() {
final OfflinePlayer[] offlinePlayers = Bukkit.getOfflinePlayers();