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

Commit

Permalink
Add Some World Switches
Browse files Browse the repository at this point in the history
  • Loading branch information
Xenmai committed Oct 5, 2017
1 parent 84e2f73 commit b560251
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
Expand Up @@ -14,13 +14,13 @@

import java.util.HashMap;

public class BlockChangeScriptEvent extends ScriptEvent {
public class BlockChangesScriptEvent extends ScriptEvent {

// <--[event]
// @Events
// block changes
//
// @Updated 2017/03/24
// @Updated 2017/10/05
//
// @Group World
//
Expand Down Expand Up @@ -53,7 +53,8 @@ public boolean couldMatch(ScriptEventData data) {
@Override
public boolean matches(ScriptEventData data) {
return D2SpongeEventHelper.checkBlockType(new_material.getInternal(), data, this::error, "new_type")
&& D2SpongeEventHelper.checkBlockType(old_material.getInternal(), data, this::error, "old_type");
&& D2SpongeEventHelper.checkBlockType(old_material.getInternal(), data, this::error, "old_type")
&& D2SpongeEventHelper.checkWorld(location.getInternal().world, data, this::error);

}

Expand Down Expand Up @@ -87,7 +88,7 @@ public void disable() {
@Listener
public void onBlockChanged(ChangeBlockEvent evt) {
for (Transaction<BlockSnapshot> block : evt.getTransactions()) {
BlockChangeScriptEvent event = (BlockChangeScriptEvent) clone();
BlockChangesScriptEvent event = (BlockChangesScriptEvent) clone();
event.internal = evt;
event.location = new LocationTag(block.getFinal().getLocation().get());
event.new_material = new BlockTypeTag(block.getFinal().getState().getType());
Expand Down
Expand Up @@ -20,7 +20,7 @@ public class BlockFadesScriptEvent extends ScriptEvent {
// @Events
// block fades
//
// @Updated 2017/03/24
// @Updated 2017/10/05
//
// @Group World
//
Expand Down Expand Up @@ -50,7 +50,8 @@ public boolean couldMatch(ScriptEventData data) {

@Override
public boolean matches(ScriptEventData data) {
return D2SpongeEventHelper.checkBlockType(material.getInternal(), data, this::error);
return D2SpongeEventHelper.checkBlockType(material.getInternal(), data, this::error)
&& D2SpongeEventHelper.checkWorld(location.getInternal().world, data, this::error);
}

public LocationTag location;
Expand Down
Expand Up @@ -7,6 +7,7 @@
import com.denizenscript.denizen2core.tags.objects.MapTag;
import com.denizenscript.denizen2core.tags.objects.NumberTag;
import com.denizenscript.denizen2sponge.Denizen2Sponge;
import com.denizenscript.denizen2sponge.events.D2SpongeEventHelper;
import com.denizenscript.denizen2sponge.tags.objects.EntityTag;
import com.denizenscript.denizen2sponge.tags.objects.LocationTag;
import org.spongepowered.api.Sponge;
Expand All @@ -26,7 +27,7 @@ public class ExplosionDetonatesScriptEvent extends ScriptEvent {
// @Events
// explosion detonates
//
// @Updated 2017/10/03
// @Updated 2017/10/05
//
// @Group World
//
Expand Down Expand Up @@ -56,10 +57,12 @@ public boolean couldMatch(ScriptEventData data) {

@Override
public boolean matches(ScriptEventData data) {
return true;
return D2SpongeEventHelper.checkWorld(location.getInternal().world, data, this::error);
}

public ListTag locations;
public LocationTag location;

public ListTag blocks;

public ListTag entities;

Expand All @@ -70,7 +73,8 @@ public boolean matches(ScriptEventData data) {
@Override
public HashMap<String, AbstractTagObject> getDefinitions(ScriptEventData data) {
HashMap<String, AbstractTagObject> defs = super.getDefinitions(data);
defs.put("locations", locations);
defs.put("location", location);
defs.put("blocks", blocks);
defs.put("entities", entities);
defs.put("explosion_data", explosion_data);
return defs;
Expand All @@ -90,11 +94,12 @@ public void disable() {
public void onExplosionDetonates(ExplosionEvent.Detonate evt) {
ExplosionDetonatesScriptEvent event = (ExplosionDetonatesScriptEvent) clone();
event.internal = evt;
event.location = new LocationTag(evt.getExplosion().getLocation());
ListTag locs = new ListTag();
for (Location<World> loc : evt.getAffectedLocations()) {
locs.getInternal().add(new LocationTag(loc));
}
event.locations = locs;
event.blocks = locs;
ListTag ents = new ListTag();
for (Entity ent : evt.getEntities()) {
locs.getInternal().add(new EntityTag(ent));
Expand All @@ -115,9 +120,9 @@ public void onExplosionDetonates(ExplosionEvent.Detonate evt) {

@Override
public void applyDetermination(boolean errors, String determination, AbstractTagObject value) {
if (determination.equals("locations")) {
if (determination.equals("blocks")) {
ListTag lt = ListTag.getFor(this::error, value);
locations = lt;
blocks = lt;
ArrayList<Location<World>> locs = new ArrayList<>();
for (AbstractTagObject loc : lt.getInternal()) {
locs.add(((LocationTag) loc).getInternal().toLocation());
Expand Down

0 comments on commit b560251

Please sign in to comment.