mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-09 20:31:28 +01:00
Use GameWorld object to store triggers instead of a Map
This commit is contained in:
parent
df843c95ef
commit
84ba83b143
@ -235,28 +235,26 @@ public class PlayerListener implements Listener {
|
||||
GameWorld gameWorld = GameWorld.getByWorld(player.getWorld());
|
||||
if (gameWorld != null) {
|
||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_AIR) {
|
||||
if (UseItemTrigger.hasTriggers(gameWorld)) {
|
||||
String name = null;
|
||||
if (item.hasItemMeta()) {
|
||||
if (item.getItemMeta().hasDisplayName()) {
|
||||
name = item.getItemMeta().getDisplayName();
|
||||
String name = null;
|
||||
if (item.hasItemMeta()) {
|
||||
if (item.getItemMeta().hasDisplayName()) {
|
||||
name = item.getItemMeta().getDisplayName();
|
||||
|
||||
} else if (item.getType() == Material.WRITTEN_BOOK || item.getType() == Material.BOOK_AND_QUILL) {
|
||||
if (item.getItemMeta() instanceof BookMeta) {
|
||||
BookMeta meta = (BookMeta) item.getItemMeta();
|
||||
if (meta.hasTitle()) {
|
||||
name = meta.getTitle();
|
||||
}
|
||||
} else if (item.getType() == Material.WRITTEN_BOOK || item.getType() == Material.BOOK_AND_QUILL) {
|
||||
if (item.getItemMeta() instanceof BookMeta) {
|
||||
BookMeta meta = (BookMeta) item.getItemMeta();
|
||||
if (meta.hasTitle()) {
|
||||
name = meta.getTitle();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (name == null) {
|
||||
name = item.getType().toString();
|
||||
}
|
||||
UseItemTrigger trigger = UseItemTrigger.get(name, gameWorld);
|
||||
if (trigger != null) {
|
||||
trigger.onTrigger(player);
|
||||
}
|
||||
}
|
||||
if (name == null) {
|
||||
name = item.getType().toString();
|
||||
}
|
||||
UseItemTrigger trigger = UseItemTrigger.getByName(name, gameWorld);
|
||||
if (trigger != null) {
|
||||
trigger.onTrigger(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -289,7 +287,7 @@ public class PlayerListener implements Listener {
|
||||
if (gameWorld != null) {
|
||||
|
||||
// Trigger InteractTrigger
|
||||
InteractTrigger trigger = InteractTrigger.get(clickedBlock, gameWorld);
|
||||
InteractTrigger trigger = InteractTrigger.getByBlock(clickedBlock, gameWorld);
|
||||
if (trigger != null) {
|
||||
if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
|
||||
trigger.onTrigger(player);
|
||||
|
@ -136,7 +136,7 @@ public class DMob {
|
||||
name = victim.getType().getName();
|
||||
}
|
||||
|
||||
MobTrigger mobTrigger = MobTrigger.get(name, gameWorld);
|
||||
MobTrigger mobTrigger = MobTrigger.getByName(name, gameWorld);
|
||||
if (mobTrigger != null) {
|
||||
mobTrigger.onTrigger();
|
||||
}
|
||||
|
@ -92,11 +92,9 @@ public class OpenDoorSign extends DSign {
|
||||
|
||||
GameWorld gameWorld = GameWorld.getByWorld(block.getWorld());
|
||||
if (gameWorld != null) {
|
||||
for (DSign dSign : gameWorld.getDSigns()) {
|
||||
if (dSign.getType() == DSignTypeDefault.OPEN_DOOR) {
|
||||
if (((OpenDoorSign) dSign).getBlock().equals(block)) {
|
||||
return true;
|
||||
}
|
||||
for (DSign dSign : gameWorld.getDSigns(DSignTypeDefault.OPEN_DOOR)) {
|
||||
if (((OpenDoorSign) dSign).getBlock().equals(block)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ public class TriggerSign extends DSign {
|
||||
return;
|
||||
}
|
||||
|
||||
SignTrigger trigger = SignTrigger.get(triggerId, getGameWorld());
|
||||
SignTrigger trigger = SignTrigger.getById(triggerId, getGameWorld());
|
||||
if (trigger != null) {
|
||||
trigger.onTrigger(true);
|
||||
}
|
||||
@ -112,7 +112,7 @@ public class TriggerSign extends DSign {
|
||||
return;
|
||||
}
|
||||
|
||||
SignTrigger trigger = SignTrigger.get(triggerId, getGameWorld());
|
||||
SignTrigger trigger = SignTrigger.getById(triggerId, getGameWorld());
|
||||
if (trigger != null) {
|
||||
trigger.onTrigger(false);
|
||||
}
|
||||
|
@ -18,9 +18,6 @@ package io.github.dre2n.dungeonsxl.trigger;
|
||||
|
||||
import io.github.dre2n.dungeonsxl.event.trigger.TriggerActionEvent;
|
||||
import io.github.dre2n.dungeonsxl.world.GameWorld;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -29,8 +26,6 @@ import org.bukkit.entity.Player;
|
||||
*/
|
||||
public class DistanceTrigger extends Trigger {
|
||||
|
||||
private static Map<GameWorld, ArrayList<DistanceTrigger>> triggers = new HashMap<>();
|
||||
|
||||
private TriggerType type = TriggerTypeDefault.DISTANCE;
|
||||
|
||||
private int distance = 5;
|
||||
@ -60,56 +55,23 @@ public class DistanceTrigger extends Trigger {
|
||||
updateDSigns();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(GameWorld gameWorld) {
|
||||
if (!hasTriggers(gameWorld)) {
|
||||
ArrayList<DistanceTrigger> list = new ArrayList<>();
|
||||
list.add(this);
|
||||
triggers.put(gameWorld, list);
|
||||
|
||||
} else {
|
||||
triggers.get(gameWorld).add(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregister(GameWorld gameWorld) {
|
||||
if (hasTriggers(gameWorld)) {
|
||||
triggers.get(gameWorld).remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TriggerType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/* Statics */
|
||||
public static void triggerAllInDistance(Player player, GameWorld gameWorld) {
|
||||
if (!hasTriggers(gameWorld)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!player.getLocation().getWorld().equals(gameWorld.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (DistanceTrigger trigger : getTriggersArray(gameWorld)) {
|
||||
for (Trigger uncasted : gameWorld.getTriggers(TriggerTypeDefault.DISTANCE)) {
|
||||
DistanceTrigger trigger = (DistanceTrigger) uncasted;
|
||||
if (player.getLocation().distance(trigger.loc) < trigger.distance) {
|
||||
trigger.onTrigger(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasTriggers(GameWorld gameWorld) {
|
||||
return !triggers.isEmpty() && triggers.containsKey(gameWorld);
|
||||
}
|
||||
|
||||
public static ArrayList<DistanceTrigger> getTriggers(GameWorld gameWorld) {
|
||||
return triggers.get(gameWorld);
|
||||
}
|
||||
|
||||
public static DistanceTrigger[] getTriggersArray(GameWorld gameWorld) {
|
||||
return getTriggers(gameWorld).toArray(new DistanceTrigger[getTriggers(gameWorld).size()]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,9 +18,6 @@ package io.github.dre2n.dungeonsxl.trigger;
|
||||
|
||||
import io.github.dre2n.dungeonsxl.event.trigger.TriggerActionEvent;
|
||||
import io.github.dre2n.dungeonsxl.world.GameWorld;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -29,8 +26,6 @@ import org.bukkit.entity.Player;
|
||||
*/
|
||||
public class InteractTrigger extends Trigger {
|
||||
|
||||
private static Map<GameWorld, ArrayList<InteractTrigger>> triggers = new HashMap<>();
|
||||
|
||||
private TriggerType type = TriggerTypeDefault.INTERACT;
|
||||
|
||||
private int interactId;
|
||||
@ -54,35 +49,17 @@ public class InteractTrigger extends Trigger {
|
||||
updateDSigns();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(GameWorld gameWorld) {
|
||||
if (!hasTriggers(gameWorld)) {
|
||||
ArrayList<InteractTrigger> list = new ArrayList<>();
|
||||
list.add(this);
|
||||
triggers.put(gameWorld, list);
|
||||
|
||||
} else {
|
||||
triggers.get(gameWorld).add(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregister(GameWorld gameWorld) {
|
||||
if (hasTriggers(gameWorld)) {
|
||||
triggers.get(gameWorld).remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TriggerType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/* Statics */
|
||||
public static InteractTrigger getOrCreate(int id, GameWorld gameWorld) {
|
||||
if (id == 0) {
|
||||
return null;
|
||||
}
|
||||
InteractTrigger trigger = get(id, gameWorld);
|
||||
InteractTrigger trigger = getById(id, gameWorld);
|
||||
if (trigger != null) {
|
||||
return trigger;
|
||||
}
|
||||
@ -90,7 +67,7 @@ public class InteractTrigger extends Trigger {
|
||||
}
|
||||
|
||||
public static InteractTrigger getOrCreate(int id, Block block, GameWorld gameWorld) {
|
||||
InteractTrigger trigger = get(id, gameWorld);
|
||||
InteractTrigger trigger = getById(id, gameWorld);
|
||||
if (trigger != null) {
|
||||
trigger.interactBlock = block;
|
||||
return trigger;
|
||||
@ -98,34 +75,28 @@ public class InteractTrigger extends Trigger {
|
||||
return new InteractTrigger(id, block);
|
||||
}
|
||||
|
||||
public static InteractTrigger get(Block block, GameWorld gameWorld) {
|
||||
if (hasTriggers(gameWorld)) {
|
||||
for (InteractTrigger trigger : triggers.get(gameWorld)) {
|
||||
if (trigger.interactBlock != null) {
|
||||
if (trigger.interactBlock.equals(block)) {
|
||||
return trigger;
|
||||
}
|
||||
public static InteractTrigger getByBlock(Block block, GameWorld gameWorld) {
|
||||
for (Trigger uncasted : gameWorld.getTriggers(TriggerTypeDefault.INTERACT)) {
|
||||
InteractTrigger trigger = (InteractTrigger) uncasted;
|
||||
if (trigger.interactBlock != null) {
|
||||
if (trigger.interactBlock.equals(block)) {
|
||||
return trigger;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static InteractTrigger get(int id, GameWorld gameWorld) {
|
||||
public static InteractTrigger getById(int id, GameWorld gameWorld) {
|
||||
if (id != 0) {
|
||||
if (hasTriggers(gameWorld)) {
|
||||
for (InteractTrigger trigger : triggers.get(gameWorld)) {
|
||||
if (trigger.interactId == id) {
|
||||
return trigger;
|
||||
}
|
||||
for (Trigger uncasted : gameWorld.getTriggers(TriggerTypeDefault.INTERACT)) {
|
||||
InteractTrigger trigger = (InteractTrigger) uncasted;
|
||||
if (trigger.interactId == id) {
|
||||
return trigger;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean hasTriggers(GameWorld gameWorld) {
|
||||
return !triggers.isEmpty() && triggers.containsKey(gameWorld);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,17 +18,12 @@ package io.github.dre2n.dungeonsxl.trigger;
|
||||
|
||||
import io.github.dre2n.dungeonsxl.event.trigger.TriggerActionEvent;
|
||||
import io.github.dre2n.dungeonsxl.world.GameWorld;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Frank Baumann, Daniel Saukel
|
||||
*/
|
||||
public class MobTrigger extends Trigger {
|
||||
|
||||
private static Map<GameWorld, ArrayList<MobTrigger>> triggers = new HashMap<>();
|
||||
|
||||
private TriggerType type = TriggerTypeDefault.MOB;
|
||||
|
||||
private String name;
|
||||
@ -49,51 +44,28 @@ public class MobTrigger extends Trigger {
|
||||
updateDSigns();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(GameWorld gameWorld) {
|
||||
if (!hasTriggers(gameWorld)) {
|
||||
ArrayList<MobTrigger> list = new ArrayList<>();
|
||||
list.add(this);
|
||||
triggers.put(gameWorld, list);
|
||||
|
||||
} else {
|
||||
triggers.get(gameWorld).add(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregister(GameWorld gameWorld) {
|
||||
if (hasTriggers(gameWorld)) {
|
||||
triggers.get(gameWorld).remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TriggerType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/* Statics */
|
||||
public static MobTrigger getOrCreate(String name, GameWorld gameWorld) {
|
||||
MobTrigger trigger = get(name, gameWorld);
|
||||
MobTrigger trigger = getByName(name, gameWorld);
|
||||
if (trigger != null) {
|
||||
return trigger;
|
||||
}
|
||||
return new MobTrigger(name);
|
||||
}
|
||||
|
||||
public static MobTrigger get(String name, GameWorld gameWorld) {
|
||||
if (hasTriggers(gameWorld)) {
|
||||
for (MobTrigger trigger : triggers.get(gameWorld)) {
|
||||
if (trigger.name.equalsIgnoreCase(name)) {
|
||||
return trigger;
|
||||
}
|
||||
public static MobTrigger getByName(String name, GameWorld gameWorld) {
|
||||
for (Trigger uncasted : gameWorld.getTriggers(TriggerTypeDefault.MOB)) {
|
||||
MobTrigger trigger = (MobTrigger) uncasted;
|
||||
if (trigger.name.equalsIgnoreCase(name)) {
|
||||
return trigger;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean hasTriggers(GameWorld gameWorld) {
|
||||
return !triggers.isEmpty() && triggers.containsKey(gameWorld);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,10 +18,7 @@ package io.github.dre2n.dungeonsxl.trigger;
|
||||
|
||||
import io.github.dre2n.dungeonsxl.event.trigger.TriggerActionEvent;
|
||||
import io.github.dre2n.dungeonsxl.world.GameWorld;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@ -29,8 +26,6 @@ import java.util.Set;
|
||||
*/
|
||||
public class ProgressTrigger extends Trigger {
|
||||
|
||||
private static Map<GameWorld, ArrayList<ProgressTrigger>> triggers = new HashMap<>();
|
||||
|
||||
private TriggerType type = TriggerTypeDefault.PROGRESS;
|
||||
|
||||
private String floor;
|
||||
@ -105,30 +100,12 @@ public class ProgressTrigger extends Trigger {
|
||||
updateDSigns();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(GameWorld gameWorld) {
|
||||
if (!hasTriggers(gameWorld)) {
|
||||
ArrayList<ProgressTrigger> list = new ArrayList<>();
|
||||
list.add(this);
|
||||
triggers.put(gameWorld, list);
|
||||
|
||||
} else {
|
||||
triggers.get(gameWorld).add(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregister(GameWorld gameWorld) {
|
||||
if (hasTriggers(gameWorld)) {
|
||||
triggers.get(gameWorld).remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TriggerType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/* Statics */
|
||||
public static ProgressTrigger getOrCreate(int floorCount, int waveCount, GameWorld gameWorld) {
|
||||
if (floorCount == 0 & waveCount == 0 || floorCount < 0 || waveCount < 0) {
|
||||
return null;
|
||||
@ -142,14 +119,10 @@ public class ProgressTrigger extends Trigger {
|
||||
|
||||
public static Set<ProgressTrigger> getByGameWorld(GameWorld gameWorld) {
|
||||
Set<ProgressTrigger> toReturn = new HashSet<>();
|
||||
for (ProgressTrigger trigger : triggers.get(gameWorld)) {
|
||||
toReturn.add(trigger);
|
||||
for (Trigger trigger : gameWorld.getTriggers(TriggerTypeDefault.PROGRESS)) {
|
||||
toReturn.add((ProgressTrigger) trigger);
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static boolean hasTriggers(GameWorld gameWorld) {
|
||||
return !triggers.isEmpty() && triggers.containsKey(gameWorld);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,9 +18,6 @@ package io.github.dre2n.dungeonsxl.trigger;
|
||||
|
||||
import io.github.dre2n.dungeonsxl.event.trigger.TriggerActionEvent;
|
||||
import io.github.dre2n.dungeonsxl.world.GameWorld;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
@ -31,8 +28,6 @@ import org.bukkit.block.Sign;
|
||||
*/
|
||||
public class RedstoneTrigger extends Trigger {
|
||||
|
||||
private static Map<GameWorld, ArrayList<RedstoneTrigger>> triggers = new HashMap<>();
|
||||
|
||||
private TriggerType type = TriggerTypeDefault.REDSTONE;
|
||||
|
||||
private Block rtBlock;
|
||||
@ -61,30 +56,12 @@ public class RedstoneTrigger extends Trigger {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(GameWorld gameWorld) {
|
||||
if (!hasTriggers(gameWorld)) {
|
||||
ArrayList<RedstoneTrigger> list = new ArrayList<>();
|
||||
list.add(this);
|
||||
triggers.put(gameWorld, list);
|
||||
|
||||
} else {
|
||||
triggers.get(gameWorld).add(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregister(GameWorld gameWorld) {
|
||||
if (hasTriggers(gameWorld)) {
|
||||
triggers.get(gameWorld).remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TriggerType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/* Statics */
|
||||
public static RedstoneTrigger getOrCreate(Sign sign, GameWorld gameWorld) {
|
||||
Block rtBlock = null;
|
||||
if (sign.getBlock().getType() == Material.WALL_SIGN) {
|
||||
@ -108,11 +85,10 @@ public class RedstoneTrigger extends Trigger {
|
||||
}
|
||||
|
||||
if (rtBlock != null) {
|
||||
if (hasTriggers(gameWorld)) {
|
||||
for (RedstoneTrigger trigger : getTriggers(gameWorld)) {
|
||||
if (trigger.rtBlock.equals(rtBlock)) {
|
||||
return trigger;
|
||||
}
|
||||
for (Trigger uncasted : gameWorld.getTriggers(TriggerTypeDefault.REDSTONE)) {
|
||||
RedstoneTrigger trigger = (RedstoneTrigger) uncasted;
|
||||
if (trigger.rtBlock.equals(rtBlock)) {
|
||||
return trigger;
|
||||
}
|
||||
}
|
||||
return new RedstoneTrigger(rtBlock);
|
||||
@ -121,23 +97,9 @@ public class RedstoneTrigger extends Trigger {
|
||||
}
|
||||
|
||||
public static void updateAll(GameWorld gameWorld) {
|
||||
if (hasTriggers(gameWorld)) {
|
||||
for (RedstoneTrigger trigger : getTriggersArray(gameWorld)) {
|
||||
trigger.onTrigger();
|
||||
}
|
||||
for (Trigger trigger : gameWorld.getTriggers(TriggerTypeDefault.REDSTONE)) {
|
||||
((RedstoneTrigger) trigger).onTrigger();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasTriggers(GameWorld gameWorld) {
|
||||
return !triggers.isEmpty() && triggers.containsKey(gameWorld);
|
||||
}
|
||||
|
||||
public static ArrayList<RedstoneTrigger> getTriggers(GameWorld gameWorld) {
|
||||
return triggers.get(gameWorld);
|
||||
}
|
||||
|
||||
public static RedstoneTrigger[] getTriggersArray(GameWorld gameWorld) {
|
||||
return getTriggers(gameWorld).toArray(new RedstoneTrigger[getTriggers(gameWorld).size()]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,17 +18,12 @@ package io.github.dre2n.dungeonsxl.trigger;
|
||||
|
||||
import io.github.dre2n.dungeonsxl.event.trigger.TriggerActionEvent;
|
||||
import io.github.dre2n.dungeonsxl.world.GameWorld;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Frank Baumann, Daniel Saukel
|
||||
*/
|
||||
public class SignTrigger extends Trigger {
|
||||
|
||||
private static Map<GameWorld, ArrayList<SignTrigger>> triggers = new HashMap<>();
|
||||
|
||||
private TriggerType type = TriggerTypeDefault.SIGN;
|
||||
|
||||
private int stId;
|
||||
@ -51,51 +46,28 @@ public class SignTrigger extends Trigger {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(GameWorld gameWorld) {
|
||||
if (!hasTriggers(gameWorld)) {
|
||||
ArrayList<SignTrigger> list = new ArrayList<>();
|
||||
list.add(this);
|
||||
triggers.put(gameWorld, list);
|
||||
|
||||
} else {
|
||||
triggers.get(gameWorld).add(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregister(GameWorld gameWorld) {
|
||||
if (hasTriggers(gameWorld)) {
|
||||
triggers.get(gameWorld).remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TriggerType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/* Statics */
|
||||
public static SignTrigger getOrCreate(int id, GameWorld gameWorld) {
|
||||
SignTrigger trigger = get(id, gameWorld);
|
||||
SignTrigger trigger = getById(id, gameWorld);
|
||||
if (trigger != null) {
|
||||
return trigger;
|
||||
}
|
||||
return new SignTrigger(id);
|
||||
}
|
||||
|
||||
public static SignTrigger get(int id, GameWorld gameWorld) {
|
||||
if (hasTriggers(gameWorld)) {
|
||||
for (SignTrigger trigger : triggers.get(gameWorld)) {
|
||||
if (trigger.stId == id) {
|
||||
return trigger;
|
||||
}
|
||||
public static SignTrigger getById(int id, GameWorld gameWorld) {
|
||||
for (Trigger uncasted : gameWorld.getTriggers(TriggerTypeDefault.SIGN)) {
|
||||
SignTrigger trigger = (SignTrigger) uncasted;
|
||||
if (trigger.stId == id) {
|
||||
return trigger;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean hasTriggers(GameWorld gameWorld) {
|
||||
return !triggers.isEmpty() && triggers.containsKey(gameWorld);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -113,6 +113,14 @@ public abstract class Trigger {
|
||||
}
|
||||
}
|
||||
|
||||
public void register(GameWorld gameWorld) {
|
||||
gameWorld.addTrigger(this);
|
||||
}
|
||||
|
||||
public void unregister(GameWorld gameWorld) {
|
||||
gameWorld.removeTrigger(this);
|
||||
}
|
||||
|
||||
public static Trigger getOrCreate(String identifier, String value, DSign dSign) {
|
||||
TriggerType type = plugin.getTriggers().getByIdentifier(identifier);
|
||||
Trigger trigger = null;
|
||||
@ -199,10 +207,6 @@ public abstract class Trigger {
|
||||
}
|
||||
|
||||
/* Abstracts */
|
||||
public abstract void register(GameWorld gameWorld);
|
||||
|
||||
public abstract void unregister(GameWorld gameWorld);
|
||||
|
||||
public abstract TriggerType getType();
|
||||
|
||||
}
|
||||
|
@ -18,9 +18,6 @@ package io.github.dre2n.dungeonsxl.trigger;
|
||||
|
||||
import io.github.dre2n.dungeonsxl.event.trigger.TriggerActionEvent;
|
||||
import io.github.dre2n.dungeonsxl.world.GameWorld;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -29,8 +26,6 @@ import org.bukkit.entity.Player;
|
||||
*/
|
||||
public class UseItemTrigger extends Trigger {
|
||||
|
||||
private static Map<GameWorld, ArrayList<UseItemTrigger>> triggers = new HashMap<>();
|
||||
|
||||
private TriggerType type = TriggerTypeDefault.USE_ITEM;
|
||||
|
||||
private String name;
|
||||
@ -57,54 +52,32 @@ public class UseItemTrigger extends Trigger {
|
||||
updateDSigns();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(GameWorld gameWorld) {
|
||||
if (!hasTriggers(gameWorld)) {
|
||||
ArrayList<UseItemTrigger> list = new ArrayList<>();
|
||||
list.add(this);
|
||||
triggers.put(gameWorld, list);
|
||||
} else {
|
||||
triggers.get(gameWorld).add(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregister(GameWorld gameWorld) {
|
||||
if (hasTriggers(gameWorld)) {
|
||||
triggers.get(gameWorld).remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TriggerType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/* Statics */
|
||||
public static UseItemTrigger getOrCreate(String name, GameWorld gameWorld) {
|
||||
UseItemTrigger trigger = get(name, gameWorld);
|
||||
UseItemTrigger trigger = getByName(name, gameWorld);
|
||||
if (trigger != null) {
|
||||
return trigger;
|
||||
}
|
||||
return new UseItemTrigger(name);
|
||||
}
|
||||
|
||||
public static UseItemTrigger get(String name, GameWorld gameWorld) {
|
||||
if (hasTriggers(gameWorld)) {
|
||||
for (UseItemTrigger trigger : triggers.get(gameWorld)) {
|
||||
if (trigger.name.equalsIgnoreCase(name)) {
|
||||
public static UseItemTrigger getByName(String name, GameWorld gameWorld) {
|
||||
for (Trigger uncasted : gameWorld.getTriggers(TriggerTypeDefault.USE_ITEM)) {
|
||||
UseItemTrigger trigger = (UseItemTrigger) uncasted;
|
||||
if (trigger.name.equalsIgnoreCase(name)) {
|
||||
return trigger;
|
||||
} else if (trigger.matchedName != null) {
|
||||
if (trigger.matchedName.equalsIgnoreCase(name)) {
|
||||
return trigger;
|
||||
} else if (trigger.matchedName != null) {
|
||||
if (trigger.matchedName.equalsIgnoreCase(name)) {
|
||||
return trigger;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean hasTriggers(GameWorld gameWorld) {
|
||||
return !triggers.isEmpty() && triggers.containsKey(gameWorld);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,10 +18,7 @@ package io.github.dre2n.dungeonsxl.trigger;
|
||||
|
||||
import io.github.dre2n.dungeonsxl.event.trigger.TriggerActionEvent;
|
||||
import io.github.dre2n.dungeonsxl.world.GameWorld;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@ -29,8 +26,6 @@ import java.util.Set;
|
||||
*/
|
||||
public class WaveTrigger extends Trigger {
|
||||
|
||||
private static Map<GameWorld, ArrayList<WaveTrigger>> triggers = new HashMap<>();
|
||||
|
||||
private TriggerType type = TriggerTypeDefault.WAVE;
|
||||
|
||||
private double mustKillRate = 1;
|
||||
@ -67,25 +62,6 @@ public class WaveTrigger extends Trigger {
|
||||
setTriggered(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(GameWorld gameWorld) {
|
||||
if (!hasTriggers(gameWorld)) {
|
||||
ArrayList<WaveTrigger> list = new ArrayList<>();
|
||||
list.add(this);
|
||||
triggers.put(gameWorld, list);
|
||||
|
||||
} else {
|
||||
triggers.get(gameWorld).add(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregister(GameWorld gameWorld) {
|
||||
if (hasTriggers(gameWorld)) {
|
||||
triggers.get(gameWorld).remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TriggerType getType() {
|
||||
return type;
|
||||
@ -101,17 +77,11 @@ public class WaveTrigger extends Trigger {
|
||||
*/
|
||||
public static Set<WaveTrigger> getByGameWorld(GameWorld gameWorld) {
|
||||
Set<WaveTrigger> toReturn = new HashSet<>();
|
||||
if (triggers.get(gameWorld) != null) {
|
||||
for (WaveTrigger trigger : triggers.get(gameWorld)) {
|
||||
toReturn.add(trigger);
|
||||
}
|
||||
for (Trigger trigger : gameWorld.getTriggers()) {
|
||||
toReturn.add((WaveTrigger) trigger);
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static boolean hasTriggers(GameWorld gameWorld) {
|
||||
return !triggers.isEmpty() && triggers.containsKey(gameWorld);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,12 +32,14 @@ import io.github.dre2n.dungeonsxl.player.DGamePlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DGroup;
|
||||
import io.github.dre2n.dungeonsxl.reward.RewardChest;
|
||||
import io.github.dre2n.dungeonsxl.sign.DSign;
|
||||
import io.github.dre2n.dungeonsxl.sign.DSignType;
|
||||
import io.github.dre2n.dungeonsxl.sign.DSignTypeDefault;
|
||||
import io.github.dre2n.dungeonsxl.sign.MobSign;
|
||||
import io.github.dre2n.dungeonsxl.sign.StartSign;
|
||||
import io.github.dre2n.dungeonsxl.trigger.ProgressTrigger;
|
||||
import io.github.dre2n.dungeonsxl.trigger.RedstoneTrigger;
|
||||
import io.github.dre2n.dungeonsxl.trigger.Trigger;
|
||||
import io.github.dre2n.dungeonsxl.trigger.TriggerType;
|
||||
import io.github.dre2n.dungeonsxl.trigger.TriggerTypeDefault;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@ -74,7 +76,6 @@ public class GameWorld {
|
||||
private World world;
|
||||
private String mapName;
|
||||
private Location locLobby;
|
||||
private Location locStart;
|
||||
private boolean isPlaying = false;
|
||||
private int id;
|
||||
private List<ItemStack> secureObjects = new ArrayList<>();
|
||||
@ -85,6 +86,7 @@ public class GameWorld {
|
||||
// TODO: Killed mobs
|
||||
private CopyOnWriteArrayList<RewardChest> rewardChests = new CopyOnWriteArrayList<>();
|
||||
private CopyOnWriteArrayList<DSign> dSigns = new CopyOnWriteArrayList<>();
|
||||
private CopyOnWriteArrayList<Trigger> triggers = new CopyOnWriteArrayList<>();
|
||||
private WorldConfig worldConfig;
|
||||
|
||||
public GameWorld() {
|
||||
@ -352,6 +354,19 @@ public class GameWorld {
|
||||
return dSigns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the triggers with the type
|
||||
*/
|
||||
public List<DSign> getDSigns(DSignType type) {
|
||||
List<DSign> dSignsOfType = new ArrayList<>();
|
||||
for (DSign dSign : dSigns) {
|
||||
if (dSign.getType() == type) {
|
||||
dSignsOfType.add(dSign);
|
||||
}
|
||||
}
|
||||
return dSignsOfType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dSigns
|
||||
* the dSigns to set
|
||||
@ -360,6 +375,42 @@ public class GameWorld {
|
||||
this.dSigns = dSigns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the triggers
|
||||
*/
|
||||
public CopyOnWriteArrayList<Trigger> getTriggers() {
|
||||
return triggers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the triggers with the type
|
||||
*/
|
||||
public List<Trigger> getTriggers(TriggerType type) {
|
||||
List<Trigger> triggersOfType = new ArrayList<>();
|
||||
for (Trigger trigger : triggers) {
|
||||
if (trigger.getType() == type) {
|
||||
triggersOfType.add(trigger);
|
||||
}
|
||||
}
|
||||
return triggersOfType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param trigger
|
||||
* the trigger to add
|
||||
*/
|
||||
public void addTrigger(Trigger trigger) {
|
||||
triggers.add(trigger);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param trigger
|
||||
* the trigger to remove
|
||||
*/
|
||||
public void removeTrigger(Trigger trigger) {
|
||||
triggers.remove(trigger);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the potential amount of mobs in the world
|
||||
*/
|
||||
@ -443,11 +494,11 @@ public class GameWorld {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (RedstoneTrigger.hasTriggers(this)) {
|
||||
for (RedstoneTrigger trigger : RedstoneTrigger.getTriggersArray(this)) {
|
||||
trigger.onTrigger();
|
||||
}
|
||||
|
||||
for (Trigger trigger : getTriggers(TriggerTypeDefault.REDSTONE)) {
|
||||
((RedstoneTrigger) trigger).onTrigger();
|
||||
}
|
||||
|
||||
for (DSign dSign : dSigns) {
|
||||
if (dSign != null) {
|
||||
if (!dSign.hasTriggers()) {
|
||||
|
Loading…
Reference in New Issue
Block a user