Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BreweryX (v3.3.6+) Support #430

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b681351
working on it
Jsinco Feb 29, 2024
7820362
working on it
Jsinco Apr 29, 2024
fceacdb
laptop push
Jsinco May 5, 2024
dadac47
should be ready for pull
Jsinco Jun 6, 2024
b89a1d8
Merge remote-tracking branch 'origin/master'
Jsinco Jun 6, 2024
92b1f86
BreweryX support
Jsinco Jun 6, 2024
ab820b4
laptop push
Jsinco Jun 7, 2024
09bc856
code fixes
Jsinco Jun 7, 2024
3e3b437
rename classes
Jsinco Jun 7, 2024
89399ef
add BreweryX dependency
Jsinco Jun 7, 2024
477394b
add BreweryX dependency
Jsinco Jun 7, 2024
1814caa
fix review issues
Jsinco Jun 7, 2024
529119c
turn bplayer obj to extension
Jsinco Jun 7, 2024
4c78d7f
Merge branch 'master' of https://github.com/Jsinco/Depenizen
Jsinco Jun 7, 2024
e1cfe5e
Merge branch 'master' of https://github.com/Jsinco/Depenizen
Jsinco Jun 7, 2024
8d1993d
Merge branch 'master' of https://github.com/Jsinco/Depenizen
Jsinco Jun 7, 2024
45d41d0
review changes
Jsinco Jun 8, 2024
9862906
review changes
Jsinco Jun 8, 2024
cdaf64f
stray newline
Jsinco Jun 9, 2024
68644f0
register tagProcessor with object init
Jsinco Jun 9, 2024
827ed9b
Merge branch 'DenizenScript:master' into master
Jsinco Jul 10, 2024
0e573d7
Merge branch 'DenizenScript:master' into master
Jsinco Aug 24, 2024
ba65850
Merge branch 'DenizenScript:master' into master
Jsinco Nov 22, 2024
49b681d
Update BreweryX dependency, fix a couple of things after Aya's review.
Jsinco Nov 22, 2024
e96c8c4
fix identifier, get names based on quality. Add is_valid, has_glint, …
Jsinco Nov 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spigot-repo</id>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this shouldn't be here

<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>

<dependencies>
Expand Down Expand Up @@ -389,6 +393,14 @@
<scope>system</scope>
<systemPath>${basedir}/lib/BigDoors.jar</systemPath>
</dependency>
<dependency>
<groupId>com.dre.brewery</groupId>
<artifactId>BreweryX</artifactId>
<version>3.1.7</version>
<type>jar</type>
<scope>system</scope>
<systemPath>${basedir}/lib/BreweryX.jar</systemPath>
</dependency>
</dependencies>

<distributionManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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.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.BreweryPlayerTag;
import com.denizenscript.depenizen.bukkit.objects.breweryx.BreweryRecipeTag;

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(BreweryPlayerTag.class);
ObjectFetcher.registerWithObjectFetcher(BreweryRecipeTag.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
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.BreweryPlayerTag;
import com.dre.brewery.api.events.PlayerChatDistortEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

public class BreweryChatDistortScriptEvent extends BukkitScriptEvent implements Listener {


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stray double newline

// <--[event]
// @Events
// brewery chat distort
//
// @Cancellable true
//
// @Triggers when a drunk brewery player's chat is distorted.
//
// @Context
// <context.message> Returns the message to be sent after being distorted.
// <context.original_message> Returns the original message before being distorted.
// <context.bplayer> Returns an BPlayerTag of the player that drank the brew.
// <context.player> Returns a PlayerTag of the player that had their chat distorted.
//
// @Determine
// ElementTag(String) to set the message to be sent after being distorted.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ElementTag(String) doesn't exist, it's just ElementTag

//
// @Plugin Depenizen, BreweryX
//
// @Player Always.
//
// @Group Depenizen
//
// -->
public BreweryChatDistortScriptEvent() {
registerCouldMatcher("brewery chat distort");
}

public PlayerChatDistortEvent event;
public PlayerTag playerTag;

@Override
public boolean matches(ScriptPath path) {
return super.matches(path);
}

@Override
public ScriptEntryData getScriptEntryData() {
return new BukkitScriptEntryData(event.getPlayer());
}

@Override
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);
};
}

