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.2.0+) Support #430

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open

Conversation

Jsinco
Copy link

@Jsinco Jsinco commented Jun 6, 2024

Many many months ago in the Denizen Discord, I wanted to figure out how to start the execution of a script from another plugin so I could include Denizen support in BreweryX. After the discussion I decided to implement BreweryX into Depenizen instead. Everything should be compatible starting with release 3.2.0 of BreweryX (which I plan to release soon after this pull request). Hopefully there isn't much I need to change here, I'm a first-time contributer but I did my best to follow the style of other plugin bridges.

BreweryX Github: https://github.com/Jsinco/BreweryX
Spigot page: https://www.spigotmc.org/resources/breweryx.114777/

@CLAassistant
Copy link

CLAassistant commented Jun 6, 2024

CLA assistant check
All committers have signed the CLA.


@Override
public boolean couldMatch(ScriptPath path) {
return path.eventLower.startsWith("brewery chat distort");
Copy link
Member

Choose a reason for hiding this comment

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

this is the legacy scriptevent format, please check the code in Denizen-Core, Denizen, or dDiscordBot for modern examples


@Override
public ScriptEntryData getScriptEntryData() {
return new BukkitScriptEntryData(new PlayerTag(event.getPlayer()), null);
Copy link
Member

Choose a reason for hiding this comment

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

this should just be new BukkitScriptEntryData(event.getPlayer() iirc


@Override
public boolean handleDetermination(ScriptPath path, String prefix, ObjectTag value) {
if (prefix.equals("message") && value instanceof ElementTag elementTag) {
Copy link
Member

Choose a reason for hiding this comment

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

the ElementTag cast is redundant

Copy link
Author

Choose a reason for hiding this comment

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

Sorry, I didn't understand this one.

        if (prefix.equals("message") && value instanceof ElementTag elementTag) { // FIXME - Cast redundant but .toString() returns class and hash?

import org.bukkit.entity.Player;

// TODO: OfflinePlayer support
public class BPlayerTag implements ObjectTag {
Copy link
Member

Choose a reason for hiding this comment

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

This whole object doesn't make sense -- this should just be an extension of PlayerTag

also identifying players by name hasn't been permissible in Minecraft in around 10 years now, since Minecraft 1.7.6 added UUIDs

public class BRecipeTag implements ObjectTag {

// <--[ObjectType]
// @name BRecipeTag
Copy link
Member

Choose a reason for hiding this comment

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

should use the full BreweryRecipeTag

// @description
// Returns the ID of the recipe as specified in the config.
// -->
if (attribute.startsWith("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 is the legacy tag system, again look at modern code or DenizenScript/Denizen#2355 or https://guide.denizenscript.com/guides/contributing/property-dev.html

@Jsinco
Copy link
Author

Jsinco commented Jun 7, 2024

I fixed a bunch of the commented issues. Not sure if I got everything 100% but just let me know what needs to be fixed and I'll get on it!

// <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

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

public class BreweryPlayerTag implements ObjectTag {
Copy link
Member

Choose a reason for hiding this comment

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

As noted before this object doesn't make sense, it should just be an extension

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.
Copy link
Member

Choose a reason for hiding this comment

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

this comment should just be a // comment not the weird line break multiline comment thing


@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

pom.xml Outdated
@@ -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

public class BreweryRecipeTag implements ObjectTag {

// <--[ObjectType]
// @name BRecipeTag
Copy link
Member

Choose a reason for hiding this comment

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

the name is still wrong here

// @returns ElementTag(Number)
// @plugin Depenizen, BreweryX
// @description
// Returns the distill runs of the recipe
Copy link
Member

Choose a reason for hiding this comment

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

. at end

// Returns the cooking time of the recipe.
// -->
tagProcessor.registerTag(ElementTag.class, "cooking_time", (attribute, object) -> {
return new ElementTag(object.bRecipe.getCookingTime());
Copy link
Member

Choose a reason for hiding this comment

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

sounds like it should probably be a DurationTag?

// @returns ElementTag(Number)
// @plugin Depenizen, BreweryX
// @description
// Returns the amount of alcohol in a perfect potion.
Copy link
Member

Choose a reason for hiding this comment

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

What unit is this? Item stacks of an alcohol item, percentage, decimal, ...?

Copy link
Author

Choose a reason for hiding this comment

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

"alcohol: Absolute amount of alcohol 0-100 in a perfect potion (will be added directly to the player, where 100 means fainting)"

Just returns the int written in Brewery's config for the specific recipe. I'll add that longer description to the comment


// <--[tag]
// @attribute <BRecipeTag.effects>
// @returns ListTag(ElementTag)
Copy link
Member

Choose a reason for hiding this comment

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

if it's a list of element just write ListTag

}
ListTag cmds = new ListTag();
for (Tuple<Integer, String> tuple : object.bRecipe.getPlayercmds()) {
cmds.addObject(new ElementTag(tuple.second()));
Copy link
Member

Choose a reason for hiding this comment

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

When constructing an ElementTag just from general plain text mark it explicitly as plaintext with , true

@Jsinco
Copy link
Author

Jsinco commented Jun 7, 2024

Fixed the new issues


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


// <--[ObjectType]
// @name BreweryRecipeTag
// @prefix brecipe
Copy link
Member

Choose a reason for hiding this comment

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

the prefix is still wrong

public static void register() {

// <--[tag]
// @attribute <BRecipeTag.id>
Copy link
Member

Choose a reason for hiding this comment

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

name in meta is still wrong

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.
Copy link
Member

Choose a reason for hiding this comment

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

this still shouldn't have all the stray newlines here

Copy link
Member

Choose a reason for hiding this comment

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

this still has a stray newline in the middle of it

Copy link
Author

Choose a reason for hiding this comment

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

removed


// <--[tag]
// @attribute <BRecipeTag.cooking_time>
// @returns ElementTag(Number)
Copy link
Member

Choose a reason for hiding this comment

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

return type here is outdated

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

Choose a reason for hiding this comment

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

. at end


public static void register() {
// <--[tag]
// @attribute <BPlayerTag.drunkenness>
Copy link
Member

Choose a reason for hiding this comment

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

this labeling is wrong

// @description
// Returns the drunkness of the brewery player.
// -->
PlayerTag.tagProcessor.registerTag(ElementTag.class, "drunkenness", (attribute, object) -> {
Copy link
Member

Choose a reason for hiding this comment

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

format the tags like brewery_drunkenness

// 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;
Copy link
Member

Choose a reason for hiding this comment

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

If this can null out, that should be explain in the tag meta. If this shouldn't have in practice, shouldn't have all the redundant checks

// @description
// Returns the quality of the brewery player's drunkenness (drunkeness * drunkeness).
// -->
PlayerTag.tagProcessor.registerTag(ElementTag.class, "quality", (attribute, object) -> {
Copy link
Member

Choose a reason for hiding this comment

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

should use registerOnlineOnlyTag if it requires online players

Copy link
Author

Choose a reason for hiding this comment

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

Doesn't require them to be online, just for Brewery to have data about them

Copy link
Member

Choose a reason for hiding this comment

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

then use getOfflinePlayer not playerEntity

Copy link
Author

Choose a reason for hiding this comment

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

fixed

@Jsinco
Copy link
Author

Jsinco commented Jun 8, 2024

Changed

@szarkans
Copy link

szarkans commented Jun 8, 2024

Please approve this, i need Depenizen x BreweryX ASAP!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants