Skip to content

Commit

Permalink
JobsReborn Event Improvements (DenizenScript#431)
Browse files Browse the repository at this point in the history
* Add <context.entity> to JobsJobsPaymentScriptEvent

* Add <context.block> to JobsJobsPaymentScriptEvent

* Add <context.entity> to JobsJobsExpGainScriptEvent

* Add <context.block> to JobsJobsExpGainScriptEvent

* Fix NPEs

* Handle getLivingEntity() returning null

* Use #getDenizenObject on EntityTags

* Change meta wording

* Add examples
  • Loading branch information
FireML authored Oct 31, 2024
1 parent 3beca27 commit f6bda87
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.denizenscript.depenizen.bukkit.events.jobs;

import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizen.objects.LocationTag;
import com.denizenscript.denizen.objects.PlayerTag;
import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData;
import com.denizenscript.denizencore.objects.ObjectTag;
Expand Down Expand Up @@ -28,6 +30,8 @@ public class JobsJobsExpGainScriptEvent extends BukkitScriptEvent implements Lis
// <context.job> Returns a JobsJobTag of the job that the player is gaining exp for.
// <context.experience> Returns an ElementTag(Decimal) of the amount of exp the player will earn.
// <context.action> Returns an ElementTag of the name of the action being paid for, which can be any of the strings from: <@link url https://github.com/Zrips/Jobs/blob/master/src/main/java/com/gamingmesh/jobs/container/ActionType.java>.
// <context.entity> Returns an EntityTag of the entity involved with this event, if any.
// <context.block> Returns a LocationTag of the block involved with this event, if any.
//
// @Determine
// "EXP:<ElementTag(Decimal)>" to change the amount of Jobs exp this action should provide.
Expand All @@ -36,6 +40,13 @@ public class JobsJobsExpGainScriptEvent extends BukkitScriptEvent implements Lis
//
// @Player Always.
//
// @Example
// on jobs player earns exp for job:
// # Returns true if the target of the action was an entity. Valid actions include but are not limited to: Kill, Shear, Milk.
// - narrate <context.entity.exists>
// # Returns true if the target of the action was a block. Valid actions include but are not limited to: Place, Break, Strip.
// - narrate <context.block.exists>
//
// @Group Depenizen
//
// -->
Expand Down Expand Up @@ -72,6 +83,8 @@ public ObjectTag getContext(String name) {
case "job" -> job;
case "experience" -> new ElementTag(event.getExp());
case "action" -> new ElementTag(event.getActionInfo().getType().getName(), true);
case "entity" -> event.getLivingEntity() == null ? null : new EntityTag(event.getLivingEntity()).getDenizenObject();
case "block" -> event.getBlock() == null ? null : new LocationTag(event.getBlock().getLocation());
default -> super.getContext(name);
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.denizenscript.depenizen.bukkit.events.jobs;

import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizen.objects.LocationTag;
import com.denizenscript.denizen.objects.PlayerTag;
import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData;
import com.denizenscript.denizencore.objects.ObjectTag;
Expand Down Expand Up @@ -29,6 +31,8 @@ public class JobsJobsPaymentScriptEvent extends BukkitScriptEvent implements Lis
// <context.money> Returns an ElementTag(Decimal) of the amount of money the player will be paid.
// <context.points> Returns an ElementTag(Decimal) of the amount of points the player will be paid.
// <context.action> Returns an ElementTag the name of the action being paid for, which can be any of the strings from: <@link url https://github.com/Zrips/Jobs/blob/master/src/main/java/com/gamingmesh/jobs/container/ActionType.java>.
// <context.entity> Returns an EntityTag of the entity involved with this event, if any.
// <context.block> Returns a LocationTag of the block involved with this event, if any.
//
// @Determine
// "MONEY:<ElementTag(Decimal)>" to change the amount of money this action should provide.
Expand All @@ -38,6 +42,13 @@ public class JobsJobsPaymentScriptEvent extends BukkitScriptEvent implements Lis
//
// @Player Always.
//
// @Example
// on jobs player earns money for job:
// # Returns true if the target of the action was an entity. Valid actions include but are not limited to: Kill, Shear, Milk.
// - narrate <context.entity.exists>
// # Returns true if the target of the action was a block. Valid actions include but are not limited to: Place, Break, Strip.
// - narrate <context.block.exists>
//
// @Group Depenizen
//
// -->
Expand Down Expand Up @@ -82,6 +93,8 @@ public ObjectTag getContext(String name) {
case "money" -> new ElementTag(event.getAmount());
case "points" -> new ElementTag(event.getPoints());
case "action" -> new ElementTag(event.getActionInfo().getType().getName(), true);
case "entity" -> event.getLivingEntity() == null ? null : new EntityTag(event.getLivingEntity()).getDenizenObject();
case "block" -> event.getBlock() == null ? null : new LocationTag(event.getBlock().getLocation());
default -> super.getContext(name);
};
}
Expand Down

0 comments on commit f6bda87

Please sign in to comment.