mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2025-02-17 21:02:12 +01:00
Added Redstone and Block sign
This commit is contained in:
parent
6968f314a9
commit
f76cd8c771
@ -51,6 +51,7 @@ public class GameWorld {
|
||||
public CopyOnWriteArrayList<DMob> dmobs = new CopyOnWriteArrayList<DMob>();
|
||||
public CopyOnWriteArrayList<GameChest> gchests = new CopyOnWriteArrayList<GameChest>();
|
||||
public CopyOnWriteArrayList<DSign> dSigns = new CopyOnWriteArrayList<DSign>();
|
||||
public CopyOnWriteArrayList<Block> untouchable = new CopyOnWriteArrayList<Block>();
|
||||
public DConfig config;
|
||||
|
||||
|
||||
@ -99,6 +100,9 @@ public class GameWorld {
|
||||
dSign.onUpdate(0,false);
|
||||
}
|
||||
}
|
||||
if(!dSign.isRedstoneTrigger() && !dSign.isDistanceTrigger() && !dSign.isSignTrigger()){
|
||||
dSign.onTrigger();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -122,11 +126,7 @@ public class GameWorld {
|
||||
|
||||
public static void deleteAll(){
|
||||
for(GameWorld gworld:gworlds){
|
||||
gworlds.remove(gworld);
|
||||
|
||||
p.getServer().unloadWorld(gworld.world,true);
|
||||
File dir = new File("DXL_Game_"+gworld.id);
|
||||
p.removeDirectory(dir);
|
||||
gworld.delete();
|
||||
}
|
||||
}
|
||||
|
||||
@ -171,6 +171,11 @@ public class GameWorld {
|
||||
public void delete(){
|
||||
gworlds.remove(this);
|
||||
|
||||
for(DSign sign:dSigns){
|
||||
if(sign != null){
|
||||
sign.killTask();
|
||||
}
|
||||
}
|
||||
p.getServer().unloadWorld(this.world,true);
|
||||
File dir = new File("DXL_Game_"+this.id);
|
||||
p.removeDirectory(dir);
|
||||
|
@ -25,6 +25,7 @@ import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import com.dre.dungeonsxl.DGSign;
|
||||
import com.dre.dungeonsxl.signs.DSign;
|
||||
import com.dre.dungeonsxl.DGroup;
|
||||
import com.dre.dungeonsxl.DLootInventory;
|
||||
import com.dre.dungeonsxl.DPlayer;
|
||||
@ -69,6 +70,22 @@ public class PlayerListener implements Listener{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Block invisible Redstone signs
|
||||
if(GameWorld.get(player.getWorld())!=null){
|
||||
GameWorld gworld = GameWorld.get(player.getWorld());
|
||||
if(!gworld.untouchable.isEmpty()){
|
||||
if(event.getAction()==Action.RIGHT_CLICK_BLOCK){
|
||||
if(gworld.untouchable.contains(clickedBlock)){
|
||||
for(DSign sign:gworld.dSigns){
|
||||
if(sign!=null){
|
||||
sign.onDiscover();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -91,9 +91,18 @@ public abstract class DSign {
|
||||
|
||||
}
|
||||
|
||||
public void onDiscover(){
|
||||
|
||||
}
|
||||
|
||||
public void onUpdate(int type,boolean powered){
|
||||
|
||||
}
|
||||
|
||||
public void killTask(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static DSign create(Sign sign, GameWorld gworld){
|
||||
String[] lines = sign.getLines();
|
||||
@ -127,6 +136,10 @@ public abstract class DSign {
|
||||
dSign = new SIGNStart(sign, gworld);
|
||||
} else if (lines[0].equalsIgnoreCase("["+SIGNTrigger.name+"]")) {
|
||||
dSign = new SIGNTrigger(sign, gworld);
|
||||
} else if (lines[0].equalsIgnoreCase("["+SIGNRedstone.name+"]")) {
|
||||
dSign = new SIGNRedstone(sign, gworld);
|
||||
} else if (lines[0].equalsIgnoreCase("["+SIGNBlock.name+"]")) {
|
||||
dSign = new SIGNBlock(sign, gworld);
|
||||
}
|
||||
|
||||
if (dSign != null && gworld != null) {
|
||||
|
77
src/com/dre/dungeonsxl/signs/SIGNBlock.java
Normal file
77
src/com/dre/dungeonsxl/signs/SIGNBlock.java
Normal file
@ -0,0 +1,77 @@
|
||||
package com.dre.dungeonsxl.signs;
|
||||
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import com.dre.dungeonsxl.game.GameWorld;
|
||||
|
||||
public class SIGNBlock extends DSign{
|
||||
|
||||
public static String name = "Block";
|
||||
public String buildPermissions = "dxl.sign.block";
|
||||
public boolean onDungeonInit = false;
|
||||
|
||||
//Variables
|
||||
private boolean initialized;
|
||||
private boolean active;
|
||||
private byte side;
|
||||
private int offBlock = 0;
|
||||
private int onBlock = 0;
|
||||
|
||||
|
||||
public SIGNBlock(Sign sign, GameWorld gworld) {
|
||||
super(sign, gworld);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean check() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInit() {
|
||||
String lines[] = sign.getLines();
|
||||
offBlock = p.parseInt(lines[1]);
|
||||
onBlock = p.parseInt(lines[2]);
|
||||
sign.getBlock().setTypeId(offBlock);
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate(int type,boolean powered) {
|
||||
if(initialized){
|
||||
setPowered(type,powered);
|
||||
if(isPowered()){
|
||||
if(!isDistanceTrigger()){
|
||||
onTrigger();
|
||||
}
|
||||
} else {
|
||||
active = false;
|
||||
sign.getBlock().setTypeId(offBlock);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onTrigger() {
|
||||
if(initialized){
|
||||
if(!active){
|
||||
sign.getBlock().setTypeId(onBlock);
|
||||
active = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissions() {
|
||||
return buildPermissions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnDungeonInit() {
|
||||
return onDungeonInit;
|
||||
}
|
||||
}
|
143
src/com/dre/dungeonsxl/signs/SIGNRedstone.java
Normal file
143
src/com/dre/dungeonsxl/signs/SIGNRedstone.java
Normal file
@ -0,0 +1,143 @@
|
||||
package com.dre.dungeonsxl.signs;
|
||||
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import com.dre.dungeonsxl.P;
|
||||
import com.dre.dungeonsxl.DPlayer;
|
||||
import com.dre.dungeonsxl.game.GameWorld;
|
||||
|
||||
public class SIGNRedstone extends DSign{
|
||||
|
||||
public static String name = "Redstone";
|
||||
public String buildPermissions = "dxl.sign.redstone";
|
||||
public boolean onDungeonInit = false;
|
||||
|
||||
//Variables
|
||||
private boolean initialized;
|
||||
private boolean active;
|
||||
private byte side;
|
||||
private BukkitTask task = null;
|
||||
|
||||
public SIGNRedstone(Sign sign, GameWorld gworld) {
|
||||
super(sign, gworld);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean check() {
|
||||
if(isRedstoneTrigger()){
|
||||
if(sign.getBlock().getType() != Material.WALL_SIGN){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInit() {
|
||||
if(sign.getBlock().getType() == Material.WALL_SIGN){
|
||||
switch(sign.getData().getData()){
|
||||
case 5:
|
||||
side = 0x1; //west
|
||||
break;
|
||||
case 4:
|
||||
side = 0x2; //east
|
||||
break;
|
||||
case 3:
|
||||
side = 0x3; //north
|
||||
break;
|
||||
case 2:
|
||||
side = 0x4; //south
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
side = 0x5; //up
|
||||
}
|
||||
gworld.untouchable.add(sign.getBlock().getRelative(BlockFace.DOWN));
|
||||
gworld.untouchable.add(sign.getBlock().getRelative(BlockFace.UP));
|
||||
gworld.untouchable.add(sign.getBlock().getRelative(BlockFace.WEST));
|
||||
gworld.untouchable.add(sign.getBlock().getRelative(BlockFace.EAST));
|
||||
gworld.untouchable.add(sign.getBlock().getRelative(BlockFace.NORTH));
|
||||
gworld.untouchable.add(sign.getBlock().getRelative(BlockFace.SOUTH));
|
||||
sign.getBlock().setTypeId(0);
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate(int type,boolean powered) {
|
||||
if(initialized){
|
||||
setPowered(type,powered);
|
||||
if(isPowered()){
|
||||
if(!isDistanceTrigger()){
|
||||
onTrigger();
|
||||
}
|
||||
} else {
|
||||
killTask();
|
||||
active = false;
|
||||
sign.getBlock().setTypeId(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDiscover(){
|
||||
if(initialized && active){
|
||||
P.p.getServer().getScheduler().scheduleSyncDelayedTask(p, new DiscoveryTask(), 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void killTask(){
|
||||
if(initialized && active){
|
||||
if(task != null){
|
||||
task.cancel();
|
||||
task = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onTrigger() {
|
||||
if(initialized){
|
||||
if(!active){
|
||||
sign.getBlock().setData(side);
|
||||
sign.getBlock().setTypeId(76);
|
||||
active = true;
|
||||
if(task == null){
|
||||
task = P.p.getServer().getScheduler().runTaskTimer(p, new DiscoveryTask(), 1, 60);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissions() {
|
||||
return buildPermissions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnDungeonInit() {
|
||||
return onDungeonInit;
|
||||
}
|
||||
|
||||
public class DiscoveryTask implements Runnable {
|
||||
|
||||
public DiscoveryTask() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if(initialized && active){
|
||||
for(DPlayer dplayer:DPlayer.players){
|
||||
dplayer.player.sendBlockChange(sign.getBlock().getLocation(),0,(byte)0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user