@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?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... what?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I might just be confused here. If I don't cast the ObjectTag to an ElementTag I can't do value.asString(). When you told me the cast was redundant I assumed you meant I could just do ObjectTag#toString(). Just looked again and I'm guessing you wanted me to do value.asElement().asString()?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused why you think toString doesn't work but yes asElement().asString() is the most proper option

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going to the declaration of value.toString() brought me to the Object.java class which is why I why I figured it wouldn't work. Sorry about that

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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.denizenscript.depenizen.bukkit.events.breweryx;


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.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;
import org.bukkit.event.Listener;

public class BreweryDrinkScriptEvent extends BukkitScriptEvent implements Listener {

// <--[event]
// @Events
// brewery drink
//
// @Cancellable true
//
// @Triggers when a player drinks a potion that is considered a BreweryX potion.
//
// @Context
// <context.item> Returns an ItemTag of the potion that was drunk.
// <context.recipe> Returns an BRecipeTag of the recipe that the brew is based off of.
// <context.bplayer> Returns an BPlayerTag of the player that drank the brew.
// <context.player> Returns a PlayerTag of the player that drank the brew.
//
// @Plugin Depenizen, BreweryX
//
// @Player Always.
//
// @Group Depenizen
//
// -->
public BreweryDrinkScriptEvent() {
registerCouldMatcher("brewery drink");
}

public BrewDrinkEvent event;
public BreweryRecipeTag recipeTag;
public BreweryPlayerTag bPlayerTag;

@Override
public boolean matches(ScriptPath path) {
return super.matches(path);
}

@Override
public ScriptEntryData getScriptEntryData() {
return new BukkitScriptEntryData(event.getPlayer());
}

@Override
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);
};
}

@EventHandler
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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
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 {

// <--[event]
// @Events
// brewery ingredient add
//
// @Cancellable true
//
// @Triggers when a player adds an ingredient to a cauldron.
//
// @Context
// <context.item> Returns an ItemTag of the ingredient that was added.
// <context.location> Returns a LocationTag of the cauldron.
// <context.player> Returns a PlayerTag of the player that added the ingredient.
// <context.take_item> 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 BreweryIngredientAddScriptEvent() {
registerCouldMatcher("brewery ingredient add");
}

public IngedientAddEvent event;

@Override
public boolean matches(ScriptPath path) {
return super.matches(path);
}

@Override
public ScriptEntryData getScriptEntryData() {
return new BukkitScriptEntryData(event.getPlayer());
}

@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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
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.BreweryRecipeTag;
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 {

// <--[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
// <context.item> Returns an ItemTag of the potion that was drunk.
// <context.recipe> Returns an BRecipeTag of the recipe that the brew is based off of.
//
// @Plugin Depenizen, BreweryX
//
// @Group Depenizen
//
// -->
public BreweryModifyBrewScriptEvent() {
registerCouldMatcher("brewery brew modify");
}

public BrewModifyEvent event;
public BreweryRecipeTag recipeTag;
public String type;

@Override
public boolean matches(ScriptPath path) {
return super.matches(path);
}

@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);
case "item" -> new ItemTag(event.getBrew().createItem(event.getBrew().getCurrentRecipe()));
default -> super.getContext(name);
};
}

@EventHandler
public void onBrewModifyEvent(BrewModifyEvent event) {
this.event = event;
this.recipeTag = new BreweryRecipeTag(event.getBrew().getCurrentRecipe());
this.type = event.getType().name();
fire(event);
}
}
Loading