From a164e6fd0396054170b23f1c38b8cbb1574177e5 Mon Sep 17 00:00:00 2001 From: Asleepp Date: Sun, 26 May 2024 18:18:05 -0300 Subject: [PATCH 01/10] Not finished (also wtf happened bukkit) --- .../SkriptItemsAdder/SkriptItemsAdder.java | 1 + .../SkriptItemsAdder/UpdateChecker.java | 123 +++++++----------- .../elements/conditions/CondGetAction.java | 4 +- .../conditions/CondGetBlockClicked.java | 2 +- .../conditions/CondIsCustomBlock.java | 2 +- .../conditions/CondIsCustomEntity.java | 2 +- .../elements/conditions/CondIsCustomItem.java | 2 +- .../elements/conditions/CondIsFullyGrown.java | 47 +++++++ .../effects/EffMakeEntityPlayAnimation.java | 4 +- .../effects/EffOpenCustomInventory.java | 2 +- .../elements/effects/EffPlaceBlock.java | 62 --------- .../elements/effects/EffPlaceBlockOrCrop.java | 74 +++++++++++ .../effects/EffPlaceCustomFurniture.java | 4 +- .../elements/effects/EffPlayBreakEffect.java | 2 +- .../effects/EffPlayIATotemAnimation.java | 2 +- .../elements/effects/EffPlayerEmote.java | 2 +- .../effects/EffRemoveCustomFurniture.java | 2 +- .../elements/effects/EffReplaceBlock.java | 4 +- .../effects/EffReplaceCustomFurniture.java | 4 +- .../effects/EffSendIAResourcePack.java | 2 +- .../elements/effects/EffSetBlocksBetween.java | 2 +- .../effects/EffSetInventoryIASlot.java | 2 +- .../effects/EffSpawnCustomEntity.java | 2 +- .../elements/events/EvtCustomBlockBreak.java | 2 +- .../events/EvtCustomBlockInteract.java | 2 +- .../elements/events/EvtCustomBlockPlace.java | 2 +- .../elements/events/EvtCustomEntityDeath.java | 2 +- .../events/EvtCustomFurnitureBreak.java | 18 ++- .../events/EvtCustomFurnitureInteract.java | 19 ++- .../events/EvtCustomFurniturePlace.java | 2 +- .../EvtCustomFurnitureSuccessEvent.java | 15 ++- .../elements/events/EvtEmote.java | 73 +++++++++++ .../events/EvtResourcePackSendEvent.java | 2 +- .../elements/expressions/ExprCropAge.java | 93 +++++++++++++ .../ExprGetCustomBlockClicked.java | 52 -------- .../expressions/ExprGetCustomBlockItem.java | 6 +- .../expressions/ExprGetCustomItem.java | 33 +++-- .../expressions/ExprGetFontImage.java | 13 +- .../elements/expressions/ExprGetID.java | 75 +++++++++++ .../elements/expressions/ExprGetLoot.java | 59 +++++++++ .../expressions/ExprLastCreatedIAGui.java | 4 +- .../sections/SecCreateCustomInventory.java | 4 +- 42 files changed, 571 insertions(+), 258 deletions(-) create mode 100644 src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsFullyGrown.java delete mode 100644 src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlaceBlock.java create mode 100644 src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlaceBlockOrCrop.java create mode 100644 src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtEmote.java create mode 100644 src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprCropAge.java delete mode 100644 src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetCustomBlockClicked.java create mode 100644 src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetID.java create mode 100644 src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetLoot.java diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/SkriptItemsAdder.java b/src/main/java/me/asleepp/SkriptItemsAdder/SkriptItemsAdder.java index 5e58a6e..7f7a0da 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/SkriptItemsAdder.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/SkriptItemsAdder.java @@ -54,6 +54,7 @@ public void onEnable() { instance = this; addon = Skript.registerAddon(this); addon.setLanguageFileDirectory("lang"); + UpdateChecker.check(this); try { addon.loadClasses("me.asleepp.SkriptItemsAdder"); } catch (IOException error) { diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/UpdateChecker.java b/src/main/java/me/asleepp/SkriptItemsAdder/UpdateChecker.java index 74d9305..59c6b2b 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/UpdateChecker.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/UpdateChecker.java @@ -1,95 +1,62 @@ package me.asleepp.SkriptItemsAdder; import ch.njol.skript.util.Version; +import com.google.gson.Gson; import com.google.gson.JsonObject; -import com.google.gson.JsonParser; +import net.kyori.adventure.text.minimessage.MiniMessage; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.plugin.java.JavaPlugin; +import java.io.BufferedReader; import java.io.InputStreamReader; -import java.net.HttpURLConnection; import java.net.URL; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; - -// Credits to ShaneBee, yoinked his Update Checker code from SkBee - -public class UpdateChecker implements Listener { - - private static Version UPDATE_VERSION; - - public static void checkForUpdate(JavaPlugin plugin, String pluginVersion) { - plugin.getLogger().info("Checking for update..."); - getLatestReleaseVersion(version -> { - Version plugVer = new Version(pluginVersion); - Version curVer = new Version(version); - if (curVer.compareTo(plugVer) <= 0) { - plugin.getLogger().info("Plugin is up to date!"); - } else { - plugin.getLogger().warning("Plugin is not up to date!"); - plugin.getLogger().warning(" - Current version: " + pluginVersion); - plugin.getLogger().warning(" - Available update: " + version); - plugin.getLogger().warning(" - Download available at: https://github.com/Asleeepp/skript-itemsadder/releases"); - UPDATE_VERSION = curVer; - } - }, plugin); - } - - private static void getLatestReleaseVersion(final Consumer consumer, JavaPlugin plugin) { - try { - URL url = new URL("https://api.github.com/repos/Asleeepp/skript-itemsadder/releases/latest"); - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setRequestMethod("GET"); - JsonObject jsonObject = new JsonParser().parse(new InputStreamReader(connection.getInputStream())).getAsJsonObject(); - String tag_name = jsonObject.get("tag_name").getAsString(); - consumer.accept(tag_name); - } catch (Exception e) { - plugin.getLogger().severe("Checking for update failed: " + e.getMessage()); - } - } - - - private final SkriptItemsAdder plugin; - - public UpdateChecker(SkriptItemsAdder plugin) { - this.plugin = plugin; - } - - @EventHandler - private void onJoin(PlayerJoinEvent event) { - Player player = event.getPlayer(); - if (!player.hasPermission("skript-itemsadder.update.check")) return; - - String currentVersion = this.plugin.getDescription().getVersion(); - CompletableFuture updateVersion = getUpdateVersion(currentVersion); - - Bukkit.getScheduler().runTaskLater(this.plugin, () -> updateVersion.thenApply(version -> { - player.sendMessage("[skript-itemsadder] update available: " + version); - player.sendMessage("[skript-itemsadder] download at https://github.com/Asleeepp/skript-itemsadder/releases"); - return true; - }), 30); +import java.util.logging.Level; + +/** + * @author ShaneBeee, ImNotStable, Equipable + */ + +public class UpdateChecker { + + public static void check(SkriptItemsAdder plugin) { + String latestVersion = getLatestVersion(); + if (latestVersion == null) + return; + String currentVersion = plugin.getDescription().getVersion(); + if (new Version(currentVersion).isSmallerThan(new Version(latestVersion))) { + SkriptItemsAdder.getInstance().getLogger().info("skript-itemsadder is NOT up to date!"); + SkriptItemsAdder.getInstance().getLogger().info("> Current Version: " + currentVersion); + SkriptItemsAdder.getInstance().getLogger().info("> Latest Version: " + latestVersion); + SkriptItemsAdder.getInstance().getLogger().info("> Download it at: https://github.com/Asleeepp/skript-itemsadder/releases"); + Bukkit.getPluginManager().registerEvents(new Listener() { + @EventHandler + public void on(PlayerJoinEvent event) { + Player player = event.getPlayer(); + if (!player.hasPermission("skript-itemsadder.update.check") && !player.isOp()) return; + + player.sendMessage(" "); + player.sendMessage(MiniMessage.miniMessage().deserialize("[skript-itemsadder] skript-itemsadder is OUTDATED!")); + player.sendMessage(MiniMessage.miniMessage().deserialize("[skript-itemsadder] New version: " + latestVersion)); + player.sendMessage(MiniMessage.miniMessage().deserialize("[skript-itemsadder] Download at: https://github.com/Asleeepp/skript-itemsadder/releases")); + player.sendMessage(" "); + } + }, plugin); + } else + SkriptItemsAdder.getInstance().getLogger().info("skript-itemsadder is up to date!"); } - private CompletableFuture getUpdateVersion(String currentVersion) { - CompletableFuture future = new CompletableFuture<>(); - if (UPDATE_VERSION != null) { - future.complete(UPDATE_VERSION); - } else { - Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> getLatestReleaseVersion(version -> { - Version plugVer = new Version(currentVersion); - Version curVer = new Version(version); - if (curVer.compareTo(plugVer) <= 0) { - future.cancel(true); - } else { - UPDATE_VERSION = curVer; - future.complete(UPDATE_VERSION); - } - }, this.plugin)); + private static String getLatestVersion() { + String url = "https://api.github.com/repos/Asleeepp/skript-itemsadder/releases/latest"; + try (BufferedReader reader = new BufferedReader(new InputStreamReader(new URL(url).openStream()))) { + JsonObject jsonObject = new Gson().fromJson(reader, JsonObject.class); + return jsonObject.get("tag_name").getAsString(); + } catch (Exception exception) { + SkriptItemsAdder.getInstance().getLogger().log(Level.WARNING, "Failed to check for latest version."); + exception.printStackTrace(); } - return future; + return null; } } diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondGetAction.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondGetAction.java index 8e22366..8c095e0 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondGetAction.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondGetAction.java @@ -19,14 +19,14 @@ @Description({"This condition checks if the player has interacted with a custom block with either a left or a right click."}) @Examples({ "on interact with custom block:", - "\tif interact action is right click:", + "\tif itemsadder interact action is right click:", "\t\tkill event-player"}) @Since("1.4") @RequiredPlugins("ItemsAdder") public class CondGetAction extends Condition { static { - Skript.registerCondition(CondGetAction.class, "[custom|ia|itemsadder] [interact] action is (:right|:left) click"); + Skript.registerCondition(CondGetAction.class, "[custom] (ia|itemsadder) [interact] action is (right|:left) click"); } private boolean isLeft; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondGetBlockClicked.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondGetBlockClicked.java index e88672b..d33f469 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondGetBlockClicked.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondGetBlockClicked.java @@ -27,7 +27,7 @@ public class CondGetBlockClicked extends Condition { private Expression block; static { - Skript.registerCondition(CondGetBlockClicked.class, "[the] block clicked is %strings%"); + Skript.registerCondition(CondGetBlockClicked.class, "[the] [custom] (ia|itemsadder) clicked block is %strings%"); } @Override diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomBlock.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomBlock.java index 8eb49bd..dd2e05a 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomBlock.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomBlock.java @@ -30,7 +30,7 @@ public class CondIsCustomBlock extends Condition { private Expression blockId; static { - Skript.registerCondition(CondIsCustomBlock.class, "%blocks% (is [a[n]]|are) (custom|ia|itemsadder) block[s] [[with id] %-string%]", "%blocks% (is[n't| not]) [a] (custom|ia|itemsadder) block[s] [[with id] %-string%]"); + Skript.registerCondition(CondIsCustomBlock.class, "%blocks% (is [a[n]]|are) [custom] (ia|itemsadder) block[s] [[with id] %-string%]", "%blocks% (is[n't| not]) [a] [custom] (ia|itemsadder) block[s] [[with id] %-string%]"); } @SuppressWarnings("unchecked") diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomEntity.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomEntity.java index bd1fc1f..9f49fa3 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomEntity.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomEntity.java @@ -31,7 +31,7 @@ public class CondIsCustomEntity extends Condition { private Expression entityId; static { - Skript.registerCondition(CondIsCustomEntity.class, new String[] {"%entities% (is [a[n]]|are) (custom|ia|itemsadder) entit(y|ies) [[with id] %-string%]", "%entities% (is[n't| not]) [a] (custom|ia|itemsadder) entit(y|ies) [[with id] %-string%]"}); + Skript.registerCondition(CondIsCustomEntity.class, "%entities% (is [a[n]]|are) [custom] (ia|itemsadder) entit(y|ies) [[with id] %-string%]", "%entities% (is[n't| not]) [a] [custom] (ia|itemsadder) entit(y|ies) [[with id] %-string%]"); } @SuppressWarnings("unchecked") diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomItem.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomItem.java index a313823..1754f96 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomItem.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomItem.java @@ -28,7 +28,7 @@ public class CondIsCustomItem extends Condition { private Expression itemId; static{ - Skript.registerCondition(CondIsCustomItem.class, new String[] {"%itemtypes% (is [a[n]]|are) (custom|ia|itemsadder) item[s] [[with id] %-string%]", "%itemtypes% (is[n't| not]) [a] (custom|ia|itemsadder) item[s] [[with id] %-string%]"}); + Skript.registerCondition(CondIsCustomItem.class, "%itemtypes% (is [a[n]]|are) [custom] (ia|itemsadder) item[s] [[with id] %-string%]", "%itemtypes% (is[n't| not]) [a] [custom] (ia|itemsadder) item[s] [[with id] %-string%]"); } @SuppressWarnings("unchecked") diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsFullyGrown.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsFullyGrown.java new file mode 100644 index 0000000..6deb016 --- /dev/null +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsFullyGrown.java @@ -0,0 +1,47 @@ +package me.asleepp.SkriptItemsAdder.elements.conditions; + +import ch.njol.skript.Skript; +import ch.njol.skript.lang.Condition; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser; +import ch.njol.util.Kleenean; +import dev.lone.itemsadder.api.CustomCrop; +import org.bukkit.block.Block; +import org.bukkit.event.Event; + +import javax.annotation.Nullable; + +public class CondIsFullyGrown extends Condition { + + private Expression blocks; + + static { + Skript.registerCondition(CondIsFullyGrown.class, + "[the] [custom] (ia|itemsadder) %blocks% (is|are) full[y] grown", + "[the] [custom] (ia|itemsadder) %blocks% (is|are) not full[y] grown"); + } + + @Override + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { + blocks = (Expression) exprs[0]; + setNegated(matchedPattern == 1); + return true; + } + + @Override + public boolean check(Event e) { + Block[] bs = blocks.getArray(e); + for (Block b : bs) { + CustomCrop crop = CustomCrop.byAlreadyPlaced(b); + if (crop != null && crop.isFullyGrown() != isNegated()) { + return false; + } + } + return true; + } + + @Override + public String toString(@Nullable Event e, boolean debug) { + return blocks.toString(e, debug) + (isNegated() ? " is not" : " is") + " fully grown"; + } +} diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffMakeEntityPlayAnimation.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffMakeEntityPlayAnimation.java index 7b7461b..5f3ee61 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffMakeEntityPlayAnimation.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffMakeEntityPlayAnimation.java @@ -20,7 +20,7 @@ @Examples({ "on right click:", "\tif clicked entity is a custom entity", - "\t\tmake clicked entity play animation \"fortnite:default_dance\""}) + "\t\tmake clicked entity play itemsadder animation \"fortnite:default_dance\""}) @Since("1.0") @RequiredPlugins("ItemsAdder") public class EffMakeEntityPlayAnimation extends Effect { @@ -30,7 +30,7 @@ public class EffMakeEntityPlayAnimation extends Effect { static { - Skript.registerEffect(EffMakeEntityPlayAnimation.class, new String[] {"(make|force) %entities% [to] play (anim|animation) %string%"}); + Skript.registerEffect(EffMakeEntityPlayAnimation.class, new String[] {"(make|force) %entities% [to] play [custom] (ia|itemsadder) (anim[ation]) %string%"}); } @Override diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffOpenCustomInventory.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffOpenCustomInventory.java index c30039a..59a4eb4 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffOpenCustomInventory.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffOpenCustomInventory.java @@ -27,7 +27,7 @@ public class EffOpenCustomInventory extends Effect { private Expression inventory; static { - Skript.registerEffect(EffOpenCustomInventory.class, "(show|open) [a[n]|the] (custom|ia|itemsadder) [inventory] %texturedinventorywrapper% to %players%"); + Skript.registerEffect(EffOpenCustomInventory.class, "(show|open) [a[n]|the] [custom] (ia|itemsadder) [inventory] %texturedinventorywrapper% to %players%"); } @Override diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlaceBlock.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlaceBlock.java deleted file mode 100644 index a18a641..0000000 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlaceBlock.java +++ /dev/null @@ -1,62 +0,0 @@ -package me.asleepp.SkriptItemsAdder.elements.effects; - -import ch.njol.skript.Skript; -import ch.njol.skript.doc.Description; -import ch.njol.skript.doc.Examples; -import ch.njol.skript.doc.Name; -import ch.njol.skript.doc.RequiredPlugins; -import ch.njol.skript.doc.Since; -import ch.njol.skript.lang.Effect; -import ch.njol.skript.lang.Expression; -import ch.njol.skript.lang.SkriptParser; -import ch.njol.util.Kleenean; -import dev.lone.itemsadder.api.CustomBlock; -import org.bukkit.Location; -import org.bukkit.event.Event; - -import javax.annotation.Nullable; -@Name("Place Custom Block") -@Description({"Places a custom block at a location."}) -@Examples({"set block at player's location to custom itemsadder block \"iasurvival:ruby_block\""}) -@Since("1.0") -@RequiredPlugins("ItemsAdder") -public class EffPlaceBlock extends Effect { - private Expression locationExpr; - private Expression customBlockIdExpr; - - static { - Skript.registerEffect(EffPlaceBlock.class, new String[]{"(set|place) block at %locations% to (custom|ia|itemsadder) block %string%"}); - } - - @Override - public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { - locationExpr = (Expression) exprs[0]; - if (exprs.length > 1 && exprs[1] != null) { - customBlockIdExpr = (Expression) exprs[1]; - } - return true; - } - - @Override - protected void execute(Event e) { - Location[] locations = locationExpr.getArray(e); - String customBlockId = customBlockIdExpr.getSingle(e); - - if (locations == null || customBlockId == null) { - return; - } - - for (Location location : locations) { - CustomBlock customBlock = CustomBlock.getInstance(customBlockId); - if (customBlock != null) { - customBlock.place(location); - } - } - } - - - @Override - public String toString(@Nullable Event e, boolean debug) { - return "place custom block " + customBlockIdExpr.toString(e, debug) + " at " + locationExpr.toString(e, debug); - } -} diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlaceBlockOrCrop.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlaceBlockOrCrop.java new file mode 100644 index 0000000..a323124 --- /dev/null +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlaceBlockOrCrop.java @@ -0,0 +1,74 @@ +package me.asleepp.SkriptItemsAdder.elements.effects; + +import ch.njol.skript.Skript; +import ch.njol.skript.doc.Description; +import ch.njol.skript.doc.Examples; +import ch.njol.skript.doc.Name; +import ch.njol.skript.doc.RequiredPlugins; +import ch.njol.skript.doc.Since; +import ch.njol.skript.lang.Effect; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser; +import ch.njol.skript.util.Direction; +import ch.njol.util.Kleenean; +import dev.lone.itemsadder.api.CustomBlock; +import dev.lone.itemsadder.api.CustomCrop; +import org.bukkit.Location; +import org.bukkit.event.Event; + +import javax.annotation.Nullable; +@Name("Place Custom Block/Crop") +@Description({"Places a custom block or crop at a location."}) +@Examples({ + "set block at player's location to itemsadder block \"iasurvival:ruby_block\"", + "set block at player's location to custom crop \"bestcrops:best_seed\""}) +@Since("1.0, 1.5 (Placing Crops & Syntax rework)") +@RequiredPlugins("ItemsAdder") +public class EffPlaceBlockOrCrop extends Effect { + private Expression locations; + private Expression customBlockIdExpr; + private boolean isCrop; + + static { + Skript.registerEffect(EffPlaceBlockOrCrop.class, "(set|place) [custom] (ia|itemsadder) (block|:crop) %string% at [%directions% %locations%]"); + } + + @Override + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { + customBlockIdExpr = (Expression) exprs[0]; + locations = Direction.combine((Expression) exprs[1], (Expression) exprs[2]); + if (parseResult.hasTag("crop")) + isCrop = true; + return true; + } + + @Override + protected void execute(Event e) { + String customBlockId = customBlockIdExpr.getSingle(e); + + if (locations == null || customBlockId == null) { + return; + } + // TODO test this + for (Location location : this.locations.getArray(e)) { + if (isCrop) { + try { // for some reason CustomCrop doesn't have getInstance + CustomCrop crop = CustomCrop.place(customBlockId, location); + } + catch (Exception exception) { + Skript.error("Your namespace:id does not exist."); + } + } else { + CustomBlock block = CustomBlock.getInstance(customBlockId); + if (block != null) { + block.place(location); + } + } + } + } + + @Override + public String toString(@Nullable Event e, boolean debug) { + return "place custom " + (isCrop ? "crop " : "block ") + this.customBlockIdExpr.toString(e, debug) + " at " + this.locations.toString(e, debug); + } +} \ No newline at end of file diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlaceCustomFurniture.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlaceCustomFurniture.java index 067b4a1..1400d7e 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlaceCustomFurniture.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlaceCustomFurniture.java @@ -27,7 +27,7 @@ public class EffPlaceCustomFurniture extends Effect { private Expression location; static { - Skript.registerEffect(EffPlaceCustomFurniture.class, "(set|place) (custom|ia|itemsadder) furniture %string% at %location%"); + Skript.registerEffect(EffPlaceCustomFurniture.class, "(set|place) [custom] (ia|itemsadder) furniture %string% at %location%"); } @Override @@ -42,7 +42,7 @@ protected void execute(Event e) { @Override public String toString(@Nullable Event e, boolean debug) { - return "(set|place) (custom|ia|itemsadder) furniture " + furnitureId.toString(e, debug) + " at " + location.toString(e, debug); + return "(set|place) [custom] (ia|itemsadder) furniture " + furnitureId.toString(e, debug) + " at " + location.toString(e, debug); } @Override diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlayBreakEffect.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlayBreakEffect.java index 66298f6..9d06c58 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlayBreakEffect.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlayBreakEffect.java @@ -27,7 +27,7 @@ public class EffPlayBreakEffect extends Effect { private Expression blocks; static { - Skript.registerEffect(EffPlayBreakEffect.class, "(show|play) break[ing] effect on [custom|ia|itemsadder] %blocks%"); + Skript.registerEffect(EffPlayBreakEffect.class, "(show|play) break[ing] effect on [custom] (ia|itemsadder) %blocks%"); } @SuppressWarnings("unchecked") diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlayIATotemAnimation.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlayIATotemAnimation.java index 5cb46b5..0c95c5f 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlayIATotemAnimation.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlayIATotemAnimation.java @@ -26,7 +26,7 @@ public class EffPlayIATotemAnimation extends Effect { private Expression totem; static { - Skript.registerEffect(EffPlayIATotemAnimation.class, "(play|make) [the] (custom|ia|itemsadder) totem [anim|animation] %string% to %players%"); + Skript.registerEffect(EffPlayIATotemAnimation.class, "(play|make) [the] [custom] (ia|itemsadder) totem [anim|animation] %string% to %players%"); } @SuppressWarnings("unchecked") diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlayerEmote.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlayerEmote.java index 7e0a78d..6ab99b4 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlayerEmote.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlayerEmote.java @@ -27,7 +27,7 @@ public class EffPlayerEmote extends Effect { static { Skript.registerEffect(EffPlayerEmote.class, - "(make|force) %players% [perform] [custom|ia|itemsadder] (emote|dance|animation) %string%", + "(make|force) %players% to perform [custom] [ia|itemsadder] (emote|dance|animation) %string%", "(make|force) %players% [to] stop [current] emot[e|ing]"); } @Override diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffRemoveCustomFurniture.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffRemoveCustomFurniture.java index 64ba298..9818a62 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffRemoveCustomFurniture.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffRemoveCustomFurniture.java @@ -24,7 +24,7 @@ public class EffRemoveCustomFurniture extends Effect { static { - Skript.registerEffect(EffRemoveCustomFurniture.class, "(remove|delete) (custom|ia|itemsadder) furniture [%string%] at %locations%"); + Skript.registerEffect(EffRemoveCustomFurniture.class, "(remove|delete) [custom] (ia|itemsadder) furniture [%string%] at %locations%"); } private Expression furnitureId; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffReplaceBlock.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffReplaceBlock.java index c303d3b..9e547e7 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffReplaceBlock.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffReplaceBlock.java @@ -26,7 +26,7 @@ public class EffReplaceBlock extends Effect { private Expression location; static { - Skript.registerEffect(EffReplaceBlock.class, "replace (custom|ia|itemsadder) block %string% at %location%"); + Skript.registerEffect(EffReplaceBlock.class, "replace [custom] (ia|itemsadder) block %string% at %location%"); } @Override @@ -46,7 +46,7 @@ protected void execute(Event e) { @Override public String toString(@Nullable Event e, boolean debug) { - return "replace (custom|ia|itemsadder) block " + blockId.toString(e, debug) + " at " + location.toString(e, debug); + return "replace itemsadder block " + blockId.toString(e, debug) + " at " + location.toString(e, debug); } @Override diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffReplaceCustomFurniture.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffReplaceCustomFurniture.java index d3659b6..5c02711 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffReplaceCustomFurniture.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffReplaceCustomFurniture.java @@ -26,7 +26,7 @@ public class EffReplaceCustomFurniture extends Effect { private Expression location; static { - Skript.registerEffect(EffReplaceCustomFurniture.class, "replace (custom|ia|itemsadder) furniture %string% at %location%"); + Skript.registerEffect(EffReplaceCustomFurniture.class, "replace [custom] (ia|itemsadder) furniture %string% at %location%"); } @Override @@ -46,7 +46,7 @@ protected void execute(Event e) { @Override public String toString(@Nullable Event e, boolean debug) { - return "replace (custom|ia|itemsadder) furniture " + furnitureId.toString(e, debug) + " at " + location.toString(e, debug); + return "replace itemsadder furniture " + furnitureId.toString(e, debug) + " at " + location.toString(e, debug); } @Override diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffSendIAResourcePack.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffSendIAResourcePack.java index 9c85ae4..7c53b88 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffSendIAResourcePack.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffSendIAResourcePack.java @@ -25,7 +25,7 @@ public class EffSendIAResourcePack extends Effect { private Expression players; static { - Skript.registerEffect(EffSendIAResourcePack.class, "(send|apply) [current] (itemsadder|ia) (texture|resource) pack to %players%"); + Skript.registerEffect(EffSendIAResourcePack.class, "(send|apply) [current] [custom] (ia|itemsadder) (texture|resource) pack to %players%"); } @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffSetBlocksBetween.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffSetBlocksBetween.java index 7b2bf6e..9e0744c 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffSetBlocksBetween.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffSetBlocksBetween.java @@ -26,7 +26,7 @@ public class EffSetBlocksBetween extends Effect { private Expression customBlockIdExpr; static { - Skript.registerEffect(EffSetBlocksBetween.class, new String[] {"(set|place) [all] blocks within %location% and %location% to (custom|ia|itemsadder) block %string%"}); + Skript.registerEffect(EffSetBlocksBetween.class, new String[] {"(set|place) [all] blocks within %location% and %location% to [custom] (ia|itemsadder) block %string%"}); } @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffSetInventoryIASlot.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffSetInventoryIASlot.java index 95c0a6d..7ad01d9 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffSetInventoryIASlot.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffSetInventoryIASlot.java @@ -28,7 +28,7 @@ public class EffSetInventoryIASlot extends Effect { private Expression items; static { - Skript.registerEffect(EffSetInventoryIASlot.class, "set slot[s] %integers% of (custom|ia|itemsadder) %texturedinventorywrapper% to %itemstacks%"); + Skript.registerEffect(EffSetInventoryIASlot.class, "set slot[s] %integers% of [custom] (ia|itemsadder) %texturedinventorywrapper% to %itemstacks%"); } @Override diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffSpawnCustomEntity.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffSpawnCustomEntity.java index aa985b2..0b3a517 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffSpawnCustomEntity.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffSpawnCustomEntity.java @@ -26,7 +26,7 @@ public class EffSpawnCustomEntity extends Effect { private Expression locationExpr; static { - Skript.registerEffect(EffSpawnCustomEntity.class, "(spawn|summon) [the] (custom|ia|itemsadder) (entity|mob) %string% at %locations%"); + Skript.registerEffect(EffSpawnCustomEntity.class, "(spawn|summon) [the] [custom] (ia|itemsadder) (entity|mob) %string% at %locations%"); } @Override diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockBreak.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockBreak.java index 8cf1968..b8fbc82 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockBreak.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockBreak.java @@ -29,7 +29,7 @@ public class EvtCustomBlockBreak extends SkriptEvent { private Literal blockName; static { - Skript.registerEvent("Custom Block Break", EvtCustomBlockBreak.class, CustomBlockBreakEvent.class, "break of (custom|ia|itemsadder) block [%string%]"); + Skript.registerEvent("Custom Block Break", EvtCustomBlockBreak.class, CustomBlockBreakEvent.class, "break of [custom] (ia|itemsadder) block [%string%]"); EventValues.registerEventValue(CustomBlockBreakEvent.class, CustomBlock.class, new Getter() { @Override public CustomBlock get(CustomBlockBreakEvent event) { diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockInteract.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockInteract.java index 3c985ca..5006d5f 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockInteract.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockInteract.java @@ -26,7 +26,7 @@ public class EvtCustomBlockInteract extends SkriptEvent { private Literal blockName; static { - Skript.registerEvent("Custom Block Interact", EvtCustomBlockInteract.class, CustomBlockInteractEvent.class, "interact with (custom|ia|itemsadder) block [%string%]"); + Skript.registerEvent("Custom Block Interact", EvtCustomBlockInteract.class, CustomBlockInteractEvent.class, "interact with [custom] (ia|itemsadder) block [%string%]"); EventValues.registerEventValue(CustomBlockInteractEvent.class, Block.class, new Getter() { @Override public Block get(CustomBlockInteractEvent event) { diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockPlace.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockPlace.java index 1042dd6..7e8b3e8 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockPlace.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockPlace.java @@ -30,7 +30,7 @@ public class EvtCustomBlockPlace extends SkriptEvent { private boolean isCancelled; static { - Skript.registerEvent("Custom Block Place", EvtCustomBlockPlace.class, CustomBlockPlaceEvent.class, "place [of] (custom|ia|itemsadder) block [%string%]"); + Skript.registerEvent("Custom Block Place", EvtCustomBlockPlace.class, CustomBlockPlaceEvent.class, "place [of] [custom] (ia|itemsadder) block [%string%]"); EventValues.registerEventValue(CustomBlockPlaceEvent.class, CustomBlock.class, new Getter() { @Override public CustomBlock get(CustomBlockPlaceEvent event) { diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomEntityDeath.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomEntityDeath.java index 8b83186..c731c1f 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomEntityDeath.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomEntityDeath.java @@ -22,7 +22,7 @@ public class EvtCustomEntityDeath extends SkriptEvent { private Literal mobID; static { - Skript.registerEvent("Custom Entity Death", EvtCustomEntityDeath.class, CustomEntityDeathEvent.class, "(custom|ia|itemsadder) entity death [of %string%]"); + Skript.registerEvent("Custom Entity Death", EvtCustomEntityDeath.class, CustomEntityDeathEvent.class, "[custom] (ia|itemsadder) entity death [of %string%]"); } @SuppressWarnings("unchecked") diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureBreak.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureBreak.java index 8520de4..9dfcf70 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureBreak.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureBreak.java @@ -9,7 +9,11 @@ import ch.njol.skript.lang.Literal; import ch.njol.skript.lang.SkriptEvent; import ch.njol.skript.lang.SkriptParser; +import ch.njol.skript.registrations.EventValues; +import ch.njol.skript.util.Getter; +import dev.lone.itemsadder.api.CustomFurniture; import dev.lone.itemsadder.api.Events.FurnitureBreakEvent; +import org.bukkit.Location; import org.bukkit.event.Event; import javax.annotation.Nullable; @@ -22,7 +26,19 @@ public class EvtCustomFurnitureBreak extends SkriptEvent { private Literal furnitureID; static { - Skript.registerEvent("Custom Furniture Break", EvtCustomFurnitureBreak.class, FurnitureBreakEvent.class, "break of (custom|ia|itemsadder) furniture [%string%]"); + Skript.registerEvent("Custom Furniture Break", EvtCustomFurnitureBreak.class, FurnitureBreakEvent.class, "break of [custom] (ia|itemsadder) furniture [%string%]"); + EventValues.registerEventValue(FurnitureBreakEvent.class, Location.class, new Getter() { + @Override + public @Nullable Location get(FurnitureBreakEvent event) { + return event.getBukkitEntity().getLocation(); + } + }, 0); + EventValues.registerEventValue(FurnitureBreakEvent.class, CustomFurniture.class, new Getter() { + @Override + public @Nullable CustomFurniture get(FurnitureBreakEvent event) { + return event.getFurniture(); + } + }, 0); } @SuppressWarnings("unchecked") diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureInteract.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureInteract.java index 93d3ec5..001906f 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureInteract.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureInteract.java @@ -9,7 +9,12 @@ import ch.njol.skript.lang.Literal; import ch.njol.skript.lang.SkriptEvent; import ch.njol.skript.lang.SkriptParser; +import ch.njol.skript.registrations.EventValues; +import ch.njol.skript.util.Getter; +import dev.lone.itemsadder.api.CustomFurniture; import dev.lone.itemsadder.api.Events.FurnitureInteractEvent; +import dev.lone.itemsadder.api.Events.FurnitureInteractEvent; +import org.bukkit.Location; import org.bukkit.event.Event; import javax.annotation.Nullable; @@ -22,7 +27,19 @@ public class EvtCustomFurnitureInteract extends SkriptEvent { private Literal furnitureID; static { - Skript.registerEvent("Custom Furniture Interact", EvtCustomFurnitureInteract.class, FurnitureInteractEvent.class, "interact with (custom|ia|itemsadder) furniture [%string%]"); + Skript.registerEvent("Custom Furniture Interact", EvtCustomFurnitureInteract.class, FurnitureInteractEvent.class, "interact with [custom] (ia|itemsadder) furniture [%string%]"); + EventValues.registerEventValue(FurnitureInteractEvent.class, Location.class, new Getter() { + @Override + public @Nullable Location get(FurnitureInteractEvent event) { + return event.getBukkitEntity().getLocation(); + } + }, 0); + EventValues.registerEventValue(FurnitureInteractEvent.class, CustomFurniture.class, new Getter() { + @Override + public @Nullable CustomFurniture get(FurnitureInteractEvent event) { + return event.getFurniture(); + } + }, 0); } @SuppressWarnings("unchecked") diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurniturePlace.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurniturePlace.java index 5897c3c..6b5f4c6 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurniturePlace.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurniturePlace.java @@ -23,7 +23,7 @@ public class EvtCustomFurniturePlace extends SkriptEvent { private Literal furnitureID; static { - Skript.registerEvent("Custom Furniture Place", EvtCustomFurniturePlace.class, FurniturePlaceEvent.class, "place of (custom|ia|itemsadder) furniture [%string%]"); + Skript.registerEvent("Custom Furniture Place", EvtCustomFurniturePlace.class, FurniturePlaceEvent.class, "place of [custom] (ia|itemsadder) furniture [%string%]"); } @SuppressWarnings("unchecked") diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureSuccessEvent.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureSuccessEvent.java index fba5394..a8f1d88 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureSuccessEvent.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureSuccessEvent.java @@ -11,6 +11,7 @@ import ch.njol.skript.lang.SkriptParser; import ch.njol.skript.registrations.EventValues; import ch.njol.skript.util.Getter; +import dev.lone.itemsadder.api.CustomFurniture; import dev.lone.itemsadder.api.Events.FurniturePlaceSuccessEvent; import org.bukkit.Location; import org.bukkit.event.Event; @@ -18,7 +19,7 @@ import javax.annotation.Nullable; @Name("Furniture Place Sucess") @Description("This event is called when a furniture is succesfully placed into the world, use this event instead if you would like to know the location, etc.") -@Examples({"on place success of custom furniture:", "on successfully placing a custom furniture:"}) +@Examples({"on place success of custom itemsadder furniture:", "on successfully placing a custom itemsadder furniture:"}) @Since("1.5") @RequiredPlugins("ItemsAdder") public class EvtCustomFurnitureSuccessEvent extends SkriptEvent { @@ -27,12 +28,18 @@ public class EvtCustomFurnitureSuccessEvent extends SkriptEvent { static { Skript.registerEvent("Custom Furniture Success", EvtCustomFurnitureSuccessEvent.class, FurniturePlaceSuccessEvent.class, - "success[fully] plac(e|ing) [a] (custom|ia|itemsadder) furniture [%string%]", - "place success [of] (custom|ia|itemsadder) furniture [%string%]"); + "success[fully] plac(e|ing) [a] [custom] (ia|itemsadder) furniture [%string%]", + "place success [of] [custom] (ia|itemsadder) furniture [%string%]"); EventValues.registerEventValue(FurniturePlaceSuccessEvent.class, Location.class, new Getter() { @Override public Location get(FurniturePlaceSuccessEvent arg) { - return arg.getFurniture().getEntity().getLocation(); + return arg.getBukkitEntity().getLocation(); + } + }, 0); + EventValues.registerEventValue(FurniturePlaceSuccessEvent.class, CustomFurniture.class, new Getter() { + @Override + public @Nullable CustomFurniture get(FurniturePlaceSuccessEvent event) { + return event.getFurniture(); } }, 0); } diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtEmote.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtEmote.java new file mode 100644 index 0000000..4880f91 --- /dev/null +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtEmote.java @@ -0,0 +1,73 @@ +package me.asleepp.SkriptItemsAdder.elements.events; + +import ch.njol.skript.Skript; +import ch.njol.skript.lang.Literal; +import ch.njol.skript.lang.SkriptEvent; +import ch.njol.skript.lang.SkriptParser; +import ch.njol.util.coll.CollectionUtils; +import dev.lone.itemsadder.api.Events.PlayerEmoteEndEvent; +import dev.lone.itemsadder.api.Events.PlayerEmotePlayEvent; +import org.bukkit.event.Event; + +import javax.annotation.Nullable; + +public class EvtEmote extends SkriptEvent { + + private Literal id; + private PlayerEmoteEndEvent.Cause cause; + private boolean checkCause; + private int integer; + + static { + Skript.registerEvent("Emote Play/Stop", EvtEmote.class, CollectionUtils.array(PlayerEmotePlayEvent.class, PlayerEmoteEndEvent.class), + "(perform|play[ing]) [of] [custom] (ia|itemsadder) emote [%strings%]", + "(stop|cancel[ing]) [of] [custom] (ia|itemsadder) emote [%strings%] [due to (:stop[ped]|:finish[ed]) [emote]]"); + } + + @Override + public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseResult parseResult) { + this.integer = matchedPattern; + this.id = (Literal) args[0]; + if (parseResult.hasTag("stop")) { + cause = PlayerEmoteEndEvent.Cause.STOP; + checkCause = true; + } else if (parseResult.hasTag("finish")) { + cause = PlayerEmoteEndEvent.Cause.FINISHED; + checkCause = true; + } else { + checkCause = false; + } + return true; + } + + @Override + public boolean check(Event event) { + String emoteName = null; + if (integer == 0 && event instanceof PlayerEmotePlayEvent) { + emoteName = ((PlayerEmotePlayEvent) event).getEmoteName(); + } else if (integer == 1 && event instanceof PlayerEmoteEndEvent) { + PlayerEmoteEndEvent endEvent = (PlayerEmoteEndEvent) event; + emoteName = endEvent.getEmoteName(); + if (checkCause && endEvent.getCause() != cause) { + return false; + } + } + if (emoteName != null) { + if (id != null) { + for (String id : this.id.getArray(event)) { + if (emoteName.equals(id)) { + return true; + } + } + } else { + return true; + } + } + return false; + } + + @Override + public String toString(@Nullable Event event, boolean debug) { + return this.integer == 0 ? "perform emote" : "stop emote" + (id != null ? id.toString(event, debug) : ""); + } +} diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtResourcePackSendEvent.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtResourcePackSendEvent.java index bda33e3..c4bc834 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtResourcePackSendEvent.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtResourcePackSendEvent.java @@ -23,7 +23,7 @@ public class EvtResourcePackSendEvent extends SkriptEvent { private boolean isItemsAdderPack; static { - Skript.registerEvent("Resource Pack Send Event", EvtResourcePackSendEvent.class, ResourcePackSendEvent.class, "[ia|itemsadder] (texture|resource) pack send"); + Skript.registerEvent("Resource Pack Send Event", EvtResourcePackSendEvent.class, ResourcePackSendEvent.class, "[custom] [ia|itemsadder] (texture|resource) pack send"); } @Override diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprCropAge.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprCropAge.java new file mode 100644 index 0000000..1a307f5 --- /dev/null +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprCropAge.java @@ -0,0 +1,93 @@ +package me.asleepp.SkriptItemsAdder.elements.expressions; + +import ch.njol.skript.Skript; +import ch.njol.skript.classes.Changer; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.ExpressionType; +import ch.njol.skript.lang.SkriptParser; +import ch.njol.skript.lang.util.SimpleExpression; +import ch.njol.util.Kleenean; +import dev.lone.itemsadder.api.CustomCrop; +import org.bukkit.block.Block; +import org.bukkit.event.Event; + +import javax.annotation.Nullable; + +public class ExprCropAge extends SimpleExpression { + + private Expression block; + private boolean maxAge; + + static { + Skript.registerExpression(ExprCropAge.class, Number.class, ExpressionType.SIMPLE, + "[the] [:max[imum]] age of [custom] (ia|itemsadder) %blocks%", + "[custom] (ia|itemsadder) %blocks%'[s] [:max[imum]] age"); + } + + @Override + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { + block = (Expression) exprs[0]; + maxAge = parseResult.hasTag("max"); + return true; + } + + @Nullable + @Override + protected Number[] get(Event e) { + Block[] bs = block.getArray(e); + Number[] ages = new Number[bs.length]; + for (int i = 0; i < bs.length; i++) { + CustomCrop crop = CustomCrop.byAlreadyPlaced(bs[i]); + if (crop != null) { + ages[i] = maxAge ? crop.getMaxAge() : crop.getAge(); + } + } + return ages; + } + + @Override + public boolean isSingle() { + return false; + } + + @Override + public Class getReturnType() { + return Number.class; + } + + @Override + public String toString(@Nullable Event e, boolean debug) { + return "age of " + block.toString(e, debug); + } + + @Override + public Class[] acceptChange(Changer.ChangeMode mode) { + if (mode == Changer.ChangeMode.SET || mode == Changer.ChangeMode.ADD || mode == Changer.ChangeMode.REMOVE) + return new Class[]{Number.class}; + return null; + } + + @Override + public void change(Event e, Object[] delta, Changer.ChangeMode mode) { + if (delta != null && delta.length != 0) { + int age = ((Number) delta[0]).intValue(); + Block[] bs = block.getArray(e); + for (Block b : bs) { + CustomCrop crop = CustomCrop.byAlreadyPlaced(b); + if (crop != null) { + switch (mode) { + case SET: + crop.setAge(age); + break; + case ADD: + crop.setAge(crop.getAge() + age); + break; + case REMOVE: + crop.setAge(crop.getAge() - age); + break; + } + } + } + } + } +} diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetCustomBlockClicked.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetCustomBlockClicked.java deleted file mode 100644 index 1dc5d8d..0000000 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetCustomBlockClicked.java +++ /dev/null @@ -1,52 +0,0 @@ -package me.asleepp.SkriptItemsAdder.elements.expressions; - -import ch.njol.skript.classes.Changer; -import ch.njol.skript.doc.Description; -import ch.njol.skript.doc.Examples; -import ch.njol.skript.doc.Name; -import ch.njol.skript.doc.RequiredPlugins; -import ch.njol.skript.doc.Since; -import ch.njol.skript.expressions.base.SimplePropertyExpression; -import ch.njol.skript.lang.ExpressionType; -import ch.njol.skript.Skript; -import dev.lone.itemsadder.api.Events.CustomBlockInteractEvent; -import org.bukkit.block.Block; -import org.bukkit.event.Event; -@Name("Get Block Clicked") -@Description({"Gets the block clicked."}) -@Examples({ - "on interact with custom block:", - "\tset {_t} to clicked custom block"}) -@Since("1.4") -@RequiredPlugins("ItemsAdder") -public class ExprGetCustomBlockClicked extends SimplePropertyExpression { - - static { - Skript.registerExpression(ExprGetCustomBlockClicked.class, Block.class, ExpressionType.PROPERTY, "[the] clicked (custom|ia|itemsadder) block"); - } - - @Override - public Block convert(CustomBlockInteractEvent event) { - return event.getBlockClicked(); - } - - @Override - protected String getPropertyName() { - return "clicked block"; - } - - @Override - public Class getReturnType() { - return Block.class; - } - - @Override - public Class[] acceptChange(Changer.ChangeMode mode) { - return null; // expression can't be changed - } - - @Override - public void change(Event e, Object[] delta, Changer.ChangeMode mode) { - // expression can't be changed - } -} diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetCustomBlockItem.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetCustomBlockItem.java index 7f1950e..ce01603 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetCustomBlockItem.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetCustomBlockItem.java @@ -19,14 +19,14 @@ @Name("Get Custom Block Item") @Description({"Gets the item associated with the custom block."}) @Examples({ - "on interact with custom block:", - "\tset {_t} to the item linked with the block"}) + "on interact with custom itemsadder block:", + "\tset {_t} to the item linked with the itemsadder block"}) @Since("1.4") @RequiredPlugins("ItemsAdder") public class ExprGetCustomBlockItem extends SimpleExpression { static { - Skript.registerExpression(ExprGetCustomBlockItem.class, ItemStack.class, ExpressionType.SIMPLE, "[the] item (linked|associated) with [the] block"); + Skript.registerExpression(ExprGetCustomBlockItem.class, ItemStack.class, ExpressionType.SIMPLE, "[the] item (linked|associated) with [the] [custom] (ia|itemsadder) block"); } @Override diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetCustomItem.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetCustomItem.java index 374034d..a7984f1 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetCustomItem.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetCustomItem.java @@ -32,21 +32,25 @@ public class ExprGetCustomItem extends SimpleExpression { private Expression itemNames; static { - Skript.registerExpression(ExprGetCustomItem.class, ItemType.class, ExpressionType.SIMPLE, "(custom|ia|itemsadder) item[s] %strings%"); + Skript.registerExpression(ExprGetCustomItem.class, ItemType.class, ExpressionType.SIMPLE, "[custom] (ia|itemsadder) item[s] %strings%"); + } + + @Override + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { + itemNames = (Expression) exprs[0]; + return true; } @Override protected ItemType[] get(Event e) { - String[] names = itemNames.getAll(e); + String[] names = itemNames.getArray(e); List items = new ArrayList<>(); for (String name : names) { - if (name != null) { - CustomStack customStack = CustomStack.getInstance(name); - if (customStack != null) { - ItemStack item = customStack.getItemStack(); - if (item != null) { - items.add(new ItemType(item)); - } + CustomStack customStack = CustomStack.getInstance(name); + if (customStack != null) { + ItemStack item = customStack.getItemStack(); + if (item != null) { + items.add(new ItemType(item)); } } } @@ -55,7 +59,7 @@ protected ItemType[] get(Event e) { @Override public boolean isSingle() { - return false; + return itemNames.isSingle(); } @Override @@ -67,11 +71,4 @@ public Class getReturnType() { public String toString(@Nullable Event e, boolean debug) { return "ItemsAdder items " + itemNames.toString(e, debug); } - - @SuppressWarnings("unchecked") - @Override - public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { - itemNames = (Expression) exprs[0]; - return true; - } -} +} \ No newline at end of file diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetFontImage.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetFontImage.java index e8ea80c..0e5e5b3 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetFontImage.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetFontImage.java @@ -31,6 +31,12 @@ public class ExprGetFontImage extends SimpleExpression { Skript.registerExpression(ExprGetFontImage.class, String.class, ExpressionType.SIMPLE, "[font|custom|ia|itemsadder] image[s] %strings%"); } + @Override + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { + fontImageNames = (Expression) exprs[0]; + return true; + } + @NotNull @Override public Class getReturnType() { @@ -39,14 +45,9 @@ public Class getReturnType() { @Override public boolean isSingle() { - return false; + return fontImageNames.isSingle(); } - @Override - public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { - fontImageNames = (Expression) exprs[0]; - return true; - } @NotNull @Override diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetID.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetID.java new file mode 100644 index 0000000..142d838 --- /dev/null +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetID.java @@ -0,0 +1,75 @@ +package me.asleepp.SkriptItemsAdder.elements.expressions; + +import ch.njol.skript.Skript; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.ExpressionType; +import ch.njol.skript.lang.SkriptParser; +import ch.njol.skript.lang.util.SimpleExpression; +import ch.njol.util.Kleenean; +import ch.njol.util.coll.CollectionUtils; +import dev.lone.itemsadder.api.CustomBlock; +import dev.lone.itemsadder.api.CustomEntity; +import dev.lone.itemsadder.api.CustomStack; +import org.bukkit.block.Block; +import org.bukkit.entity.Entity; +import org.bukkit.event.Event; +import org.bukkit.inventory.ItemStack; + +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.List; + +public class ExprGetID extends SimpleExpression { + + private Expression expr; + + static { + Skript.registerExpression(ExprGetID.class, String.class, ExpressionType.SIMPLE, "id of [custom] (ia|itemsadder) %itemstacks/blocks/entities%"); + } + + @Override + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { + expr = exprs[0]; + return true; + } + + @Override + protected String[] get(Event e) { + Object[] objects = expr.getArray(e); + List ids = new ArrayList<>(); + for (Object object : objects) { + if (object instanceof ItemStack) { + CustomStack customStack = CustomStack.byItemStack((ItemStack) object); + if (customStack != null) { + ids.add(customStack.getNamespacedID()); + } + } else if (object instanceof Block) { + CustomBlock customBlock = CustomBlock.byAlreadyPlaced((Block) object); + if (customBlock != null) { + ids.add(customBlock.getNamespacedID()); + } + } else if (object instanceof Entity) { + CustomEntity customEntity = CustomEntity.byAlreadySpawned((Entity) object); + if (customEntity != null) { + ids.add(customEntity.getNamespacedID()); + } + } + } + return ids.toArray(new String[0]); + } + + @Override + public boolean isSingle() { + return expr.isSingle(); + } + + @Override + public Class getReturnType() { + return String.class; + } + + @Override + public String toString(@Nullable Event e, boolean debug) { + return "id of [custom] (ia|itemsadder) " + expr.toString(e, debug); + } +} diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetLoot.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetLoot.java new file mode 100644 index 0000000..b8053c8 --- /dev/null +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetLoot.java @@ -0,0 +1,59 @@ +package me.asleepp.SkriptItemsAdder.elements.expressions; + +import ch.njol.skript.Skript; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.ExpressionType; +import ch.njol.skript.lang.SkriptParser; +import ch.njol.util.Kleenean; +import dev.lone.itemsadder.api.CustomBlock; +import dev.lone.itemsadder.api.CustomCrop; + +import javax.annotation.Nullable; + +public class ExprGetLoot extends SimpleExpression { + + private Expression blocks; + + static { + Skript.registerExpression(ExprGetLoot.class, ItemStack.class, ExpressionType.SIMPLE, "[the] loot [of] [custom] (ia|itemsadder) %blocks%"); + } + + @Override + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { + blocks = (Expression) exprs[0]; + return true; + } + @Nullable + @Override + protected ItemStack[] get(Event event) { + Block[] bs = blocks.getArray(event); + List loot = null; + for (Block b : bs) { + CustomBlock customBlock = CustomBlock.byAlreadyPlaced(b); + if (customBlock != null) { + loot = customBlock.getLoot(); + } else { + CustomCrop customCrop = CustomCrop.byAlreadyPlaced(b); + if (customCrop != null) { + loot = customCrop.getLoot(); + } + } + } + return loot != null ? loot.toArray(new ItemStack[0]) : null; + } + + @Override + public boolean isSingle() { + return false; + } + + @Override + public Class getReturnType() { + return ItemStack.class; + } + + @Override + public String toString(@Nullable Event event, boolean debug) { + return "loot of " + blocks.toString(event, debug); + } +} diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprLastCreatedIAGui.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprLastCreatedIAGui.java index 6f1d5cb..75ea227 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprLastCreatedIAGui.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprLastCreatedIAGui.java @@ -19,7 +19,7 @@ @Name("Last Created ItemsAdder Gui") @Description("Get's the last created ItemsAdder inventory by the Create ItemsAdder Inventory section.") @Examples({ - "create a new custom inventory:", + "create a new custom itemsadder inventory:", "\ttitle: \"Auction House\"", "\trows: 6", "\ttexture: \"inventory:auction_house\"", @@ -29,7 +29,7 @@ public class ExprLastCreatedIAGui extends SimpleExpression { static { - Skript.registerExpression(ExprLastCreatedIAGui.class, TexturedInventoryWrapper.class, ExpressionType.SIMPLE, "last created (custom|ia|itemsadder) gui"); + Skript.registerExpression(ExprLastCreatedIAGui.class, TexturedInventoryWrapper.class, ExpressionType.SIMPLE, "last created [custom] (ia|itemsadder) gui"); } @Override diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/sections/SecCreateCustomInventory.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/sections/SecCreateCustomInventory.java index 2338a20..fff516e 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/sections/SecCreateCustomInventory.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/sections/SecCreateCustomInventory.java @@ -37,7 +37,7 @@ "To create an Inventory, you need a Texture, everything else is optional. See Examples for a demonstration." }) @Examples({ - "create a new custom inventory:", + "create a new custom itemsadder inventory:", "\ttitle: \"Shop\"", "\trows: 5", "\ttexture: \"inventory:shop\" and \"inventory:shop_extras\"", @@ -65,7 +65,7 @@ public class SecCreateCustomInventory extends Section { .build(); static { - Skript.registerSection(SecCreateCustomInventory.class, "create [a] [new] (custom|ia|itemsadder) [chest] inventory"); + Skript.registerSection(SecCreateCustomInventory.class, "create [a] [new] [custom] (ia|itemsadder) [chest] inventory"); } @Override From fc7fb8a6165665d6d9fbfd0b5e0441326610f521 Mon Sep 17 00:00:00 2001 From: Asleeepp Date: Thu, 6 Jun 2024 22:48:00 -0300 Subject: [PATCH 02/10] dying --- .../SkriptItemsAdder/SkriptItemsAdder.java | 3 +- .../SkriptItemsAdder/UpdateChecker.java | 102 +++++++++--------- 2 files changed, 56 insertions(+), 49 deletions(-) diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/SkriptItemsAdder.java b/src/main/java/me/asleepp/SkriptItemsAdder/SkriptItemsAdder.java index 7f7a0da..f879779 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/SkriptItemsAdder.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/SkriptItemsAdder.java @@ -54,7 +54,8 @@ public void onEnable() { instance = this; addon = Skript.registerAddon(this); addon.setLanguageFileDirectory("lang"); - UpdateChecker.check(this); + new UpdateChecker(this); + try { addon.loadClasses("me.asleepp.SkriptItemsAdder"); } catch (IOException error) { diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/UpdateChecker.java b/src/main/java/me/asleepp/SkriptItemsAdder/UpdateChecker.java index 59c6b2b..3935a03 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/UpdateChecker.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/UpdateChecker.java @@ -1,62 +1,68 @@ package me.asleepp.SkriptItemsAdder; -import ch.njol.skript.util.Version; -import com.google.gson.Gson; import com.google.gson.JsonObject; import net.kyori.adventure.text.minimessage.MiniMessage; import org.bukkit.Bukkit; +import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.plugin.java.JavaPlugin; -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.net.URL; -import java.util.logging.Level; - -/** - * @author ShaneBeee, ImNotStable, Equipable - */ - -public class UpdateChecker { - - public static void check(SkriptItemsAdder plugin) { - String latestVersion = getLatestVersion(); - if (latestVersion == null) - return; - String currentVersion = plugin.getDescription().getVersion(); - if (new Version(currentVersion).isSmallerThan(new Version(latestVersion))) { - SkriptItemsAdder.getInstance().getLogger().info("skript-itemsadder is NOT up to date!"); - SkriptItemsAdder.getInstance().getLogger().info("> Current Version: " + currentVersion); - SkriptItemsAdder.getInstance().getLogger().info("> Latest Version: " + latestVersion); - SkriptItemsAdder.getInstance().getLogger().info("> Download it at: https://github.com/Asleeepp/skript-itemsadder/releases"); - Bukkit.getPluginManager().registerEvents(new Listener() { - @EventHandler - public void on(PlayerJoinEvent event) { - Player player = event.getPlayer(); - if (!player.hasPermission("skript-itemsadder.update.check") && !player.isOp()) return; - - player.sendMessage(" "); - player.sendMessage(MiniMessage.miniMessage().deserialize("[skript-itemsadder] skript-itemsadder is OUTDATED!")); - player.sendMessage(MiniMessage.miniMessage().deserialize("[skript-itemsadder] New version: " + latestVersion)); - player.sendMessage(MiniMessage.miniMessage().deserialize("[skript-itemsadder] Download at: https://github.com/Asleeepp/skript-itemsadder/releases")); - player.sendMessage(" "); - } - }, plugin); - } else - SkriptItemsAdder.getInstance().getLogger().info("skript-itemsadder is up to date!"); +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.util.concurrent.CompletableFuture; + +public class UpdateChecker implements Listener { + + private final JavaPlugin plugin; + private final String currentVersion; + private String latestVersion; + + public UpdateChecker(JavaPlugin plugin) { + this.plugin = plugin; + this.currentVersion = plugin.getDescription().getVersion(); + Bukkit.getPluginManager().registerEvents(this, plugin); + checkForUpdate(); } - private static String getLatestVersion() { - String url = "https://api.github.com/repos/Asleeepp/skript-itemsadder/releases/latest"; - try (BufferedReader reader = new BufferedReader(new InputStreamReader(new URL(url).openStream()))) { - JsonObject jsonObject = new Gson().fromJson(reader, JsonObject.class); - return jsonObject.get("tag_name").getAsString(); - } catch (Exception exception) { - SkriptItemsAdder.getInstance().getLogger().log(Level.WARNING, "Failed to check for latest version."); - exception.printStackTrace(); + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) { + Player player = event.getPlayer(); + if (player.hasPermission("skript-nonplayercharacter.update.check") && latestVersion != null) { + player.sendMessage(" "); + player.sendMessage(MiniMessage.miniMessage().deserialize("[skript-itemsadder] skript-itemsadder is OUTDATED!")); + player.sendMessage(MiniMessage.miniMessage().deserialize("[skript-itemsadder] New version: " + latestVersion)); + player.sendMessage(MiniMessage.miniMessage().deserialize("[skript-itemsadder] Download at: https://github.com/Asleeepp/skript-itemsadder/releases")); + player.sendMessage(" "); } - return null; } -} + + private void checkForUpdate() { + HttpClient httpClient = HttpClient.newHttpClient(); + HttpRequest request = HttpRequest.newBuilder() + .uri(URI.create("https://api.github.com/repos/asleeepp/skript-itemsadder/releases/latest")) + .build(); + + CompletableFuture> responseFuture = httpClient.sendAsync(request, HttpResponse.BodyHandlers.ofString()); + + responseFuture.thenApply(HttpResponse::body) + .thenAccept(body -> { + JsonObject jsonResponse = new JsonObject().getAsJsonObject(); + latestVersion = jsonResponse.get("tag_name").getAsString(); + + if (!currentVersion.equals(latestVersion)) { + SkriptItemsAdder.getInstance().getLogger().warning("An update for skript-nonplayercharacter is available: " + latestVersion + " (current version: " + currentVersion + ")"); + } else { + SkriptItemsAdder.getInstance().getLogger().info("skript-nonplayercharacter is up to date!"); + } + }) + .exceptionally(e -> { + SkriptItemsAdder.getInstance().getLogger().severe("Failed to check for updates: " + e.getMessage()); + return null; + }); + } +} \ No newline at end of file From 8b5a42f4719ce12bc351d5d240660ba2d9e6c4da Mon Sep 17 00:00:00 2001 From: Asleeepp Date: Sun, 9 Jun 2024 08:59:17 -0300 Subject: [PATCH 03/10] stuff --- .../SkriptItemsAdder/SkriptItemsAdder.java | 76 ++++++++++- .../elements/conditions/CondIsFullyGrown.java | 12 +- .../elements/effects/EffPlaceBlockOrCrop.java | 2 +- .../elements/events/EvtCustomBlockBreak.java | 51 +++---- .../events/EvtCustomBlockInteract.java | 29 +++- .../elements/events/EvtCustomBlockPlace.java | 21 ++- .../elements/events/EvtCustomEntityDeath.java | 22 +++ .../events/EvtCustomFurnitureBreak.java | 11 +- .../events/EvtCustomFurnitureInteract.java | 11 +- .../events/EvtCustomFurniturePlace.java | 11 +- .../EvtCustomFurnitureSuccessEvent.java | 15 +- .../expressions/ExprGetCustomBlockItem.java | 65 --------- .../expressions/ExprGetCustomItem.java | 45 ++++-- .../elements/expressions/ExprGetLoot.java | 59 -------- .../elements/types/Types.java | 78 ++++++++--- .../other/AliasesGenerator.java | 129 ++++++++++++++++++ .../other/CustomItemType.java | 51 +++++++ .../other/ItemsAdderEventListener.java | 50 +++++++ .../SkriptItemsAdder/{ => other}/Metrics.java | 2 +- .../{ => other}/UpdateChecker.java | 34 +++-- src/main/resources/aliases.yml | 0 src/main/resources/config.yml | 2 + 22 files changed, 536 insertions(+), 240 deletions(-) delete mode 100644 src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetCustomBlockItem.java delete mode 100644 src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetLoot.java create mode 100644 src/main/java/me/asleepp/SkriptItemsAdder/other/AliasesGenerator.java create mode 100644 src/main/java/me/asleepp/SkriptItemsAdder/other/CustomItemType.java create mode 100644 src/main/java/me/asleepp/SkriptItemsAdder/other/ItemsAdderEventListener.java rename src/main/java/me/asleepp/SkriptItemsAdder/{ => other}/Metrics.java (99%) rename src/main/java/me/asleepp/SkriptItemsAdder/{ => other}/UpdateChecker.java (52%) create mode 100644 src/main/resources/aliases.yml create mode 100644 src/main/resources/config.yml diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/SkriptItemsAdder.java b/src/main/java/me/asleepp/SkriptItemsAdder/SkriptItemsAdder.java index f879779..a5bc129 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/SkriptItemsAdder.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/SkriptItemsAdder.java @@ -1,35 +1,46 @@ package me.asleepp.SkriptItemsAdder; import java.io.IOException; - +import java.util.ArrayList; +import java.util.List; import ch.njol.skript.util.Version; +import dev.lone.itemsadder.api.CustomStack; +import dev.lone.itemsadder.api.ItemsAdder; +import me.asleepp.SkriptItemsAdder.other.AliasesGenerator; +import me.asleepp.SkriptItemsAdder.other.ItemsAdderEventListener; +import me.asleepp.SkriptItemsAdder.other.Metrics; +import me.asleepp.SkriptItemsAdder.other.UpdateChecker; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import ch.njol.skript.Skript; import ch.njol.skript.SkriptAddon; +import org.bukkit.scheduler.BukkitRunnable; import javax.annotation.Nullable; -@SuppressWarnings("ALL") public class SkriptItemsAdder extends JavaPlugin { private static SkriptAddon addon; - private static SkriptItemsAdder instance; + private AliasesGenerator aliasesGenerator; + private List initialItems = new ArrayList<>(); @Nullable public static SkriptItemsAdder getInstance() { return instance; } + @Nullable public static SkriptAddon getAddonInstance() { return addon; } + public boolean itemsAdderReady = false; + @Override public void onEnable() { // Let's get this show on the road. final PluginManager manager = this.getServer().getPluginManager(); @@ -43,18 +54,57 @@ public void onEnable() { manager.disablePlugin(this); return; } + if (!Skript.isAcceptRegistrations()) { + getLogger().severe("The plugin can't load when it's already loaded! Disabling..."); + manager.disablePlugin(this); + return; + } + final Plugin itemsadder = manager.getPlugin("ItemsAdder"); if (itemsadder == null || !itemsadder.isEnabled()) { getLogger().severe("Could not find ItemsAdder! Disabling..."); manager.disablePlugin(this); return; } + + this.aliasesGenerator = new AliasesGenerator(this); + + final SkriptItemsAdder plugin = this; + + // Pass the aliasesGenerator to the event listener + new BukkitRunnable() { + + @Override + public void run() { + loadInitialItems(); + ItemsAdderEventListener eventListener = new ItemsAdderEventListener(plugin, aliasesGenerator, initialItems); + manager.registerEvents(eventListener, plugin); + } + }.runTask(this); + + + getLogger().info("Waiting for ItemsAdder to finish loading."); + + getServer().getScheduler().runTaskTimer(this, () -> { + if (itemsAdderReady) { + return; + } + + + }, 0, 20); + int pluginId = 20971; Metrics metrics = new Metrics(this, pluginId); + metrics.addCustomChart(new Metrics.SimplePie("skript_version", () -> Skript.getVersion().toString())); instance = this; addon = Skript.registerAddon(this); addon.setLanguageFileDirectory("lang"); - new UpdateChecker(this); + + saveDefaultConfig(); + aliasesGenerator.loadAliasesFile(); + + if (getConfig().getBoolean("check-for-updates", true)) + new UpdateChecker(this); try { addon.loadClasses("me.asleepp.SkriptItemsAdder"); @@ -63,9 +113,25 @@ public void onEnable() { manager.disablePlugin(this); return; } + getLogger().info("Loaded!"); + } + + @Override + public void onDisable() { + aliasesGenerator.saveAliases(); + } + public void setItemsAdderReady(boolean ready) { + this.itemsAdderReady = ready; + } + public AliasesGenerator getAliasesGenerator() { + return aliasesGenerator; } + private void loadInitialItems() { + initialItems = ItemsAdder.getAllItems(); + getLogger().info("Loaded " + initialItems.size() + " aliases."); + } -} \ No newline at end of file +} diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsFullyGrown.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsFullyGrown.java index 6deb016..5766c0c 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsFullyGrown.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsFullyGrown.java @@ -30,14 +30,10 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye @Override public boolean check(Event e) { - Block[] bs = blocks.getArray(e); - for (Block b : bs) { - CustomCrop crop = CustomCrop.byAlreadyPlaced(b); - if (crop != null && crop.isFullyGrown() != isNegated()) { - return false; - } - } - return true; + return blocks.check(e, block -> { + CustomCrop crop = CustomCrop.byAlreadyPlaced(block); + return crop != null && crop.isFullyGrown(); + }, isNegated()); } @Override diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlaceBlockOrCrop.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlaceBlockOrCrop.java index a323124..4aa45cc 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlaceBlockOrCrop.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlaceBlockOrCrop.java @@ -30,7 +30,7 @@ public class EffPlaceBlockOrCrop extends Effect { private boolean isCrop; static { - Skript.registerEffect(EffPlaceBlockOrCrop.class, "(set|place) [custom] (ia|itemsadder) (block|:crop) %string% at [%directions% %locations%]"); + Skript.registerEffect(EffPlaceBlockOrCrop.class, "(set|place) [custom] (ia|itemsadder) (block|:crop) %string% [%directions% %locations%]"); } @Override diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockBreak.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockBreak.java index b8fbc82..1b19e6c 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockBreak.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockBreak.java @@ -1,39 +1,32 @@ package me.asleepp.SkriptItemsAdder.elements.events; import ch.njol.skript.Skript; -import ch.njol.skript.doc.Description; -import ch.njol.skript.doc.Examples; -import ch.njol.skript.doc.Name; -import ch.njol.skript.doc.RequiredPlugins; -import ch.njol.skript.doc.Since; import ch.njol.skript.lang.Literal; import ch.njol.skript.lang.SkriptEvent; import ch.njol.skript.lang.SkriptParser; import ch.njol.skript.registrations.EventValues; import ch.njol.skript.util.Getter; -import dev.lone.itemsadder.api.CustomBlock; import dev.lone.itemsadder.api.Events.CustomBlockBreakEvent; +import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; +import me.asleepp.SkriptItemsAdder.other.AliasesGenerator; +import me.asleepp.SkriptItemsAdder.other.CustomItemType; import org.bukkit.Location; -import org.bukkit.block.Block; import org.bukkit.event.Event; +import org.bukkit.inventory.ItemStack; import javax.annotation.Nullable; -@Name("On Custom Block Break") -@Description({"Fires when a ItemsAdder block gets broken."}) -@Examples({"on break of custom block:"}) -@Since("1.0") -@RequiredPlugins("ItemsAdder") public class EvtCustomBlockBreak extends SkriptEvent { - private Literal blockName; + private Literal blockName; static { - Skript.registerEvent("Custom Block Break", EvtCustomBlockBreak.class, CustomBlockBreakEvent.class, "break of [custom] (ia|itemsadder) block [%string%]"); - EventValues.registerEventValue(CustomBlockBreakEvent.class, CustomBlock.class, new Getter() { + Skript.registerEvent("Custom Block Break", EvtCustomBlockBreak.class, CustomBlockBreakEvent.class, "break of [custom] (ia|itemsadder) block [%customitemtype%]"); + EventValues.registerEventValue(CustomBlockBreakEvent.class, CustomItemType.class, new Getter() { @Override - public CustomBlock get(CustomBlockBreakEvent event) { - return CustomBlock.byAlreadyPlaced(event.getBlock()); + public CustomItemType get(CustomBlockBreakEvent event) { + String namespacedID = event.getNamespacedID(); + return new CustomItemType(namespacedID); } }, 0); EventValues.registerEventValue(CustomBlockBreakEvent.class, Location.class, new Getter() { @@ -42,12 +35,20 @@ public Location get(CustomBlockBreakEvent event) { return event.getBlock().getLocation(); } }, 0); + EventValues.registerEventValue(CustomBlockBreakEvent.class, ItemStack.class, new Getter() { + @Override + public @Nullable ItemStack get(CustomBlockBreakEvent event) { + return event.getCustomBlockItem(); + } + }, 0); } @SuppressWarnings("unchecked") @Override public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseResult parseResult) { - blockName = (Literal) args[0]; + if (args.length > 0 && args[0] instanceof Literal) { + blockName = (Literal) args[0]; + } return true; } @@ -62,14 +63,18 @@ public boolean check(Event event) { return false; } - // check block + // Check block name if (blockName != null) { - String specifiedBlockName = blockName.getSingle(event); - Block block = customEvent.getBlock(); - if (block == null) { + CustomItemType specifiedBlockType = blockName.getSingle(event); + AliasesGenerator aliasesGenerator = SkriptItemsAdder.getInstance().getAliasesGenerator(); + CustomItemType actualBlockType = EventValues.getEventValue(customEvent, CustomItemType.class, 0); + + if (specifiedBlockType == null || actualBlockType == null) { return false; } - String actualBlockName = customEvent.getNamespacedID(); + + String specifiedBlockName = specifiedBlockType.getNamespacedID(); + String actualBlockName = actualBlockType.getNamespacedID(); if (actualBlockName == null || actualBlockName.isEmpty() || !actualBlockName.equals(specifiedBlockName)) { return false; } diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockInteract.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockInteract.java index 5006d5f..5b66382 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockInteract.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockInteract.java @@ -12,6 +12,10 @@ import ch.njol.skript.registrations.EventValues; import ch.njol.skript.util.Getter; import dev.lone.itemsadder.api.Events.CustomBlockInteractEvent; +import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; +import me.asleepp.SkriptItemsAdder.other.AliasesGenerator; +import me.asleepp.SkriptItemsAdder.other.CustomItemType; +import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.event.Event; @@ -23,23 +27,29 @@ @Since("1.0") @RequiredPlugins("ItemsAdder") public class EvtCustomBlockInteract extends SkriptEvent { - private Literal blockName; + private Literal blockName; static { - Skript.registerEvent("Custom Block Interact", EvtCustomBlockInteract.class, CustomBlockInteractEvent.class, "interact with [custom] (ia|itemsadder) block [%string%]"); + Skript.registerEvent("Custom Block Interact", EvtCustomBlockInteract.class, CustomBlockInteractEvent.class, "interact with [custom] (ia|itemsadder) block [%customitemtype%]"); EventValues.registerEventValue(CustomBlockInteractEvent.class, Block.class, new Getter() { @Override public Block get(CustomBlockInteractEvent event) { return event.getBlockClicked(); } }, 0); + EventValues.registerEventValue(CustomBlockInteractEvent.class, Location.class, new Getter() { + @Override + public @Nullable Location get(CustomBlockInteractEvent customBlockInteractEvent) { + return customBlockInteractEvent.getBlockClicked().getLocation(); + } + }, 0); } @SuppressWarnings("unchecked") @Override public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseResult parseResult) { - blockName = (Literal) args[0]; + blockName = (Literal) args[0]; return true; } @@ -56,8 +66,17 @@ public boolean check(Event event) { // check block if (blockName != null) { - String specifiedBlockName = blockName.getSingle(event); - if (specifiedBlockName == null || !specifiedBlockName.equals(customEvent.getNamespacedID())) { + CustomItemType specifiedBlockType = blockName.getSingle(event); + AliasesGenerator aliasesGenerator = SkriptItemsAdder.getInstance().getAliasesGenerator(); + CustomItemType actualBlockType = EventValues.getEventValue(customEvent, CustomItemType.class, 0); + + if (specifiedBlockType == null || actualBlockType == null) { + return false; + } + + String specifiedBlockName = specifiedBlockType.getNamespacedID(); + String actualBlockName = actualBlockType.getNamespacedID(); + if (actualBlockName == null || actualBlockName.isEmpty() || !actualBlockName.equals(specifiedBlockName)) { return false; } } diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockPlace.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockPlace.java index 7e8b3e8..9ba2d89 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockPlace.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockPlace.java @@ -13,6 +13,9 @@ import ch.njol.skript.util.Getter; import dev.lone.itemsadder.api.CustomBlock; import dev.lone.itemsadder.api.Events.CustomBlockPlaceEvent; +import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; +import me.asleepp.SkriptItemsAdder.other.AliasesGenerator; +import me.asleepp.SkriptItemsAdder.other.CustomItemType; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.event.Event; @@ -26,11 +29,11 @@ @RequiredPlugins("ItemsAdder") public class EvtCustomBlockPlace extends SkriptEvent { - private Literal blockName; + private Literal blockName; private boolean isCancelled; static { - Skript.registerEvent("Custom Block Place", EvtCustomBlockPlace.class, CustomBlockPlaceEvent.class, "place [of] [custom] (ia|itemsadder) block [%string%]"); + Skript.registerEvent("Custom Block Place", EvtCustomBlockPlace.class, CustomBlockPlaceEvent.class, "place [of] [custom] (ia|itemsadder) block [%customitemtype%]"); EventValues.registerEventValue(CustomBlockPlaceEvent.class, CustomBlock.class, new Getter() { @Override public CustomBlock get(CustomBlockPlaceEvent event) { @@ -48,7 +51,7 @@ public Location get(CustomBlockPlaceEvent event) { @SuppressWarnings("unchecked") @Override public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseResult parseResult) { - blockName = (Literal) args[0]; + blockName = (Literal) args[0]; return true; } @@ -66,12 +69,16 @@ public boolean check(Event event) { // check block if (blockName != null) { - String specifiedBlockName = blockName.getSingle(event); - Block block = customEvent.getBlock(); - if (block == null) { + CustomItemType specifiedBlockType = blockName.getSingle(event); + AliasesGenerator aliasesGenerator = SkriptItemsAdder.getInstance().getAliasesGenerator(); + CustomItemType actualBlockType = EventValues.getEventValue(customEvent, CustomItemType.class, 0); + + if (specifiedBlockType == null || actualBlockType == null) { return false; } - String actualBlockName = customEvent.getNamespacedID(); + + String specifiedBlockName = specifiedBlockType.getNamespacedID(); + String actualBlockName = actualBlockType.getNamespacedID(); if (actualBlockName == null || actualBlockName.isEmpty() || !actualBlockName.equals(specifiedBlockName)) { return false; } diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomEntityDeath.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomEntityDeath.java index c731c1f..e98f9ba 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomEntityDeath.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomEntityDeath.java @@ -9,7 +9,11 @@ import ch.njol.skript.lang.Literal; import ch.njol.skript.lang.SkriptEvent; import ch.njol.skript.lang.SkriptParser; +import ch.njol.skript.registrations.EventValues; +import ch.njol.skript.util.Getter; import dev.lone.itemsadder.api.Events.CustomEntityDeathEvent; +import org.bukkit.Location; +import org.bukkit.entity.Entity; import org.bukkit.event.Event; import javax.annotation.Nullable; @@ -23,6 +27,24 @@ public class EvtCustomEntityDeath extends SkriptEvent { static { Skript.registerEvent("Custom Entity Death", EvtCustomEntityDeath.class, CustomEntityDeathEvent.class, "[custom] (ia|itemsadder) entity death [of %string%]"); + EventValues.registerEventValue(CustomEntityDeathEvent.class, Entity.class, new Getter() { + @Override + public @Nullable Entity get(CustomEntityDeathEvent customEntityDeathEvent) { + return customEntityDeathEvent.getEntity(); + } + }, 0); + EventValues.registerEventValue(CustomEntityDeathEvent.class, Location.class, new Getter() { + @Override + public @Nullable Location get(CustomEntityDeathEvent customEntityDeathEvent) { + return customEntityDeathEvent.getEntity().getLocation(); + } + },0); + EventValues.registerEventValue(CustomEntityDeathEvent.class, Entity.class, new Getter() { + @Override + public @Nullable Entity get(CustomEntityDeathEvent customEntityDeathEvent) { + return customEntityDeathEvent.getKiller(); + } + }, 0); } @SuppressWarnings("unchecked") diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureBreak.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureBreak.java index 9dfcf70..9eb0023 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureBreak.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureBreak.java @@ -13,6 +13,7 @@ import ch.njol.skript.util.Getter; import dev.lone.itemsadder.api.CustomFurniture; import dev.lone.itemsadder.api.Events.FurnitureBreakEvent; +import me.asleepp.SkriptItemsAdder.other.CustomItemType; import org.bukkit.Location; import org.bukkit.event.Event; @@ -23,10 +24,10 @@ @Since("1.0") @RequiredPlugins("ItemsAdder") public class EvtCustomFurnitureBreak extends SkriptEvent { - private Literal furnitureID; + private Literal furnitureID; static { - Skript.registerEvent("Custom Furniture Break", EvtCustomFurnitureBreak.class, FurnitureBreakEvent.class, "break of [custom] (ia|itemsadder) furniture [%string%]"); + Skript.registerEvent("Custom Furniture Break", EvtCustomFurnitureBreak.class, FurnitureBreakEvent.class, "break of [custom] (ia|itemsadder) furniture [%customitemtype%]"); EventValues.registerEventValue(FurnitureBreakEvent.class, Location.class, new Getter() { @Override public @Nullable Location get(FurnitureBreakEvent event) { @@ -44,7 +45,7 @@ public class EvtCustomFurnitureBreak extends SkriptEvent { @SuppressWarnings("unchecked") @Override public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseResult parseResult) { - furnitureID = (Literal) args[0]; + furnitureID = (Literal) args[0]; return true; } @@ -55,8 +56,8 @@ public boolean check(Event e) { if (furnitureID == null) { return !event.isCancelled(); } else { - String id = event.getNamespacedID(); - if (id.equals(furnitureID.getSingle(e))) { + CustomItemType id = furnitureID.getSingle(e); + if (id != null && id.equals(new CustomItemType(event.getNamespacedID()))) { return !event.isCancelled(); } } diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureInteract.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureInteract.java index 001906f..9b161b3 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureInteract.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureInteract.java @@ -14,6 +14,7 @@ import dev.lone.itemsadder.api.CustomFurniture; import dev.lone.itemsadder.api.Events.FurnitureInteractEvent; import dev.lone.itemsadder.api.Events.FurnitureInteractEvent; +import me.asleepp.SkriptItemsAdder.other.CustomItemType; import org.bukkit.Location; import org.bukkit.event.Event; @@ -24,10 +25,10 @@ @Since("1.0") @RequiredPlugins("ItemsAdder") public class EvtCustomFurnitureInteract extends SkriptEvent { - private Literal furnitureID; + private Literal furnitureID; static { - Skript.registerEvent("Custom Furniture Interact", EvtCustomFurnitureInteract.class, FurnitureInteractEvent.class, "interact with [custom] (ia|itemsadder) furniture [%string%]"); + Skript.registerEvent("Custom Furniture Interact", EvtCustomFurnitureInteract.class, FurnitureInteractEvent.class, "interact with [custom] (ia|itemsadder) furniture [%customitemtype%]"); EventValues.registerEventValue(FurnitureInteractEvent.class, Location.class, new Getter() { @Override public @Nullable Location get(FurnitureInteractEvent event) { @@ -45,7 +46,7 @@ public class EvtCustomFurnitureInteract extends SkriptEvent { @SuppressWarnings("unchecked") @Override public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseResult parseResult) { - furnitureID = (Literal) args[0]; + furnitureID = (Literal) args[0]; return true; } @@ -56,8 +57,8 @@ public boolean check(Event e) { if (furnitureID == null) { return !event.isCancelled(); } else { - String id = event.getNamespacedID(); - if (id.equals(furnitureID.getSingle(e))) { + CustomItemType id = furnitureID.getSingle(e); + if (id != null && id.equals(new CustomItemType(event.getNamespacedID()))) { return !event.isCancelled(); } } diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurniturePlace.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurniturePlace.java index 6b5f4c6..e26400e 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurniturePlace.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurniturePlace.java @@ -10,6 +10,7 @@ import ch.njol.skript.Skript; import ch.njol.skript.lang.SkriptParser; import dev.lone.itemsadder.api.Events.FurniturePlaceEvent; +import me.asleepp.SkriptItemsAdder.other.CustomItemType; import org.bukkit.event.Event; import javax.annotation.Nullable; @@ -20,16 +21,16 @@ @Since("1.0") @RequiredPlugins("ItemsAdder") public class EvtCustomFurniturePlace extends SkriptEvent { - private Literal furnitureID; + private Literal furnitureID; static { - Skript.registerEvent("Custom Furniture Place", EvtCustomFurniturePlace.class, FurniturePlaceEvent.class, "place of [custom] (ia|itemsadder) furniture [%string%]"); + Skript.registerEvent("Custom Furniture Place", EvtCustomFurniturePlace.class, FurniturePlaceEvent.class, "place of [custom] (ia|itemsadder) furniture [%customitemtype%]"); } @SuppressWarnings("unchecked") @Override public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseResult parseResult) { - furnitureID = (Literal) args[0]; + furnitureID = (Literal) args[0]; return true; } @@ -40,8 +41,8 @@ public boolean check(Event e) { if (furnitureID == null) { return !event.isCancelled(); } else { - String id = event.getNamespacedID(); - if (id.equals(furnitureID.getSingle(e))) { + CustomItemType id = furnitureID.getSingle(e); + if (id != null && id.equals(new CustomItemType(event.getNamespacedID()))) { return !event.isCancelled(); } } diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureSuccessEvent.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureSuccessEvent.java index a8f1d88..4e09187 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureSuccessEvent.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureSuccessEvent.java @@ -13,6 +13,7 @@ import ch.njol.skript.util.Getter; import dev.lone.itemsadder.api.CustomFurniture; import dev.lone.itemsadder.api.Events.FurniturePlaceSuccessEvent; +import me.asleepp.SkriptItemsAdder.other.CustomItemType; import org.bukkit.Location; import org.bukkit.event.Event; @@ -24,12 +25,12 @@ @RequiredPlugins("ItemsAdder") public class EvtCustomFurnitureSuccessEvent extends SkriptEvent { - private Literal furnitureID; + private Literal furnitureID; static { Skript.registerEvent("Custom Furniture Success", EvtCustomFurnitureSuccessEvent.class, FurniturePlaceSuccessEvent.class, - "success[fully] plac(e|ing) [a] [custom] (ia|itemsadder) furniture [%string%]", - "place success [of] [custom] (ia|itemsadder) furniture [%string%]"); + "success[fully] plac(e|ing) [a] [custom] (ia|itemsadder) furniture [%customitemtype%]", + "place success [of] [custom] (ia|itemsadder) furniture [%customitemtype%]"); EventValues.registerEventValue(FurniturePlaceSuccessEvent.class, Location.class, new Getter() { @Override public Location get(FurniturePlaceSuccessEvent arg) { @@ -47,7 +48,7 @@ public Location get(FurniturePlaceSuccessEvent arg) { @SuppressWarnings("unchecked") @Override public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseResult parseResult) { - furnitureID = (Literal) args[0]; + furnitureID = (Literal) args[0]; return true; } @@ -56,8 +57,8 @@ public boolean check(Event e) { if (e instanceof FurniturePlaceSuccessEvent) { FurniturePlaceSuccessEvent event = (FurniturePlaceSuccessEvent) e; if (furnitureID != null) { - String id = furnitureID.getSingle(e); - if (id != null && !id.equals(event.getNamespacedID())) { + CustomItemType id = furnitureID.getSingle(e); + if (id != null && !id.equals(new CustomItemType(event.getNamespacedID()))) { return false; } } @@ -68,6 +69,6 @@ public boolean check(Event e) { @Override public String toString(@Nullable Event e, boolean debug) { - return "FurniturePlaceSuccess event" + (furnitureID != null ? " with id " + furnitureID.toString(e, debug) : ""); + return "Furniture Place Success event" + (furnitureID != null ? " with id " + furnitureID.toString(e, debug) : ""); } } diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetCustomBlockItem.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetCustomBlockItem.java deleted file mode 100644 index ce01603..0000000 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetCustomBlockItem.java +++ /dev/null @@ -1,65 +0,0 @@ -package me.asleepp.SkriptItemsAdder.elements.expressions; - -import ch.njol.skript.Skript; -import ch.njol.skript.doc.Description; -import ch.njol.skript.doc.Examples; -import ch.njol.skript.doc.Name; -import ch.njol.skript.doc.RequiredPlugins; -import ch.njol.skript.doc.Since; -import ch.njol.skript.lang.Expression; -import ch.njol.skript.lang.ExpressionType; -import ch.njol.skript.lang.SkriptParser; -import ch.njol.skript.lang.util.SimpleExpression; -import ch.njol.util.Kleenean; -import dev.lone.itemsadder.api.Events.CustomBlockInteractEvent; -import org.bukkit.event.Event; -import org.bukkit.inventory.ItemStack; - -import javax.annotation.Nullable; -@Name("Get Custom Block Item") -@Description({"Gets the item associated with the custom block."}) -@Examples({ - "on interact with custom itemsadder block:", - "\tset {_t} to the item linked with the itemsadder block"}) -@Since("1.4") -@RequiredPlugins("ItemsAdder") -public class ExprGetCustomBlockItem extends SimpleExpression { - - static { - Skript.registerExpression(ExprGetCustomBlockItem.class, ItemStack.class, ExpressionType.SIMPLE, "[the] item (linked|associated) with [the] [custom] (ia|itemsadder) block"); - } - - @Override - protected ItemStack[] get(Event e) { - if (e instanceof CustomBlockInteractEvent) { - CustomBlockInteractEvent event = (CustomBlockInteractEvent) e; - return new ItemStack[]{event.getCustomBlockItem().clone()}; - } - return null; - } - - @Override - public boolean isSingle() { - return true; - } - - @Override - public Class getReturnType() { - return ItemStack.class; - } - - @Override - public String toString(@Nullable Event e, boolean debug) { - return "item linked with the block"; - } - - @Override - public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { - if (!getParser().isCurrentEvent(CustomBlockInteractEvent.class)) { - Skript.error("You can't use 'the item linked/associated with the block' outside of a custom block interact event!"); - return false; - } - return true; - } - -} diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetCustomItem.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetCustomItem.java index a7984f1..abdd626 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetCustomItem.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetCustomItem.java @@ -13,6 +13,8 @@ import ch.njol.skript.lang.util.SimpleExpression; import ch.njol.util.Kleenean; import dev.lone.itemsadder.api.CustomStack; +import dev.lone.itemsadder.api.ItemsAdder; +import me.asleepp.SkriptItemsAdder.other.CustomItemType; import org.bukkit.event.Event; import org.bukkit.inventory.ItemStack; @@ -29,37 +31,56 @@ @RequiredPlugins("ItemsAdder") public class ExprGetCustomItem extends SimpleExpression { - private Expression itemNames; + private Expression itemTypes; static { - Skript.registerExpression(ExprGetCustomItem.class, ItemType.class, ExpressionType.SIMPLE, "[custom] (ia|itemsadder) item[s] %strings%"); + Skript.registerExpression(ExprGetCustomItem.class, ItemType.class, ExpressionType.SIMPLE, + "[custom] (ia|itemsadder) item[s] %customitemtype%", + "(all [[of] the]) [custom] (ia|itemsadder) item[s]"); } @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { - itemNames = (Expression) exprs[0]; + if (matchedPattern == 1) + return true; + itemTypes = (Expression) exprs[0]; return true; } @Override protected ItemType[] get(Event e) { - String[] names = itemNames.getArray(e); List items = new ArrayList<>(); - for (String name : names) { - CustomStack customStack = CustomStack.getInstance(name); - if (customStack != null) { - ItemStack item = customStack.getItemStack(); - if (item != null) { - items.add(new ItemType(item)); + if (itemTypes != null) { + if (itemTypes.isSingle()) { + CustomItemType itemType = itemTypes.getSingle(e); + if (itemType != null) { + CustomStack customStack = CustomStack.getInstance(itemType.getNamespacedID()); + if (customStack != null) { + items.add(new ItemType(customStack.getItemStack())); + } } + } else { + for (CustomItemType itemType : itemTypes.getArray(e)) { + CustomStack customStack = CustomStack.getInstance(itemType.getNamespacedID()); + if (customStack != null) { + items.add(new ItemType(customStack.getItemStack())); + } + } + } + } else { + List customStacks = ItemsAdder.getAllItems(); + for (CustomStack customStack : customStacks) { + items.add(new ItemType(customStack.getItemStack())); } } return items.toArray(new ItemType[0]); } + + @Override public boolean isSingle() { - return itemNames.isSingle(); + return itemTypes != null && itemTypes.isSingle(); } @Override @@ -69,6 +90,6 @@ public Class getReturnType() { @Override public String toString(@Nullable Event e, boolean debug) { - return "ItemsAdder items " + itemNames.toString(e, debug); + return "ItemsAdder items " + itemTypes.toString(e, debug); } } \ No newline at end of file diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetLoot.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetLoot.java deleted file mode 100644 index b8053c8..0000000 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetLoot.java +++ /dev/null @@ -1,59 +0,0 @@ -package me.asleepp.SkriptItemsAdder.elements.expressions; - -import ch.njol.skript.Skript; -import ch.njol.skript.lang.Expression; -import ch.njol.skript.lang.ExpressionType; -import ch.njol.skript.lang.SkriptParser; -import ch.njol.util.Kleenean; -import dev.lone.itemsadder.api.CustomBlock; -import dev.lone.itemsadder.api.CustomCrop; - -import javax.annotation.Nullable; - -public class ExprGetLoot extends SimpleExpression { - - private Expression blocks; - - static { - Skript.registerExpression(ExprGetLoot.class, ItemStack.class, ExpressionType.SIMPLE, "[the] loot [of] [custom] (ia|itemsadder) %blocks%"); - } - - @Override - public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { - blocks = (Expression) exprs[0]; - return true; - } - @Nullable - @Override - protected ItemStack[] get(Event event) { - Block[] bs = blocks.getArray(event); - List loot = null; - for (Block b : bs) { - CustomBlock customBlock = CustomBlock.byAlreadyPlaced(b); - if (customBlock != null) { - loot = customBlock.getLoot(); - } else { - CustomCrop customCrop = CustomCrop.byAlreadyPlaced(b); - if (customCrop != null) { - loot = customCrop.getLoot(); - } - } - } - return loot != null ? loot.toArray(new ItemStack[0]) : null; - } - - @Override - public boolean isSingle() { - return false; - } - - @Override - public Class getReturnType() { - return ItemStack.class; - } - - @Override - public String toString(@Nullable Event event, boolean debug) { - return "loot of " + blocks.toString(event, debug); - } -} diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/types/Types.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/types/Types.java index 9c4e4c4..67ef439 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/types/Types.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/types/Types.java @@ -1,15 +1,26 @@ package me.asleepp.SkriptItemsAdder.elements.types; +import ch.njol.skript.classes.Changer; import ch.njol.skript.classes.ClassInfo; import ch.njol.skript.classes.Parser; -import ch.njol.skript.expressions.base.EventValueExpression; +import ch.njol.skript.classes.Serializer; +import ch.njol.skript.lang.DefaultExpression; +import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.ParseContext; +import ch.njol.skript.lang.SkriptParser; import ch.njol.skript.registrations.Classes; -import dev.lone.itemsadder.api.CustomBlock; -import dev.lone.itemsadder.api.FontImages.FontImageWrapper; +import ch.njol.util.Checker; +import ch.njol.util.Kleenean; +import ch.njol.yggdrasil.Fields; import dev.lone.itemsadder.api.FontImages.TexturedInventoryWrapper; +import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; +import me.asleepp.SkriptItemsAdder.other.AliasesGenerator; +import me.asleepp.SkriptItemsAdder.other.CustomItemType; +import org.bukkit.event.Event; +import javax.annotation.Nullable; import java.util.HashMap; +import java.util.Iterator; import java.util.Map; public class Types { @@ -17,34 +28,63 @@ public class Types { public static Map inventoryMap = new HashMap<>(); static { - Classes.registerClass(new ClassInfo<>(CustomBlock.class, "customblock") - .user("customblock") - .name("Custom Block") - .description("Represents a Custom/ItemsAdder Block") - .defaultExpression(new EventValueExpression<>(CustomBlock.class)) - .since("1.5") - .parser(new Parser() { - + Classes.registerClass(new ClassInfo<>(CustomItemType.class, "customitemtype") + .user("customitemtypes?") + .name("Custom Item Type") + .description("Represents a custom item type using aliases.") + .serializer(new Serializer() { @Override - public String toString(CustomBlock customBlock, int flags) { - return customBlock.getId(); + public Fields serialize(CustomItemType customItemType) { + Fields fields = new Fields(); + fields.putObject("namespacedID", customItemType.getNamespacedID()); + return fields; } @Override - public String toVariableNameString(CustomBlock customBlock) { - return "customblock:" + customBlock.getId(); + public void deserialize(CustomItemType customItemType, Fields fields) { + try { + customItemType.setNamespacedID((String) fields.getObject("namespacedID")); + } catch (java.io.StreamCorruptedException e) { + e.printStackTrace(); + } } @Override - public CustomBlock parse(String s, ParseContext context) { - return CustomBlock.getInstance(s); + public boolean mustSyncDeserialization() { + return true; } @Override - public boolean canParse(ParseContext context) { + public boolean canBeInstantiated() { return true; } - })); + }) + + .parser(new Parser() { + @Override + @Nullable + public CustomItemType parse(String s, ParseContext context) { + AliasesGenerator aliasesGenerator = SkriptItemsAdder.getInstance().getAliasesGenerator(); + String namespacedID = aliasesGenerator.getNamespacedId(s.toLowerCase().replace("_", " ")); + return namespacedID == null ? null : new CustomItemType(namespacedID); + } + + @Override + public String toString(CustomItemType customItemType, int flags) { + return customItemType.getNamespacedID(); + } + + @Override + public String toVariableNameString(CustomItemType customItemType) { + return customItemType.getNamespacedID(); + } + + + public String getVariableNamePattern() { + return ".+"; + } + }) + ); Classes.registerClass(new ClassInfo<>(TexturedInventoryWrapper.class, "texturedinventorywrapper") .user("texturedinventorywrappers?") diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/other/AliasesGenerator.java b/src/main/java/me/asleepp/SkriptItemsAdder/other/AliasesGenerator.java new file mode 100644 index 0000000..45793ef --- /dev/null +++ b/src/main/java/me/asleepp/SkriptItemsAdder/other/AliasesGenerator.java @@ -0,0 +1,129 @@ +package me.asleepp.SkriptItemsAdder.other; + +import dev.lone.itemsadder.api.CustomStack; +import dev.lone.itemsadder.api.ItemsAdder; +import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; + +import java.io.File; +import java.io.IOException; +import java.util.*; + +public class AliasesGenerator { + + private final SkriptItemsAdder plugin; + private final File aliasesFile; + private FileConfiguration aliasesConfig; + private final Map aliases = new HashMap<>(); + private final Set generatedAliases = new HashSet<>(); + + public AliasesGenerator(SkriptItemsAdder plugin) { + this.plugin = plugin; + this.aliasesFile = new File(plugin.getDataFolder(), "aliases.yml"); + loadAliasesFile(); + loadAliases(); + } + + public void loadAliasesFile() { + if (!aliasesFile.exists()) { + aliasesFile.getParentFile().mkdirs(); + plugin.saveResource("aliases.yml", false); + } + aliasesConfig = YamlConfiguration.loadConfiguration(aliasesFile); + } + + private void loadAliases() { + for (String key : aliasesConfig.getKeys(false)) { + aliases.put(key, aliasesConfig.getString(key)); + } + plugin.getLogger().info("Loaded " + aliases.size() + " aliases from file."); + } + + public void saveAliases() { + try { + aliasesConfig.save(aliasesFile); + plugin.getLogger().info("Aliases saved to " + aliasesFile.getPath()); + } catch (IOException e) { + plugin.getLogger().severe("Failed to save aliases: " + e.getMessage()); + e.printStackTrace(); + } + } + + public String generateAliasesForItem(CustomStack item) { + String name = item.getId().toLowerCase().replace("_", " "); + String namespace = item.getNamespace(); + + + String existingAlias = getAliasForItem(item); + if (existingAlias != null) { + return existingAlias; + } else { + if (!aliases.containsValue(name)) { + return name; + } else { + for (Map.Entry entry : aliases.entrySet()) { + if (entry.getValue().equals(name) && !item.getNamespace().equals(entry.getKey().split(":")[0])) { + return item.getNamespace() + ":" + item.getId().toLowerCase().replace("_", " "); + } + } + } + } + int counter = 1; + String uniqueAlias; + do { + uniqueAlias = name + "_" + counter; + counter++; + } while (aliases.containsValue(uniqueAlias)); + return uniqueAlias; + } + + private String getAliasForItem(CustomStack item) { + for (Map.Entry entry : aliases.entrySet()) { + if (entry.getValue().equals(item.getNamespacedID())) { + return entry.getKey(); + } + } + return null; + } + + public void generateAliasesForNewItems(List newItems) { + for (CustomStack item : newItems) { + String alias = generateAliasesForItem(item); + registerAlias(alias, item.getNamespacedID()); + } + saveAliases(); + } + + public void generateAliasesForAllItems() { + plugin.getLogger().info("Generating aliases for all items."); + List allItems = ItemsAdder.getAllItems(); + plugin.getLogger().info("Total items: " + allItems.size()); + for (CustomStack item : allItems) { + String existingAlias = getAliasForItem(item); + if (existingAlias == null) { + String alias = generateAliasesForItem(item); + plugin.getLogger().info("Generated alias: " + alias + " for item: " + item.getNamespacedID()); + registerAlias(alias, item.getNamespacedID()); + } + } + saveAliases(); + plugin.getLogger().info("Aliases have been generated"); + } + + + public void registerAlias(String alias, String namespacedId) { + aliases.put(alias, namespacedId); + aliasesConfig.set(alias, namespacedId); + generatedAliases.add(alias); + plugin.getLogger().info("Registered alias: " + alias + " for item: " + namespacedId); + } + + public String getNamespacedId(String alias) { + return aliases.getOrDefault(alias, alias); + } + + public Set getGeneratedAliases() { + return generatedAliases; + } +} diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/other/CustomItemType.java b/src/main/java/me/asleepp/SkriptItemsAdder/other/CustomItemType.java new file mode 100644 index 0000000..25bdf3d --- /dev/null +++ b/src/main/java/me/asleepp/SkriptItemsAdder/other/CustomItemType.java @@ -0,0 +1,51 @@ +package me.asleepp.SkriptItemsAdder.other; + +import org.bukkit.event.Event; + +import java.util.Objects; +import java.util.function.Function; + +public class CustomItemType { + + private String namespacedID; + + public CustomItemType(String namespacedID) { + this.namespacedID = namespacedID; + } + + public String getNamespacedID() { + return namespacedID; + } + + public void setNamespacedID(String namespacedID) { + this.namespacedID = namespacedID; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + CustomItemType that = (CustomItemType) o; + return namespacedID.equals(that.namespacedID); + } + + @Override + public int hashCode() { + return Objects.hash(namespacedID); + } + + @Override + public String toString() { + return namespacedID; + } + + + public static CustomItemType fromEvent(Event event, AliasesGenerator aliasesGenerator, Function idExtractor) { + String namespacedID = idExtractor.apply(event); + String alias = aliasesGenerator.getNamespacedId(namespacedID); + return alias != null ? new CustomItemType(alias) : null; + } + + + +} diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/other/ItemsAdderEventListener.java b/src/main/java/me/asleepp/SkriptItemsAdder/other/ItemsAdderEventListener.java new file mode 100644 index 0000000..831d2db --- /dev/null +++ b/src/main/java/me/asleepp/SkriptItemsAdder/other/ItemsAdderEventListener.java @@ -0,0 +1,50 @@ +package me.asleepp.SkriptItemsAdder.other; + +import dev.lone.itemsadder.api.CustomStack; +import dev.lone.itemsadder.api.Events.ItemsAdderLoadDataEvent; +import dev.lone.itemsadder.api.ItemsAdder; +import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +import java.util.ArrayList; +import java.util.List; + +public class ItemsAdderEventListener implements Listener { + private final SkriptItemsAdder plugin; + private final AliasesGenerator aliasesGenerator; + private List initialItems; + + public ItemsAdderEventListener(SkriptItemsAdder plugin, AliasesGenerator aliasesGenerator, List initialItems) { + this.plugin = plugin; + this.aliasesGenerator = aliasesGenerator; + this.initialItems = initialItems; + } + + @EventHandler + public void onItemsAdderLoadData(ItemsAdderLoadDataEvent event) { + plugin.getLogger().info("ItemsAdder fully loaded, enabling skript-itemsadder."); + plugin.setItemsAdderReady(true); + List allItems = ItemsAdder.getAllItems(); + plugin.getLogger().info("Total items loaded: " + allItems.size()); + + if (initialItems == null) { + return; + } + + List newItems = findNewItems(initialItems, allItems); + plugin.getLogger().info("New items found: " + newItems.size()); + aliasesGenerator.generateAliasesForNewItems(newItems); + aliasesGenerator.saveAliases(); + } + + private List findNewItems(List initialItems, List allItems) { + List newItems = new ArrayList<>(); + for (CustomStack newItem : allItems) { + if (!initialItems.contains(newItem)) { + newItems.add(newItem); + } + } + return newItems; + } +} diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/Metrics.java b/src/main/java/me/asleepp/SkriptItemsAdder/other/Metrics.java similarity index 99% rename from src/main/java/me/asleepp/SkriptItemsAdder/Metrics.java rename to src/main/java/me/asleepp/SkriptItemsAdder/other/Metrics.java index 1bf18be..8bfec1a 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/Metrics.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/other/Metrics.java @@ -1,4 +1,4 @@ -package me.asleepp.SkriptItemsAdder; +package me.asleepp.SkriptItemsAdder.other; import java.io.BufferedReader; import java.io.ByteArrayOutputStream; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/UpdateChecker.java b/src/main/java/me/asleepp/SkriptItemsAdder/other/UpdateChecker.java similarity index 52% rename from src/main/java/me/asleepp/SkriptItemsAdder/UpdateChecker.java rename to src/main/java/me/asleepp/SkriptItemsAdder/other/UpdateChecker.java index 3935a03..abf6a2c 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/UpdateChecker.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/other/UpdateChecker.java @@ -1,9 +1,10 @@ -package me.asleepp.SkriptItemsAdder; +package me.asleepp.SkriptItemsAdder.other; +import com.google.gson.Gson; import com.google.gson.JsonObject; +import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; import net.kyori.adventure.text.minimessage.MiniMessage; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -32,12 +33,14 @@ public UpdateChecker(JavaPlugin plugin) { @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); - if (player.hasPermission("skript-nonplayercharacter.update.check") && latestVersion != null) { - player.sendMessage(" "); - player.sendMessage(MiniMessage.miniMessage().deserialize("[skript-itemsadder] skript-itemsadder is OUTDATED!")); - player.sendMessage(MiniMessage.miniMessage().deserialize("[skript-itemsadder] New version: " + latestVersion)); - player.sendMessage(MiniMessage.miniMessage().deserialize("[skript-itemsadder] Download at: https://github.com/Asleeepp/skript-itemsadder/releases")); - player.sendMessage(" "); + if (player.hasPermission("skript-itemsadder.update.check") && latestVersion != null) { + if (!currentVersion.equals(latestVersion)) { + player.sendMessage(" "); + player.sendMessage(MiniMessage.miniMessage().deserialize("[skript-itemsadder] skript-itemsadder is OUTDATED!")); + player.sendMessage(MiniMessage.miniMessage().deserialize("[skript-itemsadder] New version: " + latestVersion)); + player.sendMessage(MiniMessage.miniMessage().deserialize("[skript-itemsadder] Download here!")); + player.sendMessage(" "); + } } } @@ -51,13 +54,17 @@ private void checkForUpdate() { responseFuture.thenApply(HttpResponse::body) .thenAccept(body -> { - JsonObject jsonResponse = new JsonObject().getAsJsonObject(); - latestVersion = jsonResponse.get("tag_name").getAsString(); + JsonObject jsonResponse = new Gson().fromJson(body, JsonObject.class); + if (jsonResponse != null && jsonResponse.has("tag_name")) { + latestVersion = jsonResponse.get("tag_name").getAsString(); - if (!currentVersion.equals(latestVersion)) { - SkriptItemsAdder.getInstance().getLogger().warning("An update for skript-nonplayercharacter is available: " + latestVersion + " (current version: " + currentVersion + ")"); + if (!currentVersion.equals(latestVersion)) { + SkriptItemsAdder.getInstance().getLogger().warning("An update for skript-itemsadder is available: " + latestVersion + " (current version: " + currentVersion + ")"); + } else { + SkriptItemsAdder.getInstance().getLogger().info("skript-itemsadder is up to date!"); + } } else { - SkriptItemsAdder.getInstance().getLogger().info("skript-nonplayercharacter is up to date!"); + SkriptItemsAdder.getInstance().getLogger().severe("Failed to check for updates: Unexpected JSON format."); } }) .exceptionally(e -> { @@ -65,4 +72,5 @@ private void checkForUpdate() { return null; }); } + } \ No newline at end of file diff --git a/src/main/resources/aliases.yml b/src/main/resources/aliases.yml new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..248866c --- /dev/null +++ b/src/main/resources/config.yml @@ -0,0 +1,2 @@ +# Enable or disable the Update Checker. +check-for-updates: true \ No newline at end of file From 544394baa9bb05c027304b4db2b3bac1bb1b064c Mon Sep 17 00:00:00 2001 From: Asleepp <119438940+Asleeepp@users.noreply.github.com> Date: Fri, 5 Jul 2024 21:20:41 -0300 Subject: [PATCH 04/10] commit --- .../elements/conditions/CondCooldown.java | 51 ++++++++++ .../conditions/CondGetBlockClicked.java | 58 ----------- .../elements/conditions/CondHUDExists.java | 53 ++++++++++ .../elements/conditions/CondHUDIsVisible.java | 51 ++++++++++ .../conditions/CondIsCustomBlock.java | 76 +++++++++------ .../elements/conditions/CondIsCustomItem.java | 74 ++++++++------ .../elements/effects/EffDamageEffect.java | 49 ++++++++++ .../effects/EffMakeEntityPlayAnimation.java | 2 +- .../elements/effects/EffPlaceBlockOrCrop.java | 69 ++++++++----- .../effects/EffPlaceCustomFurniture.java | 34 +++++-- .../elements/effects/EffSetBlocksBetween.java | 42 ++++++-- .../elements/effects/EffUpdateHUD.java | 47 +++++++++ .../elements/events/EvtCustomBlockBreak.java | 70 +++++++------ .../events/EvtCustomBlockInteract.java | 61 +++++++----- .../elements/events/EvtCustomBlockPlace.java | 53 +++++----- .../events/EvtCustomFurnitureBreak.java | 46 ++++++--- .../events/EvtCustomFurnitureInteract.java | 48 ++++++--- .../events/EvtCustomFurniturePlace.java | 66 +++++++++---- .../EvtCustomFurnitureSuccessEvent.java | 48 ++++++--- .../expressions/ExprGetCustomItem.java | 55 ++++++++--- .../expressions/ExprGetFontImage.java | 49 +++++----- .../elements/types/Types.java | 11 --- .../other/AliasesGenerator.java | 97 +++++++++++++++---- .../other/ItemsAdderEventListener.java | 36 ++++--- src/main/resources/lang/english.lang | 4 +- 25 files changed, 879 insertions(+), 371 deletions(-) create mode 100644 src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondCooldown.java delete mode 100644 src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondGetBlockClicked.java create mode 100644 src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondHUDExists.java create mode 100644 src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondHUDIsVisible.java create mode 100644 src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffDamageEffect.java create mode 100644 src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffUpdateHUD.java diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondCooldown.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondCooldown.java new file mode 100644 index 0000000..2a75b38 --- /dev/null +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondCooldown.java @@ -0,0 +1,51 @@ +package me.asleepp.SkriptItemsAdder.elements.conditions; + +import ch.njol.skript.Skript; +import ch.njol.skript.lang.Condition; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser; +import ch.njol.util.Kleenean; +import dev.lone.itemsadder.api.CustomStack; +import org.bukkit.event.Event; +import org.bukkit.inventory.ItemStack; + +import javax.annotation.Nullable; + +public class CondCooldown extends Condition { + + private Expression itemStackExpression; + + static { + Skript.registerCondition(CondCooldown.class, "[custom] [ia|itemsadder] %itemstacks% has [a] permission [associated [with it]]"); + } + + @Override + public boolean init(Expression[] exprs, int i, Kleenean kleenean, SkriptParser.ParseResult parseResult) { + itemStackExpression = (Expression) exprs[0]; + return true; + } + + @Override + public boolean check(Event event) { + ItemStack[] itemStacks = itemStackExpression.getArray(event); + + if (itemStacks == null) { + return false; + } + + for (ItemStack itemStack : itemStacks) { + CustomStack customStack = CustomStack.byItemStack(itemStack); + if (!(customStack == null)) { + return customStack.hasPermission(); + } + } + + return true; + } + + @Override + public String toString(@Nullable Event event, boolean debug) { + return itemStackExpression.toString(event, debug) + "has a permission associated with it"; + } + +} diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondGetBlockClicked.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondGetBlockClicked.java deleted file mode 100644 index d33f469..0000000 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondGetBlockClicked.java +++ /dev/null @@ -1,58 +0,0 @@ -package me.asleepp.SkriptItemsAdder.elements.conditions; - -import ch.njol.skript.Skript; -import ch.njol.skript.doc.Description; -import ch.njol.skript.doc.Examples; -import ch.njol.skript.doc.Name; -import ch.njol.skript.doc.RequiredPlugins; -import ch.njol.skript.doc.Since; -import ch.njol.skript.lang.Condition; -import ch.njol.skript.lang.Expression; -import ch.njol.skript.lang.SkriptParser; -import ch.njol.util.Kleenean; -import org.bukkit.event.Event; -import dev.lone.itemsadder.api.Events.CustomBlockInteractEvent; - -import javax.annotation.Nullable; -@Name("Is Block Clicked") -@Description({"This condition checks what block the player clicked."}) -@Examples({ - "on interact with custom block:", - "\tif clicked block is \"diamond_tiles\"", - "\t\tsend \"That's quite valuable.\" "}) -@Since("1.4") -@RequiredPlugins("ItemsAdder") -public class CondGetBlockClicked extends Condition { - - private Expression block; - - static { - Skript.registerCondition(CondGetBlockClicked.class, "[the] [custom] (ia|itemsadder) clicked block is %strings%"); - } - - @Override - public boolean check(Event e) { - if (e instanceof CustomBlockInteractEvent) { - CustomBlockInteractEvent event = (CustomBlockInteractEvent) e; - String clickedBlock = event.getBlockClicked().getType().toString(); - return clickedBlock.equals(block.getSingle(e)); - } - return false; - } - - @Override - public String toString(@Nullable Event e, boolean debug) { - return "[the] block clicked is " + block.toString(e, debug); - } - - @Override - public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { - if (!getParser().isCurrentEvent(CustomBlockInteractEvent.class)) { - Skript.error("You can't use 'the block clicked is ...' outside of a custom block interact event!"); - return false; - } - block = (Expression) exprs[0]; - return true; - } - -} diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondHUDExists.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondHUDExists.java new file mode 100644 index 0000000..091ed25 --- /dev/null +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondHUDExists.java @@ -0,0 +1,53 @@ +package me.asleepp.SkriptItemsAdder.elements.conditions; + +import ch.njol.skript.Skript; +import ch.njol.skript.lang.Condition; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser; +import ch.njol.util.Kleenean; +import dev.lone.itemsadder.api.FontImages.PlayerHudWrapper; +import dev.lone.itemsadder.api.FontImages.PlayerHudsHolderWrapper; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; + +import javax.annotation.Nullable; + +public class CondHUDExists extends Condition { + + private Expression players; + private Expression hudID; + + static { + Skript.registerCondition(CondHUDExists.class, "[custom] (ia|itemsadder) hud %string% [of %players%] exists"); + } + + @Override + public boolean init(Expression[] exprs, int i, Kleenean kleenean, SkriptParser.ParseResult parseResult) { + hudID = (Expression) exprs[0]; + players = (Expression) exprs[1]; + return true; + } + + @Override + public boolean check(Event event) { + String id = hudID.getSingle(event); + Player[] playersArray = players != null ? players.getArray(event) : new Player[]{}; + + if (id != null && playersArray.length > 0) { + for (Player player : playersArray) { + PlayerHudsHolderWrapper hudHolder = new PlayerHudsHolderWrapper(player); + PlayerHudWrapper hudWrapper = new PlayerHudWrapper(hudHolder, id); + if (!hudWrapper.exists()) { + return false; + } + } + return true; + } + return false; + } + + @Override + public String toString(@Nullable Event event, boolean debug) { + return "itemsadder hud " + hudID.toString(event, debug) + " of players " + (players != null ? players.toString(event, debug) : "all players") + " exists"; + } +} diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondHUDIsVisible.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondHUDIsVisible.java new file mode 100644 index 0000000..a137840 --- /dev/null +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondHUDIsVisible.java @@ -0,0 +1,51 @@ +package me.asleepp.SkriptItemsAdder.elements.conditions; + +import ch.njol.skript.Skript; +import ch.njol.skript.lang.Condition; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser; +import ch.njol.util.Kleenean; +import dev.lone.itemsadder.api.FontImages.PlayerHudWrapper; +import dev.lone.itemsadder.api.FontImages.PlayerHudsHolderWrapper; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; + +import javax.annotation.Nullable; + +public class CondHUDIsVisible extends Condition { + + private Expression players; + private Expression hudID; + + static { + Skript.registerCondition(CondHUDIsVisible.class, "%players% can (see|view) [custom] (ia|itemsadder) hud %string%"); + } + + @Override + public boolean init(Expression[] exprs, int i, Kleenean kleenean, SkriptParser.ParseResult parseResult) { + players = (Expression) exprs[0]; + hudID = (Expression) exprs[1]; + return true; + } + + @Override + public boolean check(Event event) { + Player[] p = players.getArray(event); + String id = hudID.getSingle(event); + + if (p != null && id != null) { + for (Player players : p) { + PlayerHudsHolderWrapper hudsHolder = new PlayerHudsHolderWrapper(players); + PlayerHudWrapper hudWrapper = new PlayerHudWrapper(hudsHolder, id); + return hudWrapper.isVisible(); + } + return false; + } + return false; + } + + @Override + public String toString(@Nullable Event event, boolean debug) { + return "player(s) " + players.toString(event, debug) + "can view itemsadder hud " + hudID.toString(event, debug); + } +} diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomBlock.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomBlock.java index dd2e05a..5c26283 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomBlock.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomBlock.java @@ -11,62 +11,76 @@ import ch.njol.skript.lang.SkriptParser; import ch.njol.util.Kleenean; import dev.lone.itemsadder.api.CustomBlock; +import me.asleepp.SkriptItemsAdder.other.CustomItemType; import org.bukkit.block.Block; import org.bukkit.event.Event; import javax.annotation.Nullable; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + @Name("Is ItemsAdder Block") @Description({"Checks if the block is an ItemsAdder block."}) @Examples({ - "on break:", - "\tif event-block is a custom block with id \"iasurvival:ruby_block\":", - "\t\tkill player", - "\telse if event-block isn't a custom block:", - "\t\tsend \"Good Job!\" to player"}) + "on break:", + "\tif event-block is a custom block with id \"iasurvival:ruby_block\":", + "\t\tkill player", + "\telse if event-block isn't a custom block:", + "\t\tsend \"Good Job!\" to player" +}) @Since("1.0, 1.5 (Negative Comparison)") @RequiredPlugins("ItemsAdder") public class CondIsCustomBlock extends Condition { - private Expression block; - private Expression blockId; + private Expression blocks; + private Expression ids; + private boolean negated; static { - Skript.registerCondition(CondIsCustomBlock.class, "%blocks% (is [a[n]]|are) [custom] (ia|itemsadder) block[s] [[with id] %-string%]", "%blocks% (is[n't| not]) [a] [custom] (ia|itemsadder) block[s] [[with id] %-string%]"); + Skript.registerCondition(CondIsCustomBlock.class, + "%blocks% (is [a[n]]|are) [custom] (ia|itemsadder) block[s] [[with id] %-customitemtypes/strings%]", + "%blocks% (is[n't| not]) [a] [custom] (ia|itemsadder) block[s] [[with id] %-customitemtypes/strings%]"); } @SuppressWarnings("unchecked") @Override - public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { - block = (Expression) exprs[0]; - blockId = (Expression) exprs[1]; - setNegated(matchedPattern == 1); + public boolean init(Expression[] expressions, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { + blocks = (Expression) expressions[0]; + ids = (Expression) expressions[1]; + negated = matchedPattern == 1; return true; } @Override - public boolean check(Event e) { - Block[] blocks = block.getArray(e); - if (blocks == null) { - return isNegated(); - } + public boolean check(Event event) { + List expectedIds = Arrays.stream(ids.getArray(event)) + .map(id -> { + if (id instanceof CustomItemType) { + return ((CustomItemType) id).getNamespacedID(); + } else if (id instanceof String) { + return (String) id; + } + return null; + }) + .filter(id -> id != null) + .collect(Collectors.toList()); - for (Block b : blocks) { - CustomBlock customBlock = CustomBlock.byAlreadyPlaced(b); - if (customBlock == null) { - return isNegated(); - } - if (blockId != null) { - String id = blockId.getSingle(e); - if (id == null || !customBlock.getId().equals(id)) { - return isNegated(); - } + boolean allMatch = blocks.getArray(event).length > 0; + for (Block block : blocks.getArray(event)) { + CustomBlock customBlock = CustomBlock.byAlreadyPlaced(block); + boolean matches = customBlock != null && expectedIds.contains(customBlock.getId()); + if (negated && matches || !negated && !matches) { + allMatch = false; + break; } } - return !isNegated(); + return allMatch; } @Override - public String toString(@Nullable Event e, boolean debug) { - return block.toString(e, debug) + (isNegated() ? " isn't" : " is") + " a custom block" + (blockId != null ? " with id " + blockId.toString(e, debug) : ""); + public String toString(@Nullable Event event, boolean debug) { + String blockString = blocks.toString(event, debug); + String idString = ids.toString(event, debug); + return blockString + (negated ? " isn't" : " is") + " a custom block" + (idString != null ? " with id " + idString : ""); } } - diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomItem.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomItem.java index 1754f96..0ccca9e 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomItem.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomItem.java @@ -1,7 +1,6 @@ package me.asleepp.SkriptItemsAdder.elements.conditions; import ch.njol.skript.Skript; -import ch.njol.skript.aliases.ItemType; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Examples; import ch.njol.skript.doc.Name; @@ -14,61 +13,72 @@ import org.bukkit.event.Event; import org.bukkit.inventory.ItemStack; import dev.lone.itemsadder.api.CustomStack; +import me.asleepp.SkriptItemsAdder.other.CustomItemType; import javax.annotation.Nullable; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; @Name("Is ItemsAdder Item") @Description({"Checks if the item is an ItemsAdder item."}) -@Examples({"if player's tool is a custom item", "if player's tool is a custom item \"icon_arrow_chest\""}) +@Examples({ + "if player's tool is a custom item", + "if player's tool is a custom item \"icon_arrow_chest\"" +}) @Since("1.0, 1.5 (Negative comparison)") @RequiredPlugins("ItemsAdder") public class CondIsCustomItem extends Condition { - private Expression item; - private Expression itemId; + private Expression items; + private Expression ids; + private boolean negated; - static{ - Skript.registerCondition(CondIsCustomItem.class, "%itemtypes% (is [a[n]]|are) [custom] (ia|itemsadder) item[s] [[with id] %-string%]", "%itemtypes% (is[n't| not]) [a] [custom] (ia|itemsadder) item[s] [[with id] %-string%]"); + static { + Skript.registerCondition(CondIsCustomItem.class, + "%itemstacks% (is [a[n]]|are) [custom] (ia|itemsadder) item[s] [[with id] %-customitemtypes/strings%]", + "%itemstacks% (is[n't| not]) [a] [custom] (ia|itemsadder) item[s] [[with id] %-customitemtypes/strings%]"); } @SuppressWarnings("unchecked") @Override - public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { - item = (Expression) exprs[0]; - itemId = (Expression) exprs[1]; - setNegated(matchedPattern == 1); + public boolean init(Expression[] expressions, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { + items = (Expression) expressions[0]; + ids = (Expression) expressions[1]; + negated = matchedPattern == 1; return true; } @Override - public boolean check(Event e) { - ItemType[] items = item.getArray(e); - if (items == null) { - return isNegated(); - } + public boolean check(Event event) { + List expectedIds = Arrays.stream(ids.getArray(event)) + .map(id -> { + if (id instanceof CustomItemType) { + return ((CustomItemType) id).getNamespacedID(); + } else if (id instanceof String) { + return (String) id; + } + return null; + }) + .filter(id -> id != null) + .collect(Collectors.toList()); - for (ItemType itemType : items) { - ItemStack itemStack = itemType.getRandom(); - if (itemStack == null) { - return isNegated(); - } + boolean allMatch = items.getArray(event).length > 0; + for (ItemStack itemStack : items.getArray(event)) { CustomStack customStack = CustomStack.byItemStack(itemStack); - if (customStack == null) { - return isNegated(); - } - if (itemId != null) { - String id = itemId.getSingle(e); - if (id == null || !customStack.getId().equals(id)) { - return isNegated(); - } + boolean matches = customStack != null && expectedIds.contains(customStack.getId()); + if (negated && matches || !negated && !matches) { + allMatch = false; + break; } } - return !isNegated(); + return allMatch; } @Override - public String toString(@Nullable Event e, boolean debug) { - return item.toString(e, debug) + (isNegated() ? " isn't" : " is") + " a custom item" + (itemId != null ? " with id " + itemId.toString(e, debug) : ""); + public String toString(@Nullable Event event, boolean debug) { + String itemString = items.toString(event, debug); + String idString = ids.toString(event, debug); + return itemString + (negated ? " isn't" : " is") + " a custom item" + (idString != null ? " with id " + idString : ""); } } - diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffDamageEffect.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffDamageEffect.java new file mode 100644 index 0000000..4fbad30 --- /dev/null +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffDamageEffect.java @@ -0,0 +1,49 @@ +package me.asleepp.SkriptItemsAdder.elements.effects; + +import ch.njol.skript.Skript; +import ch.njol.skript.lang.Effect; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser; +import ch.njol.util.Kleenean; +import dev.lone.itemsadder.api.CustomEntity; +import org.bukkit.entity.Entity; +import org.bukkit.event.Event; + +import javax.annotation.Nullable; + +public class EffDamageEffect extends Effect { + + private Expression entitiesExpr; + + static { + Skript.registerEffect(EffDamageEffect.class, "(show|play) [the] damage effect on [custom] (itemsadder|ia) entit[y|ies] %entities%"); + } + + @Override + public boolean init(Expression[] exprs, int i, Kleenean kleenean, SkriptParser.ParseResult parseResult) { + entitiesExpr = (Expression) exprs[0]; + return true; + } + + @Override + protected void execute(Event event) { + Entity[] entities = entitiesExpr.getArray(event); + + if (entities == null) { + return; + } + + for (Entity entity : entities) { + CustomEntity customEntity = CustomEntity.byAlreadySpawned(entity); + if (!(customEntity == null)) { + customEntity.playDamageEffect(false); + } + + } + } + + @Override + public String toString(@Nullable Event event, boolean debug) { + return "show damage effect on itemsadder entity " + entitiesExpr.toString(event, debug); + } +} diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffMakeEntityPlayAnimation.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffMakeEntityPlayAnimation.java index 5f3ee61..651046d 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffMakeEntityPlayAnimation.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffMakeEntityPlayAnimation.java @@ -30,7 +30,7 @@ public class EffMakeEntityPlayAnimation extends Effect { static { - Skript.registerEffect(EffMakeEntityPlayAnimation.class, new String[] {"(make|force) %entities% [to] play [custom] (ia|itemsadder) (anim[ation]) %string%"}); + Skript.registerEffect(EffMakeEntityPlayAnimation.class, "(make|force) %entities% [to] play [custom] (ia|itemsadder) (anim[ation]) %string%"); } @Override diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlaceBlockOrCrop.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlaceBlockOrCrop.java index 4aa45cc..6896275 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlaceBlockOrCrop.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlaceBlockOrCrop.java @@ -13,10 +13,14 @@ import ch.njol.util.Kleenean; import dev.lone.itemsadder.api.CustomBlock; import dev.lone.itemsadder.api.CustomCrop; +import me.asleepp.SkriptItemsAdder.other.CustomItemType; import org.bukkit.Location; import org.bukkit.event.Event; import javax.annotation.Nullable; +import java.util.Arrays; +import java.util.List; + @Name("Place Custom Block/Crop") @Description({"Places a custom block or crop at a location."}) @Examples({ @@ -26,42 +30,61 @@ @RequiredPlugins("ItemsAdder") public class EffPlaceBlockOrCrop extends Effect { private Expression locations; - private Expression customBlockIdExpr; + private Expression customBlockIdExpr; private boolean isCrop; static { - Skript.registerEffect(EffPlaceBlockOrCrop.class, "(set|place) [custom] (ia|itemsadder) (block|:crop) %string% [%directions% %locations%]"); + Skript.registerEffect(EffPlaceBlockOrCrop.class, "(set|place) [custom] (ia|itemsadder) (block|:crop) %customitemtypes/strings% [%directions% %locations%]"); } @Override - public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { - customBlockIdExpr = (Expression) exprs[0]; - locations = Direction.combine((Expression) exprs[1], (Expression) exprs[2]); - if (parseResult.hasTag("crop")) + public boolean init(Expression[] expressions, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { + customBlockIdExpr = (Expression) expressions[0]; + locations = Direction.combine((Expression) expressions[1], (Expression) expressions[2]); + if (parseResult.regexes.size() > 0 && parseResult.regexes.get(0).group().equals("crop")) isCrop = true; return true; } @Override protected void execute(Event e) { - String customBlockId = customBlockIdExpr.getSingle(e); + List customBlockIds = Arrays.asList(customBlockIdExpr.getArray(e)); - if (locations == null || customBlockId == null) { + if (locations == null || customBlockIds.isEmpty()) { return; } - // TODO test this - for (Location location : this.locations.getArray(e)) { - if (isCrop) { - try { // for some reason CustomCrop doesn't have getInstance - CustomCrop crop = CustomCrop.place(customBlockId, location); - } - catch (Exception exception) { - Skript.error("Your namespace:id does not exist."); + + for (Location location : locations.getArray(e)) { + for (Object customBlockIdObj : customBlockIds) { + String customBlockId; + if (customBlockIdObj instanceof CustomItemType) { + customBlockId = ((CustomItemType) customBlockIdObj).getNamespacedID(); + } else if (customBlockIdObj instanceof String) { + customBlockId = (String) customBlockIdObj; + } else { + continue; } - } else { - CustomBlock block = CustomBlock.getInstance(customBlockId); - if (block != null) { - block.place(location); + + try { + if (isCrop) { + CustomCrop existingCrop = CustomCrop.byAlreadyPlaced(location.getBlock()); + if (existingCrop == null) { + CustomCrop crop = CustomCrop.place(customBlockId, location); + } else { + Skript.error("There is already a crop here!"); + } + } else { + CustomBlock existingBlock = CustomBlock.byAlreadyPlaced(location.getBlock()); + CustomBlock block = CustomBlock.getInstance(customBlockId); + if (block != null) { + if (existingBlock == null) { + existingBlock.remove(); + } + block.place(location); + } + } + } catch (Exception ex) { + ex.printStackTrace(); } } } @@ -69,6 +92,8 @@ protected void execute(Event e) { @Override public String toString(@Nullable Event e, boolean debug) { - return "place custom " + (isCrop ? "crop " : "block ") + this.customBlockIdExpr.toString(e, debug) + " at " + this.locations.toString(e, debug); + String itemTypeString = customBlockIdExpr.toString(e, debug); + String type = isCrop ? "crop" : "block"; + return "place custom " + type + " " + itemTypeString + " at " + locations.toString(e, debug); } -} \ No newline at end of file +} diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlaceCustomFurniture.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlaceCustomFurniture.java index 1400d7e..00ee92f 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlaceCustomFurniture.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlaceCustomFurniture.java @@ -10,9 +10,12 @@ import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser; import ch.njol.util.Kleenean; +import org.bukkit.entity.Entity; import org.bukkit.event.Event; import dev.lone.itemsadder.api.CustomFurniture; import org.bukkit.Location; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitRunnable; import javax.annotation.Nullable; @@ -25,18 +28,41 @@ public class EffPlaceCustomFurniture extends Effect { private Expression furnitureId; private Expression location; + private JavaPlugin plugin; static { Skript.registerEffect(EffPlaceCustomFurniture.class, "(set|place) [custom] (ia|itemsadder) furniture %string% at %location%"); } + @Override + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { + furnitureId = (Expression) exprs[0]; + location = (Expression) exprs[1]; + return true; + } + @Override protected void execute(Event e) { String id = furnitureId.getSingle(e); Location loc = location.getSingle(e); + CustomFurniture customFurniture = CustomFurniture.byAlreadySpawned(loc.getBlock()); if (id != null && loc != null) { - CustomFurniture.spawn(id, loc.getBlock()); + if (customFurniture == null) { + CustomFurniture.spawn(id, loc.getBlock()); + } else { + Entity armorStand = customFurniture.getArmorstand(); + if (armorStand != null) { + Location originalLocation = armorStand.getLocation(); + customFurniture.remove(false); + new BukkitRunnable() { + @Override + public void run() { + customFurniture.teleport(originalLocation); + } + }.runTaskLater(plugin, 3); + } + } } } @@ -45,10 +71,4 @@ public String toString(@Nullable Event e, boolean debug) { return "(set|place) [custom] (ia|itemsadder) furniture " + furnitureId.toString(e, debug) + " at " + location.toString(e, debug); } - @Override - public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { - furnitureId = (Expression) exprs[0]; - location = (Expression) exprs[1]; - return true; - } } diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffSetBlocksBetween.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffSetBlocksBetween.java index 9e0744c..086eb24 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffSetBlocksBetween.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffSetBlocksBetween.java @@ -11,10 +11,17 @@ import ch.njol.skript.lang.SkriptParser; import ch.njol.util.Kleenean; import dev.lone.itemsadder.api.CustomBlock; +import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; +import me.asleepp.SkriptItemsAdder.other.AliasesGenerator; +import me.asleepp.SkriptItemsAdder.other.CustomItemType; import org.bukkit.Location; import org.bukkit.event.Event; import javax.annotation.Nullable; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + @Name("Set Custom Blocks Within") @Description({"Sets the blocks within 2 locations to ItemsAdder custom blocks."}) @Examples({"set all blocks within location(0, 100, 0) and player's location to custom block \"iasurvival:ruby_block\""}) @@ -23,23 +30,47 @@ public class EffSetBlocksBetween extends Effect { private Expression location1Expr; private Expression location2Expr; - private Expression customBlockIdExpr; + private Expression customBlockIdExpr; + private List aliases; + private AliasesGenerator aliasesGenerator = SkriptItemsAdder.getInstance().getAliasesGenerator(); static { - Skript.registerEffect(EffSetBlocksBetween.class, new String[] {"(set|place) [all] blocks within %location% and %location% to [custom] (ia|itemsadder) block %string%"}); + Skript.registerEffect(EffSetBlocksBetween.class, "(set|place) [all] blocks within %location% and %location% to [custom] (ia|itemsadder) block %customitemtypes/strings%"); } + @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { location1Expr = (Expression) exprs[0]; location2Expr = (Expression) exprs[1]; - customBlockIdExpr = (Expression) exprs[2]; + customBlockIdExpr = exprs[2]; + aliases = Arrays.stream(exprs) + .filter(expr -> expr instanceof Expression) + .map(expr -> { + Object value = ((Expression) expr).getSingle(null); + if (value instanceof CustomItemType) { + return ((CustomItemType) value).getNamespacedID(); + } else if (value instanceof String) { + return (String) value; + } + return null; + }) + .filter(name -> name != null) + .collect(Collectors.toList()); return true; } + @Override protected void execute(Event e) { Location location1 = location1Expr.getSingle(e); Location location2 = location2Expr.getSingle(e); - String customBlockId = customBlockIdExpr.getSingle(e); + Object customBlockIdObj = customBlockIdExpr.getSingle(e); + String customBlockId = null; + + if (customBlockIdObj instanceof CustomItemType) { + customBlockId = ((CustomItemType) customBlockIdObj).getNamespacedID(); + } else if (customBlockIdObj instanceof String) { + customBlockId = (String) customBlockIdObj; + } if (location1 == null || location2 == null || customBlockId == null) { return; @@ -69,7 +100,4 @@ protected void execute(Event e) { public String toString(@Nullable Event e, boolean debug) { return "place custom block " + customBlockIdExpr.toString(e, debug) + " between locations " + location1Expr.toString(e, debug) + " and " + location2Expr.toString(e, debug); } - - } - diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffUpdateHUD.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffUpdateHUD.java new file mode 100644 index 0000000..651e84b --- /dev/null +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffUpdateHUD.java @@ -0,0 +1,47 @@ +package me.asleepp.SkriptItemsAdder.elements.effects; + +import ch.njol.skript.Skript; +import ch.njol.skript.lang.Effect; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser; +import ch.njol.util.Kleenean; +import dev.lone.itemsadder.api.FontImages.PlayerHudsHolderWrapper; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; + +import javax.annotation.Nullable; + +public class EffUpdateHUD extends Effect { + + private Expression players; + + static { + Skript.registerEffect(EffUpdateHUD.class, "(update|refresh) %players%[`s] [current] [custom] (itemsadder|ia) hud"); + } + + @Override + public boolean init(Expression[] exprs, int i, Kleenean kleenean, SkriptParser.ParseResult parseResult) { + players = (Expression) exprs[0]; + return true; + } + + @Override + protected void execute(Event event) { + Player[] p = players.getArray(event); + + if (p != null) { + for (Player players : p) { + PlayerHudsHolderWrapper playerHudsHolderWrapper = new PlayerHudsHolderWrapper(players); + if (playerHudsHolderWrapper.exists()) { + playerHudsHolderWrapper.sendUpdate(); + } + } + } + } + + @Override + public String toString(@Nullable Event event, boolean debug) { + return "update " + players.toString(event, debug) + " hud"; + } + +} diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockBreak.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockBreak.java index 1b19e6c..9af6d6e 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockBreak.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockBreak.java @@ -1,32 +1,46 @@ package me.asleepp.SkriptItemsAdder.elements.events; import ch.njol.skript.Skript; +import ch.njol.skript.doc.Description; +import ch.njol.skript.doc.Examples; +import ch.njol.skript.doc.Name; +import ch.njol.skript.doc.RequiredPlugins; +import ch.njol.skript.doc.Since; import ch.njol.skript.lang.Literal; import ch.njol.skript.lang.SkriptEvent; import ch.njol.skript.lang.SkriptParser; import ch.njol.skript.registrations.EventValues; import ch.njol.skript.util.Getter; +import dev.lone.itemsadder.api.CustomBlock; import dev.lone.itemsadder.api.Events.CustomBlockBreakEvent; import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; import me.asleepp.SkriptItemsAdder.other.AliasesGenerator; import me.asleepp.SkriptItemsAdder.other.CustomItemType; import org.bukkit.Location; import org.bukkit.event.Event; -import org.bukkit.inventory.ItemStack; import javax.annotation.Nullable; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; +@Name("On Custom Block Break") +@Description({"Fires when a ItemsAdder block gets broken."}) +@Examples({"on break of custom block \"namespace:ruby_block\":", "on break of custom block ruby block:"}) +@Since("1.0") +@RequiredPlugins("ItemsAdder") public class EvtCustomBlockBreak extends SkriptEvent { - private Literal blockName; + private Literal[] blockNames; + private List aliases; + private AliasesGenerator aliasesGenerator = SkriptItemsAdder.getInstance().getAliasesGenerator(); static { - Skript.registerEvent("Custom Block Break", EvtCustomBlockBreak.class, CustomBlockBreakEvent.class, "break of [custom] (ia|itemsadder) block [%customitemtype%]"); - EventValues.registerEventValue(CustomBlockBreakEvent.class, CustomItemType.class, new Getter() { + Skript.registerEvent("Custom Block Break", EvtCustomBlockBreak.class, CustomBlockBreakEvent.class, "break [of] [custom] (ia|itemsadder) block[s] [%customitemtypes/strings%]"); + EventValues.registerEventValue(CustomBlockBreakEvent.class, CustomBlock.class, new Getter() { @Override - public CustomItemType get(CustomBlockBreakEvent event) { - String namespacedID = event.getNamespacedID(); - return new CustomItemType(namespacedID); + public CustomBlock get(CustomBlockBreakEvent event) { + return CustomBlock.byAlreadyPlaced(event.getBlock()); } }, 0); EventValues.registerEventValue(CustomBlockBreakEvent.class, Location.class, new Getter() { @@ -35,19 +49,27 @@ public Location get(CustomBlockBreakEvent event) { return event.getBlock().getLocation(); } }, 0); - EventValues.registerEventValue(CustomBlockBreakEvent.class, ItemStack.class, new Getter() { - @Override - public @Nullable ItemStack get(CustomBlockBreakEvent event) { - return event.getCustomBlockItem(); - } - }, 0); } @SuppressWarnings("unchecked") @Override public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseResult parseResult) { - if (args.length > 0 && args[0] instanceof Literal) { - blockName = (Literal) args[0]; + blockNames = args; + if (blockNames != null) { + aliases = Arrays.stream(blockNames) + .map(literal -> { + if (literal instanceof Literal) { + Object value = ((Literal) literal).getSingle(); + if (value instanceof CustomItemType) { + return ((CustomItemType) value).getNamespacedID(); + } else if (value instanceof String) { + return (String) value; + } + } + return null; + }) + .filter(name -> name != null) + .collect(Collectors.toList()); } return true; } @@ -64,26 +86,14 @@ public boolean check(Event event) { } // Check block name - if (blockName != null) { - CustomItemType specifiedBlockType = blockName.getSingle(event); - AliasesGenerator aliasesGenerator = SkriptItemsAdder.getInstance().getAliasesGenerator(); - CustomItemType actualBlockType = EventValues.getEventValue(customEvent, CustomItemType.class, 0); - - if (specifiedBlockType == null || actualBlockType == null) { - return false; - } - - String specifiedBlockName = specifiedBlockType.getNamespacedID(); - String actualBlockName = actualBlockType.getNamespacedID(); - if (actualBlockName == null || actualBlockName.isEmpty() || !actualBlockName.equals(specifiedBlockName)) { - return false; - } + if (aliases != null && !aliases.isEmpty()) { + String actualBlockName = customEvent.getNamespacedID(); + return aliases.contains(aliasesGenerator.getNamespacedId(actualBlockName)); } return true; } - @Override public String toString(@Nullable Event e, boolean debug) { return "Custom Block Break event"; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockInteract.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockInteract.java index 5b66382..639f525 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockInteract.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockInteract.java @@ -11,15 +11,19 @@ import ch.njol.skript.lang.SkriptParser; import ch.njol.skript.registrations.EventValues; import ch.njol.skript.util.Getter; +import dev.lone.itemsadder.api.CustomBlock; import dev.lone.itemsadder.api.Events.CustomBlockInteractEvent; import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; import me.asleepp.SkriptItemsAdder.other.AliasesGenerator; import me.asleepp.SkriptItemsAdder.other.CustomItemType; import org.bukkit.Location; -import org.bukkit.block.Block; import org.bukkit.event.Event; import javax.annotation.Nullable; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + @Name("On Custom Block Interact") @Description({"Fires when a ItemsAdder block gets interacted with."}) @@ -27,29 +31,47 @@ @Since("1.0") @RequiredPlugins("ItemsAdder") public class EvtCustomBlockInteract extends SkriptEvent { - private Literal blockName; + + private Literal[] blockNames; + private List aliases; + private AliasesGenerator aliasesGenerator = SkriptItemsAdder.getInstance().getAliasesGenerator(); static { - Skript.registerEvent("Custom Block Interact", EvtCustomBlockInteract.class, CustomBlockInteractEvent.class, "interact with [custom] (ia|itemsadder) block [%customitemtype%]"); - EventValues.registerEventValue(CustomBlockInteractEvent.class, Block.class, new Getter() { + Skript.registerEvent("Custom Block Interact", EvtCustomBlockInteract.class, CustomBlockInteractEvent.class, "interact with [custom] (ia|itemsadder) block[s] [%customitemtypes/strings%]"); + EventValues.registerEventValue(CustomBlockInteractEvent.class, CustomBlock.class, new Getter() { @Override - public Block get(CustomBlockInteractEvent event) { - return event.getBlockClicked(); + public CustomBlock get(CustomBlockInteractEvent event) { + return CustomBlock.byAlreadyPlaced(event.getBlockClicked()); } }, 0); EventValues.registerEventValue(CustomBlockInteractEvent.class, Location.class, new Getter() { @Override - public @Nullable Location get(CustomBlockInteractEvent customBlockInteractEvent) { - return customBlockInteractEvent.getBlockClicked().getLocation(); + public Location get(CustomBlockInteractEvent event) { + return event.getBlockClicked().getLocation(); } }, 0); } - @SuppressWarnings("unchecked") @Override public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseResult parseResult) { - blockName = (Literal) args[0]; + blockNames = args; + if (blockNames != null) { + aliases = Arrays.stream(blockNames) + .map(literal -> { + if (literal instanceof Literal) { + Object value = ((Literal) literal).getSingle(); + if (value instanceof CustomItemType) { + return ((CustomItemType) value).getNamespacedID(); + } else if (value instanceof String) { + return (String) value; + } + } + return null; + }) + .filter(name -> name != null) + .collect(Collectors.toList()); + } return true; } @@ -64,21 +86,10 @@ public boolean check(Event event) { return false; } - // check block - if (blockName != null) { - CustomItemType specifiedBlockType = blockName.getSingle(event); - AliasesGenerator aliasesGenerator = SkriptItemsAdder.getInstance().getAliasesGenerator(); - CustomItemType actualBlockType = EventValues.getEventValue(customEvent, CustomItemType.class, 0); - - if (specifiedBlockType == null || actualBlockType == null) { - return false; - } - - String specifiedBlockName = specifiedBlockType.getNamespacedID(); - String actualBlockName = actualBlockType.getNamespacedID(); - if (actualBlockName == null || actualBlockName.isEmpty() || !actualBlockName.equals(specifiedBlockName)) { - return false; - } + // Check block name + if (aliases != null && !aliases.isEmpty()) { + String actualBlockName = customEvent.getNamespacedID(); + return aliases.contains(aliasesGenerator.getNamespacedId(actualBlockName)); } return true; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockPlace.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockPlace.java index 9ba2d89..6b84886 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockPlace.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockPlace.java @@ -17,10 +17,12 @@ import me.asleepp.SkriptItemsAdder.other.AliasesGenerator; import me.asleepp.SkriptItemsAdder.other.CustomItemType; import org.bukkit.Location; -import org.bukkit.block.Block; import org.bukkit.event.Event; import javax.annotation.Nullable; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; @Name("On Custom Block Place") @Description({"Fires when a ItemsAdder block gets placed."}) @@ -29,11 +31,12 @@ @RequiredPlugins("ItemsAdder") public class EvtCustomBlockPlace extends SkriptEvent { - private Literal blockName; - private boolean isCancelled; + private Literal[] blockNames; + private List aliases; + private AliasesGenerator aliasesGenerator = SkriptItemsAdder.getInstance().getAliasesGenerator(); static { - Skript.registerEvent("Custom Block Place", EvtCustomBlockPlace.class, CustomBlockPlaceEvent.class, "place [of] [custom] (ia|itemsadder) block [%customitemtype%]"); + Skript.registerEvent("Custom Block Place", EvtCustomBlockPlace.class, CustomBlockPlaceEvent.class, "place [of] [custom] (ia|itemsadder) block[s] [%customitemtypes/strings%]"); EventValues.registerEventValue(CustomBlockPlaceEvent.class, CustomBlock.class, new Getter() { @Override public CustomBlock get(CustomBlockPlaceEvent event) { @@ -51,11 +54,26 @@ public Location get(CustomBlockPlaceEvent event) { @SuppressWarnings("unchecked") @Override public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseResult parseResult) { - blockName = (Literal) args[0]; + blockNames = args; + if (blockNames != null) { + aliases = Arrays.stream(blockNames) + .map(literal -> { + if (literal instanceof Literal) { + Object value = ((Literal) literal).getSingle(); + if (value instanceof CustomItemType) { + return ((CustomItemType) value).getNamespacedID(); + } else if (value instanceof String) { + return (String) value; + } + } + return null; + }) + .filter(name -> name != null) + .collect(Collectors.toList()); + } return true; } - @Override public boolean check(Event event) { if (!(event instanceof CustomBlockPlaceEvent)) { @@ -67,28 +85,15 @@ public boolean check(Event event) { return false; } - // check block - if (blockName != null) { - CustomItemType specifiedBlockType = blockName.getSingle(event); - AliasesGenerator aliasesGenerator = SkriptItemsAdder.getInstance().getAliasesGenerator(); - CustomItemType actualBlockType = EventValues.getEventValue(customEvent, CustomItemType.class, 0); - - if (specifiedBlockType == null || actualBlockType == null) { - return false; - } - - String specifiedBlockName = specifiedBlockType.getNamespacedID(); - String actualBlockName = actualBlockType.getNamespacedID(); - if (actualBlockName == null || actualBlockName.isEmpty() || !actualBlockName.equals(specifiedBlockName)) { - return false; - } + // Check block name + if (aliases != null && !aliases.isEmpty()) { + String actualBlockName = customEvent.getNamespacedID(); + return aliases.contains(aliasesGenerator.getNamespacedId(actualBlockName)); } + return true; } - - - @Override public String toString(@Nullable Event e, boolean debug) { return "Custom Block Place event"; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureBreak.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureBreak.java index 9eb0023..a9bca81 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureBreak.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureBreak.java @@ -13,21 +13,30 @@ import ch.njol.skript.util.Getter; import dev.lone.itemsadder.api.CustomFurniture; import dev.lone.itemsadder.api.Events.FurnitureBreakEvent; +import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; +import me.asleepp.SkriptItemsAdder.other.AliasesGenerator; import me.asleepp.SkriptItemsAdder.other.CustomItemType; import org.bukkit.Location; import org.bukkit.event.Event; import javax.annotation.Nullable; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + @Name("On Custom Furniture Break") @Description({"Fires when a ItemsAdder furniture gets broken."}) @Examples({"on break of custom furniture:"}) @Since("1.0") @RequiredPlugins("ItemsAdder") public class EvtCustomFurnitureBreak extends SkriptEvent { - private Literal furnitureID; + + private Literal[] furnitureIDs; + private List aliases; + private AliasesGenerator aliasesGenerator = SkriptItemsAdder.getInstance().getAliasesGenerator(); static { - Skript.registerEvent("Custom Furniture Break", EvtCustomFurnitureBreak.class, FurnitureBreakEvent.class, "break of [custom] (ia|itemsadder) furniture [%customitemtype%]"); + Skript.registerEvent("Custom Furniture Break", EvtCustomFurnitureBreak.class, FurnitureBreakEvent.class, "break of [custom] (ia|itemsadder) furniture [%customitemtypes/strings%]"); EventValues.registerEventValue(FurnitureBreakEvent.class, Location.class, new Getter() { @Override public @Nullable Location get(FurnitureBreakEvent event) { @@ -45,7 +54,23 @@ public class EvtCustomFurnitureBreak extends SkriptEvent { @SuppressWarnings("unchecked") @Override public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseResult parseResult) { - furnitureID = (Literal) args[0]; + furnitureIDs = args; + if (furnitureIDs != null) { + aliases = Arrays.stream(furnitureIDs) + .map(literal -> { + if (literal instanceof Literal) { + Object value = ((Literal) literal).getSingle(); + if (value instanceof CustomItemType) { + return ((CustomItemType) value).getNamespacedID(); + } else if (value instanceof String) { + return (String) value; + } + } + return null; + }) + .filter(name -> name != null) + .collect(Collectors.toList()); + } return true; } @@ -53,20 +78,19 @@ public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseRes public boolean check(Event e) { if (e instanceof FurnitureBreakEvent) { FurnitureBreakEvent event = (FurnitureBreakEvent) e; - if (furnitureID == null) { - return !event.isCancelled(); - } else { - CustomItemType id = furnitureID.getSingle(e); - if (id != null && id.equals(new CustomItemType(event.getNamespacedID()))) { - return !event.isCancelled(); - } + + if (aliases != null && !aliases.isEmpty()) { + String actualFurnitureName = event.getNamespacedID(); + return aliases.contains(aliasesGenerator.getNamespacedId(actualFurnitureName)) && !event.isCancelled(); } + + return !event.isCancelled(); } return false; } @Override public String toString(@Nullable Event e, boolean debug) { - return "ItemsAdder custom furniture " + (furnitureID != null ? furnitureID.toString(e, debug) : "") + " break"; + return "ItemsAdder custom furniture " + (furnitureIDs != null ? furnitureIDs.toString() : "") + " break"; } } diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureInteract.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureInteract.java index 9b161b3..bbd01d9 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureInteract.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureInteract.java @@ -13,22 +13,30 @@ import ch.njol.skript.util.Getter; import dev.lone.itemsadder.api.CustomFurniture; import dev.lone.itemsadder.api.Events.FurnitureInteractEvent; -import dev.lone.itemsadder.api.Events.FurnitureInteractEvent; +import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; +import me.asleepp.SkriptItemsAdder.other.AliasesGenerator; import me.asleepp.SkriptItemsAdder.other.CustomItemType; import org.bukkit.Location; import org.bukkit.event.Event; import javax.annotation.Nullable; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + @Name("On Custom Furniture Interact") @Description({"Fires when a ItemsAdder furniture gets interacted with."}) @Examples({"on interact with custom furniture:"}) @Since("1.0") @RequiredPlugins("ItemsAdder") public class EvtCustomFurnitureInteract extends SkriptEvent { - private Literal furnitureID; + + private Literal[] furnitureIDs; + private List aliases; + private AliasesGenerator aliasesGenerator = SkriptItemsAdder.getInstance().getAliasesGenerator(); static { - Skript.registerEvent("Custom Furniture Interact", EvtCustomFurnitureInteract.class, FurnitureInteractEvent.class, "interact with [custom] (ia|itemsadder) furniture [%customitemtype%]"); + Skript.registerEvent("Custom Furniture Interact", EvtCustomFurnitureInteract.class, FurnitureInteractEvent.class, "interact with [custom] (ia|itemsadder) furniture [%customitemtypes/strings%]"); EventValues.registerEventValue(FurnitureInteractEvent.class, Location.class, new Getter() { @Override public @Nullable Location get(FurnitureInteractEvent event) { @@ -46,7 +54,23 @@ public class EvtCustomFurnitureInteract extends SkriptEvent { @SuppressWarnings("unchecked") @Override public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseResult parseResult) { - furnitureID = (Literal) args[0]; + furnitureIDs = args; + if (furnitureIDs != null) { + aliases = Arrays.stream(furnitureIDs) + .map(literal -> { + if (literal instanceof Literal) { + Object value = ((Literal) literal).getSingle(); + if (value instanceof CustomItemType) { + return ((CustomItemType) value).getNamespacedID(); + } else if (value instanceof String) { + return (String) value; + } + } + return null; + }) + .filter(name -> name != null) + .collect(Collectors.toList()); + } return true; } @@ -54,19 +78,19 @@ public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseRes public boolean check(Event e) { if (e instanceof FurnitureInteractEvent) { FurnitureInteractEvent event = (FurnitureInteractEvent) e; - if (furnitureID == null) { - return !event.isCancelled(); - } else { - CustomItemType id = furnitureID.getSingle(e); - if (id != null && id.equals(new CustomItemType(event.getNamespacedID()))) { - return !event.isCancelled(); - } + + if (aliases != null && !aliases.isEmpty()) { + String actualFurnitureName = event.getNamespacedID(); + return aliases.contains(aliasesGenerator.getNamespacedId(actualFurnitureName)) && !event.isCancelled(); } + + return !event.isCancelled(); } return false; } + @Override public String toString(@Nullable Event e, boolean debug) { - return "ItemsAdder custom furniture " + (furnitureID != null ? furnitureID.toString(e, debug) : "") + " interact"; + return "ItemsAdder custom furniture " + (furnitureIDs != null ? furnitureIDs.toString() : "") + " interact"; } } diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurniturePlace.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurniturePlace.java index e26400e..09d2c2a 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurniturePlace.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurniturePlace.java @@ -1,5 +1,6 @@ package me.asleepp.SkriptItemsAdder.elements.events; +import ch.njol.skript.Skript; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Examples; import ch.njol.skript.doc.Name; @@ -7,13 +8,21 @@ import ch.njol.skript.doc.Since; import ch.njol.skript.lang.Literal; import ch.njol.skript.lang.SkriptEvent; -import ch.njol.skript.Skript; import ch.njol.skript.lang.SkriptParser; +import ch.njol.skript.registrations.EventValues; +import ch.njol.skript.util.Getter; +import dev.lone.itemsadder.api.CustomFurniture; import dev.lone.itemsadder.api.Events.FurniturePlaceEvent; +import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; +import me.asleepp.SkriptItemsAdder.other.AliasesGenerator; import me.asleepp.SkriptItemsAdder.other.CustomItemType; +import org.bukkit.Location; import org.bukkit.event.Event; import javax.annotation.Nullable; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; @Name("On Custom Furniture Place") @Description({"Fires when a ItemsAdder furniture gets placed."}) @@ -21,37 +30,60 @@ @Since("1.0") @RequiredPlugins("ItemsAdder") public class EvtCustomFurniturePlace extends SkriptEvent { - private Literal furnitureID; + + private Literal[] furnitureIDs; + private List aliases; + private AliasesGenerator aliasesGenerator = SkriptItemsAdder.getInstance().getAliasesGenerator(); static { - Skript.registerEvent("Custom Furniture Place", EvtCustomFurniturePlace.class, FurniturePlaceEvent.class, "place of [custom] (ia|itemsadder) furniture [%customitemtype%]"); + Skript.registerEvent("Custom Furniture Place", EvtCustomFurniturePlace.class, FurniturePlaceEvent.class, "place [of] [custom] (ia|itemsadder) furniture [%customitemtypes/strings%]"); } @SuppressWarnings("unchecked") @Override public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseResult parseResult) { - furnitureID = (Literal) args[0]; + furnitureIDs = args; + if (furnitureIDs != null) { + aliases = Arrays.stream(furnitureIDs) + .map(literal -> { + if (literal instanceof Literal) { + Object value = ((Literal) literal).getSingle(); + if (value instanceof CustomItemType) { + return ((CustomItemType) value).getNamespacedID(); + } else if (value instanceof String) { + return (String) value; + } + } + return null; + }) + .filter(name -> name != null) + .collect(Collectors.toList()); + } return true; } @Override - public boolean check(Event e) { - if (e instanceof FurniturePlaceEvent) { - FurniturePlaceEvent event = (FurniturePlaceEvent) e; - if (furnitureID == null) { - return !event.isCancelled(); - } else { - CustomItemType id = furnitureID.getSingle(e); - if (id != null && id.equals(new CustomItemType(event.getNamespacedID()))) { - return !event.isCancelled(); - } - } + public boolean check(Event event) { + if (!(event instanceof FurniturePlaceEvent)) { + return false; + } + + FurniturePlaceEvent customEvent = (FurniturePlaceEvent) event; + if (customEvent.isCancelled()) { + return false; + } + + // Check furniture name + if (aliases != null && !aliases.isEmpty()) { + String actualFurnitureName = customEvent.getNamespacedID(); + return aliases.contains(aliasesGenerator.getNamespacedId(actualFurnitureName)); } - return false; + + return true; } @Override public String toString(@Nullable Event e, boolean debug) { - return "ItemsAdder custom furniture " + (furnitureID != null ? furnitureID.toString(e, debug) : "") + " place"; + return "Custom Furniture Place event"; } } diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureSuccessEvent.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureSuccessEvent.java index 4e09187..7c37080 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureSuccessEvent.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureSuccessEvent.java @@ -13,24 +13,32 @@ import ch.njol.skript.util.Getter; import dev.lone.itemsadder.api.CustomFurniture; import dev.lone.itemsadder.api.Events.FurniturePlaceSuccessEvent; +import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; +import me.asleepp.SkriptItemsAdder.other.AliasesGenerator; import me.asleepp.SkriptItemsAdder.other.CustomItemType; import org.bukkit.Location; import org.bukkit.event.Event; import javax.annotation.Nullable; -@Name("Furniture Place Sucess") -@Description("This event is called when a furniture is succesfully placed into the world, use this event instead if you would like to know the location, etc.") +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +@Name("Furniture Place Success") +@Description("This event is called when a furniture is successfully placed into the world, use this event instead if you would like to know the location, etc.") @Examples({"on place success of custom itemsadder furniture:", "on successfully placing a custom itemsadder furniture:"}) @Since("1.5") @RequiredPlugins("ItemsAdder") public class EvtCustomFurnitureSuccessEvent extends SkriptEvent { - private Literal furnitureID; + private Literal[] furnitureIDs; + private List aliases; + private AliasesGenerator aliasesGenerator = SkriptItemsAdder.getInstance().getAliasesGenerator(); static { Skript.registerEvent("Custom Furniture Success", EvtCustomFurnitureSuccessEvent.class, FurniturePlaceSuccessEvent.class, - "success[fully] plac(e|ing) [a] [custom] (ia|itemsadder) furniture [%customitemtype%]", - "place success [of] [custom] (ia|itemsadder) furniture [%customitemtype%]"); + "success[fully] plac(e|ing) [a] [custom] (ia|itemsadder) furniture [%customitemtypes/strings%]", + "place success [of] [custom] (ia|itemsadder) furniture [%customitemtypes/strings%]"); EventValues.registerEventValue(FurniturePlaceSuccessEvent.class, Location.class, new Getter() { @Override public Location get(FurniturePlaceSuccessEvent arg) { @@ -48,7 +56,23 @@ public Location get(FurniturePlaceSuccessEvent arg) { @SuppressWarnings("unchecked") @Override public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseResult parseResult) { - furnitureID = (Literal) args[0]; + furnitureIDs = args; + if (furnitureIDs != null) { + aliases = Arrays.stream(furnitureIDs) + .map(literal -> { + if (literal instanceof Literal) { + Object value = ((Literal) literal).getSingle(); + if (value instanceof CustomItemType) { + return ((CustomItemType) value).getNamespacedID(); + } else if (value instanceof String) { + return (String) value; + } + } + return null; + }) + .filter(name -> name != null) + .collect(Collectors.toList()); + } return true; } @@ -56,12 +80,12 @@ public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseRes public boolean check(Event e) { if (e instanceof FurniturePlaceSuccessEvent) { FurniturePlaceSuccessEvent event = (FurniturePlaceSuccessEvent) e; - if (furnitureID != null) { - CustomItemType id = furnitureID.getSingle(e); - if (id != null && !id.equals(new CustomItemType(event.getNamespacedID()))) { - return false; - } + + if (furnitureIDs != null && !aliases.isEmpty()) { + String actualFurnitureName = event.getNamespacedID(); + return aliases.contains(aliasesGenerator.getNamespacedId(actualFurnitureName)); } + return true; } return false; @@ -69,6 +93,6 @@ public boolean check(Event e) { @Override public String toString(@Nullable Event e, boolean debug) { - return "Furniture Place Success event" + (furnitureID != null ? " with id " + furnitureID.toString(e, debug) : ""); + return "Furniture Place Success event" + (furnitureIDs != null ? " with id " + Arrays.toString(furnitureIDs) : ""); } } diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetCustomItem.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetCustomItem.java index abdd626..b06303e 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetCustomItem.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetCustomItem.java @@ -15,6 +15,7 @@ import dev.lone.itemsadder.api.CustomStack; import dev.lone.itemsadder.api.ItemsAdder; import me.asleepp.SkriptItemsAdder.other.CustomItemType; +import org.bukkit.Material; import org.bukkit.event.Event; import org.bukkit.inventory.ItemStack; @@ -31,19 +32,28 @@ @RequiredPlugins("ItemsAdder") public class ExprGetCustomItem extends SimpleExpression { - private Expression itemTypes; + private Expression itemTypes; + private Expression itemStacks; + private boolean usesItemMaterial; static { Skript.registerExpression(ExprGetCustomItem.class, ItemType.class, ExpressionType.SIMPLE, - "[custom] (ia|itemsadder) item[s] %customitemtype%", - "(all [[of] the]) [custom] (ia|itemsadder) item[s]"); + "[custom] (ia|itemsadder) item[s] %customitemtypes/strings%", + "(all [[of] the]) [custom] (ia|itemsadder) item[s] [1:(that uses|using) [item[s]|material[s]] %-itemstacks%]"); } @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { - if (matchedPattern == 1) - return true; - itemTypes = (Expression) exprs[0]; + if (matchedPattern == 1) { + usesItemMaterial = parseResult.mark == 1; + if (usesItemMaterial) { + itemStacks = (Expression) exprs[0]; + } else { + itemTypes = (Expression) exprs[0]; + } + } else { + itemTypes = (Expression) exprs[0]; + } return true; } @@ -52,21 +62,29 @@ protected ItemType[] get(Event e) { List items = new ArrayList<>(); if (itemTypes != null) { if (itemTypes.isSingle()) { - CustomItemType itemType = itemTypes.getSingle(e); + Object itemType = itemTypes.getSingle(e); if (itemType != null) { - CustomStack customStack = CustomStack.getInstance(itemType.getNamespacedID()); + CustomStack customStack = getCustomStack(itemType); if (customStack != null) { items.add(new ItemType(customStack.getItemStack())); } } } else { - for (CustomItemType itemType : itemTypes.getArray(e)) { - CustomStack customStack = CustomStack.getInstance(itemType.getNamespacedID()); + for (Object itemType : itemTypes.getArray(e)) { + CustomStack customStack = getCustomStack(itemType); if (customStack != null) { items.add(new ItemType(customStack.getItemStack())); } } } + } else if (itemStacks != null) { + for (ItemStack itemStack : itemStacks.getArray(e)) { + Material material = itemStack.getType(); + List customStacks = ItemsAdder.getAllItems(material); + for (CustomStack customStack : customStacks) { + items.add(new ItemType(customStack.getItemStack())); + } + } } else { List customStacks = ItemsAdder.getAllItems(); for (CustomStack customStack : customStacks) { @@ -76,7 +94,14 @@ protected ItemType[] get(Event e) { return items.toArray(new ItemType[0]); } - + private CustomStack getCustomStack(Object itemType) { + if (itemType instanceof CustomItemType) { + return CustomStack.getInstance(((CustomItemType) itemType).getNamespacedID()); + } else if (itemType instanceof String) { + return CustomStack.getInstance((String) itemType); + } + return null; + } @Override public boolean isSingle() { @@ -90,6 +115,10 @@ public Class getReturnType() { @Override public String toString(@Nullable Event e, boolean debug) { - return "ItemsAdder items " + itemTypes.toString(e, debug); + if (usesItemMaterial) { + return "ItemsAdder items that use item material " + itemStacks.toString(e, debug); + } else { + return "ItemsAdder items " + itemTypes.toString(e, debug); + } } -} \ No newline at end of file +} diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetFontImage.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetFontImage.java index 0e5e5b3..121b518 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetFontImage.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetFontImage.java @@ -20,23 +20,44 @@ import java.util.List; @Name("Get ItemsAdder Font Image") -@Description({"Gets ItemsAdder font image(s)"}) -@Examples({"set {_t::*} to font images \"emojis:laughing_emoji\" and \"emojis:crying_emoji\""}) -@Since("1.0, 1.5 (Multiple Images)") +@Description({"Gets ItemsAdder font image(s) with optional offset"}) +@Examples({"set {_t::*} to font images \"emojis:laughing_emoji\" and \"emojis:crying_emoji\" with x offset 2"}) +@Since("1.0, 1.5 (Multiple Images), 1.6 (With Offset)") @RequiredPlugins("ItemsAdder") public class ExprGetFontImage extends SimpleExpression { private Expression fontImageNames; + private Expression offset; static { - Skript.registerExpression(ExprGetFontImage.class, String.class, ExpressionType.SIMPLE, "[font|custom|ia|itemsadder] image[s] %strings%"); + Skript.registerExpression(ExprGetFontImage.class, String.class, ExpressionType.SIMPLE, "[font|custom|ia|itemsadder] image[s] %strings% [with [x] offset %-integer%]"); } @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { fontImageNames = (Expression) exprs[0]; + offset = (Expression) exprs[1]; return true; } + @Nullable + @Override + protected String[] get(@NotNull Event e) { + if (fontImageNames == null || fontImageNames.getArray(e) == null) { + return null; + } + String[] strArray = fontImageNames.getArray(e); + Integer offsetValue = offset != null ? offset.getSingle(e) : 0; + List fontImages = new ArrayList<>(); + for (String str : strArray) { + FontImageWrapper fontImageWrapper = new FontImageWrapper(str); + if (!fontImageWrapper.exists()) { + continue; + } + fontImages.add(fontImageWrapper.applyPixelsOffset(offsetValue)); + } + return fontImages.toArray(new String[0]); + } + @NotNull @Override public Class getReturnType() { @@ -48,27 +69,9 @@ public boolean isSingle() { return fontImageNames.isSingle(); } - @NotNull @Override public String toString(@Nullable Event e, boolean debug) { - return "font images " + fontImageNames.toString(e, debug); - } - - @Nullable - @Override - protected String[] get(@NotNull Event e) { - if (fontImageNames == null || fontImageNames.getArray(e) == null) { - return null; - } - String[] strArray = fontImageNames.getArray(e); - List fontImages = new ArrayList<>(); - for (String str : strArray) { - FontImageWrapper fontImageWrapper = new FontImageWrapper(str); - if (!fontImageWrapper.exists()) - continue; - fontImages.add(fontImageWrapper.getString()); - } - return fontImages.toArray(new String[0]); + return "font images " + fontImageNames.toString(e, debug) + (offset != null ? " with offset " + offset.toString(e, debug) : ""); } } diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/types/Types.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/types/Types.java index 67ef439..b4d3c8b 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/types/Types.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/types/Types.java @@ -1,26 +1,18 @@ package me.asleepp.SkriptItemsAdder.elements.types; -import ch.njol.skript.classes.Changer; import ch.njol.skript.classes.ClassInfo; import ch.njol.skript.classes.Parser; import ch.njol.skript.classes.Serializer; -import ch.njol.skript.lang.DefaultExpression; -import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.ParseContext; -import ch.njol.skript.lang.SkriptParser; import ch.njol.skript.registrations.Classes; -import ch.njol.util.Checker; -import ch.njol.util.Kleenean; import ch.njol.yggdrasil.Fields; import dev.lone.itemsadder.api.FontImages.TexturedInventoryWrapper; import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; import me.asleepp.SkriptItemsAdder.other.AliasesGenerator; import me.asleepp.SkriptItemsAdder.other.CustomItemType; -import org.bukkit.event.Event; import javax.annotation.Nullable; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; public class Types { @@ -59,7 +51,6 @@ public boolean canBeInstantiated() { return true; } }) - .parser(new Parser() { @Override @Nullable @@ -79,7 +70,6 @@ public String toVariableNameString(CustomItemType customItemType) { return customItemType.getNamespacedID(); } - public String getVariableNamePattern() { return ".+"; } @@ -119,4 +109,3 @@ public String getVariableNamePattern() { })); } } - diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/other/AliasesGenerator.java b/src/main/java/me/asleepp/SkriptItemsAdder/other/AliasesGenerator.java index 45793ef..478eaaf 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/other/AliasesGenerator.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/other/AliasesGenerator.java @@ -1,6 +1,11 @@ package me.asleepp.SkriptItemsAdder.other; +import ch.njol.skript.Skript; +import ch.njol.skript.aliases.Aliases; +import ch.njol.skript.aliases.AliasesProvider; +import ch.njol.skript.aliases.InvalidMinecraftIdException; import dev.lone.itemsadder.api.CustomStack; +import dev.lone.itemsadder.api.FontImages.FontImageWrapper; import dev.lone.itemsadder.api.ItemsAdder; import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; import org.bukkit.configuration.file.FileConfiguration; @@ -8,14 +13,18 @@ import java.io.File; import java.io.IOException; -import java.util.*; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.HashSet; public class AliasesGenerator { private final SkriptItemsAdder plugin; private final File aliasesFile; private FileConfiguration aliasesConfig; - private final Map aliases = new HashMap<>(); + private final Map itemAliases = new HashMap<>(); private final Set generatedAliases = new HashSet<>(); public AliasesGenerator(SkriptItemsAdder plugin) { @@ -34,13 +43,18 @@ public void loadAliasesFile() { } private void loadAliases() { - for (String key : aliasesConfig.getKeys(false)) { - aliases.put(key, aliasesConfig.getString(key)); + if (aliasesConfig.contains("items")) { + for (String key : aliasesConfig.getConfigurationSection("items").getKeys(false)) { + itemAliases.put(key, aliasesConfig.getString(key)); + } } - plugin.getLogger().info("Loaded " + aliases.size() + " aliases from file."); + plugin.getLogger().info("Loaded " + itemAliases.size() + " aliases from file."); } public void saveAliases() { + for (Map.Entry entry : itemAliases.entrySet()) { + aliasesConfig.set("items." + entry.getKey(), entry.getValue()); + } try { aliasesConfig.save(aliasesFile); plugin.getLogger().info("Aliases saved to " + aliasesFile.getPath()); @@ -50,21 +64,20 @@ public void saveAliases() { } } - public String generateAliasesForItem(CustomStack item) { + public String generateAliasForItem(CustomStack item) { String name = item.getId().toLowerCase().replace("_", " "); String namespace = item.getNamespace(); - String existingAlias = getAliasForItem(item); if (existingAlias != null) { return existingAlias; } else { - if (!aliases.containsValue(name)) { + if (!itemAliases.containsValue(name)) { return name; } else { - for (Map.Entry entry : aliases.entrySet()) { - if (entry.getValue().equals(name) && !item.getNamespace().equals(entry.getKey().split(":")[0])) { - return item.getNamespace() + ":" + item.getId().toLowerCase().replace("_", " "); + for (Map.Entry entry : itemAliases.entrySet()) { + if (entry.getValue().equals(name) && !namespace.equals(entry.getKey().split(":")[0])) { + return namespace + ":" + item.getId().toLowerCase().replace("_", " "); } } } @@ -74,12 +87,12 @@ public String generateAliasesForItem(CustomStack item) { do { uniqueAlias = name + "_" + counter; counter++; - } while (aliases.containsValue(uniqueAlias)); + } while (itemAliases.containsValue(uniqueAlias)); return uniqueAlias; } private String getAliasForItem(CustomStack item) { - for (Map.Entry entry : aliases.entrySet()) { + for (Map.Entry entry : itemAliases.entrySet()) { if (entry.getValue().equals(item.getNamespacedID())) { return entry.getKey(); } @@ -89,7 +102,7 @@ private String getAliasForItem(CustomStack item) { public void generateAliasesForNewItems(List newItems) { for (CustomStack item : newItems) { - String alias = generateAliasesForItem(item); + String alias = generateAliasForItem(item); registerAlias(alias, item.getNamespacedID()); } saveAliases(); @@ -102,7 +115,7 @@ public void generateAliasesForAllItems() { for (CustomStack item : allItems) { String existingAlias = getAliasForItem(item); if (existingAlias == null) { - String alias = generateAliasesForItem(item); + String alias = generateAliasForItem(item); plugin.getLogger().info("Generated alias: " + alias + " for item: " + item.getNamespacedID()); registerAlias(alias, item.getNamespacedID()); } @@ -111,19 +124,65 @@ public void generateAliasesForAllItems() { plugin.getLogger().info("Aliases have been generated"); } - public void registerAlias(String alias, String namespacedId) { - aliases.put(alias, namespacedId); + itemAliases.put(alias, namespacedId); aliasesConfig.set(alias, namespacedId); generatedAliases.add(alias); - plugin.getLogger().info("Registered alias: " + alias + " for item: " + namespacedId); + + AliasesProvider addonProvider = Aliases.getAddonProvider(Skript.getAddonInstance()); + AliasesProvider.AliasName aliasName = new AliasesProvider.AliasName(alias, alias, 0); + try { + addonProvider.addAlias(aliasName, namespacedId, null, new HashMap<>()); + plugin.getLogger().info("Registered alias: " + alias + " for item: " + namespacedId + " with AliasesProvider."); + } catch (NullPointerException e) { + plugin.getLogger().severe("Failed to register alias with AliasesProvider: " + e.getMessage()); + } + } + + public void syncAliasesWithProvider() { + AliasesProvider addonProvider = Aliases.getAddonProvider(Skript.getAddonInstance()); + addonProvider.clearAliases(); + + for (Map.Entry entry : itemAliases.entrySet()) { + AliasesProvider.AliasName aliasName = new AliasesProvider.AliasName(entry.getKey(), entry.getKey(), 0); + try { + addonProvider.addAlias(aliasName, entry.getValue(), null, new HashMap<>()); + } catch (InvalidMinecraftIdException e) { + plugin.getLogger().severe("Failed to sync aliases! " + e.getMessage()); + } + } + } + + public void handleAliasChange(String alias, String newNamespacedId) { + itemAliases.put(alias, newNamespacedId); + aliasesConfig.set(alias, newNamespacedId); + saveAliases(); + + syncAliasesWithProvider(); + } + + public void handleItemUnregister(CustomStack item) { + String alias = getAliasForItem(item); + if (alias != null) { + itemAliases.remove(alias); + aliasesConfig.set(alias, null); + saveAliases(); + syncAliasesWithProvider(); + } } public String getNamespacedId(String alias) { - return aliases.getOrDefault(alias, alias); + return itemAliases.getOrDefault(alias, alias); } public Set getGeneratedAliases() { return generatedAliases; } + + public void handleRemovedItems(List removedItems) { + for (CustomStack item : removedItems) { + handleItemUnregister(item); + } + } + } diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/other/ItemsAdderEventListener.java b/src/main/java/me/asleepp/SkriptItemsAdder/other/ItemsAdderEventListener.java index 831d2db..e4f6433 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/other/ItemsAdderEventListener.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/other/ItemsAdderEventListener.java @@ -7,18 +7,19 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import java.util.ArrayList; import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; public class ItemsAdderEventListener implements Listener { private final SkriptItemsAdder plugin; private final AliasesGenerator aliasesGenerator; - private List initialItems; + private List previousItems; - public ItemsAdderEventListener(SkriptItemsAdder plugin, AliasesGenerator aliasesGenerator, List initialItems) { + public ItemsAdderEventListener(SkriptItemsAdder plugin, AliasesGenerator aliasesGenerator) { this.plugin = plugin; this.aliasesGenerator = aliasesGenerator; - this.initialItems = initialItems; + this.previousItems = ItemsAdder.getAllItems(); } @EventHandler @@ -28,23 +29,30 @@ public void onItemsAdderLoadData(ItemsAdderLoadDataEvent event) { List allItems = ItemsAdder.getAllItems(); plugin.getLogger().info("Total items loaded: " + allItems.size()); - if (initialItems == null) { + if (previousItems == null) { + previousItems = allItems; return; } - List newItems = findNewItems(initialItems, allItems); + List newItems = findNewItems(previousItems, allItems); + List removedItems = findRemovedItems(previousItems, allItems); plugin.getLogger().info("New items found: " + newItems.size()); + plugin.getLogger().info("Removed items found: " + removedItems.size()); + aliasesGenerator.generateAliasesForNewItems(newItems); + aliasesGenerator.handleRemovedItems(removedItems); aliasesGenerator.saveAliases(); + + previousItems = allItems; // Update the previous items list } - private List findNewItems(List initialItems, List allItems) { - List newItems = new ArrayList<>(); - for (CustomStack newItem : allItems) { - if (!initialItems.contains(newItem)) { - newItems.add(newItem); - } - } - return newItems; + private List findNewItems(List previousItems, List allItems) { + Set previousItemIds = previousItems.stream().map(CustomStack::getNamespacedID).collect(Collectors.toSet()); + return allItems.stream().filter(item -> !previousItemIds.contains(item.getNamespacedID())).collect(Collectors.toList()); + } + + private List findRemovedItems(List previousItems, List allItems) { + Set currentItemIds = allItems.stream().map(CustomStack::getNamespacedID).collect(Collectors.toSet()); + return previousItems.stream().filter(item -> !currentItemIds.contains(item.getNamespacedID())).collect(Collectors.toList()); } } diff --git a/src/main/resources/lang/english.lang b/src/main/resources/lang/english.lang index 0cad5ca..0f33599 100644 --- a/src/main/resources/lang/english.lang +++ b/src/main/resources/lang/english.lang @@ -1,5 +1,5 @@ version: @version@ types: - customblock: customblock - texturedinventorywrapper: texturedinventorywrapper \ No newline at end of file + texturedinventorywrapper: texturedinventorywrapper + customitemtype: custom item type \ No newline at end of file From 9626d975b54dc906f9e1796b139a8daaa9b2fccf Mon Sep 17 00:00:00 2001 From: Asleepp <119438940+Asleeepp@users.noreply.github.com> Date: Tue, 16 Jul 2024 21:15:06 -0300 Subject: [PATCH 05/10] e --- src/main/java/me/asleepp/SkriptItemsAdder/SkriptItemsAdder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/SkriptItemsAdder.java b/src/main/java/me/asleepp/SkriptItemsAdder/SkriptItemsAdder.java index a5bc129..edf8f39 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/SkriptItemsAdder.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/SkriptItemsAdder.java @@ -77,7 +77,7 @@ public void onEnable() { @Override public void run() { loadInitialItems(); - ItemsAdderEventListener eventListener = new ItemsAdderEventListener(plugin, aliasesGenerator, initialItems); + ItemsAdderEventListener eventListener = new ItemsAdderEventListener(plugin, aliasesGenerator); manager.registerEvents(eventListener, plugin); } }.runTask(this); From 57007e4b9c131b7244b4475e3ed6261b172c3de5 Mon Sep 17 00:00:00 2001 From: Asleepp <119438940+Asleeepp@users.noreply.github.com> Date: Sat, 3 Aug 2024 08:47:46 -0300 Subject: [PATCH 06/10] changes, we're getting there --- build.gradle | 2 +- .../SkriptItemsAdder/SkriptItemsAdder.java | 27 ++-- .../elements/effects/EffPlaceBlockOrCrop.java | 82 +++++++++--- .../other/AliasesGenerator.java | 122 ++++++++---------- .../other/CustomItemType.java | 2 - .../other/ItemsAdderEventListener.java | 44 ++----- .../other/SkriptItemsAdderCommand.java | 68 ++++++++++ .../asleepp/SkriptItemsAdder/other/Util.java | 48 +++++++ src/main/resources/plugin.yml | 6 +- 9 files changed, 256 insertions(+), 145 deletions(-) create mode 100644 src/main/java/me/asleepp/SkriptItemsAdder/other/SkriptItemsAdderCommand.java create mode 100644 src/main/java/me/asleepp/SkriptItemsAdder/other/Util.java diff --git a/build.gradle b/build.gradle index d013351..5e719e2 100644 --- a/build.gradle +++ b/build.gradle @@ -87,7 +87,7 @@ shadowJar { include(dependency('org.bstats:bstats-bukkit')) include(dependency('org.bstats:bstats-base')) } - relocate 'org.bstats', 'me.example.addontutorial.bstats' + relocate 'org.bstats', 'me.asleepp.SkriptItemsAdder.bstats' configurations = [project.configurations.shadow] archiveVersion = project.property("version") minimize() diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/SkriptItemsAdder.java b/src/main/java/me/asleepp/SkriptItemsAdder/SkriptItemsAdder.java index edf8f39..f4c772b 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/SkriptItemsAdder.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/SkriptItemsAdder.java @@ -1,16 +1,12 @@ package me.asleepp.SkriptItemsAdder; import java.io.IOException; -import java.util.ArrayList; import java.util.List; import ch.njol.skript.util.Version; import dev.lone.itemsadder.api.CustomStack; import dev.lone.itemsadder.api.ItemsAdder; -import me.asleepp.SkriptItemsAdder.other.AliasesGenerator; -import me.asleepp.SkriptItemsAdder.other.ItemsAdderEventListener; -import me.asleepp.SkriptItemsAdder.other.Metrics; -import me.asleepp.SkriptItemsAdder.other.UpdateChecker; +import me.asleepp.SkriptItemsAdder.other.*; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; @@ -26,7 +22,6 @@ public class SkriptItemsAdder extends JavaPlugin { private static SkriptAddon addon; private static SkriptItemsAdder instance; private AliasesGenerator aliasesGenerator; - private List initialItems = new ArrayList<>(); @Nullable public static SkriptItemsAdder getInstance() { @@ -39,10 +34,12 @@ public static SkriptAddon getAddonInstance() { } public boolean itemsAdderReady = false; + public boolean loading = true; @Override public void onEnable() { // Let's get this show on the road. + long start = System.currentTimeMillis(); final PluginManager manager = this.getServer().getPluginManager(); final Plugin skript = manager.getPlugin("Skript"); if (skript == null || !skript.isEnabled()) { @@ -50,7 +47,7 @@ public void onEnable() { manager.disablePlugin(this); return; } else if (Skript.getVersion().compareTo(new Version(2, 7, 0)) < 0) { - getLogger().warning("You are running an unsupported version of Skript. Disabling..."); + getLogger().severe("You are running an unsupported version of Skript. Disabling..."); manager.disablePlugin(this); return; } @@ -73,10 +70,8 @@ public void onEnable() { // Pass the aliasesGenerator to the event listener new BukkitRunnable() { - @Override public void run() { - loadInitialItems(); ItemsAdderEventListener eventListener = new ItemsAdderEventListener(plugin, aliasesGenerator); manager.registerEvents(eventListener, plugin); } @@ -89,19 +84,18 @@ public void run() { if (itemsAdderReady) { return; } - - }, 0, 20); int pluginId = 20971; Metrics metrics = new Metrics(this, pluginId); metrics.addCustomChart(new Metrics.SimplePie("skript_version", () -> Skript.getVersion().toString())); + metrics.addCustomChart(new Metrics.SimplePie("itemsadder_version", () -> Util.getPluginVersion("ItemsAdder"))); instance = this; addon = Skript.registerAddon(this); addon.setLanguageFileDirectory("lang"); + new SkriptItemsAdderCommand(this); saveDefaultConfig(); - aliasesGenerator.loadAliasesFile(); if (getConfig().getBoolean("check-for-updates", true)) new UpdateChecker(this); @@ -113,7 +107,9 @@ public void run() { manager.disablePlugin(this); return; } - getLogger().info("Loaded!"); + long finish = System.currentTimeMillis() - start; + getLogger().info("Succesfully loaded skript-itemsadder in " + finish + "ms!"); + loading = false; } @Override @@ -129,9 +125,4 @@ public AliasesGenerator getAliasesGenerator() { return aliasesGenerator; } - private void loadInitialItems() { - initialItems = ItemsAdder.getAllItems(); - getLogger().info("Loaded " + initialItems.size() + " aliases."); - } - } diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlaceBlockOrCrop.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlaceBlockOrCrop.java index 6896275..5b976a7 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlaceBlockOrCrop.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlaceBlockOrCrop.java @@ -8,11 +8,14 @@ import ch.njol.skript.doc.Since; import ch.njol.skript.lang.Effect; import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.Literal; import ch.njol.skript.lang.SkriptParser; import ch.njol.skript.util.Direction; import ch.njol.util.Kleenean; import dev.lone.itemsadder.api.CustomBlock; import dev.lone.itemsadder.api.CustomCrop; +import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; +import me.asleepp.SkriptItemsAdder.other.AliasesGenerator; import me.asleepp.SkriptItemsAdder.other.CustomItemType; import org.bukkit.Location; import org.bukkit.event.Event; @@ -20,6 +23,7 @@ import javax.annotation.Nullable; import java.util.Arrays; import java.util.List; +import java.util.stream.Collectors; @Name("Place Custom Block/Crop") @Description({"Places a custom block or crop at a location."}) @@ -30,60 +34,96 @@ @RequiredPlugins("ItemsAdder") public class EffPlaceBlockOrCrop extends Effect { private Expression locations; - private Expression customBlockIdExpr; + private Expression blockNames; + private List aliases; private boolean isCrop; + private AliasesGenerator aliasesGenerator = SkriptItemsAdder.getInstance().getAliasesGenerator(); static { - Skript.registerEffect(EffPlaceBlockOrCrop.class, "(set|place) [custom] (ia|itemsadder) (block|:crop) %customitemtypes/strings% [%directions% %locations%]"); + Skript.registerEffect(EffPlaceBlockOrCrop.class, + "(set|place) [custom] (ia|itemsadder) (block|:crop) %customitemtypes/strings% [%directions% %locations%]", + "set block at [%directions% %locations%] to [custom] (ia|itemsadder) (block|:crop) %customitemtypes/strings%"); } @Override - public boolean init(Expression[] expressions, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { - customBlockIdExpr = (Expression) expressions[0]; - locations = Direction.combine((Expression) expressions[1], (Expression) expressions[2]); - if (parseResult.regexes.size() > 0 && parseResult.regexes.get(0).group().equals("crop")) + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { + if (matchedPattern == 0) { + blockNames = exprs[0]; + locations = Direction.combine((Expression) exprs[1], (Expression) exprs[2]); + } else { + blockNames = exprs[2]; + locations = Direction.combine((Expression) exprs[0], (Expression) exprs[1]); + } + if (blockNames != null) { + aliases = Arrays.stream(blockNames.getArray(null)) + .map(obj -> { + if (obj instanceof CustomItemType) { + return ((CustomItemType) obj).getNamespacedID(); + } else if (obj instanceof String) { + return (String) obj; + } + return null; + }) + .filter(name -> name != null) + .collect(Collectors.toList()); + } + if (parseResult.hasTag("crop")) isCrop = true; return true; } @Override protected void execute(Event e) { - List customBlockIds = Arrays.asList(customBlockIdExpr.getArray(e)); - - if (locations == null || customBlockIds.isEmpty()) { + if (locations == null || aliases == null || aliases.isEmpty()) { return; } + for (Location location : locations.getArray(e)) { - for (Object customBlockIdObj : customBlockIds) { - String customBlockId; - if (customBlockIdObj instanceof CustomItemType) { - customBlockId = ((CustomItemType) customBlockIdObj).getNamespacedID(); - } else if (customBlockIdObj instanceof String) { - customBlockId = (String) customBlockIdObj; - } else { + for (String alias : aliases) { + String customBlockId = aliasesGenerator.getNamespacedId(alias); + + if (customBlockId == null) { + Skript.error("Invalid custom block ID: " + alias); continue; } try { if (isCrop) { + // attempt to place a crop + try { + CustomCrop.place(customBlockId, location); + } catch (Exception ex) { + Skript.error("The ID " + customBlockId + " does not correspond to a valid crop."); + continue; + } + CustomCrop existingCrop = CustomCrop.byAlreadyPlaced(location.getBlock()); if (existingCrop == null) { - CustomCrop crop = CustomCrop.place(customBlockId, location); + CustomCrop.place(customBlockId, location); } else { Skript.error("There is already a crop here!"); } } else { + // ensure it corresponds to a block + if (CustomBlock.getInstance(customBlockId) == null) { + Skript.error("The ID " + customBlockId + " does not correspond to a valid block."); + continue; + } + CustomBlock existingBlock = CustomBlock.byAlreadyPlaced(location.getBlock()); + if (existingBlock != null) { + existingBlock.remove(); + } CustomBlock block = CustomBlock.getInstance(customBlockId); if (block != null) { - if (existingBlock == null) { - existingBlock.remove(); - } block.place(location); + } else { + Skript.error("Failed to get CustomBlock instance for ID: " + customBlockId); } } } catch (Exception ex) { + Skript.error("An error occurred while placing custom block/crop: " + ex.getMessage()); ex.printStackTrace(); } } @@ -92,7 +132,7 @@ protected void execute(Event e) { @Override public String toString(@Nullable Event e, boolean debug) { - String itemTypeString = customBlockIdExpr.toString(e, debug); + String itemTypeString = blockNames.toString(e, debug); String type = isCrop ? "crop" : "block"; return "place custom " + type + " " + itemTypeString + " at " + locations.toString(e, debug); } diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/other/AliasesGenerator.java b/src/main/java/me/asleepp/SkriptItemsAdder/other/AliasesGenerator.java index 478eaaf..feda189 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/other/AliasesGenerator.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/other/AliasesGenerator.java @@ -5,7 +5,6 @@ import ch.njol.skript.aliases.AliasesProvider; import ch.njol.skript.aliases.InvalidMinecraftIdException; import dev.lone.itemsadder.api.CustomStack; -import dev.lone.itemsadder.api.FontImages.FontImageWrapper; import dev.lone.itemsadder.api.ItemsAdder; import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; import org.bukkit.configuration.file.FileConfiguration; @@ -13,11 +12,7 @@ import java.io.File; import java.io.IOException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.HashSet; +import java.util.*; public class AliasesGenerator { @@ -31,7 +26,7 @@ public AliasesGenerator(SkriptItemsAdder plugin) { this.plugin = plugin; this.aliasesFile = new File(plugin.getDataFolder(), "aliases.yml"); loadAliasesFile(); - loadAliases(); + loadAliasesFromFile(); } public void loadAliasesFile() { @@ -42,16 +37,16 @@ public void loadAliasesFile() { aliasesConfig = YamlConfiguration.loadConfiguration(aliasesFile); } - private void loadAliases() { + private void loadAliasesFromFile() { if (aliasesConfig.contains("items")) { for (String key : aliasesConfig.getConfigurationSection("items").getKeys(false)) { - itemAliases.put(key, aliasesConfig.getString(key)); + itemAliases.put(key, aliasesConfig.getString("items." + key)); } } plugin.getLogger().info("Loaded " + itemAliases.size() + " aliases from file."); } - public void saveAliases() { + private void saveAliasesToFile() { for (Map.Entry entry : itemAliases.entrySet()) { aliasesConfig.set("items." + entry.getKey(), entry.getValue()); } @@ -64,40 +59,38 @@ public void saveAliases() { } } - public String generateAliasForItem(CustomStack item) { - String name = item.getId().toLowerCase().replace("_", " "); - String namespace = item.getNamespace(); - - String existingAlias = getAliasForItem(item); - if (existingAlias != null) { - return existingAlias; - } else { - if (!itemAliases.containsValue(name)) { - return name; - } else { - for (Map.Entry entry : itemAliases.entrySet()) { - if (entry.getValue().equals(name) && !namespace.equals(entry.getKey().split(":")[0])) { - return namespace + ":" + item.getId().toLowerCase().replace("_", " "); - } - } - } - } + private String generateUniqueAlias(String baseAlias) { + String uniqueAlias = baseAlias; int counter = 1; - String uniqueAlias; - do { - uniqueAlias = name + "_" + counter; + while (itemAliases.containsKey(uniqueAlias)) { + uniqueAlias = baseAlias + "_" + counter; counter++; - } while (itemAliases.containsValue(uniqueAlias)); + } return uniqueAlias; } - private String getAliasForItem(CustomStack item) { - for (Map.Entry entry : itemAliases.entrySet()) { - if (entry.getValue().equals(item.getNamespacedID())) { - return entry.getKey(); - } + private String generateAliasForItem(CustomStack item) { + String baseAlias = item.getId().toLowerCase().replace("_", " "); + if (itemAliases.containsValue(baseAlias)) { + return generateUniqueAlias(baseAlias); + } + return baseAlias; + } + + private void registerAlias(String alias, String namespacedId) { + itemAliases.put(alias, namespacedId); + generatedAliases.add(alias); + + AliasesProvider addonProvider = Aliases.getAddonProvider(Skript.getAddonInstance()); + AliasesProvider.AliasName aliasName = new AliasesProvider.AliasName(alias, alias, 0); + try { + addonProvider.addAlias(aliasName, namespacedId, null, new HashMap<>()); + plugin.getLogger().info("Registered alias: " + alias + " for item: " + namespacedId + " with AliasesProvider."); + } catch (InvalidMinecraftIdException e) { + plugin.getLogger().severe("Invalid Minecraft ID: " + namespacedId); + } catch (NullPointerException e) { + plugin.getLogger().severe("Failed to register alias with AliasesProvider: " + e.getMessage()); } - return null; } public void generateAliasesForNewItems(List newItems) { @@ -105,7 +98,7 @@ public void generateAliasesForNewItems(List newItems) { String alias = generateAliasForItem(item); registerAlias(alias, item.getNamespacedID()); } - saveAliases(); + saveAliasesToFile(); } public void generateAliasesForAllItems() { @@ -113,32 +106,16 @@ public void generateAliasesForAllItems() { List allItems = ItemsAdder.getAllItems(); plugin.getLogger().info("Total items: " + allItems.size()); for (CustomStack item : allItems) { - String existingAlias = getAliasForItem(item); - if (existingAlias == null) { + if (!itemAliases.containsValue(item.getNamespacedID())) { String alias = generateAliasForItem(item); plugin.getLogger().info("Generated alias: " + alias + " for item: " + item.getNamespacedID()); registerAlias(alias, item.getNamespacedID()); } } - saveAliases(); + saveAliasesToFile(); plugin.getLogger().info("Aliases have been generated"); } - public void registerAlias(String alias, String namespacedId) { - itemAliases.put(alias, namespacedId); - aliasesConfig.set(alias, namespacedId); - generatedAliases.add(alias); - - AliasesProvider addonProvider = Aliases.getAddonProvider(Skript.getAddonInstance()); - AliasesProvider.AliasName aliasName = new AliasesProvider.AliasName(alias, alias, 0); - try { - addonProvider.addAlias(aliasName, namespacedId, null, new HashMap<>()); - plugin.getLogger().info("Registered alias: " + alias + " for item: " + namespacedId + " with AliasesProvider."); - } catch (NullPointerException e) { - plugin.getLogger().severe("Failed to register alias with AliasesProvider: " + e.getMessage()); - } - } - public void syncAliasesWithProvider() { AliasesProvider addonProvider = Aliases.getAddonProvider(Skript.getAddonInstance()); addonProvider.clearAliases(); @@ -155,9 +132,8 @@ public void syncAliasesWithProvider() { public void handleAliasChange(String alias, String newNamespacedId) { itemAliases.put(alias, newNamespacedId); - aliasesConfig.set(alias, newNamespacedId); - saveAliases(); - + aliasesConfig.set("items." + alias, newNamespacedId); + saveAliasesToFile(); syncAliasesWithProvider(); } @@ -165,12 +141,27 @@ public void handleItemUnregister(CustomStack item) { String alias = getAliasForItem(item); if (alias != null) { itemAliases.remove(alias); - aliasesConfig.set(alias, null); - saveAliases(); + aliasesConfig.set("items." + alias, null); + saveAliasesToFile(); syncAliasesWithProvider(); } } + private String getAliasForItem(CustomStack item) { + for (Map.Entry entry : itemAliases.entrySet()) { + if (entry.getValue().equals(item.getNamespacedID())) { + return entry.getKey(); + } + } + return null; + } + + public void handleRemovedItems(List removedItems) { + for (CustomStack item : removedItems) { + handleItemUnregister(item); + } + } + public String getNamespacedId(String alias) { return itemAliases.getOrDefault(alias, alias); } @@ -179,10 +170,7 @@ public Set getGeneratedAliases() { return generatedAliases; } - public void handleRemovedItems(List removedItems) { - for (CustomStack item : removedItems) { - handleItemUnregister(item); - } + public void saveAliases() { + saveAliasesToFile(); } - } diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/other/CustomItemType.java b/src/main/java/me/asleepp/SkriptItemsAdder/other/CustomItemType.java index 25bdf3d..5c930aa 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/other/CustomItemType.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/other/CustomItemType.java @@ -46,6 +46,4 @@ public static CustomItemType fromEvent(Event event, AliasesGenerator aliasesGene return alias != null ? new CustomItemType(alias) : null; } - - } diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/other/ItemsAdderEventListener.java b/src/main/java/me/asleepp/SkriptItemsAdder/other/ItemsAdderEventListener.java index e4f6433..d0d7e64 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/other/ItemsAdderEventListener.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/other/ItemsAdderEventListener.java @@ -2,57 +2,31 @@ import dev.lone.itemsadder.api.CustomStack; import dev.lone.itemsadder.api.Events.ItemsAdderLoadDataEvent; -import dev.lone.itemsadder.api.ItemsAdder; import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; +import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - public class ItemsAdderEventListener implements Listener { private final SkriptItemsAdder plugin; private final AliasesGenerator aliasesGenerator; - private List previousItems; public ItemsAdderEventListener(SkriptItemsAdder plugin, AliasesGenerator aliasesGenerator) { this.plugin = plugin; this.aliasesGenerator = aliasesGenerator; - this.previousItems = ItemsAdder.getAllItems(); } @EventHandler public void onItemsAdderLoadData(ItemsAdderLoadDataEvent event) { - plugin.getLogger().info("ItemsAdder fully loaded, enabling skript-itemsadder."); - plugin.setItemsAdderReady(true); - List allItems = ItemsAdder.getAllItems(); - plugin.getLogger().info("Total items loaded: " + allItems.size()); - - if (previousItems == null) { - previousItems = allItems; - return; + if (plugin.loading) { + plugin.getLogger().info("ItemsAdder fully loaded, enabling skript-itemsadder."); + plugin.setItemsAdderReady(true); } - List newItems = findNewItems(previousItems, allItems); - List removedItems = findRemovedItems(previousItems, allItems); - plugin.getLogger().info("New items found: " + newItems.size()); - plugin.getLogger().info("Removed items found: " + removedItems.size()); - - aliasesGenerator.generateAliasesForNewItems(newItems); - aliasesGenerator.handleRemovedItems(removedItems); - aliasesGenerator.saveAliases(); - - previousItems = allItems; // Update the previous items list - } - - private List findNewItems(List previousItems, List allItems) { - Set previousItemIds = previousItems.stream().map(CustomStack::getNamespacedID).collect(Collectors.toSet()); - return allItems.stream().filter(item -> !previousItemIds.contains(item.getNamespacedID())).collect(Collectors.toList()); - } - - private List findRemovedItems(List previousItems, List allItems) { - Set currentItemIds = allItems.stream().map(CustomStack::getNamespacedID).collect(Collectors.toSet()); - return previousItems.stream().filter(item -> !currentItemIds.contains(item.getNamespacedID())).collect(Collectors.toList()); + // run alias generation async + Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { + aliasesGenerator.generateAliasesForAllItems(); + aliasesGenerator.saveAliases(); + }); } } diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/other/SkriptItemsAdderCommand.java b/src/main/java/me/asleepp/SkriptItemsAdder/other/SkriptItemsAdderCommand.java new file mode 100644 index 0000000..a190fea --- /dev/null +++ b/src/main/java/me/asleepp/SkriptItemsAdder/other/SkriptItemsAdderCommand.java @@ -0,0 +1,68 @@ +package me.asleepp.SkriptItemsAdder.other; + +import ch.njol.skript.Skript; +import dev.lone.itemsadder.api.ItemsAdder; +import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public class SkriptItemsAdderCommand implements CommandExecutor, TabCompleter { + + private SkriptItemsAdder skriptItemsAdder = SkriptItemsAdder.getInstance(); + private final AliasesGenerator aliasesGenerator = new AliasesGenerator(skriptItemsAdder); + + public SkriptItemsAdderCommand(SkriptItemsAdder plugin) { + this.skriptItemsAdder = plugin; + plugin.getCommand("skriptitemsadder").setExecutor(this); + plugin.getCommand("skriptitemsadder").setTabCompleter(this); + } + + @Override + public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String[] args) { + if (args.length == 0) { + Util.sendMiniMessage(sender, true,"Please provide an argument!"); + return false; + } + + if (args[0].equalsIgnoreCase("reload")) { + skriptItemsAdder.reloadConfig(); + Util.sendMiniMessage(sender, true, "Successfully reloaded config."); + return true; + } + + if (args[0].equalsIgnoreCase("info")) { + Util.sendMiniMessage(sender, ""); + Util.sendMiniMessage(sender, "-----------= INFO =-----------"); + Util.sendMiniMessage(sender, ""); + Util.sendMiniMessage(sender, "➥ Total Items registered with ItemsAdder: " + ItemsAdder.getAllItems().size()); + Util.sendMiniMessage(sender, "➥ Total aliases registered with skript-itemsadder: " + aliasesGenerator.getGeneratedAliases().size()); + Util.sendMiniMessage(sender, "➥ Update Checker: " + skriptItemsAdder.getConfig().getString("check-for-updates")); + Util.sendMiniMessage(sender, ""); + Util.sendMiniMessage(sender, "-----------= MISC =-----------"); + Util.sendMiniMessage(sender, ""); + Util.sendMiniMessage(sender, "➥ Server Version: " + Bukkit.getVersion()); + Util.sendMiniMessage(sender, "➥ ItemsAdder Version: " + Util.getPluginVersion("ItemsAdder")); + Util.sendMiniMessage(sender, "➥ LoneLibs Version: " + Util.getPluginVersion("LoneLibs")); + Util.sendMiniMessage(sender, "➥ ProtocolLib Version: " + Util.getPluginVersion("ProtocolLib")); + Util.sendMiniMessage(sender, "➥ Skript Version: " + Skript.getVersion()); + Util.sendMiniMessage(sender, ""); + Util.sendMiniMessage(sender, "➥ If you find any issues with skript-itemsadder, please report it to the GitHub: CLICK ME"); + Util.sendMiniMessage(sender, "➥ Made with ♥ by Asleepp"); + Util.sendMiniMessage(sender, ""); + return true; + } + return true; + } + + @Override + public @Nullable List onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) { + return List.of("reload", "info"); + } +} diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/other/Util.java b/src/main/java/me/asleepp/SkriptItemsAdder/other/Util.java new file mode 100644 index 0000000..4c5f306 --- /dev/null +++ b/src/main/java/me/asleepp/SkriptItemsAdder/other/Util.java @@ -0,0 +1,48 @@ +package me.asleepp.SkriptItemsAdder.other; + +import net.kyori.adventure.text.minimessage.MiniMessage; +import org.bukkit.Bukkit; +import org.bukkit.plugin.Plugin; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Util { + + private static final String prefix = "skript-itemsadder ➜"; + + public static void sendMiniMessage(Player player, String message) { + player.sendMessage(MiniMessage.miniMessage().deserialize(message)); + } + + public static void sendMiniMessage(Player player, boolean usePrefix, String message) { + String fullMessage = usePrefix ? prefix + " " + message : message; + player.sendMessage(MiniMessage.miniMessage().deserialize(fullMessage)); + } + + public static void sendMiniMessage(CommandSender sender, String message) { + if (sender instanceof Player) { + sendMiniMessage((Player) sender, message); + } else { + sender.sendMessage(MiniMessage.miniMessage().deserialize(message)); + } + } + + public static void sendMiniMessage(CommandSender sender, boolean usePrefix, String message) { + String fullMessage = usePrefix ? prefix + " " + message : message; + if (sender instanceof Player) { + sendMiniMessage((Player) sender, fullMessage); + } else { + sender.sendMessage(MiniMessage.miniMessage().deserialize(fullMessage)); + } + } + + public static String getPluginVersion(String pluginName) { + Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginName); + if (plugin != null) { + return plugin.getPluginMeta().getVersion(); + } else { + return "Unknown"; + } + } + +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 395942a..1916311 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -4,4 +4,8 @@ description: A Skript Addon that adds useful syntax to be used in conjunction wi api-version: 1.13 version: 1.5 main: me.asleepp.SkriptItemsAdder.SkriptItemsAdder -depend: [Skript, ItemsAdder] \ No newline at end of file +depend: [Skript, ItemsAdder] + +commands: + skriptitemsadder: + description: Reload the plugin's config or see information \ No newline at end of file From 107c5d2544f47c8d353f78d30fe1a4ff5bfa8d9b Mon Sep 17 00:00:00 2001 From: Asleepp <119438940+Asleeepp@users.noreply.github.com> Date: Sat, 10 Aug 2024 15:37:06 -0300 Subject: [PATCH 07/10] Organization + new build.gradle.kts --- build.gradle | 94 -------------- build.gradle.kts | 110 +++++++++++++++++ gradle.properties | 3 + gradle/libs.versions.toml | 17 +++ settings.gradle | 1 - settings.gradle.kts | 12 ++ .../SkriptItemsAdder/SkriptItemsAdder.java | 13 +- .../conditions/CondIsCustomBlock.java | 2 +- .../elements/conditions/CondIsCustomItem.java | 2 +- .../{ => blocks}/EffPlaceBlockOrCrop.java | 21 ++-- .../effects/{ => blocks}/EffReplaceBlock.java | 2 +- .../{ => blocks}/EffSetBlocksBetween.java | 6 +- .../EffPlaceCustomFurniture.java | 2 +- .../EffRemoveCustomFurniture.java | 3 +- .../EffReplaceCustomFurniture.java | 2 +- .../{ => blocks}/EvtCustomBlockBreak.java | 6 +- .../{ => blocks}/EvtCustomBlockInteract.java | 6 +- .../{ => blocks}/EvtCustomBlockPlace.java | 6 +- .../EvtCustomFurnitureBreak.java | 6 +- .../EvtCustomFurnitureInteract.java | 6 +- .../EvtCustomFurniturePlace.java | 10 +- .../EvtCustomFurnitureSuccessEvent.java | 6 +- .../{ => other}/EvtCustomEntityDeath.java | 2 +- .../elements/events/{ => other}/EvtEmote.java | 2 +- .../{ => other}/EvtResourcePackSendEvent.java | 2 +- .../expressions/ExprGetCustomItem.java | 4 +- .../elements/types/Types.java | 4 +- .../other/{ => aliases}/AliasesGenerator.java | 116 +++++++++--------- .../other/{ => aliases}/CustomItemType.java | 2 +- .../ItemsAdderEventListener.java | 4 +- .../other/{ => util}/Metrics.java | 2 +- .../{ => util}/SkriptItemsAdderCommand.java | 69 +++++++++-- .../other/{ => util}/UpdateChecker.java | 2 +- .../other/{ => util}/Util.java | 2 +- src/main/resources/plugin.yml | 3 +- 35 files changed, 318 insertions(+), 232 deletions(-) delete mode 100644 build.gradle create mode 100644 build.gradle.kts create mode 100644 gradle/libs.versions.toml delete mode 100644 settings.gradle create mode 100644 settings.gradle.kts rename src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/{ => blocks}/EffPlaceBlockOrCrop.java (88%) rename src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/{ => blocks}/EffReplaceBlock.java (96%) rename src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/{ => blocks}/EffSetBlocksBetween.java (95%) rename src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/{ => furniture}/EffPlaceCustomFurniture.java (97%) rename src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/{ => furniture}/EffRemoveCustomFurniture.java (95%) rename src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/{ => furniture}/EffReplaceCustomFurniture.java (97%) rename src/main/java/me/asleepp/SkriptItemsAdder/elements/events/{ => blocks}/EvtCustomBlockBreak.java (95%) rename src/main/java/me/asleepp/SkriptItemsAdder/elements/events/{ => blocks}/EvtCustomBlockInteract.java (95%) rename src/main/java/me/asleepp/SkriptItemsAdder/elements/events/{ => blocks}/EvtCustomBlockPlace.java (95%) rename src/main/java/me/asleepp/SkriptItemsAdder/elements/events/{ => furniture}/EvtCustomFurnitureBreak.java (94%) rename src/main/java/me/asleepp/SkriptItemsAdder/elements/events/{ => furniture}/EvtCustomFurnitureInteract.java (95%) rename src/main/java/me/asleepp/SkriptItemsAdder/elements/events/{ => furniture}/EvtCustomFurniturePlace.java (89%) rename src/main/java/me/asleepp/SkriptItemsAdder/elements/events/{ => furniture}/EvtCustomFurnitureSuccessEvent.java (95%) rename src/main/java/me/asleepp/SkriptItemsAdder/elements/events/{ => other}/EvtCustomEntityDeath.java (97%) rename src/main/java/me/asleepp/SkriptItemsAdder/elements/events/{ => other}/EvtEmote.java (97%) rename src/main/java/me/asleepp/SkriptItemsAdder/elements/events/{ => other}/EvtResourcePackSendEvent.java (96%) rename src/main/java/me/asleepp/SkriptItemsAdder/other/{ => aliases}/AliasesGenerator.java (61%) rename src/main/java/me/asleepp/SkriptItemsAdder/other/{ => aliases}/CustomItemType.java (95%) rename src/main/java/me/asleepp/SkriptItemsAdder/other/{ => listeners}/ItemsAdderEventListener.java (89%) rename src/main/java/me/asleepp/SkriptItemsAdder/other/{ => util}/Metrics.java (99%) rename src/main/java/me/asleepp/SkriptItemsAdder/other/{ => util}/SkriptItemsAdderCommand.java (52%) rename src/main/java/me/asleepp/SkriptItemsAdder/other/{ => util}/UpdateChecker.java (98%) rename src/main/java/me/asleepp/SkriptItemsAdder/other/{ => util}/Util.java (97%) diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 5e719e2..0000000 --- a/build.gradle +++ /dev/null @@ -1,94 +0,0 @@ -import org.apache.tools.ant.filters.ReplaceTokens - -plugins { - id 'com.github.johnrengelman.shadow' version '8.1.1' - id 'eclipse' - id 'java' -} - -compileJava.options.encoding = 'Cp1252' -compileTestJava.options.encoding = 'Cp1252' - -compileJava { - sourceCompatibility = '1.17' - targetCompatibility = '1.17' -} - -group = 'me.Asleepp' -version = '1.5' - -repositories { - mavenCentral() - maven { - name = "papermc-repo" - url = "https://repo.papermc.io/repository/maven-public/" - } - maven { - name = "sonatype" - url = "https://oss.sonatype.org/content/groups/public/" - } - // Skript - maven { - name = "Skript" - url = 'https://repo.skriptlang.org/releases' - } - // ItemsAdder - maven { - name = "ItemsAdder" - url = 'https://jitpack.io' - - } -} - -dependencies { - compileOnly "io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT" - compileOnly (group: 'com.github.SkriptLang', name: 'Skript', version: '2.7.1') { - transitive = false - } - compileOnly 'com.github.LoneDev6:API-ItemsAdder:3.6.1' - -} - -def targetJavaVersion = 17 -java { - def javaVersion = JavaVersion.toVersion(targetJavaVersion) - sourceCompatibility = javaVersion - targetCompatibility = javaVersion - if (JavaVersion.current() < javaVersion) { - toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion) - } -} - -tasks.withType(JavaCompile).configureEach { - options.encoding = 'UTF-8' - - if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) { - options.release.set(targetJavaVersion) - } -} - -build { - dependsOn(shadowJar) - tasks.withType(JavaCompile).tap { - configureEach { - options.compilerArgs.add("-Xlint:unchecked") - options.compilerArgs.add("-Xlint:deprecation") - } - } -} - -processResources { - filter ReplaceTokens, tokens: ["version": project.version] - } - - -shadowJar { - dependencies { - include(dependency('org.bstats:bstats-bukkit')) - include(dependency('org.bstats:bstats-base')) - } - relocate 'org.bstats', 'me.asleepp.SkriptItemsAdder.bstats' - configurations = [project.configurations.shadow] - archiveVersion = project.property("version") - minimize() -} diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..0f1f909 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,110 @@ +import org.apache.tools.ant.filters.ReplaceTokens + +plugins { + `java-library` + `maven-publish` + alias(libs.plugins.shadow) + alias(libs.plugins.run.paper) +} + +repositories { + mavenLocal() + mavenCentral() + maven("https://repo.papermc.io/repository/maven-public/") + maven("https://repo.skriptlang.org/releases") + maven("https://jitpack.io") +} + +java { + disableAutoTargetJvm() + toolchain.languageVersion = JavaLanguageVersion.of(21) +} + +description = "A skript addon that aims to bring more to linking ItemsAdder and Skript" +group = "me.Asleepp" +version = "1.6" + +dependencies { + compileOnly(libs.paper.api) + compileOnly(libs.lombok) + compileOnly(libs.itemsadder) + compileOnly(libs.skript) + annotationProcessor(libs.lombok) +} + + +tasks { + jar { + enabled = false + } + + shadowJar { + archiveFileName = "${rootProject.name}-${project.version}.jar" + archiveClassifier = null + + manifest { + attributes["Implementation-Version"] = rootProject.version + } + + relocate("org.bstats", "me.asleepp.SkriptItemsAdder.bstats") + configurations = listOf(project.configurations.shadow.get()) + minimize() + } + + assemble { + dependsOn(shadowJar) + } + + withType { + options.encoding = Charsets.UTF_8.name() + options.release = 17 + } + + withType() { + options.encoding = Charsets.UTF_8.name() + } + + processResources { + filter("tokens" to mapOf("version" to project.version)) + inputs.property("version", project.version) + + filesMatching("plugin.yml") { + expand( + "version" to rootProject.version, + ) + } + } + + defaultTasks("build") + + // 1.8.8 - 1.16.5 = Java 8 + // 1.17 = Java 16 + // 1.18 - 1.20.4 = Java 17 + // 1-20.5+ = Java 21 + val version = "1.20.4" + val javaVersion = JavaLanguageVersion.of(17) + + val jvmArgsExternal = listOf( + "-Dcom.mojang.eula.agree=true" + ) + + runServer { + minecraftVersion(version) + runDirectory = rootDir.resolve("run/paper/$version") + + javaLauncher = project.javaToolchains.launcherFor { + languageVersion = javaVersion + } + + downloadPlugins { + url("https://download.luckperms.net/1552/bukkit/loader/LuckPerms-Bukkit-5.4.137.jar") + url("https://ci.lucko.me/job/spark/439/artifact/spark-bukkit/build/libs/spark-1.10.93-bukkit.jar") + url("https://github.com/SkriptLang/Skript/releases/download/2.9.1/Skript-2.9.1.jar") + url("https://github.com/dmulloy2/ProtocolLib/releases/download/5.2.0/ProtocolLib.jar") + url("https://github.com/LoneDev6/SpigotUtilities/raw/master/LoneLibs.jar") + } + + jvmArgs = jvmArgsExternal + } +} + diff --git a/gradle.properties b/gradle.properties index e69de29..bb3a36b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -0,0 +1,3 @@ +org.gradle.parallel=true +org.gradle.caching=true +org.gradle.daemon=true \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 0000000..61d5177 --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,17 @@ +[versions] +paper-api = "1.21-R0.1-SNAPSHOT" +lombok = "1.18.34" +shadow = "8.1.8" +run-paper = "2.3.0" +skript = "2.7.1" +itemsadder = "3.6.1" + +[libraries] +paper-api = { module = "io.papermc.paper:paper-api", version.ref = "paper-api" } +lombok = { group = "org.projectlombok", name = "lombok", version.ref = "lombok" } +skript = { group = "com.github.SkriptLang", name = "Skript", version.ref = "skript"} +itemsadder = { group = "com.github.LoneDev6", name = "API-ItemsAdder", version.ref = "itemsadder"} + +[plugins] +run-paper = { id = "xyz.jpenilla.run-paper", version.ref = "run-paper" } +shadow = { id = "io.github.goooler.shadow", version.ref = "shadow" } diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index 0056cd2..0000000 --- a/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -rootProject.name = 'skript-itemsadder' diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..0de445a --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,12 @@ +pluginManagement { + repositories { + mavenCentral() + gradlePluginPortal() + } +} + +plugins { + id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0" +} + +rootProject.name = "skript-itemsadder" \ No newline at end of file diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/SkriptItemsAdder.java b/src/main/java/me/asleepp/SkriptItemsAdder/SkriptItemsAdder.java index f4c772b..3dee538 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/SkriptItemsAdder.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/SkriptItemsAdder.java @@ -1,12 +1,14 @@ package me.asleepp.SkriptItemsAdder; import java.io.IOException; -import java.util.List; import ch.njol.skript.util.Version; -import dev.lone.itemsadder.api.CustomStack; -import dev.lone.itemsadder.api.ItemsAdder; -import me.asleepp.SkriptItemsAdder.other.*; +import me.asleepp.SkriptItemsAdder.other.aliases.AliasesGenerator; +import me.asleepp.SkriptItemsAdder.other.listeners.ItemsAdderEventListener; +import me.asleepp.SkriptItemsAdder.other.util.Metrics; +import me.asleepp.SkriptItemsAdder.other.util.SkriptItemsAdderCommand; +import me.asleepp.SkriptItemsAdder.other.util.UpdateChecker; +import me.asleepp.SkriptItemsAdder.other.util.Util; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; @@ -77,7 +79,6 @@ public void run() { } }.runTask(this); - getLogger().info("Waiting for ItemsAdder to finish loading."); getServer().getScheduler().runTaskTimer(this, () -> { @@ -108,7 +109,7 @@ public void run() { return; } long finish = System.currentTimeMillis() - start; - getLogger().info("Succesfully loaded skript-itemsadder in " + finish + "ms!"); + getLogger().info("Successfully loaded skript-itemsadder in " + finish + "ms!"); loading = false; } diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomBlock.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomBlock.java index 5c26283..a2cef3a 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomBlock.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomBlock.java @@ -11,7 +11,7 @@ import ch.njol.skript.lang.SkriptParser; import ch.njol.util.Kleenean; import dev.lone.itemsadder.api.CustomBlock; -import me.asleepp.SkriptItemsAdder.other.CustomItemType; +import me.asleepp.SkriptItemsAdder.other.aliases.CustomItemType; import org.bukkit.block.Block; import org.bukkit.event.Event; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomItem.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomItem.java index 0ccca9e..0480796 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomItem.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomItem.java @@ -13,7 +13,7 @@ import org.bukkit.event.Event; import org.bukkit.inventory.ItemStack; import dev.lone.itemsadder.api.CustomStack; -import me.asleepp.SkriptItemsAdder.other.CustomItemType; +import me.asleepp.SkriptItemsAdder.other.aliases.CustomItemType; import javax.annotation.Nullable; import java.util.Arrays; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlaceBlockOrCrop.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/blocks/EffPlaceBlockOrCrop.java similarity index 88% rename from src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlaceBlockOrCrop.java rename to src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/blocks/EffPlaceBlockOrCrop.java index 5b976a7..fb8217c 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlaceBlockOrCrop.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/blocks/EffPlaceBlockOrCrop.java @@ -1,4 +1,4 @@ -package me.asleepp.SkriptItemsAdder.elements.effects; +package me.asleepp.SkriptItemsAdder.elements.effects.blocks; import ch.njol.skript.Skript; import ch.njol.skript.doc.Description; @@ -8,15 +8,14 @@ import ch.njol.skript.doc.Since; import ch.njol.skript.lang.Effect; import ch.njol.skript.lang.Expression; -import ch.njol.skript.lang.Literal; import ch.njol.skript.lang.SkriptParser; import ch.njol.skript.util.Direction; import ch.njol.util.Kleenean; import dev.lone.itemsadder.api.CustomBlock; import dev.lone.itemsadder.api.CustomCrop; import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; -import me.asleepp.SkriptItemsAdder.other.AliasesGenerator; -import me.asleepp.SkriptItemsAdder.other.CustomItemType; +import me.asleepp.SkriptItemsAdder.other.aliases.AliasesGenerator; +import me.asleepp.SkriptItemsAdder.other.aliases.CustomItemType; import org.bukkit.Location; import org.bukkit.event.Event; @@ -78,7 +77,6 @@ protected void execute(Event e) { return; } - for (Location location : locations.getArray(e)) { for (String alias : aliases) { String customBlockId = aliasesGenerator.getNamespacedId(alias); @@ -88,24 +86,18 @@ protected void execute(Event e) { continue; } + Skript.info("Attempting to place custom block/crop with ID: " + customBlockId + " at location: " + location); + try { if (isCrop) { - // attempt to place a crop try { CustomCrop.place(customBlockId, location); + Skript.info("Placed custom crop with ID: " + customBlockId + " at location: " + location); } catch (Exception ex) { Skript.error("The ID " + customBlockId + " does not correspond to a valid crop."); continue; } - - CustomCrop existingCrop = CustomCrop.byAlreadyPlaced(location.getBlock()); - if (existingCrop == null) { - CustomCrop.place(customBlockId, location); - } else { - Skript.error("There is already a crop here!"); - } } else { - // ensure it corresponds to a block if (CustomBlock.getInstance(customBlockId) == null) { Skript.error("The ID " + customBlockId + " does not correspond to a valid block."); continue; @@ -118,6 +110,7 @@ protected void execute(Event e) { CustomBlock block = CustomBlock.getInstance(customBlockId); if (block != null) { block.place(location); + Skript.info("Placed custom block with ID: " + customBlockId + " at location: " + location); } else { Skript.error("Failed to get CustomBlock instance for ID: " + customBlockId); } diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffReplaceBlock.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/blocks/EffReplaceBlock.java similarity index 96% rename from src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffReplaceBlock.java rename to src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/blocks/EffReplaceBlock.java index 9e547e7..24930f0 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffReplaceBlock.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/blocks/EffReplaceBlock.java @@ -1,4 +1,4 @@ -package me.asleepp.SkriptItemsAdder.elements.effects; +package me.asleepp.SkriptItemsAdder.elements.effects.blocks; import ch.njol.skript.Skript; import ch.njol.skript.doc.Description; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffSetBlocksBetween.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/blocks/EffSetBlocksBetween.java similarity index 95% rename from src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffSetBlocksBetween.java rename to src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/blocks/EffSetBlocksBetween.java index 086eb24..c8ff96a 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffSetBlocksBetween.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/blocks/EffSetBlocksBetween.java @@ -1,4 +1,4 @@ -package me.asleepp.SkriptItemsAdder.elements.effects; +package me.asleepp.SkriptItemsAdder.elements.effects.blocks; import ch.njol.skript.Skript; import ch.njol.skript.doc.Description; @@ -12,8 +12,8 @@ import ch.njol.util.Kleenean; import dev.lone.itemsadder.api.CustomBlock; import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; -import me.asleepp.SkriptItemsAdder.other.AliasesGenerator; -import me.asleepp.SkriptItemsAdder.other.CustomItemType; +import me.asleepp.SkriptItemsAdder.other.aliases.AliasesGenerator; +import me.asleepp.SkriptItemsAdder.other.aliases.CustomItemType; import org.bukkit.Location; import org.bukkit.event.Event; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlaceCustomFurniture.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/furniture/EffPlaceCustomFurniture.java similarity index 97% rename from src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlaceCustomFurniture.java rename to src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/furniture/EffPlaceCustomFurniture.java index 00ee92f..14dd532 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlaceCustomFurniture.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/furniture/EffPlaceCustomFurniture.java @@ -1,4 +1,4 @@ -package me.asleepp.SkriptItemsAdder.elements.effects; +package me.asleepp.SkriptItemsAdder.elements.effects.furniture; import ch.njol.skript.Skript; import ch.njol.skript.doc.Description; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffRemoveCustomFurniture.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/furniture/EffRemoveCustomFurniture.java similarity index 95% rename from src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffRemoveCustomFurniture.java rename to src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/furniture/EffRemoveCustomFurniture.java index 9818a62..74a8a9a 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffRemoveCustomFurniture.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/furniture/EffRemoveCustomFurniture.java @@ -1,4 +1,4 @@ -package me.asleepp.SkriptItemsAdder.elements.effects; +package me.asleepp.SkriptItemsAdder.elements.effects.furniture; import ch.njol.skript.Skript; import ch.njol.skript.doc.Description; @@ -10,7 +10,6 @@ import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser; import ch.njol.util.Kleenean; -import dev.lone.itemsadder.api.CustomBlock; import dev.lone.itemsadder.api.CustomFurniture; import org.bukkit.Location; import org.bukkit.event.Event; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffReplaceCustomFurniture.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/furniture/EffReplaceCustomFurniture.java similarity index 97% rename from src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffReplaceCustomFurniture.java rename to src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/furniture/EffReplaceCustomFurniture.java index 5c02711..18599d5 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffReplaceCustomFurniture.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/furniture/EffReplaceCustomFurniture.java @@ -1,4 +1,4 @@ -package me.asleepp.SkriptItemsAdder.elements.effects; +package me.asleepp.SkriptItemsAdder.elements.effects.furniture; import ch.njol.skript.Skript; import ch.njol.skript.doc.Description; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockBreak.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockBreak.java similarity index 95% rename from src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockBreak.java rename to src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockBreak.java index 9af6d6e..1cca129 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockBreak.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockBreak.java @@ -1,4 +1,4 @@ -package me.asleepp.SkriptItemsAdder.elements.events; +package me.asleepp.SkriptItemsAdder.elements.events.blocks; import ch.njol.skript.Skript; import ch.njol.skript.doc.Description; @@ -14,8 +14,8 @@ import dev.lone.itemsadder.api.CustomBlock; import dev.lone.itemsadder.api.Events.CustomBlockBreakEvent; import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; -import me.asleepp.SkriptItemsAdder.other.AliasesGenerator; -import me.asleepp.SkriptItemsAdder.other.CustomItemType; +import me.asleepp.SkriptItemsAdder.other.aliases.AliasesGenerator; +import me.asleepp.SkriptItemsAdder.other.aliases.CustomItemType; import org.bukkit.Location; import org.bukkit.event.Event; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockInteract.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockInteract.java similarity index 95% rename from src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockInteract.java rename to src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockInteract.java index 639f525..65266fb 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockInteract.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockInteract.java @@ -1,4 +1,4 @@ -package me.asleepp.SkriptItemsAdder.elements.events; +package me.asleepp.SkriptItemsAdder.elements.events.blocks; import ch.njol.skript.Skript; import ch.njol.skript.doc.Description; @@ -14,8 +14,8 @@ import dev.lone.itemsadder.api.CustomBlock; import dev.lone.itemsadder.api.Events.CustomBlockInteractEvent; import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; -import me.asleepp.SkriptItemsAdder.other.AliasesGenerator; -import me.asleepp.SkriptItemsAdder.other.CustomItemType; +import me.asleepp.SkriptItemsAdder.other.aliases.AliasesGenerator; +import me.asleepp.SkriptItemsAdder.other.aliases.CustomItemType; import org.bukkit.Location; import org.bukkit.event.Event; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockPlace.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockPlace.java similarity index 95% rename from src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockPlace.java rename to src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockPlace.java index 6b84886..279ebc9 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockPlace.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockPlace.java @@ -1,4 +1,4 @@ -package me.asleepp.SkriptItemsAdder.elements.events; +package me.asleepp.SkriptItemsAdder.elements.events.blocks; import ch.njol.skript.Skript; import ch.njol.skript.doc.Description; @@ -14,8 +14,8 @@ import dev.lone.itemsadder.api.CustomBlock; import dev.lone.itemsadder.api.Events.CustomBlockPlaceEvent; import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; -import me.asleepp.SkriptItemsAdder.other.AliasesGenerator; -import me.asleepp.SkriptItemsAdder.other.CustomItemType; +import me.asleepp.SkriptItemsAdder.other.aliases.AliasesGenerator; +import me.asleepp.SkriptItemsAdder.other.aliases.CustomItemType; import org.bukkit.Location; import org.bukkit.event.Event; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureBreak.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureBreak.java similarity index 94% rename from src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureBreak.java rename to src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureBreak.java index a9bca81..fe5be36 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureBreak.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureBreak.java @@ -1,4 +1,4 @@ -package me.asleepp.SkriptItemsAdder.elements.events; +package me.asleepp.SkriptItemsAdder.elements.events.furniture; import ch.njol.skript.Skript; import ch.njol.skript.doc.Description; @@ -14,8 +14,8 @@ import dev.lone.itemsadder.api.CustomFurniture; import dev.lone.itemsadder.api.Events.FurnitureBreakEvent; import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; -import me.asleepp.SkriptItemsAdder.other.AliasesGenerator; -import me.asleepp.SkriptItemsAdder.other.CustomItemType; +import me.asleepp.SkriptItemsAdder.other.aliases.AliasesGenerator; +import me.asleepp.SkriptItemsAdder.other.aliases.CustomItemType; import org.bukkit.Location; import org.bukkit.event.Event; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureInteract.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureInteract.java similarity index 95% rename from src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureInteract.java rename to src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureInteract.java index bbd01d9..ede7f8c 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureInteract.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureInteract.java @@ -1,4 +1,4 @@ -package me.asleepp.SkriptItemsAdder.elements.events; +package me.asleepp.SkriptItemsAdder.elements.events.furniture; import ch.njol.skript.Skript; import ch.njol.skript.doc.Description; @@ -14,8 +14,8 @@ import dev.lone.itemsadder.api.CustomFurniture; import dev.lone.itemsadder.api.Events.FurnitureInteractEvent; import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; -import me.asleepp.SkriptItemsAdder.other.AliasesGenerator; -import me.asleepp.SkriptItemsAdder.other.CustomItemType; +import me.asleepp.SkriptItemsAdder.other.aliases.AliasesGenerator; +import me.asleepp.SkriptItemsAdder.other.aliases.CustomItemType; import org.bukkit.Location; import org.bukkit.event.Event; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurniturePlace.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurniturePlace.java similarity index 89% rename from src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurniturePlace.java rename to src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurniturePlace.java index 09d2c2a..dbb82d4 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurniturePlace.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurniturePlace.java @@ -1,4 +1,4 @@ -package me.asleepp.SkriptItemsAdder.elements.events; +package me.asleepp.SkriptItemsAdder.elements.events.furniture; import ch.njol.skript.Skript; import ch.njol.skript.doc.Description; @@ -9,14 +9,10 @@ import ch.njol.skript.lang.Literal; import ch.njol.skript.lang.SkriptEvent; import ch.njol.skript.lang.SkriptParser; -import ch.njol.skript.registrations.EventValues; -import ch.njol.skript.util.Getter; -import dev.lone.itemsadder.api.CustomFurniture; import dev.lone.itemsadder.api.Events.FurniturePlaceEvent; import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; -import me.asleepp.SkriptItemsAdder.other.AliasesGenerator; -import me.asleepp.SkriptItemsAdder.other.CustomItemType; -import org.bukkit.Location; +import me.asleepp.SkriptItemsAdder.other.aliases.AliasesGenerator; +import me.asleepp.SkriptItemsAdder.other.aliases.CustomItemType; import org.bukkit.event.Event; import javax.annotation.Nullable; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureSuccessEvent.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureSuccessEvent.java similarity index 95% rename from src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureSuccessEvent.java rename to src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureSuccessEvent.java index 7c37080..8f3cc49 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomFurnitureSuccessEvent.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureSuccessEvent.java @@ -1,4 +1,4 @@ -package me.asleepp.SkriptItemsAdder.elements.events; +package me.asleepp.SkriptItemsAdder.elements.events.furniture; import ch.njol.skript.Skript; import ch.njol.skript.doc.Description; @@ -14,8 +14,8 @@ import dev.lone.itemsadder.api.CustomFurniture; import dev.lone.itemsadder.api.Events.FurniturePlaceSuccessEvent; import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; -import me.asleepp.SkriptItemsAdder.other.AliasesGenerator; -import me.asleepp.SkriptItemsAdder.other.CustomItemType; +import me.asleepp.SkriptItemsAdder.other.aliases.AliasesGenerator; +import me.asleepp.SkriptItemsAdder.other.aliases.CustomItemType; import org.bukkit.Location; import org.bukkit.event.Event; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomEntityDeath.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/other/EvtCustomEntityDeath.java similarity index 97% rename from src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomEntityDeath.java rename to src/main/java/me/asleepp/SkriptItemsAdder/elements/events/other/EvtCustomEntityDeath.java index e98f9ba..771a1d5 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomEntityDeath.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/other/EvtCustomEntityDeath.java @@ -1,4 +1,4 @@ -package me.asleepp.SkriptItemsAdder.elements.events; +package me.asleepp.SkriptItemsAdder.elements.events.other; import ch.njol.skript.Skript; import ch.njol.skript.doc.Description; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtEmote.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/other/EvtEmote.java similarity index 97% rename from src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtEmote.java rename to src/main/java/me/asleepp/SkriptItemsAdder/elements/events/other/EvtEmote.java index 4880f91..22a6930 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtEmote.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/other/EvtEmote.java @@ -1,4 +1,4 @@ -package me.asleepp.SkriptItemsAdder.elements.events; +package me.asleepp.SkriptItemsAdder.elements.events.other; import ch.njol.skript.Skript; import ch.njol.skript.lang.Literal; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtResourcePackSendEvent.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/other/EvtResourcePackSendEvent.java similarity index 96% rename from src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtResourcePackSendEvent.java rename to src/main/java/me/asleepp/SkriptItemsAdder/elements/events/other/EvtResourcePackSendEvent.java index c4bc834..fc097d7 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtResourcePackSendEvent.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/other/EvtResourcePackSendEvent.java @@ -1,4 +1,4 @@ -package me.asleepp.SkriptItemsAdder.elements.events; +package me.asleepp.SkriptItemsAdder.elements.events.other; import ch.njol.skript.Skript; import ch.njol.skript.doc.Description; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetCustomItem.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetCustomItem.java index b06303e..5bc3b1d 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetCustomItem.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetCustomItem.java @@ -14,7 +14,7 @@ import ch.njol.util.Kleenean; import dev.lone.itemsadder.api.CustomStack; import dev.lone.itemsadder.api.ItemsAdder; -import me.asleepp.SkriptItemsAdder.other.CustomItemType; +import me.asleepp.SkriptItemsAdder.other.aliases.CustomItemType; import org.bukkit.Material; import org.bukkit.event.Event; import org.bukkit.inventory.ItemStack; @@ -37,7 +37,7 @@ public class ExprGetCustomItem extends SimpleExpression { private boolean usesItemMaterial; static { - Skript.registerExpression(ExprGetCustomItem.class, ItemType.class, ExpressionType.SIMPLE, + Skript.registerExpression(ExprGetCustomItem.class, ItemType.class, ExpressionType.COMBINED, "[custom] (ia|itemsadder) item[s] %customitemtypes/strings%", "(all [[of] the]) [custom] (ia|itemsadder) item[s] [1:(that uses|using) [item[s]|material[s]] %-itemstacks%]"); } diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/types/Types.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/types/Types.java index b4d3c8b..b8eaeaa 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/types/Types.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/types/Types.java @@ -8,8 +8,8 @@ import ch.njol.yggdrasil.Fields; import dev.lone.itemsadder.api.FontImages.TexturedInventoryWrapper; import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; -import me.asleepp.SkriptItemsAdder.other.AliasesGenerator; -import me.asleepp.SkriptItemsAdder.other.CustomItemType; +import me.asleepp.SkriptItemsAdder.other.aliases.AliasesGenerator; +import me.asleepp.SkriptItemsAdder.other.aliases.CustomItemType; import javax.annotation.Nullable; import java.util.HashMap; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/other/AliasesGenerator.java b/src/main/java/me/asleepp/SkriptItemsAdder/other/aliases/AliasesGenerator.java similarity index 61% rename from src/main/java/me/asleepp/SkriptItemsAdder/other/AliasesGenerator.java rename to src/main/java/me/asleepp/SkriptItemsAdder/other/aliases/AliasesGenerator.java index feda189..b0804a9 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/other/AliasesGenerator.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/other/aliases/AliasesGenerator.java @@ -1,4 +1,4 @@ -package me.asleepp.SkriptItemsAdder.other; +package me.asleepp.SkriptItemsAdder.other.aliases; import ch.njol.skript.Skript; import ch.njol.skript.aliases.Aliases; @@ -13,20 +13,23 @@ import java.io.File; import java.io.IOException; import java.util.*; +import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; public class AliasesGenerator { private final SkriptItemsAdder plugin; private final File aliasesFile; private FileConfiguration aliasesConfig; - private final Map itemAliases = new HashMap<>(); - private final Set generatedAliases = new HashSet<>(); + private final Map itemAliases = new ConcurrentHashMap<>(); + private final Set generatedAliases = ConcurrentHashMap.newKeySet(); public AliasesGenerator(SkriptItemsAdder plugin) { this.plugin = plugin; this.aliasesFile = new File(plugin.getDataFolder(), "aliases.yml"); loadAliasesFile(); loadAliasesFromFile(); + //watchAliasesFile(); } public void loadAliasesFile() { @@ -37,7 +40,7 @@ public void loadAliasesFile() { aliasesConfig = YamlConfiguration.loadConfiguration(aliasesFile); } - private void loadAliasesFromFile() { + public void loadAliasesFromFile() { if (aliasesConfig.contains("items")) { for (String key : aliasesConfig.getConfigurationSection("items").getKeys(false)) { itemAliases.put(key, aliasesConfig.getString("items." + key)); @@ -86,36 +89,71 @@ private void registerAlias(String alias, String namespacedId) { try { addonProvider.addAlias(aliasName, namespacedId, null, new HashMap<>()); plugin.getLogger().info("Registered alias: " + alias + " for item: " + namespacedId + " with AliasesProvider."); - } catch (InvalidMinecraftIdException e) { - plugin.getLogger().severe("Invalid Minecraft ID: " + namespacedId); - } catch (NullPointerException e) { - plugin.getLogger().severe("Failed to register alias with AliasesProvider: " + e.getMessage()); + } catch (InvalidMinecraftIdException ignored) { } } - public void generateAliasesForNewItems(List newItems) { - for (CustomStack item : newItems) { - String alias = generateAliasForItem(item); - registerAlias(alias, item.getNamespacedID()); - } - saveAliasesToFile(); - } - public void generateAliasesForAllItems() { plugin.getLogger().info("Generating aliases for all items."); List allItems = ItemsAdder.getAllItems(); plugin.getLogger().info("Total items: " + allItems.size()); + + Set currentNamespaces = allItems.stream() + .map(CustomStack::getNamespacedID) + .collect(Collectors.toSet()); + + // Check if aliases need to be generated or updated + boolean allAliasesExist = currentNamespaces.stream() + .allMatch(itemAliases::containsValue); + + if (allAliasesExist && currentNamespaces.size() == itemAliases.size()) { + plugin.getLogger().info("All aliases are up to date."); + return; + } + for (CustomStack item : allItems) { - if (!itemAliases.containsValue(item.getNamespacedID())) { + String namespacedId = item.getNamespacedID(); + if (!itemAliases.containsValue(namespacedId)) { String alias = generateAliasForItem(item); - plugin.getLogger().info("Generated alias: " + alias + " for item: " + item.getNamespacedID()); - registerAlias(alias, item.getNamespacedID()); + registerAlias(alias, namespacedId); } } - saveAliasesToFile(); - plugin.getLogger().info("Aliases have been generated"); + + Set unusedAliases = itemAliases.keySet().stream() + .filter(alias -> !generatedAliases.contains(alias)) + .collect(Collectors.toSet()); + for (String unusedAlias : unusedAliases) { + itemAliases.remove(unusedAlias); + } } +// private void watchAliasesFile() { +// try { +// WatchService watchService = FileSystems.getDefault().newWatchService(); +// Path path = aliasesFile.toPath().getParent(); +// path.register(watchService, StandardWatchEventKinds.ENTRY_MODIFY); +// +// Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { +// try { +// while (true) { +// WatchKey key = watchService.take(); +// for (WatchEvent event : key.pollEvents()) { +// if (event.context().toString().equals(aliasesFile.getName())) { +// Bukkit.getScheduler().runTask(plugin, this::loadAliasesFromFile); +// syncAliasesWithProvider(); +// } +// } +// key.reset(); +// } +// } catch (InterruptedException ignored) { +// } +// }); +// } catch (IOException e) { +// plugin.getLogger().severe("Failed to watch aliases.yml for changes: " + e.getMessage()); +// e.printStackTrace(); +// } +// } + public void syncAliasesWithProvider() { AliasesProvider addonProvider = Aliases.getAddonProvider(Skript.getAddonInstance()); addonProvider.clearAliases(); @@ -124,46 +162,14 @@ public void syncAliasesWithProvider() { AliasesProvider.AliasName aliasName = new AliasesProvider.AliasName(entry.getKey(), entry.getKey(), 0); try { addonProvider.addAlias(aliasName, entry.getValue(), null, new HashMap<>()); - } catch (InvalidMinecraftIdException e) { - plugin.getLogger().severe("Failed to sync aliases! " + e.getMessage()); + } catch (InvalidMinecraftIdException ignored) { } } } - public void handleAliasChange(String alias, String newNamespacedId) { - itemAliases.put(alias, newNamespacedId); - aliasesConfig.set("items." + alias, newNamespacedId); - saveAliasesToFile(); - syncAliasesWithProvider(); - } - - public void handleItemUnregister(CustomStack item) { - String alias = getAliasForItem(item); - if (alias != null) { - itemAliases.remove(alias); - aliasesConfig.set("items." + alias, null); - saveAliasesToFile(); - syncAliasesWithProvider(); - } - } - - private String getAliasForItem(CustomStack item) { - for (Map.Entry entry : itemAliases.entrySet()) { - if (entry.getValue().equals(item.getNamespacedID())) { - return entry.getKey(); - } - } - return null; - } - - public void handleRemovedItems(List removedItems) { - for (CustomStack item : removedItems) { - handleItemUnregister(item); - } - } public String getNamespacedId(String alias) { - return itemAliases.getOrDefault(alias, alias); + return itemAliases.get(alias); } public Set getGeneratedAliases() { diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/other/CustomItemType.java b/src/main/java/me/asleepp/SkriptItemsAdder/other/aliases/CustomItemType.java similarity index 95% rename from src/main/java/me/asleepp/SkriptItemsAdder/other/CustomItemType.java rename to src/main/java/me/asleepp/SkriptItemsAdder/other/aliases/CustomItemType.java index 5c930aa..76689a1 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/other/CustomItemType.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/other/aliases/CustomItemType.java @@ -1,4 +1,4 @@ -package me.asleepp.SkriptItemsAdder.other; +package me.asleepp.SkriptItemsAdder.other.aliases; import org.bukkit.event.Event; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/other/ItemsAdderEventListener.java b/src/main/java/me/asleepp/SkriptItemsAdder/other/listeners/ItemsAdderEventListener.java similarity index 89% rename from src/main/java/me/asleepp/SkriptItemsAdder/other/ItemsAdderEventListener.java rename to src/main/java/me/asleepp/SkriptItemsAdder/other/listeners/ItemsAdderEventListener.java index d0d7e64..e1e3bbb 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/other/ItemsAdderEventListener.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/other/listeners/ItemsAdderEventListener.java @@ -1,8 +1,8 @@ -package me.asleepp.SkriptItemsAdder.other; +package me.asleepp.SkriptItemsAdder.other.listeners; -import dev.lone.itemsadder.api.CustomStack; import dev.lone.itemsadder.api.Events.ItemsAdderLoadDataEvent; import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; +import me.asleepp.SkriptItemsAdder.other.aliases.AliasesGenerator; import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/other/Metrics.java b/src/main/java/me/asleepp/SkriptItemsAdder/other/util/Metrics.java similarity index 99% rename from src/main/java/me/asleepp/SkriptItemsAdder/other/Metrics.java rename to src/main/java/me/asleepp/SkriptItemsAdder/other/util/Metrics.java index 8bfec1a..2f8118a 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/other/Metrics.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/other/util/Metrics.java @@ -1,4 +1,4 @@ -package me.asleepp.SkriptItemsAdder.other; +package me.asleepp.SkriptItemsAdder.other.util; import java.io.BufferedReader; import java.io.ByteArrayOutputStream; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/other/SkriptItemsAdderCommand.java b/src/main/java/me/asleepp/SkriptItemsAdder/other/util/SkriptItemsAdderCommand.java similarity index 52% rename from src/main/java/me/asleepp/SkriptItemsAdder/other/SkriptItemsAdderCommand.java rename to src/main/java/me/asleepp/SkriptItemsAdder/other/util/SkriptItemsAdderCommand.java index a190fea..a71c468 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/other/SkriptItemsAdderCommand.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/other/util/SkriptItemsAdderCommand.java @@ -1,25 +1,28 @@ -package me.asleepp.SkriptItemsAdder.other; +package me.asleepp.SkriptItemsAdder.other.util; import ch.njol.skript.Skript; import dev.lone.itemsadder.api.ItemsAdder; import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; +import me.asleepp.SkriptItemsAdder.other.aliases.AliasesGenerator; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; +import org.bukkit.scheduler.BukkitRunnable; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collections; import java.util.List; public class SkriptItemsAdderCommand implements CommandExecutor, TabCompleter { - private SkriptItemsAdder skriptItemsAdder = SkriptItemsAdder.getInstance(); - private final AliasesGenerator aliasesGenerator = new AliasesGenerator(skriptItemsAdder); + private SkriptItemsAdder plugin = SkriptItemsAdder.getInstance(); + private final AliasesGenerator aliasesGenerator = new AliasesGenerator(plugin); public SkriptItemsAdderCommand(SkriptItemsAdder plugin) { - this.skriptItemsAdder = plugin; + this.plugin = plugin; plugin.getCommand("skriptitemsadder").setExecutor(this); plugin.getCommand("skriptitemsadder").setTabCompleter(this); } @@ -27,14 +30,50 @@ public SkriptItemsAdderCommand(SkriptItemsAdder plugin) { @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String[] args) { if (args.length == 0) { - Util.sendMiniMessage(sender, true,"Please provide an argument!"); + Util.sendMiniMessage(sender, true, "Please provide an argument!"); return false; } - if (args[0].equalsIgnoreCase("reload")) { - skriptItemsAdder.reloadConfig(); - Util.sendMiniMessage(sender, true, "Successfully reloaded config."); - return true; + switch (args[1]) { + case "all": + Util.sendMiniMessage(sender, true, "Reloading aliases and configuration..."); + + new BukkitRunnable() { + @Override + public void run() { + aliasesGenerator.loadAliasesFile(); + aliasesGenerator.loadAliasesFromFile(); + aliasesGenerator.generateAliasesForAllItems(); + aliasesGenerator.saveAliases(); + aliasesGenerator.syncAliasesWithProvider(); + sender.sendMessage("Aliases have been reloaded."); + } + }.runTaskAsynchronously(plugin); + + plugin.reloadConfig(); + break; + case "config": + Util.sendMiniMessage(sender, true, "Reloading the configuration..."); + plugin.reloadConfig(); + Util.sendMiniMessage(sender, true, "Reloaded the configuration..."); + break; + case "aliases": + Util.sendMiniMessage(sender, true, "Reloading aliases..."); + + new BukkitRunnable() { + @Override + public void run() { + aliasesGenerator.loadAliasesFile(); + aliasesGenerator.loadAliasesFromFile(); + aliasesGenerator.generateAliasesForAllItems(); + aliasesGenerator.saveAliases(); + aliasesGenerator.syncAliasesWithProvider(); + Util.sendMiniMessage(sender, true, "Aliases have been reloaded."); + } + }.runTaskAsynchronously(plugin); + break; + } + } if (args[0].equalsIgnoreCase("info")) { @@ -43,7 +82,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command Util.sendMiniMessage(sender, ""); Util.sendMiniMessage(sender, "➥ Total Items registered with ItemsAdder: " + ItemsAdder.getAllItems().size()); Util.sendMiniMessage(sender, "➥ Total aliases registered with skript-itemsadder: " + aliasesGenerator.getGeneratedAliases().size()); - Util.sendMiniMessage(sender, "➥ Update Checker: " + skriptItemsAdder.getConfig().getString("check-for-updates")); + Util.sendMiniMessage(sender, "➥ Update Checker: " + plugin.getConfig().getString("check-for-updates")); Util.sendMiniMessage(sender, ""); Util.sendMiniMessage(sender, "-----------= MISC =-----------"); Util.sendMiniMessage(sender, ""); @@ -54,7 +93,6 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command Util.sendMiniMessage(sender, "➥ Skript Version: " + Skript.getVersion()); Util.sendMiniMessage(sender, ""); Util.sendMiniMessage(sender, "➥ If you find any issues with skript-itemsadder, please report it to the GitHub: CLICK ME"); - Util.sendMiniMessage(sender, "➥ Made with ♥ by Asleepp"); Util.sendMiniMessage(sender, ""); return true; } @@ -62,7 +100,12 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command } @Override - public @Nullable List onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) { - return List.of("reload", "info"); + public @Nullable List onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] args) { + if (args.length == 1) { + return List.of("reload", "info"); + } else if (args.length == 2) { + return List.of("all", "config", "aliases"); + } + return Collections.emptyList(); } } diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/other/UpdateChecker.java b/src/main/java/me/asleepp/SkriptItemsAdder/other/util/UpdateChecker.java similarity index 98% rename from src/main/java/me/asleepp/SkriptItemsAdder/other/UpdateChecker.java rename to src/main/java/me/asleepp/SkriptItemsAdder/other/util/UpdateChecker.java index abf6a2c..f226cc4 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/other/UpdateChecker.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/other/util/UpdateChecker.java @@ -1,4 +1,4 @@ -package me.asleepp.SkriptItemsAdder.other; +package me.asleepp.SkriptItemsAdder.other.util; import com.google.gson.Gson; import com.google.gson.JsonObject; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/other/Util.java b/src/main/java/me/asleepp/SkriptItemsAdder/other/util/Util.java similarity index 97% rename from src/main/java/me/asleepp/SkriptItemsAdder/other/Util.java rename to src/main/java/me/asleepp/SkriptItemsAdder/other/util/Util.java index 4c5f306..d09ba8d 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/other/Util.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/other/util/Util.java @@ -1,4 +1,4 @@ -package me.asleepp.SkriptItemsAdder.other; +package me.asleepp.SkriptItemsAdder.other.util; import net.kyori.adventure.text.minimessage.MiniMessage; import org.bukkit.Bukkit; diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 1916311..6716e57 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -2,10 +2,11 @@ name: skript-itemsadder authors: [Asleepp] description: A Skript Addon that adds useful syntax to be used in conjunction with ItemsAdder api-version: 1.13 -version: 1.5 +version: ${version} main: me.asleepp.SkriptItemsAdder.SkriptItemsAdder depend: [Skript, ItemsAdder] + commands: skriptitemsadder: description: Reload the plugin's config or see information \ No newline at end of file From 61b78b76b12d0d17fbe6f1c64be01b12a83e35c8 Mon Sep 17 00:00:00 2001 From: Asleepp <119438940+Asleeepp@users.noreply.github.com> Date: Fri, 16 Aug 2024 14:52:02 -0300 Subject: [PATCH 08/10] Fixes --- build.gradle.kts | 3 +- .../SkriptItemsAdder/SkriptItemsAdder.java | 44 ++----- .../effects/EffOpenCustomInventory.java | 1 - .../effects/blocks/EffPlaceBlockOrCrop.java | 58 +++------ .../events/blocks/EvtCustomBlockBreak.java | 13 +- .../events/blocks/EvtCustomBlockInteract.java | 13 +- .../events/blocks/EvtCustomBlockPlace.java | 15 +-- .../furniture/EvtCustomFurnitureBreak.java | 23 ++-- .../furniture/EvtCustomFurnitureInteract.java | 24 ++-- .../furniture/EvtCustomFurniturePlace.java | 30 ++--- .../EvtCustomFurnitureSuccessEvent.java | 26 ++-- .../elements/expressions/ExprGetID.java | 1 - .../elements/types/Types.java | 15 ++- .../other/aliases/AliasesGenerator.java | 123 +++++++----------- .../other/aliases/CustomItemType.java | 12 +- .../listeners/ItemsAdderEventListener.java | 10 +- .../other/util/UpdateChecker.java | 6 +- .../SkriptItemsAdder/other/util/Util.java | 11 ++ 18 files changed, 169 insertions(+), 259 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 0f1f909..88fcb5a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -21,7 +21,7 @@ java { } description = "A skript addon that aims to bring more to linking ItemsAdder and Skript" -group = "me.Asleepp" +group = "me.asleepp" version = "1.6" dependencies { @@ -46,7 +46,6 @@ tasks { attributes["Implementation-Version"] = rootProject.version } - relocate("org.bstats", "me.asleepp.SkriptItemsAdder.bstats") configurations = listOf(project.configurations.shadow.get()) minimize() } diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/SkriptItemsAdder.java b/src/main/java/me/asleepp/SkriptItemsAdder/SkriptItemsAdder.java index 3dee538..b808d8f 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/SkriptItemsAdder.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/SkriptItemsAdder.java @@ -3,6 +3,8 @@ import java.io.IOException; import ch.njol.skript.util.Version; +import lombok.Getter; +import lombok.Setter; import me.asleepp.SkriptItemsAdder.other.aliases.AliasesGenerator; import me.asleepp.SkriptItemsAdder.other.listeners.ItemsAdderEventListener; import me.asleepp.SkriptItemsAdder.other.util.Metrics; @@ -23,6 +25,7 @@ public class SkriptItemsAdder extends JavaPlugin { private static SkriptAddon addon; private static SkriptItemsAdder instance; + @Getter private AliasesGenerator aliasesGenerator; @Nullable @@ -35,14 +38,12 @@ public static SkriptAddon getAddonInstance() { return addon; } - public boolean itemsAdderReady = false; - public boolean loading = true; + private final PluginManager manager = this.getServer().getPluginManager(); @Override public void onEnable() { // Let's get this show on the road. long start = System.currentTimeMillis(); - final PluginManager manager = this.getServer().getPluginManager(); final Plugin skript = manager.getPlugin("Skript"); if (skript == null || !skript.isEnabled()) { getLogger().severe("Could not find Skript! Disabling..."); @@ -71,21 +72,8 @@ public void onEnable() { final SkriptItemsAdder plugin = this; // Pass the aliasesGenerator to the event listener - new BukkitRunnable() { - @Override - public void run() { - ItemsAdderEventListener eventListener = new ItemsAdderEventListener(plugin, aliasesGenerator); - manager.registerEvents(eventListener, plugin); - } - }.runTask(this); - - getLogger().info("Waiting for ItemsAdder to finish loading."); - - getServer().getScheduler().runTaskTimer(this, () -> { - if (itemsAdderReady) { - return; - } - }, 0, 20); + ItemsAdderEventListener eventListener = new ItemsAdderEventListener(plugin, aliasesGenerator); + manager.registerEvents(eventListener, plugin); int pluginId = 20971; Metrics metrics = new Metrics(this, pluginId); @@ -98,32 +86,24 @@ public void run() { saveDefaultConfig(); - if (getConfig().getBoolean("check-for-updates", true)) - new UpdateChecker(this); - try { - addon.loadClasses("me.asleepp.SkriptItemsAdder"); + addon.loadClasses("me.asleepp.SkriptItemsAdder", "elements"); } catch (IOException error) { error.printStackTrace(); manager.disablePlugin(this); return; } + + if (getConfig().getBoolean("check-for-updates", true)) + new UpdateChecker(this); + long finish = System.currentTimeMillis() - start; getLogger().info("Successfully loaded skript-itemsadder in " + finish + "ms!"); - loading = false; + eventListener.generateAliases(); } @Override public void onDisable() { aliasesGenerator.saveAliases(); } - - public void setItemsAdderReady(boolean ready) { - this.itemsAdderReady = ready; - } - - public AliasesGenerator getAliasesGenerator() { - return aliasesGenerator; - } - } diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffOpenCustomInventory.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffOpenCustomInventory.java index 59a4eb4..c24c3b4 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffOpenCustomInventory.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffOpenCustomInventory.java @@ -13,7 +13,6 @@ import dev.lone.itemsadder.api.FontImages.TexturedInventoryWrapper; import org.bukkit.entity.Player; import org.bukkit.event.Event; -import ch.njol.skript.variables.Variables; import javax.annotation.Nullable; @Name("Open ItemsAdder Inventory") diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/blocks/EffPlaceBlockOrCrop.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/blocks/EffPlaceBlockOrCrop.java index fb8217c..0f230b7 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/blocks/EffPlaceBlockOrCrop.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/blocks/EffPlaceBlockOrCrop.java @@ -13,16 +13,14 @@ import ch.njol.util.Kleenean; import dev.lone.itemsadder.api.CustomBlock; import dev.lone.itemsadder.api.CustomCrop; -import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; -import me.asleepp.SkriptItemsAdder.other.aliases.AliasesGenerator; import me.asleepp.SkriptItemsAdder.other.aliases.CustomItemType; +import me.asleepp.SkriptItemsAdder.other.util.Util; import org.bukkit.Location; import org.bukkit.event.Event; import javax.annotation.Nullable; -import java.util.Arrays; +import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; @Name("Place Custom Block/Crop") @Description({"Places a custom block or crop at a location."}) @@ -34,9 +32,7 @@ public class EffPlaceBlockOrCrop extends Effect { private Expression locations; private Expression blockNames; - private List aliases; private boolean isCrop; - private AliasesGenerator aliasesGenerator = SkriptItemsAdder.getInstance().getAliasesGenerator(); static { Skript.registerEffect(EffPlaceBlockOrCrop.class, @@ -53,56 +49,38 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye blockNames = exprs[2]; locations = Direction.combine((Expression) exprs[0], (Expression) exprs[1]); } - if (blockNames != null) { - aliases = Arrays.stream(blockNames.getArray(null)) - .map(obj -> { - if (obj instanceof CustomItemType) { - return ((CustomItemType) obj).getNamespacedID(); - } else if (obj instanceof String) { - return (String) obj; - } - return null; - }) - .filter(name -> name != null) - .collect(Collectors.toList()); - } - if (parseResult.hasTag("crop")) - isCrop = true; + isCrop = parseResult.hasTag("crop"); return true; } @Override protected void execute(Event e) { - if (locations == null || aliases == null || aliases.isEmpty()) { + if (locations == null || blockNames == null) { return; } - for (Location location : locations.getArray(e)) { - for (String alias : aliases) { - String customBlockId = aliasesGenerator.getNamespacedId(alias); + List customBlockIds = new ArrayList<>(); + if (blockNames.isSingle()) { + Object itemType = blockNames.getSingle(e); + customBlockIds.add(Util.getCustomBlockId(itemType)); + } else { + for (Object itemType : blockNames.getArray(e)) { + customBlockIds.add(Util.getCustomBlockId(itemType)); + } + } + for (Location location : locations.getArray(e)) { + for (String customBlockId : customBlockIds) { if (customBlockId == null) { - Skript.error("Invalid custom block ID: " + alias); + Skript.error("Invalid custom block ID."); continue; } - Skript.info("Attempting to place custom block/crop with ID: " + customBlockId + " at location: " + location); - try { if (isCrop) { - try { - CustomCrop.place(customBlockId, location); - Skript.info("Placed custom crop with ID: " + customBlockId + " at location: " + location); - } catch (Exception ex) { - Skript.error("The ID " + customBlockId + " does not correspond to a valid crop."); - continue; - } + CustomCrop.place(customBlockId, location); + Skript.info("Placed custom crop with ID: " + customBlockId + " at location: " + location); } else { - if (CustomBlock.getInstance(customBlockId) == null) { - Skript.error("The ID " + customBlockId + " does not correspond to a valid block."); - continue; - } - CustomBlock existingBlock = CustomBlock.byAlreadyPlaced(location.getBlock()); if (existingBlock != null) { existingBlock.remove(); diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockBreak.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockBreak.java index 1cca129..d1789ab 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockBreak.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockBreak.java @@ -16,6 +16,7 @@ import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; import me.asleepp.SkriptItemsAdder.other.aliases.AliasesGenerator; import me.asleepp.SkriptItemsAdder.other.aliases.CustomItemType; +import me.asleepp.SkriptItemsAdder.other.util.Util; import org.bukkit.Location; import org.bukkit.event.Event; @@ -59,12 +60,8 @@ public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseRes aliases = Arrays.stream(blockNames) .map(literal -> { if (literal instanceof Literal) { - Object value = ((Literal) literal).getSingle(); - if (value instanceof CustomItemType) { - return ((CustomItemType) value).getNamespacedID(); - } else if (value instanceof String) { - return (String) value; - } + Object value = literal.getSingle(); + return Util.getCustomBlockId(value); } return null; }) @@ -87,8 +84,8 @@ public boolean check(Event event) { // Check block name if (aliases != null && !aliases.isEmpty()) { - String actualBlockName = customEvent.getNamespacedID(); - return aliases.contains(aliasesGenerator.getNamespacedId(actualBlockName)); + String actualBlockName = Util.getCustomBlockId(customEvent.getNamespacedID()); + return aliases.contains(actualBlockName); } return true; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockInteract.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockInteract.java index 65266fb..6219fc4 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockInteract.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockInteract.java @@ -16,6 +16,7 @@ import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; import me.asleepp.SkriptItemsAdder.other.aliases.AliasesGenerator; import me.asleepp.SkriptItemsAdder.other.aliases.CustomItemType; +import me.asleepp.SkriptItemsAdder.other.util.Util; import org.bukkit.Location; import org.bukkit.event.Event; @@ -60,12 +61,8 @@ public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseRes aliases = Arrays.stream(blockNames) .map(literal -> { if (literal instanceof Literal) { - Object value = ((Literal) literal).getSingle(); - if (value instanceof CustomItemType) { - return ((CustomItemType) value).getNamespacedID(); - } else if (value instanceof String) { - return (String) value; - } + Object value = literal.getSingle(); + return Util.getCustomBlockId(value); } return null; }) @@ -88,8 +85,8 @@ public boolean check(Event event) { // Check block name if (aliases != null && !aliases.isEmpty()) { - String actualBlockName = customEvent.getNamespacedID(); - return aliases.contains(aliasesGenerator.getNamespacedId(actualBlockName)); + String actualBlockName = Util.getCustomBlockId(customEvent.getNamespacedID()); + return aliases.contains(actualBlockName); } return true; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockPlace.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockPlace.java index 279ebc9..a4bb093 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockPlace.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockPlace.java @@ -16,6 +16,7 @@ import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; import me.asleepp.SkriptItemsAdder.other.aliases.AliasesGenerator; import me.asleepp.SkriptItemsAdder.other.aliases.CustomItemType; +import me.asleepp.SkriptItemsAdder.other.util.Util; import org.bukkit.Location; import org.bukkit.event.Event; @@ -33,7 +34,7 @@ public class EvtCustomBlockPlace extends SkriptEvent { private Literal[] blockNames; private List aliases; - private AliasesGenerator aliasesGenerator = SkriptItemsAdder.getInstance().getAliasesGenerator(); + private final AliasesGenerator aliasesGenerator = SkriptItemsAdder.getInstance().getAliasesGenerator(); static { Skript.registerEvent("Custom Block Place", EvtCustomBlockPlace.class, CustomBlockPlaceEvent.class, "place [of] [custom] (ia|itemsadder) block[s] [%customitemtypes/strings%]"); @@ -59,12 +60,8 @@ public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseRes aliases = Arrays.stream(blockNames) .map(literal -> { if (literal instanceof Literal) { - Object value = ((Literal) literal).getSingle(); - if (value instanceof CustomItemType) { - return ((CustomItemType) value).getNamespacedID(); - } else if (value instanceof String) { - return (String) value; - } + Object value = literal.getSingle(); + return Util.getCustomBlockId(value); } return null; }) @@ -87,8 +84,8 @@ public boolean check(Event event) { // Check block name if (aliases != null && !aliases.isEmpty()) { - String actualBlockName = customEvent.getNamespacedID(); - return aliases.contains(aliasesGenerator.getNamespacedId(actualBlockName)); + String actualBlockName = Util.getCustomBlockId(customEvent.getNamespacedID()); + return aliases.contains(actualBlockName); } return true; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureBreak.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureBreak.java index fe5be36..bd94260 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureBreak.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureBreak.java @@ -16,6 +16,7 @@ import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; import me.asleepp.SkriptItemsAdder.other.aliases.AliasesGenerator; import me.asleepp.SkriptItemsAdder.other.aliases.CustomItemType; +import me.asleepp.SkriptItemsAdder.other.util.Util; import org.bukkit.Location; import org.bukkit.event.Event; @@ -58,13 +59,9 @@ public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseRes if (furnitureIDs != null) { aliases = Arrays.stream(furnitureIDs) .map(literal -> { - if (literal instanceof Literal) { - Object value = ((Literal) literal).getSingle(); - if (value instanceof CustomItemType) { - return ((CustomItemType) value).getNamespacedID(); - } else if (value instanceof String) { - return (String) value; - } + if (literal != null) { + Object value = literal.getSingle(); + return Util.getCustomBlockId(value); } return null; }) @@ -75,16 +72,14 @@ public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseRes } @Override - public boolean check(Event e) { - if (e instanceof FurnitureBreakEvent) { - FurnitureBreakEvent event = (FurnitureBreakEvent) e; - + public boolean check(Event event) { + if (event instanceof FurnitureBreakEvent furnEvent) { if (aliases != null && !aliases.isEmpty()) { - String actualFurnitureName = event.getNamespacedID(); - return aliases.contains(aliasesGenerator.getNamespacedId(actualFurnitureName)) && !event.isCancelled(); + String actualFurnitureName = Util.getCustomBlockId(furnEvent.getNamespacedID()); + return aliases.contains(actualFurnitureName); } - return !event.isCancelled(); + return !furnEvent.isCancelled(); } return false; } diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureInteract.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureInteract.java index ede7f8c..b880c6a 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureInteract.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureInteract.java @@ -12,10 +12,12 @@ import ch.njol.skript.registrations.EventValues; import ch.njol.skript.util.Getter; import dev.lone.itemsadder.api.CustomFurniture; +import dev.lone.itemsadder.api.Events.FurnitureBreakEvent; import dev.lone.itemsadder.api.Events.FurnitureInteractEvent; import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; import me.asleepp.SkriptItemsAdder.other.aliases.AliasesGenerator; import me.asleepp.SkriptItemsAdder.other.aliases.CustomItemType; +import me.asleepp.SkriptItemsAdder.other.util.Util; import org.bukkit.Location; import org.bukkit.event.Event; @@ -58,13 +60,9 @@ public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseRes if (furnitureIDs != null) { aliases = Arrays.stream(furnitureIDs) .map(literal -> { - if (literal instanceof Literal) { - Object value = ((Literal) literal).getSingle(); - if (value instanceof CustomItemType) { - return ((CustomItemType) value).getNamespacedID(); - } else if (value instanceof String) { - return (String) value; - } + if (literal != null) { + Object value = literal.getSingle(); + return Util.getCustomBlockId(value); } return null; }) @@ -75,16 +73,14 @@ public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseRes } @Override - public boolean check(Event e) { - if (e instanceof FurnitureInteractEvent) { - FurnitureInteractEvent event = (FurnitureInteractEvent) e; - + public boolean check(Event event) { + if (event instanceof FurnitureBreakEvent furnEvent) { if (aliases != null && !aliases.isEmpty()) { - String actualFurnitureName = event.getNamespacedID(); - return aliases.contains(aliasesGenerator.getNamespacedId(actualFurnitureName)) && !event.isCancelled(); + String actualFurnitureName = Util.getCustomBlockId(furnEvent.getNamespacedID()); + return aliases.contains(actualFurnitureName); } - return !event.isCancelled(); + return !furnEvent.isCancelled(); } return false; } diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurniturePlace.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurniturePlace.java index dbb82d4..0c754e4 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurniturePlace.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurniturePlace.java @@ -9,10 +9,12 @@ import ch.njol.skript.lang.Literal; import ch.njol.skript.lang.SkriptEvent; import ch.njol.skript.lang.SkriptParser; +import dev.lone.itemsadder.api.Events.FurnitureBreakEvent; import dev.lone.itemsadder.api.Events.FurniturePlaceEvent; import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; import me.asleepp.SkriptItemsAdder.other.aliases.AliasesGenerator; import me.asleepp.SkriptItemsAdder.other.aliases.CustomItemType; +import me.asleepp.SkriptItemsAdder.other.util.Util; import org.bukkit.event.Event; import javax.annotation.Nullable; @@ -42,13 +44,9 @@ public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseRes if (furnitureIDs != null) { aliases = Arrays.stream(furnitureIDs) .map(literal -> { - if (literal instanceof Literal) { - Object value = ((Literal) literal).getSingle(); - if (value instanceof CustomItemType) { - return ((CustomItemType) value).getNamespacedID(); - } else if (value instanceof String) { - return (String) value; - } + if (literal != null) { + Object value = literal.getSingle(); + return Util.getCustomBlockId(value); } return null; }) @@ -60,19 +58,13 @@ public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseRes @Override public boolean check(Event event) { - if (!(event instanceof FurniturePlaceEvent)) { - return false; - } - - FurniturePlaceEvent customEvent = (FurniturePlaceEvent) event; - if (customEvent.isCancelled()) { - return false; - } + if (event instanceof FurnitureBreakEvent furnEvent) { + if (aliases != null && !aliases.isEmpty()) { + String actualFurnitureName = Util.getCustomBlockId(furnEvent.getNamespacedID()); + return aliases.contains(actualFurnitureName); + } - // Check furniture name - if (aliases != null && !aliases.isEmpty()) { - String actualFurnitureName = customEvent.getNamespacedID(); - return aliases.contains(aliasesGenerator.getNamespacedId(actualFurnitureName)); + return !furnEvent.isCancelled(); } return true; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureSuccessEvent.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureSuccessEvent.java index 8f3cc49..7e7e9bb 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureSuccessEvent.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureSuccessEvent.java @@ -12,10 +12,12 @@ import ch.njol.skript.registrations.EventValues; import ch.njol.skript.util.Getter; import dev.lone.itemsadder.api.CustomFurniture; +import dev.lone.itemsadder.api.Events.FurnitureBreakEvent; import dev.lone.itemsadder.api.Events.FurniturePlaceSuccessEvent; import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; import me.asleepp.SkriptItemsAdder.other.aliases.AliasesGenerator; import me.asleepp.SkriptItemsAdder.other.aliases.CustomItemType; +import me.asleepp.SkriptItemsAdder.other.util.Util; import org.bukkit.Location; import org.bukkit.event.Event; @@ -60,13 +62,9 @@ public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseRes if (furnitureIDs != null) { aliases = Arrays.stream(furnitureIDs) .map(literal -> { - if (literal instanceof Literal) { - Object value = ((Literal) literal).getSingle(); - if (value instanceof CustomItemType) { - return ((CustomItemType) value).getNamespacedID(); - } else if (value instanceof String) { - return (String) value; - } + if (literal != null) { + Object value = literal.getSingle(); + return Util.getCustomBlockId(value); } return null; }) @@ -77,16 +75,14 @@ public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseRes } @Override - public boolean check(Event e) { - if (e instanceof FurniturePlaceSuccessEvent) { - FurniturePlaceSuccessEvent event = (FurniturePlaceSuccessEvent) e; - - if (furnitureIDs != null && !aliases.isEmpty()) { - String actualFurnitureName = event.getNamespacedID(); - return aliases.contains(aliasesGenerator.getNamespacedId(actualFurnitureName)); + public boolean check(Event event) { + if (event instanceof FurnitureBreakEvent furnEvent) { + if (aliases != null && !aliases.isEmpty()) { + String actualFurnitureName = Util.getCustomBlockId(furnEvent.getNamespacedID()); + return aliases.contains(actualFurnitureName); } - return true; + return !furnEvent.isCancelled(); } return false; } diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetID.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetID.java index 142d838..7f4709b 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetID.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetID.java @@ -6,7 +6,6 @@ import ch.njol.skript.lang.SkriptParser; import ch.njol.skript.lang.util.SimpleExpression; import ch.njol.util.Kleenean; -import ch.njol.util.coll.CollectionUtils; import dev.lone.itemsadder.api.CustomBlock; import dev.lone.itemsadder.api.CustomEntity; import dev.lone.itemsadder.api.CustomStack; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/types/Types.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/types/Types.java index b8eaeaa..b14dae6 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/types/Types.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/types/Types.java @@ -10,6 +10,7 @@ import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; import me.asleepp.SkriptItemsAdder.other.aliases.AliasesGenerator; import me.asleepp.SkriptItemsAdder.other.aliases.CustomItemType; +import org.jetbrains.annotations.NotNull; import javax.annotation.Nullable; import java.util.HashMap; @@ -26,14 +27,14 @@ public class Types { .description("Represents a custom item type using aliases.") .serializer(new Serializer() { @Override - public Fields serialize(CustomItemType customItemType) { + public @NotNull Fields serialize(CustomItemType customItemType) { Fields fields = new Fields(); fields.putObject("namespacedID", customItemType.getNamespacedID()); return fields; } @Override - public void deserialize(CustomItemType customItemType, Fields fields) { + public void deserialize(CustomItemType customItemType, @NotNull Fields fields) { try { customItemType.setNamespacedID((String) fields.getObject("namespacedID")); } catch (java.io.StreamCorruptedException e) { @@ -54,19 +55,19 @@ public boolean canBeInstantiated() { .parser(new Parser() { @Override @Nullable - public CustomItemType parse(String s, ParseContext context) { + public CustomItemType parse(@NotNull String s, @NotNull ParseContext context) { AliasesGenerator aliasesGenerator = SkriptItemsAdder.getInstance().getAliasesGenerator(); String namespacedID = aliasesGenerator.getNamespacedId(s.toLowerCase().replace("_", " ")); return namespacedID == null ? null : new CustomItemType(namespacedID); } @Override - public String toString(CustomItemType customItemType, int flags) { + public @NotNull String toString(CustomItemType customItemType, int flags) { return customItemType.getNamespacedID(); } @Override - public String toVariableNameString(CustomItemType customItemType) { + public @NotNull String toVariableNameString(CustomItemType customItemType) { return customItemType.getNamespacedID(); } @@ -84,7 +85,7 @@ public String getVariableNamePattern() { .parser(new Parser() { @Override - public TexturedInventoryWrapper parse(String s, ParseContext context) { + public TexturedInventoryWrapper parse(@NotNull String s, @NotNull ParseContext context) { return inventoryMap.get(s); } @@ -99,7 +100,7 @@ public String toString(TexturedInventoryWrapper texturedInventoryWrapper, int fl } @Override - public String toVariableNameString(TexturedInventoryWrapper texturedInventoryWrapper) { + public @NotNull String toVariableNameString(TexturedInventoryWrapper texturedInventoryWrapper) { return toString(texturedInventoryWrapper, 0); } diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/other/aliases/AliasesGenerator.java b/src/main/java/me/asleepp/SkriptItemsAdder/other/aliases/AliasesGenerator.java index b0804a9..5abd8d0 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/other/aliases/AliasesGenerator.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/other/aliases/AliasesGenerator.java @@ -6,9 +6,11 @@ import ch.njol.skript.aliases.InvalidMinecraftIdException; import dev.lone.itemsadder.api.CustomStack; import dev.lone.itemsadder.api.ItemsAdder; +import lombok.Getter; import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.scheduler.BukkitRunnable; import java.io.File; import java.io.IOException; @@ -22,6 +24,7 @@ public class AliasesGenerator { private final File aliasesFile; private FileConfiguration aliasesConfig; private final Map itemAliases = new ConcurrentHashMap<>(); + @Getter private final Set generatedAliases = ConcurrentHashMap.newKeySet(); public AliasesGenerator(SkriptItemsAdder plugin) { @@ -46,20 +49,22 @@ public void loadAliasesFromFile() { itemAliases.put(key, aliasesConfig.getString("items." + key)); } } - plugin.getLogger().info("Loaded " + itemAliases.size() + " aliases from file."); } private void saveAliasesToFile() { - for (Map.Entry entry : itemAliases.entrySet()) { - aliasesConfig.set("items." + entry.getKey(), entry.getValue()); - } - try { - aliasesConfig.save(aliasesFile); - plugin.getLogger().info("Aliases saved to " + aliasesFile.getPath()); - } catch (IOException e) { - plugin.getLogger().severe("Failed to save aliases: " + e.getMessage()); - e.printStackTrace(); - } + new BukkitRunnable() { + @Override + public void run() { + for (Map.Entry entry : itemAliases.entrySet()) { + aliasesConfig.set("items." + entry.getKey(), entry.getValue()); + } + try { + aliasesConfig.save(aliasesFile); + } catch (IOException e) { + e.printStackTrace(); + } + } + }.runTaskAsynchronously(plugin); } private String generateUniqueAlias(String baseAlias) { @@ -88,72 +93,48 @@ private void registerAlias(String alias, String namespacedId) { AliasesProvider.AliasName aliasName = new AliasesProvider.AliasName(alias, alias, 0); try { addonProvider.addAlias(aliasName, namespacedId, null, new HashMap<>()); - plugin.getLogger().info("Registered alias: " + alias + " for item: " + namespacedId + " with AliasesProvider."); } catch (InvalidMinecraftIdException ignored) { } } public void generateAliasesForAllItems() { - plugin.getLogger().info("Generating aliases for all items."); - List allItems = ItemsAdder.getAllItems(); - plugin.getLogger().info("Total items: " + allItems.size()); - - Set currentNamespaces = allItems.stream() - .map(CustomStack::getNamespacedID) - .collect(Collectors.toSet()); - - // Check if aliases need to be generated or updated - boolean allAliasesExist = currentNamespaces.stream() - .allMatch(itemAliases::containsValue); - - if (allAliasesExist && currentNamespaces.size() == itemAliases.size()) { - plugin.getLogger().info("All aliases are up to date."); - return; - } - - for (CustomStack item : allItems) { - String namespacedId = item.getNamespacedID(); - if (!itemAliases.containsValue(namespacedId)) { - String alias = generateAliasForItem(item); - registerAlias(alias, namespacedId); + new BukkitRunnable() { + @Override + public void run() { + List allItems = ItemsAdder.getAllItems(); + + Set currentNamespaces = allItems.stream() + .map(CustomStack::getNamespacedID) + .collect(Collectors.toSet()); + + boolean allAliasesExist = currentNamespaces.stream() + .allMatch(itemAliases::containsValue); + + if (allAliasesExist && currentNamespaces.size() == itemAliases.size()) { + return; + } + + for (CustomStack item : allItems) { + String namespacedId = item.getNamespacedID(); + if (!itemAliases.containsValue(namespacedId)) { + String alias = generateAliasForItem(item); + registerAlias(alias, namespacedId); + } + } + + Set unusedAliases = itemAliases.keySet().stream() + .filter(alias -> !generatedAliases.contains(alias)) + .collect(Collectors.toSet()); + for (String unusedAlias : unusedAliases) { + itemAliases.remove(unusedAlias); + } + + // Save asynchronously + saveAliases(); } - } - - Set unusedAliases = itemAliases.keySet().stream() - .filter(alias -> !generatedAliases.contains(alias)) - .collect(Collectors.toSet()); - for (String unusedAlias : unusedAliases) { - itemAliases.remove(unusedAlias); - } + }.runTaskAsynchronously(plugin); } -// private void watchAliasesFile() { -// try { -// WatchService watchService = FileSystems.getDefault().newWatchService(); -// Path path = aliasesFile.toPath().getParent(); -// path.register(watchService, StandardWatchEventKinds.ENTRY_MODIFY); -// -// Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { -// try { -// while (true) { -// WatchKey key = watchService.take(); -// for (WatchEvent event : key.pollEvents()) { -// if (event.context().toString().equals(aliasesFile.getName())) { -// Bukkit.getScheduler().runTask(plugin, this::loadAliasesFromFile); -// syncAliasesWithProvider(); -// } -// } -// key.reset(); -// } -// } catch (InterruptedException ignored) { -// } -// }); -// } catch (IOException e) { -// plugin.getLogger().severe("Failed to watch aliases.yml for changes: " + e.getMessage()); -// e.printStackTrace(); -// } -// } - public void syncAliasesWithProvider() { AliasesProvider addonProvider = Aliases.getAddonProvider(Skript.getAddonInstance()); addonProvider.clearAliases(); @@ -172,10 +153,6 @@ public String getNamespacedId(String alias) { return itemAliases.get(alias); } - public Set getGeneratedAliases() { - return generatedAliases; - } - public void saveAliases() { saveAliasesToFile(); } diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/other/aliases/CustomItemType.java b/src/main/java/me/asleepp/SkriptItemsAdder/other/aliases/CustomItemType.java index 76689a1..8771f61 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/other/aliases/CustomItemType.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/other/aliases/CustomItemType.java @@ -1,10 +1,14 @@ package me.asleepp.SkriptItemsAdder.other.aliases; +import lombok.Getter; +import lombok.Setter; import org.bukkit.event.Event; import java.util.Objects; import java.util.function.Function; +@Setter +@Getter public class CustomItemType { private String namespacedID; @@ -13,14 +17,6 @@ public CustomItemType(String namespacedID) { this.namespacedID = namespacedID; } - public String getNamespacedID() { - return namespacedID; - } - - public void setNamespacedID(String namespacedID) { - this.namespacedID = namespacedID; - } - @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/other/listeners/ItemsAdderEventListener.java b/src/main/java/me/asleepp/SkriptItemsAdder/other/listeners/ItemsAdderEventListener.java index e1e3bbb..ad1beca 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/other/listeners/ItemsAdderEventListener.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/other/listeners/ItemsAdderEventListener.java @@ -18,15 +18,15 @@ public ItemsAdderEventListener(SkriptItemsAdder plugin, AliasesGenerator aliases @EventHandler public void onItemsAdderLoadData(ItemsAdderLoadDataEvent event) { - if (plugin.loading) { - plugin.getLogger().info("ItemsAdder fully loaded, enabling skript-itemsadder."); - plugin.setItemsAdderReady(true); - } - // run alias generation async + generateAliases(); + } + + public void generateAliases() { Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { aliasesGenerator.generateAliasesForAllItems(); aliasesGenerator.saveAliases(); }); } + } diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/other/util/UpdateChecker.java b/src/main/java/me/asleepp/SkriptItemsAdder/other/util/UpdateChecker.java index f226cc4..a3f5c55 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/other/util/UpdateChecker.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/other/util/UpdateChecker.java @@ -36,9 +36,9 @@ public void onPlayerJoin(PlayerJoinEvent event) { if (player.hasPermission("skript-itemsadder.update.check") && latestVersion != null) { if (!currentVersion.equals(latestVersion)) { player.sendMessage(" "); - player.sendMessage(MiniMessage.miniMessage().deserialize("[skript-itemsadder] skript-itemsadder is OUTDATED!")); - player.sendMessage(MiniMessage.miniMessage().deserialize("[skript-itemsadder] New version: " + latestVersion)); - player.sendMessage(MiniMessage.miniMessage().deserialize("[skript-itemsadder] Download here!")); + player.sendMessage(MiniMessage.miniMessage().deserialize("[skript-itemsadder] skript-itemsadder is OUTDATED!")); + player.sendMessage(MiniMessage.miniMessage().deserialize("[skript-itemsadder] New version: " + latestVersion)); + player.sendMessage(MiniMessage.miniMessage().deserialize("[skript-itemsadder] Download Click here to get the latest version!'>here!")); player.sendMessage(" "); } } diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/other/util/Util.java b/src/main/java/me/asleepp/SkriptItemsAdder/other/util/Util.java index d09ba8d..6a73f62 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/other/util/Util.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/other/util/Util.java @@ -1,5 +1,7 @@ package me.asleepp.SkriptItemsAdder.other.util; +import dev.lone.itemsadder.api.CustomBlock; +import me.asleepp.SkriptItemsAdder.other.aliases.CustomItemType; import net.kyori.adventure.text.minimessage.MiniMessage; import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; @@ -45,4 +47,13 @@ public static String getPluginVersion(String pluginName) { } } + public static String getCustomBlockId(Object itemType) { + if (itemType instanceof CustomItemType) { + return ((CustomItemType) itemType).getNamespacedID(); + } else if (itemType instanceof String) { + return CustomBlock.getInstance((String) itemType) != null ? (String) itemType : null; + } + return null; + } + } From 859dc77fb21073d91001b7056f20df6d5e1e1c79 Mon Sep 17 00:00:00 2001 From: Asleepp <119438940+Asleeepp@users.noreply.github.com> Date: Fri, 16 Aug 2024 15:21:53 -0300 Subject: [PATCH 09/10] Touch-ups --- .../conditions/CondIsCustomEntity.java | 4 +- .../elements/effects/EffDamageEffect.java | 10 +++ .../effects/EffMakeEntityPlayAnimation.java | 2 +- .../effects/EffOpenCustomInventory.java | 2 +- .../effects/EffSpawnCustomEntity.java | 2 +- .../effects/blocks/EffPlaceBlockOrCrop.java | 2 +- .../effects/blocks/EffSetBlocksBetween.java | 19 ++---- .../furniture/EffPlaceCustomFurniture.java | 61 +++++++++++++------ .../furniture/EffRemoveCustomFurniture.java | 47 +++++++++----- .../furniture/EffReplaceCustomFurniture.java | 58 ------------------ .../events/blocks/EvtCustomBlockBreak.java | 16 ++--- .../events/blocks/EvtCustomBlockInteract.java | 11 ++-- .../events/blocks/EvtCustomBlockPlace.java | 11 ++-- .../furniture/EvtCustomFurnitureBreak.java | 11 ++-- .../furniture/EvtCustomFurnitureInteract.java | 11 ++-- .../furniture/EvtCustomFurniturePlace.java | 11 ++-- .../EvtCustomFurnitureSuccessEvent.java | 14 +++-- .../events/other/EvtCustomEntityDeath.java | 6 +- .../elements/events/other/EvtEmote.java | 6 +- .../other/EvtResourcePackSendEvent.java | 15 +++-- .../elements/expressions/ExprCropAge.java | 11 ++++ .../elements/expressions/ExprGetID.java | 16 ++++- 22 files changed, 181 insertions(+), 165 deletions(-) delete mode 100644 src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/furniture/EffReplaceCustomFurniture.java diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomEntity.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomEntity.java index 9f49fa3..acc824d 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomEntity.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomEntity.java @@ -19,9 +19,9 @@ @Description({"Checks if the entity is an ItemsAdder entity."}) @Examples({ "on damage:", - "\tif event-entity is a custom entity:", + "\tif event-entity is an itemsadder entity:", "\t\tsend \"how could you?\" to player", - "\tif event-entity is not a custom entity:", + "\telse if event-entity is not an itemsadder entity:", "\t\t send \"Incredible!\" to player "}) @Since("1.0, 1.5 (Negative Comparison)") @RequiredPlugins("ItemsAdder") diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffDamageEffect.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffDamageEffect.java index 4fbad30..0f3cdf4 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffDamageEffect.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffDamageEffect.java @@ -1,16 +1,26 @@ package me.asleepp.SkriptItemsAdder.elements.effects; import ch.njol.skript.Skript; +import ch.njol.skript.doc.Examples; +import ch.njol.skript.doc.RequiredPlugins; +import ch.njol.skript.doc.Since; import ch.njol.skript.lang.Effect; import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser; import ch.njol.util.Kleenean; import dev.lone.itemsadder.api.CustomEntity; +import jdk.jfr.Description; +import jdk.jfr.Name; import org.bukkit.entity.Entity; import org.bukkit.event.Event; import javax.annotation.Nullable; +@Name("Damage Effect") +@Description("Play the red damage effect on an ItemsAdder entity.") +@Examples("play damage effect on custom itemsadder entity {_iaentity}") +@Since("1.6") +@RequiredPlugins("ItemsAdder") public class EffDamageEffect extends Effect { private Expression entitiesExpr; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffMakeEntityPlayAnimation.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffMakeEntityPlayAnimation.java index 651046d..8589dfe 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffMakeEntityPlayAnimation.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffMakeEntityPlayAnimation.java @@ -19,7 +19,7 @@ @Description({"Makes an ItemsAdder entity play an animation."}) @Examples({ "on right click:", - "\tif clicked entity is a custom entity", + "\tif clicked entity is an itemsadder entity", "\t\tmake clicked entity play itemsadder animation \"fortnite:default_dance\""}) @Since("1.0") @RequiredPlugins("ItemsAdder") diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffOpenCustomInventory.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffOpenCustomInventory.java index c24c3b4..a9c35e4 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffOpenCustomInventory.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffOpenCustomInventory.java @@ -17,7 +17,7 @@ import javax.annotation.Nullable; @Name("Open ItemsAdder Inventory") @Description("Opens an ItemsAdder inventory to a player(s), made using the ItemsAdder inventory section.") -@Examples("open custom inventory {votegui} to all players") +@Examples("open custom itemsadder inventory {votegui} to all players") @Since("1.5") @RequiredPlugins("ItemsAdder") public class EffOpenCustomInventory extends Effect { diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffSpawnCustomEntity.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffSpawnCustomEntity.java index 0b3a517..f57218d 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffSpawnCustomEntity.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffSpawnCustomEntity.java @@ -17,7 +17,7 @@ import javax.annotation.Nullable; @Name("Spawn ItemsAdder Entity") @Description({"Spawns an ItemsAdder entity."}) -@Examples({"spawn custom entity \"bosses:john_wick\" at player's location"}) +@Examples({"spawn itemsadder entity \"bosses:john_wick\" at player's location"}) @Since("1.0") @RequiredPlugins("ItemsAdder") public class EffSpawnCustomEntity extends Effect { diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/blocks/EffPlaceBlockOrCrop.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/blocks/EffPlaceBlockOrCrop.java index 0f230b7..76cb108 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/blocks/EffPlaceBlockOrCrop.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/blocks/EffPlaceBlockOrCrop.java @@ -26,7 +26,7 @@ @Description({"Places a custom block or crop at a location."}) @Examples({ "set block at player's location to itemsadder block \"iasurvival:ruby_block\"", - "set block at player's location to custom crop \"bestcrops:best_seed\""}) + "set block at player's location to custom itemsadder crop best seed"}) @Since("1.0, 1.5 (Placing Crops & Syntax rework)") @RequiredPlugins("ItemsAdder") public class EffPlaceBlockOrCrop extends Effect { diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/blocks/EffSetBlocksBetween.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/blocks/EffSetBlocksBetween.java index c8ff96a..de5a602 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/blocks/EffSetBlocksBetween.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/blocks/EffSetBlocksBetween.java @@ -13,7 +13,7 @@ import dev.lone.itemsadder.api.CustomBlock; import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; import me.asleepp.SkriptItemsAdder.other.aliases.AliasesGenerator; -import me.asleepp.SkriptItemsAdder.other.aliases.CustomItemType; +import me.asleepp.SkriptItemsAdder.other.util.Util; import org.bukkit.Location; import org.bukkit.event.Event; @@ -24,7 +24,7 @@ @Name("Set Custom Blocks Within") @Description({"Sets the blocks within 2 locations to ItemsAdder custom blocks."}) -@Examples({"set all blocks within location(0, 100, 0) and player's location to custom block \"iasurvival:ruby_block\""}) +@Examples({"set all blocks within location(0, 100, 0) and player's location to itemsadder block \"iasurvival:ruby_block\""}) @Since("1.0") @RequiredPlugins("ItemsAdder") public class EffSetBlocksBetween extends Effect { @@ -47,12 +47,7 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye .filter(expr -> expr instanceof Expression) .map(expr -> { Object value = ((Expression) expr).getSingle(null); - if (value instanceof CustomItemType) { - return ((CustomItemType) value).getNamespacedID(); - } else if (value instanceof String) { - return (String) value; - } - return null; + return Util.getCustomBlockId(value); }) .filter(name -> name != null) .collect(Collectors.toList()); @@ -64,13 +59,7 @@ protected void execute(Event e) { Location location1 = location1Expr.getSingle(e); Location location2 = location2Expr.getSingle(e); Object customBlockIdObj = customBlockIdExpr.getSingle(e); - String customBlockId = null; - - if (customBlockIdObj instanceof CustomItemType) { - customBlockId = ((CustomItemType) customBlockIdObj).getNamespacedID(); - } else if (customBlockIdObj instanceof String) { - customBlockId = (String) customBlockIdObj; - } + String customBlockId = Util.getCustomBlockId(customBlockIdObj); if (location1 == null || location2 == null || customBlockId == null) { return; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/furniture/EffPlaceCustomFurniture.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/furniture/EffPlaceCustomFurniture.java index 14dd532..29d4bb0 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/furniture/EffPlaceCustomFurniture.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/furniture/EffPlaceCustomFurniture.java @@ -10,46 +10,73 @@ import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser; import ch.njol.util.Kleenean; -import org.bukkit.entity.Entity; -import org.bukkit.event.Event; import dev.lone.itemsadder.api.CustomFurniture; +import me.asleepp.SkriptItemsAdder.other.util.Util; import org.bukkit.Location; +import org.bukkit.entity.Entity; +import org.bukkit.event.Event; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitRunnable; import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.List; @Name("Place Custom Furniture") -@Description({"Place a custom furniture at a location."}) -@Examples({"place custom furniture \"coolfurniture:comfy_chair\" at player's location"}) -@Since("1.3") +@Description({ + "Place a custom furniture at a location.", + "If there is a furniture at the same location, this effect will replace it." +}) +@Examples({"place itemsadder furniture \"coolfurniture:comfy_chair\" at player's location"}) +@Since("1.3, 1.6 (Replacing)") @RequiredPlugins("ItemsAdder") public class EffPlaceCustomFurniture extends Effect { - private Expression furnitureId; - private Expression location; + private Expression furnitureIdExpr; + private Expression locationExpr; private JavaPlugin plugin; static { - Skript.registerEffect(EffPlaceCustomFurniture.class, "(set|place) [custom] (ia|itemsadder) furniture %string% at %location%"); + Skript.registerEffect(EffPlaceCustomFurniture.class, "(set|place) [custom] (ia|itemsadder) furniture %customitemtypes/strings% at %location%"); } @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { - furnitureId = (Expression) exprs[0]; - location = (Expression) exprs[1]; + furnitureIdExpr = exprs[0]; + locationExpr = (Expression) exprs[1]; return true; } @Override protected void execute(Event e) { - String id = furnitureId.getSingle(e); - Location loc = location.getSingle(e); + if (furnitureIdExpr == null || locationExpr == null) { + return; + } + + List furnitureIds = new ArrayList<>(); + if (furnitureIdExpr.isSingle()) { + Object itemType = furnitureIdExpr.getSingle(e); + furnitureIds.add(Util.getCustomBlockId(itemType)); + } else { + for (Object itemType : furnitureIdExpr.getArray(e)) { + furnitureIds.add(Util.getCustomBlockId(itemType)); + } + } + + Location location = locationExpr.getSingle(e); + if (location == null) { + return; + } + + for (String furnitureId : furnitureIds) { + if (furnitureId == null) { + Skript.error("Invalid custom furniture ID."); + continue; + } - CustomFurniture customFurniture = CustomFurniture.byAlreadySpawned(loc.getBlock()); - if (id != null && loc != null) { + CustomFurniture customFurniture = CustomFurniture.byAlreadySpawned(location.getBlock()); if (customFurniture == null) { - CustomFurniture.spawn(id, loc.getBlock()); + CustomFurniture.spawn(furnitureId, location.getBlock()); } else { Entity armorStand = customFurniture.getArmorstand(); if (armorStand != null) { @@ -58,7 +85,7 @@ protected void execute(Event e) { new BukkitRunnable() { @Override public void run() { - customFurniture.teleport(originalLocation); + CustomFurniture.spawn(furnitureId, originalLocation.getBlock()); } }.runTaskLater(plugin, 3); } @@ -68,7 +95,7 @@ public void run() { @Override public String toString(@Nullable Event e, boolean debug) { - return "(set|place) [custom] (ia|itemsadder) furniture " + furnitureId.toString(e, debug) + " at " + location.toString(e, debug); + return "(set|place) [custom] (ia|itemsadder) furniture " + furnitureIdExpr.toString(e, debug) + " at " + locationExpr.toString(e, debug); } } diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/furniture/EffRemoveCustomFurniture.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/furniture/EffRemoveCustomFurniture.java index 74a8a9a..b70e047 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/furniture/EffRemoveCustomFurniture.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/furniture/EffRemoveCustomFurniture.java @@ -11,35 +11,60 @@ import ch.njol.skript.lang.SkriptParser; import ch.njol.util.Kleenean; import dev.lone.itemsadder.api.CustomFurniture; +import me.asleepp.SkriptItemsAdder.other.util.Util; import org.bukkit.Location; import org.bukkit.event.Event; import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.List; + @Name("Remove Custom Furniture") @Description({"If there is furniture at a location, this effect will remove it."}) -@Examples({"remove custom furniture at player's location"}) +@Examples({"remove itemsadder furniture at player's location"}) @Since("1.4") @RequiredPlugins("ItemsAdder") public class EffRemoveCustomFurniture extends Effect { static { - Skript.registerEffect(EffRemoveCustomFurniture.class, "(remove|delete) [custom] (ia|itemsadder) furniture [%string%] at %locations%"); + Skript.registerEffect(EffRemoveCustomFurniture.class, "(remove|delete) [custom] (ia|itemsadder) furniture [%customitemtypes/strings%] at %locations%"); } private Expression furnitureId; private Expression locations; + @SuppressWarnings("unchecked") + @Override + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { + furnitureId = (Expression) exprs[0]; + locations = (Expression) exprs[1]; + return true; + } + @Override protected void execute(Event e) { Location[] locs = locations.getAll(e); - String id = furnitureId != null ? furnitureId.getSingle(e) : null; + List customFurnitureIds = new ArrayList<>(); + + if (furnitureId != null) { + if (furnitureId.isSingle()) { + Object itemType = furnitureId.getSingle(e); + customFurnitureIds.add(Util.getCustomBlockId(itemType)); + } else { + for (Object itemType : furnitureId.getArray(e)) { + customFurnitureIds.add(Util.getCustomBlockId(itemType)); + } + } + } for (Location loc : locs) { - if (id != null && loc != null) { - CustomFurniture existingFurniture = CustomFurniture.byAlreadySpawned(loc.getBlock()); + for (String id : customFurnitureIds) { + if (id != null && loc != null) { + CustomFurniture existingFurniture = CustomFurniture.byAlreadySpawned(loc.getBlock()); - if (existingFurniture != null) { - existingFurniture.remove(false); + if (existingFurniture != null) { + existingFurniture.remove(false); + } } } } @@ -49,12 +74,4 @@ protected void execute(Event e) { public String toString(@Nullable Event e, boolean debug) { return "remove custom furniture " + (furnitureId != null ? furnitureId.toString(e, debug) : "") + " at " + locations.toString(e, debug); } - - @SuppressWarnings("unchecked") - @Override - public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { - furnitureId = (Expression) exprs[0]; - locations = (Expression) exprs[1]; - return true; - } } diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/furniture/EffReplaceCustomFurniture.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/furniture/EffReplaceCustomFurniture.java deleted file mode 100644 index 18599d5..0000000 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/furniture/EffReplaceCustomFurniture.java +++ /dev/null @@ -1,58 +0,0 @@ -package me.asleepp.SkriptItemsAdder.elements.effects.furniture; - -import ch.njol.skript.Skript; -import ch.njol.skript.doc.Description; -import ch.njol.skript.doc.Examples; -import ch.njol.skript.doc.Name; -import ch.njol.skript.doc.Since; -import ch.njol.skript.lang.Effect; -import ch.njol.skript.lang.Expression; -import ch.njol.skript.lang.SkriptParser; -import ch.njol.util.Kleenean; -import org.bukkit.event.Event; -import dev.lone.itemsadder.api.CustomFurniture; -import org.bukkit.Location; -import org.bukkit.entity.Entity; - -import javax.annotation.Nullable; - -@Name("Replace Custom Furniture") -@Description({"If there is furniture at a location, this effect will remove it and place the one you specify."}) -@Examples({"replace custom furniture \"furniture:comfy_chair\" at player's location"}) -@Since("1.4") -public class EffReplaceCustomFurniture extends Effect { - - private Expression furnitureId; - private Expression location; - - static { - Skript.registerEffect(EffReplaceCustomFurniture.class, "replace [custom] (ia|itemsadder) furniture %string% at %location%"); - } - - @Override - protected void execute(Event e) { - String id = furnitureId.getSingle(e); - Location loc = location.getSingle(e); - if (id != null && loc != null) { - CustomFurniture existingFurniture = CustomFurniture.byAlreadySpawned(loc.getBlock()); - if (existingFurniture != null) { - Entity armorStand = existingFurniture.getArmorstand(); - Location originalLocation = armorStand.getLocation(); - existingFurniture.replaceFurniture(id); - existingFurniture.teleport(originalLocation); - } - } - } - - @Override - public String toString(@Nullable Event e, boolean debug) { - return "replace itemsadder furniture " + furnitureId.toString(e, debug) + " at " + location.toString(e, debug); - } - - @Override - public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { - furnitureId = (Expression) exprs[0]; - location = (Expression) exprs[1]; - return true; - } -} diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockBreak.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockBreak.java index d1789ab..5cf6160 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockBreak.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockBreak.java @@ -25,11 +25,6 @@ import java.util.List; import java.util.stream.Collectors; -@Name("On Custom Block Break") -@Description({"Fires when a ItemsAdder block gets broken."}) -@Examples({"on break of custom block \"namespace:ruby_block\":", "on break of custom block ruby block:"}) -@Since("1.0") -@RequiredPlugins("ItemsAdder") public class EvtCustomBlockBreak extends SkriptEvent { private Literal[] blockNames; @@ -37,7 +32,14 @@ public class EvtCustomBlockBreak extends SkriptEvent { private AliasesGenerator aliasesGenerator = SkriptItemsAdder.getInstance().getAliasesGenerator(); static { - Skript.registerEvent("Custom Block Break", EvtCustomBlockBreak.class, CustomBlockBreakEvent.class, "break [of] [custom] (ia|itemsadder) block[s] [%customitemtypes/strings%]"); + Skript.registerEvent("Custom Block Break", EvtCustomBlockBreak.class, CustomBlockBreakEvent.class, "break [of] [custom] (ia|itemsadder) block[s] [%customitemtypes/strings%]") + .description("Fires when a ItemsAdder block gets broken.") + .examples( + "on break of itemsadder block \"namespace:ruby_block\":", + "on break of itemsadder block ruby block:" + ) + .since("1.0") + .requiredPlugins("ItemsAdder"); EventValues.registerEventValue(CustomBlockBreakEvent.class, CustomBlock.class, new Getter() { @Override public CustomBlock get(CustomBlockBreakEvent event) { @@ -59,7 +61,7 @@ public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseRes if (blockNames != null) { aliases = Arrays.stream(blockNames) .map(literal -> { - if (literal instanceof Literal) { + if (literal != null) { Object value = literal.getSingle(); return Util.getCustomBlockId(value); } diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockInteract.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockInteract.java index 6219fc4..3a848b1 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockInteract.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockInteract.java @@ -26,11 +26,6 @@ import java.util.stream.Collectors; -@Name("On Custom Block Interact") -@Description({"Fires when a ItemsAdder block gets interacted with."}) -@Examples({"on interact with custom block:"}) -@Since("1.0") -@RequiredPlugins("ItemsAdder") public class EvtCustomBlockInteract extends SkriptEvent { private Literal[] blockNames; @@ -38,7 +33,11 @@ public class EvtCustomBlockInteract extends SkriptEvent { private AliasesGenerator aliasesGenerator = SkriptItemsAdder.getInstance().getAliasesGenerator(); static { - Skript.registerEvent("Custom Block Interact", EvtCustomBlockInteract.class, CustomBlockInteractEvent.class, "interact with [custom] (ia|itemsadder) block[s] [%customitemtypes/strings%]"); + Skript.registerEvent("Custom Block Interact", EvtCustomBlockInteract.class, CustomBlockInteractEvent.class, "interact with [custom] (ia|itemsadder) block[s] [%customitemtypes/strings%]") + .description("Fires when a ItemsAdder block gets interacted with.") + .examples("on interact with itemsadder block:") + .since("1.0") + .requiredPlugins("ItemsAdder"); EventValues.registerEventValue(CustomBlockInteractEvent.class, CustomBlock.class, new Getter() { @Override public CustomBlock get(CustomBlockInteractEvent event) { diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockPlace.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockPlace.java index a4bb093..a15d932 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockPlace.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockPlace.java @@ -25,11 +25,6 @@ import java.util.List; import java.util.stream.Collectors; -@Name("On Custom Block Place") -@Description({"Fires when a ItemsAdder block gets placed."}) -@Examples({"on place of custom block:"}) -@Since("1.0") -@RequiredPlugins("ItemsAdder") public class EvtCustomBlockPlace extends SkriptEvent { private Literal[] blockNames; @@ -37,7 +32,11 @@ public class EvtCustomBlockPlace extends SkriptEvent { private final AliasesGenerator aliasesGenerator = SkriptItemsAdder.getInstance().getAliasesGenerator(); static { - Skript.registerEvent("Custom Block Place", EvtCustomBlockPlace.class, CustomBlockPlaceEvent.class, "place [of] [custom] (ia|itemsadder) block[s] [%customitemtypes/strings%]"); + Skript.registerEvent("Custom Block Place", EvtCustomBlockPlace.class, CustomBlockPlaceEvent.class, "place [of] [custom] (ia|itemsadder) block[s] [%customitemtypes/strings%]") + .description("Fires when a ItemsAdder block gets placed.") + .examples("on place of itemsadder block:") + .since("1.0") + .requiredPlugins("ItemsAdder"); EventValues.registerEventValue(CustomBlockPlaceEvent.class, CustomBlock.class, new Getter() { @Override public CustomBlock get(CustomBlockPlaceEvent event) { diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureBreak.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureBreak.java index bd94260..b7fee7c 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureBreak.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureBreak.java @@ -25,11 +25,6 @@ import java.util.List; import java.util.stream.Collectors; -@Name("On Custom Furniture Break") -@Description({"Fires when a ItemsAdder furniture gets broken."}) -@Examples({"on break of custom furniture:"}) -@Since("1.0") -@RequiredPlugins("ItemsAdder") public class EvtCustomFurnitureBreak extends SkriptEvent { private Literal[] furnitureIDs; @@ -37,7 +32,11 @@ public class EvtCustomFurnitureBreak extends SkriptEvent { private AliasesGenerator aliasesGenerator = SkriptItemsAdder.getInstance().getAliasesGenerator(); static { - Skript.registerEvent("Custom Furniture Break", EvtCustomFurnitureBreak.class, FurnitureBreakEvent.class, "break of [custom] (ia|itemsadder) furniture [%customitemtypes/strings%]"); + Skript.registerEvent("Custom Furniture Break", EvtCustomFurnitureBreak.class, FurnitureBreakEvent.class, "break of [custom] (ia|itemsadder) furniture [%customitemtypes/strings%]") + .description("Fires when a ItemsAdder furniture gets broken.") + .examples("on break of itemsadder furniture:") + .since("1.0") + .requiredPlugins("ItemsAdder"); EventValues.registerEventValue(FurnitureBreakEvent.class, Location.class, new Getter() { @Override public @Nullable Location get(FurnitureBreakEvent event) { diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureInteract.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureInteract.java index b880c6a..0a6082b 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureInteract.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureInteract.java @@ -26,11 +26,6 @@ import java.util.List; import java.util.stream.Collectors; -@Name("On Custom Furniture Interact") -@Description({"Fires when a ItemsAdder furniture gets interacted with."}) -@Examples({"on interact with custom furniture:"}) -@Since("1.0") -@RequiredPlugins("ItemsAdder") public class EvtCustomFurnitureInteract extends SkriptEvent { private Literal[] furnitureIDs; @@ -38,7 +33,11 @@ public class EvtCustomFurnitureInteract extends SkriptEvent { private AliasesGenerator aliasesGenerator = SkriptItemsAdder.getInstance().getAliasesGenerator(); static { - Skript.registerEvent("Custom Furniture Interact", EvtCustomFurnitureInteract.class, FurnitureInteractEvent.class, "interact with [custom] (ia|itemsadder) furniture [%customitemtypes/strings%]"); + Skript.registerEvent("Custom Furniture Interact", EvtCustomFurnitureInteract.class, FurnitureInteractEvent.class, "interact with [custom] (ia|itemsadder) furniture [%customitemtypes/strings%]") + .description("Fires when a ItemsAdder furniture gets interacted with.") + .examples("on interact with itemsadder furniture:") + .since("1.0") + .requiredPlugins("ItemsAdder"); EventValues.registerEventValue(FurnitureInteractEvent.class, Location.class, new Getter() { @Override public @Nullable Location get(FurnitureInteractEvent event) { diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurniturePlace.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurniturePlace.java index 0c754e4..9f3249d 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurniturePlace.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurniturePlace.java @@ -22,11 +22,6 @@ import java.util.List; import java.util.stream.Collectors; -@Name("On Custom Furniture Place") -@Description({"Fires when a ItemsAdder furniture gets placed."}) -@Examples({"on place of custom furniture:"}) -@Since("1.0") -@RequiredPlugins("ItemsAdder") public class EvtCustomFurniturePlace extends SkriptEvent { private Literal[] furnitureIDs; @@ -34,7 +29,11 @@ public class EvtCustomFurniturePlace extends SkriptEvent { private AliasesGenerator aliasesGenerator = SkriptItemsAdder.getInstance().getAliasesGenerator(); static { - Skript.registerEvent("Custom Furniture Place", EvtCustomFurniturePlace.class, FurniturePlaceEvent.class, "place [of] [custom] (ia|itemsadder) furniture [%customitemtypes/strings%]"); + Skript.registerEvent("Custom Furniture Place", EvtCustomFurniturePlace.class, FurniturePlaceEvent.class, "place [of] [custom] (ia|itemsadder) furniture [%customitemtypes/strings%]") + .description("Fires when a ItemsAdder furniture gets placed.") + .examples("on place of itemsadder furniture:") + .since("1.0") + .requiredPlugins("ItemsAdder"); } @SuppressWarnings("unchecked") diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureSuccessEvent.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureSuccessEvent.java index 7e7e9bb..32768e0 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureSuccessEvent.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureSuccessEvent.java @@ -26,11 +26,6 @@ import java.util.List; import java.util.stream.Collectors; -@Name("Furniture Place Success") -@Description("This event is called when a furniture is successfully placed into the world, use this event instead if you would like to know the location, etc.") -@Examples({"on place success of custom itemsadder furniture:", "on successfully placing a custom itemsadder furniture:"}) -@Since("1.5") -@RequiredPlugins("ItemsAdder") public class EvtCustomFurnitureSuccessEvent extends SkriptEvent { private Literal[] furnitureIDs; @@ -40,7 +35,14 @@ public class EvtCustomFurnitureSuccessEvent extends SkriptEvent { static { Skript.registerEvent("Custom Furniture Success", EvtCustomFurnitureSuccessEvent.class, FurniturePlaceSuccessEvent.class, "success[fully] plac(e|ing) [a] [custom] (ia|itemsadder) furniture [%customitemtypes/strings%]", - "place success [of] [custom] (ia|itemsadder) furniture [%customitemtypes/strings%]"); + "place success [of] [custom] (ia|itemsadder) furniture [%customitemtypes/strings%]") + .description("This event is called when a furniture is successfully placed into the world, use this event instead if you would like to know the location.") + .examples( + "on place success of custom itemsadder furniture:", + "on successfully placing a custom itemsadder furniture:" + ) + .since("1.5") + .requiredPlugins("ItemsAdder"); EventValues.registerEventValue(FurniturePlaceSuccessEvent.class, Location.class, new Getter() { @Override public Location get(FurniturePlaceSuccessEvent arg) { diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/other/EvtCustomEntityDeath.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/other/EvtCustomEntityDeath.java index 771a1d5..0bc2bf1 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/other/EvtCustomEntityDeath.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/other/EvtCustomEntityDeath.java @@ -26,7 +26,11 @@ public class EvtCustomEntityDeath extends SkriptEvent { private Literal mobID; static { - Skript.registerEvent("Custom Entity Death", EvtCustomEntityDeath.class, CustomEntityDeathEvent.class, "[custom] (ia|itemsadder) entity death [of %string%]"); + Skript.registerEvent("Custom Entity Death", EvtCustomEntityDeath.class, CustomEntityDeathEvent.class, "[custom] (ia|itemsadder) entity death [of %string%]") + .description("Fires when a ItemsAdder Entity dies.") + .examples("on itemsadder entity death:") + .since("1.0") + .requiredPlugins("ItemsAdder"); EventValues.registerEventValue(CustomEntityDeathEvent.class, Entity.class, new Getter() { @Override public @Nullable Entity get(CustomEntityDeathEvent customEntityDeathEvent) { diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/other/EvtEmote.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/other/EvtEmote.java index 22a6930..a7b5a2e 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/other/EvtEmote.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/other/EvtEmote.java @@ -21,7 +21,11 @@ public class EvtEmote extends SkriptEvent { static { Skript.registerEvent("Emote Play/Stop", EvtEmote.class, CollectionUtils.array(PlayerEmotePlayEvent.class, PlayerEmoteEndEvent.class), "(perform|play[ing]) [of] [custom] (ia|itemsadder) emote [%strings%]", - "(stop|cancel[ing]) [of] [custom] (ia|itemsadder) emote [%strings%] [due to (:stop[ped]|:finish[ed]) [emote]]"); + "(stop|cancel[ing]) [of] [custom] (ia|itemsadder) emote [%strings%] [due to (:stop[ped]|:finish[ed]) [emote]]") + .description("Called when a player begins to perform an emote.") + .examples("on perform custom itemsadder emote:") + .since("1.6") + .requiredPlugins("ItemsAdder"); } @Override diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/other/EvtResourcePackSendEvent.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/other/EvtResourcePackSendEvent.java index fc097d7..86abed2 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/other/EvtResourcePackSendEvent.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/other/EvtResourcePackSendEvent.java @@ -13,17 +13,20 @@ import org.bukkit.event.Event; import javax.annotation.Nullable; -@Name("On Resource Pack Send") -@Description({"Fires when a Resource pack gets sent to the player."}) -@Examples({"on resource pack send:", "on ia resource pack send:"}) -@Since("1.0") -@RequiredPlugins("ItemsAdder") + public class EvtResourcePackSendEvent extends SkriptEvent { private boolean isItemsAdderPack; static { - Skript.registerEvent("Resource Pack Send Event", EvtResourcePackSendEvent.class, ResourcePackSendEvent.class, "[custom] [ia|itemsadder] (texture|resource) pack send"); + Skript.registerEvent("ItemsAdder Resource Pack Send Event", EvtResourcePackSendEvent.class, ResourcePackSendEvent.class, "[custom] [ia|itemsadder] (texture|resource) pack send") + .description("Fires when a Resource pack from ItemsAdder gets sent to the player.") + .examples( + "on resource pack send:", + "on ia resource pack send:" + ) + .since("1.0") + .requiredPlugins("ItemsAdder"); } @Override diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprCropAge.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprCropAge.java index 1a307f5..df06e51 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprCropAge.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprCropAge.java @@ -2,17 +2,28 @@ import ch.njol.skript.Skript; import ch.njol.skript.classes.Changer; +import ch.njol.skript.doc.Examples; +import ch.njol.skript.doc.RequiredPlugins; +import ch.njol.skript.doc.Since; import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.ExpressionType; import ch.njol.skript.lang.SkriptParser; import ch.njol.skript.lang.util.SimpleExpression; import ch.njol.util.Kleenean; import dev.lone.itemsadder.api.CustomCrop; +import jdk.jfr.Description; +import jdk.jfr.Name; import org.bukkit.block.Block; import org.bukkit.event.Event; import javax.annotation.Nullable; +@Name("Crop Age") +@Description("Get or Set the age of a crop, or get the maximum age of one.") +@Examples("send maximum age of custom itemsadder block {_crop}") +@Since("1.6") +@RequiredPlugins("ItemsAdder") + public class ExprCropAge extends SimpleExpression { private Expression block; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetID.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetID.java index 7f4709b..c5693c7 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetID.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetID.java @@ -1,6 +1,9 @@ package me.asleepp.SkriptItemsAdder.elements.expressions; import ch.njol.skript.Skript; +import ch.njol.skript.doc.Examples; +import ch.njol.skript.doc.RequiredPlugins; +import ch.njol.skript.doc.Since; import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.ExpressionType; import ch.njol.skript.lang.SkriptParser; @@ -9,6 +12,8 @@ import dev.lone.itemsadder.api.CustomBlock; import dev.lone.itemsadder.api.CustomEntity; import dev.lone.itemsadder.api.CustomStack; +import jdk.jfr.Description; +import jdk.jfr.Name; import org.bukkit.block.Block; import org.bukkit.entity.Entity; import org.bukkit.event.Event; @@ -18,12 +23,17 @@ import java.util.ArrayList; import java.util.List; +@Name("Get ID") +@Description("Gets the Namespaced:ID of your blocks, furnitures, or items.") +@Examples("send id of itemsadder item player's tool") +@Since("1.6") +@RequiredPlugins("ItemsAdder") public class ExprGetID extends SimpleExpression { private Expression expr; static { - Skript.registerExpression(ExprGetID.class, String.class, ExpressionType.SIMPLE, "id of [custom] (ia|itemsadder) %itemstacks/blocks/entities%"); + Skript.registerExpression(ExprGetID.class, String.class, ExpressionType.SIMPLE, "id of [custom] (ia|itemsadder) [item|block|furniture] %itemstacks/blocks/entities%"); } @Override @@ -33,8 +43,8 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye } @Override - protected String[] get(Event e) { - Object[] objects = expr.getArray(e); + protected String[] get(Event event) { + Object[] objects = expr.getArray(event); List ids = new ArrayList<>(); for (Object object : objects) { if (object instanceof ItemStack) { From 063dbec07ff1a8fce498e7950d688cfecd98d0e1 Mon Sep 17 00:00:00 2001 From: Asleepp <119438940+Asleeepp@users.noreply.github.com> Date: Wed, 11 Sep 2024 21:12:15 -0300 Subject: [PATCH 10/10] Final Commit (hopefully) --- build.gradle.kts | 1 - .../SkriptItemsAdder/SkriptItemsAdder.java | 16 ++--- .../{other => }/aliases/AliasesGenerator.java | 2 +- .../{other => }/aliases/CustomItemType.java | 4 +- .../elements/conditions/CondCooldown.java | 51 -------------- .../elements/conditions/CondGetAction.java | 63 ----------------- .../elements/conditions/CondGetBlockFace.java | 70 ------------------- .../elements/conditions/CondHUDExists.java | 2 +- .../elements/conditions/CondHUDIsVisible.java | 14 +++- .../conditions/CondIsCustomBlock.java | 7 +- .../elements/conditions/CondIsCustomItem.java | 2 +- .../elements/conditions/CondIsFullyGrown.java | 2 +- .../elements/effects/EffDamageEffect.java | 4 -- .../elements/effects/EffUpdateHUD.java | 2 +- .../effects/blocks/EffPlaceBlockOrCrop.java | 5 +- .../effects/blocks/EffSetBlocksBetween.java | 24 ++++--- .../furniture/EffPlaceCustomFurniture.java | 2 +- .../furniture/EffRemoveCustomFurniture.java | 2 +- .../events/blocks/EvtCustomBlockBreak.java | 19 ++--- .../events/blocks/EvtCustomBlockInteract.java | 39 +++++++---- .../events/blocks/EvtCustomBlockPlace.java | 21 +++--- .../furniture/EvtCustomFurnitureBreak.java | 19 ++--- .../furniture/EvtCustomFurnitureInteract.java | 19 ++--- .../furniture/EvtCustomFurniturePlace.java | 19 ++--- .../EvtCustomFurnitureSuccessEvent.java | 19 ++--- .../elements/expressions/ExprCropAge.java | 2 +- .../expressions/ExprGetCustomItem.java | 2 +- .../elements/types/Types.java | 44 ++++++++++-- .../listeners/ItemsAdderEventListener.java | 4 +- .../{other => }/util/Metrics.java | 2 +- .../util/SkriptItemsAdderCommand.java | 4 +- .../{other => }/util/UpdateChecker.java | 9 ++- .../{other => }/util/Util.java | 4 +- src/main/resources/lang/english.lang | 32 ++++++++- 34 files changed, 196 insertions(+), 335 deletions(-) rename src/main/java/me/asleepp/SkriptItemsAdder/{other => }/aliases/AliasesGenerator.java (99%) rename src/main/java/me/asleepp/SkriptItemsAdder/{other => }/aliases/CustomItemType.java (93%) delete mode 100644 src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondCooldown.java delete mode 100644 src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondGetAction.java delete mode 100644 src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondGetBlockFace.java rename src/main/java/me/asleepp/SkriptItemsAdder/{other => }/listeners/ItemsAdderEventListener.java (88%) rename src/main/java/me/asleepp/SkriptItemsAdder/{other => }/util/Metrics.java (99%) rename src/main/java/me/asleepp/SkriptItemsAdder/{other => }/util/SkriptItemsAdderCommand.java (97%) rename src/main/java/me/asleepp/SkriptItemsAdder/{other => }/util/UpdateChecker.java (79%) rename src/main/java/me/asleepp/SkriptItemsAdder/{other => }/util/Util.java (94%) diff --git a/build.gradle.kts b/build.gradle.kts index 88fcb5a..0fd5b87 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -97,7 +97,6 @@ tasks { downloadPlugins { url("https://download.luckperms.net/1552/bukkit/loader/LuckPerms-Bukkit-5.4.137.jar") - url("https://ci.lucko.me/job/spark/439/artifact/spark-bukkit/build/libs/spark-1.10.93-bukkit.jar") url("https://github.com/SkriptLang/Skript/releases/download/2.9.1/Skript-2.9.1.jar") url("https://github.com/dmulloy2/ProtocolLib/releases/download/5.2.0/ProtocolLib.jar") url("https://github.com/LoneDev6/SpigotUtilities/raw/master/LoneLibs.jar") diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/SkriptItemsAdder.java b/src/main/java/me/asleepp/SkriptItemsAdder/SkriptItemsAdder.java index b808d8f..d447d05 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/SkriptItemsAdder.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/SkriptItemsAdder.java @@ -4,20 +4,18 @@ import ch.njol.skript.util.Version; import lombok.Getter; -import lombok.Setter; -import me.asleepp.SkriptItemsAdder.other.aliases.AliasesGenerator; -import me.asleepp.SkriptItemsAdder.other.listeners.ItemsAdderEventListener; -import me.asleepp.SkriptItemsAdder.other.util.Metrics; -import me.asleepp.SkriptItemsAdder.other.util.SkriptItemsAdderCommand; -import me.asleepp.SkriptItemsAdder.other.util.UpdateChecker; -import me.asleepp.SkriptItemsAdder.other.util.Util; +import me.asleepp.SkriptItemsAdder.aliases.AliasesGenerator; +import me.asleepp.SkriptItemsAdder.listeners.ItemsAdderEventListener; +import me.asleepp.SkriptItemsAdder.util.Metrics; +import me.asleepp.SkriptItemsAdder.util.SkriptItemsAdderCommand; +import me.asleepp.SkriptItemsAdder.util.UpdateChecker; +import me.asleepp.SkriptItemsAdder.util.Util; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import ch.njol.skript.Skript; import ch.njol.skript.SkriptAddon; -import org.bukkit.scheduler.BukkitRunnable; import javax.annotation.Nullable; @@ -49,7 +47,7 @@ public void onEnable() { getLogger().severe("Could not find Skript! Disabling..."); manager.disablePlugin(this); return; - } else if (Skript.getVersion().compareTo(new Version(2, 7, 0)) < 0) { + } else if (Skript.getVersion().isSmallerThan(new Version(2, 7, 0))) { getLogger().severe("You are running an unsupported version of Skript. Disabling..."); manager.disablePlugin(this); return; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/other/aliases/AliasesGenerator.java b/src/main/java/me/asleepp/SkriptItemsAdder/aliases/AliasesGenerator.java similarity index 99% rename from src/main/java/me/asleepp/SkriptItemsAdder/other/aliases/AliasesGenerator.java rename to src/main/java/me/asleepp/SkriptItemsAdder/aliases/AliasesGenerator.java index 5abd8d0..b02ee7a 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/other/aliases/AliasesGenerator.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/aliases/AliasesGenerator.java @@ -1,4 +1,4 @@ -package me.asleepp.SkriptItemsAdder.other.aliases; +package me.asleepp.SkriptItemsAdder.aliases; import ch.njol.skript.Skript; import ch.njol.skript.aliases.Aliases; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/other/aliases/CustomItemType.java b/src/main/java/me/asleepp/SkriptItemsAdder/aliases/CustomItemType.java similarity index 93% rename from src/main/java/me/asleepp/SkriptItemsAdder/other/aliases/CustomItemType.java rename to src/main/java/me/asleepp/SkriptItemsAdder/aliases/CustomItemType.java index 8771f61..0d72bca 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/other/aliases/CustomItemType.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/aliases/CustomItemType.java @@ -1,4 +1,4 @@ -package me.asleepp.SkriptItemsAdder.other.aliases; +package me.asleepp.SkriptItemsAdder.aliases; import lombok.Getter; import lombok.Setter; @@ -13,6 +13,8 @@ public class CustomItemType { private String namespacedID; + public CustomItemType() { } + public CustomItemType(String namespacedID) { this.namespacedID = namespacedID; } diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondCooldown.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondCooldown.java deleted file mode 100644 index 2a75b38..0000000 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondCooldown.java +++ /dev/null @@ -1,51 +0,0 @@ -package me.asleepp.SkriptItemsAdder.elements.conditions; - -import ch.njol.skript.Skript; -import ch.njol.skript.lang.Condition; -import ch.njol.skript.lang.Expression; -import ch.njol.skript.lang.SkriptParser; -import ch.njol.util.Kleenean; -import dev.lone.itemsadder.api.CustomStack; -import org.bukkit.event.Event; -import org.bukkit.inventory.ItemStack; - -import javax.annotation.Nullable; - -public class CondCooldown extends Condition { - - private Expression itemStackExpression; - - static { - Skript.registerCondition(CondCooldown.class, "[custom] [ia|itemsadder] %itemstacks% has [a] permission [associated [with it]]"); - } - - @Override - public boolean init(Expression[] exprs, int i, Kleenean kleenean, SkriptParser.ParseResult parseResult) { - itemStackExpression = (Expression) exprs[0]; - return true; - } - - @Override - public boolean check(Event event) { - ItemStack[] itemStacks = itemStackExpression.getArray(event); - - if (itemStacks == null) { - return false; - } - - for (ItemStack itemStack : itemStacks) { - CustomStack customStack = CustomStack.byItemStack(itemStack); - if (!(customStack == null)) { - return customStack.hasPermission(); - } - } - - return true; - } - - @Override - public String toString(@Nullable Event event, boolean debug) { - return itemStackExpression.toString(event, debug) + "has a permission associated with it"; - } - -} diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondGetAction.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondGetAction.java deleted file mode 100644 index 8c095e0..0000000 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondGetAction.java +++ /dev/null @@ -1,63 +0,0 @@ -package me.asleepp.SkriptItemsAdder.elements.conditions; - -import ch.njol.skript.Skript; -import ch.njol.skript.doc.Description; -import ch.njol.skript.doc.Examples; -import ch.njol.skript.doc.Name; -import ch.njol.skript.doc.RequiredPlugins; -import ch.njol.skript.doc.Since; -import ch.njol.skript.lang.Condition; -import ch.njol.skript.lang.Expression; -import ch.njol.skript.lang.SkriptParser; -import ch.njol.util.Kleenean; -import org.bukkit.event.Event; -import dev.lone.itemsadder.api.Events.CustomBlockInteractEvent; -import org.bukkit.event.block.Action; - -import javax.annotation.Nullable; -@Name("Is Action") -@Description({"This condition checks if the player has interacted with a custom block with either a left or a right click."}) -@Examples({ - "on interact with custom block:", - "\tif itemsadder interact action is right click:", - "\t\tkill event-player"}) -@Since("1.4") -@RequiredPlugins("ItemsAdder") -public class CondGetAction extends Condition { - - static { - Skript.registerCondition(CondGetAction.class, "[custom] (ia|itemsadder) [interact] action is (right|:left) click"); - } - - private boolean isLeft; - - @Override - public boolean check(Event e) { - if (!(e instanceof CustomBlockInteractEvent)) { - return false; - } - CustomBlockInteractEvent event = (CustomBlockInteractEvent) e; - if (isLeft) { - return event.getAction() == Action.LEFT_CLICK_BLOCK; - } else { - return event.getAction() == Action.RIGHT_CLICK_BLOCK; - } - } - - - @Override - public String toString(@Nullable Event e, boolean debug) { - return "interact action is " + (isLeft ? "left" : "right") + " click"; - } - - @Override - public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { - if (!getParser().isCurrentEvent(CustomBlockInteractEvent.class)) { - Skript.error("You can't use 'interact action is (:right|:left) click' outside of a custom block interact event!"); - return false; - } - isLeft = parseResult.hasTag("left"); - return true; - } - -} diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondGetBlockFace.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondGetBlockFace.java deleted file mode 100644 index d035b62..0000000 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondGetBlockFace.java +++ /dev/null @@ -1,70 +0,0 @@ -package me.asleepp.SkriptItemsAdder.elements.conditions; - -import ch.njol.skript.Skript; -import ch.njol.skript.doc.Description; -import ch.njol.skript.doc.Examples; -import ch.njol.skript.doc.Name; -import ch.njol.skript.doc.RequiredPlugins; -import ch.njol.skript.doc.Since; -import ch.njol.skript.lang.Condition; -import ch.njol.skript.lang.Expression; -import ch.njol.skript.lang.SkriptParser; -import ch.njol.util.Kleenean; -import dev.lone.itemsadder.api.Events.CustomBlockInteractEvent; -import org.bukkit.block.BlockFace; -import org.bukkit.event.Event; - -import javax.annotation.Nullable; -@Name("Is Block Face") -@Description({"This condition checks what face of a block the player has interacted with."}) -@Examples({ - "on interact with custom block:", - "\tif clicked block face is south:", - "\t\tsend \"Why are you doing that?\""}) -@Since("1.4") -@RequiredPlugins("ItemsAdder") -public class CondGetBlockFace extends Condition { - - static { - Skript.registerCondition(CondGetBlockFace.class, "[clicked] block face is (:down|:north|:south|:east|:west|:up)"); - } - - private BlockFace face; - - @Override - public boolean check(Event e) { - if (!(e instanceof CustomBlockInteractEvent)) { - return false; - } - CustomBlockInteractEvent event = (CustomBlockInteractEvent) e; - return event.getBlockFace() == face; - } - - - @Override - public String toString(@Nullable Event e, boolean debug) { - return "clicked block face is " + face.toString(); - } - - @Override - public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { - if (!getParser().isCurrentEvent(CustomBlockInteractEvent.class)) { - Skript.error("You can't use 'clicked block face is (:down|:north|:south|:east|:west|:up)' outside of a custom block interact event!"); - return false; - } - if (parseResult.hasTag("north")) { - face = BlockFace.NORTH; - } else if (parseResult.hasTag("south")) { - face = BlockFace.SOUTH; - } else if (parseResult.hasTag("east")) { - face = BlockFace.EAST; - } else if (parseResult.hasTag("west")) { - face = BlockFace.WEST; - } else if (parseResult.hasTag("up")) { - face = BlockFace.UP; - } else if (parseResult.hasTag("down")) { - face = BlockFace.DOWN; - } - return true; - } -} diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondHUDExists.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondHUDExists.java index 091ed25..b84b239 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondHUDExists.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondHUDExists.java @@ -33,7 +33,7 @@ public boolean check(Event event) { String id = hudID.getSingle(event); Player[] playersArray = players != null ? players.getArray(event) : new Player[]{}; - if (id != null && playersArray.length > 0) { + if (id != null) { for (Player player : playersArray) { PlayerHudsHolderWrapper hudHolder = new PlayerHudsHolderWrapper(player); PlayerHudWrapper hudWrapper = new PlayerHudWrapper(hudHolder, id); diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondHUDIsVisible.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondHUDIsVisible.java index a137840..621f31f 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondHUDIsVisible.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondHUDIsVisible.java @@ -1,6 +1,11 @@ package me.asleepp.SkriptItemsAdder.elements.conditions; import ch.njol.skript.Skript; +import ch.njol.skript.doc.Description; +import ch.njol.skript.doc.Examples; +import ch.njol.skript.doc.Name; +import ch.njol.skript.doc.RequiredPlugins; +import ch.njol.skript.doc.Since; import ch.njol.skript.lang.Condition; import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser; @@ -12,6 +17,11 @@ import javax.annotation.Nullable; +@Name("HUD Is Visible") +@Description("Determines whether players can see a hud/if a hud is active.") +@Examples("if player can see itemsadder hud \"namespaced:id\"") +@Since("1.6") +@RequiredPlugins("ItemsAdder") public class CondHUDIsVisible extends Condition { private Expression players; @@ -33,7 +43,7 @@ public boolean check(Event event) { Player[] p = players.getArray(event); String id = hudID.getSingle(event); - if (p != null && id != null) { + if (id != null) { for (Player players : p) { PlayerHudsHolderWrapper hudsHolder = new PlayerHudsHolderWrapper(players); PlayerHudWrapper hudWrapper = new PlayerHudWrapper(hudsHolder, id); @@ -46,6 +56,6 @@ public boolean check(Event event) { @Override public String toString(@Nullable Event event, boolean debug) { - return "player(s) " + players.toString(event, debug) + "can view itemsadder hud " + hudID.toString(event, debug); + return players.toString(event, debug) + "can view itemsadder hud " + hudID.toString(event, debug); } } diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomBlock.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomBlock.java index a2cef3a..425552e 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomBlock.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomBlock.java @@ -11,12 +11,11 @@ import ch.njol.skript.lang.SkriptParser; import ch.njol.util.Kleenean; import dev.lone.itemsadder.api.CustomBlock; -import me.asleepp.SkriptItemsAdder.other.aliases.CustomItemType; +import me.asleepp.SkriptItemsAdder.aliases.CustomItemType; import org.bukkit.block.Block; import org.bukkit.event.Event; import javax.annotation.Nullable; -import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; @@ -39,7 +38,7 @@ public class CondIsCustomBlock extends Condition { static { Skript.registerCondition(CondIsCustomBlock.class, "%blocks% (is [a[n]]|are) [custom] (ia|itemsadder) block[s] [[with id] %-customitemtypes/strings%]", - "%blocks% (is[n't| not]) [a] [custom] (ia|itemsadder) block[s] [[with id] %-customitemtypes/strings%]"); + "%blocks% (isn't|is not|aren't|are not) [a] [custom] (ia|itemsadder) block[s] [[with id] %-customitemtypes/strings%]"); } @SuppressWarnings("unchecked") @@ -53,7 +52,7 @@ public boolean init(Expression[] expressions, int matchedPattern, Kleenean is @Override public boolean check(Event event) { - List expectedIds = Arrays.stream(ids.getArray(event)) + List expectedIds = ids.stream(event) .map(id -> { if (id instanceof CustomItemType) { return ((CustomItemType) id).getNamespacedID(); diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomItem.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomItem.java index 0480796..961a461 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomItem.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomItem.java @@ -13,7 +13,7 @@ import org.bukkit.event.Event; import org.bukkit.inventory.ItemStack; import dev.lone.itemsadder.api.CustomStack; -import me.asleepp.SkriptItemsAdder.other.aliases.CustomItemType; +import me.asleepp.SkriptItemsAdder.aliases.CustomItemType; import javax.annotation.Nullable; import java.util.Arrays; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsFullyGrown.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsFullyGrown.java index 5766c0c..abde8db 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsFullyGrown.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsFullyGrown.java @@ -18,7 +18,7 @@ public class CondIsFullyGrown extends Condition { static { Skript.registerCondition(CondIsFullyGrown.class, "[the] [custom] (ia|itemsadder) %blocks% (is|are) full[y] grown", - "[the] [custom] (ia|itemsadder) %blocks% (is|are) not full[y] grown"); + "[the] [custom] (ia|itemsadder) %blocks% (isn't|is not|aren't|are not) full[y] grown"); } @Override diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffDamageEffect.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffDamageEffect.java index 0f3cdf4..4473964 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffDamageEffect.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffDamageEffect.java @@ -39,10 +39,6 @@ public boolean init(Expression[] exprs, int i, Kleenean kleenean, SkriptParse protected void execute(Event event) { Entity[] entities = entitiesExpr.getArray(event); - if (entities == null) { - return; - } - for (Entity entity : entities) { CustomEntity customEntity = CustomEntity.byAlreadySpawned(entity); if (!(customEntity == null)) { diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffUpdateHUD.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffUpdateHUD.java index 651e84b..879abb0 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffUpdateHUD.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffUpdateHUD.java @@ -16,7 +16,7 @@ public class EffUpdateHUD extends Effect { private Expression players; static { - Skript.registerEffect(EffUpdateHUD.class, "(update|refresh) %players%[`s] [current] [custom] (itemsadder|ia) hud"); + Skript.registerEffect(EffUpdateHUD.class, "(update|refresh) %players%'[s] [current] [custom] (itemsadder|ia) hud"); } @Override diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/blocks/EffPlaceBlockOrCrop.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/blocks/EffPlaceBlockOrCrop.java index 76cb108..62d7162 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/blocks/EffPlaceBlockOrCrop.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/blocks/EffPlaceBlockOrCrop.java @@ -13,8 +13,7 @@ import ch.njol.util.Kleenean; import dev.lone.itemsadder.api.CustomBlock; import dev.lone.itemsadder.api.CustomCrop; -import me.asleepp.SkriptItemsAdder.other.aliases.CustomItemType; -import me.asleepp.SkriptItemsAdder.other.util.Util; +import me.asleepp.SkriptItemsAdder.util.Util; import org.bukkit.Location; import org.bukkit.event.Event; @@ -79,7 +78,6 @@ protected void execute(Event e) { try { if (isCrop) { CustomCrop.place(customBlockId, location); - Skript.info("Placed custom crop with ID: " + customBlockId + " at location: " + location); } else { CustomBlock existingBlock = CustomBlock.byAlreadyPlaced(location.getBlock()); if (existingBlock != null) { @@ -88,7 +86,6 @@ protected void execute(Event e) { CustomBlock block = CustomBlock.getInstance(customBlockId); if (block != null) { block.place(location); - Skript.info("Placed custom block with ID: " + customBlockId + " at location: " + location); } else { Skript.error("Failed to get CustomBlock instance for ID: " + customBlockId); } diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/blocks/EffSetBlocksBetween.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/blocks/EffSetBlocksBetween.java index de5a602..f383e63 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/blocks/EffSetBlocksBetween.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/blocks/EffSetBlocksBetween.java @@ -12,12 +12,13 @@ import ch.njol.util.Kleenean; import dev.lone.itemsadder.api.CustomBlock; import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; -import me.asleepp.SkriptItemsAdder.other.aliases.AliasesGenerator; -import me.asleepp.SkriptItemsAdder.other.util.Util; +import me.asleepp.SkriptItemsAdder.aliases.AliasesGenerator; +import me.asleepp.SkriptItemsAdder.util.Util; import org.bukkit.Location; import org.bukkit.event.Event; import javax.annotation.Nullable; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; @@ -31,7 +32,6 @@ public class EffSetBlocksBetween extends Effect { private Expression location1Expr; private Expression location2Expr; private Expression customBlockIdExpr; - private List aliases; private AliasesGenerator aliasesGenerator = SkriptItemsAdder.getInstance().getAliasesGenerator(); static { @@ -43,14 +43,6 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye location1Expr = (Expression) exprs[0]; location2Expr = (Expression) exprs[1]; customBlockIdExpr = exprs[2]; - aliases = Arrays.stream(exprs) - .filter(expr -> expr instanceof Expression) - .map(expr -> { - Object value = ((Expression) expr).getSingle(null); - return Util.getCustomBlockId(value); - }) - .filter(name -> name != null) - .collect(Collectors.toList()); return true; } @@ -61,6 +53,16 @@ protected void execute(Event e) { Object customBlockIdObj = customBlockIdExpr.getSingle(e); String customBlockId = Util.getCustomBlockId(customBlockIdObj); + List customBlockIds = new ArrayList<>(); + if (customBlockIdExpr.isSingle()) { + Object itemType = customBlockIdExpr.getSingle(e); + customBlockIds.add(Util.getCustomBlockId(itemType)); + } else { + for (Object itemType : customBlockIdExpr.getArray(e)) { + customBlockIds.add(Util.getCustomBlockId(itemType)); + } + } + if (location1 == null || location2 == null || customBlockId == null) { return; } diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/furniture/EffPlaceCustomFurniture.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/furniture/EffPlaceCustomFurniture.java index 29d4bb0..8326bd0 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/furniture/EffPlaceCustomFurniture.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/furniture/EffPlaceCustomFurniture.java @@ -11,7 +11,7 @@ import ch.njol.skript.lang.SkriptParser; import ch.njol.util.Kleenean; import dev.lone.itemsadder.api.CustomFurniture; -import me.asleepp.SkriptItemsAdder.other.util.Util; +import me.asleepp.SkriptItemsAdder.util.Util; import org.bukkit.Location; import org.bukkit.entity.Entity; import org.bukkit.event.Event; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/furniture/EffRemoveCustomFurniture.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/furniture/EffRemoveCustomFurniture.java index b70e047..1ebf956 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/furniture/EffRemoveCustomFurniture.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/furniture/EffRemoveCustomFurniture.java @@ -11,7 +11,7 @@ import ch.njol.skript.lang.SkriptParser; import ch.njol.util.Kleenean; import dev.lone.itemsadder.api.CustomFurniture; -import me.asleepp.SkriptItemsAdder.other.util.Util; +import me.asleepp.SkriptItemsAdder.util.Util; import org.bukkit.Location; import org.bukkit.event.Event; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockBreak.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockBreak.java index 5cf6160..ae33570 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockBreak.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockBreak.java @@ -1,11 +1,6 @@ package me.asleepp.SkriptItemsAdder.elements.events.blocks; import ch.njol.skript.Skript; -import ch.njol.skript.doc.Description; -import ch.njol.skript.doc.Examples; -import ch.njol.skript.doc.Name; -import ch.njol.skript.doc.RequiredPlugins; -import ch.njol.skript.doc.Since; import ch.njol.skript.lang.Literal; import ch.njol.skript.lang.SkriptEvent; import ch.njol.skript.lang.SkriptParser; @@ -14,9 +9,8 @@ import dev.lone.itemsadder.api.CustomBlock; import dev.lone.itemsadder.api.Events.CustomBlockBreakEvent; import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; -import me.asleepp.SkriptItemsAdder.other.aliases.AliasesGenerator; -import me.asleepp.SkriptItemsAdder.other.aliases.CustomItemType; -import me.asleepp.SkriptItemsAdder.other.util.Util; +import me.asleepp.SkriptItemsAdder.aliases.AliasesGenerator; +import me.asleepp.SkriptItemsAdder.util.Util; import org.bukkit.Location; import org.bukkit.event.Event; @@ -24,6 +18,7 @@ import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; +import java.util.stream.Stream; public class EvtCustomBlockBreak extends SkriptEvent { @@ -60,12 +55,12 @@ public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseRes blockNames = args; if (blockNames != null) { aliases = Arrays.stream(blockNames) - .map(literal -> { + .flatMap(literal -> { if (literal != null) { - Object value = literal.getSingle(); - return Util.getCustomBlockId(value); + return Arrays.stream(literal.getArray()) + .map(Util::getCustomBlockId); } - return null; + return Stream.empty(); }) .filter(name -> name != null) .collect(Collectors.toList()); diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockInteract.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockInteract.java index 3a848b1..87e8efe 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockInteract.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockInteract.java @@ -1,11 +1,6 @@ package me.asleepp.SkriptItemsAdder.elements.events.blocks; import ch.njol.skript.Skript; -import ch.njol.skript.doc.Description; -import ch.njol.skript.doc.Examples; -import ch.njol.skript.doc.Name; -import ch.njol.skript.doc.RequiredPlugins; -import ch.njol.skript.doc.Since; import ch.njol.skript.lang.Literal; import ch.njol.skript.lang.SkriptEvent; import ch.njol.skript.lang.SkriptParser; @@ -14,16 +9,18 @@ import dev.lone.itemsadder.api.CustomBlock; import dev.lone.itemsadder.api.Events.CustomBlockInteractEvent; import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; -import me.asleepp.SkriptItemsAdder.other.aliases.AliasesGenerator; -import me.asleepp.SkriptItemsAdder.other.aliases.CustomItemType; -import me.asleepp.SkriptItemsAdder.other.util.Util; +import me.asleepp.SkriptItemsAdder.aliases.AliasesGenerator; +import me.asleepp.SkriptItemsAdder.util.Util; import org.bukkit.Location; +import org.bukkit.block.BlockFace; import org.bukkit.event.Event; +import org.bukkit.event.block.Action; import javax.annotation.Nullable; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; +import java.util.stream.Stream; public class EvtCustomBlockInteract extends SkriptEvent { @@ -43,13 +40,25 @@ public class EvtCustomBlockInteract extends SkriptEvent { public CustomBlock get(CustomBlockInteractEvent event) { return CustomBlock.byAlreadyPlaced(event.getBlockClicked()); } - }, 0); + }, EventValues.TIME_NOW); EventValues.registerEventValue(CustomBlockInteractEvent.class, Location.class, new Getter() { @Override public Location get(CustomBlockInteractEvent event) { return event.getBlockClicked().getLocation(); } - }, 0); + }, EventValues.TIME_NOW); + EventValues.registerEventValue(CustomBlockInteractEvent.class, Action.class, new Getter() { + @Override + public Action get(CustomBlockInteractEvent customBlockInteractEvent) { + return customBlockInteractEvent.getAction(); + } + }, EventValues.TIME_NOW); + EventValues.registerEventValue(CustomBlockInteractEvent.class, BlockFace.class, new Getter() { + @Override + public BlockFace get(CustomBlockInteractEvent customBlockInteractEvent) { + return customBlockInteractEvent.getBlockFace(); + } + }, EventValues.TIME_NOW); } @SuppressWarnings("unchecked") @@ -58,12 +67,12 @@ public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseRes blockNames = args; if (blockNames != null) { aliases = Arrays.stream(blockNames) - .map(literal -> { - if (literal instanceof Literal) { - Object value = literal.getSingle(); - return Util.getCustomBlockId(value); + .flatMap(literal -> { + if (literal != null) { + return Arrays.stream(literal.getArray()) + .map(Util::getCustomBlockId); } - return null; + return Stream.empty(); }) .filter(name -> name != null) .collect(Collectors.toList()); diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockPlace.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockPlace.java index a15d932..356aa61 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockPlace.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockPlace.java @@ -1,11 +1,6 @@ package me.asleepp.SkriptItemsAdder.elements.events.blocks; import ch.njol.skript.Skript; -import ch.njol.skript.doc.Description; -import ch.njol.skript.doc.Examples; -import ch.njol.skript.doc.Name; -import ch.njol.skript.doc.RequiredPlugins; -import ch.njol.skript.doc.Since; import ch.njol.skript.lang.Literal; import ch.njol.skript.lang.SkriptEvent; import ch.njol.skript.lang.SkriptParser; @@ -14,9 +9,8 @@ import dev.lone.itemsadder.api.CustomBlock; import dev.lone.itemsadder.api.Events.CustomBlockPlaceEvent; import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; -import me.asleepp.SkriptItemsAdder.other.aliases.AliasesGenerator; -import me.asleepp.SkriptItemsAdder.other.aliases.CustomItemType; -import me.asleepp.SkriptItemsAdder.other.util.Util; +import me.asleepp.SkriptItemsAdder.aliases.AliasesGenerator; +import me.asleepp.SkriptItemsAdder.util.Util; import org.bukkit.Location; import org.bukkit.event.Event; @@ -24,6 +18,7 @@ import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; +import java.util.stream.Stream; public class EvtCustomBlockPlace extends SkriptEvent { @@ -57,12 +52,12 @@ public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseRes blockNames = args; if (blockNames != null) { aliases = Arrays.stream(blockNames) - .map(literal -> { - if (literal instanceof Literal) { - Object value = literal.getSingle(); - return Util.getCustomBlockId(value); + .flatMap(literal -> { + if (literal != null) { + return Arrays.stream(literal.getArray()) + .map(Util::getCustomBlockId); } - return null; + return Stream.empty(); }) .filter(name -> name != null) .collect(Collectors.toList()); diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureBreak.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureBreak.java index b7fee7c..f9fe8e7 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureBreak.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureBreak.java @@ -1,11 +1,6 @@ package me.asleepp.SkriptItemsAdder.elements.events.furniture; import ch.njol.skript.Skript; -import ch.njol.skript.doc.Description; -import ch.njol.skript.doc.Examples; -import ch.njol.skript.doc.Name; -import ch.njol.skript.doc.RequiredPlugins; -import ch.njol.skript.doc.Since; import ch.njol.skript.lang.Literal; import ch.njol.skript.lang.SkriptEvent; import ch.njol.skript.lang.SkriptParser; @@ -14,9 +9,8 @@ import dev.lone.itemsadder.api.CustomFurniture; import dev.lone.itemsadder.api.Events.FurnitureBreakEvent; import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; -import me.asleepp.SkriptItemsAdder.other.aliases.AliasesGenerator; -import me.asleepp.SkriptItemsAdder.other.aliases.CustomItemType; -import me.asleepp.SkriptItemsAdder.other.util.Util; +import me.asleepp.SkriptItemsAdder.aliases.AliasesGenerator; +import me.asleepp.SkriptItemsAdder.util.Util; import org.bukkit.Location; import org.bukkit.event.Event; @@ -24,6 +18,7 @@ import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; +import java.util.stream.Stream; public class EvtCustomFurnitureBreak extends SkriptEvent { @@ -57,12 +52,12 @@ public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseRes furnitureIDs = args; if (furnitureIDs != null) { aliases = Arrays.stream(furnitureIDs) - .map(literal -> { + .flatMap(literal -> { if (literal != null) { - Object value = literal.getSingle(); - return Util.getCustomBlockId(value); + return Arrays.stream(literal.getArray()) + .map(Util::getCustomBlockId); } - return null; + return Stream.empty(); }) .filter(name -> name != null) .collect(Collectors.toList()); diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureInteract.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureInteract.java index 0a6082b..6e1bb72 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureInteract.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureInteract.java @@ -1,11 +1,6 @@ package me.asleepp.SkriptItemsAdder.elements.events.furniture; import ch.njol.skript.Skript; -import ch.njol.skript.doc.Description; -import ch.njol.skript.doc.Examples; -import ch.njol.skript.doc.Name; -import ch.njol.skript.doc.RequiredPlugins; -import ch.njol.skript.doc.Since; import ch.njol.skript.lang.Literal; import ch.njol.skript.lang.SkriptEvent; import ch.njol.skript.lang.SkriptParser; @@ -15,9 +10,8 @@ import dev.lone.itemsadder.api.Events.FurnitureBreakEvent; import dev.lone.itemsadder.api.Events.FurnitureInteractEvent; import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; -import me.asleepp.SkriptItemsAdder.other.aliases.AliasesGenerator; -import me.asleepp.SkriptItemsAdder.other.aliases.CustomItemType; -import me.asleepp.SkriptItemsAdder.other.util.Util; +import me.asleepp.SkriptItemsAdder.aliases.AliasesGenerator; +import me.asleepp.SkriptItemsAdder.util.Util; import org.bukkit.Location; import org.bukkit.event.Event; @@ -25,6 +19,7 @@ import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; +import java.util.stream.Stream; public class EvtCustomFurnitureInteract extends SkriptEvent { @@ -58,12 +53,12 @@ public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseRes furnitureIDs = args; if (furnitureIDs != null) { aliases = Arrays.stream(furnitureIDs) - .map(literal -> { + .flatMap(literal -> { if (literal != null) { - Object value = literal.getSingle(); - return Util.getCustomBlockId(value); + return Arrays.stream(literal.getArray()) + .map(Util::getCustomBlockId); } - return null; + return Stream.empty(); }) .filter(name -> name != null) .collect(Collectors.toList()); diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurniturePlace.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurniturePlace.java index 9f3249d..d33c5c8 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurniturePlace.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurniturePlace.java @@ -1,26 +1,21 @@ package me.asleepp.SkriptItemsAdder.elements.events.furniture; import ch.njol.skript.Skript; -import ch.njol.skript.doc.Description; -import ch.njol.skript.doc.Examples; -import ch.njol.skript.doc.Name; -import ch.njol.skript.doc.RequiredPlugins; -import ch.njol.skript.doc.Since; import ch.njol.skript.lang.Literal; import ch.njol.skript.lang.SkriptEvent; import ch.njol.skript.lang.SkriptParser; import dev.lone.itemsadder.api.Events.FurnitureBreakEvent; import dev.lone.itemsadder.api.Events.FurniturePlaceEvent; import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; -import me.asleepp.SkriptItemsAdder.other.aliases.AliasesGenerator; -import me.asleepp.SkriptItemsAdder.other.aliases.CustomItemType; -import me.asleepp.SkriptItemsAdder.other.util.Util; +import me.asleepp.SkriptItemsAdder.aliases.AliasesGenerator; +import me.asleepp.SkriptItemsAdder.util.Util; import org.bukkit.event.Event; import javax.annotation.Nullable; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; +import java.util.stream.Stream; public class EvtCustomFurniturePlace extends SkriptEvent { @@ -42,12 +37,12 @@ public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseRes furnitureIDs = args; if (furnitureIDs != null) { aliases = Arrays.stream(furnitureIDs) - .map(literal -> { + .flatMap(literal -> { if (literal != null) { - Object value = literal.getSingle(); - return Util.getCustomBlockId(value); + return Arrays.stream(literal.getArray()) + .map(Util::getCustomBlockId); } - return null; + return Stream.empty(); }) .filter(name -> name != null) .collect(Collectors.toList()); diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureSuccessEvent.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureSuccessEvent.java index 32768e0..dbc953c 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureSuccessEvent.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureSuccessEvent.java @@ -1,11 +1,6 @@ package me.asleepp.SkriptItemsAdder.elements.events.furniture; import ch.njol.skript.Skript; -import ch.njol.skript.doc.Description; -import ch.njol.skript.doc.Examples; -import ch.njol.skript.doc.Name; -import ch.njol.skript.doc.RequiredPlugins; -import ch.njol.skript.doc.Since; import ch.njol.skript.lang.Literal; import ch.njol.skript.lang.SkriptEvent; import ch.njol.skript.lang.SkriptParser; @@ -15,9 +10,8 @@ import dev.lone.itemsadder.api.Events.FurnitureBreakEvent; import dev.lone.itemsadder.api.Events.FurniturePlaceSuccessEvent; import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; -import me.asleepp.SkriptItemsAdder.other.aliases.AliasesGenerator; -import me.asleepp.SkriptItemsAdder.other.aliases.CustomItemType; -import me.asleepp.SkriptItemsAdder.other.util.Util; +import me.asleepp.SkriptItemsAdder.aliases.AliasesGenerator; +import me.asleepp.SkriptItemsAdder.util.Util; import org.bukkit.Location; import org.bukkit.event.Event; @@ -25,6 +19,7 @@ import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; +import java.util.stream.Stream; public class EvtCustomFurnitureSuccessEvent extends SkriptEvent { @@ -63,12 +58,12 @@ public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseRes furnitureIDs = args; if (furnitureIDs != null) { aliases = Arrays.stream(furnitureIDs) - .map(literal -> { + .flatMap(literal -> { if (literal != null) { - Object value = literal.getSingle(); - return Util.getCustomBlockId(value); + return Arrays.stream(literal.getArray()) + .map(Util::getCustomBlockId); } - return null; + return Stream.empty(); }) .filter(name -> name != null) .collect(Collectors.toList()); diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprCropAge.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprCropAge.java index df06e51..feb3a30 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprCropAge.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprCropAge.java @@ -80,7 +80,7 @@ public Class[] acceptChange(Changer.ChangeMode mode) { @Override public void change(Event e, Object[] delta, Changer.ChangeMode mode) { - if (delta != null && delta.length != 0) { + if (delta.length != 0) { int age = ((Number) delta[0]).intValue(); Block[] bs = block.getArray(e); for (Block b : bs) { diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetCustomItem.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetCustomItem.java index 5bc3b1d..615fe9c 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetCustomItem.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetCustomItem.java @@ -14,7 +14,7 @@ import ch.njol.util.Kleenean; import dev.lone.itemsadder.api.CustomStack; import dev.lone.itemsadder.api.ItemsAdder; -import me.asleepp.SkriptItemsAdder.other.aliases.CustomItemType; +import me.asleepp.SkriptItemsAdder.aliases.CustomItemType; import org.bukkit.Material; import org.bukkit.event.Event; import org.bukkit.inventory.ItemStack; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/elements/types/Types.java b/src/main/java/me/asleepp/SkriptItemsAdder/elements/types/Types.java index b14dae6..78e30e9 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/elements/types/Types.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/elements/types/Types.java @@ -1,6 +1,7 @@ package me.asleepp.SkriptItemsAdder.elements.types; import ch.njol.skript.classes.ClassInfo; +import ch.njol.skript.classes.EnumClassInfo; import ch.njol.skript.classes.Parser; import ch.njol.skript.classes.Serializer; import ch.njol.skript.lang.ParseContext; @@ -8,11 +9,14 @@ import ch.njol.yggdrasil.Fields; import dev.lone.itemsadder.api.FontImages.TexturedInventoryWrapper; import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; -import me.asleepp.SkriptItemsAdder.other.aliases.AliasesGenerator; -import me.asleepp.SkriptItemsAdder.other.aliases.CustomItemType; +import me.asleepp.SkriptItemsAdder.aliases.AliasesGenerator; +import me.asleepp.SkriptItemsAdder.aliases.CustomItemType; +import org.bukkit.block.BlockFace; +import org.bukkit.event.block.Action; import org.jetbrains.annotations.NotNull; import javax.annotation.Nullable; +import java.io.StreamCorruptedException; import java.util.HashMap; import java.util.Map; @@ -26,19 +30,35 @@ public class Types { .name("Custom Item Type") .description("Represents a custom item type using aliases.") .serializer(new Serializer() { + private static final String FIELD_NAME = "namespacedID"; + @Override public @NotNull Fields serialize(CustomItemType customItemType) { Fields fields = new Fields(); - fields.putObject("namespacedID", customItemType.getNamespacedID()); + fields.putObject(FIELD_NAME, customItemType.getNamespacedID()); return fields; } @Override public void deserialize(CustomItemType customItemType, @NotNull Fields fields) { try { - customItemType.setNamespacedID((String) fields.getObject("namespacedID")); - } catch (java.io.StreamCorruptedException e) { + String namespacedID = (String) fields.getObject(FIELD_NAME); + if (namespacedID != null) { + customItemType.setNamespacedID(namespacedID); + } + } catch (StreamCorruptedException e) { + e.printStackTrace(); + } + } + + @Override + public @Nullable CustomItemType deserialize(@NotNull Fields fields) { + try { + String namespacedID = (String) fields.getObject(FIELD_NAME); + return namespacedID != null ? new CustomItemType(namespacedID) : null; + } catch (StreamCorruptedException e) { e.printStackTrace(); + return null; } } @@ -108,5 +128,19 @@ public String getVariableNamePattern() { return ".+"; } })); + if (Classes.getExactClassInfo(Action.class) == null) { + Classes.registerClass(new EnumClassInfo<>(Action.class, "action", "actions") + .user("actions?") + .name("Action") + .description("The action taken in an event.") + .since("1.6")); + } + if (Classes.getExactClassInfo(BlockFace.class) == null) { + Classes.registerClass(new EnumClassInfo<>(BlockFace.class, "blockface", "block faces") + .user("block ?faces?") + .name("Block faces") + .description("The block face clicked in an event.") + .since("1.6")); + } } } diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/other/listeners/ItemsAdderEventListener.java b/src/main/java/me/asleepp/SkriptItemsAdder/listeners/ItemsAdderEventListener.java similarity index 88% rename from src/main/java/me/asleepp/SkriptItemsAdder/other/listeners/ItemsAdderEventListener.java rename to src/main/java/me/asleepp/SkriptItemsAdder/listeners/ItemsAdderEventListener.java index ad1beca..51d2620 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/other/listeners/ItemsAdderEventListener.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/listeners/ItemsAdderEventListener.java @@ -1,8 +1,8 @@ -package me.asleepp.SkriptItemsAdder.other.listeners; +package me.asleepp.SkriptItemsAdder.listeners; import dev.lone.itemsadder.api.Events.ItemsAdderLoadDataEvent; import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; -import me.asleepp.SkriptItemsAdder.other.aliases.AliasesGenerator; +import me.asleepp.SkriptItemsAdder.aliases.AliasesGenerator; import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/other/util/Metrics.java b/src/main/java/me/asleepp/SkriptItemsAdder/util/Metrics.java similarity index 99% rename from src/main/java/me/asleepp/SkriptItemsAdder/other/util/Metrics.java rename to src/main/java/me/asleepp/SkriptItemsAdder/util/Metrics.java index 2f8118a..86eddd3 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/other/util/Metrics.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/util/Metrics.java @@ -1,4 +1,4 @@ -package me.asleepp.SkriptItemsAdder.other.util; +package me.asleepp.SkriptItemsAdder.util; import java.io.BufferedReader; import java.io.ByteArrayOutputStream; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/other/util/SkriptItemsAdderCommand.java b/src/main/java/me/asleepp/SkriptItemsAdder/util/SkriptItemsAdderCommand.java similarity index 97% rename from src/main/java/me/asleepp/SkriptItemsAdder/other/util/SkriptItemsAdderCommand.java rename to src/main/java/me/asleepp/SkriptItemsAdder/util/SkriptItemsAdderCommand.java index a71c468..d4e4549 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/other/util/SkriptItemsAdderCommand.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/util/SkriptItemsAdderCommand.java @@ -1,9 +1,9 @@ -package me.asleepp.SkriptItemsAdder.other.util; +package me.asleepp.SkriptItemsAdder.util; import ch.njol.skript.Skript; import dev.lone.itemsadder.api.ItemsAdder; import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; -import me.asleepp.SkriptItemsAdder.other.aliases.AliasesGenerator; +import me.asleepp.SkriptItemsAdder.aliases.AliasesGenerator; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/other/util/UpdateChecker.java b/src/main/java/me/asleepp/SkriptItemsAdder/util/UpdateChecker.java similarity index 79% rename from src/main/java/me/asleepp/SkriptItemsAdder/other/util/UpdateChecker.java rename to src/main/java/me/asleepp/SkriptItemsAdder/util/UpdateChecker.java index a3f5c55..f2f1d1c 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/other/util/UpdateChecker.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/util/UpdateChecker.java @@ -1,9 +1,8 @@ -package me.asleepp.SkriptItemsAdder.other.util; +package me.asleepp.SkriptItemsAdder.util; import com.google.gson.Gson; import com.google.gson.JsonObject; import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; -import net.kyori.adventure.text.minimessage.MiniMessage; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -36,9 +35,9 @@ public void onPlayerJoin(PlayerJoinEvent event) { if (player.hasPermission("skript-itemsadder.update.check") && latestVersion != null) { if (!currentVersion.equals(latestVersion)) { player.sendMessage(" "); - player.sendMessage(MiniMessage.miniMessage().deserialize("[skript-itemsadder] skript-itemsadder is OUTDATED!")); - player.sendMessage(MiniMessage.miniMessage().deserialize("[skript-itemsadder] New version: " + latestVersion)); - player.sendMessage(MiniMessage.miniMessage().deserialize("[skript-itemsadder] Download Click here to get the latest version!'>here!")); + player.sendRichMessage("[skript-itemsadder] skript-itemsadder is OUTDATED!"); + player.sendRichMessage("[skript-itemsadder] New version: " + latestVersion); + player.sendRichMessage("[skript-itemsadder] Download Click here to get the latest version!'>here!"); player.sendMessage(" "); } } diff --git a/src/main/java/me/asleepp/SkriptItemsAdder/other/util/Util.java b/src/main/java/me/asleepp/SkriptItemsAdder/util/Util.java similarity index 94% rename from src/main/java/me/asleepp/SkriptItemsAdder/other/util/Util.java rename to src/main/java/me/asleepp/SkriptItemsAdder/util/Util.java index 6a73f62..93df45a 100644 --- a/src/main/java/me/asleepp/SkriptItemsAdder/other/util/Util.java +++ b/src/main/java/me/asleepp/SkriptItemsAdder/util/Util.java @@ -1,7 +1,7 @@ -package me.asleepp.SkriptItemsAdder.other.util; +package me.asleepp.SkriptItemsAdder.util; import dev.lone.itemsadder.api.CustomBlock; -import me.asleepp.SkriptItemsAdder.other.aliases.CustomItemType; +import me.asleepp.SkriptItemsAdder.aliases.CustomItemType; import net.kyori.adventure.text.minimessage.MiniMessage; import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; diff --git a/src/main/resources/lang/english.lang b/src/main/resources/lang/english.lang index 0f33599..5baf804 100644 --- a/src/main/resources/lang/english.lang +++ b/src/main/resources/lang/english.lang @@ -2,4 +2,34 @@ version: @version@ types: texturedinventorywrapper: texturedinventorywrapper - customitemtype: custom item type \ No newline at end of file + customitemtype: custom item type + action: action|s + blockface: block face|s + +actions: + left_click_air: left click air + right_click_air: right click air + left_click_block: left click block + right_click_block: right click block + physical: physical + +block faces: + down: down + east: east + east_north_east: east north east + east_south_east: east south east + north: north + north_east: north east + north_north_east: north north east + north_north_west: north north west + north_west: north west + self: self + south: south + south_east: south east + south_south_east: south south east + south_south_west: south south west + south_west: south west + up: up + west: west + west_north_west: west north west + west_south_west: west south west \ No newline at end of file