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

Commit

Permalink
Tons of switches
Browse files Browse the repository at this point in the history
Also improved some ItemStack.empty()
  • Loading branch information
Xenmai committed Oct 14, 2017
1 parent 5cee88b commit f3bbad2
Show file tree
Hide file tree
Showing 16 changed files with 87 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class EntityDamagedScriptEvent extends ScriptEvent {
// @Events
// entity damaged
//
// @Updated 2017/03/24
// @Updated 2017/10/14
//
// @Group Entity
//
Expand All @@ -28,6 +28,8 @@ public class EntityDamagedScriptEvent extends ScriptEvent {
// @Triggers when an entity is damaged.
//
// @Switch type (EntityTypeTag) checks the entity type.
// @Switch world (WorldTag) checks the world.
// @Switch cuboid (CuboidTag) checks the cuboid area.
//
// @Context
// entity (EntityTag) returns the entity that was damaged.
Expand All @@ -49,7 +51,10 @@ public boolean couldMatch(ScriptEventData data) {

@Override
public boolean matches(ScriptEventData data) {
return D2SpongeEventHelper.checkEntityType(entity.getInternal().getType(), data, this::error);
return D2SpongeEventHelper.checkEntityType(entity.getInternal().getType(), data, this::error)
&& D2SpongeEventHelper.checkWorld(entity.getInternal().getLocation().getExtent(), data, this::error)
&& D2SpongeEventHelper.checkCuboid((new LocationTag(entity.getInternal()
.getLocation())).getInternal(), data, this::error);
}

public EntityTag entity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.denizenscript.denizen2sponge.events.D2SpongeEventHelper;
import com.denizenscript.denizen2sponge.tags.objects.EntityTag;
import com.denizenscript.denizen2sponge.tags.objects.FormattedTextTag;
import com.denizenscript.denizen2sponge.tags.objects.LocationTag;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.entity.DestructEntityEvent;
Expand All @@ -19,7 +20,7 @@ public class EntityDiesScriptEvent extends ScriptEvent {
// @Events
// entity dies
//
// @Updated 2017/03/24
// @Updated 2017/10/14
//
// @Group Entity
//
Expand All @@ -28,6 +29,8 @@ public class EntityDiesScriptEvent extends ScriptEvent {
// @Triggers when an entity dies.
//
// @Switch type (EntityTypeTag) checks the entity type.
// @Switch world (WorldTag) checks the world.
// @Switch cuboid (CuboidTag) checks the cuboid area.
//
// @Context
// entity (EntityTag) returns the entity that died.
Expand All @@ -50,7 +53,10 @@ public boolean couldMatch(ScriptEventData data) {

@Override
public boolean matches(ScriptEventData data) {
return D2SpongeEventHelper.checkEntityType(entity.getInternal().getType(), data, this::error);
return D2SpongeEventHelper.checkEntityType(entity.getInternal().getType(), data, this::error)
&& D2SpongeEventHelper.checkWorld(entity.getInternal().getLocation().getExtent(), data, this::error)
&& D2SpongeEventHelper.checkCuboid((new LocationTag(entity.getInternal()
.getLocation())).getInternal(), data, this::error);
}

public EntityTag entity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
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;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.entity.DamageEntityEvent;
Expand All @@ -18,7 +19,7 @@ public class EntityKilledScriptEvent extends ScriptEvent {
// @Events
// entity killed
//
// @Updated 2017/03/24
// @Updated 2017/10/14
//
// @Group Entity
//
Expand All @@ -27,6 +28,8 @@ public class EntityKilledScriptEvent extends ScriptEvent {
// @Triggers when an entity is killed.
//
// @Switch type (EntityTypeTag) checks the entity type.
// @Switch world (WorldTag) checks the world.
// @Switch cuboid (CuboidTag) checks the cuboid area.
//
// @Context
// entity (EntityTag) returns the entity that was killed.
Expand All @@ -48,7 +51,10 @@ public boolean couldMatch(ScriptEventData data) {

@Override
public boolean matches(ScriptEventData data) {
return D2SpongeEventHelper.checkEntityType(entity.getInternal().getType(), data, this::error);
return D2SpongeEventHelper.checkEntityType(entity.getInternal().getType(), data, this::error)
&& D2SpongeEventHelper.checkWorld(entity.getInternal().getLocation().getExtent(), data, this::error)
&& D2SpongeEventHelper.checkCuboid((new LocationTag(entity.getInternal()
.getLocation())).getInternal(), data, this::error);
}

public EntityTag entity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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;
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.event.Listener;
Expand All @@ -18,13 +19,15 @@ public class EntitySpawnScriptEvent extends ScriptEvent {
// @Events
// entity spawns
//
// @Updated 2016/09/23
// @Updated 2017/10/14
//
// @Group Entity
//
// @Cancellable true
//
// @Switch type (EntityTypeTag) checks the entity type.
// @Switch world (WorldTag) checks the world.
// @Switch cuboid (CuboidTag) checks the cuboid area.
//
// @Triggers when an entity spawns in the world (non players).
//
Expand All @@ -47,7 +50,10 @@ public boolean couldMatch(ScriptEvent.ScriptEventData data) {

@Override
public boolean matches(ScriptEvent.ScriptEventData data) {
return D2SpongeEventHelper.checkEntityType(entity.getInternal().getType(), data, this::error);
return D2SpongeEventHelper.checkEntityType(entity.getInternal().getType(), data, this::error)
&& D2SpongeEventHelper.checkWorld(entity.getInternal().getLocation().getExtent(), data, this::error)
&& D2SpongeEventHelper.checkCuboid((new LocationTag(entity.getInternal()
.getLocation())).getInternal(), data, this::error);
}

public EntityTag entity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@
import com.denizenscript.denizen2sponge.Denizen2Sponge;
import com.denizenscript.denizen2sponge.events.D2SpongeEventHelper;
import com.denizenscript.denizen2sponge.tags.objects.BlockTypeTag;
import com.denizenscript.denizen2sponge.tags.objects.ItemTag;
import com.denizenscript.denizen2sponge.tags.objects.LocationTag;
import com.denizenscript.denizen2sponge.tags.objects.PlayerTag;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.block.BlockSnapshot;
import org.spongepowered.api.data.Transaction;
import org.spongepowered.api.data.type.HandTypes;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.block.ChangeBlockEvent;
import org.spongepowered.api.event.filter.cause.Root;
import org.spongepowered.api.item.inventory.ItemStack;

import java.util.HashMap;

Expand All @@ -23,7 +26,7 @@ public class PlayerBreaksBlockScriptEvent extends ScriptEvent {
// @Events
// player breaks block
//
// @Updated 2016/09/22
// @Updated 2017/10/14
//
// @Cancellable true
//
Expand All @@ -32,6 +35,9 @@ public class PlayerBreaksBlockScriptEvent extends ScriptEvent {
// @Triggers when a player breaks a block.
//
// @Switch type (BlockTypeTag) checks the block type.
// @Switch with_item (ItemTag) checks the item in hand.
// @Switch world (WorldTag) checks the world.
// @Switch cuboid (CuboidTag) checks the cuboid area.
//
// @Context
// player (PlayerTag) returns the player that broke the block.
Expand All @@ -54,7 +60,11 @@ 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.checkItem(new ItemTag(player.getInternal()
.getItemInHand(HandTypes.MAIN_HAND).orElse(ItemStack.empty())), data, this::error)
&& D2SpongeEventHelper.checkWorld(location.getInternal().world, data, this::error)
&& D2SpongeEventHelper.checkCuboid(location.getInternal(), data, this::error);
}

public PlayerTag player;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import com.denizenscript.denizen2core.events.ScriptEvent;
import com.denizenscript.denizen2core.tags.AbstractTagObject;
import com.denizenscript.denizen2sponge.Denizen2Sponge;
import com.denizenscript.denizen2sponge.events.D2SpongeEventHelper;
import com.denizenscript.denizen2sponge.tags.objects.FormattedTextTag;
import com.denizenscript.denizen2sponge.tags.objects.LocationTag;
import com.denizenscript.denizen2sponge.tags.objects.PlayerTag;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.entity.living.player.Player;
Expand All @@ -19,14 +21,17 @@ public class PlayerChatsScriptEvent extends ScriptEvent {
// @Events
// player chats
//
// @Updated 2017/03/22
// @Updated 2017/10/14
//
// @Cancellable true
//
// @Group Player
//
// @Triggers when a player sends a chat message.
//
// @Switch world (WorldTag) checks the world.
// @Switch cuboid (CuboidTag) checks the cuboid area.
//
// @Context
// player (PlayerTag) returns the player that sent the message.
// message (FormattedTextTag) returns the chat message.
Expand All @@ -47,7 +52,9 @@ public boolean couldMatch(ScriptEventData data) {

@Override
public boolean matches(ScriptEventData data) {
return true;
return D2SpongeEventHelper.checkWorld(player.getOnline(this::error).getLocation().getExtent(), data, this::error)
&& D2SpongeEventHelper.checkCuboid((new LocationTag(player.getOnline(this::error)
.getLocation())).getInternal(), data, this::error);
}

public PlayerTag player;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class PlayerLeftClicksBlockScriptEvent extends ScriptEvent {
// @Events
// player left clicks block
//
// @Updated 2017/04/05
// @Updated 2017/10/14
//
// @Cancellable true
//
Expand All @@ -38,6 +38,8 @@ public class PlayerLeftClicksBlockScriptEvent extends ScriptEvent {
//
// @Switch type (BlockTypeTag) checks the block type.
// @Switch with_item (ItemTag) checks the item in hand.
// @Switch world (WorldTag) checks the world.
// @Switch cuboid (CuboidTag) checks the cuboid area.
//
// @Context
// player (PlayerTag) returns the player that did the left clicking.
Expand All @@ -64,7 +66,9 @@ public boolean couldMatch(ScriptEventData data) {
public boolean matches(ScriptEventData data) {
return D2SpongeEventHelper.checkBlockType(location.getInternal().toLocation().getBlock().getType(), data, this::error)
&& D2SpongeEventHelper.checkItem(new ItemTag(player.getInternal()
.getItemInHand(HandTypes.MAIN_HAND).orElse(ItemStack.of(ItemTypes.NONE, 1))), data, this::error);
.getItemInHand(HandTypes.MAIN_HAND).orElse(ItemStack.empty())), data, this::error)
&& D2SpongeEventHelper.checkWorld(location.getInternal().world, data, this::error)
&& D2SpongeEventHelper.checkCuboid(location.getInternal(), data, this::error);
}

public PlayerTag player;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public boolean couldMatch(ScriptEventData data) {
public boolean matches(ScriptEventData data) {
return D2SpongeEventHelper.checkEntityType(entity.getInternal().getType(), data, this::error)
&& D2SpongeEventHelper.checkItem(new ItemTag(player.getInternal()
.getItemInHand(HandTypes.MAIN_HAND).orElse(ItemStack.of(ItemTypes.NONE, 1))), data, this::error);
.getItemInHand(HandTypes.MAIN_HAND).orElse(ItemStack.empty())), data, this::error);
}

public PlayerTag player;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public boolean couldMatch(ScriptEventData data) {
@Override
public boolean matches(ScriptEventData data) {
return D2SpongeEventHelper.checkItem(new ItemTag(player.getInternal().
getItemInHand(HandTypes.MAIN_HAND).orElse(ItemStack.of(ItemTypes.NONE, 1))), data, this::error);
getItemInHand(HandTypes.MAIN_HAND).orElse(ItemStack.empty())), data, this::error);
}

public PlayerTag player;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class PlayerRightClicksBlockScriptEvent extends ScriptEvent {
// @Events
// player right clicks block
//
// @Updated 2017/03/30
// @Updated 2017/10/14
//
// @Cancellable true
//
Expand All @@ -41,6 +41,8 @@ public class PlayerRightClicksBlockScriptEvent extends ScriptEvent {
// @Switch type (BlockTypeTag) checks the block type.
// @Switch hand (TextTag) checks the hand type.
// @Switch with_item (ItemTag) checks the item in hand.
// @Switch world (WorldTag) checks the world.
// @Switch cuboid (CuboidTag) checks the cuboid area.
//
// @Context
// player (PlayerTag) returns the player that did the right clicking.
Expand Down Expand Up @@ -69,7 +71,9 @@ public boolean matches(ScriptEventData data) {
return D2SpongeEventHelper.checkBlockType(location.getInternal().toLocation().getBlock().getType(), data, this::error)
&& D2SpongeEventHelper.checkHandType(hand.getInternal(), data, this::error)
&& D2SpongeEventHelper.checkItem(new ItemTag(player.getInternal()
.getItemInHand(hInternal).orElse(ItemStack.of(ItemTypes.NONE, 1))), data, this::error);
.getItemInHand(hInternal).orElse(ItemStack.empty())), data, this::error)
&& D2SpongeEventHelper.checkWorld(location.getInternal().world, data, this::error)
&& D2SpongeEventHelper.checkCuboid(location.getInternal(), data, this::error);
}

public PlayerTag player;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public boolean matches(ScriptEventData data) {
return D2SpongeEventHelper.checkEntityType(entity.getInternal().getType(), data, this::error)
&& D2SpongeEventHelper.checkHandType(hand.getInternal(), data, this::error)
&& D2SpongeEventHelper.checkItem(new ItemTag(player.getInternal()
.getItemInHand(hInternal).orElse(ItemStack.of(ItemTypes.NONE, 1))), data, this::error);
.getItemInHand(hInternal).orElse(ItemStack.empty())), data, this::error);
}

public PlayerTag player;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public boolean couldMatch(ScriptEventData data) {
@Override
public boolean matches(ScriptEventData data) {
return D2SpongeEventHelper.checkItem(new ItemTag(player.getInternal().
getItemInHand(HandTypes.MAIN_HAND).orElse(ItemStack.of(ItemTypes.NONE, 1))), data, this::error);
getItemInHand(HandTypes.MAIN_HAND).orElse(ItemStack.empty())), data, this::error);
}

public PlayerTag player;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class BlockChangesScriptEvent extends ScriptEvent {
// @Events
// block changes
//
// @Updated 2017/10/05
// @Updated 2017/10/14
//
// @Group World
//
Expand All @@ -30,6 +30,8 @@ public class BlockChangesScriptEvent extends ScriptEvent {
//
// @Switch new_type (BlockTypeTag) checks the new block type.
// @Switch old_type (BlockTypeTag) checks the old block type.
// @Switch world (WorldTag) checks the world.
// @Switch cuboid (CuboidTag) checks the cuboid area.
//
// @Context
// location (LocationTag) returns the location of the changed block.
Expand All @@ -54,7 +56,8 @@ public boolean couldMatch(ScriptEventData data) {
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.checkWorld(location.getInternal().world, data, this::error);
&& D2SpongeEventHelper.checkWorld(location.getInternal().world, data, this::error)
&& D2SpongeEventHelper.checkCuboid(location.getInternal(), data, this::error);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class BlockFadesScriptEvent extends ScriptEvent {
// @Events
// block fades
//
// @Updated 2017/10/05
// @Updated 2017/10/14
//
// @Group World
//
Expand All @@ -29,6 +29,8 @@ public class BlockFadesScriptEvent extends ScriptEvent {
// @Triggers when a block fades (like leaves).
//
// @Switch type (BlockTypeTag) checks the block type.
// @Switch world (WorldTag) checks the world.
// @Switch cuboid (CuboidTag) checks the cuboid area.
//
// @Context
// location (LocationTag) returns the location of the faded block.
Expand All @@ -51,7 +53,8 @@ public boolean couldMatch(ScriptEventData data) {
@Override
public boolean matches(ScriptEventData data) {
return D2SpongeEventHelper.checkBlockType(material.getInternal(), data, this::error)
&& D2SpongeEventHelper.checkWorld(location.getInternal().world, data, this::error);
&& D2SpongeEventHelper.checkWorld(location.getInternal().world, data, this::error)
&& D2SpongeEventHelper.checkCuboid(location.getInternal(), data, this::error);
}

public LocationTag location;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public class ExplosionDetonatesScriptEvent extends ScriptEvent {
//
// @Triggers when an explosion detonates and is calculating the affected locations and entities.
//
// @Switch world (WorldTag) checks the world.
// @Switch cuboid (CuboidTag) checks the cuboid area.
//
// @Context
// locations (ListTag<LocationTag>) returns the locations affected by the explosion.
// entities (ListTag<EntityTag>) returns the entities affected by the explosion.
Expand Down
Loading

0 comments on commit f3bbad2

Please sign in to comment.