From 69e12306904e863a8390988ec521584126d4dce1 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Wed, 27 Jan 2016 20:19:28 +0100 Subject: [PATCH] Advanced groups --- .../dre2n/dungeonsxl/command/ChatCommand.java | 2 +- .../dre2n/dungeonsxl/command/DCommands.java | 1 + .../dungeonsxl/command/GroupCommand.java | 247 ++++++++++++++++++ .../dre2n/dungeonsxl/command/PlayCommand.java | 50 +++- .../dre2n/dungeonsxl/command/TestCommand.java | 51 +++- .../dungeonsxl/config/MessageConfig.java | 29 +- .../event/dgroup/DGroupCreateEvent.java | 2 +- .../event/dgroup/DGroupDisbandEvent.java | 86 ++++++ .../event/dplayer/DPlayerKickEvent.java | 29 +- .../dre2n/dungeonsxl/global/DPortal.java | 2 +- .../dungeonsxl/listener/EntityListener.java | 3 + .../dungeonsxl/listener/PlayerListener.java | 19 +- .../dre2n/dungeonsxl/player/DGroup.java | 213 ++++++++++++--- .../dre2n/dungeonsxl/player/DPlayer.java | 38 ++- .../util/playerutil/PlayerUtil.java | 41 ++- .../dungeonsxl/util/playerutil/v1_7_R3.java | 28 +- .../dungeonsxl/util/playerutil/v1_7_R4.java | 28 +- .../dungeonsxl/util/playerutil/v1_8_R1.java | 28 +- .../dungeonsxl/util/playerutil/v1_8_R2.java | 28 +- .../dungeonsxl/util/playerutil/v1_8_R3.java | 28 +- .../dungeonsxl/util/playerutil/v1_9_R1.java | 28 +- src/plugin.yml | 4 + 22 files changed, 803 insertions(+), 182 deletions(-) create mode 100644 src/io/github/dre2n/dungeonsxl/command/GroupCommand.java create mode 100644 src/io/github/dre2n/dungeonsxl/event/dgroup/DGroupDisbandEvent.java diff --git a/src/io/github/dre2n/dungeonsxl/command/ChatCommand.java b/src/io/github/dre2n/dungeonsxl/command/ChatCommand.java index 901667b2..53c7af44 100644 --- a/src/io/github/dre2n/dungeonsxl/command/ChatCommand.java +++ b/src/io/github/dre2n/dungeonsxl/command/ChatCommand.java @@ -24,7 +24,7 @@ public class ChatCommand extends DCommand { DPlayer dplayer = DPlayer.getByPlayer(player); if (dplayer == null) { - MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_NOT_IN_GROUP)); + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_JOIN_GROUP)); return; } diff --git a/src/io/github/dre2n/dungeonsxl/command/DCommands.java b/src/io/github/dre2n/dungeonsxl/command/DCommands.java index c9ba0518..8044e1a1 100644 --- a/src/io/github/dre2n/dungeonsxl/command/DCommands.java +++ b/src/io/github/dre2n/dungeonsxl/command/DCommands.java @@ -17,6 +17,7 @@ public class DCommands { dCommands.add(new CreateCommand()); dCommands.add(new EditCommand()); dCommands.add(new EscapeCommand()); + dCommands.add(new GroupCommand()); dCommands.add(new InviteCommand()); dCommands.add(new LeaveCommand()); dCommands.add(new ListCommand()); diff --git a/src/io/github/dre2n/dungeonsxl/command/GroupCommand.java b/src/io/github/dre2n/dungeonsxl/command/GroupCommand.java new file mode 100644 index 00000000..7951f8a5 --- /dev/null +++ b/src/io/github/dre2n/dungeonsxl/command/GroupCommand.java @@ -0,0 +1,247 @@ +package io.github.dre2n.dungeonsxl.command; + +import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages; +import io.github.dre2n.dungeonsxl.event.dgroup.DGroupCreateEvent; +import io.github.dre2n.dungeonsxl.event.dgroup.DGroupDisbandEvent; +import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerKickEvent; +import io.github.dre2n.dungeonsxl.player.DGroup; +import io.github.dre2n.dungeonsxl.player.DPlayer; +import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil; + +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class GroupCommand extends DCommand { + + public GroupCommand() { + setCommand("group"); + setMinArgs(0); + setMaxArgs(2); + setHelp(messageConfig.getMessage(Messages.HELP_CMD_GROUP)); + setPermission("dxl.group"); + setPlayerCommand(true); + } + + private CommandSender sender; + private Player player; + private String[] args; + + @Override + public void onExecute(String[] args, CommandSender sender) { + this.sender = sender; + this.player = (Player) sender; + this.args = args; + + DGroup dGroup = DGroup.getByPlayer(player); + + if (args.length == 2) { + + if (args[1].equalsIgnoreCase("disband")) { + disbandGroup(dGroup); + return; + + } else if (args[1].equalsIgnoreCase("show")) { + showGroup(dGroup); + return; + } + + } else if (args.length >= 3) { + + if (args[1].equalsIgnoreCase("kick")) { + kickPlayer(dGroup); + return; + + } else if (args[1].equalsIgnoreCase("invite")) { + invitePlayer(dGroup); + return; + + } else if (args[1].equalsIgnoreCase("uninvite")) { + uninvitePlayer(dGroup); + return; + + } else if (args[1].equalsIgnoreCase("help")) { + showHelp(args[2]); + return; + + } else if (args[1].equalsIgnoreCase("create")) { + createGroup(); + return; + + } else if (args[1].equalsIgnoreCase("disband") && sender.hasPermission("dxl.group.admin")) { + disbandGroup(DGroup.getByName(args[2])); + return; + + } else if (args[1].equalsIgnoreCase("join")) { + joinGroup(DGroup.getByName(args[2])); + return; + + } else if (args[1].equalsIgnoreCase("show") && sender.hasPermission("dxl.group.admin")) { + showGroup(DGroup.getByName(args[2])); + return; + } + } + + showHelp("1"); + } + + public void createGroup() { + if (DGroup.getByPlayer(player) == null && DGroup.getByName(args[2]) == null) { + DGroup dGroup = new DGroup(args[2], player); + DGroupCreateEvent event = new DGroupCreateEvent(dGroup, player, DGroupCreateEvent.Cause.COMMAND); + + if (event.isCancelled()) { + plugin.getDGroups().remove(dGroup); + dGroup = null; + + } else { + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.GROUP_CREATED, sender.getName(), args[2])); + } + + } else { + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_LEAVE_GROUP)); + } + } + + public void disbandGroup(DGroup dGroup) { + if (dGroup != null) { + DGroupDisbandEvent event = new DGroupDisbandEvent(dGroup, player, DGroupDisbandEvent.Cause.COMMAND); + + if ( !event.isCancelled()) { + plugin.getDGroups().remove(dGroup); + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.GROUP_DISBANDED, sender.getName(), dGroup.getName())); + dGroup = null; + } + + } else { + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_NO_SUCH_GROUP)); + } + } + + public void invitePlayer(DGroup dGroup) { + if (dGroup == null) { + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_JOIN_GROUP)); + return; + } + + Player toInvite = plugin.getServer().getPlayer(args[2]); + + if (toInvite != null) { + dGroup.addInvitedPlayer(toInvite, false); + + } else { + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_NO_SUCH_PLAYER, args[2])); + } + } + + public void uninvitePlayer(DGroup dGroup) { + if (dGroup == null) { + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_JOIN_GROUP)); + return; + } + + dGroup.clearOfflineInvitedPlayers(); + + Player toUninvite = plugin.getServer().getPlayer(args[2]); + + if (toUninvite != null) { + if (dGroup.getInvitedPlayers().contains(toUninvite)) { + dGroup.removeInvitedPlayer(toUninvite, false); + + } else { + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_NOT_IN_GROUP, args[2])); + } + + } else { + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_NO_SUCH_PLAYER, args[2])); + } + } + + public void joinGroup(DGroup dGroup) { + if (dGroup == null) { + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_NO_SUCH_GROUP, args[2])); + return; + } + + for (DGroup anyDGroup : plugin.getDGroups()) { + if (anyDGroup.getPlayers().contains(player)) { + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_LEAVE_GROUP)); + } + } + + if ( !dGroup.getInvitedPlayers().contains(player) && !player.hasPermission("dxl.bypass")) { + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_NOT_INVITED, args[2])); + return; + } + + dGroup.addPlayer(player); + dGroup.removeInvitedPlayer(player, true); + } + + public void kickPlayer(DGroup dGroup) { + if (dGroup == null) { + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_JOIN_GROUP)); + } + + Player toKick = plugin.getServer().getPlayer(args[2]); + if (toKick != null) { + DPlayerKickEvent event = new DPlayerKickEvent(DPlayer.getByPlayer(toKick.getPlayer()), DPlayerKickEvent.Cause.COMMAND); + + if ( !event.isCancelled()) { + if (dGroup.getPlayers().contains(toKick)) { + dGroup.removePlayer(toKick); + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.GROUP_KICKED_PLAYER, sender.getName(), args[2], dGroup.getName())); + + } else { + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_NOT_IN_GROUP, args[2], dGroup.getName())); + } + } + + } else { + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_NO_SUCH_PLAYER, args[2])); + } + } + + public void showGroup(DGroup dGroup) { + if (dGroup == null) { + if (args.length == 3) { + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_NO_SUCH_GROUP, args[2])); + + } else if (args.length == 2) { + MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_JOIN_GROUP)); + } + + return; + } + + MessageUtil.sendCenteredMessage(sender, "&4&l[ &6" + dGroup.getName() + " &4&l]"); + MessageUtil.sendMessage(sender, "&bCaptain: &e" + dGroup.getCaptain().getName()); + String players = "&e"; + for (Player player : dGroup.getPlayers()) { + players += (player == dGroup.getPlayers().get(0) ? "" : "&b, &e") + player.getName(); + } + MessageUtil.sendMessage(sender, "&bPlayers: &e" + players); + MessageUtil.sendMessage(sender, "&bDungeon: &e" + (dGroup.getDungeonName() == null ? "N/A" : dGroup.getDungeonName())); + MessageUtil.sendMessage(sender, "&bMap: &e" + (dGroup.getMapName() == null ? "N/A" : dGroup.getMapName())); + } + + public void showHelp(String page) { + MessageUtil.sendPluginTag(sender, plugin); + switch (page) { + default: + MessageUtil.sendCenteredMessage(sender, "&4&l[ &61-5 &4/ &67 &4| &61 &4&l]"); + MessageUtil.sendMessage(sender, "&bcreate" + "&7 - " + messageConfig.getMessage(Messages.HELP_CMD_GROUP_CREATE)); + MessageUtil.sendMessage(sender, "&bdisband" + "&7 - " + messageConfig.getMessage(Messages.HELP_CMD_GROUP_DISBAND)); + MessageUtil.sendMessage(sender, "&binvite" + "&7 - " + messageConfig.getMessage(Messages.HELP_CMD_GROUP_INVITE)); + MessageUtil.sendMessage(sender, "&buninvite" + "&7 - " + messageConfig.getMessage(Messages.HELP_CMD_GROUP_UNINVITE)); + MessageUtil.sendMessage(sender, "&bjoin" + "&7 - " + messageConfig.getMessage(Messages.HELP_CMD_GROUP_JOIN)); + break; + case "2": + MessageUtil.sendCenteredMessage(sender, "&4&l[ &66-10 &4/ &67 &4| &62 &4&l]"); + MessageUtil.sendMessage(sender, "&bkick" + "&7 - " + messageConfig.getMessage(Messages.HELP_CMD_GROUP_KICK)); + MessageUtil.sendMessage(sender, "&bshow" + "&7 - " + messageConfig.getMessage(Messages.HELP_CMD_GROUP_SHOW)); + break; + } + + } + +} diff --git a/src/io/github/dre2n/dungeonsxl/command/PlayCommand.java b/src/io/github/dre2n/dungeonsxl/command/PlayCommand.java index 2f9319dd..1dedc491 100644 --- a/src/io/github/dre2n/dungeonsxl/command/PlayCommand.java +++ b/src/io/github/dre2n/dungeonsxl/command/PlayCommand.java @@ -1,5 +1,6 @@ package io.github.dre2n.dungeonsxl.command; +import io.github.dre2n.dungeonsxl.config.DungeonConfig; import io.github.dre2n.dungeonsxl.config.WorldConfig; import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages; import io.github.dre2n.dungeonsxl.dungeon.Dungeon; @@ -29,9 +30,9 @@ public class PlayCommand extends DCommand { @Override public void onExecute(String[] args, CommandSender sender) { Player player = (Player) sender; - DPlayer dplayer = DPlayer.getByPlayer(player); + DPlayer dPlayer = DPlayer.getByPlayer(player); - if (dplayer != null) { + if (dPlayer != null) { MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_LEAVE_DUNGEON)); return; } @@ -86,16 +87,43 @@ public class PlayCommand extends DCommand { return; } - if (DGroup.getByPlayer(player) != null) { - MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_LEAVE_GROUP)); - return; - } + DGroup dGroup = DGroup.getByPlayer(player); - DGroup dGroup = new DGroup(player, identifier, multiFloor); + if (dGroup != null) { + if ( !dGroup.getCaptain().equals(player) && !player.hasPermission("dxl.bypass")) { + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_NOT_CAPTAIN)); + } + + if (dGroup.getMapName() == null) { + if ( !multiFloor) { + dGroup.setMapName(identifier); + + } else { + dGroup.setDungeonName(identifier); + Dungeon dungeon = plugin.getDungeons().getDungeon(identifier); + + if (dungeon != null) { + DungeonConfig config = dungeon.getConfig(); + + if (config != null) { + dGroup.setMapName(config.getStartFloor()); + } + } + } + + } else { + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_LEAVE_GROUP)); + return; + } + + } else { + dGroup = new DGroup(player, identifier, multiFloor); + } DGroupCreateEvent event = new DGroupCreateEvent(dGroup, player, DGroupCreateEvent.Cause.COMMAND); if (event.isCancelled()) { + plugin.getDGroups().remove(dGroup); dGroup = null; } @@ -114,10 +142,14 @@ public class PlayCommand extends DCommand { } if (dGroup.getGameWorld().getLocLobby() == null) { - new DPlayer(player, dGroup.getGameWorld().getWorld(), dGroup.getGameWorld().getWorld().getSpawnLocation(), false); + for (Player groupPlayer : dGroup.getPlayers()) { + new DPlayer(groupPlayer, dGroup.getGameWorld().getWorld(), dGroup.getGameWorld().getWorld().getSpawnLocation(), false); + } } else { - new DPlayer(player, dGroup.getGameWorld().getWorld(), dGroup.getGameWorld().getLocLobby(), false); + for (Player groupPlayer : dGroup.getPlayers()) { + new DPlayer(groupPlayer, dGroup.getGameWorld().getWorld(), dGroup.getGameWorld().getLocLobby(), false); + } } } diff --git a/src/io/github/dre2n/dungeonsxl/command/TestCommand.java b/src/io/github/dre2n/dungeonsxl/command/TestCommand.java index 776a8a8e..c716d009 100644 --- a/src/io/github/dre2n/dungeonsxl/command/TestCommand.java +++ b/src/io/github/dre2n/dungeonsxl/command/TestCommand.java @@ -1,5 +1,6 @@ package io.github.dre2n.dungeonsxl.command; +import io.github.dre2n.dungeonsxl.config.DungeonConfig; import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages; import io.github.dre2n.dungeonsxl.dungeon.Dungeon; import io.github.dre2n.dungeonsxl.dungeon.EditWorld; @@ -62,16 +63,43 @@ public class TestCommand extends DCommand { return; } - if (DGroup.getByPlayer(player) != null) { - MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_LEAVE_GROUP)); - return; - } + DGroup dGroup = DGroup.getByPlayer(player); - DGroup dGroup = new DGroup(player, identifier, multiFloor); + if (dGroup != null) { + if ( !dGroup.getCaptain().equals(player) && !player.hasPermission("dxl.bypass")) { + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_NOT_CAPTAIN)); + } + + if (dGroup.getMapName() == null) { + if ( !multiFloor) { + dGroup.setMapName(identifier); + + } else { + dGroup.setDungeonName(identifier); + Dungeon dungeon = plugin.getDungeons().getDungeon(identifier); + + if (dungeon != null) { + DungeonConfig config = dungeon.getConfig(); + + if (config != null) { + dGroup.setMapName(config.getStartFloor()); + } + } + } + + } else { + MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_LEAVE_GROUP)); + return; + } + + } else { + dGroup = new DGroup(player, identifier, multiFloor); + } DGroupCreateEvent event = new DGroupCreateEvent(dGroup, player, DGroupCreateEvent.Cause.COMMAND); if (event.isCancelled()) { + plugin.getDGroups().remove(dGroup); dGroup = null; } @@ -88,17 +116,16 @@ public class TestCommand extends DCommand { dGroup.remove(); return; } - - DPlayer newDPlayer; - if (dGroup.getGameWorld().getLocLobby() == null) { - newDPlayer = new DPlayer(player, dGroup.getGameWorld().getWorld(), dGroup.getGameWorld().getWorld().getSpawnLocation(), false); + for (Player groupPlayer : dGroup.getPlayers()) { + new DPlayer(groupPlayer, dGroup.getGameWorld().getWorld(), dGroup.getGameWorld().getWorld().getSpawnLocation(), false).setInTestMode(true); + } } else { - newDPlayer = new DPlayer(player, dGroup.getGameWorld().getWorld(), dGroup.getGameWorld().getLocLobby(), false); + for (Player groupPlayer : dGroup.getPlayers()) { + new DPlayer(groupPlayer, dGroup.getGameWorld().getWorld(), dGroup.getGameWorld().getLocLobby(), false).setInTestMode(true); + } } - - newDPlayer.setInTestMode(true); } } diff --git a/src/io/github/dre2n/dungeonsxl/config/MessageConfig.java b/src/io/github/dre2n/dungeonsxl/config/MessageConfig.java index d2c00856..81462371 100644 --- a/src/io/github/dre2n/dungeonsxl/config/MessageConfig.java +++ b/src/io/github/dre2n/dungeonsxl/config/MessageConfig.java @@ -11,6 +11,13 @@ public class MessageConfig { public enum Messages { + GROUP_CREATED("Group_Created", "&4&v1&6 created the group &4&v2&6!"), + GROUP_DISBANDED("Group_Disbanded", "&4&v1&6 disbanded the group &4&v2&6."), + GROUP_INVITED_PLAYER("Group_InvitedPlayer", "&4&v1&6 invited the player &4&v2&6 to the group &4&v3&6."), + GROUP_UNINVITED_PLAYER("Group_UninvitedPlayer", "&4&v1&6 took back the invitation for &4&v2&6 to the group &4&v3&6."), + GROUP_KICKED_PLAYER("Group_KickedPlayer", "&4&v1&6 kicked the player &4&v2&6 from the group &4&v3&6."), + GROUP_PLAYER_JOINED("Group_PlayerJoined", "&6Player &4&v1&6 has joined the group!"), + LOG_ERROR_MOB_ENCHANTMENT("Log_Error_MobEnchantment", "&4Error at loading mob.yml: Enchantment &6&v1&4 doesn't exist!"), LOG_ERROR_MOBTYPE("Log_Error_MobType", "&4Error at loading mob.yml: Mob &6&v1&4 doesn't exist!"), LOG_ERROR_NO_CONSOLE_COMMAND("Log_Error_NoConsoleCommand", "&6/dxl &v1&4 can not be executed as Console!"), @@ -23,10 +30,14 @@ public class MessageConfig { PLAYER_DEATH("Player_Death", "&6You died, lives left: &2&v1"), PLAYER_DEATH_KICK("Player_DeathKick", "&2&v1&6 died and lost his last life."), PLAYER_FINISHED_DUNGEON("Player_FinishedDungeon", "&6You successfully finished the Dungeon!"), - PLAYER_JOIN_GROUP("Player_JoinGroup", "&6Player &4&v1&6 has joined the Group!"), + PLAYER_INVITED("Player_Invited", "&4&v1&6 invited you to the group &4&v2&6."), + PLAYER_UNINVITED("Player_Uninvited", "&4&v1&6 took back your invitation to the group &4&v2&6."), + PLAYER_JOIN_GROUP("Player_JoinGroup", "&6You successfully joined the group!"), + PLAYER_KICKED("Player_Kicked", "&4You have been kicked out of the group &6&v1&4."), PLAYER_LEAVE_GROUP("Player_LeaveGroup", "&6You have successfully left your group!"), PLAYER_LEFT_GROUP("Player_LeftGroup", "&6Player &4&v1&6 has left the Group!"), PLAYER_LOOT_ADDED("Player_LootAdded", "&4&v1&6 have been added to your reward inventory!"), + PLAYER_NEW_CAPTAIN("Player_NewCaptain", "&6You are now the new captain of your group."), PLAYER_OFFLINE("Player_Offline", "&Player &4&v1&6 went offline. In &4&v2&6 seconds he will autmatically be kicked from the Dungeon!"), PLAYER_OFFLINE_NEVER("Player_OfflineNever", "&Player &4&v1&6 went offline. He will &4not&6 be kicked from the Dungeon automatically!"), PLAYER_PORTAL_ABORT("Player_PortalAbort", "&6Portal creation cancelled!"), @@ -69,6 +80,8 @@ public class MessageConfig { ERROR_DROP("Error_Drop", "&4You cannot drop safe items"), ERROR_DUNGEON_NOT_EXIST("Error_DungeonNotExist", "&4Dungeon &6&v1&4 does not exist!"), ERROR_ENDERCHEST("Error_Enderchest", "&4You cannot use an enderchest while in a Dungeon!"), + ERROR_IN_GROUP("Error_InGroup", "&4The player &6&v1&4 is already member of a group."), + ERROR_JOIN_GROUP("Error_JoinGroup", "&4You have to join a group first!"), ERROR_LEAVE_DUNGEON("Error_LeaveDungeon", "&4You have to leave your current dungeon first!"), ERROR_LEAVE_GROUP("Error_LeaveGroup", "&4You have to leave your group first!"), ERROR_LEFT_CLICK("Error_Leftklick", "&4You have to use Left-Click on this sign!"), @@ -81,8 +94,12 @@ public class MessageConfig { ERROR_NO_PERMISSIONS("Error_NoPermissions", "&4You have no permission to do this!"), ERROR_NO_PLAYER_COMMAND("Error_NoPlayerCommand", "&6/dxl &v1&4 cannot be executed as player!"), ERROR_NO_PROTECTED_BLOCK("Error_NoDXLBlock", "&4This is not a block protected by DungeonsXL!"), + ERROR_NO_SUCH_GROUP("Error_NoSuchGroup", "&4The group &6&v1&4 does not exist!"), + ERROR_NO_SUCH_PLAYER("Error_NoSuchPlayer", "&4The player &6&v1&4 does not exist!"), + ERROR_NOT_CAPTAIN("Error_NotCaptain", "&4You are not the captain of your group!"), ERROR_NOT_IN_DUNGEON("Error_NotInDungeon", "&4You are not in a dungeon!"), - ERROR_NOT_IN_GROUP("Error_NotInGroup", "&4You have to join a group first!"), + ERROR_NOT_IN_GROUP("Error_NotInGroup", "&4The player &6&v1&4 is not member of the group &6&v2&v4."), + ERROR_NOT_INVITED("Error_NotInvited", "&4You are not invited to the group &6&v1&4."), ERROR_NOT_SAVED("Error_NotSaved", "&4The map &6&v1&4 has not been saved to the &6DungeonsXL/maps/ &4folder yet!"), ERROR_TUTORIAL_NOT_EXIST("Error_TutorialNotExist", "&4Tutorial dungeon does not exist!"), ERROR_READY("Error_Ready", "&4Choose your class first!"), @@ -95,6 +112,14 @@ public class MessageConfig { HELP_CMD_CREATE("Help_Cmd_Create", "/dxl create - Creates a new dungeon"), HELP_CMD_EDIT("Help_Cmd_Edit", "/dxl edit - Edit an existing dungeon"), HELP_CMD_ESCAPE("Help_Cmd_Escape", "/dxl escape - Leaves the current dungeon, without saving!"), + HELP_CMD_GROUP("Help_Cmd_Group", "/dxl group - Shows group command help"), + HELP_CMD_GROUP_CREATE("Help_Cmd_GroupCreate", "/dxl group create [group] - Creates a new group"), + HELP_CMD_GROUP_DISBAND("Help_Cmd_GroupDisband", "/dxl group disband ([group]) - Disbands a group"), + HELP_CMD_GROUP_INVITE("Help_Cmd_GroupInvite", "/dxl group invite [player]- Invites someone to your group"), + HELP_CMD_GROUP_UNINVITE("Help_Cmd_GroupUninvite", "/dxl group uninvite [player] - Takes back an invitation to your group"), + HELP_CMD_GROUP_JOIN("Help_Cmd_GroupJoin", "/dxl group join [group]- Join a group"), + HELP_CMD_GROUP_KICK("Help_Cmd_GroupKick", "/dxl group kick [player] - Kicks a player"), + HELP_CMD_GROUP_SHOW("Help_Cmd_GroupShow", "/dxl group show [group] - Shows a group"), HELP_CMD_HELP("Help_Cmd_Help", "/dxl help - Shows the help page"), HELP_CMD_INVITE("Help_Cmd_Invite", "/dxl invite - Invite a player to edit a dungeon"), HELP_CMD_LEAVE("Help_Cmd_Leave", "/dxl leave - Leaves the current dungeon"), diff --git a/src/io/github/dre2n/dungeonsxl/event/dgroup/DGroupCreateEvent.java b/src/io/github/dre2n/dungeonsxl/event/dgroup/DGroupCreateEvent.java index 4c82b0d4..59a813f5 100644 --- a/src/io/github/dre2n/dungeonsxl/event/dgroup/DGroupCreateEvent.java +++ b/src/io/github/dre2n/dungeonsxl/event/dgroup/DGroupCreateEvent.java @@ -12,7 +12,7 @@ public class DGroupCreateEvent extends DGroupEvent implements Cancellable { COMMAND, GROUP_SIGN, - CUSTOM; + CUSTOM } diff --git a/src/io/github/dre2n/dungeonsxl/event/dgroup/DGroupDisbandEvent.java b/src/io/github/dre2n/dungeonsxl/event/dgroup/DGroupDisbandEvent.java new file mode 100644 index 00000000..9e01b86b --- /dev/null +++ b/src/io/github/dre2n/dungeonsxl/event/dgroup/DGroupDisbandEvent.java @@ -0,0 +1,86 @@ +package io.github.dre2n.dungeonsxl.event.dgroup; + +import io.github.dre2n.dungeonsxl.player.DGroup; + +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; + +public class DGroupDisbandEvent extends DGroupEvent implements Cancellable { + + public enum Cause { + + COMMAND, + DUNGEON_FINISHED, + CUSTOM + + } + + private static final HandlerList handlers = new HandlerList(); + private boolean cancelled; + + private Player disbander; + + private Cause cause; + + public DGroupDisbandEvent(DGroup dGroup, Cause cause) { + super(dGroup); + this.cause = cause; + } + + public DGroupDisbandEvent(DGroup dGroup, Player disbander, Cause cause) { + super(dGroup); + this.disbander = disbander; + this.cause = cause; + } + + /** + * @return the disbander + */ + public Player getDisbander() { + return disbander; + } + + /** + * @param disbander + * the disbander to set + */ + public void setDisbander(Player disbander) { + this.disbander = disbander; + } + + /** + * @return the cause + */ + public Cause getCause() { + return cause; + } + + /** + * @param cause + * the cause to set + */ + public void setCause(Cause cause) { + this.cause = cause; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancelled) { + this.cancelled = cancelled; + } + +} diff --git a/src/io/github/dre2n/dungeonsxl/event/dplayer/DPlayerKickEvent.java b/src/io/github/dre2n/dungeonsxl/event/dplayer/DPlayerKickEvent.java index 58992f4d..e85e9df8 100644 --- a/src/io/github/dre2n/dungeonsxl/event/dplayer/DPlayerKickEvent.java +++ b/src/io/github/dre2n/dungeonsxl/event/dplayer/DPlayerKickEvent.java @@ -7,11 +7,38 @@ import org.bukkit.event.HandlerList; public class DPlayerKickEvent extends DPlayerEvent implements Cancellable { + public enum Cause { + + COMMAND, + DEATH, + OFFLINE, + CUSTOM + + } + private static final HandlerList handlers = new HandlerList(); private boolean cancelled; - public DPlayerKickEvent(DPlayer dPlayer) { + private Cause cause; + + public DPlayerKickEvent(DPlayer dPlayer, Cause cause) { super(dPlayer); + this.cause = cause; + } + + /** + * @return the cause + */ + public Cause getCause() { + return cause; + } + + /** + * @param cause + * the cause to set + */ + public void setCause(Cause cause) { + this.cause = cause; } @Override diff --git a/src/io/github/dre2n/dungeonsxl/global/DPortal.java b/src/io/github/dre2n/dungeonsxl/global/DPortal.java index 09f00675..d59d1f26 100644 --- a/src/io/github/dre2n/dungeonsxl/global/DPortal.java +++ b/src/io/github/dre2n/dungeonsxl/global/DPortal.java @@ -162,7 +162,7 @@ public class DPortal { DGroup dgroup = DGroup.getByPlayer(player); if (dgroup == null) { - MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.ERROR_NOT_IN_GROUP)); + MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.ERROR_JOIN_GROUP)); return; } diff --git a/src/io/github/dre2n/dungeonsxl/listener/EntityListener.java b/src/io/github/dre2n/dungeonsxl/listener/EntityListener.java index b6581edd..92ce4d0c 100644 --- a/src/io/github/dre2n/dungeonsxl/listener/EntityListener.java +++ b/src/io/github/dre2n/dungeonsxl/listener/EntityListener.java @@ -11,6 +11,7 @@ import io.github.dre2n.dungeonsxl.player.DPlayer; import java.util.List; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; @@ -121,11 +122,13 @@ public class EntityListener implements Listener { attackedDGroup = DGroup.getByPlayer(attackedPlayer); if (config.isPlayerVersusPlayer()) { + Bukkit.broadcastMessage("pvp cancel"); event.setCancelled(true); } if (attackerDGroup != null && attackedDGroup != null) { if (config.isFriendlyFire() && attackerDGroup.equals(attackedDGroup)) { + Bukkit.broadcastMessage("ff cancel"); event.setCancelled(true); } } diff --git a/src/io/github/dre2n/dungeonsxl/listener/PlayerListener.java b/src/io/github/dre2n/dungeonsxl/listener/PlayerListener.java index cfd7df0a..28d026c9 100644 --- a/src/io/github/dre2n/dungeonsxl/listener/PlayerListener.java +++ b/src/io/github/dre2n/dungeonsxl/listener/PlayerListener.java @@ -12,6 +12,7 @@ import io.github.dre2n.dungeonsxl.dungeon.game.GameChest; import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld; import io.github.dre2n.dungeonsxl.event.dgroup.DGroupCreateEvent; import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerDeathEvent; +import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerKickEvent; import io.github.dre2n.dungeonsxl.global.DPortal; import io.github.dre2n.dungeonsxl.global.GroupSign; import io.github.dre2n.dungeonsxl.global.LeaveSign; @@ -78,14 +79,18 @@ public class PlayerListener implements Listener { dPlayer.setLives(dPlayer.getLives() - dPlayerDeathEvent.getLostLives()); if (dPlayer.getLives() == 0 && dPlayer.isReady()) { - MessageUtil.broadcastMessage(messageConfig.getMessage(Messages.PLAYER_DEATH_KICK, player.getName())); + DPlayerKickEvent dPlayerKickEvent = new DPlayerKickEvent(dPlayer, DPlayerKickEvent.Cause.DEATH); - // TODO: This Runnable is a workaround for a bug I couldn't find, yet... - new org.bukkit.scheduler.BukkitRunnable() { - public void run() { - dPlayer.leave(); - } - }.runTaskLater(plugin, 1L); + if ( !dPlayerKickEvent.isCancelled()) { + MessageUtil.broadcastMessage(messageConfig.getMessage(Messages.PLAYER_DEATH_KICK, player.getName())); + + // TODO: This Runnable is a workaround for a bug I couldn't find, yet... + new org.bukkit.scheduler.BukkitRunnable() { + public void run() { + dPlayer.leave(); + } + }.runTaskLater(plugin, 1L); + } } else if ( !(dPlayer.getLives() == -1)) { MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.PLAYER_DEATH, String.valueOf(dPlayer.getLives()))); diff --git a/src/io/github/dre2n/dungeonsxl/player/DGroup.java b/src/io/github/dre2n/dungeonsxl/player/DGroup.java index 92c8f07d..ba3799bd 100644 --- a/src/io/github/dre2n/dungeonsxl/player/DGroup.java +++ b/src/io/github/dre2n/dungeonsxl/player/DGroup.java @@ -14,7 +14,7 @@ import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.CopyOnWriteArrayList; +import java.util.UUID; import org.bukkit.entity.Player; @@ -23,7 +23,9 @@ public class DGroup { static DungeonsXL plugin = DungeonsXL.getPlugin(); private String name; - private CopyOnWriteArrayList players = new CopyOnWriteArrayList(); + private Player captain; + private List players = new ArrayList(); + private List invitedPlayers = new ArrayList(); private String dungeonName; private String mapName; private List unplayedFloors = new ArrayList(); @@ -32,42 +34,75 @@ public class DGroup { private int floorCount; private List rewards = new ArrayList(); - public DGroup(String name, Player player, String identifier, boolean multiFloor) { + public DGroup(String name, Player player) { plugin.getDGroups().add(this); this.name = name; - this.players.add(player); + captain = player; + players.add(player); - Dungeon dungeon = plugin.getDungeons().getDungeon(identifier); - if (multiFloor && dungeon != null) { - this.dungeonName = identifier; - this.mapName = dungeon.getConfig().getStartFloor(); - this.unplayedFloors = dungeon.getConfig().getFloors(); - - } else { - this.mapName = identifier; - } - this.playing = false; - this.floorCount = 0; + playing = false; + floorCount = 0; } public DGroup(Player player, String identifier, boolean multiFloor) { plugin.getDGroups().add(this); - this.name = "Group_" + plugin.getDGroups().size(); + name = "Group_" + plugin.getDGroups().size(); - this.players.add(player); + captain = player; + players.add(player); Dungeon dungeon = plugin.getDungeons().getDungeon(identifier); if (multiFloor && dungeon != null) { - this.dungeonName = identifier; - this.mapName = dungeon.getConfig().getStartFloor(); - this.unplayedFloors = dungeon.getConfig().getFloors(); + dungeonName = identifier; + mapName = dungeon.getConfig().getStartFloor(); + unplayedFloors = dungeon.getConfig().getFloors(); } else { - this.mapName = identifier; + mapName = identifier; } - this.playing = false; - this.floorCount = 0; + playing = false; + floorCount = 0; + } + + public DGroup(String name, Player player, String identifier, boolean multiFloor) { + plugin.getDGroups().add(this); + this.name = name; + + captain = player; + players.add(player); + + Dungeon dungeon = plugin.getDungeons().getDungeon(identifier); + if (multiFloor && dungeon != null) { + dungeonName = identifier; + mapName = dungeon.getConfig().getStartFloor(); + unplayedFloors = dungeon.getConfig().getFloors(); + + } else { + mapName = identifier; + } + playing = false; + floorCount = 0; + } + + public DGroup(String name, Player captain, List players, String identifier, boolean multiFloor) { + plugin.getDGroups().add(this); + this.name = name; + + this.captain = captain; + this.players = players; + + Dungeon dungeon = plugin.getDungeons().getDungeon(identifier); + if (multiFloor && dungeon != null) { + dungeonName = identifier; + mapName = dungeon.getConfig().getStartFloor(); + unplayedFloors = dungeon.getConfig().getFloors(); + + } else { + mapName = identifier; + } + playing = false; + floorCount = 0; } // Getters and setters @@ -87,10 +122,25 @@ public class DGroup { this.name = name; } + /** + * @return the captain + */ + public Player getCaptain() { + return captain; + } + + /** + * @param captain + * the captain to set + */ + public void setCaptain(Player captain) { + this.captain = captain; + } + /** * @return the players */ - public CopyOnWriteArrayList getPlayers() { + public List getPlayers() { return players; } @@ -99,13 +149,10 @@ public class DGroup { * the player to add */ public void addPlayer(Player player) { - // Send message - for (Player groupPlayer : getPlayers()) { - MessageUtil.sendMessage(groupPlayer, plugin.getMessageConfig().getMessage(Messages.PLAYER_JOIN_GROUP, player.getName())); - } + sendMessage(plugin.getMessageConfig().getMessage(Messages.GROUP_PLAYER_JOINED, player.getName())); + MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.PLAYER_JOIN_GROUP)); - // Add player - getPlayers().add(player); + players.add(player); } /** @@ -113,13 +160,11 @@ public class DGroup { * the player to remove */ public void removePlayer(Player player) { - getPlayers().remove(player); + players.remove(player); GroupSign.updatePerGroup(this); // Send message - for (Player groupPlayer : getPlayers()) { - MessageUtil.sendMessage(groupPlayer, plugin.getMessageConfig().getMessage(Messages.PLAYER_LEFT_GROUP, player.getName())); - } + sendMessage(plugin.getMessageConfig().getMessage(Messages.PLAYER_LEFT_GROUP, player.getName())); // Check group if (isEmpty()) { @@ -127,6 +172,92 @@ public class DGroup { } } + /** + * @return the players + */ + public List getInvitedPlayers() { + ArrayList players = new ArrayList(); + for (UUID uuid : invitedPlayers) { + players.add(plugin.getServer().getPlayer(uuid)); + } + + return players; + } + + /** + * @param player + * the player to add + */ + public void addInvitedPlayer(Player player, boolean silent) { + if (player == null) { + return; + } + + if (DGroup.getByPlayer(player) != null) { + if ( !silent) { + MessageUtil.sendMessage(captain, plugin.getMessageConfig().getMessage(Messages.ERROR_IN_GROUP, player.getName())); + } + return; + } + + if ( !silent) { + MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.PLAYER_INVITED, captain.getName(), name)); + } + + // Send message + if ( !silent) { + sendMessage(plugin.getMessageConfig().getMessage(Messages.GROUP_INVITED_PLAYER, captain.getName(), player.getName(), name)); + } + + // Add player + invitedPlayers.add(player.getUniqueId()); + } + + /** + * @param player + * the player to remove + */ + public void removeInvitedPlayer(Player player, boolean silent) { + if (player == null) { + return; + } + + if (DGroup.getByPlayer(player) != this) { + if ( !silent) { + MessageUtil.sendMessage(captain, plugin.getMessageConfig().getMessage(Messages.ERROR_NOT_IN_GROUP, player.getName(), name)); + } + return; + } + + if ( !silent) { + MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.PLAYER_UNINVITED, player.getName(), name)); + } + + // Send message + if ( !silent) { + for (Player groupPlayer : getPlayers()) { + MessageUtil.sendMessage(groupPlayer, plugin.getMessageConfig().getMessage(Messages.GROUP_UNINVITED_PLAYER, captain.getName(), player.getName(), name)); + } + } + + invitedPlayers.remove(player.getUniqueId()); + } + + /** + * Remove all invitations for players who are not online + */ + public void clearOfflineInvitedPlayers() { + ArrayList toRemove = new ArrayList(); + + for (UUID uuid : invitedPlayers) { + if (plugin.getServer().getPlayer(uuid) == null) { + toRemove.add(uuid); + } + } + + invitedPlayers.removeAll(toRemove); + } + /** * @return the gameWorld */ @@ -184,7 +315,7 @@ public class DGroup { * the name to set */ public void setMapName(String name) { - this.mapName = name; + mapName = name; } /** @@ -332,7 +463,7 @@ public class DGroup { /** * Send a message to all players in the group - * + * * @param except * Players who do not receive the message */ @@ -346,6 +477,16 @@ public class DGroup { // Statics + public static DGroup getByName(String name) { + for (DGroup dGroup : plugin.getDGroups()) { + if (dGroup.getName().equals(name)) { + return dGroup; + } + } + + return null; + } + public static DGroup getByPlayer(Player player) { for (DGroup dGroup : plugin.getDGroups()) { if (dGroup.getPlayers().contains(player)) { diff --git a/src/io/github/dre2n/dungeonsxl/player/DPlayer.java b/src/io/github/dre2n/dungeonsxl/player/DPlayer.java index 660292e2..e7779329 100644 --- a/src/io/github/dre2n/dungeonsxl/player/DPlayer.java +++ b/src/io/github/dre2n/dungeonsxl/player/DPlayer.java @@ -44,7 +44,7 @@ import org.bukkit.potion.PotionEffect; public class DPlayer { static DungeonsXL plugin = DungeonsXL.getPlugin(); - MessageConfig MessageConfig = plugin.getMessageConfig(); + MessageConfig messageConfig = plugin.getMessageConfig(); // Variables private Player player; @@ -67,7 +67,7 @@ public class DPlayer { private ItemStack[] respawnArmor; private String[] linesCopy; - private Inventory treasureInv = plugin.getServer().createInventory(getPlayer(), 45, MessageConfig.getMessage(Messages.PLAYER_TREASURES)); + private Inventory treasureInv = plugin.getServer().createInventory(getPlayer(), 45, messageConfig.getMessage(Messages.PLAYER_TREASURES)); private int initialLives = -1; private int lives; @@ -488,6 +488,7 @@ public class DPlayer { } else { savePlayer.reset(dConfig.getKeepInventoryOnEscape()); } + } else { savePlayer.reset(false); } @@ -551,18 +552,18 @@ public class DPlayer { } } - // Give Secure Objects other Players if (dGroup != null) { + // Give Secure Objects other Players if ( !dGroup.isEmpty()) { int i = 0; Player groupPlayer; do { groupPlayer = dGroup.getPlayers().get(i); if (groupPlayer != null) { - for (ItemStack istack : getPlayer().getInventory()) { - if (istack != null) { - if (gameWorld.getSecureObjects().contains(istack.getType())) { - groupPlayer.getInventory().addItem(istack); + for (ItemStack itemStack : getPlayer().getInventory()) { + if (itemStack != null) { + if (gameWorld.getSecureObjects().contains(itemStack.getType())) { + groupPlayer.getInventory().addItem(itemStack); } } } @@ -570,7 +571,16 @@ public class DPlayer { i++; } while (groupPlayer == null); } + + if (dGroup.getCaptain().equals(player) && dGroup.getPlayers().size() > 0) { + // Captain here! + Player newCaptain = dGroup.getPlayers().get(0); + dGroup.setCaptain(newCaptain); + MessageUtil.sendMessage(newCaptain, messageConfig.getMessage(Messages.PLAYER_NEW_CAPTAIN)); + // ...*flies away* + } } + } } @@ -618,7 +628,7 @@ public class DPlayer { } public void finishFloor(String specifiedFloor) { - MessageUtil.sendMessage(getPlayer(), MessageConfig.getMessage(Messages.PLAYER_FINISHED_DUNGEON)); + MessageUtil.sendMessage(getPlayer(), messageConfig.getMessage(Messages.PLAYER_FINISHED_DUNGEON)); finished = true; DGroup dGroup = DGroup.getByPlayer(getPlayer()); @@ -633,7 +643,7 @@ public class DPlayer { for (Player player : dGroup.getPlayers()) { DPlayer dPlayer = getByPlayer(player); if ( !dPlayer.finished) { - MessageUtil.sendMessage(this.getPlayer(), MessageConfig.getMessage(Messages.PLAYER_WAIT_FOR_OTHER_PLAYERS)); + MessageUtil.sendMessage(this.getPlayer(), messageConfig.getMessage(Messages.PLAYER_WAIT_FOR_OTHER_PLAYERS)); return; } } @@ -691,7 +701,7 @@ public class DPlayer { } public void finish() { - MessageUtil.sendMessage(getPlayer(), MessageConfig.getMessage(Messages.PLAYER_FINISHED_DUNGEON)); + MessageUtil.sendMessage(getPlayer(), messageConfig.getMessage(Messages.PLAYER_FINISHED_DUNGEON)); finished = true; DGroup dGroup = DGroup.getByPlayer(getPlayer()); @@ -709,7 +719,7 @@ public class DPlayer { for (Player player : dGroup.getPlayers()) { DPlayer dPlayer = getByPlayer(player); if ( !dPlayer.finished) { - MessageUtil.sendMessage(this.getPlayer(), MessageConfig.getMessage(Messages.PLAYER_WAIT_FOR_OTHER_PLAYERS)); + MessageUtil.sendMessage(this.getPlayer(), messageConfig.getMessage(Messages.PLAYER_WAIT_FOR_OTHER_PLAYERS)); hasToWait = true; } else if (dPlayer != this) { @@ -784,14 +794,14 @@ public class DPlayer { } } else { linesCopy = lines; - MessageUtil.sendMessage(getPlayer(), MessageConfig.getMessage(Messages.PLAYER_SIGN_COPIED)); + MessageUtil.sendMessage(getPlayer(), messageConfig.getMessage(Messages.PLAYER_SIGN_COPIED)); } } else { String info = "" + block.getType(); if (block.getData() != 0) { info = info + "," + block.getData(); } - MessageUtil.sendMessage(getPlayer(), MessageConfig.getMessage(Messages.PLAYER_BLOCK_INFO, info)); + MessageUtil.sendMessage(getPlayer(), messageConfig.getMessage(Messages.PLAYER_BLOCK_INFO, info)); } } @@ -896,7 +906,7 @@ public class DPlayer { } if (kick) { - DPlayerKickEvent dPlayerKickEvent = new DPlayerKickEvent(this); + DPlayerKickEvent dPlayerKickEvent = new DPlayerKickEvent(this, DPlayerKickEvent.Cause.OFFLINE); if ( !dPlayerKickEvent.isCancelled()) { leave(); diff --git a/src/io/github/dre2n/dungeonsxl/util/playerutil/PlayerUtil.java b/src/io/github/dre2n/dungeonsxl/util/playerutil/PlayerUtil.java index 32d6f8dd..460658d7 100644 --- a/src/io/github/dre2n/dungeonsxl/util/playerutil/PlayerUtil.java +++ b/src/io/github/dre2n/dungeonsxl/util/playerutil/PlayerUtil.java @@ -6,57 +6,70 @@ import io.github.dre2n.dungeonsxl.util.VersionUtil.Internals; import java.util.UUID; +import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; public class PlayerUtil { - public static Player getOfflinePlayer(String player, UUID uuid) { + public static Player getOfflinePlayer(String name) { + @SuppressWarnings("deprecation") + OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(name); + return getOfflinePlayer(name, offlinePlayer.getUniqueId()); + } + + public static Player getOfflinePlayer(UUID uuid) { + OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(uuid); + return getOfflinePlayer(offlinePlayer.getName(), uuid); + } + + public static Player getOfflinePlayer(String name, UUID uuid) { VersionUtil versions = DungeonsXL.getPlugin().getVersion(); if (versions.getInternals() == Internals.v1_9_R1) { - return v1_9_R1.getOfflinePlayer(player, uuid); + return v1_9_R1.getOfflinePlayer(name, uuid); } else if (versions.getInternals() == Internals.v1_8_R3) { - return v1_8_R3.getOfflinePlayer(player, uuid); + return v1_8_R3.getOfflinePlayer(name, uuid); } else if (versions.getInternals() == Internals.v1_8_R2) { - return v1_8_R2.getOfflinePlayer(player, uuid); + return v1_8_R2.getOfflinePlayer(name, uuid); } else if (versions.getInternals() == Internals.v1_8_R1) { - return v1_8_R1.getOfflinePlayer(player, uuid); + return v1_8_R1.getOfflinePlayer(name, uuid); } else if (versions.getInternals() == Internals.v1_7_R4) { - return v1_7_R4.getOfflinePlayer(player, uuid); + return v1_7_R4.getOfflinePlayer(name, uuid); } else if (versions.getInternals() == Internals.v1_7_R3) { - return v1_7_R3.getOfflinePlayer(player, uuid); + return v1_7_R3.getOfflinePlayer(name, uuid); } else { return null; } } - public static Player getOfflinePlayer(String player, UUID uuid, Location location) { + public static Player getOfflinePlayer(String name, UUID uuid, Location location) { VersionUtil versions = DungeonsXL.getPlugin().getVersion(); if (versions.getInternals() == Internals.v1_9_R1) { - return v1_9_R1.getOfflinePlayer(player, uuid, location); + return v1_9_R1.getOfflinePlayer(name, uuid, location); } else if (versions.getInternals() == Internals.v1_8_R3) { - return v1_8_R3.getOfflinePlayer(player, uuid, location); + return v1_8_R3.getOfflinePlayer(name, uuid, location); } else if (versions.getInternals() == Internals.v1_8_R2) { - return v1_8_R2.getOfflinePlayer(player, uuid, location); + return v1_8_R2.getOfflinePlayer(name, uuid, location); } else if (versions.getInternals() == Internals.v1_8_R1) { - return v1_8_R1.getOfflinePlayer(player, uuid, location); + return v1_8_R1.getOfflinePlayer(name, uuid, location); } else if (versions.getInternals() == Internals.v1_7_R4) { - return v1_7_R4.getOfflinePlayer(player, uuid, location); + return v1_7_R4.getOfflinePlayer(name, uuid, location); } else if (versions.getInternals() == Internals.v1_7_R3) { - return v1_7_R3.getOfflinePlayer(player, uuid, location); + return v1_7_R3.getOfflinePlayer(name, uuid, location); } else { return null; diff --git a/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_7_R3.java b/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_7_R3.java index b139c5f6..da6c639e 100644 --- a/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_7_R3.java +++ b/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_7_R3.java @@ -16,18 +16,18 @@ import org.bukkit.entity.Player; class v1_7_R3 { - static Player getOfflinePlayer(String player, UUID uuid) { + static Player getOfflinePlayer(String name, UUID uuid) { Player pplayer = null; try { - File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); + File playerFolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); - for (File playerfile : playerfolder.listFiles()) { - String filename = playerfile.getName(); - String playername = filename.substring(0, filename.length() - 4); + for (File playerFile : playerFolder.listFiles()) { + String fileName = playerFile.getName(); + String playerName = fileName.substring(0, fileName.length() - 4); - GameProfile profile = new GameProfile(uuid, playername); + GameProfile profile = new GameProfile(uuid, playerName); - if (playername.trim().equalsIgnoreCase(player)) { + if (playerName.trim().equalsIgnoreCase(name)) { MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0))); Player target = entity == null ? null : (Player) entity.getBukkitEntity(); @@ -43,18 +43,18 @@ class v1_7_R3 { return pplayer; } - static Player getOfflinePlayer(String player, UUID uuid, Location location) { + static Player getOfflinePlayer(String name, UUID uuid, Location location) { Player pplayer = null; try { - File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); + File playerFolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); - for (File playerfile : playerfolder.listFiles()) { - String filename = playerfile.getName(); - String playername = filename.substring(0, filename.length() - 4); + for (File playerFile : playerFolder.listFiles()) { + String fileName = playerFile.getName(); + String playerName = fileName.substring(0, fileName.length() - 4); - GameProfile profile = new GameProfile(uuid, playername); + GameProfile profile = new GameProfile(uuid, playerName); - if (playername.trim().equalsIgnoreCase(player)) { + if (playerName.trim().equalsIgnoreCase(name)) { MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0))); entity.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); diff --git a/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_7_R4.java b/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_7_R4.java index c50fee13..a190aa80 100644 --- a/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_7_R4.java +++ b/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_7_R4.java @@ -16,18 +16,18 @@ import org.bukkit.entity.Player; class v1_7_R4 { - static Player getOfflinePlayer(String player, UUID uuid) { + static Player getOfflinePlayer(String name, UUID uuid) { Player pplayer = null; try { - File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); + File playerFolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); - for (File playerfile : playerfolder.listFiles()) { - String filename = playerfile.getName(); - String playername = filename.substring(0, filename.length() - 4); + for (File playerFile : playerFolder.listFiles()) { + String fileName = playerFile.getName(); + String playerName = fileName.substring(0, fileName.length() - 4); - GameProfile profile = new GameProfile(uuid, playername); + GameProfile profile = new GameProfile(uuid, playerName); - if (playername.trim().equalsIgnoreCase(player)) { + if (playerName.trim().equalsIgnoreCase(name)) { MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0))); Player target = entity == null ? null : (Player) entity.getBukkitEntity(); @@ -43,18 +43,18 @@ class v1_7_R4 { return pplayer; } - static Player getOfflinePlayer(String player, UUID uuid, Location location) { + static Player getOfflinePlayer(String name, UUID uuid, Location location) { Player pplayer = null; try { - File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); + File playerFolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); - for (File playerfile : playerfolder.listFiles()) { - String filename = playerfile.getName(); - String playername = filename.substring(0, filename.length() - 4); + for (File playerFile : playerFolder.listFiles()) { + String fileName = playerFile.getName(); + String playerName = fileName.substring(0, fileName.length() - 4); - GameProfile profile = new GameProfile(uuid, playername); + GameProfile profile = new GameProfile(uuid, playerName); - if (playername.trim().equalsIgnoreCase(player)) { + if (playerName.trim().equalsIgnoreCase(name)) { MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0))); entity.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); diff --git a/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_8_R1.java b/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_8_R1.java index 3feb37c9..8d6294a8 100644 --- a/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_8_R1.java +++ b/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_8_R1.java @@ -17,18 +17,18 @@ import com.mojang.authlib.GameProfile; class v1_8_R1 { - static Player getOfflinePlayer(String player, UUID uuid) { + static Player getOfflinePlayer(String name, UUID uuid) { Player pplayer = null; try { - File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); + File playerFolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); - for (File playerfile : playerfolder.listFiles()) { - String filename = playerfile.getName(); - String playername = filename.substring(0, filename.length() - 4); + for (File playerFile : playerFolder.listFiles()) { + String filename = playerFile.getName(); + String playerName = filename.substring(0, filename.length() - 4); - GameProfile profile = new GameProfile(uuid, playername); + GameProfile profile = new GameProfile(uuid, playerName); - if (playername.trim().equalsIgnoreCase(player)) { + if (playerName.trim().equalsIgnoreCase(name)) { MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0))); Player target = entity == null ? null : (Player) entity.getBukkitEntity(); @@ -44,18 +44,18 @@ class v1_8_R1 { return pplayer; } - static Player getOfflinePlayer(String player, UUID uuid, Location location) { + static Player getOfflinePlayer(String name, UUID uuid, Location location) { Player pplayer = null; try { - File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); + File playerFolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); - for (File playerfile : playerfolder.listFiles()) { - String filename = playerfile.getName(); - String playername = filename.substring(0, filename.length() - 4); + for (File playerFile : playerFolder.listFiles()) { + String filename = playerFile.getName(); + String playerName = filename.substring(0, filename.length() - 4); - GameProfile profile = new GameProfile(uuid, playername); + GameProfile profile = new GameProfile(uuid, playerName); - if (playername.trim().equalsIgnoreCase(player)) { + if (playerName.trim().equalsIgnoreCase(name)) { MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0))); entity.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); diff --git a/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_8_R2.java b/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_8_R2.java index 030e63d5..4b550060 100644 --- a/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_8_R2.java +++ b/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_8_R2.java @@ -17,18 +17,18 @@ import com.mojang.authlib.GameProfile; class v1_8_R2 { - static Player getOfflinePlayer(String player, UUID uuid) { + static Player getOfflinePlayer(String name, UUID uuid) { Player pplayer = null; try { - File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); + File playerFolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); - for (File playerfile : playerfolder.listFiles()) { - String filename = playerfile.getName(); - String playername = filename.substring(0, filename.length() - 4); + for (File playerFile : playerFolder.listFiles()) { + String fileName = playerFile.getName(); + String playerName = fileName.substring(0, fileName.length() - 4); - GameProfile profile = new GameProfile(uuid, playername); + GameProfile profile = new GameProfile(uuid, playerName); - if (playername.trim().equalsIgnoreCase(player)) { + if (playerName.trim().equalsIgnoreCase(name)) { MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0))); Player target = entity == null ? null : (Player) entity.getBukkitEntity(); @@ -44,18 +44,18 @@ class v1_8_R2 { return pplayer; } - static Player getOfflinePlayer(String player, UUID uuid, Location location) { + static Player getOfflinePlayer(String name, UUID uuid, Location location) { Player pplayer = null; try { - File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); + File playerFolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); - for (File playerfile : playerfolder.listFiles()) { - String filename = playerfile.getName(); - String playername = filename.substring(0, filename.length() - 4); + for (File playerFile : playerFolder.listFiles()) { + String fileName = playerFile.getName(); + String playerName = fileName.substring(0, fileName.length() - 4); - GameProfile profile = new GameProfile(uuid, playername); + GameProfile profile = new GameProfile(uuid, playerName); - if (playername.trim().equalsIgnoreCase(player)) { + if (playerName.trim().equalsIgnoreCase(name)) { MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0))); entity.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); diff --git a/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_8_R3.java b/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_8_R3.java index 419cb2ac..67ea5913 100644 --- a/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_8_R3.java +++ b/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_8_R3.java @@ -17,18 +17,18 @@ import com.mojang.authlib.GameProfile; class v1_8_R3 { - static Player getOfflinePlayer(String player, UUID uuid) { + static Player getOfflinePlayer(String name, UUID uuid) { Player pplayer = null; try { - File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); + File playerFolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); - for (File playerfile : playerfolder.listFiles()) { - String filename = playerfile.getName(); - String playername = filename.substring(0, filename.length() - 4); + for (File playerFile : playerFolder.listFiles()) { + String fileName = playerFile.getName(); + String playerName = fileName.substring(0, fileName.length() - 4); - GameProfile profile = new GameProfile(uuid, playername); + GameProfile profile = new GameProfile(uuid, playerName); - if (playername.trim().equalsIgnoreCase(player)) { + if (playerName.trim().equalsIgnoreCase(name)) { MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0))); Player target = entity == null ? null : (Player) entity.getBukkitEntity(); @@ -44,18 +44,18 @@ class v1_8_R3 { return pplayer; } - static Player getOfflinePlayer(String player, UUID uuid, Location location) { + static Player getOfflinePlayer(String name, UUID uuid, Location location) { Player pplayer = null; try { - File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); + File playerFolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); - for (File playerfile : playerfolder.listFiles()) { - String filename = playerfile.getName(); - String playername = filename.substring(0, filename.length() - 4); + for (File playerFile : playerFolder.listFiles()) { + String fileName = playerFile.getName(); + String playerName = fileName.substring(0, fileName.length() - 4); - GameProfile profile = new GameProfile(uuid, playername); + GameProfile profile = new GameProfile(uuid, playerName); - if (playername.trim().equalsIgnoreCase(player)) { + if (playerName.trim().equalsIgnoreCase(name)) { MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0))); entity.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); diff --git a/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_9_R1.java b/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_9_R1.java index 4d1ca647..dd98b00e 100644 --- a/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_9_R1.java +++ b/src/io/github/dre2n/dungeonsxl/util/playerutil/v1_9_R1.java @@ -17,18 +17,18 @@ import com.mojang.authlib.GameProfile; class v1_9_R1 { - static Player getOfflinePlayer(String player, UUID uuid) { + static Player getOfflinePlayer(String name, UUID uuid) { Player pplayer = null; try { - File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); + File playerFolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); - for (File playerfile : playerfolder.listFiles()) { - String filename = playerfile.getName(); - String playername = filename.substring(0, filename.length() - 4); + for (File playerFile : playerFolder.listFiles()) { + String fileName = playerFile.getName(); + String playerName = fileName.substring(0, fileName.length() - 4); - GameProfile profile = new GameProfile(uuid, playername); + GameProfile profile = new GameProfile(uuid, playerName); - if (playername.trim().equalsIgnoreCase(player)) { + if (playerName.trim().equalsIgnoreCase(name)) { MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0))); Player target = entity == null ? null : (Player) entity.getBukkitEntity(); @@ -44,18 +44,18 @@ class v1_9_R1 { return pplayer; } - static Player getOfflinePlayer(String player, UUID uuid, Location location) { + static Player getOfflinePlayer(String name, UUID uuid, Location location) { Player pplayer = null; try { - File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); + File playerFolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); - for (File playerfile : playerfolder.listFiles()) { - String filename = playerfile.getName(); - String playername = filename.substring(0, filename.length() - 4); + for (File playerFile : playerFolder.listFiles()) { + String fileName = playerFile.getName(); + String playerName = fileName.substring(0, fileName.length() - 4); - GameProfile profile = new GameProfile(uuid, playername); + GameProfile profile = new GameProfile(uuid, playerName); - if (playername.trim().equalsIgnoreCase(player)) { + if (playerName.trim().equalsIgnoreCase(name)) { MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0))); entity.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); diff --git a/src/plugin.yml b/src/plugin.yml index 2d878849..aae5283e 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -22,6 +22,10 @@ permissions: default: op dxl.escape: default: true + dxl.group: + default: op + dxl.group.admin: + default: op dxl.help: default: true dxl.invite: