Added /dxl break command

+ Some minor improvements
This commit is contained in:
Daniel Saukel 2015-12-29 16:13:06 +01:00
parent 1dd8b66024
commit c38d0dfc4a
16 changed files with 120 additions and 29 deletions

View File

@ -52,6 +52,7 @@ public class DungeonsXL extends JavaPlugin {
private DSigns dSigns;
private Dungeons dungeons;
private CopyOnWriteArrayList<Player> inBreakMode = new CopyOnWriteArrayList<Player>();
private CopyOnWriteArrayList<Player> chatSpyers = new CopyOnWriteArrayList<Player>();
private CopyOnWriteArrayList<DLootInventory> dLootInventories = new CopyOnWriteArrayList<DLootInventory>();
private CopyOnWriteArrayList<EditWorld> editWorlds = new CopyOnWriteArrayList<EditWorld>();
@ -404,6 +405,13 @@ public class DungeonsXL extends JavaPlugin {
dungeons = new Dungeons();
}
/**
* @return the inBreakMode
*/
public CopyOnWriteArrayList<Player> getInBreakMode() {
return inBreakMode;
}
/**
* @return the chatSpyers
*/

View File

@ -0,0 +1,33 @@
package io.github.dre2n.dungeonsxl.command;
import io.github.dre2n.dungeonsxl.file.DMessages.Messages;
import io.github.dre2n.dungeonsxl.util.MessageUtil;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class BreakCommand extends DCommand {
public BreakCommand() {
setCommand("break");
setMinArgs(0);
setMaxArgs(0);
setHelp(dMessages.getMessage(Messages.HELP_CMD_BREAK));
setPermission("dxl.break");
setPlayerCommand(true);
}
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
if ( !plugin.getInBreakMode().contains(player)) {
plugin.getInBreakMode().add(player);
MessageUtil.sendMessage(sender, dMessages.getMessage(Messages.CMD_BREAK_BREAK_MODE));
} else {
plugin.getInBreakMode().remove(player);
MessageUtil.sendMessage(sender, dMessages.getMessage(Messages.CMD_BREAK_PROTECTED_MODE));
}
}
}

View File

