Skip to content

Commit

Permalink
better clicks block inventory checking
Browse files Browse the repository at this point in the history
  • Loading branch information
mergu committed Aug 18, 2017
1 parent 86c9f51 commit 171a3b2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
Expand Up @@ -16,6 +16,7 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.PlayerInteractEvent;

import java.util.Arrays;
Expand Down Expand Up @@ -62,13 +63,13 @@ private boolean couldMatchIn(String lower) {
if (index == -1) return true;

String in = CoreUtilities.getXthArg(index + 1, lower);
if (in.equals("notable")
|| dWorld.matches(in)
|| dCuboid.matches(in)
|| dEllipsoid.matches(in)) {
return true;
if (dInventory.valueOf("in@" + in, null, null, true) != null) {
return false;
}
for (InventoryType type : InventoryType.values()) {
if (in.equalsIgnoreCase(type.name())) return false;
}
return false;
return true;
}

private boolean runUsingCheck(ScriptContainer scriptContainer, String s, String lower) {
Expand Down
Expand Up @@ -152,14 +152,18 @@ public static dInventory valueOf(String string, TagContext context) {
}
}

public static dInventory valueOf(String string, dPlayer player, dNPC npc) {
return valueOf(string, player, npc, false);
}

/**
* Gets a dInventory from a string format.
*
* @param string The inventory in string form. (in@player[playerName], in@scriptName, etc.)
* @return The dInventory value. If the string is incorrectly formatted or
* the specified inventory is invalid, this is null.
*/
public static dInventory valueOf(String string, dPlayer player, dNPC npc) {
public static dInventory valueOf(String string, dPlayer player, dNPC npc, boolean silent) {

if (string == null) {
return null;
Expand Down Expand Up @@ -211,7 +215,7 @@ else if (arg.matchesPrimitive(PrimitiveType.Integer)) {
return new dInventory(arg.asElement().asInt());
}
else {
dB.echoError("That type of inventory does not exist!");
if (!silent) dB.echoError("That type of inventory does not exist!");
}
}
else if (type.equals("npc")) {
Expand All @@ -228,7 +232,7 @@ else if (type.equals("workbench")) {
if (dPlayer.matches(holder)) {
dInventory workbench = dPlayer.valueOf(holder).getWorkbench();
if (workbench != null) {
dB.echoError("Value of dInventory returning null (" + string + ")." +
if (!silent) dB.echoError("Value of dInventory returning null (" + string + ")." +
" Specified player does not have an open workbench.");
}
else {
Expand All @@ -253,12 +257,12 @@ else if (type.equals("location")) {
}

// If the dInventory is invalid, alert the user and return null
dB.echoError("Value of dInventory returning null. Invalid " +
if (!silent) dB.echoError("Value of dInventory returning null. Invalid " +
type + " specified: " + holder);
return null;
}

dB.echoError("Value of dInventory returning null. Invalid dInventory specified: " + string);
if (!silent) dB.echoError("Value of dInventory returning null. Invalid dInventory specified: " + string);
return null;
}

Expand Down

0 comments on commit 171a3b2

Please sign in to comment.