Compare commits

..

16 Commits
1.0.1 ... 1.1.3

Author SHA1 Message Date
Auxilor
2a2aed52e0 Optimised VectorUtils getCircle() 2021-01-12 14:52:36 +00:00
Auxilor
b16266e22a Cleaned up numerals 2021-01-10 20:05:50 +00:00
Auxilor
2c886dc33b Updated to 1.1.2 2021-01-10 18:51:37 +00:00
Auxilor
db9c60cf35 Added fromNumeral method 2021-01-10 18:51:21 +00:00
Auxilor
a34b36daec Updated to 1.1.1 2021-01-08 22:18:17 +00:00
Auxilor
41a35e99fd Call update is now invoked twice 2021-01-08 22:18:00 +00:00
Auxilor
8e12dad247 Added players to packet adapters 2021-01-08 08:02:15 +00:00
Auxilor
72afa1e5cc Updated to 1.1.0 2021-01-08 08:01:21 +00:00
Auxilor
9904553325 Updated to 1.0.6 2021-01-05 14:17:41 +00:00
Auxilor
ad069ab32f Cleaned up loader 2021-01-05 14:17:26 +00:00
Auxilor
b83a3dd548 Fixed TelekinesisUtils and updated to 1.0.5 2021-01-05 09:09:05 +00:00
Auxilor
7f41eab5e4 Fixed compileOnly issues with jitpack 2021-01-04 12:46:00 +00:00
Auxilor
0d1c2364da Fixed telekinesistests registration and updated to 1.0.4 2021-01-04 12:45:05 +00:00
Auxilor
5bca33a9f5 Added protected getter for BaseConfig and updated to 1.0.3 2021-01-02 17:55:22 +00:00
Auxilor
1196fe8004 Updated to 1.0.2 2021-01-01 16:54:05 +00:00
Auxilor
98ae416fa7 Reduced loaded integration verbosity 2021-01-01 16:53:32 +00:00
7 changed files with 104 additions and 26 deletions

View File

@@ -20,7 +20,7 @@ dependencies {
compileOnly 'fr.neatmonster:nocheatplus:3.16.1-SNAPSHOT' compileOnly 'fr.neatmonster:nocheatplus:3.16.1-SNAPSHOT'
compileOnly 'com.github.jiangdashao:matrix-api-repo:317d4635fd' compileOnly 'com.github.jiangdashao:matrix-api-repo:317d4635fd'
compileOnly 'org.jetbrains:annotations:19.0.0' compileOnly 'org.jetbrains:annotations:19.0.0'
compileOnly fileTree(dir: '/lib', include: ['*.jar']) compileOnly fileTree(dir: 'lib', include: ['*.jar'])
// Lombok // Lombok
compileOnly 'org.projectlombok:lombok:1.18.16' compileOnly 'org.projectlombok:lombok:1.18.16'
@@ -98,5 +98,5 @@ build.dependsOn publishToMavenLocal
group = 'com.willfp' group = 'com.willfp'
archivesBaseName = project.name archivesBaseName = project.name
version = '1.0.1' version = '1.1.3'
java.sourceCompatibility = JavaVersion.VERSION_1_8 java.sourceCompatibility = JavaVersion.VERSION_1_8

View File

@@ -3,6 +3,7 @@ package com.willfp.eco.util;
import lombok.experimental.UtilityClass; import lombok.experimental.UtilityClass;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
@@ -85,6 +86,22 @@ public class NumberUtils {
} }
} }
/**
* Get number from roman numeral.
*
* @param numeral The numeral to convert.
* @return The number, converted from a roman numeral.
*/
public static int fromNumeral(String numeral) {
if (numeral.isEmpty()) return 0;
for (Map.Entry<Integer, String> entry : NUMERALS.entrySet()) {
if (numeral.startsWith(entry.getValue())) {
return entry.getKey() + fromNumeral(numeral.substring(entry.getValue().length()));
}
}
return 0;
}
/** /**
* Generate random integer in range. * Generate random integer in range.
* *

View File

@@ -6,9 +6,16 @@ import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
@UtilityClass @UtilityClass
public class VectorUtils { public class VectorUtils {
/**
* Cached circles to prevent many sqrt calls.
*/
private final Map<Integer, Vector[]> CIRCLE_CACHE = new HashMap<>();
/** /**
* If vector has all components as finite. * If vector has all components as finite.
* *
@@ -66,6 +73,11 @@ public class VectorUtils {
* @return An array of {@link Vector}s. * @return An array of {@link Vector}s.
*/ */
public Vector[] getCircle(final int radius) { public Vector[] getCircle(final int radius) {
Vector[] cached = CIRCLE_CACHE.get(radius);
if (cached != null) {
return cached;
}
ArrayList<Vector> circleVecs = new ArrayList<>(); ArrayList<Vector> circleVecs = new ArrayList<>();
double xoffset = -radius; double xoffset = -radius;
@@ -85,7 +97,9 @@ public class VectorUtils {
zoffset++; zoffset++;
} }
return circleVecs.toArray(new Vector[0]); Vector[] result = circleVecs.toArray(new Vector[0]);
CIRCLE_CACHE.put(radius, result);
return result;
} }
/** /**

View File

@@ -28,6 +28,7 @@ public abstract class BaseConfig extends PluginDependent implements ValueGetter
/** /**
* The physical config file, as stored on disk. * The physical config file, as stored on disk.
*/ */
@Getter(AccessLevel.PROTECTED)
private final File configFile; private final File configFile;
/** /**

View File

@@ -7,14 +7,21 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.ServicePriority; import org.bukkit.plugin.ServicePriority;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.function.Function; import java.util.function.Function;
@UtilityClass @UtilityClass
public final class TelekinesisUtils { public final class TelekinesisUtils {
private final Object instance;
private final Class<?> clazz;
/** /**
* The test service registered to bukkit. * The test service registered to bukkit.
*/ */
private final TelekinesisTests tests; private final Method testMethod;
private final Method registerMethod;
/** /**
* Test the player for telekinesis. * Test the player for telekinesis.
@@ -25,7 +32,13 @@ public final class TelekinesisUtils {
* @return If the player is telekinetic. * @return If the player is telekinetic.
*/ */
public boolean testPlayer(@NotNull final Player player) { public boolean testPlayer(@NotNull final Player player) {
return tests.testPlayer(player); try {
return (boolean) testMethod.invoke(instance, player);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
return false;
} }
/** /**
@@ -34,14 +47,33 @@ public final class TelekinesisUtils {
* @param test The test to register, where the boolean output is if the player is telekinetic. * @param test The test to register, where the boolean output is if the player is telekinetic.
*/ */
public void registerTest(@NotNull final Function<Player, Boolean> test) { public void registerTest(@NotNull final Function<Player, Boolean> test) {
tests.registerTest(test); try {
registerMethod.invoke(instance, test);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
} }
static { static {
if (!Bukkit.getServicesManager().isProvidedFor(TelekinesisTests.class)) { Method testMethod1;
Method registerMethod1;
if (Bukkit.getServicesManager().getKnownServices().stream().noneMatch(clazz -> clazz.getName().contains("TelekinesisTests"))) {
Bukkit.getServicesManager().register(TelekinesisTests.class, new EcoTelekinesisTests(), AbstractEcoPlugin.getInstance(), ServicePriority.Normal); Bukkit.getServicesManager().register(TelekinesisTests.class, new EcoTelekinesisTests(), AbstractEcoPlugin.getInstance(), ServicePriority.Normal);
} }
tests = Bukkit.getServicesManager().load(TelekinesisTests.class); instance = Bukkit.getServicesManager().load(Bukkit.getServicesManager().getKnownServices().stream().filter(clazz -> clazz.getName().contains("TelekinesisTests")).findFirst().get());
clazz = instance.getClass();
try {
testMethod1 = clazz.getDeclaredMethod("testPlayer", Player.class);
registerMethod1 = clazz.getDeclaredMethod("registerTest", Function.class);
} catch (NoSuchMethodException e) {
e.printStackTrace();
testMethod1 = null;
registerMethod1 = null;
}
testMethod = testMethod1;
registerMethod = registerMethod1;
} }
} }

View File

