From b681351dfc4a7ca573fc5a62f6b527e4be9b120d Mon Sep 17 00:00:00 2001 From: Jsinco Date: Thu, 29 Feb 2024 14:40:05 -0500 Subject: [PATCH 01/18] working on it --- lib | 2 +- pom.xml | 12 + .../bukkit/bridges/BreweryXBridge.java | 12 + .../breweryx/BreweryBrewDrinkScriptEvent.java | 74 ++++ .../bukkit/objects/breweryx/BPlayerTag.java | 161 ++++++++ .../bukkit/objects/breweryx/BRecipeTag.java | 349 ++++++++++++++++++ 6 files changed, 609 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/denizenscript/depenizen/bukkit/bridges/BreweryXBridge.java create mode 100644 src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryBrewDrinkScriptEvent.java create mode 100644 src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BPlayerTag.java create mode 100644 src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BRecipeTag.java diff --git a/lib b/lib index c64343ea9..ab5c5abd8 160000 --- a/lib +++ b/lib @@ -1 +1 @@ -Subproject commit c64343ea9ed21970ef8262fcde20c3262cbeb4af +Subproject commit ab5c5abd846940b74c9ed17e60a71b9efa808600 diff --git a/pom.xml b/pom.xml index 3d6848c0c..a0a063b49 100644 --- a/pom.xml +++ b/pom.xml @@ -39,6 +39,10 @@ true + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + @@ -389,6 +393,14 @@ system ${basedir}/lib/BigDoors.jar + + com.dre.brewery + BreweryX + 3.1.7 + jar + system + ${basedir}/lib/BreweryX.jar + diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/bridges/BreweryXBridge.java b/src/main/java/com/denizenscript/depenizen/bukkit/bridges/BreweryXBridge.java new file mode 100644 index 000000000..f75603353 --- /dev/null +++ b/src/main/java/com/denizenscript/depenizen/bukkit/bridges/BreweryXBridge.java @@ -0,0 +1,12 @@ +package com.denizenscript.depenizen.bukkit.bridges; + +import com.denizenscript.denizencore.events.ScriptEvent; +import com.denizenscript.depenizen.bukkit.Bridge; +import com.dre.brewery.api.events.brew.BrewDrinkEvent; + +public class BreweryXBridge extends Bridge { + @Override + public void init() { + ScriptEvent.registerScriptEvent(); + } +} diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryBrewDrinkScriptEvent.java b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryBrewDrinkScriptEvent.java new file mode 100644 index 000000000..2a0b35ea3 --- /dev/null +++ b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryBrewDrinkScriptEvent.java @@ -0,0 +1,74 @@ +package com.denizenscript.depenizen.bukkit.events.breweryx; + + +import com.denizenscript.denizen.events.BukkitScriptEvent; +import com.denizenscript.denizen.objects.PlayerTag; +import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData; +import com.denizenscript.denizencore.objects.ObjectTag; +import com.denizenscript.denizencore.objects.core.ElementTag; +import com.denizenscript.denizencore.objects.core.TimeTag; +import com.denizenscript.denizencore.scripts.ScriptEntryData; +import com.denizenscript.depenizen.bukkit.objects.breweryx.BPlayerTag; +import com.denizenscript.depenizen.bukkit.objects.breweryx.BRecipeTag; +import com.dre.brewery.api.events.brew.BrewDrinkEvent; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +public class BreweryBrewDrinkScriptEvent extends BukkitScriptEvent implements Listener { + + public BreweryBrewDrinkScriptEvent() { + } + + // <--[event] + // @Events + // brewery player drinks <'brew'> + // + // @Cancellable true + // + // @Triggers when a player drinks a potion that is considered a BreweryX potion. + // + // @Context + // Returns an ItemTag of the potion that was drunk. + // Returns an BRecipeTag of the recipe that the brew is based off of. + // Returns an BPlayerTag of the player that drank the brew. + // + // @Determine + // "RECIPE:" to change the brew's recipe. Effectively changing the brew to another one. + // + // @Plugin Depenizen, BreweryX + // + // @Player Always. + // + // @Group Depenizen + // + // --> + public BrewDrinkEvent event; + public BRecipeTag recipeTag; + public BPlayerTag bPlayerTag; + + @Override + public boolean couldMatch(ScriptPath path) { + return path.eventLower.startsWith("brewery drink"); + } + + @Override + public ScriptEntryData getScriptEntryData() { + return new BukkitScriptEntryData(new PlayerTag(event.getPlayer()), null); + } + + @Override + public ObjectTag getContext(String name) { + return switch (name) { + case "recipe" -> recipeTag; + case "bplayer" -> bPlayerTag; + case "item" -> new ItemTag(event.getBrew().); + } + return super.getContext(name); + } + + @EventHandler + public void onBrewDrinkEvent(BrewDrinkEvent event) { + this.event = event; + fire(event); + } +} diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BPlayerTag.java b/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BPlayerTag.java new file mode 100644 index 000000000..c25a721aa --- /dev/null +++ b/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BPlayerTag.java @@ -0,0 +1,161 @@ +package com.denizenscript.depenizen.bukkit.objects.breweryx; + +import com.denizenscript.denizen.objects.PlayerTag; +import com.denizenscript.denizencore.objects.Fetchable; +import com.denizenscript.denizencore.objects.ObjectTag; +import com.denizenscript.denizencore.objects.core.ElementTag; +import com.denizenscript.denizencore.tags.Attribute; +import com.denizenscript.denizencore.tags.TagContext; +import com.denizenscript.denizencore.utilities.debugging.Debug; +import com.dre.brewery.BPlayer; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +// TODO: OfflinePlayer support +public class BPlayerTag implements ObjectTag { + + // <--[ObjectType] + // @name BplayerTag + // @prefix bplayer + // @base ElementTag + // @format + // The identity format for brewery players is + // For example, 'bplayer@my_player'. + // + // @plugin Depenizen, BreweryX + // @description + // A BPlayerTag represents a Brewery player. + // + // --> + + @Fetchable("bplayer") + public static BPlayerTag valueOf(String string, TagContext context) { + if (string.startsWith("bplayer@")) { + string = string.substring("bplayer@".length()); + } + Player player = Bukkit.getPlayerExact(string); + if (player == null) { + return null; + } + return new BPlayerTag(player); + } + + public static boolean matches(String arg) { + arg = arg.replace("bplayer@", ""); + Player player = Bukkit.getPlayerExact(arg); + if (player == null) { + return false; + } + return BPlayer.hasPlayer(player); + } + + public static BPlayerTag forPlayer(PlayerTag player) { + return new BPlayerTag(player.getPlayerEntity()); + } + + BPlayer bPlayer = null; + + public BPlayerTag(Player player) { + if (BPlayer.hasPlayer(player)) { + bPlayer = BPlayer.get(player); + } + else { + Debug.echoError("BPlayer referenced is null!"); + } + } + + + String prefix = "bplayer"; + + @Override + public String getPrefix() { + return prefix; + } + + @Override + public boolean isUnique() { + return true; + } + + @Override + public String identify() { + return "bplayer@" + bPlayer.getName(); + } + + @Override + public String identifySimple() { + return identify(); + } + + @Override + public ObjectTag setPrefix(String aString) { + this.prefix = aString; + return this; + } + + + @Override + public ObjectTag getObjectAttribute(Attribute attribute) { + if (attribute == null) { + return null; + } + + // <--[tag] + // @attribute + // @returns ElementTag + // @plugin Depenizen, BreweryX + // @description + // Returns the name of the brewery player. + // --> + if (attribute.startsWith("name")) { + return new ElementTag(bPlayer.getName()).getObjectAttribute(attribute.fulfill(1)); + } + + // <--[tag] + // @attribute + // @returns ElementTag + // @plugin Depenizen, BreweryX + // @description + // Returns the drunkness of the brewery player. + // --> + else if (attribute.startsWith("drunkenness")) { + return new ElementTag(bPlayer.getDrunkeness()).getObjectAttribute(attribute.fulfill(1)); + } + + // <--[tag] + // @attribute + // @returns ElementTag + // @plugin Depenizen, BreweryX + // @description + // Returns the quality of the brewery player's drunkenness (drunkeness * drunkeness). + // --> + else if (attribute.startsWith("quality")) { + return new ElementTag(bPlayer.getQuality()).getObjectAttribute(attribute.fulfill(1)); + } + + // <--[tag] + // @attribute + // @returns ElementTag + // @plugin Depenizen, BreweryX + // @description + // Returns the drunkenness reduction per minute. + // --> + else if (attribute.startsWith("alcrecovery")) { + return new ElementTag(bPlayer.getQuality()).getObjectAttribute(attribute.fulfill(1)); + } + + // <--[tag] + // @attribute + // @returns ElementTag + // @plugin Depenizen, BreweryX + // @description + // Returns the Brewery player's UUID. + // --> + else if (attribute.startsWith("uuid")) { + return new ElementTag(bPlayer.getUuid()).getObjectAttribute(attribute.fulfill(1)); + } + + + return new ElementTag(identify()).getObjectAttribute(attribute); + } +} diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BRecipeTag.java b/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BRecipeTag.java new file mode 100644 index 000000000..5365b04e6 --- /dev/null +++ b/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BRecipeTag.java @@ -0,0 +1,349 @@ +package com.denizenscript.depenizen.bukkit.objects.breweryx; + +import com.denizenscript.denizen.objects.ItemTag; +import com.denizenscript.denizencore.objects.Fetchable; +import com.denizenscript.denizencore.objects.ObjectTag; +import com.denizenscript.denizencore.objects.core.ColorTag; +import com.denizenscript.denizencore.objects.core.ElementTag; +import com.denizenscript.denizencore.objects.core.ListTag; +import com.denizenscript.denizencore.tags.Attribute; +import com.denizenscript.denizencore.tags.TagContext; +import com.dre.brewery.recipe.BEffect; +import com.dre.brewery.recipe.BRecipe; +import com.dre.brewery.recipe.RecipeItem; +import com.dre.brewery.utility.Tuple; +import org.bukkit.Color; +import org.bukkit.Material; + +import java.util.Optional; + +public class BRecipeTag implements ObjectTag { + + // <--[ObjectType] + // @name BRecipeTag + // @prefix brecipe + // @base ElementTag + // @format + // The identity format for brewery is + // For example, 'brecipe@my_recipe'. + // + // @plugin Depenizen, BreweryX + // @description + // A BRecipeTag represents a Brewery recipe. + // + // --> + + + @Fetchable("brecipe") + public static BRecipeTag valueOf(String string, TagContext context) { + if (string.startsWith("brecipe@")) { + string = string.substring("brecipe@".length()); + } + + BRecipe recipe = BRecipe.get(string); + if (recipe == null) { + return null; + } + return new BRecipeTag(recipe); + } + + public static boolean matches(String arg) { + arg = arg.replace("brecipe@", ""); + return BRecipe.get(arg) != null; + } + + BRecipe bRecipe; + + public BRecipeTag(BRecipe bRecipe) { + this.bRecipe = bRecipe; + } + + String prefix = "brecipe"; + + @Override + public String getPrefix() { + return prefix; + } + + @Override + public boolean isUnique() { + return true; + } + + @Override + public String identify() { + return "brecipe@" + bRecipe.getRecipeName(); + } + + @Override + public String identifySimple() { + return identify(); + } + + @Override + public ObjectTag setPrefix(String aString) { + prefix = aString; + return this; + } + + + + @Override + public ObjectTag getObjectAttribute(Attribute attribute) { + if (attribute == null) { + return null; + } + + // <--[tag] + // @attribute + // @returns ElementTag + // @plugin Depenizen, BreweryX + // @description + // Returns the ID of the recipe as specified in the config. + // --> + if (attribute.startsWith("id")) { + /* + TODO: This being optional was infrastructure added by the original authors and is not used + in Brewery. It will be deprecated and replaced soon. + */ + Optional id = bRecipe.getOptionalID(); + if (id.isPresent()) { + return new ElementTag(id.get()).getObjectAttribute(attribute.fulfill(1)); + } + } + + // <--[tag] + // @attribute + // @returns ElementTag + // @plugin Depenizen, BreweryX + // @description + // Returns the name of the recipe at it's highest quality. + // --> + else if (attribute.startsWith("name")) { + return new ElementTag(bRecipe.getRecipeName()).getObjectAttribute(attribute.fulfill(1)); + } + + // <--[tag] + // @attribute + // @returns ListTag(ItemTag) + // @plugin Depenizen, BreweryX + // @description + // Returns a ListTag of ItemTags that are the ingredients of the recipe. + // --> + else if (attribute.startsWith("ingredients")) { + ListTag ingredients = new ListTag(); + for (RecipeItem recipeItem : bRecipe.getIngredients()) { + if (recipeItem.getMaterials() == null) { + continue; + } + for (Material material : recipeItem.getMaterials()) { + ingredients.addObject(new ItemTag(material, recipeItem.getAmount())); + } + } + return ingredients.getObjectAttribute(attribute.fulfill(1)); + } + + // <--[tag] + // @attribute + // @returns ElementTag(Number) + // @plugin Depenizen, BreweryX + // @description + // Returns the difficulty of the recipe. + // --> + else if (attribute.startsWith("difficulty")) { + return new ElementTag(bRecipe.getDifficulty()).getObjectAttribute(attribute.fulfill(1)); + } + + // <--[tag] + // @attribute + // @returns ElementTag(Number) + // @plugin Depenizen, BreweryX + // @description + // Returns the cooking time of the recipe. + // --> + else if (attribute.startsWith("cooking_time")) { + return new ElementTag(bRecipe.getCookingTime()).getObjectAttribute(attribute.fulfill(1)); + } + + // <--[tag] + // @attribute + // @returns ElementTag(Number) + // @plugin Depenizen, BreweryX + // @description + // Returns the distill runs of the recipe + // --> + else if (attribute.startsWith("distill_runs")) { + return new ElementTag(bRecipe.getDistillRuns()).getObjectAttribute(attribute.fulfill(1)); + } + + // <--[tag] + // @attribute + // @returns ElementTag(Number) + // @plugin Depenizen, BreweryX + // @description + // Returns the amount of time each distill run takes. + // --> + else if (attribute.startsWith("distill_time")) { + return new ElementTag(bRecipe.getDistillTime()).getObjectAttribute(attribute.fulfill(1)); + } + + // <--[tag] + // @attribute + // @returns ElementTag(Number) + // @plugin Depenizen, BreweryX + // @description + // Returns the type of wood used in the recipe (by number, Ex: 0 = Any, 1 = Oak). + // --> + else if (attribute.startsWith("wood")) { + return new ElementTag(bRecipe.getWood()).getObjectAttribute(attribute.fulfill(1)); + } + + // <--[tag] + // @attribute + // @returns ElementTag(Number) + // @plugin Depenizen, BreweryX + // @description + // Returns the amount of minecraft days the potion must age in a Brewery barrel. + // --> + else if (attribute.startsWith("age")) { + return new ElementTag(bRecipe.getAge()).getObjectAttribute(attribute.fulfill(1)); + } + + // <--[tag] + // @attribute + // @returns ColorTag + // @plugin Depenizen, BreweryX + // @description + // Returns the color of the distilled/finished potion. + // --> + else if (attribute.startsWith("color")) { + Color color = bRecipe.getColor().getColor(); + return new ColorTag(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()).getObjectAttribute(attribute.fulfill(1)); + } + + // <--[tag] + // @attribute + // @returns ElementTag(Number) + // @plugin Depenizen, BreweryX + // @description + // Returns the amount of alcohol in a perfect potion. + // --> + else if (attribute.startsWith("alcohol")) { + return new ElementTag(bRecipe.getAlcohol()).getObjectAttribute(attribute.fulfill(1)); + } + + // <--[tag] + // @attribute + // @returns ListTag(ElementTag) + // @plugin Depenizen, BreweryX + // @description + // Returns a ListTag of the lore of the recipe (displayed on potion). + // --> + else if (attribute.startsWith("lore")) { + if (bRecipe.getLore() == null) { + return null; + } + ListTag lore = new ListTag(); + for (Tuple tuple : bRecipe.getLore()) { + lore.addObject(new ElementTag(tuple.second())); + } + return lore.getObjectAttribute(attribute.fulfill(1)); + } + + // <--[tag] + // @attribute + // @returns ListTag(ElementTag(Number)) + // @plugin Depenizen, BreweryX + // @description + // Returns a ListTag of the 3 possible custom model data's for each varied quality of the recipe/potion. + // --> + else if (attribute.startsWith("custom_model_data")) { + ListTag cmDatas = new ListTag(); + for (int cmData : bRecipe.getCmData()) { + cmDatas.addObject(new ElementTag(cmData)); + } + return cmDatas.getObjectAttribute(attribute.fulfill(1)); + } + + // <--[tag] + // @attribute + // @returns ListTag(ElementTag) + // @plugin Depenizen, BreweryX + // @description + // Returns a ListTag of potion effects of as their names (Example: SLOW_FALLING). + // --> + else if (attribute.startsWith("effects")) { + ListTag effects = new ListTag(); + for (BEffect bEffect : bRecipe.getEffects()) { + effects.addObject(new ElementTag(bEffect.getType().toString())); + } + return effects.getObjectAttribute(attribute.fulfill(1)); + } + + // <--[tag] + // @attribute + // @returns ListTag(ElementTag) + // @plugin Depenizen, BreweryX + // @description + // Returns a ListTag of commands that are run by the player when the potion is drunk. + // --> + else if (attribute.startsWith("player_commands")) { + if (bRecipe.getPlayercmds() == null) { + return null; + } + ListTag cmds = new ListTag(); + for (Tuple tuple : bRecipe.getPlayercmds()) { + cmds.addObject(new ElementTag(tuple.second())); + } + return cmds.getObjectAttribute(attribute.fulfill(1)); + } + + // <--[tag] + // @attribute + // @returns ListTag(ElementTag) + // @plugin Depenizen, BreweryX + // @description + // Returns a ListTag of commands that are run by the server when the potion is drunk. + // --> + else if (attribute.startsWith("server_commands")) { + if (bRecipe.getServercmds() == null) { + return null; + } + ListTag cmds = new ListTag(); + for (Tuple tuple : bRecipe.getServercmds()) { + cmds.addObject(new ElementTag(tuple.second())); + } + return cmds.getObjectAttribute(attribute.fulfill(1)); + } + + // <--[tag] + // @attribute + // @returns ElementTag + // @plugin Depenizen, BreweryX + // @description + // Returns the message sent to the player when the potion is drunk. + // --> + else if (attribute.startsWith("message")) { + if (bRecipe.getDrinkMsg() == null) { + return null; + } + return new ElementTag(bRecipe.getDrinkMsg()).getObjectAttribute(attribute.fulfill(1)); + } + + // <--[tag] + // @attribute + // @returns ElementTag + // @plugin Depenizen, BreweryX + // @description + // Returns the title message sent to the player when the potion is drunk. + // --> + else if (attribute.startsWith("title")) { + if (bRecipe.getDrinkTitle() == null) { + return null; + } + return new ElementTag(bRecipe.getDrinkTitle()).getObjectAttribute(attribute.fulfill(1)); + } + + return new ElementTag(identify()).getObjectAttribute(attribute); + } +} From 7820362c3c07b04072a932a2679ff7a2aca20044 Mon Sep 17 00:00:00 2001 From: Jsinco Date: Mon, 29 Apr 2024 03:01:11 -0400 Subject: [PATCH 02/18] working on it --- .../depenizen/bukkit/Depenizen.java | 1 + .../bukkit/bridges/BreweryXBridge.java | 9 ++- ...vent.java => BreweryDrinkScriptEvent.java} | 20 +++--- .../BreweryModifyBrewScriptEvent.java | 71 +++++++++++++++++++ 4 files changed, 88 insertions(+), 13 deletions(-) rename src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/{BreweryBrewDrinkScriptEvent.java => BreweryDrinkScriptEvent.java} (78%) create mode 100644 src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryModifyBrewScriptEvent.java diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/Depenizen.java b/src/main/java/com/denizenscript/depenizen/bukkit/Depenizen.java index 37ae8caea..4564ca18d 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/Depenizen.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/Depenizen.java @@ -146,6 +146,7 @@ public void registerCoreBridges() { registerBridge("Votifier", () -> new VotifierBridge()); registerBridge("WorldEdit", () -> new WorldEditBridge()); registerBridge("WorldGuard", () -> new WorldGuardBridge()); + registerBridge("Brewery", () -> new BreweryXBridge()); } public void registerBridge(String name, Supplier bridgeSupplier) { diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/bridges/BreweryXBridge.java b/src/main/java/com/denizenscript/depenizen/bukkit/bridges/BreweryXBridge.java index f75603353..24955805b 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/bridges/BreweryXBridge.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/bridges/BreweryXBridge.java @@ -1,12 +1,17 @@ package com.denizenscript.depenizen.bukkit.bridges; import com.denizenscript.denizencore.events.ScriptEvent; +import com.denizenscript.denizencore.objects.ObjectFetcher; import com.denizenscript.depenizen.bukkit.Bridge; -import com.dre.brewery.api.events.brew.BrewDrinkEvent; +import com.denizenscript.depenizen.bukkit.events.breweryx.BreweryDrinkScriptEvent; +import com.denizenscript.depenizen.bukkit.objects.breweryx.BPlayerTag; +import com.denizenscript.depenizen.bukkit.objects.breweryx.BRecipeTag; public class BreweryXBridge extends Bridge { @Override public void init() { - ScriptEvent.registerScriptEvent(); + ScriptEvent.registerScriptEvent(BreweryDrinkScriptEvent.class); + ObjectFetcher.registerWithObjectFetcher(BPlayerTag.class); + ObjectFetcher.registerWithObjectFetcher(BRecipeTag.class); } } diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryBrewDrinkScriptEvent.java b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryDrinkScriptEvent.java similarity index 78% rename from src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryBrewDrinkScriptEvent.java rename to src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryDrinkScriptEvent.java index 2a0b35ea3..2541c101b 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryBrewDrinkScriptEvent.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryDrinkScriptEvent.java @@ -2,11 +2,10 @@ import com.denizenscript.denizen.events.BukkitScriptEvent; +import com.denizenscript.denizen.objects.ItemTag; import com.denizenscript.denizen.objects.PlayerTag; import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData; import com.denizenscript.denizencore.objects.ObjectTag; -import com.denizenscript.denizencore.objects.core.ElementTag; -import com.denizenscript.denizencore.objects.core.TimeTag; import com.denizenscript.denizencore.scripts.ScriptEntryData; import com.denizenscript.depenizen.bukkit.objects.breweryx.BPlayerTag; import com.denizenscript.depenizen.bukkit.objects.breweryx.BRecipeTag; @@ -14,14 +13,14 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -public class BreweryBrewDrinkScriptEvent extends BukkitScriptEvent implements Listener { +public class BreweryDrinkScriptEvent extends BukkitScriptEvent implements Listener { - public BreweryBrewDrinkScriptEvent() { + public BreweryDrinkScriptEvent() { } // <--[event] // @Events - // brewery player drinks <'brew'> + // brewery drink // // @Cancellable true // @@ -32,9 +31,6 @@ public BreweryBrewDrinkScriptEvent() { // Returns an BRecipeTag of the recipe that the brew is based off of. // Returns an BPlayerTag of the player that drank the brew. // - // @Determine - // "RECIPE:" to change the brew's recipe. Effectively changing the brew to another one. - // // @Plugin Depenizen, BreweryX // // @Player Always. @@ -61,14 +57,16 @@ public ObjectTag getContext(String name) { return switch (name) { case "recipe" -> recipeTag; case "bplayer" -> bPlayerTag; - case "item" -> new ItemTag(event.getBrew().); - } - return super.getContext(name); + case "item" -> new ItemTag(event.getBrew().createItem(event.getBrew().getCurrentRecipe())); + default -> super.getContext(name); + }; } @EventHandler public void onBrewDrinkEvent(BrewDrinkEvent event) { this.event = event; + this.recipeTag = new BRecipeTag(event.getBrew().getCurrentRecipe()); + this.bPlayerTag = BPlayerTag.forPlayer(new PlayerTag(event.getPlayer())); fire(event); } } diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryModifyBrewScriptEvent.java b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryModifyBrewScriptEvent.java new file mode 100644 index 000000000..6f09c9172 --- /dev/null +++ b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryModifyBrewScriptEvent.java @@ -0,0 +1,71 @@ +package com.denizenscript.depenizen.bukkit.events.breweryx; + +import com.denizenscript.denizen.events.BukkitScriptEvent; +import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData; +import com.denizenscript.denizencore.objects.ObjectTag; +import com.denizenscript.denizencore.objects.core.ElementTag; +import com.denizenscript.denizencore.scripts.ScriptEntryData; +import com.denizenscript.depenizen.bukkit.objects.breweryx.BRecipeTag; +import com.dre.brewery.api.events.brew.BrewEvent; +import com.dre.brewery.api.events.brew.BrewModifyEvent; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +public class BreweryModifyBrewScriptEvent extends BukkitScriptEvent implements Listener { + + public BreweryModifyBrewScriptEvent() { + } + + // <--[event] + // @Events + // brewery brew modify + // + // @Cancellable true + // + // @Triggers When a Brew has been created or modified. + // Usually happens on filling from cauldron, distilling and aging. + // Modifications to the Brew or the PotionMeta can be done now + // Cancelling reverts the Brew to the state it was before the modification + // + // @Context + // Returns an ItemTag of the potion that was drunk. + // Returns an BRecipeTag of the recipe that the brew is based off of. + // + // @Plugin Depenizen, BreweryX + // + // @Player Always. + // + // @Group Depenizen + // + // --> + public BrewModifyEvent event; + public BRecipeTag recipeTag; + public String type; + + @Override + public boolean couldMatch(ScriptPath path) { + return path.eventLower.startsWith("brewery modify brew"); + } + + @Override + public ScriptEntryData getScriptEntryData() { + return new BukkitScriptEntryData(null, null); + } + + @Override + public ObjectTag getContext(String name) { + return switch (name) { + case "recipe" -> recipeTag; + case "type" -> new ElementTag(type); + default -> super.getContext(name); + }; + } + + @EventHandler + public void onBrewDrinkEvent(BrewModifyEvent event) { + this.event = event; + this.recipeTag = new BRecipeTag(event.getBrew().getCurrentRecipe()); + this.type = event.getType().name(); + fire(event); + } +} From fceacdb68be5367ae2af0202de9d95afd9c0e6c4 Mon Sep 17 00:00:00 2001 From: Jsinco Date: Sun, 5 May 2024 18:19:58 -0400 Subject: [PATCH 03/18] laptop push --- .../bukkit/bridges/BreweryXBridge.java | 6 ++ .../BreweryChatDistortScriptEvent.java | 81 +++++++++++++++++ .../breweryx/BreweryDrinkScriptEvent.java | 2 + .../BreweryIngredientAddScriptEvent.java | 88 +++++++++++++++++++ .../BreweryModifyBrewScriptEvent.java | 7 +- 5 files changed, 180 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryChatDistortScriptEvent.java create mode 100644 src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryIngredientAddScriptEvent.java diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/bridges/BreweryXBridge.java b/src/main/java/com/denizenscript/depenizen/bukkit/bridges/BreweryXBridge.java index 24955805b..3ceea7c20 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/bridges/BreweryXBridge.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/bridges/BreweryXBridge.java @@ -3,7 +3,10 @@ import com.denizenscript.denizencore.events.ScriptEvent; import com.denizenscript.denizencore.objects.ObjectFetcher; import com.denizenscript.depenizen.bukkit.Bridge; +import com.denizenscript.depenizen.bukkit.events.breweryx.BreweryChatDistortScriptEvent; import com.denizenscript.depenizen.bukkit.events.breweryx.BreweryDrinkScriptEvent; +import com.denizenscript.depenizen.bukkit.events.breweryx.BreweryIngredientAddScriptEvent; +import com.denizenscript.depenizen.bukkit.events.breweryx.BreweryModifyBrewScriptEvent; import com.denizenscript.depenizen.bukkit.objects.breweryx.BPlayerTag; import com.denizenscript.depenizen.bukkit.objects.breweryx.BRecipeTag; @@ -11,6 +14,9 @@ public class BreweryXBridge extends Bridge { @Override public void init() { ScriptEvent.registerScriptEvent(BreweryDrinkScriptEvent.class); + ScriptEvent.registerScriptEvent(BreweryModifyBrewScriptEvent.class); + ScriptEvent.registerScriptEvent(BreweryIngredientAddScriptEvent.class); + ScriptEvent.registerScriptEvent(BreweryChatDistortScriptEvent.class); ObjectFetcher.registerWithObjectFetcher(BPlayerTag.class); ObjectFetcher.registerWithObjectFetcher(BRecipeTag.class); } diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryChatDistortScriptEvent.java b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryChatDistortScriptEvent.java new file mode 100644 index 000000000..5e9ef4cee --- /dev/null +++ b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryChatDistortScriptEvent.java @@ -0,0 +1,81 @@ +package com.denizenscript.depenizen.bukkit.events.breweryx; + +import com.denizenscript.denizen.events.BukkitScriptEvent; +import com.denizenscript.denizen.objects.PlayerTag; +import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData; +import com.denizenscript.denizencore.objects.ObjectTag; +import com.denizenscript.denizencore.objects.core.ElementTag; +import com.denizenscript.denizencore.scripts.ScriptEntryData; +import com.denizenscript.depenizen.bukkit.objects.breweryx.BPlayerTag; +import com.dre.brewery.api.events.PlayerChatDistortEvent; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +public class BreweryChatDistortScriptEvent extends BukkitScriptEvent implements Listener { + public BreweryChatDistortScriptEvent() { + } + + // <--[event] + // @Events + // brewery chat distort + // + // @Cancellable true + // + // @Triggers when a drunk brewery player's chat is distorted. + // + // @Context + // Returns the message to be sent after being distorted. + // Returns the original message before being distorted. + // Returns an BPlayerTag of the player that drank the brew. + // Returns a PlayerTag of the player that had their chat distorted. + // + // @Determine + // ElementTag(String) to set the message to be sent after being distorted. + // + // @Plugin Depenizen, BreweryX + // + // @Player Always. + // + // @Group Depenizen + // + // --> + public PlayerChatDistortEvent event; + public PlayerTag playerTag; + + @Override + public boolean couldMatch(ScriptPath path) { + return path.eventLower.startsWith("brewery chat distort"); + } + + @Override + public ScriptEntryData getScriptEntryData() { + return new BukkitScriptEntryData(new PlayerTag(event.getPlayer()), null); + } + + @Override + public ObjectTag getContext(String name) { + return switch (name) { + case "message" -> new ElementTag(event.getDistortedMessage()); + case "original_message" -> new ElementTag(event.getWrittenMessage()); + case "bplayer" -> BPlayerTag.forPlayer(playerTag); + case "player" -> playerTag; + default -> super.getContext(name); + }; + } + + @Override + public boolean handleDetermination(ScriptPath path, String prefix, ObjectTag value) { + if (prefix.equals("message") && value instanceof ElementTag elementTag) { + event.setDistortedMessage(elementTag.asString()); + return true; + } + return super.handleDetermination(path, prefix, value); + } + + @EventHandler + public void onChatDistort(PlayerChatDistortEvent event) { + this.event = event; + this.playerTag = new PlayerTag(event.getPlayer()); + fire(event); + } +} diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryDrinkScriptEvent.java b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryDrinkScriptEvent.java index 2541c101b..2bc86a915 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryDrinkScriptEvent.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryDrinkScriptEvent.java @@ -30,6 +30,7 @@ public BreweryDrinkScriptEvent() { // Returns an ItemTag of the potion that was drunk. // Returns an BRecipeTag of the recipe that the brew is based off of. // Returns an BPlayerTag of the player that drank the brew. + // Returns a PlayerTag of the player that drank the brew. // // @Plugin Depenizen, BreweryX // @@ -58,6 +59,7 @@ public ObjectTag getContext(String name) { case "recipe" -> recipeTag; case "bplayer" -> bPlayerTag; case "item" -> new ItemTag(event.getBrew().createItem(event.getBrew().getCurrentRecipe())); + case "player" -> new PlayerTag(event.getPlayer()); default -> super.getContext(name); }; } diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryIngredientAddScriptEvent.java b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryIngredientAddScriptEvent.java new file mode 100644 index 000000000..25ac33157 --- /dev/null +++ b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryIngredientAddScriptEvent.java @@ -0,0 +1,88 @@ +package com.denizenscript.depenizen.bukkit.events.breweryx; + +import com.denizenscript.denizen.events.BukkitScriptEvent; +import com.denizenscript.denizen.objects.ItemTag; +import com.denizenscript.denizen.objects.LocationTag; +import com.denizenscript.denizen.objects.PlayerTag; +import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData; +import com.denizenscript.denizencore.events.ScriptEvent; +import com.denizenscript.denizencore.objects.ObjectTag; +import com.denizenscript.denizencore.objects.core.ElementTag; +import com.denizenscript.denizencore.scripts.ScriptEntryData; +import com.dre.brewery.api.events.IngedientAddEvent; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +public class BreweryIngredientAddScriptEvent extends BukkitScriptEvent implements Listener { + public BreweryIngredientAddScriptEvent() { + } + + // <--[event] + // @Events + // brewery ingredient add + // + // @Cancellable true + // + // @Triggers when a player adds an ingredient to a cauldron. + // + // @Context + // Returns an ItemTag of the ingredient that was added. + // Returns a LocationTag of the cauldron. + // Returns a PlayerTag of the player that added the ingredient. + // Returns an ElementTag of whether the item should be taken from the player. + // + // @Determine + // ItemTag to set the ingredient that was added. + // ElementTag(Boolean) to set whether the item should be taken from the player. + // + // @Plugin Depenizen, BreweryX + // + // @Player Always. + // + // @Group Depenizen + // + // --> + public IngedientAddEvent event; + + @Override + public boolean couldMatch(ScriptEvent.ScriptPath path) { + return path.eventLower.startsWith("brewery ingredient add"); + } + + @Override + public ScriptEntryData getScriptEntryData() { + return new BukkitScriptEntryData(new PlayerTag(event.getPlayer()), null); + } + + @Override + public ObjectTag getContext(String name) { + return switch (name) { + case "location" -> new LocationTag(event.getBlock().getLocation()); + case "player" -> new PlayerTag(event.getPlayer()); + case "item" -> new ItemTag(event.getIngredient()); + case "take_item" -> new ElementTag(event.willTakeItem()); + default -> super.getContext(name); + }; + } + + @Override + public boolean handleDetermination(ScriptPath path, String prefix, ObjectTag value) { + switch (prefix) { + case "item" -> { + event.setIngredient(((ItemTag) value).getItemStack()); + return true; + } + case "take_item" -> { + event.setTakeItem(((ElementTag) value).asBoolean()); + return true; + } + } + return super.handleDetermination(path, prefix, value); + } + + @EventHandler + public void onIngredientAddEvent(IngedientAddEvent event) { + this.event = event; + fire(event); + } +} diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryModifyBrewScriptEvent.java b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryModifyBrewScriptEvent.java index 6f09c9172..63d2be67a 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryModifyBrewScriptEvent.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryModifyBrewScriptEvent.java @@ -1,12 +1,12 @@ package com.denizenscript.depenizen.bukkit.events.breweryx; import com.denizenscript.denizen.events.BukkitScriptEvent; +import com.denizenscript.denizen.objects.ItemTag; import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData; import com.denizenscript.denizencore.objects.ObjectTag; import com.denizenscript.denizencore.objects.core.ElementTag; import com.denizenscript.denizencore.scripts.ScriptEntryData; import com.denizenscript.depenizen.bukkit.objects.breweryx.BRecipeTag; -import com.dre.brewery.api.events.brew.BrewEvent; import com.dre.brewery.api.events.brew.BrewModifyEvent; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -33,8 +33,6 @@ public BreweryModifyBrewScriptEvent() { // // @Plugin Depenizen, BreweryX // - // @Player Always. - // // @Group Depenizen // // --> @@ -57,12 +55,13 @@ public ObjectTag getContext(String name) { return switch (name) { case "recipe" -> recipeTag; case "type" -> new ElementTag(type); + case "item" -> new ItemTag(event.getBrew().createItem(event.getBrew().getCurrentRecipe())); default -> super.getContext(name); }; } @EventHandler - public void onBrewDrinkEvent(BrewModifyEvent event) { + public void onBrewModifyEvent(BrewModifyEvent event) { this.event = event; this.recipeTag = new BRecipeTag(event.getBrew().getCurrentRecipe()); this.type = event.getType().name(); From dadac475d827eca935cbfa8ffddf7a3f3fa6f98d Mon Sep 17 00:00:00 2001 From: Jsinco Date: Thu, 6 Jun 2024 13:03:18 -0400 Subject: [PATCH 04/18] should be ready for pull --- .../bukkit/events/breweryx/BreweryDrinkScriptEvent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryDrinkScriptEvent.java b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryDrinkScriptEvent.java index 2bc86a915..0e052a132 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryDrinkScriptEvent.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryDrinkScriptEvent.java @@ -54,7 +54,7 @@ public ScriptEntryData getScriptEntryData() { } @Override - public ObjectTag getContext(String name) { + public ObjectTag getContext(String name) { // return switch (name) { case "recipe" -> recipeTag; case "bplayer" -> bPlayerTag; From 92b1f8642453dce9c5f4ce88a43776db2904c885 Mon Sep 17 00:00:00 2001 From: Jsinco Date: Thu, 6 Jun 2024 17:55:46 -0400 Subject: [PATCH 05/18] BreweryX support --- src/main/java/com/denizenscript/depenizen/bukkit/Depenizen.java | 2 +- .../bukkit/events/breweryx/BreweryDrinkScriptEvent.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/Depenizen.java b/src/main/java/com/denizenscript/depenizen/bukkit/Depenizen.java index 4564ca18d..585ecee05 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/Depenizen.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/Depenizen.java @@ -146,7 +146,7 @@ public void registerCoreBridges() { registerBridge("Votifier", () -> new VotifierBridge()); registerBridge("WorldEdit", () -> new WorldEditBridge()); registerBridge("WorldGuard", () -> new WorldGuardBridge()); - registerBridge("Brewery", () -> new BreweryXBridge()); + registerBridge("BreweryX", () -> new BreweryXBridge()); } public void registerBridge(String name, Supplier bridgeSupplier) { diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryDrinkScriptEvent.java b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryDrinkScriptEvent.java index 0e052a132..2bc86a915 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryDrinkScriptEvent.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryDrinkScriptEvent.java @@ -54,7 +54,7 @@ public ScriptEntryData getScriptEntryData() { } @Override - public ObjectTag getContext(String name) { // + public ObjectTag getContext(String name) { return switch (name) { case "recipe" -> recipeTag; case "bplayer" -> bPlayerTag; From ab820b41ba8aea78c450f8566064925fe867b870 Mon Sep 17 00:00:00 2001 From: Jsinco Date: Thu, 6 Jun 2024 21:33:32 -0400 Subject: [PATCH 06/18] laptop push --- .../BreweryChatDistortScriptEvent.java | 5 +++++ .../bukkit/objects/breweryx/BPlayerTag.java | 20 ++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryChatDistortScriptEvent.java b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryChatDistortScriptEvent.java index 5e9ef4cee..64be26959 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryChatDistortScriptEvent.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryChatDistortScriptEvent.java @@ -47,6 +47,11 @@ public boolean couldMatch(ScriptPath path) { return path.eventLower.startsWith("brewery chat distort"); } + @Override + public boolean matches(ScriptPath path) { + + } + @Override public ScriptEntryData getScriptEntryData() { return new BukkitScriptEntryData(new PlayerTag(event.getPlayer()), null); diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BPlayerTag.java b/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BPlayerTag.java index c25a721aa..e0fe8856c 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BPlayerTag.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BPlayerTag.java @@ -12,12 +12,12 @@ import org.bukkit.entity.Player; // TODO: OfflinePlayer support -public class BPlayerTag implements ObjectTag { +public class BPlayerTag extends PlayerTag { // <--[ObjectType] // @name BplayerTag // @prefix bplayer - // @base ElementTag + // @base PlayerTag // @format // The identity format for brewery players is // For example, 'bplayer@my_player'. @@ -56,6 +56,7 @@ public static BPlayerTag forPlayer(PlayerTag player) { BPlayer bPlayer = null; public BPlayerTag(Player player) { + super(player); if (BPlayer.hasPlayer(player)) { bPlayer = BPlayer.get(player); } @@ -69,32 +70,27 @@ public BPlayerTag(Player player) { @Override public String getPrefix() { - return prefix; - } - - @Override - public boolean isUnique() { - return true; + return this.prefix; } @Override public String identify() { - return "bplayer@" + bPlayer.getName(); + return "bplayer@" + this.getUUID(); } @Override public String identifySimple() { - return identify(); + return "bplayer@" + bPlayer.getName(); } @Override - public ObjectTag setPrefix(String aString) { + public PlayerTag setPrefix(String aString) { this.prefix = aString; return this; } - @Override + @Override // FIXME: Reference some other class to fix this public ObjectTag getObjectAttribute(Attribute attribute) { if (attribute == null) { return null; From 09bc85643803876c61e3106a9376ba9cf8ee8160 Mon Sep 17 00:00:00 2001 From: Jsinco Date: Fri, 7 Jun 2024 03:41:16 -0400 Subject: [PATCH 07/18] code fixes --- .../BreweryChatDistortScriptEvent.java | 18 +- .../breweryx/BreweryDrinkScriptEvent.java | 13 +- .../BreweryIngredientAddScriptEvent.java | 12 +- .../BreweryModifyBrewScriptEvent.java | 11 +- .../bukkit/objects/breweryx/BPlayerTag.java | 60 +++---- .../bukkit/objects/breweryx/BRecipeTag.java | 156 +++++++++--------- 6 files changed, 138 insertions(+), 132 deletions(-) diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryChatDistortScriptEvent.java b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryChatDistortScriptEvent.java index 64be26959..92ef74f10 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryChatDistortScriptEvent.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryChatDistortScriptEvent.java @@ -12,8 +12,7 @@ import org.bukkit.event.Listener; public class BreweryChatDistortScriptEvent extends BukkitScriptEvent implements Listener { - public BreweryChatDistortScriptEvent() { - } + // <--[event] // @Events @@ -39,22 +38,21 @@ public BreweryChatDistortScriptEvent() { // @Group Depenizen // // --> + public BreweryChatDistortScriptEvent() { + registerCouldMatcher("brewery chat distort"); + } + public PlayerChatDistortEvent event; public PlayerTag playerTag; - @Override - public boolean couldMatch(ScriptPath path) { - return path.eventLower.startsWith("brewery chat distort"); - } - @Override public boolean matches(ScriptPath path) { - + return super.matches(path); } @Override public ScriptEntryData getScriptEntryData() { - return new BukkitScriptEntryData(new PlayerTag(event.getPlayer()), null); + return new BukkitScriptEntryData(event.getPlayer()); } @Override @@ -70,7 +68,7 @@ public ObjectTag getContext(String name) { @Override public boolean handleDetermination(ScriptPath path, String prefix, ObjectTag value) { - if (prefix.equals("message") && value instanceof ElementTag elementTag) { + if (prefix.equals("message") && value instanceof ElementTag elementTag) { // FIXME - Cast redundant but .toString() returns class and hash? event.setDistortedMessage(elementTag.asString()); return true; } diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryDrinkScriptEvent.java b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryDrinkScriptEvent.java index 2bc86a915..2bd1882ad 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryDrinkScriptEvent.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryDrinkScriptEvent.java @@ -15,9 +15,6 @@ public class BreweryDrinkScriptEvent extends BukkitScriptEvent implements Listener { - public BreweryDrinkScriptEvent() { - } - // <--[event] // @Events // brewery drink @@ -39,18 +36,22 @@ public BreweryDrinkScriptEvent() { // @Group Depenizen // // --> + public BreweryDrinkScriptEvent() { + registerCouldMatcher("brewery drink"); + } + public BrewDrinkEvent event; public BRecipeTag recipeTag; public BPlayerTag bPlayerTag; @Override - public boolean couldMatch(ScriptPath path) { - return path.eventLower.startsWith("brewery drink"); + public boolean matches(ScriptPath path) { + return super.matches(path); } @Override public ScriptEntryData getScriptEntryData() { - return new BukkitScriptEntryData(new PlayerTag(event.getPlayer()), null); + return new BukkitScriptEntryData(event.getPlayer()); } @Override diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryIngredientAddScriptEvent.java b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryIngredientAddScriptEvent.java index 25ac33157..74ec2b2a7 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryIngredientAddScriptEvent.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryIngredientAddScriptEvent.java @@ -14,8 +14,6 @@ import org.bukkit.event.Listener; public class BreweryIngredientAddScriptEvent extends BukkitScriptEvent implements Listener { - public BreweryIngredientAddScriptEvent() { - } // <--[event] // @Events @@ -42,16 +40,20 @@ public BreweryIngredientAddScriptEvent() { // @Group Depenizen // // --> + public BreweryIngredientAddScriptEvent() { + registerCouldMatcher("brewery ingredient add"); + } + public IngedientAddEvent event; @Override - public boolean couldMatch(ScriptEvent.ScriptPath path) { - return path.eventLower.startsWith("brewery ingredient add"); + public boolean matches(ScriptPath path) { + return super.matches(path); } @Override public ScriptEntryData getScriptEntryData() { - return new BukkitScriptEntryData(new PlayerTag(event.getPlayer()), null); + return new BukkitScriptEntryData(event.getPlayer()); } @Override diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryModifyBrewScriptEvent.java b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryModifyBrewScriptEvent.java index 63d2be67a..842f278c1 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryModifyBrewScriptEvent.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryModifyBrewScriptEvent.java @@ -13,9 +13,6 @@ public class BreweryModifyBrewScriptEvent extends BukkitScriptEvent implements Listener { - public BreweryModifyBrewScriptEvent() { - } - // <--[event] // @Events // brewery brew modify @@ -36,13 +33,17 @@ public BreweryModifyBrewScriptEvent() { // @Group Depenizen // // --> + public BreweryModifyBrewScriptEvent() { + registerCouldMatcher("brewery brew modify"); + } + public BrewModifyEvent event; public BRecipeTag recipeTag; public String type; @Override - public boolean couldMatch(ScriptPath path) { - return path.eventLower.startsWith("brewery modify brew"); + public boolean matches(ScriptPath path) { + return super.matches(path); } @Override diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BPlayerTag.java b/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BPlayerTag.java index e0fe8856c..a2f294103 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BPlayerTag.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BPlayerTag.java @@ -5,14 +5,14 @@ import com.denizenscript.denizencore.objects.ObjectTag; import com.denizenscript.denizencore.objects.core.ElementTag; import com.denizenscript.denizencore.tags.Attribute; +import com.denizenscript.denizencore.tags.ObjectTagProcessor; import com.denizenscript.denizencore.tags.TagContext; import com.denizenscript.denizencore.utilities.debugging.Debug; import com.dre.brewery.BPlayer; import org.bukkit.Bukkit; import org.bukkit.entity.Player; -// TODO: OfflinePlayer support -public class BPlayerTag extends PlayerTag { +public class BPlayerTag implements ObjectTag { // <--[ObjectType] // @name BplayerTag @@ -56,7 +56,6 @@ public static BPlayerTag forPlayer(PlayerTag player) { BPlayer bPlayer = null; public BPlayerTag(Player player) { - super(player); if (BPlayer.hasPlayer(player)) { bPlayer = BPlayer.get(player); } @@ -66,16 +65,21 @@ public BPlayerTag(Player player) { } - String prefix = "bplayer"; + String prefix = "BPlayer"; @Override public String getPrefix() { return this.prefix; } + @Override + public boolean isUnique() { + return true; + } + @Override public String identify() { - return "bplayer@" + this.getUUID(); + return "bplayer@" + bPlayer.getUuid(); } @Override @@ -84,17 +88,12 @@ public String identifySimple() { } @Override - public PlayerTag setPrefix(String aString) { + public ObjectTag setPrefix(String aString) { this.prefix = aString; return this; } - - @Override // FIXME: Reference some other class to fix this - public ObjectTag getObjectAttribute(Attribute attribute) { - if (attribute == null) { - return null; - } + public static void register() { // <--[tag] // @attribute @@ -103,9 +102,10 @@ public ObjectTag getObjectAttribute(Attribute attribute) { // @description // Returns the name of the brewery player. // --> - if (attribute.startsWith("name")) { - return new ElementTag(bPlayer.getName()).getObjectAttribute(attribute.fulfill(1)); - } + tagProcessor.registerTag(ElementTag.class, "name", (attribute, object) -> { + return new ElementTag(object.bPlayer.getName()); + }); + // <--[tag] // @attribute @@ -114,9 +114,9 @@ public ObjectTag getObjectAttribute(Attribute attribute) { // @description // Returns the drunkness of the brewery player. // --> - else if (attribute.startsWith("drunkenness")) { - return new ElementTag(bPlayer.getDrunkeness()).getObjectAttribute(attribute.fulfill(1)); - } + tagProcessor.registerTag(ElementTag.class, "drunkenness", (attribute, object) -> { + return new ElementTag(object.bPlayer.getDrunkeness()); + }); // <--[tag] // @attribute @@ -125,9 +125,9 @@ else if (attribute.startsWith("drunkenness")) { // @description // Returns the quality of the brewery player's drunkenness (drunkeness * drunkeness). // --> - else if (attribute.startsWith("quality")) { - return new ElementTag(bPlayer.getQuality()).getObjectAttribute(attribute.fulfill(1)); - } + tagProcessor.registerTag(ElementTag.class, "quality", (attribute, object) -> { + return new ElementTag(object.bPlayer.getQuality()); + }); // <--[tag] // @attribute @@ -136,9 +136,9 @@ else if (attribute.startsWith("quality")) { // @description // Returns the drunkenness reduction per minute. // --> - else if (attribute.startsWith("alcrecovery")) { - return new ElementTag(bPlayer.getQuality()).getObjectAttribute(attribute.fulfill(1)); - } + tagProcessor.registerTag(ElementTag.class, "alcrecovery", (attribute, object) -> { + return new ElementTag(object.bPlayer.getAlcRecovery()); + }); // <--[tag] // @attribute @@ -147,11 +147,15 @@ else if (attribute.startsWith("alcrecovery")) { // @description // Returns the Brewery player's UUID. // --> - else if (attribute.startsWith("uuid")) { - return new ElementTag(bPlayer.getUuid()).getObjectAttribute(attribute.fulfill(1)); - } + tagProcessor.registerTag(ElementTag.class, "uuid", (attribute, object) -> { + return new ElementTag(object.bPlayer.getUuid()); + }); + } + public static ObjectTagProcessor tagProcessor = new ObjectTagProcessor<>(); - return new ElementTag(identify()).getObjectAttribute(attribute); + @Override + public ObjectTag getObjectAttribute(Attribute attribute) { + return tagProcessor.getObjectAttribute(this, attribute); } } diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BRecipeTag.java b/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BRecipeTag.java index 5365b04e6..9a1707c2c 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BRecipeTag.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BRecipeTag.java @@ -7,6 +7,7 @@ import com.denizenscript.denizencore.objects.core.ElementTag; import com.denizenscript.denizencore.objects.core.ListTag; import com.denizenscript.denizencore.tags.Attribute; +import com.denizenscript.denizencore.tags.ObjectTagProcessor; import com.denizenscript.denizencore.tags.TagContext; import com.dre.brewery.recipe.BEffect; import com.dre.brewery.recipe.BRecipe; @@ -33,7 +34,6 @@ public class BRecipeTag implements ObjectTag { // // --> - @Fetchable("brecipe") public static BRecipeTag valueOf(String string, TagContext context) { if (string.startsWith("brecipe@")) { @@ -86,13 +86,7 @@ public ObjectTag setPrefix(String aString) { return this; } - - - @Override - public ObjectTag getObjectAttribute(Attribute attribute) { - if (attribute == null) { - return null; - } + public static void register() { // <--[tag] // @attribute @@ -101,16 +95,17 @@ public ObjectTag getObjectAttribute(Attribute attribute) { // @description // Returns the ID of the recipe as specified in the config. // --> - if (attribute.startsWith("id")) { + tagProcessor.registerTag(ElementTag.class, "id", (attribute, object) -> { /* - TODO: This being optional was infrastructure added by the original authors and is not used + This being optional was infrastructure added by the original authors and is not used in Brewery. It will be deprecated and replaced soon. - */ - Optional id = bRecipe.getOptionalID(); + */ + Optional id = object.bRecipe.getOptionalID(); if (id.isPresent()) { - return new ElementTag(id.get()).getObjectAttribute(attribute.fulfill(1)); + return new ElementTag(id.get()); } - } + return null; + }); // <--[tag] // @attribute @@ -119,9 +114,9 @@ public ObjectTag getObjectAttribute(Attribute attribute) { // @description // Returns the name of the recipe at it's highest quality. // --> - else if (attribute.startsWith("name")) { - return new ElementTag(bRecipe.getRecipeName()).getObjectAttribute(attribute.fulfill(1)); - } + tagProcessor.registerTag(ElementTag.class, "name", (attribute, object) -> { + return new ElementTag(object.bRecipe.getRecipeName()); + }); // <--[tag] // @attribute @@ -130,9 +125,9 @@ else if (attribute.startsWith("name")) { // @description // Returns a ListTag of ItemTags that are the ingredients of the recipe. // --> - else if (attribute.startsWith("ingredients")) { + tagProcessor.registerTag(ListTag.class, "ingredients", (attribute, object) -> { ListTag ingredients = new ListTag(); - for (RecipeItem recipeItem : bRecipe.getIngredients()) { + for (RecipeItem recipeItem : object.bRecipe.getIngredients()) { if (recipeItem.getMaterials() == null) { continue; } @@ -140,8 +135,8 @@ else if (attribute.startsWith("ingredients")) { ingredients.addObject(new ItemTag(material, recipeItem.getAmount())); } } - return ingredients.getObjectAttribute(attribute.fulfill(1)); - } + return ingredients; + }); // <--[tag] // @attribute @@ -150,9 +145,9 @@ else if (attribute.startsWith("ingredients")) { // @description // Returns the difficulty of the recipe. // --> - else if (attribute.startsWith("difficulty")) { - return new ElementTag(bRecipe.getDifficulty()).getObjectAttribute(attribute.fulfill(1)); - } + tagProcessor.registerTag(ElementTag.class, "difficulty", (attribute, object) -> { + return new ElementTag(object.bRecipe.getDifficulty()); + }); // <--[tag] // @attribute @@ -161,9 +156,9 @@ else if (attribute.startsWith("difficulty")) { // @description // Returns the cooking time of the recipe. // --> - else if (attribute.startsWith("cooking_time")) { - return new ElementTag(bRecipe.getCookingTime()).getObjectAttribute(attribute.fulfill(1)); - } + tagProcessor.registerTag(ElementTag.class, "cooking_time", (attribute, object) -> { + return new ElementTag(object.bRecipe.getCookingTime()); + }); // <--[tag] // @attribute @@ -172,9 +167,9 @@ else if (attribute.startsWith("cooking_time")) { // @description // Returns the distill runs of the recipe // --> - else if (attribute.startsWith("distill_runs")) { - return new ElementTag(bRecipe.getDistillRuns()).getObjectAttribute(attribute.fulfill(1)); - } + tagProcessor.registerTag(ElementTag.class, "distill_runs", (attribute, object) -> { + return new ElementTag(object.bRecipe.getDistillRuns()); + }); // <--[tag] // @attribute @@ -183,9 +178,9 @@ else if (attribute.startsWith("distill_runs")) { // @description // Returns the amount of time each distill run takes. // --> - else if (attribute.startsWith("distill_time")) { - return new ElementTag(bRecipe.getDistillTime()).getObjectAttribute(attribute.fulfill(1)); - } + tagProcessor.registerTag(ElementTag.class, "distill_time", (attribute, object) -> { + return new ElementTag(object.bRecipe.getDistillTime()); + }); // <--[tag] // @attribute @@ -194,9 +189,9 @@ else if (attribute.startsWith("distill_time")) { // @description // Returns the type of wood used in the recipe (by number, Ex: 0 = Any, 1 = Oak). // --> - else if (attribute.startsWith("wood")) { - return new ElementTag(bRecipe.getWood()).getObjectAttribute(attribute.fulfill(1)); - } + tagProcessor.registerTag(ElementTag.class, "wood", (attribute, object) -> { + return new ElementTag(object.bRecipe.getWood()); + }); // <--[tag] // @attribute @@ -205,9 +200,9 @@ else if (attribute.startsWith("wood")) { // @description // Returns the amount of minecraft days the potion must age in a Brewery barrel. // --> - else if (attribute.startsWith("age")) { - return new ElementTag(bRecipe.getAge()).getObjectAttribute(attribute.fulfill(1)); - } + tagProcessor.registerTag(ElementTag.class, "age", (attribute, object) -> { + return new ElementTag(object.bRecipe.getAge()); + }); // <--[tag] // @attribute @@ -216,10 +211,10 @@ else if (attribute.startsWith("age")) { // @description // Returns the color of the distilled/finished potion. // --> - else if (attribute.startsWith("color")) { - Color color = bRecipe.getColor().getColor(); - return new ColorTag(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()).getObjectAttribute(attribute.fulfill(1)); - } + tagProcessor.registerTag(ColorTag.class, "color", ((attribute, object) -> { + Color color = object.bRecipe.getColor().getColor(); + return new ColorTag(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()); + })); // <--[tag] // @attribute @@ -228,9 +223,9 @@ else if (attribute.startsWith("color")) { // @description // Returns the amount of alcohol in a perfect potion. // --> - else if (attribute.startsWith("alcohol")) { - return new ElementTag(bRecipe.getAlcohol()).getObjectAttribute(attribute.fulfill(1)); - } + tagProcessor.registerTag(ElementTag.class, "alcohol", (attribute, object) -> { + return new ElementTag(object.bRecipe.getAlcohol()); + }); // <--[tag] // @attribute @@ -239,16 +234,16 @@ else if (attribute.startsWith("alcohol")) { // @description // Returns a ListTag of the lore of the recipe (displayed on potion). // --> - else if (attribute.startsWith("lore")) { - if (bRecipe.getLore() == null) { + tagProcessor.registerTag(ListTag.class, "lore", (attribute, object) -> { + if (object.bRecipe.getLore() == null) { return null; } ListTag lore = new ListTag(); - for (Tuple tuple : bRecipe.getLore()) { + for (Tuple tuple : object.bRecipe.getLore()) { lore.addObject(new ElementTag(tuple.second())); } - return lore.getObjectAttribute(attribute.fulfill(1)); - } + return lore; + }); // <--[tag] // @attribute @@ -257,13 +252,13 @@ else if (attribute.startsWith("lore")) { // @description // Returns a ListTag of the 3 possible custom model data's for each varied quality of the recipe/potion. // --> - else if (attribute.startsWith("custom_model_data")) { + tagProcessor.registerTag(ListTag.class, "custom_model_data", (attribute, object) -> { ListTag cmDatas = new ListTag(); - for (int cmData : bRecipe.getCmData()) { + for (int cmData : object.bRecipe.getCmData()) { cmDatas.addObject(new ElementTag(cmData)); } - return cmDatas.getObjectAttribute(attribute.fulfill(1)); - } + return cmDatas; + }); // <--[tag] // @attribute @@ -272,13 +267,13 @@ else if (attribute.startsWith("custom_model_data")) { // @description // Returns a ListTag of potion effects of as their names (Example: SLOW_FALLING). // --> - else if (attribute.startsWith("effects")) { + tagProcessor.registerTag(ListTag.class, "effects", (attribute, object) -> { ListTag effects = new ListTag(); - for (BEffect bEffect : bRecipe.getEffects()) { + for (BEffect bEffect : object.bRecipe.getEffects()) { effects.addObject(new ElementTag(bEffect.getType().toString())); } - return effects.getObjectAttribute(attribute.fulfill(1)); - } + return effects; + }); // <--[tag] // @attribute @@ -287,16 +282,16 @@ else if (attribute.startsWith("effects")) { // @description // Returns a ListTag of commands that are run by the player when the potion is drunk. // --> - else if (attribute.startsWith("player_commands")) { - if (bRecipe.getPlayercmds() == null) { + tagProcessor.registerTag(ListTag.class, "player_commands", (attribute, object) -> { + if (object.bRecipe.getPlayercmds() == null) { return null; } ListTag cmds = new ListTag(); - for (Tuple tuple : bRecipe.getPlayercmds()) { + for (Tuple tuple : object.bRecipe.getPlayercmds()) { cmds.addObject(new ElementTag(tuple.second())); } - return cmds.getObjectAttribute(attribute.fulfill(1)); - } + return cmds; + }); // <--[tag] // @attribute @@ -305,16 +300,16 @@ else if (attribute.startsWith("player_commands")) { // @description // Returns a ListTag of commands that are run by the server when the potion is drunk. // --> - else if (attribute.startsWith("server_commands")) { - if (bRecipe.getServercmds() == null) { + tagProcessor.registerTag(ListTag.class, "server_commands", (attribute, object) -> { + if (object.bRecipe.getServercmds() == null) { return null; } ListTag cmds = new ListTag(); - for (Tuple tuple : bRecipe.getServercmds()) { + for (Tuple tuple : object.bRecipe.getServercmds()) { cmds.addObject(new ElementTag(tuple.second())); } - return cmds.getObjectAttribute(attribute.fulfill(1)); - } + return cmds; + }); // <--[tag] // @attribute @@ -323,12 +318,12 @@ else if (attribute.startsWith("server_commands")) { // @description // Returns the message sent to the player when the potion is drunk. // --> - else if (attribute.startsWith("message")) { - if (bRecipe.getDrinkMsg() == null) { + tagProcessor.registerTag(ElementTag.class, "message", (attribute, object) -> { + if (object.bRecipe.getDrinkMsg() == null) { return null; } - return new ElementTag(bRecipe.getDrinkMsg()).getObjectAttribute(attribute.fulfill(1)); - } + return new ElementTag(object.bRecipe.getDrinkMsg()); + }); // <--[tag] // @attribute @@ -337,13 +332,18 @@ else if (attribute.startsWith("message")) { // @description // Returns the title message sent to the player when the potion is drunk. // --> - else if (attribute.startsWith("title")) { - if (bRecipe.getDrinkTitle() == null) { + tagProcessor.registerTag(ElementTag.class, "title", ((attribute, object) -> { + if (object.bRecipe.getDrinkTitle() == null) { return null; } - return new ElementTag(bRecipe.getDrinkTitle()).getObjectAttribute(attribute.fulfill(1)); - } + return new ElementTag(object.bRecipe.getDrinkTitle()); + })); + } - return new ElementTag(identify()).getObjectAttribute(attribute); + public static ObjectTagProcessor tagProcessor = new ObjectTagProcessor<>(); + + @Override + public ObjectTag getObjectAttribute(Attribute attribute) { + return tagProcessor.getObjectAttribute(this, attribute); } } From 3e3b437f78bd6df2036641bb879c501bece5dd04 Mon Sep 17 00:00:00 2001 From: Jsinco Date: Fri, 7 Jun 2024 03:44:02 -0400 Subject: [PATCH 08/18] rename classes --- .../depenizen/bukkit/bridges/BreweryXBridge.java | 8 ++++---- .../breweryx/BreweryChatDistortScriptEvent.java | 4 ++-- .../events/breweryx/BreweryDrinkScriptEvent.java | 12 ++++++------ .../breweryx/BreweryModifyBrewScriptEvent.java | 6 +++--- .../{BPlayerTag.java => BreweryPlayerTag.java} | 14 +++++++------- .../{BRecipeTag.java => BreweryRecipeTag.java} | 10 +++++----- 6 files changed, 27 insertions(+), 27 deletions(-) rename src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/{BPlayerTag.java => BreweryPlayerTag.java} (90%) rename src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/{BRecipeTag.java => BreweryRecipeTag.java} (97%) diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/bridges/BreweryXBridge.java b/src/main/java/com/denizenscript/depenizen/bukkit/bridges/BreweryXBridge.java index 3ceea7c20..87fe23079 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/bridges/BreweryXBridge.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/bridges/BreweryXBridge.java @@ -7,8 +7,8 @@ import com.denizenscript.depenizen.bukkit.events.breweryx.BreweryDrinkScriptEvent; import com.denizenscript.depenizen.bukkit.events.breweryx.BreweryIngredientAddScriptEvent; import com.denizenscript.depenizen.bukkit.events.breweryx.BreweryModifyBrewScriptEvent; -import com.denizenscript.depenizen.bukkit.objects.breweryx.BPlayerTag; -import com.denizenscript.depenizen.bukkit.objects.breweryx.BRecipeTag; +import com.denizenscript.depenizen.bukkit.objects.breweryx.BreweryPlayerTag; +import com.denizenscript.depenizen.bukkit.objects.breweryx.BreweryRecipeTag; public class BreweryXBridge extends Bridge { @Override @@ -17,7 +17,7 @@ public void init() { ScriptEvent.registerScriptEvent(BreweryModifyBrewScriptEvent.class); ScriptEvent.registerScriptEvent(BreweryIngredientAddScriptEvent.class); ScriptEvent.registerScriptEvent(BreweryChatDistortScriptEvent.class); - ObjectFetcher.registerWithObjectFetcher(BPlayerTag.class); - ObjectFetcher.registerWithObjectFetcher(BRecipeTag.class); + ObjectFetcher.registerWithObjectFetcher(BreweryPlayerTag.class); + ObjectFetcher.registerWithObjectFetcher(BreweryRecipeTag.class); } } diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryChatDistortScriptEvent.java b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryChatDistortScriptEvent.java index 92ef74f10..a1ec2f5fa 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryChatDistortScriptEvent.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryChatDistortScriptEvent.java @@ -6,7 +6,7 @@ import com.denizenscript.denizencore.objects.ObjectTag; import com.denizenscript.denizencore.objects.core.ElementTag; import com.denizenscript.denizencore.scripts.ScriptEntryData; -import com.denizenscript.depenizen.bukkit.objects.breweryx.BPlayerTag; +import com.denizenscript.depenizen.bukkit.objects.breweryx.BreweryPlayerTag; import com.dre.brewery.api.events.PlayerChatDistortEvent; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -60,7 +60,7 @@ public ObjectTag getContext(String name) { return switch (name) { case "message" -> new ElementTag(event.getDistortedMessage()); case "original_message" -> new ElementTag(event.getWrittenMessage()); - case "bplayer" -> BPlayerTag.forPlayer(playerTag); + case "bplayer" -> BreweryPlayerTag.forPlayer(playerTag); case "player" -> playerTag; default -> super.getContext(name); }; diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryDrinkScriptEvent.java b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryDrinkScriptEvent.java index 2bd1882ad..59b9a1681 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryDrinkScriptEvent.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryDrinkScriptEvent.java @@ -7,8 +7,8 @@ import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData; import com.denizenscript.denizencore.objects.ObjectTag; import com.denizenscript.denizencore.scripts.ScriptEntryData; -import com.denizenscript.depenizen.bukkit.objects.breweryx.BPlayerTag; -import com.denizenscript.depenizen.bukkit.objects.breweryx.BRecipeTag; +import com.denizenscript.depenizen.bukkit.objects.breweryx.BreweryPlayerTag; +import com.denizenscript.depenizen.bukkit.objects.breweryx.BreweryRecipeTag; import com.dre.brewery.api.events.brew.BrewDrinkEvent; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -41,8 +41,8 @@ public BreweryDrinkScriptEvent() { } public BrewDrinkEvent event; - public BRecipeTag recipeTag; - public BPlayerTag bPlayerTag; + public BreweryRecipeTag recipeTag; + public BreweryPlayerTag bPlayerTag; @Override public boolean matches(ScriptPath path) { @@ -68,8 +68,8 @@ public ObjectTag getContext(String name) { @EventHandler public void onBrewDrinkEvent(BrewDrinkEvent event) { this.event = event; - this.recipeTag = new BRecipeTag(event.getBrew().getCurrentRecipe()); - this.bPlayerTag = BPlayerTag.forPlayer(new PlayerTag(event.getPlayer())); + this.recipeTag = new BreweryRecipeTag(event.getBrew().getCurrentRecipe()); + this.bPlayerTag = BreweryPlayerTag.forPlayer(new PlayerTag(event.getPlayer())); fire(event); } } diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryModifyBrewScriptEvent.java b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryModifyBrewScriptEvent.java index 842f278c1..8d54e0a91 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryModifyBrewScriptEvent.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryModifyBrewScriptEvent.java @@ -6,7 +6,7 @@ import com.denizenscript.denizencore.objects.ObjectTag; import com.denizenscript.denizencore.objects.core.ElementTag; import com.denizenscript.denizencore.scripts.ScriptEntryData; -import com.denizenscript.depenizen.bukkit.objects.breweryx.BRecipeTag; +import com.denizenscript.depenizen.bukkit.objects.breweryx.BreweryRecipeTag; import com.dre.brewery.api.events.brew.BrewModifyEvent; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -38,7 +38,7 @@ public BreweryModifyBrewScriptEvent() { } public BrewModifyEvent event; - public BRecipeTag recipeTag; + public BreweryRecipeTag recipeTag; public String type; @Override @@ -64,7 +64,7 @@ public ObjectTag getContext(String name) { @EventHandler public void onBrewModifyEvent(BrewModifyEvent event) { this.event = event; - this.recipeTag = new BRecipeTag(event.getBrew().getCurrentRecipe()); + this.recipeTag = new BreweryRecipeTag(event.getBrew().getCurrentRecipe()); this.type = event.getType().name(); fire(event); } diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BPlayerTag.java b/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BreweryPlayerTag.java similarity index 90% rename from src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BPlayerTag.java rename to src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BreweryPlayerTag.java index a2f294103..88d036b46 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BPlayerTag.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BreweryPlayerTag.java @@ -12,7 +12,7 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; -public class BPlayerTag implements ObjectTag { +public class BreweryPlayerTag implements ObjectTag { // <--[ObjectType] // @name BplayerTag @@ -29,7 +29,7 @@ public class BPlayerTag implements ObjectTag { // --> @Fetchable("bplayer") - public static BPlayerTag valueOf(String string, TagContext context) { + public static BreweryPlayerTag valueOf(String string, TagContext context) { if (string.startsWith("bplayer@")) { string = string.substring("bplayer@".length()); } @@ -37,7 +37,7 @@ public static BPlayerTag valueOf(String string, TagContext context) { if (player == null) { return null; } - return new BPlayerTag(player); + return new BreweryPlayerTag(player); } public static boolean matches(String arg) { @@ -49,13 +49,13 @@ public static boolean matches(String arg) { return BPlayer.hasPlayer(player); } - public static BPlayerTag forPlayer(PlayerTag player) { - return new BPlayerTag(player.getPlayerEntity()); + public static BreweryPlayerTag forPlayer(PlayerTag player) { + return new BreweryPlayerTag(player.getPlayerEntity()); } BPlayer bPlayer = null; - public BPlayerTag(Player player) { + public BreweryPlayerTag(Player player) { if (BPlayer.hasPlayer(player)) { bPlayer = BPlayer.get(player); } @@ -152,7 +152,7 @@ public static void register() { }); } - public static ObjectTagProcessor tagProcessor = new ObjectTagProcessor<>(); + public static ObjectTagProcessor tagProcessor = new ObjectTagProcessor<>(); @Override public ObjectTag getObjectAttribute(Attribute attribute) { diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BRecipeTag.java b/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BreweryRecipeTag.java similarity index 97% rename from src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BRecipeTag.java rename to src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BreweryRecipeTag.java index 9a1707c2c..678e8bde8 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BRecipeTag.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BreweryRecipeTag.java @@ -18,7 +18,7 @@ import java.util.Optional; -public class BRecipeTag implements ObjectTag { +public class BreweryRecipeTag implements ObjectTag { // <--[ObjectType] // @name BRecipeTag @@ -35,7 +35,7 @@ public class BRecipeTag implements ObjectTag { // --> @Fetchable("brecipe") - public static BRecipeTag valueOf(String string, TagContext context) { + public static BreweryRecipeTag valueOf(String string, TagContext context) { if (string.startsWith("brecipe@")) { string = string.substring("brecipe@".length()); } @@ -44,7 +44,7 @@ public static BRecipeTag valueOf(String string, TagContext context) { if (recipe == null) { return null; } - return new BRecipeTag(recipe); + return new BreweryRecipeTag(recipe); } public static boolean matches(String arg) { @@ -54,7 +54,7 @@ public static boolean matches(String arg) { BRecipe bRecipe; - public BRecipeTag(BRecipe bRecipe) { + public BreweryRecipeTag(BRecipe bRecipe) { this.bRecipe = bRecipe; } @@ -340,7 +340,7 @@ public static void register() { })); } - public static ObjectTagProcessor tagProcessor = new ObjectTagProcessor<>(); + public static ObjectTagProcessor tagProcessor = new ObjectTagProcessor<>(); @Override public ObjectTag getObjectAttribute(Attribute attribute) { From 89399ef02b29b46257dd3c8bf36821e873bfda7d Mon Sep 17 00:00:00 2001 From: Jsinco Date: Fri, 7 Jun 2024 03:58:09 -0400 Subject: [PATCH 09/18] add BreweryX dependency --- src/main/java/com/denizenscript/depenizen/bukkit/Depenizen.java | 2 +- src/main/resources/plugin.yml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/Depenizen.java b/src/main/java/com/denizenscript/depenizen/bukkit/Depenizen.java index 585ecee05..580db9b83 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/Depenizen.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/Depenizen.java @@ -110,6 +110,7 @@ public void registerCoreBridges() { registerBridge("BetonQuest", () -> new BetonQuestBridge()); registerBridge("BigDoors", () -> new BigDoorsBridge()); registerBridge("BossShopPro", () -> new BossShopBridge()); + registerBridge("BreweryX", () -> new BreweryXBridge()); registerBridge("CoreProtect", () -> new CoreProtectBridge()); registerBridge("CrackShot", () -> new CrackShotBridge()); registerBridge("EffectLib", () -> new EffectLibBridge()); @@ -146,7 +147,6 @@ public void registerCoreBridges() { registerBridge("Votifier", () -> new VotifierBridge()); registerBridge("WorldEdit", () -> new WorldEditBridge()); registerBridge("WorldGuard", () -> new WorldGuardBridge()); - registerBridge("BreweryX", () -> new BreweryXBridge()); } public void registerBridge(String name, Supplier bridgeSupplier) { diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 4d231cdae..501a2567a 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -13,6 +13,7 @@ softdepend: - BetonQuest - BigDoors - BossShopPro + - BreweryX - CoreProtect - CrackShot - EffectLib From 477394bf82bb451f607fd396e14078e749830035 Mon Sep 17 00:00:00 2001 From: Jsinco Date: Fri, 7 Jun 2024 03:58:09 -0400 Subject: [PATCH 10/18] add BreweryX dependency --- src/main/java/com/denizenscript/depenizen/bukkit/Depenizen.java | 2 +- .../bukkit/events/breweryx/BreweryIngredientAddScriptEvent.java | 1 - src/main/resources/plugin.yml | 1 + 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/Depenizen.java b/src/main/java/com/denizenscript/depenizen/bukkit/Depenizen.java index 585ecee05..580db9b83 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/Depenizen.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/Depenizen.java @@ -110,6 +110,7 @@ public void registerCoreBridges() { registerBridge("BetonQuest", () -> new BetonQuestBridge()); registerBridge("BigDoors", () -> new BigDoorsBridge()); registerBridge("BossShopPro", () -> new BossShopBridge()); + registerBridge("BreweryX", () -> new BreweryXBridge()); registerBridge("CoreProtect", () -> new CoreProtectBridge()); registerBridge("CrackShot", () -> new CrackShotBridge()); registerBridge("EffectLib", () -> new EffectLibBridge()); @@ -146,7 +147,6 @@ public void registerCoreBridges() { registerBridge("Votifier", () -> new VotifierBridge()); registerBridge("WorldEdit", () -> new WorldEditBridge()); registerBridge("WorldGuard", () -> new WorldGuardBridge()); - registerBridge("BreweryX", () -> new BreweryXBridge()); } public void registerBridge(String name, Supplier bridgeSupplier) { diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryIngredientAddScriptEvent.java b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryIngredientAddScriptEvent.java index 74ec2b2a7..448647473 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryIngredientAddScriptEvent.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryIngredientAddScriptEvent.java @@ -5,7 +5,6 @@ import com.denizenscript.denizen.objects.LocationTag; import com.denizenscript.denizen.objects.PlayerTag; import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData; -import com.denizenscript.denizencore.events.ScriptEvent; import com.denizenscript.denizencore.objects.ObjectTag; import com.denizenscript.denizencore.objects.core.ElementTag; import com.denizenscript.denizencore.scripts.ScriptEntryData; diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 4d231cdae..501a2567a 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -13,6 +13,7 @@ softdepend: - BetonQuest - BigDoors - BossShopPro + - BreweryX - CoreProtect - CrackShot - EffectLib From 1814caada0c966ebf952c781eb70084ffa3a1a0c Mon Sep 17 00:00:00 2001 From: Jsinco Date: Fri, 7 Jun 2024 15:37:43 -0400 Subject: [PATCH 11/18] fix review issues --- pom.xml | 4 -- .../BreweryChatDistortScriptEvent.java | 6 +-- .../objects/breweryx/BreweryPlayerTag.java | 31 +++---------- .../objects/breweryx/BreweryRecipeTag.java | 43 ++++++++++--------- 4 files changed, 30 insertions(+), 54 deletions(-) diff --git a/pom.xml b/pom.xml index 0bfd9386f..fd14b202b 100644 --- a/pom.xml +++ b/pom.xml @@ -39,10 +39,6 @@ true - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryChatDistortScriptEvent.java b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryChatDistortScriptEvent.java index a1ec2f5fa..a496ec1ce 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryChatDistortScriptEvent.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryChatDistortScriptEvent.java @@ -29,7 +29,7 @@ public class BreweryChatDistortScriptEvent extends BukkitScriptEvent implements // Returns a PlayerTag of the player that had their chat distorted. // // @Determine - // ElementTag(String) to set the message to be sent after being distorted. + // ElementTag to set the message to be sent after being distorted. // // @Plugin Depenizen, BreweryX // @@ -68,8 +68,8 @@ public ObjectTag getContext(String name) { @Override public boolean handleDetermination(ScriptPath path, String prefix, ObjectTag value) { - if (prefix.equals("message") && value instanceof ElementTag elementTag) { // FIXME - Cast redundant but .toString() returns class and hash? - event.setDistortedMessage(elementTag.asString()); + if (prefix.equals("message")) { + event.setDistortedMessage(value.asElement().asString()); return true; } return super.handleDetermination(path, prefix, value); diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BreweryPlayerTag.java b/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BreweryPlayerTag.java index 88d036b46..0ee372212 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BreweryPlayerTag.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BreweryPlayerTag.java @@ -12,10 +12,10 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; -public class BreweryPlayerTag implements ObjectTag { +public class BreweryPlayerTag extends PlayerTag { // <--[ObjectType] - // @name BplayerTag + // @name BreweryPlayerTag // @prefix bplayer // @base PlayerTag // @format @@ -56,6 +56,7 @@ public static BreweryPlayerTag forPlayer(PlayerTag player) { BPlayer bPlayer = null; public BreweryPlayerTag(Player player) { + super(player); if (BPlayer.hasPlayer(player)) { bPlayer = BPlayer.get(player); } @@ -65,7 +66,7 @@ public BreweryPlayerTag(Player player) { } - String prefix = "BPlayer"; + String prefix = "bplayer"; @Override public String getPrefix() { @@ -88,25 +89,13 @@ public String identifySimple() { } @Override - public ObjectTag setPrefix(String aString) { + public PlayerTag setPrefix(String aString) { this.prefix = aString; return this; } public static void register() { - // <--[tag] - // @attribute - // @returns ElementTag - // @plugin Depenizen, BreweryX - // @description - // Returns the name of the brewery player. - // --> - tagProcessor.registerTag(ElementTag.class, "name", (attribute, object) -> { - return new ElementTag(object.bPlayer.getName()); - }); - - // <--[tag] // @attribute // @returns ElementTag @@ -140,16 +129,6 @@ public static void register() { return new ElementTag(object.bPlayer.getAlcRecovery()); }); - // <--[tag] - // @attribute - // @returns ElementTag - // @plugin Depenizen, BreweryX - // @description - // Returns the Brewery player's UUID. - // --> - tagProcessor.registerTag(ElementTag.class, "uuid", (attribute, object) -> { - return new ElementTag(object.bPlayer.getUuid()); - }); } public static ObjectTagProcessor tagProcessor = new ObjectTagProcessor<>(); diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BreweryRecipeTag.java b/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BreweryRecipeTag.java index 678e8bde8..c427e38a1 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BreweryRecipeTag.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BreweryRecipeTag.java @@ -4,6 +4,7 @@ import com.denizenscript.denizencore.objects.Fetchable; import com.denizenscript.denizencore.objects.ObjectTag; import com.denizenscript.denizencore.objects.core.ColorTag; +import com.denizenscript.denizencore.objects.core.DurationTag; import com.denizenscript.denizencore.objects.core.ElementTag; import com.denizenscript.denizencore.objects.core.ListTag; import com.denizenscript.denizencore.tags.Attribute; @@ -21,7 +22,7 @@ public class BreweryRecipeTag implements ObjectTag { // <--[ObjectType] - // @name BRecipeTag + // @name BreweryRecipeTag // @prefix brecipe // @base ElementTag // @format @@ -96,13 +97,13 @@ public static void register() { // Returns the ID of the recipe as specified in the config. // --> tagProcessor.registerTag(ElementTag.class, "id", (attribute, object) -> { - /* - This being optional was infrastructure added by the original authors and is not used - in Brewery. It will be deprecated and replaced soon. - */ + + // This being optional was infrastructure added by the original authors and is not used + // in Brewery. It will be deprecated and replaced soon. + Optional id = object.bRecipe.getOptionalID(); if (id.isPresent()) { - return new ElementTag(id.get()); + return new ElementTag(id.get(), true); } return null; }); @@ -115,7 +116,7 @@ public static void register() { // Returns the name of the recipe at it's highest quality. // --> tagProcessor.registerTag(ElementTag.class, "name", (attribute, object) -> { - return new ElementTag(object.bRecipe.getRecipeName()); + return new ElementTag(object.bRecipe.getRecipeName(), true); }); // <--[tag] @@ -156,8 +157,8 @@ public static void register() { // @description // Returns the cooking time of the recipe. // --> - tagProcessor.registerTag(ElementTag.class, "cooking_time", (attribute, object) -> { - return new ElementTag(object.bRecipe.getCookingTime()); + tagProcessor.registerTag(DurationTag.class, "cooking_time", (attribute, object) -> { + return new DurationTag(object.bRecipe.getCookingTime() * 60); // Brewery returns value in minutes }); // <--[tag] @@ -165,7 +166,7 @@ public static void register() { // @returns ElementTag(Number) // @plugin Depenizen, BreweryX // @description - // Returns the distill runs of the recipe + // Returns the distill runs of the recipe. // --> tagProcessor.registerTag(ElementTag.class, "distill_runs", (attribute, object) -> { return new ElementTag(object.bRecipe.getDistillRuns()); @@ -221,7 +222,7 @@ public static void register() { // @returns ElementTag(Number) // @plugin Depenizen, BreweryX // @description - // Returns the amount of alcohol in a perfect potion. + // Returns the absolute amount of alcohol 0-100 in a perfect potion (will be added directly to the player, where 100 means fainting) // --> tagProcessor.registerTag(ElementTag.class, "alcohol", (attribute, object) -> { return new ElementTag(object.bRecipe.getAlcohol()); @@ -229,7 +230,7 @@ public static void register() { // <--[tag] // @attribute - // @returns ListTag(ElementTag) + // @returns ListTag // @plugin Depenizen, BreweryX // @description // Returns a ListTag of the lore of the recipe (displayed on potion). @@ -240,7 +241,7 @@ public static void register() { } ListTag lore = new ListTag(); for (Tuple tuple : object.bRecipe.getLore()) { - lore.addObject(new ElementTag(tuple.second())); + lore.addObject(new ElementTag(tuple.second(), true)); } return lore; }); @@ -262,7 +263,7 @@ public static void register() { // <--[tag] // @attribute - // @returns ListTag(ElementTag) + // @returns ListTag // @plugin Depenizen, BreweryX // @description // Returns a ListTag of potion effects of as their names (Example: SLOW_FALLING). @@ -270,14 +271,14 @@ public static void register() { tagProcessor.registerTag(ListTag.class, "effects", (attribute, object) -> { ListTag effects = new ListTag(); for (BEffect bEffect : object.bRecipe.getEffects()) { - effects.addObject(new ElementTag(bEffect.getType().toString())); + effects.addObject(new ElementTag(bEffect.getType().toString(), true)); } return effects; }); // <--[tag] // @attribute - // @returns ListTag(ElementTag) + // @returns ListTag // @plugin Depenizen, BreweryX // @description // Returns a ListTag of commands that are run by the player when the potion is drunk. @@ -288,14 +289,14 @@ public static void register() { } ListTag cmds = new ListTag(); for (Tuple tuple : object.bRecipe.getPlayercmds()) { - cmds.addObject(new ElementTag(tuple.second())); + cmds.addObject(new ElementTag(tuple.second(), true)); } return cmds; }); // <--[tag] // @attribute - // @returns ListTag(ElementTag) + // @returns ListTag // @plugin Depenizen, BreweryX // @description // Returns a ListTag of commands that are run by the server when the potion is drunk. @@ -306,7 +307,7 @@ public static void register() { } ListTag cmds = new ListTag(); for (Tuple tuple : object.bRecipe.getServercmds()) { - cmds.addObject(new ElementTag(tuple.second())); + cmds.addObject(new ElementTag(tuple.second(), true)); } return cmds; }); @@ -322,7 +323,7 @@ public static void register() { if (object.bRecipe.getDrinkMsg() == null) { return null; } - return new ElementTag(object.bRecipe.getDrinkMsg()); + return new ElementTag(object.bRecipe.getDrinkMsg(), true); }); // <--[tag] @@ -336,7 +337,7 @@ public static void register() { if (object.bRecipe.getDrinkTitle() == null) { return null; } - return new ElementTag(object.bRecipe.getDrinkTitle()); + return new ElementTag(object.bRecipe.getDrinkTitle(), true); })); } From 529119c991fbfed9330ba8839083c0cba630c694 Mon Sep 17 00:00:00 2001 From: Jsinco Date: Fri, 7 Jun 2024 16:02:35 -0400 Subject: [PATCH 12/18] turn bplayer obj to extension --- .../bukkit/bridges/BreweryXBridge.java | 4 +- .../BreweryChatDistortScriptEvent.java | 3 - .../breweryx/BreweryDrinkScriptEvent.java | 5 - .../objects/breweryx/BreweryPlayerTag.java | 140 ------------------ .../breweryx/BreweryPlayerExtensions.java | 55 +++++++ 5 files changed, 57 insertions(+), 150 deletions(-) delete mode 100644 src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BreweryPlayerTag.java create mode 100644 src/main/java/com/denizenscript/depenizen/bukkit/properties/breweryx/BreweryPlayerExtensions.java diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/bridges/BreweryXBridge.java b/src/main/java/com/denizenscript/depenizen/bukkit/bridges/BreweryXBridge.java index 87fe23079..f559eb711 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/bridges/BreweryXBridge.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/bridges/BreweryXBridge.java @@ -7,8 +7,8 @@ import com.denizenscript.depenizen.bukkit.events.breweryx.BreweryDrinkScriptEvent; import com.denizenscript.depenizen.bukkit.events.breweryx.BreweryIngredientAddScriptEvent; import com.denizenscript.depenizen.bukkit.events.breweryx.BreweryModifyBrewScriptEvent; -import com.denizenscript.depenizen.bukkit.objects.breweryx.BreweryPlayerTag; import com.denizenscript.depenizen.bukkit.objects.breweryx.BreweryRecipeTag; +import com.denizenscript.depenizen.bukkit.properties.breweryx.BreweryPlayerExtensions; public class BreweryXBridge extends Bridge { @Override @@ -17,7 +17,7 @@ public void init() { ScriptEvent.registerScriptEvent(BreweryModifyBrewScriptEvent.class); ScriptEvent.registerScriptEvent(BreweryIngredientAddScriptEvent.class); ScriptEvent.registerScriptEvent(BreweryChatDistortScriptEvent.class); - ObjectFetcher.registerWithObjectFetcher(BreweryPlayerTag.class); ObjectFetcher.registerWithObjectFetcher(BreweryRecipeTag.class); + BreweryPlayerExtensions.register(); } } diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryChatDistortScriptEvent.java b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryChatDistortScriptEvent.java index a496ec1ce..a3bcf2e7d 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryChatDistortScriptEvent.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryChatDistortScriptEvent.java @@ -6,7 +6,6 @@ import com.denizenscript.denizencore.objects.ObjectTag; import com.denizenscript.denizencore.objects.core.ElementTag; import com.denizenscript.denizencore.scripts.ScriptEntryData; -import com.denizenscript.depenizen.bukkit.objects.breweryx.BreweryPlayerTag; import com.dre.brewery.api.events.PlayerChatDistortEvent; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -25,7 +24,6 @@ public class BreweryChatDistortScriptEvent extends BukkitScriptEvent implements // @Context // Returns the message to be sent after being distorted. // Returns the original message before being distorted. - // Returns an BPlayerTag of the player that drank the brew. // Returns a PlayerTag of the player that had their chat distorted. // // @Determine @@ -60,7 +58,6 @@ public ObjectTag getContext(String name) { return switch (name) { case "message" -> new ElementTag(event.getDistortedMessage()); case "original_message" -> new ElementTag(event.getWrittenMessage()); - case "bplayer" -> BreweryPlayerTag.forPlayer(playerTag); case "player" -> playerTag; default -> super.getContext(name); }; diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryDrinkScriptEvent.java b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryDrinkScriptEvent.java index 59b9a1681..65638d277 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryDrinkScriptEvent.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryDrinkScriptEvent.java @@ -7,7 +7,6 @@ import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData; import com.denizenscript.denizencore.objects.ObjectTag; import com.denizenscript.denizencore.scripts.ScriptEntryData; -import com.denizenscript.depenizen.bukkit.objects.breweryx.BreweryPlayerTag; import com.denizenscript.depenizen.bukkit.objects.breweryx.BreweryRecipeTag; import com.dre.brewery.api.events.brew.BrewDrinkEvent; import org.bukkit.event.EventHandler; @@ -26,7 +25,6 @@ public class BreweryDrinkScriptEvent extends BukkitScriptEvent implements Listen // @Context // Returns an ItemTag of the potion that was drunk. // Returns an BRecipeTag of the recipe that the brew is based off of. - // Returns an BPlayerTag of the player that drank the brew. // Returns a PlayerTag of the player that drank the brew. // // @Plugin Depenizen, BreweryX @@ -42,7 +40,6 @@ public BreweryDrinkScriptEvent() { public BrewDrinkEvent event; public BreweryRecipeTag recipeTag; - public BreweryPlayerTag bPlayerTag; @Override public boolean matches(ScriptPath path) { @@ -58,7 +55,6 @@ public ScriptEntryData getScriptEntryData() { public ObjectTag getContext(String name) { return switch (name) { case "recipe" -> recipeTag; - case "bplayer" -> bPlayerTag; case "item" -> new ItemTag(event.getBrew().createItem(event.getBrew().getCurrentRecipe())); case "player" -> new PlayerTag(event.getPlayer()); default -> super.getContext(name); @@ -69,7 +65,6 @@ public ObjectTag getContext(String name) { public void onBrewDrinkEvent(BrewDrinkEvent event) { this.event = event; this.recipeTag = new BreweryRecipeTag(event.getBrew().getCurrentRecipe()); - this.bPlayerTag = BreweryPlayerTag.forPlayer(new PlayerTag(event.getPlayer())); fire(event); } } diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BreweryPlayerTag.java b/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BreweryPlayerTag.java deleted file mode 100644 index 0ee372212..000000000 --- a/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BreweryPlayerTag.java +++ /dev/null @@ -1,140 +0,0 @@ -package com.denizenscript.depenizen.bukkit.objects.breweryx; - -import com.denizenscript.denizen.objects.PlayerTag; -import com.denizenscript.denizencore.objects.Fetchable; -import com.denizenscript.denizencore.objects.ObjectTag; -import com.denizenscript.denizencore.objects.core.ElementTag; -import com.denizenscript.denizencore.tags.Attribute; -import com.denizenscript.denizencore.tags.ObjectTagProcessor; -import com.denizenscript.denizencore.tags.TagContext; -import com.denizenscript.denizencore.utilities.debugging.Debug; -import com.dre.brewery.BPlayer; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -public class BreweryPlayerTag extends PlayerTag { - - // <--[ObjectType] - // @name BreweryPlayerTag - // @prefix bplayer - // @base PlayerTag - // @format - // The identity format for brewery players is - // For example, 'bplayer@my_player'. - // - // @plugin Depenizen, BreweryX - // @description - // A BPlayerTag represents a Brewery player. - // - // --> - - @Fetchable("bplayer") - public static BreweryPlayerTag valueOf(String string, TagContext context) { - if (string.startsWith("bplayer@")) { - string = string.substring("bplayer@".length()); - } - Player player = Bukkit.getPlayerExact(string); - if (player == null) { - return null; - } - return new BreweryPlayerTag(player); - } - - public static boolean matches(String arg) { - arg = arg.replace("bplayer@", ""); - Player player = Bukkit.getPlayerExact(arg); - if (player == null) { - return false; - } - return BPlayer.hasPlayer(player); - } - - public static BreweryPlayerTag forPlayer(PlayerTag player) { - return new BreweryPlayerTag(player.getPlayerEntity()); - } - - BPlayer bPlayer = null; - - public BreweryPlayerTag(Player player) { - super(player); - if (BPlayer.hasPlayer(player)) { - bPlayer = BPlayer.get(player); - } - else { - Debug.echoError("BPlayer referenced is null!"); - } - } - - - String prefix = "bplayer"; - - @Override - public String getPrefix() { - return this.prefix; - } - - @Override - public boolean isUnique() { - return true; - } - - @Override - public String identify() { - return "bplayer@" + bPlayer.getUuid(); - } - - @Override - public String identifySimple() { - return "bplayer@" + bPlayer.getName(); - } - - @Override - public PlayerTag setPrefix(String aString) { - this.prefix = aString; - return this; - } - - public static void register() { - - // <--[tag] - // @attribute - // @returns ElementTag - // @plugin Depenizen, BreweryX - // @description - // Returns the drunkness of the brewery player. - // --> - tagProcessor.registerTag(ElementTag.class, "drunkenness", (attribute, object) -> { - return new ElementTag(object.bPlayer.getDrunkeness()); - }); - - // <--[tag] - // @attribute - // @returns ElementTag - // @plugin Depenizen, BreweryX - // @description - // Returns the quality of the brewery player's drunkenness (drunkeness * drunkeness). - // --> - tagProcessor.registerTag(ElementTag.class, "quality", (attribute, object) -> { - return new ElementTag(object.bPlayer.getQuality()); - }); - - // <--[tag] - // @attribute - // @returns ElementTag - // @plugin Depenizen, BreweryX - // @description - // Returns the drunkenness reduction per minute. - // --> - tagProcessor.registerTag(ElementTag.class, "alcrecovery", (attribute, object) -> { - return new ElementTag(object.bPlayer.getAlcRecovery()); - }); - - } - - public static ObjectTagProcessor tagProcessor = new ObjectTagProcessor<>(); - - @Override - public ObjectTag getObjectAttribute(Attribute attribute) { - return tagProcessor.getObjectAttribute(this, attribute); - } -} diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/properties/breweryx/BreweryPlayerExtensions.java b/src/main/java/com/denizenscript/depenizen/bukkit/properties/breweryx/BreweryPlayerExtensions.java new file mode 100644 index 000000000..995ba4a5e --- /dev/null +++ b/src/main/java/com/denizenscript/depenizen/bukkit/properties/breweryx/BreweryPlayerExtensions.java @@ -0,0 +1,55 @@ +package com.denizenscript.depenizen.bukkit.properties.breweryx; + +import com.denizenscript.denizen.objects.PlayerTag; +import com.denizenscript.denizencore.objects.core.ElementTag; +import com.dre.brewery.BPlayer; + +public class BreweryPlayerExtensions { + + public static void register() { + // <--[tag] + // @attribute + // @returns ElementTag + // @plugin Depenizen, BreweryX + // @description + // Returns the drunkness of the brewery player. + // --> + PlayerTag.tagProcessor.registerTag(ElementTag.class, "drunkenness", (attribute, object) -> { + BPlayer bPlayer = BPlayer.hasPlayer(object.getPlayerEntity()) ? BPlayer.get(object.getPlayerEntity()) : null; + if (bPlayer != null) { + return new ElementTag(bPlayer.getDrunkeness()); + } + return null; + }); + + // <--[tag] + // @attribute + // @returns ElementTag + // @plugin Depenizen, BreweryX + // @description + // Returns the quality of the brewery player's drunkenness (drunkeness * drunkeness). + // --> + PlayerTag.tagProcessor.registerTag(ElementTag.class, "quality", (attribute, object) -> { + BPlayer bPlayer = BPlayer.hasPlayer(object.getPlayerEntity()) ? BPlayer.get(object.getPlayerEntity()) : null; + if (bPlayer != null) { + return new ElementTag(bPlayer.getQuality()); + } + return null; + }); + + // <--[tag] + // @attribute + // @returns ElementTag + // @plugin Depenizen, BreweryX + // @description + // Returns the drunkenness reduction per minute. + // --> + PlayerTag.tagProcessor.registerTag(ElementTag.class, "alcrecovery", (attribute, object) -> { + BPlayer bPlayer = BPlayer.hasPlayer(object.getPlayerEntity()) ? BPlayer.get(object.getPlayerEntity()) : null; + if (bPlayer != null) { + return new ElementTag(bPlayer.getAlcRecovery()); + } + return null; + }); + } +} From 45d41d01e72939ec1dc2da89865fcabd5bba9e02 Mon Sep 17 00:00:00 2001 From: Jsinco Date: Fri, 7 Jun 2024 21:30:29 -0400 Subject: [PATCH 13/18] review changes --- .../BreweryChatDistortScriptEvent.java | 1 - .../breweryx/BreweryDrinkScriptEvent.java | 2 +- .../BreweryModifyBrewScriptEvent.java | 2 +- .../objects/breweryx/BreweryRecipeTag.java | 61 +++++++++---------- .../breweryx/BreweryPlayerExtensions.java | 18 +++--- 5 files changed, 40 insertions(+), 44 deletions(-) diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryChatDistortScriptEvent.java b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryChatDistortScriptEvent.java index a3bcf2e7d..7aed4bc8d 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryChatDistortScriptEvent.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryChatDistortScriptEvent.java @@ -12,7 +12,6 @@ public class BreweryChatDistortScriptEvent extends BukkitScriptEvent implements Listener { - // <--[event] // @Events // brewery chat distort diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryDrinkScriptEvent.java b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryDrinkScriptEvent.java index 65638d277..ee00401f6 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryDrinkScriptEvent.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryDrinkScriptEvent.java @@ -24,7 +24,7 @@ public class BreweryDrinkScriptEvent extends BukkitScriptEvent implements Listen // // @Context // Returns an ItemTag of the potion that was drunk. - // Returns an BRecipeTag of the recipe that the brew is based off of. + // Returns an BreweryRecipeTag of the recipe that the brew is based off of. // Returns a PlayerTag of the player that drank the brew. // // @Plugin Depenizen, BreweryX diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryModifyBrewScriptEvent.java b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryModifyBrewScriptEvent.java index 8d54e0a91..0390612c8 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryModifyBrewScriptEvent.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryModifyBrewScriptEvent.java @@ -26,7 +26,7 @@ public class BreweryModifyBrewScriptEvent extends BukkitScriptEvent implements L // // @Context // Returns an ItemTag of the potion that was drunk. - // Returns an BRecipeTag of the recipe that the brew is based off of. + // Returns an BreweryRecipeTag of the recipe that the brew is based off of. // // @Plugin Depenizen, BreweryX // diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BreweryRecipeTag.java b/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BreweryRecipeTag.java index c427e38a1..700335aa2 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BreweryRecipeTag.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BreweryRecipeTag.java @@ -23,22 +23,22 @@ public class BreweryRecipeTag implements ObjectTag { // <--[ObjectType] // @name BreweryRecipeTag - // @prefix brecipe + // @prefix breweryrecipe // @base ElementTag // @format // The identity format for brewery is - // For example, 'brecipe@my_recipe'. + // For example, 'breweryrecipe@my_recipe'. // // @plugin Depenizen, BreweryX // @description - // A BRecipeTag represents a Brewery recipe. + // A BreweryRecipeTag represents a Brewery recipe. // // --> - @Fetchable("brecipe") + @Fetchable("breweryrecipe") public static BreweryRecipeTag valueOf(String string, TagContext context) { - if (string.startsWith("brecipe@")) { - string = string.substring("brecipe@".length()); + if (string.startsWith("breweryrecipe@")) { + string = string.substring("breweryrecipe@".length()); } BRecipe recipe = BRecipe.get(string); @@ -49,7 +49,7 @@ public static BreweryRecipeTag valueOf(String string, TagContext context) { } public static boolean matches(String arg) { - arg = arg.replace("brecipe@", ""); + arg = arg.replace("breweryrecipe@", ""); return BRecipe.get(arg) != null; } @@ -59,7 +59,7 @@ public BreweryRecipeTag(BRecipe bRecipe) { this.bRecipe = bRecipe; } - String prefix = "brecipe"; + String prefix = "breweryrecipe"; @Override public String getPrefix() { @@ -73,7 +73,7 @@ public boolean isUnique() { @Override public String identify() { - return "brecipe@" + bRecipe.getRecipeName(); + return "breweryrecipe@" + bRecipe.getRecipeName(); } @Override @@ -88,19 +88,16 @@ public ObjectTag setPrefix(String aString) { } public static void register() { - // <--[tag] - // @attribute + // @attribute // @returns ElementTag // @plugin Depenizen, BreweryX // @description // Returns the ID of the recipe as specified in the config. // --> tagProcessor.registerTag(ElementTag.class, "id", (attribute, object) -> { - // This being optional was infrastructure added by the original authors and is not used // in Brewery. It will be deprecated and replaced soon. - Optional id = object.bRecipe.getOptionalID(); if (id.isPresent()) { return new ElementTag(id.get(), true); @@ -109,7 +106,7 @@ public static void register() { }); // <--[tag] - // @attribute + // @attribute // @returns ElementTag // @plugin Depenizen, BreweryX // @description @@ -120,7 +117,7 @@ public static void register() { }); // <--[tag] - // @attribute + // @attribute // @returns ListTag(ItemTag) // @plugin Depenizen, BreweryX // @description @@ -140,7 +137,7 @@ public static void register() { }); // <--[tag] - // @attribute + // @attribute // @returns ElementTag(Number) // @plugin Depenizen, BreweryX // @description @@ -151,8 +148,8 @@ public static void register() { }); // <--[tag] - // @attribute - // @returns ElementTag(Number) + // @attribute + // @returns DurationTag // @plugin Depenizen, BreweryX // @description // Returns the cooking time of the recipe. @@ -162,7 +159,7 @@ public static void register() { }); // <--[tag] - // @attribute + // @attribute // @returns ElementTag(Number) // @plugin Depenizen, BreweryX // @description @@ -173,7 +170,7 @@ public static void register() { }); // <--[tag] - // @attribute + // @attribute // @returns ElementTag(Number) // @plugin Depenizen, BreweryX // @description @@ -184,7 +181,7 @@ public static void register() { }); // <--[tag] - // @attribute + // @attribute // @returns ElementTag(Number) // @plugin Depenizen, BreweryX // @description @@ -195,7 +192,7 @@ public static void register() { }); // <--[tag] - // @attribute + // @attribute // @returns ElementTag(Number) // @plugin Depenizen, BreweryX // @description @@ -206,7 +203,7 @@ public static void register() { }); // <--[tag] - // @attribute + // @attribute // @returns ColorTag // @plugin Depenizen, BreweryX // @description @@ -218,18 +215,18 @@ public static void register() { })); // <--[tag] - // @attribute + // @attribute // @returns ElementTag(Number) // @plugin Depenizen, BreweryX // @description - // Returns the absolute amount of alcohol 0-100 in a perfect potion (will be added directly to the player, where 100 means fainting) + // Returns the absolute amount of alcohol 0-100 in a perfect potion (will be added directly to the player, where 100 means fainting). // --> tagProcessor.registerTag(ElementTag.class, "alcohol", (attribute, object) -> { return new ElementTag(object.bRecipe.getAlcohol()); }); // <--[tag] - // @attribute + // @attribute // @returns ListTag // @plugin Depenizen, BreweryX // @description @@ -247,7 +244,7 @@ public static void register() { }); // <--[tag] - // @attribute + // @attribute // @returns ListTag(ElementTag(Number)) // @plugin Depenizen, BreweryX // @description @@ -262,7 +259,7 @@ public static void register() { }); // <--[tag] - // @attribute + // @attribute // @returns ListTag // @plugin Depenizen, BreweryX // @description @@ -277,7 +274,7 @@ public static void register() { }); // <--[tag] - // @attribute + // @attribute // @returns ListTag // @plugin Depenizen, BreweryX // @description @@ -295,7 +292,7 @@ public static void register() { }); // <--[tag] - // @attribute + // @attribute // @returns ListTag // @plugin Depenizen, BreweryX // @description @@ -313,7 +310,7 @@ public static void register() { }); // <--[tag] - // @attribute + // @attribute // @returns ElementTag // @plugin Depenizen, BreweryX // @description @@ -327,7 +324,7 @@ public static void register() { }); // <--[tag] - // @attribute + // @attribute // @returns ElementTag // @plugin Depenizen, BreweryX // @description diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/properties/breweryx/BreweryPlayerExtensions.java b/src/main/java/com/denizenscript/depenizen/bukkit/properties/breweryx/BreweryPlayerExtensions.java index 995ba4a5e..ceb1ccc8f 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/properties/breweryx/BreweryPlayerExtensions.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/properties/breweryx/BreweryPlayerExtensions.java @@ -8,13 +8,13 @@ public class BreweryPlayerExtensions { public static void register() { // <--[tag] - // @attribute + // @attribute // @returns ElementTag // @plugin Depenizen, BreweryX // @description - // Returns the drunkness of the brewery player. + // Returns the drunkenness of the brewery player or null if Brewery has no data on the player. // --> - PlayerTag.tagProcessor.registerTag(ElementTag.class, "drunkenness", (attribute, object) -> { + PlayerTag.tagProcessor.registerTag(ElementTag.class, "brewery_drunkenness", (attribute, object) -> { BPlayer bPlayer = BPlayer.hasPlayer(object.getPlayerEntity()) ? BPlayer.get(object.getPlayerEntity()) : null; if (bPlayer != null) { return new ElementTag(bPlayer.getDrunkeness()); @@ -23,13 +23,13 @@ public static void register() { }); // <--[tag] - // @attribute + // @attribute // @returns ElementTag // @plugin Depenizen, BreweryX // @description - // Returns the quality of the brewery player's drunkenness (drunkeness * drunkeness). + // Returns the quality of the brewery player's drunkenness (drunkeness * drunkeness) or null if Brewery has no data on the player. // --> - PlayerTag.tagProcessor.registerTag(ElementTag.class, "quality", (attribute, object) -> { + PlayerTag.tagProcessor.registerTag(ElementTag.class, "brewery_quality", (attribute, object) -> { BPlayer bPlayer = BPlayer.hasPlayer(object.getPlayerEntity()) ? BPlayer.get(object.getPlayerEntity()) : null; if (bPlayer != null) { return new ElementTag(bPlayer.getQuality()); @@ -38,13 +38,13 @@ public static void register() { }); // <--[tag] - // @attribute + // @attribute // @returns ElementTag // @plugin Depenizen, BreweryX // @description - // Returns the drunkenness reduction per minute. + // Returns the drunkenness reduction per minute or null if Brewery has no data on the player. // --> - PlayerTag.tagProcessor.registerTag(ElementTag.class, "alcrecovery", (attribute, object) -> { + PlayerTag.tagProcessor.registerTag(ElementTag.class, "brewery_alcoholrecovery", (attribute, object) -> { BPlayer bPlayer = BPlayer.hasPlayer(object.getPlayerEntity()) ? BPlayer.get(object.getPlayerEntity()) : null; if (bPlayer != null) { return new ElementTag(bPlayer.getAlcRecovery()); From 9862906f4a8bc0bc54512d19278742ca457592d4 Mon Sep 17 00:00:00 2001 From: Jsinco Date: Fri, 7 Jun 2024 22:00:49 -0400 Subject: [PATCH 14/18] review changes --- .../bukkit/properties/breweryx/BreweryPlayerExtensions.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/properties/breweryx/BreweryPlayerExtensions.java b/src/main/java/com/denizenscript/depenizen/bukkit/properties/breweryx/BreweryPlayerExtensions.java index ceb1ccc8f..9b49e1c1a 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/properties/breweryx/BreweryPlayerExtensions.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/properties/breweryx/BreweryPlayerExtensions.java @@ -15,7 +15,7 @@ public static void register() { // Returns the drunkenness of the brewery player or null if Brewery has no data on the player. // --> PlayerTag.tagProcessor.registerTag(ElementTag.class, "brewery_drunkenness", (attribute, object) -> { - BPlayer bPlayer = BPlayer.hasPlayer(object.getPlayerEntity()) ? BPlayer.get(object.getPlayerEntity()) : null; + BPlayer bPlayer = BPlayer.hasPlayer(object.getOfflinePlayer()) ? BPlayer.get(object.getOfflinePlayer()) : null; if (bPlayer != null) { return new ElementTag(bPlayer.getDrunkeness()); } @@ -30,7 +30,7 @@ public static void register() { // Returns the quality of the brewery player's drunkenness (drunkeness * drunkeness) or null if Brewery has no data on the player. // --> PlayerTag.tagProcessor.registerTag(ElementTag.class, "brewery_quality", (attribute, object) -> { - BPlayer bPlayer = BPlayer.hasPlayer(object.getPlayerEntity()) ? BPlayer.get(object.getPlayerEntity()) : null; + BPlayer bPlayer = BPlayer.hasPlayer(object.getOfflinePlayer()) ? BPlayer.get(object.getOfflinePlayer()) : null; if (bPlayer != null) { return new ElementTag(bPlayer.getQuality()); } @@ -45,7 +45,7 @@ public static void register() { // Returns the drunkenness reduction per minute or null if Brewery has no data on the player. // --> PlayerTag.tagProcessor.registerTag(ElementTag.class, "brewery_alcoholrecovery", (attribute, object) -> { - BPlayer bPlayer = BPlayer.hasPlayer(object.getPlayerEntity()) ? BPlayer.get(object.getPlayerEntity()) : null; + BPlayer bPlayer = BPlayer.hasPlayer(object.getOfflinePlayer()) ? BPlayer.get(object.getOfflinePlayer()) : null; if (bPlayer != null) { return new ElementTag(bPlayer.getAlcRecovery()); } From cdaf64f4684c46685d504fdf1c1579343fdcfe46 Mon Sep 17 00:00:00 2001 From: Jsinco Date: Sat, 8 Jun 2024 20:57:18 -0400 Subject: [PATCH 15/18] stray newline --- .../depenizen/bukkit/objects/breweryx/BreweryRecipeTag.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BreweryRecipeTag.java b/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BreweryRecipeTag.java index 700335aa2..2f23fb9cb 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BreweryRecipeTag.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BreweryRecipeTag.java @@ -96,8 +96,7 @@ public static void register() { // Returns the ID of the recipe as specified in the config. // --> tagProcessor.registerTag(ElementTag.class, "id", (attribute, object) -> { - // This being optional was infrastructure added by the original authors and is not used - // in Brewery. It will be deprecated and replaced soon. + // This being optional was infrastructure added by the original authors and is not used in Brewery. It will be deprecated and replaced soon. Optional id = object.bRecipe.getOptionalID(); if (id.isPresent()) { return new ElementTag(id.get(), true); From 68644f0ededf8829a59a179bb8e6a9068c6a1073 Mon Sep 17 00:00:00 2001 From: Jsinco Date: Sat, 8 Jun 2024 21:19:21 -0400 Subject: [PATCH 16/18] register tagProcessor with object init --- .../denizenscript/depenizen/bukkit/bridges/BreweryXBridge.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/bridges/BreweryXBridge.java b/src/main/java/com/denizenscript/depenizen/bukkit/bridges/BreweryXBridge.java index f559eb711..f8da835ab 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/bridges/BreweryXBridge.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/bridges/BreweryXBridge.java @@ -17,7 +17,7 @@ public void init() { ScriptEvent.registerScriptEvent(BreweryModifyBrewScriptEvent.class); ScriptEvent.registerScriptEvent(BreweryIngredientAddScriptEvent.class); ScriptEvent.registerScriptEvent(BreweryChatDistortScriptEvent.class); - ObjectFetcher.registerWithObjectFetcher(BreweryRecipeTag.class); + ObjectFetcher.registerWithObjectFetcher(BreweryRecipeTag.class, BreweryRecipeTag.tagProcessor); BreweryPlayerExtensions.register(); } } From 49b681d539541a3d9b6f1fe6931e8b01c514d6d5 Mon Sep 17 00:00:00 2001 From: Jsinco Date: Thu, 21 Nov 2024 23:27:48 -0500 Subject: [PATCH 17/18] Update BreweryX dependency, fix a couple of things after Aya's review. --- pom.xml | 2 +- .../breweryx/BreweryDrinkScriptEvent.java | 2 +- .../BreweryModifyBrewScriptEvent.java | 2 +- .../objects/breweryx/BreweryRecipeTag.java | 19 ++++--------------- 4 files changed, 7 insertions(+), 18 deletions(-) diff --git a/pom.xml b/pom.xml index 31c552442..404db9846 100644 --- a/pom.xml +++ b/pom.xml @@ -392,7 +392,7 @@ com.dre.brewery BreweryX - 3.2.0 + 3.3.6-SNAPSHOT jar system ${basedir}/lib/BreweryX.jar diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryDrinkScriptEvent.java b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryDrinkScriptEvent.java index ee00401f6..ba41dc834 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryDrinkScriptEvent.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryDrinkScriptEvent.java @@ -55,7 +55,7 @@ public ScriptEntryData getScriptEntryData() { public ObjectTag getContext(String name) { return switch (name) { case "recipe" -> recipeTag; - case "item" -> new ItemTag(event.getBrew().createItem(event.getBrew().getCurrentRecipe())); + case "item" -> new ItemTag(event.getBrew().createItem(event.getBrew().getCurrentRecipe(), false)); case "player" -> new PlayerTag(event.getPlayer()); default -> super.getContext(name); }; diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryModifyBrewScriptEvent.java b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryModifyBrewScriptEvent.java index 0390612c8..8d1cee14a 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryModifyBrewScriptEvent.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/events/breweryx/BreweryModifyBrewScriptEvent.java @@ -56,7 +56,7 @@ public ObjectTag getContext(String name) { return switch (name) { case "recipe" -> recipeTag; case "type" -> new ElementTag(type); - case "item" -> new ItemTag(event.getBrew().createItem(event.getBrew().getCurrentRecipe())); + case "item" -> new ItemTag(event.getBrew().createItem(event.getBrew().getCurrentRecipe(), false)); default -> super.getContext(name); }; } diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BreweryRecipeTag.java b/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BreweryRecipeTag.java index 2f23fb9cb..13c0202c1 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BreweryRecipeTag.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BreweryRecipeTag.java @@ -17,8 +17,6 @@ import org.bukkit.Color; import org.bukkit.Material; -import java.util.Optional; - public class BreweryRecipeTag implements ObjectTag { // <--[ObjectType] @@ -96,12 +94,8 @@ public static void register() { // Returns the ID of the recipe as specified in the config. // --> tagProcessor.registerTag(ElementTag.class, "id", (attribute, object) -> { - // This being optional was infrastructure added by the original authors and is not used in Brewery. It will be deprecated and replaced soon. - Optional id = object.bRecipe.getOptionalID(); - if (id.isPresent()) { - return new ElementTag(id.get(), true); - } - return null; + String id = object.bRecipe.getId(); + return new ElementTag(id, true); }); // <--[tag] @@ -125,12 +119,7 @@ public static void register() { tagProcessor.registerTag(ListTag.class, "ingredients", (attribute, object) -> { ListTag ingredients = new ListTag(); for (RecipeItem recipeItem : object.bRecipe.getIngredients()) { - if (recipeItem.getMaterials() == null) { - continue; - } - for (Material material : recipeItem.getMaterials()) { - ingredients.addObject(new ItemTag(material, recipeItem.getAmount())); - } + ingredients.add(recipeItem.toConfigString()); } return ingredients; }); @@ -165,7 +154,7 @@ public static void register() { // Returns the distill runs of the recipe. // --> tagProcessor.registerTag(ElementTag.class, "distill_runs", (attribute, object) -> { - return new ElementTag(object.bRecipe.getDistillRuns()); + return new ElementTag(object.bRecipe.getDistillruns()); }); // <--[tag] From e96c8c4cbea007df3cccb4163ab2422eb10c5f95 Mon Sep 17 00:00:00 2001 From: Jsinco Date: Fri, 22 Nov 2024 20:10:57 -0500 Subject: [PATCH 18/18] fix identifier, get names based on quality. Add is_valid, has_glint, full_name --- .../objects/breweryx/BreweryRecipeTag.java | 50 +++++++++++++++---- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BreweryRecipeTag.java b/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BreweryRecipeTag.java index 13c0202c1..a581ae2b9 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BreweryRecipeTag.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/objects/breweryx/BreweryRecipeTag.java @@ -1,6 +1,5 @@ package com.denizenscript.depenizen.bukkit.objects.breweryx; -import com.denizenscript.denizen.objects.ItemTag; import com.denizenscript.denizencore.objects.Fetchable; import com.denizenscript.denizencore.objects.ObjectTag; import com.denizenscript.denizencore.objects.core.ColorTag; @@ -15,7 +14,6 @@ import com.dre.brewery.recipe.RecipeItem; import com.dre.brewery.utility.Tuple; import org.bukkit.Color; -import org.bukkit.Material; public class BreweryRecipeTag implements ObjectTag { @@ -25,7 +23,7 @@ public class BreweryRecipeTag implements ObjectTag { // @base ElementTag // @format // The identity format for brewery is - // For example, 'breweryrecipe@my_recipe'. + // For example, 'breweryrecipe@example_recipe'. // // @plugin Depenizen, BreweryX // @description @@ -71,7 +69,7 @@ public boolean isUnique() { @Override public String identify() { - return "breweryrecipe@" + bRecipe.getRecipeName(); + return "breweryrecipe@" + bRecipe.getId(); } @Override @@ -91,7 +89,7 @@ public static void register() { // @returns ElementTag // @plugin Depenizen, BreweryX // @description - // Returns the ID of the recipe as specified in the config. + // Returns the ID of the recipe. // --> tagProcessor.registerTag(ElementTag.class, "id", (attribute, object) -> { String id = object.bRecipe.getId(); @@ -99,14 +97,25 @@ public static void register() { }); // <--[tag] - // @attribute + // @attribute [] // @returns ElementTag // @plugin Depenizen, BreweryX // @description - // Returns the name of the recipe at it's highest quality. + // Returns the name of the recipe based on the provided quality number. // --> - tagProcessor.registerTag(ElementTag.class, "name", (attribute, object) -> { - return new ElementTag(object.bRecipe.getRecipeName(), true); + tagProcessor.registerTag(ElementTag.class, ElementTag.class, "name", (attribute, object, quality) -> { + return new ElementTag(object.bRecipe.getName(quality.asInt()), true); + }); + + // <--[tag] + // @attribute + // @returns ElementTag + // @plugin Depenizen, BreweryX + // @description + // Returns the full name of the recipe as declared in the recipes file. + // --> + tagProcessor.registerTag(ElementTag.class, "full_name", (attribute, object) -> { + return new ElementTag(String.join("/", object.bRecipe.getName()), true); }); // <--[tag] @@ -324,6 +333,29 @@ public static void register() { } return new ElementTag(object.bRecipe.getDrinkTitle(), true); })); + + // <--[tag] + // @attribute + // @returns ElementTag + // @plugin Depenizen, BreweryX + // @description + // Returns if the recipe, once created into a brew, has a glint effect. + // --> + tagProcessor.registerTag(ElementTag.class, "has_glint", ((attribute, object) -> { + return new ElementTag(object.bRecipe.isGlint()); + })); + + + // <--[tag] + // @attribute + // @returns ElementTag + // @plugin Depenizen, BreweryX + // @description + // Returns if the recipe is valid and can be created. + // --> + tagProcessor.registerTag(ElementTag.class, "is_valid", ((attribute, object) -> { + return new ElementTag(object.bRecipe.isValid()); + })); } public static ObjectTagProcessor tagProcessor = new ObjectTagProcessor<>();