Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A few meta changes and additions (#2244)
* Add Item in Off Hand for `- take` * Add world context to <player.groups> * Minor Meta fixes * Update PlayerTag.java Oopsies forgot to update this. * Minor Meta updates & JavaDoc * Removed redundant spaces * Remove more redundant spaces. * Correct identify() for TradeTag * Added Villager Events Added: `on villager acquires trade` `on villager replenishes trade` `on villager changes profession` Referencing #1913 * Correct typo on event name. * Revert "Minor Meta updates & JavaDoc" This reverts commit d8cfb62. * Revert "Correct identify() for TradeTag" This reverts commit dbf6966 * Updates as per request on PR * Revert "Add Item in Off Hand for `- take`" This reverts commit 740c34f * Uncomplicate the PlayerTag.groups tag * Fix my stupid * Lil Fix * This should fix that * fix the idiocy again, cause idiot.
- Loading branch information
1 parent
6f846c9
commit 8743c78
Showing
12 changed files
with
314 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
...c/main/java/com/denizenscript/denizen/events/entity/VillagerAcquiresTradeScriptEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package com.denizenscript.denizen.events.entity; | ||
|
||
import com.denizenscript.denizen.events.BukkitScriptEvent; | ||
import com.denizenscript.denizen.objects.EntityTag; | ||
import com.denizenscript.denizen.objects.TradeTag; | ||
import com.denizenscript.denizencore.objects.ObjectTag; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.entity.VillagerAcquireTradeEvent; | ||
|
||
public class VillagerAcquiresTradeScriptEvent extends BukkitScriptEvent implements Listener { | ||
|
||
// <--[event] | ||
// @Events | ||
// villager acquires trade | ||
// | ||
// @Regex ^on villager acquires trade$ | ||
// | ||
// @Group Entity | ||
// | ||
// @Switch in:<area> to only process the event if it occurred within a specified area. | ||
// | ||
// @Cancellable true | ||
// | ||
// @Triggers when a villager acquires a new trade. | ||
// | ||
// @Context | ||
// <context.entity> returns the EntityTag of the villager. | ||
// <context.trade> returns the TradeTag for the new trade. | ||
// | ||
// @Determine | ||
// TradeTag to change the new trade. | ||
// --> | ||
|
||
public VillagerAcquiresTradeScriptEvent() { | ||
instance = this; | ||
} | ||
|
||
public static VillagerAcquiresTradeScriptEvent instance; | ||
public EntityTag entity; | ||
public VillagerAcquireTradeEvent event; | ||
|
||
@Override | ||
public boolean couldMatch(ScriptPath path) { | ||
return path.eventLower.startsWith("villager acquires trade"); | ||
} | ||
|
||
@Override | ||
public boolean matches(ScriptPath path) { | ||
if (!runInCheck(path, entity.getLocation())) { | ||
return false; | ||
} | ||
return super.matches(path); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "VillagerAcquiresTrade"; | ||
} | ||
|
||
|
||
@Override | ||
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) { | ||
if (TradeTag.matches(determinationObj.toString())) { | ||
event.setRecipe(determinationObj.asType(TradeTag.class, getTagContext(path)).getRecipe()); | ||
return true; | ||
} | ||
return super.applyDetermination(path, determinationObj); | ||
} | ||
|
||
@Override | ||
public ObjectTag getContext(String name) { | ||
if (name.equals("entity")) { | ||
return entity; | ||
} | ||
else if (name.equals("trade")) { | ||
return new TradeTag(event.getRecipe()); | ||
} | ||
return super.getContext(name); | ||
} | ||
|
||
@EventHandler | ||
public void onVillagerAcquiresTrade(VillagerAcquireTradeEvent event) { | ||
this.event = event; | ||
fire(event); | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
...in/java/com/denizenscript/denizen/events/entity/VillagerChangesProfessionScriptEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package com.denizenscript.denizen.events.entity; | ||
|
||
import com.denizenscript.denizen.events.BukkitScriptEvent; | ||
import com.denizenscript.denizen.objects.EntityTag; | ||
import com.denizenscript.denizen.utilities.debugging.Debug; | ||
import com.denizenscript.denizencore.objects.ObjectTag; | ||
import com.denizenscript.denizencore.objects.core.ElementTag; | ||
import org.bukkit.entity.Villager; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.entity.VillagerCareerChangeEvent; | ||
|
||
public class VillagerChangesProfessionScriptEvent extends BukkitScriptEvent implements Listener { | ||
|
||
// <--[event] | ||
// @Events | ||
// villager changes profession | ||
// | ||
// @Regex ^on villager changes profession$ | ||
// | ||
// @Group Entity | ||
// | ||
// @Switch in:<area> to only process the event if it occurred within a specified area. | ||
// | ||
// @Cancellable true | ||
// | ||
// @Triggers when a villager changes profession. | ||
// | ||
// @Context | ||
// <context.entity> returns the EntityTag of the villager. | ||
// <context.profession> returns the name of the new profession. <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/entity/Villager.Profession.html> | ||
// <context.reason> returns the reason for the change. <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/entity/VillagerCareerChangeEvent.ChangeReason.html> | ||
// | ||
// @Determine | ||
// ElementTag to change the profession. | ||
// --> | ||
|
||
public VillagerChangesProfessionScriptEvent() { | ||
instance = this; | ||
} | ||
|
||
public static VillagerChangesProfessionScriptEvent instance; | ||
public EntityTag entity; | ||
public VillagerCareerChangeEvent event; | ||
|
||
@Override | ||
public boolean couldMatch(ScriptPath path) { | ||
return path.eventLower.startsWith("villager changes profession"); | ||
} | ||
|
||
@Override | ||
public boolean matches(ScriptPath path) { | ||
if (!runInCheck(path, entity.getLocation())) { | ||
return false; | ||
} | ||
return super.matches(path); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "VillagerChangesProfession"; | ||
} | ||
|
||
|
||
@Override | ||
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) { | ||
String determination = determinationObj.toString(); | ||
try { | ||
Villager.Profession newProfession = Villager.Profession.valueOf(determination.toUpperCase()); | ||
event.setProfession(newProfession); | ||
return true; | ||
} | ||
catch (IllegalArgumentException e) { | ||
Debug.echoError("Invalid profession specified: " + determination); | ||
} | ||
return super.applyDetermination(path, determinationObj); | ||
} | ||
|
||
@Override | ||
public ObjectTag getContext(String name) { | ||
if (name.equals("entity")) { | ||
return entity; | ||
} | ||
else if (name.equals("reason")) { | ||
return new ElementTag(event.getReason().toString()); | ||
} | ||
else if (name.equals("profession")) { | ||
return new ElementTag(event.getProfession().toString()); | ||
} | ||
return super.getContext(name); | ||
} | ||
|
||
@EventHandler | ||
public void onVillagerChangesProfession(VillagerCareerChangeEvent event) { | ||
this.event = event; | ||
this.entity = new EntityTag(event.getEntity()); | ||
fire(event); | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
...ain/java/com/denizenscript/denizen/events/entity/VillagerReplenishesTradeScriptEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package com.denizenscript.denizen.events.entity; | ||
|
||
import com.denizenscript.denizen.events.BukkitScriptEvent; | ||
import com.denizenscript.denizen.objects.EntityTag; | ||
import com.denizenscript.denizen.objects.TradeTag; | ||
import com.denizenscript.denizencore.objects.ObjectTag; | ||
import com.denizenscript.denizencore.objects.core.ElementTag; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.entity.VillagerReplenishTradeEvent; | ||
|
||
public class VillagerReplenishesTradeScriptEvent extends BukkitScriptEvent implements Listener { | ||
|
||
// <--[event] | ||
// @Events | ||
// villager replenishes trade | ||
// | ||
// @Regex ^on villager replenishes trade$ | ||
// | ||
// @Group Entity | ||
// | ||
// @Switch in:<area> to only process the event if it occurred within a specified area. | ||
// | ||
// @Cancellable true | ||
// | ||
// @Triggers when a villager replenishes a trade. | ||
// | ||
// @Context | ||
// <context.entity> returns the EntityTag of the villager. | ||
// <context.trade> returns the TradeTag for the trade being replenished. | ||
// <context.bonus> returns the number of bonus uses added. | ||
// | ||
// @Determine | ||
// TradeTag to change the trade being replenished. | ||
// ElementTag(Number) to change the number of bonus uses added. | ||
// --> | ||
|
||
public VillagerReplenishesTradeScriptEvent() { | ||
instance = this; | ||
} | ||
|
||
public static VillagerReplenishesTradeScriptEvent instance; | ||
public EntityTag entity; | ||
public VillagerReplenishTradeEvent event; | ||
|
||
@Override | ||
public boolean couldMatch(ScriptPath path) { | ||
return path.eventLower.startsWith("villager replenishes trade"); | ||
} | ||
|
||
@Override | ||
public boolean matches(ScriptPath path) { | ||
if (!runInCheck(path, entity.getLocation())) { | ||
return false; | ||
} | ||
return super.matches(path); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "VillagerReplenishesTrade"; | ||
} | ||
|
||
|
||
@Override | ||
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) { | ||
if (TradeTag.matches(determinationObj.toString())) { | ||
event.setRecipe(determinationObj.asType(TradeTag.class, getTagContext(path)).getRecipe()); | ||
return true; | ||
} | ||
else if (determinationObj instanceof ElementTag && ((ElementTag) determinationObj).isInt()) { | ||
event.setBonus(((ElementTag) determinationObj).asInt()); | ||
return true; | ||
} | ||
return super.applyDetermination(path, determinationObj); | ||
} | ||
|
||
@Override | ||
public ObjectTag getContext(String name) { | ||
if (name.equals("entity")) { | ||
return entity; | ||
} | ||
else if (name.equals("trade")) { | ||
return new TradeTag(event.getRecipe()); | ||
} | ||
else if (name.equals("bonus")) { | ||
return new ElementTag(event.getBonus()); | ||
} | ||
return super.getContext(name); | ||
} | ||
|
||
@EventHandler | ||
public void onVillagerReplenishesTrade(VillagerReplenishTradeEvent event) { | ||
this.event = event; | ||
fire(event); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.