From 267961ab388e13714e72355dcc9e16948dc0f7bb Mon Sep 17 00:00:00 2001 From: Paldiu Date: Mon, 22 Feb 2021 08:45:56 -0600 Subject: [PATCH 1/5] Updated a bunch of framework, removed useless functions and fixed possible N(2o) complexity issue. --- .../paldiu/simplexcore/SimplexCore.java | 2 +- .../io/github/paldiu/simplexcore/ban/Ban.java | 3 +- .../{future => concurrent}/Announcer.java | 2 +- .../{future => concurrent}/SimplexTask.java | 2 +- .../paldiu/simplexcore/config/IConfig.java | 41 +++++++++ .../paldiu/simplexcore/config/Json.java | 91 ++++++++++++++++++- .../paldiu/simplexcore/config/Path.java | 6 ++ .../paldiu/simplexcore/config/Yaml.java | 72 ++++++++------- .../simplexcore/particle/IParticleEffect.java | 14 +++ 9 files changed, 193 insertions(+), 40 deletions(-) rename src/main/java/io/github/paldiu/simplexcore/{future => concurrent}/Announcer.java (94%) rename src/main/java/io/github/paldiu/simplexcore/{future => concurrent}/SimplexTask.java (97%) create mode 100644 src/main/java/io/github/paldiu/simplexcore/config/IConfig.java create mode 100644 src/main/java/io/github/paldiu/simplexcore/config/Path.java create mode 100644 src/main/java/io/github/paldiu/simplexcore/particle/IParticleEffect.java diff --git a/src/main/java/io/github/paldiu/simplexcore/SimplexCore.java b/src/main/java/io/github/paldiu/simplexcore/SimplexCore.java index a16f4a1..8447bcc 100644 --- a/src/main/java/io/github/paldiu/simplexcore/SimplexCore.java +++ b/src/main/java/io/github/paldiu/simplexcore/SimplexCore.java @@ -1,7 +1,7 @@ package io.github.paldiu.simplexcore; import io.github.paldiu.simplexcore.command.defaults.Command_info; -import io.github.paldiu.simplexcore.future.Announcer; +import io.github.paldiu.simplexcore.concurrent.Announcer; import io.github.paldiu.simplexcore.listener.ServerPluginListener; import io.github.paldiu.simplexcore.listener.SimplexListener; import io.github.paldiu.simplexcore.plugin.SimplexAddon; diff --git a/src/main/java/io/github/paldiu/simplexcore/ban/Ban.java b/src/main/java/io/github/paldiu/simplexcore/ban/Ban.java index 729db59..2a490bb 100644 --- a/src/main/java/io/github/paldiu/simplexcore/ban/Ban.java +++ b/src/main/java/io/github/paldiu/simplexcore/ban/Ban.java @@ -58,7 +58,7 @@ public abstract class Ban implements IBan { if (separateFiles) { Yaml yaml = new YamlFactory(Constants.getPlugin()).from(null, fileLocation, player.getName() + ".yml"); yaml.getConfig().createSection(getOffender().toString()); - ConfigurationSection section = yaml.getConfigurationSection(getOffender().toString()); + ConfigurationSection section = yaml.getConfigurationSection(getOffender()::toString); section.set("name", player.getName()); section.set("ban_id", banId); section.set("sender", sender.getName()); @@ -74,6 +74,7 @@ public abstract class Ban implements IBan { yaml.reload(); } else { // TODO: Write to a single file as separate sections per UUID. + Yaml yaml = new YamlFactory(Constants.getPlugin()).from(null, fileLocation, "bans.yml"); } } } diff --git a/src/main/java/io/github/paldiu/simplexcore/future/Announcer.java b/src/main/java/io/github/paldiu/simplexcore/concurrent/Announcer.java similarity index 94% rename from src/main/java/io/github/paldiu/simplexcore/future/Announcer.java rename to src/main/java/io/github/paldiu/simplexcore/concurrent/Announcer.java index 0955332..994c587 100644 --- a/src/main/java/io/github/paldiu/simplexcore/future/Announcer.java +++ b/src/main/java/io/github/paldiu/simplexcore/concurrent/Announcer.java @@ -1,4 +1,4 @@ -package io.github.paldiu.simplexcore.future; +package io.github.paldiu.simplexcore.concurrent; import io.github.paldiu.simplexcore.chat.Messages; import io.github.paldiu.simplexcore.utils.Constants; diff --git a/src/main/java/io/github/paldiu/simplexcore/future/SimplexTask.java b/src/main/java/io/github/paldiu/simplexcore/concurrent/SimplexTask.java similarity index 97% rename from src/main/java/io/github/paldiu/simplexcore/future/SimplexTask.java rename to src/main/java/io/github/paldiu/simplexcore/concurrent/SimplexTask.java index 8963614..2f234a3 100644 --- a/src/main/java/io/github/paldiu/simplexcore/future/SimplexTask.java +++ b/src/main/java/io/github/paldiu/simplexcore/concurrent/SimplexTask.java @@ -1,4 +1,4 @@ -package io.github.paldiu.simplexcore.future; +package io.github.paldiu.simplexcore.concurrent; import io.github.paldiu.simplexcore.plugin.SimplexAddon; import io.github.paldiu.simplexcore.utils.Constants; diff --git a/src/main/java/io/github/paldiu/simplexcore/config/IConfig.java b/src/main/java/io/github/paldiu/simplexcore/config/IConfig.java new file mode 100644 index 0000000..04aa275 --- /dev/null +++ b/src/main/java/io/github/paldiu/simplexcore/config/IConfig.java @@ -0,0 +1,41 @@ +package io.github.paldiu.simplexcore.config; + +import org.bukkit.configuration.ConfigurationSection; + +import java.util.List; + +public interface IConfig { + void set(Path path, Object value); + + boolean contains(Path path); + + ConfigurationSection getConfigurationSection(Path path); + + List getStringList(Path path); + + long getLong(Path path); + + List getList(Path path); + + boolean getBoolean(Path path); + + int getInt(Path path); + + double getDouble(Path path); + + String getString(Path path); + + long getLong(Path path, long def); + + List getList(Path path, List def); + + boolean getBoolean(Path path, boolean def); + + int getInt(Path path, int def); + + double getDouble(Path path, double def); + + String getString(Path path, String def); + + Object get(Path path, Object def); +} diff --git a/src/main/java/io/github/paldiu/simplexcore/config/Json.java b/src/main/java/io/github/paldiu/simplexcore/config/Json.java index 6a2944c..658ccf1 100644 --- a/src/main/java/io/github/paldiu/simplexcore/config/Json.java +++ b/src/main/java/io/github/paldiu/simplexcore/config/Json.java @@ -1,5 +1,94 @@ package io.github.paldiu.simplexcore.config; -public class Json { +import org.bukkit.configuration.ConfigurationSection; + +import java.util.List; + +public class Json implements IConfig { // TODO: Write actual JSON implementations. + + @Override + public void set(Path path, Object value) { + + } + + @Override + public boolean contains(Path path) { + return false; + } + + @Override + public ConfigurationSection getConfigurationSection(Path path) { + return null; + } + + @Override + public List getStringList(Path path) { + return null; + } + + @Override + public long getLong(Path path) { + return 0; + } + + @Override + public List getList(Path path) { + return null; + } + + @Override + public boolean getBoolean(Path path) { + return false; + } + + @Override + public int getInt(Path path) { + return 0; + } + + @Override + public double getDouble(Path path) { + return 0; + } + + @Override + public String getString(Path path) { + return null; + } + + @Override + public long getLong(Path path, long def) { + return 0; + } + + @Override + public List getList(Path path, List def) { + return null; + } + + @Override + public boolean getBoolean(Path path, boolean def) { + return false; + } + + @Override + public int getInt(Path path, int def) { + return 0; + } + + @Override + public double getDouble(Path path, double def) { + return 0; + } + + @Override + public String getString(Path path, String def) { + return null; + } + + @Override + public Object get(Path path, Object def) { + return null; + } } diff --git a/src/main/java/io/github/paldiu/simplexcore/config/Path.java b/src/main/java/io/github/paldiu/simplexcore/config/Path.java new file mode 100644 index 0000000..ea08ec1 --- /dev/null +++ b/src/main/java/io/github/paldiu/simplexcore/config/Path.java @@ -0,0 +1,6 @@ +package io.github.paldiu.simplexcore.config; + +@FunctionalInterface +public interface Path { + String getPath(); +} diff --git a/src/main/java/io/github/paldiu/simplexcore/config/Yaml.java b/src/main/java/io/github/paldiu/simplexcore/config/Yaml.java index 56aacef..329360f 100644 --- a/src/main/java/io/github/paldiu/simplexcore/config/Yaml.java +++ b/src/main/java/io/github/paldiu/simplexcore/config/Yaml.java @@ -14,7 +14,7 @@ import java.io.IOException; import java.nio.file.NotDirectoryException; import java.util.List; -public final class Yaml { +public final class Yaml implements IConfig { private final SimplexAddon plugin; private final String fileName; private final File directory; @@ -37,72 +37,73 @@ public final class Yaml { this.resourcePath = resourcePath; } - public final void set(String path, Object value) { - this.getConfig().set(path, value); + @Override + public final void set(Path path, Object value) { + this.getConfig().set(path.getPath(), value); } - public boolean contains(String path) { - return this.getConfig().contains(path); + public boolean contains(Path path) { + return this.getConfig().contains(path.getPath()); } - public ConfigurationSection getConfigurationSection(String path) { - return this.getConfig().getConfigurationSection(path); + public ConfigurationSection getConfigurationSection(Path path) { + return this.getConfig().getConfigurationSection(path.getPath()); } - public List getStringList(String path) { - return this.getConfig().getStringList(path); + public List getStringList(Path path) { + return this.getConfig().getStringList(path.getPath()); } - public long getLong(String path) { - return this.getConfig().getLong(path); + public long getLong(Path path) { + return this.getConfig().getLong(path.getPath()); } - public List getList(String path) { - return this.getConfig().getList(path); + public List getList(Path path) { + return this.getConfig().getList(path.getPath()); } - public boolean getBoolean(String path) { - return this.getConfig().getBoolean(path); + public boolean getBoolean(Path path) { + return this.getConfig().getBoolean(path.getPath()); } - public int getInt(String path) { - return this.getConfig().getInt(path); + public int getInt(Path path) { + return this.getConfig().getInt(path.getPath()); } - public double getDouble(String path) { - return this.getConfig().getDouble(path); + public double getDouble(Path path) { + return this.getConfig().getDouble(path.getPath()); } - public String getString(String path) { - return this.getConfig().getString(path); + public String getString(Path path) { + return this.getConfig().getString(path.getPath()); } - public long getLong(String path, long def) { - return this.getConfig().getLong(path, def); + public long getLong(Path path, long def) { + return this.getConfig().getLong(path.getPath(), def); } - public List getList(String path, List def) { - return this.getConfig().getList(path, def); + public List getList(Path path, List def) { + return this.getConfig().getList(path.getPath(), def); } - public boolean getBoolean(String path, boolean def) { - return this.getConfig().getBoolean(path, def); + public boolean getBoolean(Path path, boolean def) { + return this.getConfig().getBoolean(path.getPath(), def); } - public int getInt(String path, int def) { - return this.getConfig().getInt(path, def); + public int getInt(Path path, int def) { + return this.getConfig().getInt(path.getPath(), def); } - public double getDouble(String path, double def) { - return this.getConfig().getDouble(path, def); + public double getDouble(Path path, double def) { + return this.getConfig().getDouble(path.getPath(), def); } - public String getString(String path, String def) { - return this.getConfig().getString(path, def); + public String getString(Path path, String def) { + return this.getConfig().getString(path.getPath(), def); } - public Object get(String path, Object def) { - return this.getConfig().get(path, def); + public Object get(Path path, Object def) { + return this.getConfig().get(path.getPath(), def); } public final void reload() { @@ -115,6 +116,7 @@ public final class Yaml { } } } else { // Directory doesn't exist. + //noinspection ResultOfMethodCallIgnored this.directory.mkdir(); // Make directory } this.file = new File(this.directory, this.fileName); diff --git a/src/main/java/io/github/paldiu/simplexcore/particle/IParticleEffect.java b/src/main/java/io/github/paldiu/simplexcore/particle/IParticleEffect.java new file mode 100644 index 0000000..87af799 --- /dev/null +++ b/src/main/java/io/github/paldiu/simplexcore/particle/IParticleEffect.java @@ -0,0 +1,14 @@ +package io.github.paldiu.simplexcore.particle; + +import org.bukkit.Color; +import org.bukkit.Particle; + +public interface IParticleEffect { + Particle[] getParticles(); + + Color[] getParticleColors(); + + Float getSize(); + + Long getDuration(); +} From 4bf672d3ee2707b0a5d41e8733e5b8f36708bd4a Mon Sep 17 00:00:00 2001 From: Paldiu Date: Mon, 22 Feb 2021 12:43:56 -0600 Subject: [PATCH 2/5] Added a couple new api features --- .../paldiu/simplexcore/SimplexCore.java | 4 +-- ...nListener.java => DependencyListener.java} | 2 +- .../paldiu/simplexcore/sign/IUsableSign.java | 17 +++++++++++ .../simplexcore/structures/IStructure.java | 29 +++++++++++++++++++ .../simplexcore/structures/Structure.java | 5 ++++ 5 files changed, 54 insertions(+), 3 deletions(-) rename src/main/java/io/github/paldiu/simplexcore/listener/{ServerPluginListener.java => DependencyListener.java} (95%) create mode 100644 src/main/java/io/github/paldiu/simplexcore/sign/IUsableSign.java create mode 100644 src/main/java/io/github/paldiu/simplexcore/structures/IStructure.java create mode 100644 src/main/java/io/github/paldiu/simplexcore/structures/Structure.java diff --git a/src/main/java/io/github/paldiu/simplexcore/SimplexCore.java b/src/main/java/io/github/paldiu/simplexcore/SimplexCore.java index 8447bcc..3b394a9 100644 --- a/src/main/java/io/github/paldiu/simplexcore/SimplexCore.java +++ b/src/main/java/io/github/paldiu/simplexcore/SimplexCore.java @@ -2,7 +2,7 @@ package io.github.paldiu.simplexcore; import io.github.paldiu.simplexcore.command.defaults.Command_info; import io.github.paldiu.simplexcore.concurrent.Announcer; -import io.github.paldiu.simplexcore.listener.ServerPluginListener; +import io.github.paldiu.simplexcore.listener.DependencyListener; import io.github.paldiu.simplexcore.listener.SimplexListener; import io.github.paldiu.simplexcore.plugin.SimplexAddon; import io.github.paldiu.simplexcore.utils.Constants; @@ -35,7 +35,7 @@ public final class SimplexCore extends SimplexAddon { Constants.getCommandLoader().classpath(Command_info.class).load(); Constants.getConfig().reload(); // - SimplexListener.register(new ServerPluginListener(), this); + SimplexListener.register(new DependencyListener(), this); new Announcer(); } catch (Exception ex) { suspended = true; diff --git a/src/main/java/io/github/paldiu/simplexcore/listener/ServerPluginListener.java b/src/main/java/io/github/paldiu/simplexcore/listener/DependencyListener.java similarity index 95% rename from src/main/java/io/github/paldiu/simplexcore/listener/ServerPluginListener.java rename to src/main/java/io/github/paldiu/simplexcore/listener/DependencyListener.java index 7a68fc8..052b6da 100644 --- a/src/main/java/io/github/paldiu/simplexcore/listener/ServerPluginListener.java +++ b/src/main/java/io/github/paldiu/simplexcore/listener/DependencyListener.java @@ -9,7 +9,7 @@ import org.bukkit.event.server.PluginEnableEvent; import java.util.ArrayList; import java.util.List; -public final class ServerPluginListener extends SimplexListener { +public final class DependencyListener extends SimplexListener { public List PAPI_NAMES = new ArrayList<>() {{ add("PlaceholderAPI"); add("PlaceHolderAPI"); diff --git a/src/main/java/io/github/paldiu/simplexcore/sign/IUsableSign.java b/src/main/java/io/github/paldiu/simplexcore/sign/IUsableSign.java new file mode 100644 index 0000000..0523067 --- /dev/null +++ b/src/main/java/io/github/paldiu/simplexcore/sign/IUsableSign.java @@ -0,0 +1,17 @@ +package io.github.paldiu.simplexcore.sign; + +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.block.Block; + +public interface IUsableSign { + Block getBlock(); + + Location getSignLocation(); + + World getWorld(); + + String getSignText(); + + void executeOnInteract(); +} diff --git a/src/main/java/io/github/paldiu/simplexcore/structures/IStructure.java b/src/main/java/io/github/paldiu/simplexcore/structures/IStructure.java new file mode 100644 index 0000000..fb32415 --- /dev/null +++ b/src/main/java/io/github/paldiu/simplexcore/structures/IStructure.java @@ -0,0 +1,29 @@ +package io.github.paldiu.simplexcore.structures; + +import io.github.paldiu.simplexcore.math.Size; +import org.bukkit.Location; +import org.bukkit.NamespacedKey; +import org.bukkit.World; +import org.bukkit.block.Block; + +public interface IStructure { + NamespacedKey getNamespacedKey(); + + String getName(); + + int getId(); + + Location getLocation(); + + World getWorld(); + + boolean shouldGenerateNaturally(); + + void generate(Location location, World world); + + void generate(Location location, World world, boolean generateNaturally); + + Size getApproximateSize(); + + Block[] getBlocks(); +} diff --git a/src/main/java/io/github/paldiu/simplexcore/structures/Structure.java b/src/main/java/io/github/paldiu/simplexcore/structures/Structure.java new file mode 100644 index 0000000..a101a7c --- /dev/null +++ b/src/main/java/io/github/paldiu/simplexcore/structures/Structure.java @@ -0,0 +1,5 @@ +package io.github.paldiu.simplexcore.structures; + +public class Structure { + // TODO: Write this file to parse schematics. +} From 7dbd8707bb87f885637d446f5712b15563735dc1 Mon Sep 17 00:00:00 2001 From: Recarnation <65880363+Pindicator@users.noreply.github.com> Date: Tue, 23 Feb 2021 18:57:55 +0530 Subject: [PATCH 3/5] Cuboid.java Fix --- .../io/github/paldiu/simplexcore/math/Cuboid.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/java/io/github/paldiu/simplexcore/math/Cuboid.java b/src/main/java/io/github/paldiu/simplexcore/math/Cuboid.java index 5383204..4fd8516 100644 --- a/src/main/java/io/github/paldiu/simplexcore/math/Cuboid.java +++ b/src/main/java/io/github/paldiu/simplexcore/math/Cuboid.java @@ -34,16 +34,14 @@ public final class Cuboid { int b = t2 + y; int c = t3 + z; - while (t1 < a) { - while (t2 < b) { - while (t3 < c) { - t3++; - location.getWorld().getBlockAt(t1, t2, t3).setType(material); + for (int currentX = t1; currentX < a; currentX++) { + for (int currentY = t2; currentY < b; currentY++) { + for (int currentZ = t3; currentZ < c; currentZ++) { + location.getWorld().getBlockAt(currentX, currentY, currentZ).setType(material); } - t2++; } - t1++; } + }; Constants.getScheduler().runTaskLaterAsynchronously(Constants.getPlugin(), task, Constants.getTimeValues().SECOND()); From dda04773724d0506f3351901a336a0ba1f7ec78c Mon Sep 17 00:00:00 2001 From: Recarnation <65880363+Pindicator@users.noreply.github.com> Date: Tue, 23 Feb 2021 19:02:19 +0530 Subject: [PATCH 4/5] A --- .../paldiu/simplexcore/math/Cuboid.java | 52 +------------------ 1 file changed, 1 insertion(+), 51 deletions(-) diff --git a/src/main/java/io/github/paldiu/simplexcore/math/Cuboid.java b/src/main/java/io/github/paldiu/simplexcore/math/Cuboid.java index 5383204..4ba0d19 100644 --- a/src/main/java/io/github/paldiu/simplexcore/math/Cuboid.java +++ b/src/main/java/io/github/paldiu/simplexcore/math/Cuboid.java @@ -1,51 +1 @@ -package io.github.paldiu.simplexcore.math; - -import io.github.paldiu.simplexcore.utils.Constants; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.scheduler.BukkitTask; - -import java.util.function.Consumer; - -public final class Cuboid { - private final int x, y, z; - - public Cuboid() { - this(3, 3, 3); - } - - public Cuboid(int xSize, int ySize, int zSize) { - this.x = xSize; - this.y = ySize; - this.z = zSize; - } - - public Cuboid(Size size) { - this(size.getX(), size.getY(), size.getZ()); - } - - public void generate(Location location, Material material) { - Consumer task = bukkitTask -> { - int t1 = location.getBlockX(); - int t2 = location.getBlockY(); - int t3 = location.getBlockZ(); - - int a = t1 + x; - int b = t2 + y; - int c = t3 + z; - - while (t1 < a) { - while (t2 < b) { - while (t3 < c) { - t3++; - location.getWorld().getBlockAt(t1, t2, t3).setType(material); - } - t2++; - } - t1++; - } - }; - - Constants.getScheduler().runTaskLaterAsynchronously(Constants.getPlugin(), task, Constants.getTimeValues().SECOND()); - } -} +since I can't From 7e4d2499f711871a720746b384470991ea9aa136 Mon Sep 17 00:00:00 2001 From: Recarnation <65880363+Pindicator@users.noreply.github.com> Date: Tue, 23 Feb 2021 19:02:55 +0530 Subject: [PATCH 5/5] Cuboid.java Generate Method Fix --- .../paldiu/simplexcore/math/Cuboid.java | 50 ++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/github/paldiu/simplexcore/math/Cuboid.java b/src/main/java/io/github/paldiu/simplexcore/math/Cuboid.java index 4ba0d19..4fd8516 100644 --- a/src/main/java/io/github/paldiu/simplexcore/math/Cuboid.java +++ b/src/main/java/io/github/paldiu/simplexcore/math/Cuboid.java @@ -1 +1,49 @@ -since I can't +package io.github.paldiu.simplexcore.math; + +import io.github.paldiu.simplexcore.utils.Constants; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.scheduler.BukkitTask; + +import java.util.function.Consumer; + +public final class Cuboid { + private final int x, y, z; + + public Cuboid() { + this(3, 3, 3); + } + + public Cuboid(int xSize, int ySize, int zSize) { + this.x = xSize; + this.y = ySize; + this.z = zSize; + } + + public Cuboid(Size size) { + this(size.getX(), size.getY(), size.getZ()); + } + + public void generate(Location location, Material material) { + Consumer task = bukkitTask -> { + int t1 = location.getBlockX(); + int t2 = location.getBlockY(); + int t3 = location.getBlockZ(); + + int a = t1 + x; + int b = t2 + y; + int c = t3 + z; + + for (int currentX = t1; currentX < a; currentX++) { + for (int currentY = t2; currentY < b; currentY++) { + for (int currentZ = t3; currentZ < c; currentZ++) { + location.getWorld().getBlockAt(currentX, currentY, currentZ).setType(material); + } + } + } + + }; + + Constants.getScheduler().runTaskLaterAsynchronously(Constants.getPlugin(), task, Constants.getTimeValues().SECOND()); + } +}