From 115ca903b23cabfe6d3ca36f42f840c2e74851f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Fri, 24 Jul 2020 17:36:48 +0200 Subject: [PATCH] Remove unused stuff --- .../com/plotsquared/core/PlotSquared.java | 13 - .../plotsquared/core/command/DebugExec.java | 3 +- .../com/plotsquared/core/command/Like.java | 5 +- .../com/plotsquared/core/command/Purge.java | 3 +- .../com/plotsquared/core/command/Rate.java | 6 +- .../core/util/ReflectionUtils.java | 394 ------------------ 6 files changed, 9 insertions(+), 415 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/PlotSquared.java b/Core/src/main/java/com/plotsquared/core/PlotSquared.java index 6dc1bb08c..d09477b36 100644 --- a/Core/src/main/java/com/plotsquared/core/PlotSquared.java +++ b/Core/src/main/java/com/plotsquared/core/PlotSquared.java @@ -122,7 +122,6 @@ import java.util.zip.ZipInputStream; public class PlotSquared { private static final Logger logger = LoggerFactory.getLogger("P2/" + PlotSquared.class.getSimpleName()); - private static final Set EMPTY_SET = Collections.unmodifiableSet(Collections.emptySet()); private static PlotSquared instance; // Implementation @@ -138,8 +137,6 @@ public class PlotSquared { private WorldEdit worldedit; private File configFile; private File worldsFile; - public File translationFile; // TODO: REMOVE - public YamlConfiguration style; // TODO: REMOVE private YamlConfiguration worldConfiguration; // Temporary hold the plots/clusters before the worlds load private HashMap> clustersTmp; @@ -448,16 +445,6 @@ public class PlotSquared { } - /** - * Gets all the base plots in a single set (for merged plots it just returns - * the bottom plot). - * - * @return Set of base Plots - */ - public Set getBasePlots() { - return PlotQuery.newQuery().whereBasePlot().asSet(); - } - public List sortPlotsByTemp(Collection plots) { int max = 0; int overflowCount = 0; diff --git a/Core/src/main/java/com/plotsquared/core/command/DebugExec.java b/Core/src/main/java/com/plotsquared/core/command/DebugExec.java index e7d81b2d7..926aa776a 100644 --- a/Core/src/main/java/com/plotsquared/core/command/DebugExec.java +++ b/Core/src/main/java/com/plotsquared/core/command/DebugExec.java @@ -59,6 +59,7 @@ import com.plotsquared.core.util.SetupUtils; import com.plotsquared.core.util.StringMan; import com.plotsquared.core.util.WEManager; import com.plotsquared.core.util.WorldUtil; +import com.plotsquared.core.util.query.PlotQuery; import com.plotsquared.core.util.task.RunnableVal; import com.plotsquared.core.util.task.RunnableVal2; import com.plotsquared.core.util.task.RunnableVal3; @@ -273,7 +274,7 @@ public class DebugExec extends SubCommand { final PlotFlag flagInstance = GlobalFlagContainer.getInstance().getFlagFromString(flag); if (flagInstance != null) { - for (Plot plot : PlotSquared.get().getBasePlots()) { + for (Plot plot : PlotQuery.newQuery().whereBasePlot()) { PlotFlagRemoveEvent event = this.eventDispatcher .callFlagRemove(flagInstance, plot); if (event.getEventResult() != Result.DENY) { diff --git a/Core/src/main/java/com/plotsquared/core/command/Like.java b/Core/src/main/java/com/plotsquared/core/command/Like.java index 48d8dd3a8..32d96ad1f 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Like.java +++ b/Core/src/main/java/com/plotsquared/core/command/Like.java @@ -26,7 +26,6 @@ package com.plotsquared.core.command; import com.google.inject.Inject; -import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.caption.TranslatableCaption; @@ -39,11 +38,11 @@ import com.plotsquared.core.plot.Rating; import com.plotsquared.core.plot.flag.implementations.DoneFlag; import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.Permissions; +import com.plotsquared.core.util.query.PlotQuery; import com.plotsquared.core.util.task.TaskManager; import net.kyori.adventure.text.minimessage.Template; import javax.annotation.Nonnull; -import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; @@ -69,7 +68,7 @@ public class Like extends SubCommand { if (args.length == 1) { switch (args[0].toLowerCase()) { case "next": { - final List plots = new ArrayList<>(PlotSquared.get().getBasePlots()); + final List plots = PlotQuery.newQuery().whereBasePlot().asList(); plots.sort((p1, p2) -> { double v1 = getLikesPercentage(p1); double v2 = getLikesPercentage(p2); diff --git a/Core/src/main/java/com/plotsquared/core/command/Purge.java b/Core/src/main/java/com/plotsquared/core/command/Purge.java index 136b1e163..19ee68a92 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Purge.java +++ b/Core/src/main/java/com/plotsquared/core/command/Purge.java @@ -37,6 +37,7 @@ import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotId; import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.util.StringMan; +import com.plotsquared.core.util.query.PlotQuery; import com.plotsquared.core.util.task.TaskManager; import net.kyori.adventure.text.minimessage.Template; import org.slf4j.Logger; @@ -151,7 +152,7 @@ public class Purge extends SubCommand { } } final HashSet toDelete = new HashSet<>(); - for (Plot plot : PlotSquared.get().getBasePlots()) { + for (Plot plot : PlotQuery.newQuery().whereBasePlot()) { if (world != null && !plot.getWorldName().equalsIgnoreCase(world)) { continue; } diff --git a/Core/src/main/java/com/plotsquared/core/command/Rate.java b/Core/src/main/java/com/plotsquared/core/command/Rate.java index 8f69485e7..ad9646dfc 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Rate.java +++ b/Core/src/main/java/com/plotsquared/core/command/Rate.java @@ -26,7 +26,6 @@ package com.plotsquared.core.command; import com.google.inject.Inject; -import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.caption.TranslatableCaption; @@ -43,12 +42,13 @@ import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.InventoryUtil; import com.plotsquared.core.util.MathMan; import com.plotsquared.core.util.Permissions; +import com.plotsquared.core.util.query.PlotQuery; import com.plotsquared.core.util.task.TaskManager; import net.kyori.adventure.text.minimessage.Template; import javax.annotation.Nonnull; -import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map.Entry; import java.util.UUID; @@ -74,7 +74,7 @@ public class Rate extends SubCommand { if (args.length == 1) { switch (args[0].toLowerCase()) { case "next": { - ArrayList plots = new ArrayList<>(PlotSquared.get().getBasePlots()); + final List plots = PlotQuery.newQuery().whereBasePlot().asList(); plots.sort((p1, p2) -> { double v1 = 0; if (!p1.getRatings().isEmpty()) { diff --git a/Core/src/main/java/com/plotsquared/core/util/ReflectionUtils.java b/Core/src/main/java/com/plotsquared/core/util/ReflectionUtils.java index afe86e83b..8a6f81420 100644 --- a/Core/src/main/java/com/plotsquared/core/util/ReflectionUtils.java +++ b/Core/src/main/java/com/plotsquared/core/util/ReflectionUtils.java @@ -27,13 +27,7 @@ package com.plotsquared.core.util; import java.lang.reflect.Constructor; import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; import java.util.Map; /** @@ -70,161 +64,6 @@ public class ReflectionUtils { } } - public static Method findMethod(Class clazz, boolean isStatic, Class returnType, - Class... types) { - loop: - for (Method method : clazz.getMethods()) { - Class result = method.getReturnType(); - Class[] param = method.getParameterTypes(); - int paramCount = param.length; - boolean stc = Modifier.isStatic(method.getModifiers()); - if (stc == isStatic && result == returnType && types.length == paramCount) { - for (int i = 0; i < types.length; i++) { - if (types[i] != param[i]) { - continue loop; - } - } - method.setAccessible(true); - return method; - } - } - throw new RuntimeException("no such method"); - } - - public static Field findField(Class clazz, Class fieldClass) { - for (Field field : clazz.getFields()) { - if (fieldClass == field.getType() || fieldClass.isAssignableFrom(field.getType())) { - field.setAccessible(true); - return field; - } - } - return null; - } - - public static List getStaticFields(Class clazz) { - ArrayList list = new ArrayList(); - try { - Field[] fields = clazz.getFields(); - for (Field field : fields) { - Object value = field.get(null); - try { - list.add((T) value); - } catch (ClassCastException ignored) { - } - } - } catch (IllegalAccessException | IllegalArgumentException | SecurityException e) { - e.printStackTrace(); - } - return list; - } - - public static Class getNmsClass(String name) { - String className = preClassM + '.' + name; - return getClass(className); - } - - public static Class getCbClass(String name) { - String className = preClassB + '.' + name; - return getClass(className); - } - - public static Class getUtilClass(String name) { - try { - return Class.forName(name); //Try before 1.8 first - } catch (ClassNotFoundException ignored) { - } - try { - return Class.forName("net.minecraft.util." + name); //Not 1.8 - } catch (ClassNotFoundException ignored) { - return null; - } - } - - public static Object getHandle(Object wrapper) { - Method getHandle = makeMethod(wrapper.getClass(), "getHandle"); - return callMethod(getHandle, wrapper); - } - - //Utils - public static Method makeMethod(Class clazz, String methodName, Class... paramaters) { - try { - return clazz.getDeclaredMethod(methodName, paramaters); - } catch (NoSuchMethodException ignored) { - return null; - } - } - - @SuppressWarnings("unchecked") - public static T callMethod(Method method, Object instance, Object... paramaters) { - if (method == null) { - throw new RuntimeException("No such method"); - } - method.setAccessible(true); - try { - return (T) method.invoke(instance, paramaters); - } catch (InvocationTargetException ex) { - throw new RuntimeException(ex.getCause()); - } catch (IllegalAccessException | IllegalArgumentException ex) { - throw new RuntimeException(ex); - } - } - - @SuppressWarnings("unchecked") - public static Constructor makeConstructor(Class clazz, Class... parameterTypes) { - try { - return (Constructor) clazz.getConstructor(parameterTypes); - } catch (NoSuchMethodException ignored) { - //todo print a constructor not found method - return null; - } - } - - public static T callConstructor(Constructor constructor, Object... parameters) { - if (constructor == null) { - throw new RuntimeException("No such constructor"); - } - constructor.setAccessible(true); - try { - return constructor.newInstance(parameters); - } catch (InvocationTargetException ex) { - throw new RuntimeException(ex.getCause()); - } catch (IllegalAccessException | IllegalArgumentException | InstantiationException ex) { - throw new RuntimeException(ex); - } - } - - public static Field makeField(Class clazz, String name) { - try { - return clazz.getDeclaredField(name); - } catch (NoSuchFieldException ignored) { - return null; - } - } - - @SuppressWarnings("unchecked") public static T getField(Field field, Object instance) { - if (field == null) { - throw new RuntimeException("No such field"); - } - field.setAccessible(true); - try { - return (T) field.get(instance); - } catch (IllegalAccessException | IllegalArgumentException ex) { - throw new RuntimeException(ex); - } - } - - public static void setField(Field field, Object instance, Object value) { - if (field == null) { - throw new RuntimeException("No such field"); - } - field.setAccessible(true); - try { - field.set(instance, value); - } catch (IllegalAccessException | IllegalArgumentException ex) { - throw new RuntimeException(ex); - } - } - public static Class getClass(String name) { try { return Class.forName(name); @@ -285,16 +124,6 @@ public class ReflectionUtils { return this.clazz; } - /** - * see {@link Class#isInstance(Object)} - * - * @param object the object to check - * @return true if object is an instance of this class - */ - public boolean isInstance(Object object) { - return this.clazz.isInstance(object); - } - /** * get existing method by name and types * @@ -322,143 +151,6 @@ public class ReflectionUtils { } } - /** - * get existing constructor by types - * - * @param types parameters. can be Class or RefClass - * @return RefMethod object - * @throws RuntimeException if constructor not found - */ - public RefConstructor getConstructor(Object... types) throws NoSuchMethodException { - Class[] classes = new Class[types.length]; - int i = 0; - for (Object e : types) { - if (e instanceof Class) { - classes[i++] = (Class) e; - } else if (e instanceof RefClass) { - classes[i++] = ((RefClass) e).getRealClass(); - } else { - classes[i++] = e.getClass(); - } - } - try { - return new RefConstructor(this.clazz.getConstructor(classes)); - } catch (NoSuchMethodException ignored) { - return new RefConstructor(this.clazz.getDeclaredConstructor(classes)); - } - } - - /** - * find method by type parameters - * - * @param types parameters. can be Class or RefClass - * @return RefMethod object - * @throws RuntimeException if method not found - */ - public RefMethod findMethod(Object... types) { - Class[] classes = new Class[types.length]; - int t = 0; - for (Object e : types) { - if (e instanceof Class) { - classes[t++] = (Class) e; - } else if (e instanceof RefClass) { - classes[t++] = ((RefClass) e).getRealClass(); - } else { - classes[t++] = e.getClass(); - } - } - List methods = new ArrayList<>(); - Collections.addAll(methods, this.clazz.getMethods()); - Collections.addAll(methods, this.clazz.getDeclaredMethods()); - findMethod: - for (Method m : methods) { - Class[] methodTypes = m.getParameterTypes(); - if (methodTypes.length != classes.length) { - continue; - } - for (Class aClass : classes) { - if (!Arrays.equals(classes, methodTypes)) { - continue findMethod; - } - return new RefMethod(m); - } - } - throw new RuntimeException("no such method"); - } - - /** - * find method by name - * - * @param names possible names of method - * @return RefMethod object - * @throws RuntimeException if method not found - */ - public RefMethod findMethodByName(String... names) { - List methods = new ArrayList<>(); - Collections.addAll(methods, this.clazz.getMethods()); - Collections.addAll(methods, this.clazz.getDeclaredMethods()); - for (Method m : methods) { - for (String name : names) { - if (m.getName().equals(name)) { - return new RefMethod(m); - } - } - } - throw new RuntimeException("no such method"); - } - - /** - * find method by return value - * - * @param type type of returned value - * @return RefMethod - * @throws RuntimeException if method not found - */ - public RefMethod findMethodByReturnType(RefClass type) { - return findMethodByReturnType(type.clazz); - } - - /** - * find method by return value - * - * @param type type of returned value - * @return RefMethod - * @throws RuntimeException if method not found - */ - public RefMethod findMethodByReturnType(Class type) { - if (type == null) { - type = void.class; - } - List methods = new ArrayList<>(); - Collections.addAll(methods, this.clazz.getMethods()); - Collections.addAll(methods, this.clazz.getDeclaredMethods()); - for (Method m : methods) { - if (type.equals(m.getReturnType())) { - return new RefMethod(m); - } - } - throw new RuntimeException("no such method"); - } - - /** - * find constructor by number of arguments - * - * @param number number of arguments - * @return RefConstructor - * @throws RuntimeException if constructor not found - */ - public RefConstructor findConstructor(int number) { - List constructors = new ArrayList<>(); - Collections.addAll(constructors, this.clazz.getConstructors()); - Collections.addAll(constructors, this.clazz.getDeclaredConstructors()); - for (Constructor m : constructors) { - if (m.getParameterTypes().length == number) { - return new RefConstructor(m); - } - } - throw new RuntimeException("no such constructor"); - } - /** * get field by name * @@ -474,38 +166,6 @@ public class ReflectionUtils { } } - /** - * find field by type - * - * @param type field type - * @return RefField - * @throws RuntimeException if field not found - */ - public RefField findField(RefClass type) { - return findField(type.clazz); - } - - /** - * find field by type - * - * @param type field type - * @return RefField - * @throws RuntimeException if field not found - */ - public RefField findField(Class type) { - if (type == null) { - type = void.class; - } - List fields = new ArrayList<>(); - Collections.addAll(fields, this.clazz.getFields()); - Collections.addAll(fields, this.clazz.getDeclaredFields()); - for (Field f : fields) { - if (type.equals(f.getType())) { - return new RefField(f); - } - } - throw new RuntimeException("no such field"); - } } @@ -528,20 +188,6 @@ public class ReflectionUtils { return this.method; } - /** - * @return owner class of method - */ - public RefClass getRefClass() { - return new RefClass(this.method.getDeclaringClass()); - } - - /** - * @return class of method return type - */ - public RefClass getReturnRefClass() { - return new RefClass(this.method.getReturnType()); - } - /** * apply method to object * @@ -552,19 +198,6 @@ public class ReflectionUtils { return new RefExecutor(e); } - /** - * call static method - * - * @param params sent parameters - * @return return value - */ - public Object call(Object... params) { - try { - return this.method.invoke(null, params); - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - throw new RuntimeException(e); - } - } public class RefExecutor { @@ -604,20 +237,6 @@ public class ReflectionUtils { constructor.setAccessible(true); } - /** - * @return passed constructor - */ - public Constructor getRealConstructor() { - return this.constructor; - } - - /** - * @return owner class of method - */ - public RefClass getRefClass() { - return new RefClass(this.constructor.getDeclaringClass()); - } - /** * create new instance with constructor * @@ -649,19 +268,6 @@ public class ReflectionUtils { return this.field; } - /** - * @return owner class of field - */ - public RefClass getRefClass() { - return new RefClass(this.field.getDeclaringClass()); - } - - /** - * @return type of field - */ - public RefClass getFieldRefClass() { - return new RefClass(this.field.getType()); - } /** * apply fiend for object