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