mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-05 02:09:48 +01:00
Added open door sign
This commit is contained in:
parent
1ddf0df88a
commit
c7695f815e
@ -39,6 +39,7 @@ import io.github.dre2n.dungeonsxl.player.DPlayers;
|
||||
import io.github.dre2n.dungeonsxl.player.DSavePlayer;
|
||||
import io.github.dre2n.dungeonsxl.reward.DLootInventory;
|
||||
import io.github.dre2n.dungeonsxl.reward.RewardChest;
|
||||
import io.github.dre2n.dungeonsxl.sign.OpenDoorSign;
|
||||
import io.github.dre2n.dungeonsxl.task.RespawnTask;
|
||||
import io.github.dre2n.dungeonsxl.trigger.InteractTrigger;
|
||||
import io.github.dre2n.dungeonsxl.trigger.UseItemTrigger;
|
||||
@ -312,6 +313,9 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else if (OpenDoorSign.isProtected(clickedBlock)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -41,6 +41,7 @@ public enum DSignTypeDefault implements DSignType {
|
||||
MESSAGE("MSG", "msg", false, MessageSign.class),
|
||||
@Deprecated
|
||||
MYTHIC_MOBS("MythicMobs", "mob", false, ExternalMobSign.class),
|
||||
OPEN_DOOR("Door", "door", false, OpenDoorSign.class),
|
||||
PLACE("Place", "place", false, PlaceSign.class),
|
||||
READY("Ready", "ready", true, ReadySign.class),
|
||||
REDSTONE("Redstone", "redstone", false, RedstoneSign.class),
|
||||
|
107
src/main/java/io/github/dre2n/dungeonsxl/sign/OpenDoorSign.java
Normal file
107
src/main/java/io/github/dre2n/dungeonsxl/sign/OpenDoorSign.java
Normal file
@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2016 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package io.github.dre2n.dungeonsxl.sign;
|
||||
|
||||
import io.github.dre2n.commons.util.BlockUtil;
|
||||
import io.github.dre2n.dungeonsxl.world.GameWorld;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.material.Openable;
|
||||
|
||||
/**
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class OpenDoorSign extends DSign {
|
||||
|
||||
private DSignType type = DSignTypeDefault.OPEN_DOOR;
|
||||
|
||||
private Openable block;
|
||||
|
||||
public OpenDoorSign(Sign sign, String[] lines, GameWorld gameWorld) {
|
||||
super(sign, lines, gameWorld);
|
||||
}
|
||||
|
||||
/* Getters and setters */
|
||||
/**
|
||||
* @return the door / fence gate / ... to open;
|
||||
*/
|
||||
public Openable getBlock() {
|
||||
return block;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param block
|
||||
* the door / fence gate / ... to open
|
||||
*/
|
||||
public void setBlock(Openable block) {
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DSignType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/* Actions */
|
||||
@Override
|
||||
public boolean check() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInit() {
|
||||
Block block = BlockUtil.getAttachedBlock(getSign().getBlock());
|
||||
if (block instanceof Openable) {
|
||||
this.block = (Openable) block;
|
||||
}
|
||||
|
||||
getSign().setType(Material.AIR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTrigger() {
|
||||
block.setOpen(true);
|
||||
}
|
||||
|
||||
/* Statics */
|
||||
/**
|
||||
* @param block
|
||||
* the block to check
|
||||
* @return
|
||||
* true if the block is openable only with a sign
|
||||
*/
|
||||
public static boolean isProtected(Block block) {
|
||||
if (!(block instanceof Openable)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user