mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-13 10:34:09 +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
|
* Core Stuff
|
||||||
*/
|
*/
|
||||||
PREFIX("&c[&6&Plot&c] "),
|
PREFIX("&c[&6Plot&c] "),
|
||||||
ENABLED("&6PlotSquared is now enabled"),
|
ENABLED("&6PlotSquared is now enabled"),
|
||||||
EXAMPLE_MESSAGE("&cThis is an example message &k!!!"),
|
EXAMPLE_MESSAGE("&cThis is an example message &k!!!"),
|
||||||
/*
|
/*
|
||||||
|
@ -162,11 +162,9 @@ public class UUIDHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check online
|
// check online
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
Player player = uuidWrapper.getPlayer(uuid);
|
||||||
UUID u2 = UUIDHandler.uuidWrapper.getUUID(player);
|
if (player != null) {
|
||||||
if (uuid.equals(u2)) {
|
return player.getName();
|
||||||
return player.getName();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// check cache
|
// check cache
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
package com.intellectualcrafters.plot.uuid;
|
package com.intellectualcrafters.plot.uuid;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.Server;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
@ -13,6 +16,19 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
|
|||||||
|
|
||||||
public class OfflineUUIDWrapper extends UUIDWrapper {
|
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
|
@Override
|
||||||
public UUID getUUID(final Player player) {
|
public UUID getUUID(final Player player) {
|
||||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8));
|
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8));
|
||||||
@ -46,9 +62,31 @@ public class OfflineUUIDWrapper extends UUIDWrapper {
|
|||||||
return null;
|
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
|
@Override
|
||||||
public Player getPlayer(final UUID uuid) {
|
public Player getPlayer(final UUID uuid) {
|
||||||
for (final Player player : Bukkit.getOnlinePlayers()) {
|
for (final Player player : getOnlinePlayers()) {
|
||||||
if (getUUID(player).equals(uuid)) {
|
if (getUUID(player).equals(uuid)) {
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user