mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-26 07:06:44 +01:00
FIxed plot cluster + some debug stuff
This commit is contained in:
parent
79564eed08
commit
7b2944c466
@ -25,6 +25,7 @@ import com.intellectualcrafters.plot.commands.BukkitCommand;
|
||||
import com.intellectualcrafters.plot.commands.Chat;
|
||||
import com.intellectualcrafters.plot.commands.Claim;
|
||||
import com.intellectualcrafters.plot.commands.Clear;
|
||||
import com.intellectualcrafters.plot.commands.Cluster;
|
||||
import com.intellectualcrafters.plot.commands.Comment;
|
||||
import com.intellectualcrafters.plot.commands.Condense;
|
||||
import com.intellectualcrafters.plot.commands.Confirm;
|
||||
@ -253,6 +254,9 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
||||
MainCommand.subCommands.add(new Clear());
|
||||
MainCommand.subCommands.add(new Delete());
|
||||
MainCommand.subCommands.add(new SetOwner());
|
||||
if (Settings.ENABLE_CLUSTERS) {
|
||||
MainCommand.subCommands.add(new Cluster());
|
||||
}
|
||||
|
||||
MainCommand.subCommands.add(new Trust());
|
||||
MainCommand.subCommands.add(new Add());
|
||||
|
@ -25,7 +25,6 @@ import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.Lag;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.RUtils;
|
||||
|
||||
public class Debug extends SubCommand {
|
||||
public Debug() {
|
||||
@ -63,9 +62,6 @@ public class Debug extends SubCommand {
|
||||
information.append(getSection(section, "PlotWorld"));
|
||||
information.append(getLine(line, "Plot Worlds", worlds));
|
||||
information.append(getLine(line, "Owned Plots", PlotSquared.getPlots().size()));
|
||||
information.append(getSection(section, "RAM"));
|
||||
information.append(getLine(line, "Free Ram", RUtils.getFreeRam() + "MB"));
|
||||
information.append(getLine(line, "Total Ram", RUtils.getTotalRam() + "MB"));
|
||||
information.append(getSection(section, "Messages"));
|
||||
information.append(getLine(line, "Total Messages", C.values().length));
|
||||
information.append(getLine(line, "View all captions", "/plot debug msg"));
|
||||
|
@ -22,6 +22,7 @@ package com.intellectualcrafters.plot.generator;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
@ -150,6 +151,9 @@ public class HybridPlotWorld extends ClassicPlotWorld {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.ROAD_SCHEMATIC_ENABLED = true;
|
||||
|
||||
if ((schem1 == null) || (schem2 == null) || (this.ROAD_WIDTH == 0)) {
|
||||
PlotSquared.log(C.PREFIX.s() + "&3 - schematic: &7false");
|
||||
return;
|
||||
@ -192,7 +196,6 @@ public class HybridPlotWorld extends ClassicPlotWorld {
|
||||
}
|
||||
}
|
||||
}
|
||||
this.ROAD_SCHEMATIC_ENABLED = true;
|
||||
}
|
||||
|
||||
public static byte wrap(byte data, int start) {
|
||||
|
@ -1,92 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.util;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
|
||||
/**
|
||||
* Random utilities
|
||||
*
|
||||
* @author Citymonstret
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class RUtils {
|
||||
/**
|
||||
* Get the total allocated ram
|
||||
*
|
||||
* @return total ram
|
||||
*/
|
||||
public static long getTotalRam() {
|
||||
return (Runtime.getRuntime().totalMemory() / 1024) / 1024;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the total free ram
|
||||
*
|
||||
* @return free ram
|
||||
*/
|
||||
public static long getFreeRam() {
|
||||
return (Runtime.getRuntime().freeMemory() / 1024) / 1024;
|
||||
}
|
||||
|
||||
/**
|
||||
* Percentage of used ram
|
||||
*
|
||||
* @return percentage
|
||||
*/
|
||||
public static long getRamPercentage() {
|
||||
return (getFreeRam() / getTotalRam()) * 100;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get formatted time
|
||||
*
|
||||
* @param sec seconds
|
||||
*
|
||||
* @return formatted time
|
||||
*/
|
||||
public static String formatTime(final double sec) {
|
||||
final double h = sec / 3600;
|
||||
final double m = (sec % 3600) / 60;
|
||||
final double s = sec % 60;
|
||||
final String string = C.TIME_FORMAT.s();
|
||||
final String s_h = (int) h + " " + ((int) h != 1 ? "hours" : "hour");
|
||||
final String s_m = (int) m + " " + ((int) m != 1 ? "minutes" : "minute");
|
||||
final String s_s = (int) s + " " + ((int) s != 1 ? "seconds" : "second");
|
||||
return string.replaceAll("%sec%", s_s).replaceAll("%min%", s_m).replaceAll("%hours%", s_h);
|
||||
}
|
||||
|
||||
enum Direction {
|
||||
SOUTH(0),
|
||||
EAST(1),
|
||||
NORTH(2),
|
||||
WEST(3);
|
||||
private final int i;
|
||||
|
||||
Direction(final int i) {
|
||||
this.i = i;
|
||||
}
|
||||
|
||||
public int getInt() {
|
||||
return this.i;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,148 @@
|
||||
package com.intellectualcrafters.plot.util;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
/**
|
||||
* Reflection Utilities for minecraft
|
||||
*
|
||||
*/
|
||||
public class ReflectionUtil {
|
||||
public static Class<?> getNmsClass(final String name) {
|
||||
final String className = "net.minecraft.server." + getVersion() + "." + name;
|
||||
return getClass(className);
|
||||
}
|
||||
|
||||
public static Class<?> getCbClass(final String name) {
|
||||
final String className = "org.bukkit.craftbukkit." + getVersion() + "." + name;
|
||||
return getClass(className);
|
||||
}
|
||||
|
||||
public static Class<?> getUtilClass(final String name) {
|
||||
try {
|
||||
return Class.forName(name); //Try before 1.8 first
|
||||
} catch (final ClassNotFoundException ex) {
|
||||
try {
|
||||
return Class.forName("net.minecraft.util." + name); //Not 1.8
|
||||
} catch (final ClassNotFoundException ex2) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String getVersion() {
|
||||
final String packageName = Bukkit.getServer().getClass().getPackage().getName();
|
||||
return packageName.substring(packageName.lastIndexOf('.') + 1);
|
||||
}
|
||||
|
||||
public static Object getHandle(final Object wrapper) {
|
||||
final Method getHandle = makeMethod(wrapper.getClass(), "getHandle");
|
||||
return callMethod(getHandle, wrapper);
|
||||
}
|
||||
|
||||
//Utils
|
||||
public static Method makeMethod(final Class<?> clazz, final String methodName, final Class<?>... paramaters) {
|
||||
try {
|
||||
return clazz.getDeclaredMethod(methodName, paramaters);
|
||||
} catch (final NoSuchMethodException ex) {
|
||||
return null;
|
||||
} catch (final Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T callMethod(final Method method, final Object instance, final Object... paramaters) {
|
||||
if (method == null) {
|
||||
throw new RuntimeException("No such method");
|
||||
}
|
||||
method.setAccessible(true);
|
||||
try {
|
||||
return (T) method.invoke(instance, paramaters);
|
||||
} catch (final InvocationTargetException ex) {
|
||||
throw new RuntimeException(ex.getCause());
|
||||
} catch (final Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> Constructor<T> makeConstructor(final Class<?> clazz, final Class<?>... paramaterTypes) {
|
||||
try {
|
||||
return (Constructor<T>) clazz.getConstructor(paramaterTypes);
|
||||
} catch (final NoSuchMethodException ex) {
|
||||
return null;
|
||||
} catch (final Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T callConstructor(final Constructor<T> constructor, final Object... paramaters) {
|
||||
if (constructor == null) {
|
||||
throw new RuntimeException("No such constructor");
|
||||
}
|
||||
constructor.setAccessible(true);
|
||||
try {
|
||||
return constructor.newInstance(paramaters);
|
||||
} catch (final InvocationTargetException ex) {
|
||||
throw new RuntimeException(ex.getCause());
|
||||
} catch (final Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static Field makeField(final Class<?> clazz, final String name) {
|
||||
try {
|
||||
return clazz.getDeclaredField(name);
|
||||
} catch (final NoSuchFieldException ex) {
|
||||
return null;
|
||||
} catch (final Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T getField(final Field field, final Object instance) {
|
||||
if (field == null) {
|
||||
throw new RuntimeException("No such field");
|
||||
}
|
||||
field.setAccessible(true);
|
||||
try {
|
||||
return (T) field.get(instance);
|
||||
} catch (final Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setField(final Field field, final Object instance, final Object value) {
|
||||
if (field == null) {
|
||||
throw new RuntimeException("No such field");
|
||||
}
|
||||
field.setAccessible(true);
|
||||
try {
|
||||
field.set(instance, value);
|
||||
} catch (final Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static Class<?> getClass(final String name) {
|
||||
try {
|
||||
return Class.forName(name);
|
||||
} catch (final ClassNotFoundException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> Class<? extends T> getClass(final String name, final Class<T> superClass) {
|
||||
try {
|
||||
return Class.forName(name).asSubclass(superClass);
|
||||
} catch (ClassCastException | ClassNotFoundException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -22,6 +22,7 @@ package com.intellectualcrafters.plot.util;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -76,6 +77,140 @@ public class ReflectionUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static Class<?> getNmsClass(final String name) {
|
||||
final String className = "net.minecraft.server." + getVersion() + "." + name;
|
||||
return getClass(className);
|
||||
}
|
||||
|
||||
public static Class<?> getCbClass(final String name) {
|
||||
final String className = "org.bukkit.craftbukkit." + getVersion() + "." + name;
|
||||
return getClass(className);
|
||||
}
|
||||
|
||||
public static Class<?> getUtilClass(final String name) {
|
||||
try {
|
||||
return Class.forName(name); //Try before 1.8 first
|
||||
} catch (final ClassNotFoundException ex) {
|
||||
try {
|
||||
return Class.forName("net.minecraft.util." + name); //Not 1.8
|
||||
} catch (final ClassNotFoundException ex2) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String getVersion() {
|
||||
final String packageName = Bukkit.getServer().getClass().getPackage().getName();
|
||||
return packageName.substring(packageName.lastIndexOf('.') + 1);
|
||||
}
|
||||
|
||||
public static Object getHandle(final Object wrapper) {
|
||||
final Method getHandle = makeMethod(wrapper.getClass(), "getHandle");
|
||||
return callMethod(getHandle, wrapper);
|
||||
}
|
||||
|
||||
//Utils
|
||||
public static Method makeMethod(final Class<?> clazz, final String methodName, final Class<?>... paramaters) {
|
||||
try {
|
||||
return clazz.getDeclaredMethod(methodName, paramaters);
|
||||
} catch (final NoSuchMethodException ex) {
|
||||
return null;
|
||||
} catch (final Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T callMethod(final Method method, final Object instance, final Object... paramaters) {
|
||||
if (method == null) {
|
||||
throw new RuntimeException("No such method");
|
||||
}
|
||||
method.setAccessible(true);
|
||||
try {
|
||||
return (T) method.invoke(instance, paramaters);
|
||||
} catch (final InvocationTargetException ex) {
|
||||
throw new RuntimeException(ex.getCause());
|
||||
} catch (final Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> Constructor<T> makeConstructor(final Class<?> clazz, final Class<?>... paramaterTypes) {
|
||||
try {
|
||||
return (Constructor<T>) clazz.getConstructor(paramaterTypes);
|
||||
} catch (final NoSuchMethodException ex) {
|
||||
return null;
|
||||
} catch (final Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T callConstructor(final Constructor<T> constructor, final Object... paramaters) {
|
||||
if (constructor == null) {
|
||||
throw new RuntimeException("No such constructor");
|
||||
}
|
||||
constructor.setAccessible(true);
|
||||
try {
|
||||
return constructor.newInstance(paramaters);
|
||||
} catch (final InvocationTargetException ex) {
|
||||
throw new RuntimeException(ex.getCause());
|
||||
} catch (final Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static Field makeField(final Class<?> clazz, final String name) {
|
||||
try {
|
||||
return clazz.getDeclaredField(name);
|
||||
} catch (final NoSuchFieldException ex) {
|
||||
return null;
|
||||
} catch (final Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T getField(final Field field, final Object instance) {
|
||||
if (field == null) {
|
||||
throw new RuntimeException("No such field");
|
||||
}
|
||||
field.setAccessible(true);
|
||||
try {
|
||||
return (T) field.get(instance);
|
||||
} catch (final Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setField(final Field field, final Object instance, final Object value) {
|
||||
if (field == null) {
|
||||
throw new RuntimeException("No such field");
|
||||
}
|
||||
field.setAccessible(true);
|
||||
try {
|
||||
field.set(instance, value);
|
||||
} catch (final Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static Class<?> getClass(final String name) {
|
||||
try {
|
||||
return Class.forName(name);
|
||||
} catch (final ClassNotFoundException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> Class<? extends T> getClass(final String name, final Class<T> superClass) {
|
||||
try {
|
||||
return Class.forName(name).asSubclass(superClass);
|
||||
} catch (ClassCastException | ClassNotFoundException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if server has forge classes
|
||||
*/
|
||||
|
@ -0,0 +1,92 @@
|
||||
package com.intellectualcrafters.plot.util.bukkit;
|
||||
|
||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.callConstructor;
|
||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.callMethod;
|
||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.getCbClass;
|
||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.getNmsClass;
|
||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.getUtilClass;
|
||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.makeConstructor;
|
||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.makeMethod;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class OfflinePlayerUtil {
|
||||
|
||||
public static Player loadPlayer(final String name) {
|
||||
return loadPlayer(Bukkit.getOfflinePlayer(name));
|
||||
}
|
||||
|
||||
public static Player loadPlayer(final UUID id) {
|
||||
return loadPlayer(Bukkit.getOfflinePlayer(id));
|
||||
}
|
||||
|
||||
public static Player loadPlayer(final OfflinePlayer player) {
|
||||
if (player == null) {
|
||||
return null;
|
||||
}
|
||||
if (player instanceof Player) {
|
||||
return (Player) player;
|
||||
}
|
||||
return loadPlayer(player.getUniqueId(), player.getName());
|
||||
}
|
||||
|
||||
private static Player loadPlayer(final UUID id, final String name) {
|
||||
final Object server = getMinecraftServer();
|
||||
final Object interactManager = newPlayerInteractManager();
|
||||
final Object worldServer = getWorldServer();
|
||||
final Object profile = newGameProfile(id, name);
|
||||
final Class<?> entityPlayerClass = getNmsClass("EntityPlayer");
|
||||
final Constructor entityPlayerConstructor = makeConstructor(entityPlayerClass, getNmsClass("MinecraftServer"), getNmsClass("WorldServer"), getUtilClass("com.mojang.authlib.GameProfile"), getNmsClass("PlayerInteractManager"));
|
||||
final Object entityPlayer = callConstructor(entityPlayerConstructor, server, worldServer, profile, interactManager);
|
||||
final Player player = (Player) getBukkitEntity(entityPlayer);
|
||||
return player;
|
||||
}
|
||||
|
||||
private static Object newGameProfile(final UUID id, final String name) {
|
||||
final Class<?> gameProfileClass = getUtilClass("com.mojang.authlib.GameProfile");
|
||||
if (gameProfileClass == null) { //Before uuids
|
||||
return name;
|
||||
}
|
||||
Constructor gameProfileConstructor = null;
|
||||
gameProfileConstructor = makeConstructor(gameProfileClass, UUID.class, String.class);
|
||||
if (gameProfileConstructor == null) { //Verson has string constructor
|
||||
gameProfileConstructor = makeConstructor(gameProfileClass, String.class, String.class);
|
||||
return callConstructor(gameProfileConstructor, id.toString(), name);
|
||||
} else { //Version has uuid constructor
|
||||
return callConstructor(gameProfileConstructor, id, name);
|
||||
}
|
||||
}
|
||||
|
||||
private static Object newPlayerInteractManager() {
|
||||
final Object worldServer = getWorldServer();
|
||||
final Class<?> playerInteractClass = getNmsClass("PlayerInteractManager");
|
||||
final Class<?> worldClass = getNmsClass("World");
|
||||
final Constructor c = makeConstructor(playerInteractClass, worldClass);
|
||||
return callConstructor(c, worldServer);
|
||||
}
|
||||
|
||||
private static Object getWorldServer() {
|
||||
final Object server = getMinecraftServer();
|
||||
final Class<?> minecraftServerClass = getNmsClass("MinecraftServer");
|
||||
final Method getWorldServer = makeMethod(minecraftServerClass, "getWorldServer", int.class);
|
||||
return callMethod(getWorldServer, server, 0);
|
||||
}
|
||||
|
||||
//NMS Utils
|
||||
|
||||
private static Object getMinecraftServer() {
|
||||
return callMethod(makeMethod(getCbClass("CraftServer"), "getServer"), Bukkit.getServer());
|
||||
}
|
||||
|
||||
private static Entity getBukkitEntity(final Object o) {
|
||||
final Method getBukkitEntity = makeMethod(o.getClass(), "getBukkitEntity");
|
||||
return callMethod(getBukkitEntity, o);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user