mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 21:26:45 +01:00
Compatability fixes for Bukkit 1.5
This commit is contained in:
parent
762bc79f38
commit
f258c37171
@ -161,7 +161,7 @@ public enum C {
|
||||
/*
|
||||
* Core Stuff
|
||||
*/
|
||||
PREFIX("&c[&6&Plot&c] "),
|
||||
PREFIX("&c[&6Plot&c] "),
|
||||
ENABLED("&6PlotSquared is now enabled"),
|
||||
EXAMPLE_MESSAGE("&cThis is an example message &k!!!"),
|
||||
/*
|
||||
|
@ -162,11 +162,9 @@ public class UUIDHandler {
|
||||
}
|
||||
|
||||
// check online
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
UUID u2 = UUIDHandler.uuidWrapper.getUUID(player);
|
||||
if (uuid.equals(u2)) {
|
||||
return player.getName();
|
||||
}
|
||||
Player player = uuidWrapper.getPlayer(uuid);
|
||||
if (player != null) {
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
// check cache
|
||||
|
@ -1,9 +1,12 @@
|
||||
package com.intellectualcrafters.plot.uuid;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
@ -13,6 +16,19 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
|
||||
public class OfflineUUIDWrapper extends UUIDWrapper {
|
||||
|
||||
private Method getOnline = null;
|
||||
private Object[] arg = new Object[0];
|
||||
|
||||
public OfflineUUIDWrapper() {
|
||||
try {
|
||||
this.getOnline = Server.class.getMethod("getOnlinePlayers", new Class[0]);
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SecurityException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUUID(final Player player) {
|
||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8));
|
||||
@ -46,9 +62,31 @@ public class OfflineUUIDWrapper extends UUIDWrapper {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Player[] getOnlinePlayers() {
|
||||
if (getOnline == null) {
|
||||
return Bukkit.getOnlinePlayers().toArray(new Player[0]);
|
||||
}
|
||||
try {
|
||||
Object players = getOnline.invoke(Bukkit.getServer(), arg);
|
||||
if (players instanceof Player[]) {
|
||||
return (Player[]) players;
|
||||
}
|
||||
else {
|
||||
@SuppressWarnings("unchecked")
|
||||
Collection<? extends Player> p = (Collection<? extends Player>) players;
|
||||
return p.toArray(new Player[0]);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.out.print("Failed to resolve online players");
|
||||
getOnline = null;
|
||||
return Bukkit.getOnlinePlayers().toArray(new Player[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Player getPlayer(final UUID uuid) {
|
||||
for (final Player player : Bukkit.getOnlinePlayers()) {
|
||||
for (final Player player : getOnlinePlayers()) {
|
||||
if (getUUID(player).equals(uuid)) {
|
||||
return player;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user