-
-
Notifications
You must be signed in to change notification settings - Fork 107
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
Determination format modernization Part.2 #2689
base: dev
Are you sure you want to change the base?
Changes from all commits
49e00e5
b52aff3
61e4cec
555015d
5e1f897
75eef25
c20b149
f753d3c
722943c
5dbc99c
bff9a8b
55d9e93
5b6b72c
41b61c2
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 |
---|---|---|
|
@@ -50,6 +50,9 @@ public class PlayerCraftsItemScriptEvent extends BukkitScriptEvent implements Li | |
// --> | ||
|
||
public PlayerCraftsItemScriptEvent() { | ||
this.<PlayerCraftsItemScriptEvent, ItemTag>registerDetermination(null, ItemTag.class, (evt, context, result_item) -> { | ||
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. Java naming standards - this would be |
||
event.setCurrentItem(result_item.getItemStack()); | ||
}); | ||
} | ||
|
||
public CraftItemEvent event; | ||
|
@@ -58,13 +61,10 @@ public PlayerCraftsItemScriptEvent() { | |
|
||
@Override | ||
public boolean couldMatch(ScriptPath path) { | ||
if (!path.eventArgsLowEqualStartingAt(0, "player", "crafts")) { | ||
if (!path.eventLower.startsWith("player crafts ")) { | ||
return false; | ||
} | ||
if (!couldMatchItem(path.eventArgLowerAt(2))) { | ||
return false; | ||
} | ||
return true; | ||
return couldMatchItem(path.eventArgLowerAt(2)); | ||
Comment on lines
-64
to
+67
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. That syntax was intentional - either way if anything just update it to |
||
} | ||
|
||
@Override | ||
|
@@ -75,17 +75,6 @@ public boolean matches(ScriptPath path) { | |
return super.matches(path); | ||
} | ||
|
||
@Override | ||
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) { | ||
String determination = determinationObj.toString(); | ||
if (ItemTag.matches(determination)) { | ||
event.setCurrentItem(ItemTag.valueOf(determination, path.container).getItemStack()); | ||
return true; | ||
} | ||
|
||
return super.applyDetermination(path, determinationObj); | ||
} | ||
|
||
@Override | ||
public ScriptEntryData getScriptEntryData() { | ||
return new BukkitScriptEntryData(player, null); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,11 @@ public class PlayerItemTakesDamageScriptEvent extends BukkitScriptEvent implemen | |
|
||
public PlayerItemTakesDamageScriptEvent() { | ||
registerCouldMatcher("player <item> takes damage"); | ||
this.<PlayerItemTakesDamageScriptEvent, ElementTag>registerDetermination(null, ElementTag.class, (evt, context, amount) -> { | ||
if (amount.asElement().isInt()) { | ||
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. Same here, this is already an element |
||
evt.event.setDamage(amount.asInt()); | ||
} | ||
}); | ||
} | ||
|
||
public PlayerItemDamageEvent event; | ||
|
@@ -66,21 +71,12 @@ public boolean matches(ScriptPath path) { | |
|
||
@Override | ||
public ObjectTag getContext(String name) { | ||
switch (name) { | ||
case "item": return item; | ||
case "damage": return new ElementTag(event.getDamage()); | ||
case "slot": return new ElementTag(SlotHelper.slotForItem(event.getPlayer().getInventory(), item.getItemStack()) + 1); | ||
} | ||
return super.getContext(name); | ||
} | ||
|
||
@Override | ||
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) { | ||
if (determinationObj instanceof ElementTag element && element.isInt()) { | ||
event.setDamage(element.asInt()); | ||
return true; | ||
} | ||
return super.applyDetermination(path, determinationObj); | ||
return switch (name) { | ||
case "item" -> item; | ||
case "damage" -> new ElementTag(event.getDamage()); | ||
case "slot" -> new ElementTag(SlotHelper.slotForItem(event.getPlayer().getInventory(), item.getItemStack()) + 1); | ||
default -> super.getContext(name); | ||
}; | ||
} | ||
|
||
@Override | ||
|
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.
It should already be an element?