From 8fcf40a8f24be5f148744d5670b61b4931e52033 Mon Sep 17 00:00:00 2001
From: Hempfest <64885225+Hempfest@users.noreply.github.com>
Date: Mon, 30 May 2022 22:47:53 -0700
Subject: [PATCH] * Completely removed old task scheduling utility for newly
optimized alternative. * Optimized task execution handling. * Added new
isModded check to LegacyCheckService * Added new toBlockFace method to
DirectivePoint * Optimized internal Unity task executions. * Finalized
OrdinalProcedure service. * Completely removed old PaginatedList.java
utility. * Finalized sub-command injection handling. * Optimized and fixed
remaining issues with Message.java abstraction in tandem with ComponentUtil.
---
labyrinth-common/pom.xml | 2 +-
.../labyrinth/api/LegacyCheckService.java | 6 +
.../labyrinth/command/SubCommandList.java | 79 +++-
.../sanctum/labyrinth/data/AddonLoader.java | 5 +-
.../labyrinth/data/ConfigurableNode.java | 30 +-
.../data/service/AnnotationDiscovery.java | 32 +-
.../formatting/ComponentCompliment.java | 12 -
.../formatting/ComponentDecoration.java | 12 -
.../labyrinth/formatting/ComponentUtil.java | 2 +-
.../formatting/FinishingCompliment.java | 11 -
.../labyrinth/formatting/PaginatedList.java | 205 -----------
.../formatting/PrintedPaginationBuilder.java | 91 -----
.../formatting/StartingCompliment.java | 10 -
.../labyrinth/formatting/TablistInstance.java | 10 +-
.../formatting/string/ImageBreakdown.java | 2 +-
.../labyrinth/interfacing/Catchable.java | 9 +-
.../labyrinth/interfacing/OrdinalElement.java | 4 +
.../interfacing/OrdinalProcedure.java | 249 ++++++++++++-
.../labyrinth/interfacing/OrdinalResult.java | 46 +++
.../labyrinth/interfacing/WebResponse.java | 2 +
.../labyrinth/library/CommandUtils.java | 23 +-
.../labyrinth/library/DirectivePoint.java | 115 +++---
.../sanctum/labyrinth/library/Mailer.java | 2 +-
.../labyrinth/library/StringUtils.java | 84 ++---
.../sanctum/labyrinth/task/Asynchronous.java | 281 ---------------
.../labyrinth/task/AsynchronousTaskChain.java | 33 +-
...cheduler.java => CustomTaskScheduler.java} | 7 +-
.../labyrinth/task/NormalTaskScheduler.java | 71 ++++
.../sanctum/labyrinth/task/RenderedTask.java | 150 ++++++--
.../sanctum/labyrinth/task/Schedule.java | 47 ---
.../sanctum/labyrinth/task/ScheduledTask.java | 26 --
.../sanctum/labyrinth/task/Synchronous.java | 338 ------------------
.../labyrinth/task/SynchronousTaskChain.java | 109 ++----
.../github/sanctum/labyrinth/task/Task.java | 68 +++-
.../labyrinth/task/TaskCancellation.java | 12 -
.../sanctum/labyrinth/task/TaskMonitor.java | 226 +++++++++---
.../sanctum/labyrinth/task/TaskScheduler.java | 5 +-
labyrinth-gui/pom.xml | 2 +-
.../labyrinth/gui/unity/construct/Menu.java | 16 +-
.../construct}/MenuDuplicationException.java | 2 +-
.../construct}/MenuNotCacheableException.java | 2 +-
.../unity/construct}/MenuRegistration.java | 4 +-
.../gui/unity/construct/PaginatedMenu.java | 1 -
.../gui/unity/construct/PrintableMenu.java | 2 +-
.../gui/unity/impl/InventoryElement.java | 277 +++++++-------
.../labyrinth/gui/unity/impl/MenuType.java | 3 +-
.../labyrinth/gui/unity/impl/MenuViewer.java | 11 +
labyrinth-paste/pom.xml | 2 +-
labyrinth-perms/pom.xml | 2 +-
labyrinth-placeholders/pom.xml | 2 +-
labyrinth-plugin/pom.xml | 2 +-
.../github/sanctum/labyrinth/Labyrinth.java | 4 +-
.../labyrinth/event/custom/VentMapImpl.java | 37 +-
.../src/main/resources/lib/1_16_R3.jar | Bin 3943 -> 4187 bytes
.../src/main/resources/lib/1_18_2_R1.jar | Bin 0 -> 4081 bytes
labyrinth-regions/pom.xml | 2 +-
labyrinth-skulls/pom.xml | 2 +-
pom.xml | 4 +-
58 files changed, 1216 insertions(+), 1577 deletions(-)
delete mode 100644 labyrinth-common/src/main/java/com/github/sanctum/labyrinth/formatting/ComponentCompliment.java
delete mode 100644 labyrinth-common/src/main/java/com/github/sanctum/labyrinth/formatting/ComponentDecoration.java
delete mode 100644 labyrinth-common/src/main/java/com/github/sanctum/labyrinth/formatting/FinishingCompliment.java
delete mode 100644 labyrinth-common/src/main/java/com/github/sanctum/labyrinth/formatting/PaginatedList.java
delete mode 100644 labyrinth-common/src/main/java/com/github/sanctum/labyrinth/formatting/PrintedPaginationBuilder.java
delete mode 100644 labyrinth-common/src/main/java/com/github/sanctum/labyrinth/formatting/StartingCompliment.java
create mode 100644 labyrinth-common/src/main/java/com/github/sanctum/labyrinth/interfacing/OrdinalResult.java
delete mode 100644 labyrinth-common/src/main/java/com/github/sanctum/labyrinth/task/Asynchronous.java
rename labyrinth-common/src/main/java/com/github/sanctum/labyrinth/task/{LabyrinthTaskScheduler.java => CustomTaskScheduler.java} (93%)
create mode 100644 labyrinth-common/src/main/java/com/github/sanctum/labyrinth/task/NormalTaskScheduler.java
delete mode 100644 labyrinth-common/src/main/java/com/github/sanctum/labyrinth/task/Schedule.java
delete mode 100644 labyrinth-common/src/main/java/com/github/sanctum/labyrinth/task/ScheduledTask.java
delete mode 100644 labyrinth-common/src/main/java/com/github/sanctum/labyrinth/task/Synchronous.java
delete mode 100644 labyrinth-common/src/main/java/com/github/sanctum/labyrinth/task/TaskCancellation.java
rename labyrinth-gui/src/main/java/com/github/sanctum/labyrinth/{api => gui/unity/construct}/MenuDuplicationException.java (84%)
rename labyrinth-gui/src/main/java/com/github/sanctum/labyrinth/{api => gui/unity/construct}/MenuNotCacheableException.java (84%)
rename labyrinth-gui/src/main/java/com/github/sanctum/labyrinth/{api => gui/unity/construct}/MenuRegistration.java (97%)
create mode 100644 labyrinth-plugin/src/main/resources/lib/1_18_2_R1.jar
diff --git a/labyrinth-common/pom.xml b/labyrinth-common/pom.xml
index 753a8091..68a6a4d2 100644
--- a/labyrinth-common/pom.xml
+++ b/labyrinth-common/pom.xml
@@ -5,7 +5,7 @@
labyrinthcom.github.the-h-team
- 1.7.7
+ 1.7.84.0.0
diff --git a/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/api/LegacyCheckService.java b/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/api/LegacyCheckService.java
index ed76b36d..11a8eded 100644
--- a/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/api/LegacyCheckService.java
+++ b/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/api/LegacyCheckService.java
@@ -1,11 +1,17 @@
package com.github.sanctum.labyrinth.api;
+import com.github.sanctum.labyrinth.library.StringUtils;
import org.bukkit.Bukkit;
/**
* Detects legacy server environments.
*/
public interface LegacyCheckService extends Service {
+
+ default boolean isModded() {
+ return StringUtils.use(Bukkit.getServer().getName()).containsIgnoreCase("forge", "magma");
+ }
+
/**
* Check if the environment of the server is legacy.
*
diff --git a/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/command/SubCommandList.java b/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/command/SubCommandList.java
index 41679816..f4976c82 100644
--- a/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/command/SubCommandList.java
+++ b/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/command/SubCommandList.java
@@ -1,19 +1,35 @@
package com.github.sanctum.labyrinth.command;
+import com.github.sanctum.labyrinth.LabyrinthProvider;
+import com.github.sanctum.labyrinth.annotation.Ordinal;
import com.github.sanctum.labyrinth.data.container.LabyrinthCollection;
import com.github.sanctum.labyrinth.data.container.LabyrinthCollectionBase;
import com.github.sanctum.labyrinth.data.container.LabyrinthList;
+import com.github.sanctum.labyrinth.interfacing.OrdinalProcedure;
+import com.github.sanctum.labyrinth.library.CommandUtils;
import com.github.sanctum.labyrinth.library.StringUtils;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
+import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.bukkit.command.Command;
+import org.bukkit.command.CommandMap;
import org.bukkit.command.CommandSender;
+import org.bukkit.command.PluginCommand;
import org.bukkit.entity.Player;
+import org.bukkit.plugin.Plugin;
+import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+/**
+ * A class designed for easy bukkit sub command flow. Append or remove sub labels to registered commands.
+ *
+ * @author Hempfest
+ */
public abstract class SubCommandList extends LabyrinthCollectionBase {
protected final Crossover parent;
@@ -22,10 +38,71 @@ protected SubCommandList(@NotNull Command parent) {
this.parent = new Crossover(parent);
}
- public final String getCommand() {
+ /**
+ * Get the main command label this sub command belongs to.
+ *
+ * @return The main command this sub command is for.
+ */
+ public final @NotNull String getCommand() {
return parent.getLabel();
}
+ /**
+ * Get a sub command from this list by its label.
+ *
+ * @param label The label of the sub command.
+ * @return a sub command match or null if not found.
+ */
+ public final @Nullable SubCommand getSubCommand(@NotNull String label) {
+ return stream().filter(s -> s.getLabel().equalsIgnoreCase(label)).findFirst().orElse(null);
+ }
+
+ /**
+ * Register a sub command into this list.
+ *
+ * @param subCommand The command to register.
+ */
+ public final void register(@NotNull SubCommand subCommand) {
+ if (subCommand.getCommand().equalsIgnoreCase(getCommand())) {
+ final Command parent = CommandUtils.getCommandByLabel(subCommand.getCommand());
+ if (parent != null) {
+ final Plugin plugin = Optional.of((Plugin)JavaPlugin.getProvidingPlugin(parent.getClass())).orElseGet(() -> {
+ if (parent instanceof PluginCommand) {
+ return ((PluginCommand)parent).getPlugin();
+ } else return LabyrinthProvider.getInstance().getPluginInstance();
+ });
+ CommandUtils.read(entry -> {
+ Map commandMappings = entry.getValue();
+ CommandMap map = entry.getKey();
+ commandMappings.remove(parent.getName());
+ for (String alias : parent.getAliases()) {
+ if (commandMappings.containsKey(alias) && commandMappings.get(alias).getAliases().contains(alias)) {
+ commandMappings.remove(alias);
+ }
+ }
+ parent.unregister(map);
+ map.register(getCommand(), plugin.getName(), parent);
+ if (!contains(subCommand)) add(subCommand);
+ return this;
+ });
+ } else throw new IllegalArgumentException("Command " + subCommand.getCommand() + " either not found or not loaded yet.");
+ }
+ }
+
+ /**
+ * Unregister a sub command from this list.
+ *
+ * @param subCommand The command to unregister.
+ */
+ public final void unregister(@NotNull SubCommand subCommand) {
+ if (subCommand.getCommand().equalsIgnoreCase(getCommand())) {
+ final Command parent = CommandUtils.getCommandByLabel(subCommand.getCommand());
+ if (parent != null) {
+ if (contains(subCommand)) remove(subCommand);
+ } else throw new IllegalArgumentException("Command " + subCommand.getCommand() + " either not found or not loaded yet.");
+ }
+ }
+
class Crossover extends Command {
private final Command command;
diff --git a/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/data/AddonLoader.java b/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/data/AddonLoader.java
index 04eb63af..5b78793b 100644
--- a/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/data/AddonLoader.java
+++ b/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/data/AddonLoader.java
@@ -1,5 +1,6 @@
package com.github.sanctum.labyrinth.data;
+import com.github.sanctum.labyrinth.LabyrinthProvider;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import java.io.File;
@@ -13,6 +14,7 @@
import java.util.Optional;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;
+import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
/**
@@ -40,9 +42,10 @@ final class AddonClassLoader extends URLClassLoader {
private AddonClassLoader(URL[] urls) {
super(urls, javaPlugin.getClass().getClassLoader());
+ Bukkit.getLogger().severe(javaPlugin.getClass().getClassLoader().getClass().getName());
}
- final Class> resolveClass(String name) throws ClassNotFoundException {
+ Class> resolveClass(String name) throws ClassNotFoundException {
return loadClass(name, true);
}
diff --git a/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/data/ConfigurableNode.java b/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/data/ConfigurableNode.java
index e1ce504b..c8a389f9 100644
--- a/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/data/ConfigurableNode.java
+++ b/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/data/ConfigurableNode.java
@@ -2,12 +2,8 @@
import com.github.sanctum.labyrinth.LabyrinthProvider;
import com.github.sanctum.labyrinth.api.Service;
-import com.github.sanctum.labyrinth.task.Schedule;
import com.github.sanctum.labyrinth.task.TaskScheduler;
-import com.google.gson.GsonBuilder;
import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -69,7 +65,7 @@ public String getString() {
@Override
public int getInt() {
- return config.getInt(this.key);
+ return config.getInt(this.key);
}
@Override
@@ -237,7 +233,7 @@ public boolean create() {
if (config.getType() == FileType.JSON) {
set(new Object());
} else {
- ((YamlConfiguration)config).getConfig().createSection(this.key);
+ ((YamlConfiguration) config).getConfig().createSection(this.key);
}
save();
return false;
@@ -286,17 +282,17 @@ public Set getKeys(boolean deep) {
Set keys = new HashSet<>();
JsonConfiguration json = (JsonConfiguration) config;
if (json.get(this.key) instanceof Map) {
- Map map1 = (Map)json.get(this.key);
+ Map map1 = (Map) json.get(this.key);
if (deep) {
for (Map.Entry entry : map1.entrySet()) {
if (entry.getValue() instanceof Map) {
- Map map2 = (Map)entry.getValue();
+ Map map2 = (Map) entry.getValue();
for (Map.Entry entry2 : map2.entrySet()) {
if (entry2.getValue() instanceof Map) {
- Map map3 = (Map)entry2.getValue();
+ Map map3 = (Map) entry2.getValue();
for (Map.Entry entry3 : map3.entrySet()) {
if (entry3.getValue() instanceof Map) {
- Map map4 = (Map)entry2.getValue();
+ Map map4 = (Map) entry2.getValue();
for (Map.Entry entry4 : map4.entrySet()) {
keys.add(this.key + "." + entry.getKey() + "." + entry2.getKey() + "." + entry3.getKey() + "." + entry4.getKey());
}
@@ -331,17 +327,17 @@ public Map getValues(boolean deep) {
Map map = new HashMap<>();
JsonConfiguration json = (JsonConfiguration) config;
if (json.get(this.key) instanceof Map) {
- Map map1 = (Map)json.get(this.key);
+ Map map1 = (Map) json.get(this.key);
if (deep) {
for (Map.Entry entry : map1.entrySet()) {
if (entry.getValue() instanceof Map) {
- Map map2 = (Map)entry.getValue();
+ Map map2 = (Map) entry.getValue();
for (Map.Entry entry2 : map2.entrySet()) {
if (entry2.getValue() instanceof Map) {
- Map map3 = (Map)entry2.getValue();
+ Map map3 = (Map) entry2.getValue();
for (Map.Entry entry3 : map3.entrySet()) {
if (entry3.getValue() instanceof Map) {
- Map map4 = (Map)entry2.getValue();
+ Map map4 = (Map) entry2.getValue();
for (Map.Entry entry4 : map4.entrySet()) {
map.put(this.key + "." + entry.getKey() + "." + entry2.getKey() + "." + entry3.getKey() + "." + entry4.getKey(), entry4.getValue());
}
@@ -359,13 +355,13 @@ public Map getValues(boolean deep) {
} else {
for (Map.Entry entry : map1.entrySet()) {
if (entry.getValue() instanceof Map) {
- Map map2 = (Map)entry.getValue();
+ Map map2 = (Map) entry.getValue();
for (Map.Entry entry2 : map2.entrySet()) {
if (entry2.getValue() instanceof Map) {
- Map map3 = (Map)entry2.getValue();
+ Map map3 = (Map) entry2.getValue();
for (Map.Entry entry3 : map3.entrySet()) {
if (entry3.getValue() instanceof Map) {
- Map map4 = (Map)entry2.getValue();
+ Map map4 = (Map) entry2.getValue();
for (Map.Entry entry4 : map4.entrySet()) {
map.put(this.key + "." + entry.getKey() + "." + entry2.getKey() + "." + entry3.getKey() + "." + entry4.getKey(), entry4.getValue());
}
diff --git a/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/data/service/AnnotationDiscovery.java b/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/data/service/AnnotationDiscovery.java
index be5b134f..fcb37a35 100644
--- a/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/data/service/AnnotationDiscovery.java
+++ b/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/data/service/AnnotationDiscovery.java
@@ -15,7 +15,6 @@
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Collectors;
-import org.bukkit.Bukkit;
import org.jetbrains.annotations.NotNull;
/**
@@ -24,7 +23,7 @@
* @param A type of annotation.
* @param A listener to use.
*/
-public final class AnnotationDiscovery implements Iterable{
+public final class AnnotationDiscovery implements Iterable {
private final int count;
private final Class annotation;
@@ -41,7 +40,8 @@ public final class AnnotationDiscovery implements Itera
for (Method method : rClass.getDeclaredMethods()) {
try {
method.setAccessible(true);
- } catch (Exception ignored) {}
+ } catch (Exception ignored) {
+ }
if (method.isAnnotationPresent(annotation)) {
annotated++;
}
@@ -59,7 +59,8 @@ public final class AnnotationDiscovery implements Itera
for (Method method : rClass.getDeclaredMethods()) {
try {
method.setAccessible(true);
- } catch (Exception ignored) {}
+ } catch (Exception ignored) {
+ }
if (method.isAnnotationPresent(annotation)) {
annotated++;
}
@@ -105,7 +106,7 @@ public AnnotationDiscovery filter(Predicate super Method> predicate) {
* Filter the methods and only work with ones of interest.
*
* @param predicate The filtration.
- * @param hard whether or not to breach accessibility.
+ * @param hard whether or not to breach accessibility.
* @return The same annotation discovery object.
*/
public AnnotationDiscovery filter(Predicate super Method> predicate, boolean hard) {
@@ -118,7 +119,8 @@ public AnnotationDiscovery filter(Predicate super Method> predicate, boo
methods.addAll(Arrays.stream(this.rClass.getDeclaredMethods()).filter(m -> {
try {
m.setAccessible(true);
- } catch (Exception ignored){}
+ } catch (Exception ignored) {
+ }
return m.isAnnotationPresent(annotation) && predicate.test(m);
}).collect(Collectors.toList()));
}
@@ -140,25 +142,25 @@ public boolean isPresent() {
*/
public void ifPresent(WideConsumer function) {
if (isPresent()) {
- for (Method m : methods) {
+ methods.forEach(m -> {
for (Annotation a : m.getAnnotations()) {
if (annotation.isAssignableFrom(a.annotationType())) {
function.accept((T) a, m);
}
}
- }
+ });
}
}
/**
* Get information from the leading source objects located annotation.
- *
+ *
* This method gives you access to an annotation and the source object itself.
*
- * @deprecated Use {@link AnnotationDiscovery#mapFromClass(AnnotativeConsumer)} instead!
* @param function The function.
- * @param The desired return value.
+ * @param The desired return value.
* @return A value from an annotation.
+ * @deprecated Use {@link AnnotationDiscovery#mapFromClass(AnnotativeConsumer)} instead!
*/
@Deprecated
public U map(AnnotativeConsumer function) {
@@ -167,11 +169,11 @@ public U map(AnnotativeConsumer function) {
/**
* Get information from the leading source objects located annotation.
- *
+ *
* This method gives you access to an annotation and the source object itself.
*
* @param function The function.
- * @param The desired return value.
+ * @param The desired return value.
* @return A value from an annotation.
*/
public U mapFromClass(AnnotativeConsumer function) {
@@ -183,11 +185,11 @@ public U mapFromClass(AnnotativeConsumer function) {
/**
* Get information from the leading source objects methods found with the specified annotation.
- *
+ *
* This method gives you access to an annotation and the source object itself.
*
* @param function The function.
- * @param The desired return value.
+ * @param The desired return value.
* @return A value from an annotation.
*/
public List mapFromMethods(AnnotativeConsumer function) {
diff --git a/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/formatting/ComponentCompliment.java b/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/formatting/ComponentCompliment.java
deleted file mode 100644
index 612dcf7a..00000000
--- a/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/formatting/ComponentCompliment.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package com.github.sanctum.labyrinth.formatting;
-
-/**
- * @author Hempfest
- */
-@Deprecated
-public interface ComponentCompliment {
-
- @SuppressWarnings("EmptyMethod")
- void apply(PaginatedList pagination, int page, int max);
-
-}
diff --git a/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/formatting/ComponentDecoration.java b/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/formatting/ComponentDecoration.java
deleted file mode 100644
index b7ee8930..00000000
--- a/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/formatting/ComponentDecoration.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package com.github.sanctum.labyrinth.formatting;
-
-/**
- * @author Hempfest
- */
-@FunctionalInterface
-@Deprecated
-public interface ComponentDecoration {
-
- void apply(PaginatedList pagination, T object, int page, int max, int placement);
-
-}
diff --git a/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/formatting/ComponentUtil.java b/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/formatting/ComponentUtil.java
index 68ae0a7c..7b68cfc8 100644
--- a/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/formatting/ComponentUtil.java
+++ b/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/formatting/ComponentUtil.java
@@ -13,7 +13,7 @@ public static void addContent(BaseComponent component, String context) {
if (component.getHoverEvent() == null) {
component.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(TextComponent.fromLegacyText(StringUtils.use(context).translate()))));
} else {
- component.getHoverEvent().addContent(new Text(StringUtils.use(context).translate()));
+ component.getHoverEvent().addContent(new Text(TextComponent.fromLegacyText(StringUtils.use(context).translate())));
}
}
diff --git a/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/formatting/FinishingCompliment.java b/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/formatting/FinishingCompliment.java
deleted file mode 100644
index c593d839..00000000
--- a/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/formatting/FinishingCompliment.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.github.sanctum.labyrinth.formatting;
-
-/**
- * @author Hempfest
- */
-@Deprecated
-public interface FinishingCompliment extends ComponentCompliment {
-
- void apply(PaginatedList pagination, int page, int max);
-
-}
diff --git a/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/formatting/PaginatedList.java b/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/formatting/PaginatedList.java
deleted file mode 100644
index 852f72d2..00000000
--- a/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/formatting/PaginatedList.java
+++ /dev/null
@@ -1,205 +0,0 @@
-package com.github.sanctum.labyrinth.formatting;
-
-import com.github.sanctum.labyrinth.annotation.Experimental;
-import com.github.sanctum.labyrinth.library.MathUtils;
-
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-import java.util.function.Consumer;
-import java.util.function.Predicate;
-import java.util.stream.Collectors;
-
-/**
- * Encapsulate a list of objects to be sorted and paginated.
- *
- * @deprecated Replaced by {@link com.github.sanctum.labyrinth.formatting.pagination.AbstractPaginatedCollection}
- * @param the object type representative of this pagination operation
- * @author Hempfest
- */
-@Deprecated
-@Experimental(dueTo = "This class will attempt to be replaced soon.", atRisk = true)
-public class PaginatedList {
- private List typeList;
- private ComponentCompliment start;
- private ComponentCompliment finish;
- private ComponentDecoration decoration;
- private int linesPerPage;
-
- public PaginatedList(List list) {
- this.typeList = new LinkedList<>(new LinkedHashSet<>(list));
- }
-
- public PaginatedList(Set set) {
- this.typeList = new LinkedList<>(set);
- }
-
- /**
- * Format/trim a given amount to a specific length format.
- *
- * @param amount the amount to format
- * @param precision the math precision to stop the decimal placing at
- * @return the newly formatted double
- */
- public double format(Number amount, int precision) {
- return MathUtils.use(amount).format(precision);
- }
-
- /**
- * Setup a comparator for this list's sorting procedure.
- *
- * @param comparable the comparing operation to run for the given object type
- * @return this paginated list procedure
- */
- public PaginatedList compare(Comparator super T> comparable) {
- this.typeList.sort(comparable);
- return this;
- }
-
- /**
- * Provided the page number, total page count, object in queue and
- * current paginated list instance; decorate any possible actions
- * to take while iterating through the entries.
- *
- * @param decoration the primary execution to be ran for every entry given
- * @return this paginated list procedure
- */
- public PaginatedList decorate(ComponentDecoration decoration) {
- this.decoration = decoration;
- return this;
- }
-
- /**
- * Specify an amount of entries to be display per page.
- *
- * Lower entry counts will result in larger page counts.
- *
- * @param linesPerPage the amount of entries per page to display
- * @return this paginated list procedure
- */
- public PaginatedList limit(int linesPerPage) {
- this.linesPerPage = linesPerPage;
- return this;
- }
-
- /**
- * Provided the page number and total page count, provide a starting
- * sequence for the pagination.
- *
- * @param compliment the starting execution to be run once
- * @return this paginated list procedure
- */
- public PaginatedList start(StartingCompliment compliment) {
- this.start = compliment;
- return this;
- }
-
- /**
- * Provided the page number and total page count,
- * describe a finishing sequence for the pagination.
- *
- * @param compliment the finishing execution to be run once
- * @return this paginated list procedure
- */
- public PaginatedList finish(FinishingCompliment compliment) {
- this.finish = compliment;
- return this;
- }
-
- /**
- * Provided the page number and total page count, describe a finishing
- * sequence for the pagination (so the desired player can browse pages).
- *
- * @param builderConsumer the finishing execution to be run once
- * @return this paginated list procedure
- */
- public PaginatedList finish(Consumer builderConsumer) {
- this.finish = (list, page, max) -> {
-
- PrintedPaginationBuilder builder = new PrintedPaginationBuilder(max).setPage(page);
-
- builderConsumer.accept(builder);
-
- builder.build(list);
-
- };
- return this;
- }
-
- /**
- * Separate unwanted elements from the list.
- *
- * @param predicate test that must succeed to include an element
- * @return this paginated list procedure
- */
- public PaginatedList filter(Predicate super T> predicate) {
- this.typeList = typeList.stream().filter(predicate).collect(Collectors.toList());
- return this;
- }
-
- public int getTotalPageCount() {
- int totalPageCount = 1;
- if ((this.typeList.size() % linesPerPage) == 0) {
- if (this.typeList.size() > 0) {
- totalPageCount = this.typeList.size() / linesPerPage;
- }
- } else {
- totalPageCount = (this.typeList.size() / linesPerPage) + 1;
- }
- return totalPageCount;
- }
-
- public PaginatedList update(Collection list) {
- this.typeList = new LinkedList<>(list);
- return this;
- }
-
- /**
- * Run all prior sorting arrangements and sequence operations for a specified page.
- *
- * @param pageNum the page to to collect
- * @return a list of collected objects from the sorting procedure
- */
- public List get(int pageNum) {
- LinkedList list = new LinkedList<>();
- int page = pageNum;
-
- int o = linesPerPage;
-
- int totalPageCount = getTotalPageCount();
-
- if (page <= totalPageCount) {
-
- if (this.start != null) {
- this.start.apply(this, pageNum, totalPageCount);
- }
-
- if (!typeList.isEmpty()) {
- int i1 = 0, k = 0;
- page--;
- LinkedList sorted_list = new LinkedList<>(this.typeList);
-
- for (T value : sorted_list) {
-
- k++;
- if ((((page * o) + i1 + 1) == k) && (k != ((page * o) + o + 1))) {
- i1++;
- if (decoration != null) {
- decoration.apply(this, value, pageNum, totalPageCount, k);
- }
- list.add(value);
- }
- }
- if (this.finish != null) {
- this.finish.apply(this, pageNum, totalPageCount);
- }
- }
- // end line
- }
- return list;
- }
-
-}
diff --git a/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/formatting/PrintedPaginationBuilder.java b/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/formatting/PrintedPaginationBuilder.java
deleted file mode 100644
index f0226591..00000000
--- a/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/formatting/PrintedPaginationBuilder.java
+++ /dev/null
@@ -1,91 +0,0 @@
-package com.github.sanctum.labyrinth.formatting;
-
-import com.github.sanctum.labyrinth.library.Mailer;
-import com.github.sanctum.labyrinth.library.Message;
-import com.github.sanctum.labyrinth.library.TextLib;
-import net.md_5.bungee.api.chat.BaseComponent;
-import org.bukkit.entity.Player;
-
-import java.util.LinkedList;
-import java.util.List;
-
-public class PrintedPaginationBuilder {
-
- private final List toSend = new LinkedList<>();
-
- private final int max;
-
- private String prefix = "";
-
- private String suffix = "";
-
- private int page;
-
- private Player player;
-
-
- protected PrintedPaginationBuilder(int max) {
- this.max = max;
- }
-
-
- public PrintedPaginationBuilder setPlayer(Player player) {
- this.player = player;
- return this;
- }
-
- public PrintedPaginationBuilder setPage(int page) {
- this.page = page;
- return this;
- }
-
- public PrintedPaginationBuilder setPrefix(String prefix) {
- this.prefix = prefix;
- return this;
- }
-
- public PrintedPaginationBuilder setSuffix(String suffix) {
- this.suffix = suffix;
- return this;
- }
-
- void build(PaginatedList list) {
- TextLib component = TextLib.getInstance();
- int next = page + 1;
- int last = Math.max(page - 1, 1);
- if (!this.prefix.isEmpty()) {
- Mailer.empty(player).chat(this.prefix).deploy();
- }
- List toSend = new LinkedList<>();
- if (page == 1) {
- if (page == max) {
- toSend.add(component.textHoverable("", "&8« ", "&cYou are on the first page already."));
- toSend.add(component.textHoverable("&f<&7" + page + "&f/&7" + max + "&f>", "", ""));
- toSend.add(component.textHoverable("", " &8»", "&cYou are already on the last page."));
- player.spigot().sendMessage(toSend.toArray(new BaseComponent[0]));
- return;
- }
- toSend.add(component.textHoverable("", "&8« ", "&cYou are on the first page already."));
- toSend.add(component.textHoverable("&f<&7" + page + "&f/&7" + max + "&f>", "", ""));
- toSend.add(component.execute(() -> list.get(next), component.textHoverable("", " &3»", "&aGoto the next page.")));
- player.spigot().sendMessage(toSend.toArray(new BaseComponent[0]));
- return;
- }
- if (page == max) {
- toSend.add(component.execute(() -> list.get(last), component.textHoverable("", "&3« ", "&aGoto the previous page.")));
- toSend.add(component.textHoverable("&f<&7" + page + "&f/&7" + max + "&f>", "", ""));
- toSend.add(component.textHoverable("", " &8»", "&cYou are already on the last page."));
- player.spigot().sendMessage(toSend.toArray(new BaseComponent[0]));
- return;
- }
- if (next <= max) {
- toSend.add(component.execute(() -> list.get(last), component.textHoverable("", "&3« ", "&aGoto the previous page.")));
- toSend.add(component.textHoverable("&f<&7" + page + "&f/&7" + max + "&f>", "", ""));
- toSend.add(component.execute(() -> list.get(next), component.textHoverable("", " &3»", "&aGoto the next page.")));
- player.spigot().sendMessage(toSend.toArray(new BaseComponent[0]));
- }
- if (!this.suffix.isEmpty()) {
- Mailer.empty(this.player).chat(this.suffix).deploy();
- }
- }
-}
diff --git a/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/formatting/StartingCompliment.java b/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/formatting/StartingCompliment.java
deleted file mode 100644
index 10305e3e..00000000
--- a/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/formatting/StartingCompliment.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package com.github.sanctum.labyrinth.formatting;
-
-/**
- * @author Hempfest
- */
-public interface StartingCompliment extends ComponentCompliment {
-
- void apply(PaginatedList pagination, int page, int max);
-
-}
diff --git a/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/formatting/TablistInstance.java b/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/formatting/TablistInstance.java
index d7d5f94c..bebee865 100644
--- a/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/formatting/TablistInstance.java
+++ b/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/formatting/TablistInstance.java
@@ -4,9 +4,6 @@
import com.github.sanctum.labyrinth.api.Service;
import com.github.sanctum.labyrinth.api.TaskService;
import com.github.sanctum.labyrinth.library.StringUtils;
-import com.github.sanctum.labyrinth.task.Schedule;
-import com.github.sanctum.labyrinth.task.Synchronous;
-import com.github.sanctum.labyrinth.task.Task;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
@@ -93,8 +90,8 @@ public interface TablistInstance {
* Activate this tab list display instance and include custom meta within the task, alternating displays every x y (x being time and y being the unit.)
*
* @param consumer The meta to include.
- * @param unit The time unit to use
- * @param period The amount of time to use.
+ * @param unit The time unit to use
+ * @param period The amount of time to use.
* @return true if the instance was activated, false if already running.
*/
boolean enable(Consumer consumer, TimeUnit unit, long period);
@@ -200,7 +197,8 @@ public boolean remove(TabGroup group) {
@Override
public boolean enable() {
- return enable(player1 -> {}, TimeUnit.MILLISECONDS, 40);
+ return enable(player1 -> {
+ }, TimeUnit.MILLISECONDS, 40);
}
@Override
diff --git a/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/formatting/string/ImageBreakdown.java b/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/formatting/string/ImageBreakdown.java
index 8030e3fa..fb52bdcf 100644
--- a/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/formatting/string/ImageBreakdown.java
+++ b/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/formatting/string/ImageBreakdown.java
@@ -15,7 +15,7 @@
import org.jetbrains.annotations.NotNull;
/**
- * Newly improved by hemp with full rgb support depending on version.
+ * An object dedicated to converting imagery to pixel art. Improved upon by Hempfest allowing support for RGB.
*
* @author bobacadodl
* @author Hempfest
diff --git a/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/interfacing/Catchable.java b/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/interfacing/Catchable.java
index 947d5786..5ed8bccc 100644
--- a/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/interfacing/Catchable.java
+++ b/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/interfacing/Catchable.java
@@ -1,6 +1,13 @@
package com.github.sanctum.labyrinth.interfacing;
-public interface Catchable {
+import com.github.sanctum.labyrinth.api.Service;
+
+/**
+ * A non-linked snapshot initialization service.
+ *
+ * @param The type of snapshot.
+ */
+public interface Catchable extends Service {
T getSnapshot();
diff --git a/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/interfacing/OrdinalElement.java b/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/interfacing/OrdinalElement.java
index b54dcd67..ed5b1f4b 100644
--- a/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/interfacing/OrdinalElement.java
+++ b/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/interfacing/OrdinalElement.java
@@ -29,4 +29,8 @@ public interface OrdinalElement {
*/
GenericOrdinalElement select(int ordinal, Object... args);
+ default GenericOrdinalElement toGeneric() {
+ return this instanceof GenericOrdinalElement ? (GenericOrdinalElement) this : null;
+ }
+
}
diff --git a/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/interfacing/OrdinalProcedure.java b/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/interfacing/OrdinalProcedure.java
index 45a0e731..1442e046 100644
--- a/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/interfacing/OrdinalProcedure.java
+++ b/labyrinth-common/src/main/java/com/github/sanctum/labyrinth/interfacing/OrdinalProcedure.java
@@ -14,9 +14,254 @@
* If the intended object for use contains no usage of {@link Ordinal} this utility has no use to you.
*
*/
-public abstract class OrdinalProcedure {
+public abstract class OrdinalProcedure {
- OrdinalProcedure() {}
+ private E e;
+ private Iterable eI;
+
+ protected OrdinalProcedure(E e) {
+ this.e = e;
+ }
+
+ protected OrdinalProcedure(Iterable e) {
+ this.eI = e;
+ }
+
+ /**
+ * Process all flagged ordinal's within every object.
+ *
+ * @return A list of processed elements.
+ */
+ public OrdinalResult run() {
+ if (isIterable()) {
+ List> processed = new ArrayList<>();
+ for (E o : eI) {
+ processed.add(run(o));
+ }
+ return OrdinalResult.of(processed);
+ } else {
+ return OrdinalResult.of(run(e));
+ }
+ }
+
+ /**
+ * Process a specific ordinal
+ *
+ * @param ordinal The ordinal to process.
+ * @return A processed element.
+ */
+ public OrdinalResult run(int ordinal) {
+ if (isIterable()) {
+ List> processed = new ArrayList<>();
+ for (E o : eI) {
+ processed.add(run(o, ordinal));
+ }
+ return OrdinalResult.of(processed);
+ } else {
+ return OrdinalResult.of(run(e, ordinal));
+ }
+ }
+
+ /**
+ * Process all ordinals within range (0 - specified) in order.
+ *
+ * @param ordinal The max ordinal range to process.
+ * @return A processed element.
+ */
+ public OrdinalResult max(int ordinal) {
+ if (isIterable()) {
+ List> processed = new ArrayList<>();
+ for (E o : eI) {
+ processed.add(max(o, ordinal));
+ }
+ return OrdinalResult.of(processed);
+ } else {
+ return OrdinalResult.of(max(e, ordinal));
+ }
+ }
+
+ /**
+ * Process all ordinals within range (specified+) in order, ordinals lower than specified will not process.
+ *
+ * @param ordinal The max ordinal range to process.
+ * @return A processed element.
+ */
+ public OrdinalResult min(int ordinal) {
+ if (isIterable()) {
+ List> processed = new ArrayList<>();
+ for (E o : eI) {
+ processed.add(min(o, ordinal));
+ }
+ return OrdinalResult.of(processed);
+ } else {
+ return OrdinalResult.of(min(e, ordinal));
+ }
+ }
+
+ /**
+ * Get a specific method from the sourced element using its declared ordinal.
+ *
+ * @param ordinal The ordinal to use.
+ * @return A generic ordinal containing synchronized information.
+ */
+ public OrdinalResult