@@ -51,6 +51,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@@ -86,6 +87,18 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
@Getter @Getter
private final String proxyPackage; private final String proxyPackage;
/**
* The color of the plugin, used in messages.
*/
@Getter
private final String color;
/**
* Loaded integrations.
*/
@Getter
private final Set<String> loadedIntegrations = new HashSet<>();
/** /**
* Set of external plugin integrations. * Set of external plugin integrations.
*/ */
@@ -159,15 +172,18 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
* @param resourceId The spigot resource ID for the plugin. * @param resourceId The spigot resource ID for the plugin.
* @param bStatsId The bStats resource ID for the plugin. * @param bStatsId The bStats resource ID for the plugin.
* @param proxyPackage The package where proxy implementations are stored. * @param proxyPackage The package where proxy implementations are stored.
* @param color The color of the plugin (used in messages, such as &a, &b)
*/ */
protected AbstractEcoPlugin(@NotNull final String pluginName, protected AbstractEcoPlugin(@NotNull final String pluginName,
final int resourceId, final int resourceId,
final int bStatsId, final int bStatsId,
@NotNull final String proxyPackage) { @NotNull final String proxyPackage,
@NotNull final String color) {
this.pluginName = pluginName; this.pluginName = pluginName;
this.resourceId = resourceId; this.resourceId = resourceId;
this.bStatsId = bStatsId; this.bStatsId = bStatsId;
this.proxyPackage = proxyPackage; this.proxyPackage = proxyPackage;
this.color = color;
this.log = new EcoLogger(this); this.log = new EcoLogger(this);
this.scheduler = new EcoScheduler(this); this.scheduler = new EcoScheduler(this);
@@ -186,12 +202,8 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
public final void onEnable() { public final void onEnable() {
super.onLoad(); super.onLoad();
this.getLog().info("==========================================");
this.getLog().info(""); this.getLog().info("");
this.getLog().info("Loading &a" + this.pluginName); this.getLog().info("Loading " + this.color + this.pluginName);
this.getLog().info("Made by &aAuxilor&f - willfp.com");
this.getLog().info("");
this.getLog().info("==========================================");
this.getEventManager().registerListener(new ArrowDataListener(this)); this.getEventManager().registerListener(new ArrowDataListener(this));
this.getEventManager().registerListener(new NaturalExpGainListeners()); this.getEventManager().registerListener(new NaturalExpGainListeners());
@@ -219,17 +231,13 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
Set<String> enabledPlugins = Arrays.stream(Bukkit.getPluginManager().getPlugins()).map(Plugin::getName).collect(Collectors.toSet()); Set<String> enabledPlugins = Arrays.stream(Bukkit.getPluginManager().getPlugins()).map(Plugin::getName).collect(Collectors.toSet());
this.getDefaultIntegrations().forEach((integrationLoader -> { this.getDefaultIntegrations().forEach((integrationLoader -> {
StringBuilder infoBuilder = new StringBuilder();
infoBuilder.append(integrationLoader.getPluginName()).append(": ");
if (enabledPlugins.contains(integrationLoader.getPluginName())) { if (enabledPlugins.contains(integrationLoader.getPluginName())) {
this.loadedIntegrations.add(integrationLoader.getPluginName());
integrationLoader.load(); integrationLoader.load();
infoBuilder.append("&aENABLED");
} else {
infoBuilder.append("&9DISABLED");
} }
this.getLog().info(infoBuilder.toString());
})); }));
this.getLog().info("");
this.getLog().info("Loaded integrations: " + String.join(", ", this.getLoadedIntegrations()));
Prerequisite.update(); Prerequisite.update();
@@ -256,6 +264,8 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
this.updatableClasses.forEach(clazz -> this.getConfigHandler().registerUpdatableClass(clazz)); this.updatableClasses.forEach(clazz -> this.getConfigHandler().registerUpdatableClass(clazz));
this.enable(); this.enable();
this.getLog().info("");
} }
/** /**
@@ -312,7 +322,7 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
this.reload(); this.reload();
this.getLog().info("Loaded &a" + this.pluginName); this.getLog().info("Loaded " + this.color + this.pluginName);
} }
/** /**
@@ -320,6 +330,7 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
*/ */
public final void reload() { public final void reload() {
this.getConfigHandler().callUpdate(); this.getConfigHandler().callUpdate();
this.getConfigHandler().callUpdate(); // Call twice to fix issues
this.getScheduler().cancelAll(); this.getScheduler().cancelAll();
new FastCollatedDropQueue.CollatedRunnable(this); new FastCollatedDropQueue.CollatedRunnable(this);

View File

@@ -8,6 +8,7 @@ import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.events.PacketEvent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin; import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import lombok.Getter; import lombok.Getter;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.Collections; import java.util.Collections;
@@ -61,7 +62,8 @@ public abstract class AbstractPacketAdapter extends PacketAdapter {
* *
* @param packet The packet. * @param packet The packet.
*/ */
public void onReceive(@NotNull final PacketContainer packet) { public void onReceive(@NotNull final PacketContainer packet,
@NotNull final Player player) {
// Empty rather than abstract as implementations don't need both // Empty rather than abstract as implementations don't need both
} }
@@ -70,7 +72,8 @@ public abstract class AbstractPacketAdapter extends PacketAdapter {
* *
* @param packet The packet. * @param packet The packet.
*/ */
public void onSend(@NotNull final PacketContainer packet) { public void onSend(@NotNull final PacketContainer packet,
@NotNull final Player player) {
// Empty rather than abstract as implementations don't need both // Empty rather than abstract as implementations don't need both
} }
@@ -89,7 +92,7 @@ public abstract class AbstractPacketAdapter extends PacketAdapter {
return; return;
} }
onReceive(event.getPacket()); onReceive(event.getPacket(), event.getPlayer());
} }
/** /**
@@ -107,7 +110,7 @@ public abstract class AbstractPacketAdapter extends PacketAdapter {
return; return;
} }
onSend(event.getPacket()); onSend(event.getPacket(), event.getPlayer());
} }
/** /**