mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-05 02:09:48 +01:00
Use InteractTrigger for Ready, Leave, End
This commit is contained in:
parent
565413c555
commit
13bff0801e
@ -41,9 +41,6 @@ public class GameWorld {
|
||||
public String dungeonname;
|
||||
public Location locLobby;
|
||||
public Location locStart;
|
||||
public CopyOnWriteArrayList<Block> blocksEnd = new CopyOnWriteArrayList<Block>();
|
||||
public CopyOnWriteArrayList<Block> blocksReady = new CopyOnWriteArrayList<Block>();
|
||||
public CopyOnWriteArrayList<Block> blocksLeave = new CopyOnWriteArrayList<Block>();
|
||||
public boolean isPlaying = false;
|
||||
public int id;
|
||||
public CopyOnWriteArrayList<Material> secureObjects = new CopyOnWriteArrayList<Material>();
|
||||
|
@ -134,44 +134,7 @@ public class PlayerListener implements Listener {
|
||||
trigger.onTrigger(player);
|
||||
}
|
||||
|
||||
// Ready Sign
|
||||
for (Block blockReady : gworld.blocksReady) {
|
||||
if (blockReady.getLocation().distance(clickedBlock.getLocation()) < 1) {
|
||||
if (!dplayer.isReady) {
|
||||
if (gworld.signClass.isEmpty() || dplayer.dclass != null) {
|
||||
dplayer.ready();
|
||||
p.msg(player, p.language.get("Player_Ready"));
|
||||
return;
|
||||
} else {
|
||||
p.msg(player, p.language.get("Error_Ready"));
|
||||
}
|
||||
} else {
|
||||
dplayer.ready();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// End Sign
|
||||
for (Block blockEnd : gworld.blocksEnd) {
|
||||
if (blockEnd.getLocation().distance(clickedBlock.getLocation()) < 1) {
|
||||
if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
|
||||
dplayer.finish();
|
||||
return;
|
||||
} else {
|
||||
p.msg(player, p.language.get("Error_Leftklick"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Leave Sign
|
||||
for (Block blockLeave : gworld.blocksLeave) {
|
||||
if (blockLeave.getLocation().distance(clickedBlock.getLocation()) < 1) {
|
||||
dplayer.leave();
|
||||
}
|
||||
}
|
||||
|
||||
// Class Signs
|
||||
|
||||
for (Sign classSign : gworld.signClass) {
|
||||
if (classSign != null) {
|
||||
if (classSign.getLocation().distance(clickedBlock.getLocation()) < 1) {
|
||||
|
@ -2,7 +2,11 @@ package com.dre.dungeonsxl.signs;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.dre.dungeonsxl.DPlayer;
|
||||
import com.dre.dungeonsxl.game.GameWorld;
|
||||
import com.dre.dungeonsxl.trigger.InteractTrigger;
|
||||
|
||||
public class SIGNEnd extends DSign {
|
||||
|
||||
@ -23,12 +27,38 @@ public class SIGNEnd extends DSign {
|
||||
|
||||
@Override
|
||||
public void onInit() {
|
||||
gworld.blocksEnd.add(sign.getBlock());
|
||||
sign.setLine(0, ChatColor.DARK_BLUE + "############");
|
||||
sign.setLine(1, ChatColor.DARK_GREEN + "End");
|
||||
sign.setLine(2, "");
|
||||
sign.setLine(3, ChatColor.DARK_BLUE + "############");
|
||||
sign.update();
|
||||
if (triggers.isEmpty()) {
|
||||
InteractTrigger trigger = InteractTrigger.getOrCreate(0, sign.getBlock(), gworld);
|
||||
if (trigger != null) {
|
||||
trigger.addListener(this);
|
||||
this.triggers.add(trigger);
|
||||
}
|
||||
sign.setLine(0, ChatColor.DARK_BLUE + "############");
|
||||
sign.setLine(1, ChatColor.DARK_GREEN + "End");
|
||||
sign.setLine(2, "");
|
||||
sign.setLine(3, ChatColor.DARK_BLUE + "############");
|
||||
sign.update();
|
||||
} else {
|
||||
sign.getBlock().setTypeId(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPlayerTrigger(Player player) {
|
||||
DPlayer dplayer = DPlayer.get(player);
|
||||
if (dplayer != null) {
|
||||
if (!dplayer.isFinished) {
|
||||
dplayer.finish();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTrigger() {
|
||||
for (DPlayer dplayer : DPlayer.players) {
|
||||
dplayer.finish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -15,7 +15,7 @@ import com.dre.dungeonsxl.trigger.InteractTrigger;
|
||||
public class SIGNInteract extends DSign {
|
||||
public static String name = "Interact";
|
||||
public String buildPermissions = "dxl.sign.trigger";
|
||||
public boolean onDungeonInit = false;
|
||||
public boolean onDungeonInit = true;
|
||||
|
||||
public SIGNInteract(Sign sign, GameWorld gworld) {
|
||||
super(sign, gworld);
|
||||
@ -47,7 +47,7 @@ public class SIGNInteract extends DSign {
|
||||
}
|
||||
} else {
|
||||
id = p.parseInt(sign.getLine(1));
|
||||
if (used.contains(id)) {
|
||||
if (id == 0 || used.contains(id)) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
|
@ -2,7 +2,11 @@ package com.dre.dungeonsxl.signs;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.dre.dungeonsxl.DPlayer;
|
||||
import com.dre.dungeonsxl.game.GameWorld;
|
||||
import com.dre.dungeonsxl.trigger.InteractTrigger;
|
||||
|
||||
public class SIGNLeave extends DSign {
|
||||
|
||||
@ -23,12 +27,36 @@ public class SIGNLeave extends DSign {
|
||||
|
||||
@Override
|
||||
public void onInit() {
|
||||
gworld.blocksLeave.add(sign.getBlock());
|
||||
sign.setLine(0, ChatColor.BLUE + "############");
|
||||
sign.setLine(1, ChatColor.DARK_GREEN + "Leave");
|
||||
sign.setLine(2, "");
|
||||
sign.setLine(3, ChatColor.BLUE + "############");
|
||||
sign.update();
|
||||
if (triggers.isEmpty()) {
|
||||
InteractTrigger trigger = InteractTrigger.getOrCreate(0, sign.getBlock(), gworld);
|
||||
if (trigger != null) {
|
||||
trigger.addListener(this);
|
||||
this.triggers.add(trigger);
|
||||
}
|
||||
sign.setLine(0, ChatColor.DARK_BLUE + "############");
|
||||
sign.setLine(1, ChatColor.DARK_GREEN + "Leave");
|
||||
sign.setLine(2, "");
|
||||
sign.setLine(3, ChatColor.DARK_BLUE + "############");
|
||||
sign.update();
|
||||
} else {
|
||||
sign.getBlock().setTypeId(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPlayerTrigger(Player player) {
|
||||
DPlayer dplayer = DPlayer.get(player);
|
||||
if (dplayer != null) {
|
||||
dplayer.leave();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTrigger() {
|
||||
for (DPlayer dplayer : DPlayer.players) {
|
||||
dplayer.leave();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2,7 +2,12 @@ package com.dre.dungeonsxl.signs;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.dre.dungeonsxl.DPlayer;
|
||||
import com.dre.dungeonsxl.game.GameWorld;
|
||||
import com.dre.dungeonsxl.trigger.InteractTrigger;
|
||||
import com.dre.dungeonsxl.P;
|
||||
|
||||
public class SIGNReady extends DSign {
|
||||
|
||||
@ -23,12 +28,47 @@ public class SIGNReady extends DSign {
|
||||
|
||||
@Override
|
||||
public void onInit() {
|
||||
gworld.blocksReady.add(sign.getBlock());
|
||||
sign.setLine(0, ChatColor.BLUE + "############");
|
||||
sign.setLine(1, ChatColor.DARK_GREEN + "Ready");
|
||||
sign.setLine(2, "");
|
||||
sign.setLine(3, ChatColor.BLUE + "############");
|
||||
sign.update();
|
||||
if (triggers.isEmpty()) {
|
||||
InteractTrigger trigger = InteractTrigger.getOrCreate(0, sign.getBlock(), gworld);
|
||||
if (trigger != null) {
|
||||
trigger.addListener(this);
|
||||
this.triggers.add(trigger);
|
||||
}
|
||||
sign.setLine(0, ChatColor.DARK_BLUE + "############");
|
||||
sign.setLine(1, ChatColor.DARK_GREEN + "Ready");
|
||||
sign.setLine(2, "");
|
||||
sign.setLine(3, ChatColor.DARK_BLUE + "############");
|
||||
sign.update();
|
||||
} else {
|
||||
sign.getBlock().setTypeId(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPlayerTrigger(Player player) {
|
||||
ready(DPlayer.get(player));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTrigger() {
|
||||
for (DPlayer dplayer : DPlayer.players) {
|
||||
ready(dplayer);
|
||||
}
|
||||
}
|
||||
|
||||
private void ready(DPlayer dplayer) {
|
||||
if (dplayer != null) {
|
||||
if (!dplayer.isReady) {
|
||||
if (gworld.signClass.isEmpty() || dplayer.dclass != null) {
|
||||
dplayer.ready();
|
||||
P.p.msg(dplayer.player, p.language.get("Player_Ready"));
|
||||
return;
|
||||
} else {
|
||||
P.p.msg(dplayer.player, p.language.get("Error_Ready"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -13,7 +13,7 @@ import com.dre.dungeonsxl.trigger.SignTrigger;
|
||||
public class SIGNTrigger extends DSign {
|
||||
public static String name = "Trigger";
|
||||
public String buildPermissions = "dxl.sign.trigger";
|
||||
public boolean onDungeonInit = false;
|
||||
public boolean onDungeonInit = true;
|
||||
|
||||
// Variables
|
||||
private int triggerId;
|
||||
|
@ -44,6 +44,9 @@ public class InteractTrigger extends Trigger {
|
||||
}
|
||||
|
||||
public static InteractTrigger getOrCreate(int id, GameWorld gworld) {
|
||||
if (id == 0) {
|
||||
return null;
|
||||
}
|
||||
InteractTrigger trigger = get(id, gworld);
|
||||
if (trigger != null) {
|
||||
return trigger;
|
||||
|
Loading…
Reference in New Issue
Block a user