diff --git a/.gitignore b/.gitignore index 3c0ce68..8ea7e15 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,7 @@ hs_err_pid* *.iml *.xml +*.txt +*.lst +*.lst +target/classes/config.yml diff --git a/pom.xml b/pom.xml index 0fecaf0..0746069 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ io.github.paldiu.simplexcore SimplexCore - 1.1.0-EDGE + 1.13-BLEEDING jar SimplexCore diff --git a/src/main/java/io/github/paldiu/simplexcore/ban/BanFactory.java b/src/main/java/io/github/paldiu/simplexcore/ban/BanFactory.java index e43cb78..14f182d 100644 --- a/src/main/java/io/github/paldiu/simplexcore/ban/BanFactory.java +++ b/src/main/java/io/github/paldiu/simplexcore/ban/BanFactory.java @@ -50,6 +50,7 @@ public final class BanFactory { /** * Creates a new instance of the abstract class Ban. + * * @return A new ban instance. */ public Ban create() { diff --git a/src/main/java/io/github/paldiu/simplexcore/ban/BanType.java b/src/main/java/io/github/paldiu/simplexcore/ban/BanType.java index 05acec2..fc29ef4 100644 --- a/src/main/java/io/github/paldiu/simplexcore/ban/BanType.java +++ b/src/main/java/io/github/paldiu/simplexcore/ban/BanType.java @@ -10,10 +10,6 @@ public enum BanType { this.prefix = prefix; } - public String getPrefix() { - return prefix; - } - public static String value(BanType type) { if (type.equals(PERMANENT)) { return "Permanent"; @@ -23,4 +19,8 @@ public enum BanType { return "Unknown"; } } + + public String getPrefix() { + return prefix; + } } diff --git a/src/main/java/io/github/paldiu/simplexcore/command/SimplexCommand.java b/src/main/java/io/github/paldiu/simplexcore/command/SimplexCommand.java index 42e961a..be547aa 100644 --- a/src/main/java/io/github/paldiu/simplexcore/command/SimplexCommand.java +++ b/src/main/java/io/github/paldiu/simplexcore/command/SimplexCommand.java @@ -2,7 +2,6 @@ package io.github.paldiu.simplexcore.command; import io.github.paldiu.simplexcore.utils.Constants; import io.github.paldiu.simplexcore.utils.Utilities; -import jdk.jfr.BooleanFlag; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -16,7 +15,7 @@ import java.util.List; import java.util.UUID; public abstract class SimplexCommand implements CommandExecutor, TabCompleter { - @BooleanFlag + public boolean isPlayer(CommandSender sender) { return sender instanceof Player; } @@ -33,7 +32,7 @@ public abstract class SimplexCommand implements CommandExecutor, TabCompleter { @Nullable public Player getPlayer(CommandSender sender) { - return isPlayer(sender) ? (Player)sender : null; + return isPlayer(sender) ? (Player) sender : null; } public void playerMsg(Player player, String... messages) { diff --git a/src/main/java/io/github/paldiu/simplexcore/concurrent/SimplexTask.java b/src/main/java/io/github/paldiu/simplexcore/concurrent/SimplexTask.java index 2f234a3..84899bd 100644 --- a/src/main/java/io/github/paldiu/simplexcore/concurrent/SimplexTask.java +++ b/src/main/java/io/github/paldiu/simplexcore/concurrent/SimplexTask.java @@ -7,6 +7,7 @@ import org.bukkit.scheduler.BukkitTask; import java.util.Date; import java.util.function.Consumer; +// TODO: Rewrite this entire class and the task system to have more control over tasks. public abstract class SimplexTask implements Consumer { protected final long DELAY; protected final long INTERVAL; @@ -29,13 +30,13 @@ public abstract class SimplexTask implements Consumer { public void register(T task, SimplexAddon plugin, boolean repeating, boolean delayed) { if (delayed && repeating) { - Constants.getScheduler().runTaskTimerAsynchronously(plugin, task, DELAY, INTERVAL); + Constants.getScheduler().runTaskTimer(plugin, task, DELAY, INTERVAL); } else if (delayed) { - Constants.getScheduler().runTaskLaterAsynchronously(plugin, task, DELAY); + Constants.getScheduler().runTaskLater(plugin, task, DELAY); } else if (repeating) { - Constants.getScheduler().runTaskTimerAsynchronously(plugin, task, 0L, INTERVAL); + Constants.getScheduler().runTaskTimer(plugin, task, 0L, INTERVAL); } else { - Constants.getScheduler().runTaskAsynchronously(plugin, task); + Constants.getScheduler().runTask(plugin, task); } } diff --git a/src/main/java/io/github/paldiu/simplexcore/concurrent/TaskFactory.java b/src/main/java/io/github/paldiu/simplexcore/concurrent/TaskFactory.java new file mode 100644 index 0000000..f5e3cb5 --- /dev/null +++ b/src/main/java/io/github/paldiu/simplexcore/concurrent/TaskFactory.java @@ -0,0 +1,4 @@ +package io.github.paldiu.simplexcore.concurrent; + +public final class TaskFactory { +} 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 329360f..570e3e8 100644 --- a/src/main/java/io/github/paldiu/simplexcore/config/Yaml.java +++ b/src/main/java/io/github/paldiu/simplexcore/config/Yaml.java @@ -1,10 +1,7 @@ package io.github.paldiu.simplexcore.config; -import io.github.paldiu.simplexcore.functional.Guard; import io.github.paldiu.simplexcore.plugin.SimplexAddon; -import io.github.paldiu.simplexcore.utils.Bean; import io.github.paldiu.simplexcore.utils.Constants; -import io.github.paldiu.simplexcore.utils.Utilities; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; @@ -24,11 +21,11 @@ public final class Yaml implements IConfig { Yaml(SimplexAddon plugin, String fileName, File directory, String resourcePath) { if (!fileName.endsWith(".yml")) { - fileName+=".yml"; + fileName += ".yml"; } if (!resourcePath.endsWith(".yml")) { - resourcePath+=".yml"; + resourcePath += ".yml"; } this.plugin = plugin; diff --git a/src/main/java/io/github/paldiu/simplexcore/gui/AbstractGUI.java b/src/main/java/io/github/paldiu/simplexcore/gui/AbstractGUI.java new file mode 100644 index 0000000..f865ebd --- /dev/null +++ b/src/main/java/io/github/paldiu/simplexcore/gui/AbstractGUI.java @@ -0,0 +1,121 @@ +package io.github.paldiu.simplexcore.gui; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.Listener; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.*; + +public abstract class AbstractGUI implements InventoryHolder, IGUI { + private final Inventory INV; + private final Map actions; + private final UUID uuid; + + private final List validSize = new ArrayList<>(){{ + add(9); + add(18); + add(27); + add(36); + add(45); + add(54); + }}; + + public static final Map invByUUId = new HashMap<>(); + public static final Map openInvs = new HashMap<>(); + + public AbstractGUI(int size, String name) { + uuid = UUID.randomUUID(); + if (!validSize.contains(size)) { + throw new NumberFormatException("Inventory sizes must be a multiple of nine!"); + } + INV = Bukkit.createInventory(null, size, name); + actions = new HashMap<>(); + invByUUId.put(getInvUUId(), this); + } + + @Override + public UUID getInvUUId() { + return uuid; + } + + @NotNull + @Override + public Inventory getInventory() { + return INV; + } + + @Override + public void setItem(int slot, @NotNull ItemStack stack, @Nullable Action action) { + INV.setItem(slot, stack); + if (action != null) { + actions.put(slot, action); + } + } + + @Override + public void setItem(int slot, @NotNull ItemStack stack) { + setItem(slot, stack, null); + } + + @Override + public void open(@NotNull Player player) { + player.openInventory(INV); + openInvs.put(player.getUniqueId(), getInvUUId()); + } + + @Override + public void close(@NotNull Player player) { + player.closeInventory(); + openInvs.remove(player.getUniqueId()); + } + + @Override + public void delete() { + Bukkit.getOnlinePlayers().forEach(player -> { + UUID id = openInvs.get(player.getUniqueId()); + if (id.equals(getInvUUId())) { + player.closeInventory(); + } + }); + invByUUId.remove(getInvUUId()); + } + + public static Map getInvByUUId() { + return invByUUId; + } + + public static Map getOpenInvs() { + return openInvs; + } + + @Override + public Map getActions() { + return actions; + } + + @Override + public ItemStack newItem(@NotNull Material material, @NotNull String name, String... lore) { + ItemStack item = new ItemStack(material, 1); + ItemMeta meta = item.getItemMeta(); + if (meta == null) { + return item; + } + meta.setDisplayName(name); + ArrayList metaLore = new ArrayList<>(Arrays.asList(lore)); + meta.setLore(metaLore); + item.setItemMeta(meta); + return item; + } + + @Override + public ItemStack newItem(@NotNull Material material, @NotNull String name) { + return newItem(material, name, ""); + } +} diff --git a/src/main/java/io/github/paldiu/simplexcore/gui/Action.java b/src/main/java/io/github/paldiu/simplexcore/gui/Action.java new file mode 100644 index 0000000..2d87fd6 --- /dev/null +++ b/src/main/java/io/github/paldiu/simplexcore/gui/Action.java @@ -0,0 +1,8 @@ +package io.github.paldiu.simplexcore.gui; + +import org.bukkit.entity.Player; + +@FunctionalInterface +public interface Action { + void onClick(Player player); +} diff --git a/src/main/java/io/github/paldiu/simplexcore/gui/GUIHandler.java b/src/main/java/io/github/paldiu/simplexcore/gui/GUIHandler.java new file mode 100644 index 0000000..aa51005 --- /dev/null +++ b/src/main/java/io/github/paldiu/simplexcore/gui/GUIHandler.java @@ -0,0 +1,38 @@ +package io.github.paldiu.simplexcore.gui; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; + +import java.util.UUID; + +public final class GUIHandler implements Listener { + @EventHandler(priority = EventPriority.NORMAL) + public void invClick(InventoryClickEvent event) { + if (!(event.getWhoClicked() instanceof Player)) { + return; + } + + Player player = (Player) event.getWhoClicked(); + UUID pID = player.getUniqueId(); + UUID invUUID = AbstractGUI.getOpenInvs().get(pID); + + if (invUUID != null) { + event.setCancelled(true); + IGUI gui = AbstractGUI.getInvByUUId().get(invUUID); + Action action = gui.getActions().get(event.getSlot()); + if (action != null) { + action.onClick(player); + } + } + } + + @EventHandler(priority = EventPriority.NORMAL) + public void onClose(InventoryCloseEvent event) { + Player player = (Player) event.getPlayer(); + AbstractGUI.getOpenInvs().remove(player.getUniqueId()); + } +} diff --git a/src/main/java/io/github/paldiu/simplexcore/gui/IGUI.java b/src/main/java/io/github/paldiu/simplexcore/gui/IGUI.java new file mode 100644 index 0000000..bd6d64e --- /dev/null +++ b/src/main/java/io/github/paldiu/simplexcore/gui/IGUI.java @@ -0,0 +1,33 @@ +package io.github.paldiu.simplexcore.gui; + +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Map; +import java.util.UUID; + +public interface IGUI { + UUID getInvUUId(); + + Inventory getInventory(); + + void setItem(int slot, @NotNull ItemStack stack, @Nullable Action action); + + void setItem(int slot, @NotNull ItemStack stack); + + void open(@NotNull Player player); + + void close(@NotNull Player player); + + void delete(); + + Map getActions(); + + ItemStack newItem(@NotNull Material material, @NotNull String name, String... lore); + + ItemStack newItem(@NotNull Material material, @NotNull String name); +} diff --git a/src/main/java/io/github/paldiu/simplexcore/sign/IUsableSign.java b/src/main/java/io/github/paldiu/simplexcore/sign/IUsableSign.java index 0523067..ff4f9e7 100644 --- a/src/main/java/io/github/paldiu/simplexcore/sign/IUsableSign.java +++ b/src/main/java/io/github/paldiu/simplexcore/sign/IUsableSign.java @@ -14,4 +14,6 @@ public interface IUsableSign { String getSignText(); void executeOnInteract(); + + String signTag(); } diff --git a/src/main/java/io/github/paldiu/simplexcore/utils/Constants.java b/src/main/java/io/github/paldiu/simplexcore/utils/Constants.java index 46e05f2..6d0e6b0 100644 --- a/src/main/java/io/github/paldiu/simplexcore/utils/Constants.java +++ b/src/main/java/io/github/paldiu/simplexcore/utils/Constants.java @@ -14,11 +14,6 @@ import org.bukkit.scheduler.BukkitScheduler; import java.util.logging.Logger; public final class Constants { - // Utility class should not be instantiated. - private Constants() { - throw new AssertionError(); - } - private static final SimplexCore plugin = JavaPlugin.getPlugin(SimplexCore.class); private static final Server server = plugin.getServer(); private static final Logger logger = plugin.getLogger(); @@ -27,6 +22,10 @@ public final class Constants { private static final DependencyManagement dpm = new DependencyManagement(); private static final Yaml config = new YamlFactory(plugin).setDefaultPathways(); private static final TimeValues time = new TimeValues(); + // Utility class should not be instantiated. + private Constants() { + throw new AssertionError(); + } public static SimplexCore getPlugin() { return plugin; diff --git a/src/main/java/io/github/paldiu/simplexcore/utils/Utilities.java b/src/main/java/io/github/paldiu/simplexcore/utils/Utilities.java index 88ff103..ba58e9a 100644 --- a/src/main/java/io/github/paldiu/simplexcore/utils/Utilities.java +++ b/src/main/java/io/github/paldiu/simplexcore/utils/Utilities.java @@ -2,11 +2,30 @@ package io.github.paldiu.simplexcore.utils; import io.github.paldiu.simplexcore.ban.BanType; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.SplittableRandom; import java.util.function.Consumer; import java.util.stream.Stream; public final class Utilities { + private static final SplittableRandom random = new SplittableRandom(); + private static final SplittableRandom numbers = new SplittableRandom(); + private static final List list = new ArrayList<>() {{ + add('0'); + add('1'); + add('2'); + add('3'); + add('4'); + add('5'); + add('6'); + add('7'); + add('8'); + add('9'); + add('-'); + }}; + //Utility class should not be instantiated. private Utilities() { throw new AssertionError(); @@ -41,22 +60,6 @@ public final class Utilities { return sb.toString(); } - private static final SplittableRandom random = new SplittableRandom(); - private static final SplittableRandom numbers = new SplittableRandom(); - private static final List list = new ArrayList<>(){{ - add('0'); - add('1'); - add('2'); - add('3'); - add('4'); - add('5'); - add('6'); - add('7'); - add('8'); - add('9'); - add('-'); - }}; - private static char capitalize(char character) { if (list.contains(character)) { return character; diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst index 8f6ed4b..6b65c3b 100644 --- a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -1,30 +1,51 @@ -io\github\paldiu\simplexcore\command\defaults\Command_info.class -io\github\paldiu\simplexcore\listener\ServerPluginListener.class io\github\paldiu\simplexcore\command\CommandLoader.class +io\github\paldiu\simplexcore\ban\BanType.class io\github\paldiu\simplexcore\command\CommandInfo.class -io\github\paldiu\simplexcore\future\Announcer$1.class -io\github\paldiu\simplexcore\plugin\AddonRegistry.class io\github\paldiu\simplexcore\command\CommandLoader$Registry.class -io\github\paldiu\simplexcore\CoreState$1.class io\github\paldiu\simplexcore\utils\Constants$TimeValues.class io\github\paldiu\simplexcore\CoreState.class -io\github\paldiu\simplexcore\config\YamlFactory.class +io\github\paldiu\simplexcore\concurrent\TaskFactory.class +io\github\paldiu\simplexcore\listener\DependencyListener$1.class +io\github\paldiu\simplexcore\concurrent\SimplexTask.class +io\github\paldiu\simplexcore\potion\PotionsFactory.class io\github\paldiu\simplexcore\plugin\SimplexAddon.class io\github\paldiu\simplexcore\chat\Messages.class +io\github\paldiu\simplexcore\gui\Action.class +io\github\paldiu\simplexcore\gui\GUIHandler.class io\github\paldiu\simplexcore\plugin\AddonManager.class -io\github\paldiu\simplexcore\chat\ChatUtils.class +io\github\paldiu\simplexcore\structures\Structure.class +io\github\paldiu\simplexcore\gui\AbstractGUI.class io\github\paldiu\simplexcore\command\defaults\DefaultCommand.class io\github\paldiu\simplexcore\utils\Utilities.class -io\github\paldiu\simplexcore\chat\TextComponentFactory.class -io\github\paldiu\simplexcore\command\SimplexCommand.class +io\github\paldiu\simplexcore\ban\BanFactory.class io\github\paldiu\simplexcore\math\Size.class +io\github\paldiu\simplexcore\config\Path.class io\github\paldiu\simplexcore\utils\Bean.class -io\github\paldiu\simplexcore\utils\Constants.class -io\github\paldiu\simplexcore\future\SimplexTask.class +io\github\paldiu\simplexcore\ban\Ban.class io\github\paldiu\simplexcore\config\JsonFactory.class +io\github\paldiu\simplexcore\listener\DependencyListener.class io\github\paldiu\simplexcore\SimplexCore.class io\github\paldiu\simplexcore\utils\Trio.class -io\github\paldiu\simplexcore\listener\SimplexListener.class -io\github\paldiu\simplexcore\future\Announcer.class +io\github\paldiu\simplexcore\config\IConfig.class io\github\paldiu\simplexcore\math\Cuboid.class io\github\paldiu\simplexcore\CoreState$State.class +io\github\paldiu\simplexcore\concurrent\Announcer.class +io\github\paldiu\simplexcore\command\defaults\Command_info.class +io\github\paldiu\simplexcore\particle\IParticleEffect.class +io\github\paldiu\simplexcore\structures\IStructure.class +io\github\paldiu\simplexcore\concurrent\Announcer$1.class +io\github\paldiu\simplexcore\plugin\AddonRegistry.class +io\github\paldiu\simplexcore\CoreState$1.class +io\github\paldiu\simplexcore\config\YamlFactory.class +io\github\paldiu\simplexcore\potion\IPotionEffect.class +io\github\paldiu\simplexcore\gui\AbstractGUI$1.class +io\github\paldiu\simplexcore\chat\ChatUtils.class +io\github\paldiu\simplexcore\gui\IGUI.class +io\github\paldiu\simplexcore\chat\TextComponentFactory.class +io\github\paldiu\simplexcore\command\SimplexCommand.class +io\github\paldiu\simplexcore\ban\BanFactory$1.class +io\github\paldiu\simplexcore\sign\IUsableSign.class +io\github\paldiu\simplexcore\utils\Constants.class +io\github\paldiu\simplexcore\ban\IBan.class +io\github\paldiu\simplexcore\listener\SimplexListener.class +io\github\paldiu\simplexcore\listener\DependencyListener$2.class