Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
Switch Improvements (#7)
Browse files Browse the repository at this point in the history
They now accept lists as input.
  • Loading branch information
Xenmai authored and mcmonkey4eva committed Mar 26, 2017
1 parent 05070fa commit 1a758ab
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
@@ -1,6 +1,8 @@
package com.denizenscript.denizen2sponge.events;

import com.denizenscript.denizen2core.events.ScriptEvent;
import com.denizenscript.denizen2core.tags.AbstractTagObject;
import com.denizenscript.denizen2core.tags.objects.ListTag;
import com.denizenscript.denizen2core.utilities.Action;
import com.denizenscript.denizen2sponge.tags.objects.BlockTypeTag;
import com.denizenscript.denizen2sponge.tags.objects.EntityTypeTag;
Expand All @@ -16,31 +18,46 @@ public static boolean checkBlockType(BlockType btype, ScriptEvent.ScriptEventDat
}

public static boolean checkBlockType(BlockType btype, ScriptEvent.ScriptEventData data, Action<String> error, String tname) {
// TODO: type_list as well?
return !data.switches.containsKey(tname)
|| BlockTypeTag.getFor(error, data.switches.get(tname)).getInternal()
.equals(btype);
if (!data.switches.containsKey(tname)) {
return true;
}
for (AbstractTagObject ato : ListTag.getFor(error, data.switches.get(tname)).getInternal()) {
if ((BlockTypeTag.getFor(error, ato)).getInternal().equals(btype)) {
return true;
}
}
return false;
}

public static boolean checkEntityType(EntityType etype, ScriptEvent.ScriptEventData data, Action<String> error) {
return checkEntityType(etype, data, error, "type");
}

public static boolean checkEntityType(EntityType etype, ScriptEvent.ScriptEventData data, Action<String> error, String tname) {
// TODO: type_list as well?
return !data.switches.containsKey(tname)
|| EntityTypeTag.getFor(error, data.switches.get(tname)).getInternal()
.equals(etype);
if (!data.switches.containsKey(tname)) {
return true;
}
for (AbstractTagObject ato : ListTag.getFor(error, data.switches.get(tname)).getInternal()) {
if ((EntityTypeTag.getFor(error, ato)).getInternal().equals(etype)) {
return true;
}
}
return false;
}

public static boolean checkWorld(World world, ScriptEvent.ScriptEventData data, Action<String> error) {
return checkWorld(world, data, error, "world");
}

public static boolean checkWorld(World world, ScriptEvent.ScriptEventData data, Action<String> error, String tname) {
// TODO: type_list as well?
return !data.switches.containsKey(tname)
|| WorldTag.getFor(error, data.switches.get(tname)).getInternal()
.equals(world);
if (!data.switches.containsKey(tname)) {
return true;
}
for (AbstractTagObject ato : ListTag.getFor(error, data.switches.get(tname)).getInternal()) {
if ((WorldTag.getFor(error, ato)).getInternal().equals(world)) {
return true;
}
}
return false;
}
}
Expand Up @@ -51,7 +51,6 @@ public boolean couldMatch(ScriptEventData data) {
@Override
public boolean matches(ScriptEventData data) {
return D2SpongeEventHelper.checkBlockType(material.getInternal(), data, this::error);

}

public LocationTag location;
Expand Down

0 comments on commit 1a758ab

Please sign in to comment.