@ -11,13 +11,14 @@ public class DCommands {
public DCommands() {
// Add Commands
dCommands.add(new HelpCommand());
dCommands.add(new LeaveCommand());
dCommands.add(new BreakCommand());
dCommands.add(new ChatCommand());
dCommands.add(new ChatSpyCommand());
dCommands.add(new CreateCommand());
dCommands.add(new EditCommand());
dCommands.add(new EscapeCommand());
dCommands.add(new InviteCommand());
dCommands.add(new LeaveCommand());
dCommands.add(new ListCommand());
dCommands.add(new LivesCommand());
dCommands.add(new MainCommand());

View File

@ -32,7 +32,7 @@ public class EscapeCommand extends DCommand {
dPlayer.escape();
EditWorld editWorld = EditWorld.get(dPlayer.getWorld());
EditWorld editWorld = EditWorld.getByWorld(dPlayer.getWorld());
if (editWorld == null) {
return;
}

View File

@ -26,7 +26,7 @@ public class MsgCommand extends DCommand {
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
EditWorld editWorld = EditWorld.get(player.getWorld());
EditWorld editWorld = EditWorld.getByWorld(player.getWorld());
if (editWorld == null) {
MessageUtil.sendMessage(player, dMessages.getMessage(Messages.ERROR_NOT_IN_DUNGEON));

View File

@ -21,7 +21,7 @@ public class SaveCommand extends DCommand {
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
EditWorld editWorld = EditWorld.get(player.getWorld());
EditWorld editWorld = EditWorld.getByWorld(player.getWorld());
if (editWorld != null) {
editWorld.save();
MessageUtil.sendMessage(player, dMessages.getMessage(Messages.CMD_SAVE_SUCCESS));

View File

@ -125,7 +125,7 @@ public class EditWorld {
}
// Static
public static EditWorld get(World world) {
public static EditWorld getByWorld(World world) {
for (EditWorld editWorld : plugin.getEditWorlds()) {
if (editWorld.world.equals(world)) {
return editWorld;
@ -135,7 +135,7 @@ public class EditWorld {
return null;
}
public static EditWorld get(String name) {
public static EditWorld getByName(String name) {
for (EditWorld editWorld : plugin.getEditWorlds()) {
if (editWorld.mapName.equalsIgnoreCase(name)) {
return editWorld;
@ -245,7 +245,7 @@ public class EditWorld {
config.save();
// Kick Player
EditWorld editWorld = EditWorld.get(editWorldName);
EditWorld editWorld = EditWorld.getByName(editWorldName);
if (editWorld != null) {
DPlayer player = DPlayer.getByName(name);

View File

@ -40,6 +40,8 @@ public class DMessages {
PLAYER_TREASURES("Player_Treasures", "&1Treasures"),
PLAYER_WAIT_FOR_OTHER_PLAYERS("Player_WaitForOtherPlayers", "&6Waiting for teammates..."),
CMD_BREAK_PROTECTED_MODE("Cmd_Break_ProtectedMode", "&6You may not break blocks protected by DungeonsXL anymore."),
CMD_BREAK_BREAK_MODE("Cmd_Break_BreakMode", "&6You may break a block protected by DungeonsXL."),
CMD_CHAT_DUNGEON_CHAT("Cmd_Chat_DungeonChat", "&6You have entered the Dungeon-chat"),
CMD_CHAT_NORMAL_CHAT("Cmd_Chat_NormalChat", "&6You are now in the public chat"),
CMD_CHATSPY_STOPPED("Cmd_Chatspy_Stopped", "&6You stopped spying the DXL-chat!"),

View File

@ -112,6 +112,10 @@ public class GroupSign {
this.multiFloor = multiFloor;
}
public void delete() {
plugin.getGroupSigns().remove(this);
}
public void update() {
int i = 0;
for (DGroup dGroup : dGroups) {

View File

@ -35,6 +35,10 @@ public class LeaveSign {
sign.update();
}
public void delete() {
plugin.getLeaveSigns().remove(this);
}
public static boolean playerInteract(Block block, Player player) {
LeaveSign leaveSign = getSign(block);

View File

@ -47,37 +47,72 @@ public class BlockListener implements Listener {
@EventHandler(priority = EventPriority.HIGH)
public void onBlockBreak(BlockBreakEvent event) {
Block block = event.getBlock();
Player player = event.getPlayer();
// Deny DPortal destroying
if (block.getType() == Material.PORTAL) {
if (DPortal.getByBlock(event.getBlock()) != null) {
DPortal dPortal = DPortal.getByBlock(event.getBlock());
if (dPortal != null) {
if (plugin.getInBreakMode().contains(player)) {
dPortal.delete();
MessageUtil.sendMessage(player, plugin.getDMessages().getMessage(Messages.PLAYER_PROTECTED_BLOCK_DELETED));
MessageUtil.sendMessage(player, plugin.getDMessages().getMessage(Messages.CMD_BREAK_PROTECTED_MODE));
plugin.getInBreakMode().remove(player);
} else {
event.setCancelled(true);
}
return;
}
}
// Delete GroupSign
GroupSign groupSign = GroupSign.getSign(block);
if (groupSign != null) {
if (plugin.getInBreakMode().contains(player)) {
groupSign.delete();
MessageUtil.sendMessage(player, plugin.getDMessages().getMessage(Messages.PLAYER_PROTECTED_BLOCK_DELETED));
MessageUtil.sendMessage(player, plugin.getDMessages().getMessage(Messages.CMD_BREAK_PROTECTED_MODE));
plugin.getInBreakMode().remove(player);
} else {
event.setCancelled(true);
}
return;
}
// Deny DGSignblocks destroying
if (GroupSign.isRelativeSign(block, 1, 0) || GroupSign.isRelativeSign(block, -1, 0) || GroupSign.isRelativeSign(block, 0, 1) || GroupSign.isRelativeSign(block, 0, -1)) {
event.setCancelled(true);
return;
}
// DGSign destroying
if (GroupSign.getSign(block) != null) {
plugin.getGroupSigns().remove(GroupSign.getSign(block));
// Delete LeaveSign
LeaveSign leaveSign = LeaveSign.getSign(block);
if (leaveSign != null) {
if (plugin.getInBreakMode().contains(player)) {
leaveSign.delete();
MessageUtil.sendMessage(player, plugin.getDMessages().getMessage(Messages.PLAYER_PROTECTED_BLOCK_DELETED));
MessageUtil.sendMessage(player, plugin.getDMessages().getMessage(Messages.CMD_BREAK_PROTECTED_MODE));
plugin.getInBreakMode().remove(player);
} else {
event.setCancelled(true);
}
return;
}
// Deny LeaveSignblocks destroying
if (LeaveSign.isRelativeSign(block, 1, 0) || LeaveSign.isRelativeSign(block, -1, 0) || LeaveSign.isRelativeSign(block, 0, 1) || LeaveSign.isRelativeSign(block, 0, -1)) {
event.setCancelled(true);
}
// LeaveSign destroying
if (LeaveSign.getSign(block) != null) {
event.setCancelled(true);
// LeaveSign.lsigns.remove(LeaveSign.getSign(block));
return;
}
// Editworld Signs
EditWorld editWorld = EditWorld.get(block.getWorld());
EditWorld editWorld = EditWorld.getByWorld(block.getWorld());
if (editWorld != null) {
editWorld.getSign().remove(event.getBlock());
}
@ -124,7 +159,7 @@ public class BlockListener implements Listener {
Player player = event.getPlayer();
Block block = event.getBlock();
String[] lines = event.getLines();
EditWorld editWorld = EditWorld.get(player.getWorld());
EditWorld editWorld = EditWorld.getByWorld(player.getWorld());
// Group Signs
if (editWorld == null) {
@ -211,7 +246,7 @@ public class BlockListener implements Listener {
}
// Check EditWorlds
EditWorld editWorld = EditWorld.get(event.getBlock().getWorld());
EditWorld editWorld = EditWorld.getByWorld(event.getBlock().getWorld());
if (editWorld != null) {
event.setCancelled(true);
}

View File

@ -47,7 +47,7 @@ public class EntityListener implements Listener {
public void onCreatureSpawn(CreatureSpawnEvent event) {
World world = event.getLocation().getWorld();
EditWorld editWorld = EditWorld.get(world);
EditWorld editWorld = EditWorld.getByWorld(world);
GameWorld gameWorld = GameWorld.getByWorld(world);
if (editWorld != null || gameWorld != null) {

View File

@ -98,9 +98,13 @@ public class PlayerListener implements Listener {
Player player = event.getPlayer();
Block clickedBlock = event.getClickedBlock();
if (plugin.getInBreakMode().contains(player)) {
return;
}
if (clickedBlock != null) {
// Block Enderchests
if (GameWorld.getByWorld(player.getWorld()) != null || EditWorld.get(player.getWorld()) != null) {
if (GameWorld.getByWorld(player.getWorld()) != null || EditWorld.getByWorld(player.getWorld()) != null) {
if (event.getAction() != Action.LEFT_CLICK_BLOCK) {
if (clickedBlock.getType() == Material.ENDER_CHEST) {
if ( !player.hasPermission("dxl.bypass")) {
@ -156,7 +160,7 @@ public class PlayerListener implements Listener {
}
// Copy/Paste a Sign and Block-info
if (EditWorld.get(player.getWorld()) != null) {
if (EditWorld.getByWorld(player.getWorld()) != null) {
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (item.getType() == Material.STICK) {
DPlayer dPlayer = DPlayer.getByPlayer(player);
@ -294,7 +298,7 @@ public class PlayerListener implements Listener {
}
if (dPlayer.isEditing()) {
EditWorld editWorld = EditWorld.get(dPlayer.getWorld());
EditWorld editWorld = EditWorld.getByWorld(dPlayer.getWorld());
if (editWorld == null) {
return;
}

View File

@ -131,7 +131,7 @@ public class DPlayer {
}
if (editing) {
EditWorld editWorld = EditWorld.get(world);
EditWorld editWorld = EditWorld.getByWorld(world);
if (editWorld != null) {
editWorld.save();
}
@ -349,7 +349,7 @@ public class DPlayer {
public void sendMessage(String message) {
if (editing) {
EditWorld editWorld = EditWorld.get(world);
EditWorld editWorld = EditWorld.getByWorld(world);
editWorld.msg(message);
for (Player player : plugin.getChatSpyers()) {
if ( !editWorld.getWorld().getPlayers().contains(player)) {
@ -811,7 +811,7 @@ public class DPlayer {
if ( !updateSecond) {
if ( !dPlayer.getPlayer().getWorld().equals(dPlayer.world)) {
if (dPlayer.editing) {
EditWorld editWorld = EditWorld.get(dPlayer.world);
EditWorld editWorld = EditWorld.getByWorld(dPlayer.world);
if (editWorld != null) {
if (editWorld.getLobby() == null) {
MiscUtil.secureTeleport(dPlayer.getPlayer(), editWorld.getWorld().getSpawnLocation());

View File

@ -24,7 +24,7 @@ public class InteractSign extends DSign {
@Override
public boolean check() {
Set<Integer> used = new HashSet<Integer>();
for (Block block : EditWorld.get(getSign().getLocation().getWorld()).getSign()) {
for (Block block : EditWorld.getByWorld(getSign().getLocation().getWorld()).getSign()) {
if (block == null) {
continue;
}

View File

@ -27,7 +27,7 @@ public class TriggerSign extends DSign {
@Override
public boolean check() {
Set<Integer> used = new HashSet<Integer>();
for (Block block : EditWorld.get(getSign().getLocation().getWorld()).getSign()) {
for (Block block : EditWorld.getByWorld(getSign().getLocation().getWorld()).getSign()) {
if (block == null) {
continue;
}