mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-24 19:45:43 +01:00
Merge pull request #29 from DRE2N/TriggerAPI
Add API for trigger (not fully implemented)
This commit is contained in:
commit
8c1b6cf8a9
@ -21,6 +21,7 @@ import io.github.dre2n.dungeonsxl.player.DGroup;
|
||||
import io.github.dre2n.dungeonsxl.player.DPlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DSavePlayer;
|
||||
import io.github.dre2n.dungeonsxl.sign.DSigns;
|
||||
import io.github.dre2n.dungeonsxl.trigger.Triggers;
|
||||
import io.github.dre2n.dungeonsxl.util.FileUtil;
|
||||
import io.github.dre2n.dungeonsxl.util.VersionUtil;
|
||||
import io.github.dre2n.dungeonsxl.util.VersionUtil.Internals;
|
||||
@ -50,6 +51,7 @@ public class DungeonsXL extends JavaPlugin {
|
||||
private VersionUtil versionUtil;
|
||||
private DCommands dCommands;
|
||||
private DSigns dSigns;
|
||||
private Triggers triggers;
|
||||
private Dungeons dungeons;
|
||||
|
||||
private CopyOnWriteArrayList<Player> inBreakMode = new CopyOnWriteArrayList<Player>();
|
||||
@ -391,6 +393,21 @@ public class DungeonsXL extends JavaPlugin {
|
||||
dSigns = new DSigns();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the triggers
|
||||
*/
|
||||
public Triggers getTriggers() {
|
||||
return triggers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param triggers
|
||||
* the triggers to set
|
||||
*/
|
||||
public void loadTriggers() {
|
||||
triggers = new Triggers();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the loaded instance of Dungeons
|
||||
*/
|
||||
|
@ -113,7 +113,7 @@ public abstract class DSign {
|
||||
|
||||
public void onUpdate() {
|
||||
for (Trigger trigger : triggers) {
|
||||
if ( !trigger.triggered) {
|
||||
if ( !trigger.isTriggered()) {
|
||||
onDisable();
|
||||
return;
|
||||
}
|
||||
@ -122,11 +122,11 @@ public abstract class DSign {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (trigger.player == null) {
|
||||
if (trigger.getPlayer() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (onPlayerTrigger(trigger.player)) {
|
||||
if (onPlayerTrigger(trigger.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,8 @@ public class DistanceTrigger extends Trigger {
|
||||
|
||||
private static Map<GameWorld, ArrayList<DistanceTrigger>> triggers = new HashMap<GameWorld, ArrayList<DistanceTrigger>>();
|
||||
|
||||
private TriggerType type = TriggerTypeDefault.DISTANCE;
|
||||
|
||||
private int distance = 5;
|
||||
private Location loc;
|
||||
|
||||
@ -28,56 +30,61 @@ public class DistanceTrigger extends Trigger {
|
||||
}
|
||||
|
||||
public void onTrigger(Player player) {
|
||||
triggered = true;
|
||||
this.player = player;
|
||||
setTriggered(true);
|
||||
this.setPlayer(player);
|
||||
updateDSigns();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(GameWorld gworld) {
|
||||
if ( !hasTriggers(gworld)) {
|
||||
public void register(GameWorld gameWorld) {
|
||||
if ( !hasTriggers(gameWorld)) {
|
||||
ArrayList<DistanceTrigger> list = new ArrayList<DistanceTrigger>();
|
||||
list.add(this);
|
||||
triggers.put(gworld, list);
|
||||
triggers.put(gameWorld, list);
|
||||
|
||||
} else {
|
||||
triggers.get(gworld).add(this);
|
||||
triggers.get(gameWorld).add(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregister(GameWorld gworld) {
|
||||
if (hasTriggers(gworld)) {
|
||||
triggers.get(gworld).remove(this);
|
||||
public void unregister(GameWorld gameWorld) {
|
||||
if (hasTriggers(gameWorld)) {
|
||||
triggers.get(gameWorld).remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
public static void triggerAllInDistance(Player player, GameWorld gWorld) {
|
||||
if ( !hasTriggers(gWorld)) {
|
||||
@Override
|
||||
public TriggerType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public static void triggerAllInDistance(Player player, GameWorld gameWorld) {
|
||||
if ( !hasTriggers(gameWorld)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !player.getLocation().getWorld().equals(gWorld.getWorld())) {
|
||||
if ( !player.getLocation().getWorld().equals(gameWorld.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (DistanceTrigger trigger : getTriggersArray(gWorld)) {
|
||||
for (DistanceTrigger trigger : getTriggersArray(gameWorld)) {
|
||||
if (player.getLocation().distance(trigger.loc) < trigger.distance) {
|
||||
trigger.onTrigger(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasTriggers(GameWorld gworld) {
|
||||
return !triggers.isEmpty() && triggers.containsKey(gworld);
|
||||
public static boolean hasTriggers(GameWorld gameWorld) {
|
||||
return !triggers.isEmpty() && triggers.containsKey(gameWorld);
|
||||
}
|
||||
|
||||
public static ArrayList<DistanceTrigger> getTriggers(GameWorld gworld) {
|
||||
return triggers.get(gworld);
|
||||
public static ArrayList<DistanceTrigger> getTriggers(GameWorld gameWorld) {
|
||||
return triggers.get(gameWorld);
|
||||
}
|
||||
|
||||
public static DistanceTrigger[] getTriggersArray(GameWorld gworld) {
|
||||
return getTriggers(gworld).toArray(new DistanceTrigger[getTriggers(gworld).size()]);
|
||||
public static DistanceTrigger[] getTriggersArray(GameWorld gameWorld) {
|
||||
return getTriggers(gameWorld).toArray(new DistanceTrigger[getTriggers(gameWorld).size()]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -13,6 +13,8 @@ public class InteractTrigger extends Trigger {
|
||||
|
||||
private static Map<GameWorld, ArrayList<InteractTrigger>> triggers = new HashMap<GameWorld, ArrayList<InteractTrigger>>();
|
||||
|
||||
private TriggerType type = TriggerTypeDefault.INTERACT;
|
||||
|
||||
private int interactId;
|
||||
private Block interactBlock;
|
||||
|
||||
@ -22,43 +24,48 @@ public class InteractTrigger extends Trigger {
|
||||
}
|
||||
|
||||
public void onTrigger(Player player) {
|
||||
triggered = true;
|
||||
this.player = player;
|
||||
setTriggered(true);
|
||||
this.setPlayer(player);
|
||||
updateDSigns();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(GameWorld gworld) {
|
||||
if ( !hasTriggers(gworld)) {
|
||||
public void register(GameWorld gameWorld) {
|
||||
if ( !hasTriggers(gameWorld)) {
|
||||
ArrayList<InteractTrigger> list = new ArrayList<InteractTrigger>();
|
||||
list.add(this);
|
||||
triggers.put(gworld, list);
|
||||
triggers.put(gameWorld, list);
|
||||
|
||||
} else {
|
||||
triggers.get(gworld).add(this);
|
||||
triggers.get(gameWorld).add(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregister(GameWorld gworld) {
|
||||
if (hasTriggers(gworld)) {
|
||||
triggers.get(gworld).remove(this);
|
||||
public void unregister(GameWorld gameWorld) {
|
||||
if (hasTriggers(gameWorld)) {
|
||||
triggers.get(gameWorld).remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
public static InteractTrigger getOrCreate(int id, GameWorld gworld) {
|
||||
@Override
|
||||
public TriggerType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public static InteractTrigger getOrCreate(int id, GameWorld gameWorld) {
|
||||
if (id == 0) {
|
||||
return null;
|
||||
}
|
||||
InteractTrigger trigger = get(id, gworld);
|
||||
InteractTrigger trigger = get(id, gameWorld);
|
||||
if (trigger != null) {
|
||||
return trigger;
|
||||
}
|
||||
return new InteractTrigger(id, null);
|
||||
}
|
||||
|
||||
public static InteractTrigger getOrCreate(int id, Block block, GameWorld gworld) {
|
||||
InteractTrigger trigger = get(id, gworld);
|
||||
public static InteractTrigger getOrCreate(int id, Block block, GameWorld gameWorld) {
|
||||
InteractTrigger trigger = get(id, gameWorld);
|
||||
if (trigger != null) {
|
||||
trigger.interactBlock = block;
|
||||
return trigger;
|
||||
@ -66,9 +73,9 @@ public class InteractTrigger extends Trigger {
|
||||
return new InteractTrigger(id, block);
|
||||
}
|
||||
|
||||
public static InteractTrigger get(Block block, GameWorld gworld) {
|
||||
if (hasTriggers(gworld)) {
|
||||
for (InteractTrigger trigger : triggers.get(gworld)) {
|
||||
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;
|
||||
@ -79,10 +86,10 @@ public class InteractTrigger extends Trigger {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static InteractTrigger get(int id, GameWorld gworld) {
|
||||
public static InteractTrigger get(int id, GameWorld gameWorld) {
|
||||
if (id != 0) {
|
||||
if (hasTriggers(gworld)) {
|
||||
for (InteractTrigger trigger : triggers.get(gworld)) {
|
||||
if (hasTriggers(gameWorld)) {
|
||||
for (InteractTrigger trigger : triggers.get(gameWorld)) {
|
||||
if (trigger.interactId == id) {
|
||||
return trigger;
|
||||
}
|
||||
@ -92,8 +99,8 @@ public class InteractTrigger extends Trigger {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean hasTriggers(GameWorld gworld) {
|
||||
return !triggers.isEmpty() && triggers.containsKey(gworld);
|
||||
public static boolean hasTriggers(GameWorld gameWorld) {
|
||||
return !triggers.isEmpty() && triggers.containsKey(gameWorld);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,6 +10,8 @@ public class MobTrigger extends Trigger {
|
||||
|
||||
private static Map<GameWorld, ArrayList<MobTrigger>> triggers = new HashMap<GameWorld, ArrayList<MobTrigger>>();
|
||||
|
||||
private TriggerType type = TriggerTypeDefault.MOB;
|
||||
|
||||
private String name;
|
||||
|
||||
public MobTrigger(String name) {
|
||||
@ -17,40 +19,45 @@ public class MobTrigger extends Trigger {
|
||||
}
|
||||
|
||||
public void onTrigger() {
|
||||
triggered = true;
|
||||
setTriggered(true);
|
||||
updateDSigns();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(GameWorld gworld) {
|
||||
if ( !hasTriggers(gworld)) {
|
||||
public void register(GameWorld gameWorld) {
|
||||
if ( !hasTriggers(gameWorld)) {
|
||||
ArrayList<MobTrigger> list = new ArrayList<MobTrigger>();
|
||||
list.add(this);
|
||||
triggers.put(gworld, list);
|
||||
triggers.put(gameWorld, list);
|
||||
|
||||
} else {
|
||||
triggers.get(gworld).add(this);
|
||||
triggers.get(gameWorld).add(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregister(GameWorld gworld) {
|
||||
if (hasTriggers(gworld)) {
|
||||
triggers.get(gworld).remove(this);
|
||||
public void unregister(GameWorld gameWorld) {
|
||||
if (hasTriggers(gameWorld)) {
|
||||
triggers.get(gameWorld).remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
public static MobTrigger getOrCreate(String name, GameWorld gworld) {
|
||||
MobTrigger trigger = get(name, gworld);
|
||||
@Override
|
||||
public TriggerType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public static MobTrigger getOrCreate(String name, GameWorld gameWorld) {
|
||||
MobTrigger trigger = get(name, gameWorld);
|
||||
if (trigger != null) {
|
||||
return trigger;
|
||||
}
|
||||
return new MobTrigger(name);
|
||||
}
|
||||
|
||||
public static MobTrigger get(String name, GameWorld gworld) {
|
||||
if (hasTriggers(gworld)) {
|
||||
for (MobTrigger trigger : triggers.get(gworld)) {
|
||||
public static MobTrigger get(String name, GameWorld gameWorld) {
|
||||
if (hasTriggers(gameWorld)) {
|
||||
for (MobTrigger trigger : triggers.get(gameWorld)) {
|
||||
if (trigger.name.equalsIgnoreCase(name)) {
|
||||
return trigger;
|
||||
}
|
||||
@ -59,8 +66,8 @@ public class MobTrigger extends Trigger {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean hasTriggers(GameWorld gworld) {
|
||||
return !triggers.isEmpty() && triggers.containsKey(gworld);
|
||||
public static boolean hasTriggers(GameWorld gameWorld) {
|
||||
return !triggers.isEmpty() && triggers.containsKey(gameWorld);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,6 +15,8 @@ public class RedstoneTrigger extends Trigger {
|
||||
|
||||
private static Map<GameWorld, ArrayList<RedstoneTrigger>> triggers = new HashMap<GameWorld, ArrayList<RedstoneTrigger>>();
|
||||
|
||||
private TriggerType type = TriggerTypeDefault.REDSTONE;
|
||||
|
||||
private Block rtBlock;
|
||||
|
||||
public RedstoneTrigger(Block block) {
|
||||
@ -23,40 +25,45 @@ public class RedstoneTrigger extends Trigger {
|
||||
|
||||
public void onTrigger() {
|
||||
if (rtBlock.isBlockPowered()) {
|
||||
if ( !triggered) {
|
||||
triggered = true;
|
||||
if ( !isTriggered()) {
|
||||
setTriggered(true);
|
||||
updateDSigns();
|
||||
}
|
||||
|
||||
} else {
|
||||
if (triggered) {
|
||||
triggered = false;
|
||||
if (isTriggered()) {
|
||||
setTriggered(false);
|
||||
updateDSigns();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(GameWorld gworld) {
|
||||
if ( !hasTriggers(gworld)) {
|
||||
public void register(GameWorld gameWorld) {
|
||||
if ( !hasTriggers(gameWorld)) {
|
||||
ArrayList<RedstoneTrigger> list = new ArrayList<RedstoneTrigger>();
|
||||
list.add(this);
|
||||
triggers.put(gworld, list);
|
||||
triggers.put(gameWorld, list);
|
||||
|
||||
} else {
|
||||
triggers.get(gworld).add(this);
|
||||
triggers.get(gameWorld).add(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregister(GameWorld gworld) {
|
||||
if (hasTriggers(gworld)) {
|
||||
triggers.get(gworld).remove(this);
|
||||
public void unregister(GameWorld gameWorld) {
|
||||
if (hasTriggers(gameWorld)) {
|
||||
triggers.get(gameWorld).remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TriggerType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static RedstoneTrigger getOrCreate(Sign sign, GameWorld gworld) {
|
||||
public static RedstoneTrigger getOrCreate(Sign sign, GameWorld gameWorld) {
|
||||
Block rtBlock = null;
|
||||
if (sign.getBlock().getType() == Material.WALL_SIGN) {
|
||||
switch (sign.getData().getData()) {
|
||||
@ -79,8 +86,8 @@ public class RedstoneTrigger extends Trigger {
|
||||
}
|
||||
|
||||
if (rtBlock != null) {
|
||||
if (hasTriggers(gworld)) {
|
||||
for (RedstoneTrigger trigger : getTriggers(gworld)) {
|
||||
if (hasTriggers(gameWorld)) {
|
||||
for (RedstoneTrigger trigger : getTriggers(gameWorld)) {
|
||||
if (trigger.rtBlock.equals(rtBlock)) {
|
||||
return trigger;
|
||||
}
|
||||
@ -91,24 +98,24 @@ public class RedstoneTrigger extends Trigger {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void updateAll(GameWorld gworld) {
|
||||
if (hasTriggers(gworld)) {
|
||||
for (RedstoneTrigger trigger : getTriggersArray(gworld)) {
|
||||
public static void updateAll(GameWorld gameWorld) {
|
||||
if (hasTriggers(gameWorld)) {
|
||||
for (RedstoneTrigger trigger : getTriggersArray(gameWorld)) {
|
||||
trigger.onTrigger();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasTriggers(GameWorld gworld) {
|
||||
return !triggers.isEmpty() && triggers.containsKey(gworld);
|
||||
public static boolean hasTriggers(GameWorld gameWorld) {
|
||||
return !triggers.isEmpty() && triggers.containsKey(gameWorld);
|
||||
}
|
||||
|
||||
public static ArrayList<RedstoneTrigger> getTriggers(GameWorld gworld) {
|
||||
return triggers.get(gworld);
|
||||
public static ArrayList<RedstoneTrigger> getTriggers(GameWorld gameWorld) {
|
||||
return triggers.get(gameWorld);
|
||||
}
|
||||
|
||||
public static RedstoneTrigger[] getTriggersArray(GameWorld gworld) {
|
||||
return getTriggers(gworld).toArray(new RedstoneTrigger[getTriggers(gworld).size()]);
|
||||
public static RedstoneTrigger[] getTriggersArray(GameWorld gameWorld) {
|
||||
return getTriggers(gameWorld).toArray(new RedstoneTrigger[getTriggers(gameWorld).size()]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,6 +10,8 @@ public class SignTrigger extends Trigger {
|
||||
|
||||
private static Map<GameWorld, ArrayList<SignTrigger>> triggers = new HashMap<GameWorld, ArrayList<SignTrigger>>();
|
||||
|
||||
private TriggerType type = TriggerTypeDefault.SIGN;
|
||||
|
||||
private int stId;
|
||||
|
||||
public SignTrigger(int stId) {
|
||||
@ -17,42 +19,47 @@ public class SignTrigger extends Trigger {
|
||||
}
|
||||
|
||||
public void onTrigger(boolean enable) {
|
||||
if (enable != triggered) {
|
||||
triggered = enable;
|
||||
if (enable != isTriggered()) {
|
||||
setTriggered(enable);
|
||||
updateDSigns();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(GameWorld gworld) {
|
||||
if ( !hasTriggers(gworld)) {
|
||||
public void register(GameWorld gameWorld) {
|
||||
if ( !hasTriggers(gameWorld)) {
|
||||
ArrayList<SignTrigger> list = new ArrayList<SignTrigger>();
|
||||
list.add(this);
|
||||
triggers.put(gworld, list);
|
||||
triggers.put(gameWorld, list);
|
||||
|
||||
} else {
|
||||
triggers.get(gworld).add(this);
|
||||
triggers.get(gameWorld).add(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregister(GameWorld gworld) {
|
||||
if (hasTriggers(gworld)) {
|
||||
triggers.get(gworld).remove(this);
|
||||
public void unregister(GameWorld gameWorld) {
|
||||
if (hasTriggers(gameWorld)) {
|
||||
triggers.get(gameWorld).remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
public static SignTrigger getOrCreate(int id, GameWorld gworld) {
|
||||
SignTrigger trigger = get(id, gworld);
|
||||
@Override
|
||||
public TriggerType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public static SignTrigger getOrCreate(int id, GameWorld gameWorld) {
|
||||
SignTrigger trigger = get(id, gameWorld);
|
||||
if (trigger != null) {
|
||||
return trigger;
|
||||
}
|
||||
return new SignTrigger(id);
|
||||
}
|
||||
|
||||
public static SignTrigger get(int id, GameWorld gworld) {
|
||||
if (hasTriggers(gworld)) {
|
||||
for (SignTrigger trigger : triggers.get(gworld)) {
|
||||
public static SignTrigger get(int id, GameWorld gameWorld) {
|
||||
if (hasTriggers(gameWorld)) {
|
||||
for (SignTrigger trigger : triggers.get(gameWorld)) {
|
||||
if (trigger.stId == id) {
|
||||
return trigger;
|
||||
}
|
||||
@ -61,8 +68,8 @@ public class SignTrigger extends Trigger {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean hasTriggers(GameWorld gworld) {
|
||||
return !triggers.isEmpty() && triggers.containsKey(gworld);
|
||||
public static boolean hasTriggers(GameWorld gameWorld) {
|
||||
return !triggers.isEmpty() && triggers.containsKey(gameWorld);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,79 +11,132 @@ import org.bukkit.entity.Player;
|
||||
|
||||
public abstract class Trigger {
|
||||
|
||||
protected Set<DSign> dsigns = new HashSet<DSign>();
|
||||
public boolean triggered = false;
|
||||
public Player player = null; // Holds Player for Player specific Triggers
|
||||
private boolean triggered;
|
||||
private Player player; // Holds Player for Player specific Triggers
|
||||
|
||||
public Trigger() {
|
||||
private Set<DSign> dSigns = new HashSet<DSign>();
|
||||
|
||||
/**
|
||||
* @return the triggered
|
||||
*/
|
||||
public boolean isTriggered() {
|
||||
return triggered;
|
||||
}
|
||||
|
||||
public abstract void register(GameWorld gworld);
|
||||
/**
|
||||
* @param triggered
|
||||
* the triggered to set
|
||||
*/
|
||||
public void setTriggered(boolean triggered) {
|
||||
this.triggered = triggered;
|
||||
}
|
||||
|
||||
public abstract void unregister(GameWorld gworld);
|
||||
/**
|
||||
* @return the player
|
||||
*/
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player
|
||||
* the player to set
|
||||
*/
|
||||
public void setPlayer(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dSigns
|
||||
*/
|
||||
public Set<DSign> getDSigns() {
|
||||
return dSigns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dSign
|
||||
* the dSign to add
|
||||
*/
|
||||
public void addDSign(DSign dSign) {
|
||||
dSigns.add(dSign);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dSign
|
||||
* the dSign to remove
|
||||
*/
|
||||
public void removeDSign(DSign dSign) {
|
||||
dSigns.remove(dSign);
|
||||
}
|
||||
|
||||
public void addListener(DSign dSign) {
|
||||
if (dSigns.isEmpty()) {
|
||||
register(dSign.getGameWorld());
|
||||
}
|
||||
dSigns.add(dSign);
|
||||
}
|
||||
|
||||
public void removeListener(DSign dSign) {
|
||||
dSigns.remove(dSign);
|
||||
if (dSigns.isEmpty()) {
|
||||
unregister(dSign.getGameWorld());
|
||||
}
|
||||
}
|
||||
|
||||
public void updateDSigns() {
|
||||
for (DSign dSign : dSigns.toArray(new DSign[dSigns.size()])) {
|
||||
dSign.onUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: Dynamic checks
|
||||
public static Trigger getOrCreate(String type, String value, DSign dsign) {
|
||||
Trigger trigger = null;
|
||||
|
||||
if (type.equalsIgnoreCase("R")) {
|
||||
|
||||
trigger = RedstoneTrigger.getOrCreate(dsign.getSign(), dsign.getGameWorld());
|
||||
return RedstoneTrigger.getOrCreate(dsign.getSign(), dsign.getGameWorld());
|
||||
|
||||
} else if (type.equalsIgnoreCase("D")) {
|
||||
|
||||
if (value != null) {
|
||||
trigger = new DistanceTrigger(IntegerUtil.parseInt(value), dsign.getSign().getLocation());
|
||||
return new DistanceTrigger(IntegerUtil.parseInt(value), dsign.getSign().getLocation());
|
||||
} else {
|
||||
trigger = new DistanceTrigger(dsign.getSign().getLocation());
|
||||
return new DistanceTrigger(dsign.getSign().getLocation());
|
||||
}
|
||||
|
||||
} else if (type.equalsIgnoreCase("T")) {
|
||||
|
||||
if (value != null) {
|
||||
trigger = SignTrigger.getOrCreate(IntegerUtil.parseInt(value), dsign.getGameWorld());
|
||||
return SignTrigger.getOrCreate(IntegerUtil.parseInt(value), dsign.getGameWorld());
|
||||
}
|
||||
|
||||
} else if (type.equalsIgnoreCase("I")) {
|
||||
|
||||
if (value != null) {
|
||||
trigger = InteractTrigger.getOrCreate(IntegerUtil.parseInt(value), dsign.getGameWorld());
|
||||
return InteractTrigger.getOrCreate(IntegerUtil.parseInt(value), dsign.getGameWorld());
|
||||
}
|
||||
|
||||
} else if (type.equalsIgnoreCase("M")) {
|
||||
|
||||
if (value != null) {
|
||||
trigger = MobTrigger.getOrCreate(value, dsign.getGameWorld());
|
||||
return MobTrigger.getOrCreate(value, dsign.getGameWorld());
|
||||
}
|
||||
|
||||
} else if (type.equalsIgnoreCase("U")) {
|
||||
|
||||
if (value != null) {
|
||||
trigger = UseItemTrigger.getOrCreate(value, dsign.getGameWorld());
|
||||
}
|
||||
|
||||
}
|
||||
return trigger;
|
||||
}
|
||||
|
||||
public void addListener(DSign dsign) {
|
||||
if (dsigns.isEmpty()) {
|
||||
register(dsign.getGameWorld());
|
||||
}
|
||||
dsigns.add(dsign);
|
||||
}
|
||||
|
||||
public void removeListener(DSign dsign) {
|
||||
dsigns.remove(dsign);
|
||||
if (dsigns.isEmpty()) {
|
||||
unregister(dsign.getGameWorld());
|
||||
return UseItemTrigger.getOrCreate(value, dsign.getGameWorld());
|
||||
}
|
||||
}
|
||||
|
||||
public void updateDSigns() {
|
||||
for (DSign dsign : dsigns.toArray(new DSign[dsigns.size()])) {
|
||||
dsign.onUpdate();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Abstract methods
|
||||
|
||||
public abstract void register(GameWorld gameWorld);
|
||||
|
||||
public abstract void unregister(GameWorld gameWorld);
|
||||
|
||||
public abstract TriggerType getType();
|
||||
|
||||
}
|
||||
|
15
src/io/github/dre2n/dungeonsxl/trigger/TriggerType.java
Normal file
15
src/io/github/dre2n/dungeonsxl/trigger/TriggerType.java
Normal file
@ -0,0 +1,15 @@
|
||||
package io.github.dre2n.dungeonsxl.trigger;
|
||||
|
||||
public interface TriggerType {
|
||||
|
||||
/**
|
||||
* @return the identifier
|
||||
*/
|
||||
public String getIdentifier();
|
||||
|
||||
/**
|
||||
* @return the handler
|
||||
*/
|
||||
public Class<? extends Trigger> getHandler();
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package io.github.dre2n.dungeonsxl.trigger;
|
||||
|
||||
public enum TriggerTypeDefault implements TriggerType {
|
||||
|
||||
DISTANCE("D", DistanceTrigger.class),
|
||||
INTERACT("I", InteractTrigger.class),
|
||||
MOB("M", MobTrigger.class),
|
||||
REDSTONE("R", RedstoneTrigger.class),
|
||||
SIGN("T", SignTrigger.class),
|
||||
USE_ITEM("U", UseItemTrigger.class);
|
||||
|
||||
private String identifier;
|
||||
private Class<? extends Trigger> handler;
|
||||
|
||||
TriggerTypeDefault(String identifier, Class<? extends Trigger> handler) {
|
||||
this.identifier = identifier;
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends Trigger> getHandler() {
|
||||
return handler;
|
||||
}
|
||||
|
||||
}
|
39
src/io/github/dre2n/dungeonsxl/trigger/Triggers.java
Normal file
39
src/io/github/dre2n/dungeonsxl/trigger/Triggers.java
Normal file
@ -0,0 +1,39 @@
|
||||
package io.github.dre2n.dungeonsxl.trigger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Triggers {
|
||||
|
||||
private List<TriggerType> triggers = new ArrayList<TriggerType>();
|
||||
|
||||
public Triggers() {
|
||||
for (TriggerType type : TriggerTypeDefault.values()) {
|
||||
triggers.add(type);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the triggers
|
||||
*/
|
||||
public List<TriggerType> getTriggers() {
|
||||
return triggers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param trigger
|
||||
* the triggers to add
|
||||
*/
|
||||
public void addTrigger(TriggerType trigger) {
|
||||
triggers.add(trigger);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param trigger
|
||||
* the trigger to remove
|
||||
*/
|
||||
public void removeTrigger(TriggerType trigger) {
|
||||
triggers.remove(trigger);
|
||||
}
|
||||
|
||||
}
|
@ -13,6 +13,8 @@ public class UseItemTrigger extends Trigger {
|
||||
|
||||
private static Map<GameWorld, ArrayList<UseItemTrigger>> triggers = new HashMap<GameWorld, ArrayList<UseItemTrigger>>();
|
||||
|
||||
private TriggerType type = TriggerTypeDefault.USE_ITEM;
|
||||
|
||||
private String name;
|
||||
private String matchedName;
|
||||
|
||||
@ -25,40 +27,45 @@ public class UseItemTrigger extends Trigger {
|
||||
}
|
||||
|
||||
public void onTrigger(Player player) {
|
||||
triggered = true;
|
||||
this.player = player;
|
||||
setTriggered(true);
|
||||
this.setPlayer(player);
|
||||
updateDSigns();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(GameWorld gworld) {
|
||||
if ( !hasTriggers(gworld)) {
|
||||
public void register(GameWorld gameWorld) {
|
||||
if ( !hasTriggers(gameWorld)) {
|
||||
ArrayList<UseItemTrigger> list = new ArrayList<UseItemTrigger>();
|
||||
list.add(this);
|
||||
triggers.put(gworld, list);
|
||||
triggers.put(gameWorld, list);
|
||||
} else {
|
||||
triggers.get(gworld).add(this);
|
||||
triggers.get(gameWorld).add(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregister(GameWorld gworld) {
|
||||
if (hasTriggers(gworld)) {
|
||||
triggers.get(gworld).remove(this);
|
||||
public void unregister(GameWorld gameWorld) {
|
||||
if (hasTriggers(gameWorld)) {
|
||||
triggers.get(gameWorld).remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
public static UseItemTrigger getOrCreate(String name, GameWorld gworld) {
|
||||
UseItemTrigger trigger = get(name, gworld);
|
||||
@Override
|
||||
public TriggerType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public static UseItemTrigger getOrCreate(String name, GameWorld gameWorld) {
|
||||
UseItemTrigger trigger = get(name, gameWorld);
|
||||
if (trigger != null) {
|
||||
return trigger;
|
||||
}
|
||||
return new UseItemTrigger(name);
|
||||
}
|
||||
|
||||
public static UseItemTrigger get(String name, GameWorld gworld) {
|
||||
if (hasTriggers(gworld)) {
|
||||
for (UseItemTrigger trigger : triggers.get(gworld)) {
|
||||
public static UseItemTrigger get(String name, GameWorld gameWorld) {
|
||||
if (hasTriggers(gameWorld)) {
|
||||
for (UseItemTrigger trigger : triggers.get(gameWorld)) {
|
||||
if (trigger.name.equalsIgnoreCase(name)) {
|
||||
return trigger;
|
||||
} else {
|
||||
@ -73,8 +80,8 @@ public class UseItemTrigger extends Trigger {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean hasTriggers(GameWorld gworld) {
|
||||
return !triggers.isEmpty() && triggers.containsKey(gworld);
|
||||
public static boolean hasTriggers(GameWorld gameWorld) {
|
||||
return !triggers.isEmpty() && triggers.containsKey(gameWorld);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user