Skip to content

Commit

Permalink
modernize opens/closes inventory events
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Nov 26, 2019
1 parent 4fc7b7f commit d771ccc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 32 deletions.
Expand Up @@ -2,12 +2,12 @@

import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizen.objects.InventoryTag;
import com.denizenscript.denizen.objects.notable.NotableManager;
import com.denizenscript.denizen.objects.PlayerTag;
import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData;
import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.scripts.ScriptEntryData;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryCloseEvent;
Expand Down Expand Up @@ -38,7 +38,7 @@ public PlayerClosesInvScriptEvent() {
public static PlayerClosesInvScriptEvent instance;

public InventoryTag inventory;
private EntityTag entity;
private PlayerTag player;
public InventoryCloseEvent event;

@Override
Expand All @@ -48,19 +48,7 @@ public boolean couldMatch(ScriptPath path) {

@Override
public boolean matches(ScriptPath path) {
String entName = path.eventArgLowerAt(0);
if (entName.equals("player") && !entity.isPlayer()) {
return false;
}
String inv = path.eventArgLowerAt(2);
String nname = NotableManager.isSaved(inventory) ?
CoreUtilities.toLowerCase(NotableManager.getSavedId(inventory)) :
"\0";
if (!inv.equals("inventory")
&& !inv.equals(CoreUtilities.toLowerCase(inventory.getInventoryType().name()))
&& !inv.equals(CoreUtilities.toLowerCase(inventory.getIdHolder()))
&& !(inv.equals("notable") && !nname.equals("\0"))
&& !inv.equals(nname)) {
if (!tryInventory(inventory, path.eventArgLowerAt(2))) {
return false;
}
return super.matches(path);
Expand All @@ -73,8 +61,7 @@ public String getName() {

@Override
public ScriptEntryData getScriptEntryData() {
// TODO: Store the player?
return new BukkitScriptEntryData(entity.isPlayer() ? entity.getDenizenPlayer() : null, null);
return new BukkitScriptEntryData(player, null);
}

@Override
Expand All @@ -91,7 +78,7 @@ public void onPlayerClosesInv(InventoryCloseEvent event) {
return;
}
inventory = InventoryTag.mirrorBukkitInventory(event.getInventory());
entity = new EntityTag(event.getPlayer());
player = new PlayerTag((Player) event.getPlayer());
this.event = event;
fire(event);
}
Expand Down
Expand Up @@ -2,12 +2,10 @@

import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizen.objects.InventoryTag;
import com.denizenscript.denizen.objects.notable.NotableManager;
import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData;
import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.scripts.ScriptEntryData;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryOpenEvent;
Expand Down Expand Up @@ -47,15 +45,7 @@ public boolean couldMatch(ScriptPath path) {

@Override
public boolean matches(ScriptPath path) {
String inv = path.eventArgLowerAt(2);
String nname = NotableManager.isSaved(inventory) ?
CoreUtilities.toLowerCase(NotableManager.getSavedId(inventory)) :
"\0";
if (!inv.equals("inventory")
&& !inv.equals(CoreUtilities.toLowerCase(inventory.getInventoryType().name()))
&& !inv.equals(CoreUtilities.toLowerCase(inventory.getIdHolder()))
&& !(inv.equals("notable") && !nname.equals("\0"))
&& !inv.equals(nname)) {
if (!tryInventory(inventory, path.eventArgLowerAt(2))) {
return false;
}
return super.matches(path);
Expand Down
Expand Up @@ -2303,8 +2303,8 @@ else if (mtr.angle == BlockFace.EAST) {
// @attribute <EntityTag.precise_target_position[<range>]>
// @returns LocationTag
// @description
// Returns the entity this entity is looking at, using precise ray trace logic.
// Optionally, specify a maximum range to find the entity from (defaults to 200).
// Returns the location this entity is looking at, using precise ray trace (against entities) logic.
// Optionally, specify a maximum range to find the target from (defaults to 200).
// -->
registerTag("precise_target_position", (attribute, object) -> {
int range = attribute.getIntContext(1);
Expand Down

0 comments on commit d771ccc

Please sign in to comment.