-
-
Notifications
You must be signed in to change notification settings - Fork 45
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
base: master
Are you sure you want to change the base?
Changes from 10 commits
b681351
7820362
fceacdb
dadac47
b89a1d8
92b1f86
ab820b4
09bc856
3e3b437
89399ef
477394b
1814caa
529119c
4c78d7f
e1cfe5e
8d1993d
45d41d0
9862906
cdaf64f
68644f0
827ed9b
0e573d7
ba65850
49b681d
e96c8c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 { | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
// | ||
// @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? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... what? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
} |
There was a problem hiding this comment.
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