diff --git a/.github/PULL_REQUEST_TEMPLATE b/.github/PULL_REQUEST_TEMPLATE new file mode 100644 index 000000000..bcaa0058b --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE @@ -0,0 +1,21 @@ + +### PR guidelines + +- Everything needs to be tested. This can be done with or without QA as appropriate. When in doubt, _ask_. +- Skim over your diff at least once before submitting. By skimming over the diff, you may catch glaring errors, merge issues, etc. that may otherwise waste time in code review. + +Fill out the form below (replace the space between the brackets with an `x` if the statement is accurate). The provided release notes will appear in #pc-release. + +(You may delete the following divider and everything above it) + +--- + +- [ ] I have tested, to the best of my ability, the changes being submitted. + +Public release notes: +- One +- Two +- Threeee + +Internal / private release notes (if applicable): +- Four diff --git a/Plugins/Mineplex.Core/src/mineplex/core/anvilMenu/PlayerInputActionMenu.java b/Plugins/Mineplex.Core/src/mineplex/core/anvilMenu/PlayerInputActionMenu.java new file mode 100644 index 000000000..2976e2b00 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/anvilMenu/PlayerInputActionMenu.java @@ -0,0 +1,166 @@ +package mineplex.core.anvilMenu; + +import mineplex.core.MiniPlugin; +import mineplex.core.account.CoreClientManager; +import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.party.Party; +import mineplex.core.party.PartyManager; +import net.minecraft.server.v1_8_R3.*; +import org.apache.commons.lang.StringUtils; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.inventory.Inventory; + +import static sun.audio.AudioPlayer.player; + +/** + * A utility class for creating simple and easy Anvil GUI's that require actions based on a users input. + */ +public abstract class PlayerInputActionMenu implements Listener +{ + + protected MiniPlugin _plugin; + protected Player _player; + protected Inventory _currentInventory; + protected String _itemName = ""; + protected boolean _searching; + protected Party _party; + + public PlayerInputActionMenu(MiniPlugin plugin, Player player, Party party) + { + _player = player; + _plugin = plugin; + _party = party; + player.closeInventory(); + _plugin.registerEvents(this); + } + + public abstract void inputReceived(String name); + + @EventHandler + public void onInventoryClose(InventoryCloseEvent event) + { + if (event.getPlayer() == _player) + { + unregisterListener(); + } + } + + public void unregisterListener() + { + if(_currentInventory != null) + { + _currentInventory.clear(); + } + HandlerList.unregisterAll(this); + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) + { + if (event.getPlayer() == _player) + { + unregisterListener(); + } + } + + @EventHandler + public void onInventoryClick(InventoryClickEvent event) + { + if (event.getRawSlot() < 3) + { + event.setCancelled(true); + + if (event.getRawSlot() == 2) + { + if (_itemName.length() > 1 && !_searching) + { + _searching = true; + inputReceived(_itemName); + } else + { + _player.playSound(_player.getLocation(), Sound.ITEM_BREAK, 1, .6f); + } + } + } else if (event.isShiftClick()) + { + event.setCancelled(true); + } + } + + public void openInventory() + { + + EntityPlayer p = ((CraftPlayer) _player).getHandle(); + + AnvilContainer container = new AnvilContainer(p); + int c = p.nextContainerCounter(); + + PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(c, "minecraft:anvil", new ChatMessage(Blocks.ANVIL.a() + ".name", new Object[0])); + + UtilPlayer.sendPacket(_player, packet); + + // Set their active container to the container + p.activeContainer = container; + + // Set their active container window id to that counter stuff + p.activeContainer.windowId = c; + + // Add the slot listener + p.activeContainer.addSlotListener(p); // Set the items to the items from the inventory given + _currentInventory = container.getBukkitView().getTopInventory(); + + _currentInventory.setItem(0, new ItemBuilder(Material.PAPER).setRawTitle("Input Text...").build()); + _currentInventory.setItem(2, new ItemBuilder(Material.PAPER).setRawTitle("Search").build()); + } + + private class AnvilContainer extends ContainerAnvil + { + private String n; + + public AnvilContainer(EntityHuman entity) + { + super(entity.inventory, entity.world, new BlockPosition(0, 0, 0), entity); + } + + @Override + public boolean a(EntityHuman entityhuman) + { + return true; + } + + @Override + public void a(String origString) + { + n = origString; + _itemName = origString; + + if (getSlot(2).hasItem()) + { + net.minecraft.server.v1_8_R3.ItemStack itemstack = getSlot(2).getItem(); + + if (StringUtils.isBlank(origString)) + { + itemstack.r(); + } else + { + itemstack.c(this.n); + } + } + + e(); + } + + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/anvilMenu/player/PlayerNameMenu.java b/Plugins/Mineplex.Core/src/mineplex/core/anvilMenu/player/PlayerNameMenu.java new file mode 100644 index 000000000..ab4999c54 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/anvilMenu/player/PlayerNameMenu.java @@ -0,0 +1,58 @@ +package mineplex.core.anvilMenu.player; + +import mineplex.core.MiniPlugin; +import mineplex.core.account.CoreClientManager; +import mineplex.core.anvilMenu.PlayerInputActionMenu; +import mineplex.core.common.util.C; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.party.Party; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Player; + +import static net.minecraft.server.v1_8_R3.PotionBrewer.n; + +/** + * A wrapped menu that handles looking for players specifically. + */ +public abstract class PlayerNameMenu extends PlayerInputActionMenu +{ + + protected CoreClientManager _clientManager; + + public PlayerNameMenu(MiniPlugin plugin, CoreClientManager clientManager, Player player, Party party) + { + super(plugin, player, party); + _clientManager = clientManager; + } + + public abstract void onSuccess(String name); + + public abstract void onFail(String name); + + @Override + public void inputReceived(String name) + { + if(Bukkit.getPlayer(name) != null) + { + onSuccess(Bukkit.getPlayer(name).getName()); + return; + } + _clientManager.checkPlayerName(_player, _itemName, result -> { + _searching = false; + + if (result != null) + { + onSuccess(result); + } else + { + onFail(name); + _currentInventory.setItem(2, new ItemBuilder(Material.PAPER) + .setTitle(C.cYellow + "0" + C.cGray + " matches for [" + C.cYellow + name + C.cGray + "]") + .build()); + _player.playSound(_player.getLocation(), Sound.ITEM_BREAK, 1, .6f); + } + }); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/Fountain.java b/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/Fountain.java index a7efd950b..471bfe8e2 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/Fountain.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/Fountain.java @@ -5,16 +5,20 @@ import mineplex.core.brawl.fountain.gui.FountainShop; import mineplex.core.common.SortedSchematicLoader; import mineplex.core.common.block.schematic.UtilSchematic; import mineplex.core.common.util.C; +import mineplex.core.common.util.Callback; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilText; import mineplex.core.donation.DonationManager; import mineplex.core.hologram.Hologram; import mineplex.core.hologram.HologramManager; import mineplex.core.stats.StatsManager; +import mineplex.core.thread.ThreadPool; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; +import mineplex.serverdata.Region; import mineplex.serverdata.redis.counter.GoalCounter; import mineplex.serverdata.redis.counter.GoalCounterListener; +import mineplex.serverdata.servers.ConnectionData; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -49,7 +53,7 @@ public class Fountain implements GoalCounterListener private final FountainShop _shop; - public Fountain(Location location, Location pasteLocation, String name, String dataKey, long goal, FountainManager fountainManager, + public Fountain(ConnectionData writeConnection, ConnectionData readConnection, Region region, Location location, Location pasteLocation, String name, String dataKey, long goal, FountainManager fountainManager, CoreClientManager clientManager, DonationManager donationManager, HologramManager hologramManager, StatsManager statsManager) { @@ -60,7 +64,7 @@ public class Fountain implements GoalCounterListener _dataKey = dataKey; _location = location; _hologram = new Hologram(hologramManager, location.clone().add(4, 3, -3), name).start(); - _counter = new GoalCounter(dataKey, 5000, goal); + _counter = new GoalCounter(writeConnection, readConnection, region, dataKey, goal); _counter.addListener(this); _brawlActive = false; // _blockProgressBar = new BlockProgressBar(_lavaLocation.getBlock(), Material.LAVA, BlockFace.UP); @@ -164,11 +168,16 @@ public class Fountain implements GoalCounterListener } } - public void increment(Player player, long amount) + public void increment(Player player, long amount, Callback callback) { _statsManager.incrementStat(player, getStatName(), amount); - _counter.addAndGet(amount); - updateVisuals(); + _statsManager.runAsync(() -> { + long count = _counter.addAndGet(amount); + _statsManager.runSync(() -> { + updateVisuals(); + if (callback != null) callback.run(count); + }); + }); } public long getAmountAdded(Player player) @@ -243,6 +252,11 @@ public class Fountain implements GoalCounterListener } } + public void updateCounter() + { + _counter.updateCount(); + } + public boolean isBrawlActive() { return _brawlActive; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/FountainManager.java b/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/FountainManager.java index 11e4cf821..d141e1997 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/FountainManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/FountainManager.java @@ -14,6 +14,7 @@ import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.serverdata.Region; import mineplex.serverdata.redis.counter.Counter; +import mineplex.serverdata.servers.ConnectionData; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; @@ -51,8 +52,10 @@ public class FountainManager extends MiniPlugin World world = Bukkit.getWorlds().get(0);//-43.5, 66, -38.5 - int goal = !new File("eu.dat").exists() ? 200000000 : 20000000; - _gemFountain = new Fountain(new Location(world, -32.5, 72, -23.5), new Location(world, -43.5, 67, -38.5), + int goal = 70000000;//!new File("eu.dat").exists() ? 200000000 : 20000000; + _gemFountain = new Fountain(new ConnectionData("10.3.203.80", 6379, ConnectionData.ConnectionType.MASTER, "USRedis"), + new ConnectionData("10.3.203.80", 6377, ConnectionData.ConnectionType.SLAVE, "USRedis"), Region.ALL, + new Location(world, -32.5, 72, -23.5), new Location(world, -43.5, 67, -38.5), C.cGreen + "Gem Fountain", "GemFountain_01", goal, this, clientManager, donationManager, _hologramManager, _statsManager); } @@ -72,6 +75,15 @@ public class FountainManager extends MiniPlugin _gemFountain.updateVisuals(); } + @EventHandler + public void updateCounter(UpdateEvent event) + { + if (event.getType() != UpdateType.SEC_05) + return; + + runAsync(_gemFountain::updateCounter); + } + @EventHandler public void onInteractAtEntity(PlayerInteractAtEntityEvent event) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/command/AddCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/command/AddCommand.java index 1be61d068..cd1bf65a5 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/command/AddCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/command/AddCommand.java @@ -41,7 +41,7 @@ public class AddCommand extends CommandBase { if (result == TransactionResponse.Success) { - Plugin.getGemFountain().increment(caller, amount); + Plugin.getGemFountain().increment(caller, amount, null); UtilPlayer.message(caller, F.main("Fountain", "Added " + F.elem(amount) + " to the fountain!")); } else if (result == TransactionResponse.InsufficientFunds) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/gui/button/FountainAddButton.java b/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/gui/button/FountainAddButton.java index 9460025c1..c37c8c551 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/gui/button/FountainAddButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/gui/button/FountainAddButton.java @@ -34,7 +34,7 @@ public class FountainAddButton implements IButton { public void run() { - _page.getPlugin().getGemFountain().increment(player, _gems); + _page.getPlugin().getGemFountain().increment(player, _gems, null); _page.refresh(); } }, _page, _salesPackage, CurrencyType.GEM, player)); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/InviteData.java b/Plugins/Mineplex.Core/src/mineplex/core/party/InviteData.java new file mode 100644 index 000000000..b401da6d1 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/InviteData.java @@ -0,0 +1,27 @@ +package mineplex.core.party; + +/** + * Serializable invite data + */ +public class InviteData +{ + + private String _invitedTo; + private String _serverFrom; + + public InviteData(String invitedTo, String serverFrom) + { + _invitedTo = invitedTo; + _serverFrom = serverFrom; + } + + public String getInvitedTo() + { + return _invitedTo; + } + + public String getServerFrom() + { + return _serverFrom; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/Lang.java b/Plugins/Mineplex.Core/src/mineplex/core/party/Lang.java new file mode 100644 index 000000000..0cccd2bc9 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/Lang.java @@ -0,0 +1,99 @@ +package mineplex.core.party; + +import mineplex.core.common.util.C; +import org.bukkit.entity.Player; + +import java.text.MessageFormat; + +/** + * All chat messages for the party system to align with PE + */ +public enum Lang +{ + + //Party + SUCCESS_SERVER_CONNECT("Sending you and your party to {0}..."), + INVITE_SUCCESS_PLAYER("Successfully invited {0} to the party."), + SUCCESS_INVITE("{0} has invited {1} to the party."), + INVITE_RECEIVED("You have been invited to {0}''s party! You have 60 seconds to reply."), + INVITE_ACCEPT("{0} has joined the party."), + INVITE_DENY("{0} declined your invite."), + INVITE_EXPIRED("{0} did not respond in time."), + INVITE_EXPIRED_PLAYER("Your invite to {0}'s party has expired."), + + SHOW_MEMBERS("Party members: {0}."), + REMOVE_PLAYER("{0} has left the party."), + REMOVE_PLAYER_KICK("{0} has been removed from the party."), + ADD_MEMBER("{0} has joined the party."), + LEFT("You have left your party."), + PARTY_OWNER_LEAVE("{0} has left the party. {1} is the new party owner."), + TRANSFER_OWNER("{0} has given party leadership to {1}."), + DISBANDED("Your party has been disbanded, due to a lack of players."), + DISBANDED_BY_OWNER("Your party has been disbanded!"), + REMOVED("You have been removed from the party."), + + NOT_EXIST("Error: {0} is not in a party right now."), + ALREADY_MEMBER("Error: {0} is already in the party!"), + NO_PARTY("Error: You are not in a party!"), + ALREADY_IN("Error: You are already in a party!"), + NOT_MEMBER("Error: {0} is not a member of your party."), + NOT_INVITED("Error: You do not have a pending invite to {0}'s party."), + NOT_OWNER("Error: You must be the party owner to do this!"), + NOT_OWNER_SERVER("Error: You must be the owner to move servers!"), + ALREADY_INVITED("Error: {0} has already been invited."), + PARTY_FULL("Error: Your party is full!"), + SERVER_CLOSED("Error: Your server is closed and you cannot invite players to join it right now!"), + SERVER_FULL("Error: Your server is full and you cannot invite more players to join it right now!"), + PLAYER_IN_DIFFERENT_PARTY("Error: {0} is in a different party.") + + ; + + private String _message; + + Lang(String message) + { + _message = message; + } + + public void send(Player player, String... args) + { + player.sendMessage(C.mHead + "Party> " + getFormatted(args)); + } + + public void send(Party party, String... args) + { + party.sendMessage(C.mHead + "Party> " + getFormatted(args)); + } + + private String getFormatted(String[] args) + { + String color = C.mBody; + + if(args.length == 0) + { + return color + _message; + } + + if(_message.startsWith("Error:")) + { + color = C.cRed; + } + + int firstIndex = _message.indexOf("{"); + + String[] coloredArgs = new String[args.length]; + + for(int i = 0; i < args.length; i++) + { + coloredArgs[i] = C.cYellow + args[i] + color; + } + + String message = MessageFormat.format(_message, coloredArgs); + + String coloredRest = message.substring(firstIndex); + + message = color + message.substring(0, firstIndex) + coloredRest; + return message; + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java b/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java index baa697e0a..b5eb8ee63 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/Party.java @@ -1,439 +1,277 @@ package mineplex.core.party; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Iterator; - -import mineplex.core.common.Rank; -import mineplex.core.common.jsonchat.ChildJsonMessage; -import mineplex.core.common.jsonchat.ClickEvent; -import mineplex.core.common.jsonchat.JsonMessage; -import mineplex.core.common.util.C; -import mineplex.core.common.util.F; -import mineplex.core.common.util.NautHashMap; -import mineplex.core.common.util.UtilPlayer; -import mineplex.core.common.util.UtilTime; -import mineplex.core.party.redis.RedisPartyData; -import mineplex.serverdata.Region; -import mineplex.serverdata.commands.ServerTransfer; -import mineplex.serverdata.commands.TransferCommand; -import mineplex.serverdata.data.ServerGroup; -import mineplex.serverdata.servers.ServerManager; - +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import mineplex.core.common.util.UtilServer; +import mineplex.core.party.constants.PartyRemoveReason; +import mineplex.core.party.event.PartyTransferOwnerEvent; +import mineplex.core.party.event.PartyTransferOwnerEvent.TransferReason; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.Sound; import org.bukkit.entity.Player; -import org.bukkit.scoreboard.DisplaySlot; -import org.bukkit.scoreboard.Objective; -import org.bukkit.scoreboard.Scoreboard; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +/** + * The main object for Parites. + */ public class Party { - private PartyManager _manager; - private boolean _isHub; - private String _creator; - private String _previousServer; + /** + * This is controls whether or not the owner is currently in the menu, and kicking members + */ + private transient boolean _ownerKickMode = false; - private ArrayList _players = new ArrayList(); - private NautHashMap _invitee = new NautHashMap(); + /** + * Asserts if this party has already been put into teams in order to prevent the Arcade from reassigning teams + */ + private transient boolean _alreadyTeamed = false; - private Scoreboard _scoreboard; - private Objective _scoreboardObj; - private ArrayList _scoreboardLast = new ArrayList(); + /** + * The standard size for parties, for ALL {@code {@link mineplex.core.common.Rank}} + */ + private static final int PARTY_MIN_SIZE = 5; - private long _partyOfflineTimer = -1; - private long _informNewLeaderTimer = -1; + /** + * An upgraded size for the party, given to donators and staff. + */ + private static final int PARTY_MAX_SIZE = 10; - public Party(PartyManager manager, RedisPartyData partyData) + /** + * The current leader of this party + */ + private String _owner; + + /** + * The names of all current party members + */ + private List _members; + + /** + * The UUIDS of all current party members + */ + private List _membersByUUID; + + /** + * All current pending invites + */ + private Map _invites; + + /** + * This party's max size + */ + private int _size; + + /** + * Empty constructor for GSON + */ + public Party() { - this(manager); - _players = new ArrayList(Arrays.asList(partyData.getPlayers())); - _creator = partyData.getLeader(); - _previousServer = partyData.getPreviousServer(); } - public Party(PartyManager manager) + /** + * Creates a new fresh party instance + * + * @param owner The owner / leader of the party. + */ + public Party(String owner) { - _manager = manager; - Region region = manager.getPlugin().getConfig().getBoolean("serverstatus.us") ? Region.US : Region.EU; - String groupName = manager.getPlugin().getConfig().getString("serverstatus.group"); + _owner = owner; + _members = Lists.newArrayList(); + _invites = Maps.newHashMap(); + _members.add(owner); + _membersByUUID = Lists.newArrayList(); + } - ServerGroup serverGroup = ServerManager.getServerRepository(region).getServerGroup(groupName); + public String getOwner() + { + return _owner; + } - if (serverGroup == null) + /** + * Get the current members by their IGN + * + * @return The list of named party members + */ + public List getMembers() + { + return _members; + } + + public Map getInvites() + { + return _invites; + } + + /** + * An alternate method to get the owner of the party. + * While this does not have any difference to using {@code getOwner}, it may serve a purpose in the future, should we wish to allow + * donators to name their party something custom. + * + * @return This party's name + */ + public String getName() + { + return _owner; + } + + /** + * Send's a message to the party + * + * @param message The string message to send to all players in the party + */ + public void sendMessage(String message) + { + getMembers().stream().map(Bukkit::getPlayer).forEach(player -> player.sendMessage(message)); + } + + public int getSize() + { + return _size; + } + + /** + * Set's this party's size cap base off the current players rank + * + */ + public void setSize() + { + _size = PARTY_MAX_SIZE; + } + + /** + * Called when a player is added to the party. + * + * @param player The name of the player + */ + public void onPlayerAdd(String player) + { + _invites.remove(player); + if(_members.contains(player)) + { return; - - _isHub = !serverGroup.getArcadeGroup(); - - if (_isHub) + } + _members.add(player); + Lang.ADD_MEMBER.send(this, player); + getMembers().forEach(s -> { - // Scoreboard - _scoreboard = Bukkit.getScoreboardManager().getNewScoreboard(); - _scoreboardObj = _scoreboard.registerNewObjective("Party", "dummy"); - _scoreboardObj.setDisplaySlot(DisplaySlot.SIDEBAR); + Player player1 = Bukkit.getPlayer(s); + player1.playSound(player1.getLocation(), Sound.NOTE_PLING, 1.0F, 10.0F); + }); + } - _scoreboard.registerNewTeam(ChatColor.GREEN + "Members"); - - // Scoreboard Ranks - for (Rank rank : Rank.values()) + /** + * Called when a member of the party is removed + * + * @param player The name of the player + * @param reason The reason for his removal. + */ + public void onPlayerRemove(String player, PartyRemoveReason reason) + { + if(reason == PartyRemoveReason.DISBANDED) + { + Player bukkitPlayer = Bukkit.getPlayerExact(player); + Lang.DISBANDED.send(bukkitPlayer); + bukkitPlayer.closeInventory(); + return; + } + if(_members.size() <= 0) + { + return; + } + if(reason == PartyRemoveReason.LEFT) + { + if(player.equalsIgnoreCase(_owner) && _members.size() > 1) { - if (rank != Rank.ALL) - _scoreboard.registerNewTeam(rank.Name).setPrefix(rank.getTag(true, true) + ChatColor.RESET + " "); - else - _scoreboard.registerNewTeam(rank.Name).setPrefix(""); + _owner = _members.get(0); + Lang.TRANSFER_OWNER.send(this, player, _owner); + PartyTransferOwnerEvent event = new PartyTransferOwnerEvent(this, _owner, player, TransferReason.LEFT); + UtilServer.getServer().getPluginManager().callEvent(event); + return; } + Lang.REMOVE_PLAYER.send(this, player); + return; + } + if(reason == PartyRemoveReason.OTHER) + { + return; + } + if(reason == PartyRemoveReason.KICKED) + { + Lang.REMOVE_PLAYER_KICK.send(this, player); + } + } - _scoreboard.registerNewTeam("Party").setPrefix(ChatColor.LIGHT_PURPLE + C.Bold + "Party" + ChatColor.RESET + " "); + /** + * Gets the current state of whether or not the owner is kicking people in the UI. + * + * @return true if the owner is kicking people + */ + public boolean isOwnerKickMode() + { + return _ownerKickMode; + } - // Add Players - for (Player player : Bukkit.getOnlinePlayers()) + /** + * Set's the current state of kicking players + * + * @param ownerKickMode true if the owner is kicking people + */ + public void setOwnerKickMode(boolean ownerKickMode) + { + _ownerKickMode = ownerKickMode; + } + + /** + * Set's the new owner for this party instance + * + * @param owner The new owner's name + */ + public void setOwner(String owner) + { + _owner = owner; + } + + /** + * Get a list of all members in the party by their UUID + * + * @return A list of members by UUID + */ + public List getMembersByUUID() + { + return _membersByUUID; + } + + public boolean alreadyTeamed() + { + return _alreadyTeamed; + } + + public void setAlreadyTeamed(boolean alreadyTeamed) + { + _alreadyTeamed = alreadyTeamed; + } + + /** + * Check to see if this party contains a certain player name + * This is case-insensitive + * + * @param name The players name + * @return true If the player is in the party + */ + public boolean contains(String name) + { + for(String s : _members) + { + if(s.equalsIgnoreCase(name)) { - _scoreboard.getTeam(_manager.GetClients().Get(player).GetRank().Name).addPlayer(player); + return true; } } - } - - public void JoinParty(Player player) - { - // Add Leader - if (_players.isEmpty()) - { - _players.add(player.getName()); - - UtilPlayer.message(player, F.main("Party", "You created a new Party.")); - - _creator = player.getName(); - } - else - { - _players.add(player.getName()); - _invitee.remove(player.getName()); - - Announce(F.elem(player.getName()) + " has joined the party!"); - } - - if (_isHub) - { - _scoreboard.getTeam("Party").addPlayer(player); - } - } - - public void InviteParty(Player player, boolean inviteeInParty) - { - _invitee.put(player.getName(), System.currentTimeMillis()); - - // Decline - if (_players.contains(player.getName())) - { - UtilPlayer.message(player, F.main("Party", F.name(player.getName()) + " is already in the Party.")); - player.playSound(player.getLocation(), Sound.NOTE_BASS, 1f, 1.5f); - } - - // Announce - Announce(F.name(player.getName()) + " has been invited to your Party."); - - // Inform - UtilPlayer.message(player, F.main("Party", F.name(GetLeader()) + " invited you to their Party.")); - - // Instruct - if (inviteeInParty) - { - ChildJsonMessage message = new JsonMessage("").extra(C.mHead + "Party> " + C.mBody + "Type "); - - message.add(F.link("/party leave")).click(ClickEvent.RUN_COMMAND, "/party leave"); - - message.add(C.mBody + " then "); - - message.add(F.link("/party " + GetLeader())).click(ClickEvent.RUN_COMMAND, "/party " + GetLeader()); - - message.add(C.mBody + " to join."); - - message.sendToPlayer(player); - } - else - { - ChildJsonMessage message = new JsonMessage("").extra(C.mHead + "Party> " + C.mBody + "Type "); - - message.add(F.link("/party " + GetLeader())).click(ClickEvent.RUN_COMMAND, "/party " + GetLeader()); - - message.add(C.mBody + " to join."); - - message.sendToPlayer(player); - } - - player.playSound(player.getLocation(), Sound.NOTE_PLING, 1f, 1.5f); - } - - public void LeaveParty(Player player) - { - // Announce - Announce(F.name(player.getName()) + " has left the Party."); - - boolean leader = player.equals(GetLeader()); - - _players.remove(player.getName()); - - if (_isHub) - { - // Set Scoreboard - _scoreboard.getTeam(_manager.GetClients().Get(player).GetRank().Name).addPlayer(player); - } - - if (leader && _players.size() > 0) - { - Announce("Party Leadership passed on to " + F.name(GetLeader()) + "."); - } - } - - public void KickParty(String player) - { - // Announce - Announce(F.name(player) + " was kicked from the Party."); - - _players.remove(player); - } - - public void PlayerJoin(Player player) - { - if (_isHub) - { - // Scoreboard - if (_players.contains(player.getName())) - _scoreboard.getTeam("Party").addPlayer(player); - else if (_manager.GetClients().Get(player) != null) - _scoreboard.getTeam(_manager.GetClients().Get(player).GetRank().Name).addPlayer(player); - } - - if (_creator.equals(player.getName())) - { - _players.remove(player.getName()); - _players.add(0, player.getName()); - - if (_informNewLeaderTimer < System.currentTimeMillis()) - { - Announce("Party Leadership returned to " + F.name(GetLeader()) + "."); - } - - if (_previousServer != null) - { - for (String playerName : _players) - { - Player p = Bukkit.getPlayerExact(playerName); - - if (p != null) - { - continue; - } - - TransferCommand transferCommand = new TransferCommand( - new ServerTransfer(playerName, _manager.getServerName())); - - transferCommand.setTargetServers(_previousServer); - - transferCommand.publish(); - } - - _previousServer = null; - } - } - } - - // Shuffle Leader - public void PlayerQuit(Player player) - { - if (player.getName().equals(GetLeader())) - { - _players.remove(player.getName()); - _players.add(player.getName()); - - if (_informNewLeaderTimer < System.currentTimeMillis()) - { - Announce("Party Leadership passed on to " + F.name(GetLeader()) + "."); - } - } - } - - public void Announce(String message) - { - for (String name : _players) - { - Player player = UtilPlayer.searchExact(name); - - if (player != null && player.isOnline()) - { - UtilPlayer.message(player, F.main("Party", message)); - player.playSound(player.getLocation(), Sound.NOTE_PLING, 1f, 1.5f); - } - } - } - - public void ExpireInvitees() - { - Iterator inviteeIterator = _invitee.keySet().iterator(); - - while (inviteeIterator.hasNext()) - { - String name = inviteeIterator.next(); - - if (UtilTime.elapsed(_invitee.get(name), 60000)) - { - Announce(F.name(name) + " did not respond to the Party invite."); - inviteeIterator.remove(); - } - } - } - - public String GetLeader() - { - if (_players.isEmpty()) - return _creator; - - return _players.get(0); - } - - public Collection GetPlayers() - { - return _players; - } - - public Collection GetPlayersOnline() - { - ArrayList players = new ArrayList(); - - for (String name : _players) - { - Player player = UtilPlayer.searchExact(name); - if (player != null) - players.add(player); - } - - return players; - } - - public Collection GetInvitees() - { - return _invitee.keySet(); - } - - public void UpdateScoreboard() - { - if (_isHub) - { - _scoreboardObj.setDisplayName(GetLeader() + "'s Party"); - - // Clear Past - for (String pastLine : _scoreboardLast) - _scoreboard.resetScores(pastLine); - _scoreboardLast.clear(); - - int i = 16; - - // Add New - for (int j = 0; j < _players.size(); j++) - { - String name = _players.get(j); - Player player = UtilPlayer.searchExact(name); - - ChatColor col = ChatColor.GREEN; - if (player == null) - col = ChatColor.RED; - - String line = col + name; - - if (line.length() > 16) - line = line.substring(0, 16); - - _scoreboardObj.getScore(line).setScore(i); - - _scoreboardLast.add(line); - - i--; - } - - // Add New - for (String name : _invitee.keySet()) - { - int time = 1 + (int) ((60000 - (System.currentTimeMillis() - _invitee.get(name))) / 1000); - - String line = time + " " + ChatColor.GRAY + name; - - if (line.length() > 16) - line = line.substring(0, 16); - - _scoreboardObj.getScore(line).setScore(i); - - _scoreboardLast.add(line); - - i--; - } - - // Set Scoreboard - for (String name : _players) - { - Player player = UtilPlayer.searchExact(name); - - if (player != null) - { - if (!player.getScoreboard().equals(_scoreboard)) - { - player.setScoreboard(_scoreboard); - } - } - } - } - } - - public boolean IsDead() - { - if (_players.size() == 0) - return true; - - if (_players.size() == 1 && _invitee.size() == 0) - return true; - - int online = 0; - for (String name : _players) - { - Player player = UtilPlayer.searchExact(name); - if (player != null) - online++; - } - - // One or Less Members Online - Expirey Countdown - if (online <= 1) - { - if (_partyOfflineTimer == -1) - { - _partyOfflineTimer = System.currentTimeMillis(); - } - else - { - if (UtilTime.elapsed(_partyOfflineTimer, online == 0 ? 5000 : 120000)) // 5 seconds for no players, 2 minutes if - // one player. - { - return true; - } - } - } - else if (_partyOfflineTimer > 0) - { - _partyOfflineTimer = -1; - } - return false; } - - public void resetWaitingTime() - { - _partyOfflineTimer = -1; - } - - public void switchedServer() - { - _informNewLeaderTimer = System.currentTimeMillis() + 5000; - } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyEventListener.java b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyEventListener.java new file mode 100644 index 000000000..a6cb19271 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyEventListener.java @@ -0,0 +1,153 @@ +package mineplex.core.party; + +import mineplex.core.common.Rank; +import mineplex.core.party.constants.PartyRemoveReason; +import mineplex.core.party.event.PartyMemberKickGUIEvent; +import mineplex.core.party.event.PartyTransferOwnerEvent; +import mineplex.core.party.ui.Menu; +import mineplex.core.portal.ServerTransferEvent; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +/** + * Event handler for Parties + */ +public class PartyEventListener implements Listener +{ + + private final PartyManager _plugin; + + public PartyEventListener(PartyManager plugin) + { + _plugin = plugin; + _plugin.getPluginManager().registerEvents(this, plugin.getPlugin()); + } + + @EventHandler + public void onJoin(PlayerJoinEvent event) + { + Player player = event.getPlayer(); + + player.getInventory().setItem(PartyManager.INTERFACE_SLOT, PartyManager.INTERFACE_ITEM); + + String partyName = _plugin.getInviteManager().getPartyWaiting(player.getUniqueId()); + + if (partyName == null) + { + return; + } + + Party party = _plugin.getParty(partyName); + + Player bukkitPlayer = Bukkit.getPlayerExact(partyName); + + if (party == null) + { + party = new Party(partyName); + + if (bukkitPlayer != null && _plugin.getClientManager().Get(bukkitPlayer).GetRank().has(Rank.ULTRA)) + { + party.setSize(); + } else + { + party.setSize(); + } + + _plugin.addParty(party); + } + + _plugin.getInviteManager().cancelTask(player.getUniqueId()); + + _plugin.getMethodManager().addToParty(Bukkit.getPlayerExact(partyName), party); + + _plugin.getMethodManager().addToParty(player, party); + + _plugin.getInviteManager().removeFromWaiting(player.getUniqueId()); + + } + + @EventHandler + public void onQuit(PlayerQuitEvent event) + { + Player player = event.getPlayer(); + + Party party = _plugin.getParty(player); + + _plugin.getInviteManager().removeAll(player.getUniqueId()); + + if (party == null) + { + return; + } + + PartyRemoveReason reason = PartyRemoveReason.LEFT; + + if(_plugin.getJoinManager().isTransferring(player)) + { + reason = PartyRemoveReason.OTHER; + } + + _plugin.getMethodManager().removeFromParty(player, reason); + } + + + @EventHandler + public void onTransferOwner(PartyTransferOwnerEvent event) + { + _plugin.getMethodManager().transferOwner(event.getNewOwner(), event.getOldOwner()); + } + + @EventHandler + public void onKick(PartyMemberKickGUIEvent event) + { + Player clicked = Bukkit.getPlayerExact(event.getPlayerClicked()); + Lang.REMOVED.send(clicked); + _plugin.getMethodManager().removeFromParty(clicked, PartyRemoveReason.KICKED); + Menu.get(event.getOwner().getUniqueId()).resetAndUpdate(event.getOwner()); + } + + @EventHandler + public void onTransfer(ServerTransferEvent event) + { + Player player = event.getPlayer(); + Party party = _plugin.getParty(player); + + if (party == null) + { + return; + } + + if(event.isDraggedByParty()) + { + return; + } + + event.setCancel(true); + + if (!party.getOwner().equalsIgnoreCase(player.getName())) + { + Lang.NOT_OWNER_SERVER.send(player); + return; + } + + _plugin.getJoinManager().requestServerJoin(event.getServer(), party); + + } + + @EventHandler + public void onClick(PlayerInteractEvent event) + { + if(event.hasItem() && event.getItem().getType() == Material.NAME_TAG) + { + event.setCancelled(true); + event.getPlayer().chat("/party"); + } + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java index b79283d76..918d3f8b6 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/PartyManager.java @@ -1,73 +1,129 @@ package mineplex.core.party; -import java.util.HashSet; -import java.util.Iterator; - +import com.google.common.collect.Maps; import mineplex.core.MiniPlugin; import mineplex.core.account.CoreClientManager; -import mineplex.core.common.util.NautHashMap; -import mineplex.core.party.commands.PartyCommand; -import mineplex.core.party.redis.RedisPartyData; -import mineplex.core.party.redis.RedisPartyHandler; +import mineplex.core.common.util.C; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.party.command.PartyCommand; +import mineplex.core.party.manager.PartyInviteManager; +import mineplex.core.party.manager.PartyJoinManager; +import mineplex.core.party.manager.PartyMethodManager; +import mineplex.core.party.manager.PartyRedisManager; +import mineplex.core.party.ui.MenuListener; import mineplex.core.portal.Portal; -import mineplex.core.portal.ServerTransferEvent; import mineplex.core.preferences.PreferencesManager; -import mineplex.core.updater.UpdateType; -import mineplex.core.updater.event.UpdateEvent; -import mineplex.serverdata.commands.ServerCommandManager; - +import mineplex.serverdata.Utility; +import mineplex.serverdata.servers.ServerManager; +import org.bukkit.Material; import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; +import java.util.Map; +import java.util.UUID; + public class PartyManager extends MiniPlugin { - private CoreClientManager _clientManager; - private PreferencesManager _preferenceManager; - private Portal _portal; - private String _serverName; - public NautHashMap _partyLeaderMap = new NautHashMap(); + /** + * The item given to a player in his hotbar to manage the Parties via the new UI. + */ + public static final ItemStack INTERFACE_ITEM = new ItemBuilder(Material.NAME_TAG).setTitle(C.cGreen + "Parties").build(); + /** + * The slow to which it goes in. + */ + public static final int INTERFACE_SLOT = 5; + + //Managers + private final Portal _portal; + private final CoreClientManager _clientManager; + private final PreferencesManager _preferencesManager; + private final PartyRedisManager _redisManager; + private final PartyInviteManager _inviteManager; + private final PartyJoinManager _joinManager; + private final PartyMethodManager _methodManager; + + /** + * This local instance's name + */ + private final String _serverName; + + /** + * A map of player's in parties server wide. + */ + private final Map _players = Maps.newHashMap(); + + /** + * A map of owner (name) -> party server wide + */ + private final Map _parties = Maps.newHashMap(); public PartyManager(JavaPlugin plugin, Portal portal, CoreClientManager clientManager, PreferencesManager preferenceManager) { - super("Party Manager", plugin); - + super("Parties", plugin); _portal = portal; _clientManager = clientManager; - _preferenceManager = preferenceManager; - _serverName = getPlugin().getConfig().getString("serverstatus.name"); + _preferencesManager = preferenceManager; - ServerCommandManager.getInstance().registerCommandType("RedisPartyData", RedisPartyData.class, - new RedisPartyHandler(this)); - } + _serverName = _plugin.getConfig().getString("serverstatus.name"); + + _redisManager = new PartyRedisManager(this, _serverName, + Utility.generatePool(ServerManager.getMasterConnection()), + Utility.generatePool(ServerManager.getSlaveConnection())); + + _inviteManager = new PartyInviteManager(this, _redisManager); + _joinManager = new PartyJoinManager(this); + _methodManager = new PartyMethodManager(this); - @Override - public void addCommands() - { addCommand(new PartyCommand(this)); + getPluginManager().registerEvents(new MenuListener(), getPlugin()); + new PartyEventListener(this); } - public CoreClientManager GetClients() + public Party getParty(String party) + { + return _parties.get(party); + } + + public Party getParty(Player player) + { + return _players.get(player.getUniqueId()); + } + + public void addParty(Party party) + { + _parties.put(party.getName(), party); + } + + public void removeParty(Party party) + { + _parties.remove(party.getName()); + } + + public Portal getPortal() + { + return _portal; + } + + public CoreClientManager getClientManager() { return _clientManager; } - public PreferencesManager getPreferenceManager() + public PreferencesManager getPreferencesManager() { - return _preferenceManager; + return _preferencesManager; } - public Party CreateParty(Player player) + public PartyRedisManager getRedisManager() { - Party party = new Party(this); - party.JoinParty(player); - _partyLeaderMap.put(player.getName(), party); + return _redisManager; + } - return party; + public PartyInviteManager getInviteManager() + { + return _inviteManager; } public String getServerName() @@ -75,107 +131,23 @@ public class PartyManager extends MiniPlugin return _serverName; } - public void addParty(Party party) + public PartyJoinManager getJoinManager() { - if (_partyLeaderMap.containsKey(party.GetLeader())) - _partyLeaderMap.get(party.GetLeader()).resetWaitingTime(); - else - _partyLeaderMap.put(party.GetLeader(), party); + return _joinManager; } - @EventHandler - public void serverTransfer(ServerTransferEvent event) + public PartyMethodManager getMethodManager() { - if (event.isDraggedByParty()) - return; - - Party party = _partyLeaderMap.get(event.getPlayer().getName()); - - if (party != null) - { - party.switchedServer(); - - RedisPartyData data = new RedisPartyData(party, _serverName); - data.setTargetServers(event.getServer()); - data.publish(); - - for (Player player : party.GetPlayersOnline()) - { - if (player != event.getPlayer()) - { - _portal.sendPlayerToServer(player, event.getServer(), true); - } - } - } + return _methodManager; } - @EventHandler(priority = EventPriority.MONITOR) - public void PlayerJoin(PlayerJoinEvent event) + public Map getPlayerParties() { - try - { - for (Party party : _partyLeaderMap.values()) - { - party.PlayerJoin(event.getPlayer()); - } - } - catch (Exception ex) - { - throw ex; - } + return _players; } - @EventHandler - public void PlayerQuit(PlayerQuitEvent event) + public Map getParties() { - for (Party party : _partyLeaderMap.values()) - { - party.PlayerQuit(event.getPlayer()); - } - } - - @EventHandler - public void Update(UpdateEvent event) - { - if (event.getType() != UpdateType.FAST) - return; - - ExpireParties(); - - for (Party party : _partyLeaderMap.values()) - { - party.ExpireInvitees(); - party.UpdateScoreboard(); - } - } - - public void ExpireParties() - { - Iterator partyIterator = _partyLeaderMap.values().iterator(); - - while (partyIterator.hasNext()) - { - Party party = partyIterator.next(); - - // Empty Party - if (party.IsDead()) - { - party.Announce("Your Party has been closed."); - partyIterator.remove(); - } - } - } - - public Party GetParty(Player player) - { - for (Party party : _partyLeaderMap.values()) - { - if (party.GetPlayers().contains(player.getName())) - { - return party; - } - } - - return null; + return _parties; } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java new file mode 100644 index 000000000..152a4eeaf --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java @@ -0,0 +1,95 @@ +package mineplex.core.party.command; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.party.Party; +import mineplex.core.party.PartyManager; +import mineplex.core.party.ui.menus.PartyInvitesMenu; +import mineplex.core.party.ui.menus.PartyMainMenu; +import mineplex.core.party.ui.menus.PartyOwnerMenu; +import mineplex.core.party.ui.menus.PartyViewMenu; +import org.bukkit.entity.Player; + +/** + * Command handler for party commands + */ +public class PartyCommand extends CommandBase +{ + + private final String[] HELP = { + F.main("Party", "Party Commands (Click the command!)"), + help("", "Brings up the Party GUI"), + help("", "Send an invitation to a player."), + help("leave", "Leave your current party."), + C.cBlue + "Party> " + C.cWhite + "# " + C.cGray + "- Send a message to your party.", + C.cGreenB + "All party functions have been moved to the GUI!", + C.cGreenB + "Click the NameTag in your hotbar to get started!" + }; + + public PartyCommand(PartyManager plugin) + { + super(plugin, Rank.ALL, "party", "z", "partyaccept", "partydeny", "openinvitesmenu", "partyinvite"); + } + + @Override + public void Execute(Player caller, String[] args) + { + if (args.length == 0) + { + if(_aliasUsed.equalsIgnoreCase("openinvitesmenu")) + { + new PartyInvitesMenu(Plugin).open(caller); + return; + } + Party party = Plugin.getParty(caller); + if (party == null) + { + new PartyMainMenu(Plugin).open(caller); + return; + } + if (party.getOwner().equalsIgnoreCase(caller.getName())) + { + new PartyOwnerMenu(party, Plugin).open(caller); + return; + } + new PartyViewMenu(party, Plugin).open(caller); + return; + } + + if(args.length == 1) + { + String arg = args[0]; + if (_aliasUsed.equalsIgnoreCase("partyaccept")) + { + Plugin.getMethodManager().respondToInvite(caller, arg, true); + return; + } + if (_aliasUsed.equalsIgnoreCase("partydeny")) + { + Plugin.getMethodManager().respondToInvite(caller, arg, false); + return; + } + if(_aliasUsed.equalsIgnoreCase("partyinvite")) + { + Plugin.getMethodManager().invite(caller, arg); + return; + } + if(arg.equalsIgnoreCase("leave")) { + Plugin.getMethodManager().leaveParty(caller); + return; + } + Plugin.getMethodManager().invite(caller, arg); + return; + } + caller.sendMessage(HELP); + } + + private String help(String command, String description) + { + return C.cBlue + "Party> " + C.cWhite + "/party " + command + C.cGray + " - " + description; + } + +} + diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/commands/PartyCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/party/commands/PartyCommand.java deleted file mode 100644 index 1c8fcbfbb..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/commands/PartyCommand.java +++ /dev/null @@ -1,177 +0,0 @@ -package mineplex.core.party.commands; - -import mineplex.core.command.CommandBase; -import mineplex.core.common.Rank; -import mineplex.core.common.jsonchat.ChildJsonMessage; -import mineplex.core.common.jsonchat.ClickEvent; -import mineplex.core.common.jsonchat.JsonMessage; -import mineplex.core.common.util.C; -import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilEnt; -import mineplex.core.common.util.UtilPlayer; -import mineplex.core.party.Party; -import mineplex.core.party.PartyManager; - -import org.bukkit.Bukkit; -import org.bukkit.Sound; -import org.bukkit.entity.Player; - -public class PartyCommand extends CommandBase -{ - public PartyCommand(PartyManager plugin) - { - super(plugin, Rank.ALL, new String[] - { - "party", "z" - }); - } - - @Override - public void Execute(Player caller, String[] args) - { - if (args == null || args.length == 0 || (args[0].equalsIgnoreCase("kick") && args.length < 2)) - { - UtilPlayer.message(caller, F.main("Party", "Listing Party Commands;")); - UtilPlayer.message(caller, F.value(0, "/party ", "Join/Create/Invite Player")); - UtilPlayer.message(caller, F.value(0, "/party leave", "Leave your current Party")); - UtilPlayer.message(caller, F.value(0, "/party kick ", "Kick player from your Party")); - - return; - } - - // Callers Party - Party party = Plugin.GetParty(caller); - - // Leave - if (args[0].equalsIgnoreCase("leave")) - { - if (party == null) - { - UtilPlayer.message(caller, F.main("Party", "You are not in a Party.")); - } - else - { - party.LeaveParty(caller); - } - - return; - } - - // Leave - if (args[0].equalsIgnoreCase("kick")) - { - if (party == null) - { - UtilPlayer.message(caller, F.main("Party", "You are not in a Party.")); - } - else - { - if (party.GetLeader().equals(caller.getName())) - { - String target = UtilPlayer.searchCollection(caller, args[1], party.GetPlayers(), "Party ", true); - if (target == null) - return; - - if (target.equals(caller.getName())) - { - UtilPlayer.message(caller, F.main("Party", "You cannot kick yourself from the Party.")); - return; - } - - party.KickParty(target); - } - else - { - UtilPlayer.message(caller, F.main("Party", "You are not the Party Leader.")); - } - } - - return; - } - - // Main - Player target = UtilPlayer.searchOnline(caller, args[0], true); - if (target == null) - return; - - if (target.equals(caller)) - { - UtilPlayer.message(caller, F.main("Party", "You cannot Party with yourself.")); - return; - } - - // Preference check - if (!Plugin.getPreferenceManager().Get(target).PartyRequests) - { - UtilPlayer.message( - caller, - F.main("Party", "You may not party with " + F.name(UtilEnt.getName(target)) - + "! They are not accepting party requests!")); - return; - } - - // Invite or Suggest - if (party != null) - { - if (party.GetPlayers().size() + party.GetInvitees().size() >= 16) - { - UtilPlayer.message(caller, "Your party cannot be larger than 16 players."); - caller.playSound(caller.getLocation(), Sound.NOTE_BASS, 1f, 1.5f); - } - // Decline - else if (party.GetPlayers().contains(target.getName())) - { - UtilPlayer.message(caller, F.main("Party", F.name(target.getName()) + " is already in the Party.")); - caller.playSound(caller.getLocation(), Sound.NOTE_BASS, 1f, 1.5f); - } - // Decline - else if (party.GetInvitees().contains(target.getName())) - { - UtilPlayer.message(caller, F.main("Party", F.name(target.getName()) + " is already invited to the Party.")); - caller.playSound(caller.getLocation(), Sound.NOTE_BASS, 1f, 1.5f); - } - // Invite - else if (party.GetLeader().equals(caller.getName())) - { - party.InviteParty(target, Plugin.GetParty(target) != null); - } - // Suggest - else - { - party.Announce(F.name(caller.getName()) + " suggested " + F.name(target.getName()) + " be invited to the Party."); - - Player leader = Bukkit.getPlayerExact(party.GetLeader()); - - if (leader != null) - { - ChildJsonMessage message = new JsonMessage("").extra(C.mHead + "Party> " + C.mBody + "Type "); - - message.add(F.link("/party " + target.getName())).click(ClickEvent.RUN_COMMAND, "/party " + target.getName()); - - message.add(C.mBody + " to invite them."); - - message.sendToPlayer(leader); - } - } - } - // Create or Join - else - { - Party targetParty = Plugin.GetParty(target); - - // Try to Join - if (targetParty != null) - { - if (targetParty.GetInvitees().contains(caller.getName())) - { - targetParty.JoinParty(caller); - return; - } - } - - // Create - party = Plugin.CreateParty(caller); - party.InviteParty(target, Plugin.GetParty(target) != null); - } - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/constants/InviteResponse.java b/Plugins/Mineplex.Core/src/mineplex/core/party/constants/InviteResponse.java new file mode 100644 index 000000000..30212e51d --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/constants/InviteResponse.java @@ -0,0 +1,27 @@ +package mineplex.core.party.constants; + +import mineplex.core.common.util.F; + +/** + * + */ +public enum InviteResponse +{ + + ACCEPTED("{0} has joined the party!"), + DENIED("{0} has declined joining your party."), + EXPIRED("{0} did not respond in time."); + + private String _message; + + InviteResponse(String message) + { + _message = message; + } + + public String format(String target) + { + return _message.replace("{0}", F.name(target)); + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/constants/JoinResponseReason.java b/Plugins/Mineplex.Core/src/mineplex/core/party/constants/JoinResponseReason.java new file mode 100644 index 000000000..56cd100e2 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/constants/JoinResponseReason.java @@ -0,0 +1,26 @@ +package mineplex.core.party.constants; + +import mineplex.core.common.util.F; + +/** + * + */ +public enum JoinResponseReason +{ + + CANNOT_JOIN_FULL(F.main("Party", "Your party cannot join full servers!")), + SUCCESS(""); + + private String _message; + + JoinResponseReason(String message) + { + _message = message; + } + + public String getMessage() + { + return _message; + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/constants/PartyRemoveReason.java b/Plugins/Mineplex.Core/src/mineplex/core/party/constants/PartyRemoveReason.java new file mode 100644 index 000000000..bff47e023 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/constants/PartyRemoveReason.java @@ -0,0 +1,15 @@ +package mineplex.core.party.constants; + +/** + * + */ +public enum PartyRemoveReason +{ + KICKED, + LEFT, + OTHER, + DISBANDED, + DISBANDED_BY_OWNER,; + + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/event/PartyDataReceivedEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/party/event/PartyDataReceivedEvent.java new file mode 100644 index 000000000..d4d25f699 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/event/PartyDataReceivedEvent.java @@ -0,0 +1,37 @@ +package mineplex.core.party.event; + +import mineplex.core.party.Party; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +/** + * An event called when a server receives a PartyPacket containing the information about a party + */ +public class PartyDataReceivedEvent extends Event +{ + private static final HandlerList HANDLER_LIST = new HandlerList(); + + private final Party _party; + + public PartyDataReceivedEvent(Party party) + { + _party = party; + } + + public Party getParty() + { + return _party; + } + + @Override + public HandlerList getHandlers() + { + return HANDLER_LIST; + } + + public static HandlerList getHandlerList() + { + return HANDLER_LIST; + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/event/PartyMemberKickGUIEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/party/event/PartyMemberKickGUIEvent.java new file mode 100644 index 000000000..885567240 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/event/PartyMemberKickGUIEvent.java @@ -0,0 +1,51 @@ +package mineplex.core.party.event; + +import mineplex.core.party.Party; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +/** + * This event is called when an owner clicks a PartyMemberIcon while having Kick mode activated. + */ +public class PartyMemberKickGUIEvent extends Event +{ + private static final HandlerList HANDLER_LIST = new HandlerList(); + + private final Party _party; + private final String _playerClicked; + private final Player _owner; + + public PartyMemberKickGUIEvent(Party party, String playerClicked, Player owner) + { + _party = party; + _playerClicked = playerClicked; + _owner = owner; + } + + public String getPlayerClicked() + { + return _playerClicked; + } + + public Player getOwner() + { + return _owner; + } + + public Party getParty() + { + return _party; + } + + @Override + public HandlerList getHandlers() + { + return HANDLER_LIST; + } + + public static HandlerList getHandlerList() + { + return HANDLER_LIST; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/event/PartySelectServerEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/party/event/PartySelectServerEvent.java new file mode 100644 index 000000000..1509dac3c --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/event/PartySelectServerEvent.java @@ -0,0 +1,36 @@ +package mineplex.core.party.event; + +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +/** + * This event is called when a party owner selects the compass icon. + */ +public class PartySelectServerEvent extends Event +{ + private static final HandlerList HANDLER_LIST = new HandlerList(); + + private final Player _player; + + public PartySelectServerEvent(Player player) + { + _player = player; + } + + public Player getPlayer() + { + return _player; + } + + @Override + public HandlerList getHandlers() + { + return HANDLER_LIST; + } + + public static HandlerList getHandlerList() + { + return HANDLER_LIST; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/event/PartyTransferOwnerEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/party/event/PartyTransferOwnerEvent.java new file mode 100644 index 000000000..c21abd883 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/event/PartyTransferOwnerEvent.java @@ -0,0 +1,65 @@ +package mineplex.core.party.event; + +import mineplex.core.party.Party; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +/** + * An event called when an owner leaves a party + */ +public class PartyTransferOwnerEvent extends Event +{ + + public enum TransferReason + { + LEFT, + TRANSFER; + } + + private static final HandlerList HANDLER_LIST = new HandlerList(); + + private final Party _party; + private final String _newOwner; + private final String _oldOwner; + private final TransferReason _reason; + + public PartyTransferOwnerEvent(Party party, String newOwner, String oldOwner, TransferReason reason) + { + _party = party; + _newOwner = newOwner; + _oldOwner = oldOwner; + _reason = reason; + } + + public String getNewOwner() + { + return _newOwner; + } + + public String getOldOwner() + { + return _oldOwner; + } + + public TransferReason getReason() + { + return _reason; + } + + public Party getParty() + { + return _party; + } + + @Override + public HandlerList getHandlers() + { + return HANDLER_LIST; + } + + public static HandlerList getHandlerList() + { + return HANDLER_LIST; + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyInviteManager.java b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyInviteManager.java new file mode 100644 index 000000000..27b9dedd0 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyInviteManager.java @@ -0,0 +1,400 @@ +package mineplex.core.party.manager; + +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import mineplex.core.common.Rank; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.party.InviteData; +import mineplex.core.party.Lang; +import mineplex.core.party.Party; +import mineplex.core.party.PartyManager; +import mineplex.core.party.constants.InviteResponse; +import mineplex.core.party.redis.RedisMessageType; +import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.ClickEvent.Action; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; + +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +/** + * + */ +public class PartyInviteManager +{ + + private final Map> _activeInvites = Maps.newHashMap(); + private final Map _invitedBy = Maps.newHashMap(); + private final Map _awaitingJoin = Maps.newHashMap(); + private final Map _players = Maps.newHashMap(); + private final Map _tasks = Maps.newHashMap(); + + private final PartyManager _plugin; + private final PartyRedisManager _partyRedisManager; + + public PartyInviteManager(PartyManager plugin, PartyRedisManager partyRedisManager) + { + _plugin = plugin; + _partyRedisManager = partyRedisManager; + } + + /** + * Responds to an invite, regardless of the server + * + * @param player The player calling + * @param party The party + * @param accept Whether or not the player accepted the invite + */ + public void respondToInvite(Player player, String party, boolean accept) + { + Player possible = Bukkit.getPlayerExact(party); + + InviteData data = remove(party, player.getUniqueId()); + + _players.remove(player.getUniqueId()); + cancelTask(player.getUniqueId()); + + if(possible != null) + { + Party newParty = _plugin.getParty(party); + if(!accept) + { + String message = C.mHead + "Party> " + C.mBody + InviteResponse.DENIED.format(player.getName()); + if (newParty == null) + { + possible.sendMessage(message); + return; + } + newParty.sendMessage(message); + return; + } + if (newParty == null) + { + newParty = new Party(possible.getName()); + if(_plugin.getClientManager().Get(possible).GetRank().has(Rank.ULTRA)) + { + newParty.setSize(); + } else + { + newParty.setSize(); + } + _plugin.addParty(newParty); + _plugin.getMethodManager().addToParty(possible.getUniqueId(), newParty); + } + _plugin.getMethodManager().addToParty(player.getUniqueId(), newParty); + return; + } + + String serverFrom = data.getServerFrom(); + + if(accept) + { + _plugin.getPortal().sendPlayerToServer(player, serverFrom); + } + + _partyRedisManager.publish(serverFrom, RedisMessageType.INVITE_PLAYER_RESPONSE, party, + player.getName(), player.getUniqueId().toString(), accept ? InviteResponse.ACCEPTED.name() : InviteResponse.DENIED.name()); + } + + /** + * Handles a received response via redis + * + * @param sender The player sending the request + * @param target The player target + * @param serverFrom The server initiating the request + */ + public void handleInviteRequest(String sender, String target, String serverFrom) + { + Player player = Bukkit.getPlayer(target); + if (player == null) + { + //Shouldn't happen, as a "findPLayer" packet will be sent out first. + return; + } + _players.put(player.getUniqueId(), player.getName()); + inviteTo(player.getUniqueId(), sender, sender, serverFrom); + Lang.INVITE_RECEIVED.send(player, sender); + sendAcceptOrDeny(player, sender); + } + + /** + * Handles the response returned via redis when an invite is handled cross server + * + * @param sender The player sender + * @param target The player target + * @param targetUUID The player targets UUID + * @param response The response to this invite + */ + public void handleInviteResponse(String sender, String target, UUID targetUUID, InviteResponse response) + { + remove(sender, targetUUID); + Player player = Bukkit.getPlayer(sender); + if (player == null) + { + return; + } + String message = F.main("Party", response.format(target)); + + Party party = _plugin.getParty(sender); + String partyName = sender; + if(party != null) + { + partyName = party.getName(); + } + + switch (response) + { + case ACCEPTED: + addToPendingJoin(targetUUID, partyName); + break; + case EXPIRED: + case DENIED: + if (party == null) + { + player.sendMessage(message); + return; + } + party.sendMessage(message); + break; + } + } + + /** + * Remove all references tied with this player + * + * @param player The player's UUID + */ + public void removeAll(UUID player) + { + _players.remove(player); + _invitedBy.remove(player); + _activeInvites.remove(player); + } + + /** + * Get the name of the party who is awaiting this player to join + * + * @param player The player's UUID + * @return The name of the awaiting party. + */ + public String getPartyWaiting(UUID player) + { + return _awaitingJoin.get(player); + } + + /** + * Remove the party reference that invited this player + * + * @param player The player's UUID + */ + public void removeFromWaiting(UUID player) + { + _awaitingJoin.remove(player); + } + + /** + * Add a player to the active invites map + * + * @param player The player who has been invited + * @param party The party name + */ + public void inviteTo(UUID player, String invitedBy, String party, String server) + { + addToInvite(player, invitedBy, party, server); + _tasks.put(player, new BukkitRunnable() + { + @Override + public void run() + { + if (!isInvitedTo(player, party)) + { + cancel(); + return; + } + InviteData data = remove(party, player); + Player possible = Bukkit.getPlayer(player); + String playerName = _players.remove(player); + if (possible != null) + { + playerName = possible.getName(); + possible.sendMessage(F.main("Party", "Your invite to " + F.name(party) + "'s party has expired")); + } + sendExpired(data.getServerFrom(), party, playerName, player); + } + }.runTaskLater(_plugin.getPlugin(), 20 * 60)); + } + + /** + * Checks to see if a player is invited to a specific party + * + * @param player The player who we want to check against + * @param party The name of the party to check + * @return true if the player has an invite to the specific party + */ + public boolean isInvitedTo(UUID player, String party) + { + if (!_activeInvites.containsKey(player)) + { + return false; + } + List dataList = _activeInvites.get(player); + for (InviteData data : dataList) + { + if (data.getInvitedTo().equalsIgnoreCase(party)) + { + return true; + } + } + return false; + } + + /** + * Remove a player's invite to a certain party + * + * @param party The name of the party + * @param invited The UUID of the player + */ + public InviteData remove(String party, UUID invited) + { + List data = _activeInvites.get(invited); + InviteData temp = null; + for (InviteData inviteData : data) + { + if (inviteData.getInvitedTo().equalsIgnoreCase(party)) + { + temp = inviteData; + break; + } + } + if (temp != null) + { + data.remove(temp); + } + _activeInvites.put(invited, data); + return temp; + } + + /** + * Stop the player's expired task from running + * + * @param player The UUID of the player + */ + public void cancelTask(UUID player) + { + BukkitTask task = _tasks.remove(player); + if(task != null) + { + task.cancel(); + } + } + + /** + * Retrieves all invites currently pending for a specific player + * @param player The player + * @return All his current pending invites + */ + public Collection getAllInvites(Player player) + { + return _activeInvites.get(player.getUniqueId()); + } + + /** + * Send an "ExpiredPartyInvite" redis message + * + * @param server The server to + * @param party The party who initiated the request (can also be a player's name) + * @param playerName The name of the invited player + * @param player The invited player's UUID + */ + private void sendExpired(String server, String party, String playerName, UUID player) + { + _plugin.getRedisManager().publish(server, RedisMessageType.INVITE_PLAYER_RESPONSE, party, playerName, player.toString(), InviteResponse.EXPIRED.name()); + } + + /** + * Marks this player as having an accepted invite + * This is used to control the creation of single player parties, and makes sure a party is created ONLY if a player joins the server successfully. + * + * @param player The UUID of the player + * @param party The name of the party + */ + private void addToPendingJoin(UUID player, String party) + { + _awaitingJoin.put(player, party); + } + + /** + * Add a pending invite for a player + * + * @param invited The invited players UUUD + * @param invitedBy The person who invited him + * @param party The name of the party invited to + * @param server The server the request is from + */ + private void addToInvite(UUID invited, String invitedBy, String party, String server) + { + List inviteDatas = _activeInvites.get(invited); + if (inviteDatas == null) + { + inviteDatas = Lists.newArrayList(); + } + InviteData inviteData = new InviteData(party, server); + inviteDatas.add(inviteData); + _invitedBy.put(invited, invitedBy); + _activeInvites.put(invited, inviteDatas); + } + + /** + * Sends a Text Componoent clickable message to a player for easier quick responses to invites + * + * @param player The player who received the invite + * @param arg The name of the inviting party + */ + public void sendAcceptOrDeny(Player player, String arg) + { + TextComponent textComponent = new TextComponent(F.main("Party", "Reply: ")); + + TextComponent accept = new TextComponent("ACCEPT"); + accept.setColor(ChatColor.GREEN); + accept.setBold(true); + accept.setClickEvent(new ClickEvent(Action.RUN_COMMAND, "/partyaccept " + arg)); + accept.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{ + new TextComponent("Click to join " + F.name(arg) + "'s party") + })); + + textComponent.addExtra(accept); + textComponent.addExtra(" "); + + TextComponent deny = new TextComponent("DENY"); + deny.setColor(ChatColor.RED); + deny.setBold(true); + deny.setClickEvent(new ClickEvent(Action.RUN_COMMAND, "/partydeny " + arg)); + deny.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{ + new TextComponent("Click to decline joining " + F.name(arg) + "'s party") + })); + + textComponent.addExtra(deny); + textComponent.addExtra(" "); + + TextComponent view = new TextComponent("VIEW"); + view.setColor(ChatColor.YELLOW); + view.setBold(true); + view.setClickEvent(new ClickEvent(Action.RUN_COMMAND, "/openinvitesmenu")); + view.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{ + new TextComponent("Click to view all pending invites.") + })); + + textComponent.addExtra(view); + + player.spigot().sendMessage(textComponent); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyJoinManager.java b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyJoinManager.java new file mode 100644 index 000000000..9226ce9c6 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyJoinManager.java @@ -0,0 +1,125 @@ +package mineplex.core.party.manager; + +import com.google.common.collect.Lists; +import mineplex.core.common.Rank; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilServer; +import mineplex.core.party.Party; +import mineplex.core.party.PartyManager; +import mineplex.core.party.constants.JoinResponseReason; +import mineplex.core.party.redis.RedisMessageType; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import java.util.List; +import java.util.UUID; +import java.util.stream.Collectors; + +/** + * Manages allocating slots for parties to join + */ +public class PartyJoinManager +{ + + private final PartyManager _plugin; + private final int _maxPLayers; + private final List _transferring; + + public PartyJoinManager(PartyManager plugin) + { + _plugin = plugin; + _maxPLayers = plugin.getPlugin().getServer().getMaxPlayers(); + _transferring = Lists.newArrayList(); + } + + /** + * Initiates a request to join a server for a specific party + * + * @param server The desired server + * @param party The requesting party + */ + public void requestServerJoin(String server, Party party) + { + boolean canJoinFull = true; + List players = party.getMembers().stream().map(Bukkit::getPlayer).collect(Collectors.toList()); + for (Player player : players) + { + Rank rank = _plugin.getClientManager().Get(player).GetRank(); + if (rank == Rank.ALL) + { + canJoinFull = false; + break; + } + } + _plugin.getRedisManager().publish(server, RedisMessageType.PREJOIN_SERVER_REQUEST, + _plugin.getServerName(), party.getOwner(), "" + party.getMembers().size(), "" + canJoinFull); + } + + /** + * Manages a received request + * + * @param serverFrom The server who initiated the request + * @param partySize The size of the party + * @param initiator The player who sent the request + * @param canJoinFull true if the party contains all donators or staff (full joining able players) + */ + public void handleJoinRequest(String serverFrom, int partySize, String initiator, boolean canJoinFull) + { + int currentPlayers = UtilServer.getPlayers().length; + if (currentPlayers >= _maxPLayers || (currentPlayers + partySize) >= _maxPLayers) + { + //Max number of people on. + if (!canJoinFull) + { + _plugin.getRedisManager().publish(serverFrom, RedisMessageType.PREJOIN_SERVER_RESPONSE, initiator, JoinResponseReason.CANNOT_JOIN_FULL.name(), _plugin.getServerName()); + return; + } + } + + _plugin.getRedisManager().publish(serverFrom, RedisMessageType.PREJOIN_SERVER_RESPONSE, initiator, JoinResponseReason.SUCCESS.name(), _plugin.getServerName()); + + } + + /** + * Manages a received response + * + * @param playerSender The player who sent the request + * @param server The server responding + * @param reason The reason for the response + */ + public void handleJoinResponse(String playerSender, String server, JoinResponseReason reason) + { + Player player = Bukkit.getPlayer(playerSender); + if (player == null) + { + return; + } + Party party = _plugin.getParty(player); + if (party == null) + { + return; + } + if (reason != JoinResponseReason.SUCCESS) + { + party.sendMessage(reason.getMessage()); + return; + } + party.sendMessage(F.main("Party", "Transferring servers...")); + _plugin.getRedisManager().sendPartyInfo(server, party); + _transferring.addAll(party.getMembersByUUID()); + } + + /** + * Retrieve whether or not the player is currently transferring servers + * We wont need this information again, so calling a remove works fine. + * + * @param player The player + * @return true if the player is transferring servers + */ + public boolean isTransferring(Player player) + { + return _transferring.remove(player.getUniqueId()); + } + + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyMethodManager.java b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyMethodManager.java new file mode 100644 index 000000000..4d2a5c21e --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyMethodManager.java @@ -0,0 +1,337 @@ +package mineplex.core.party.manager; + +import com.google.common.collect.Lists; +import mineplex.core.common.util.F; +import mineplex.core.party.Lang; +import mineplex.core.party.Party; +import mineplex.core.party.PartyManager; +import mineplex.core.party.constants.PartyRemoveReason; +import mineplex.core.party.ui.Menu; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import java.util.List; +import java.util.UUID; + +/** + * Contains all methods used by the internal UI system + */ +public class PartyMethodManager +{ + + private PartyManager _plugin; + + public PartyMethodManager(PartyManager plugin) + { + _plugin = plugin; + } + + /** + * Invite a player to either a new party or existing one + * + * @param caller The player who initiated the request + * @param target The player's target + */ + public void invite(Player caller, String target) + { + Player possible = Bukkit.getPlayer(target); + Party party = _plugin.getParty(caller); + + if(target.equalsIgnoreCase(caller.getName())) + { + caller.sendMessage(F.main("Party", "You cannot invite yourself!")); + return; + } + + boolean can = Bukkit.getMaxPlayers() >= _plugin.getPlugin().getServer().getOnlinePlayers().size(); + if(!can) + { + Lang.SERVER_FULL.send(caller); + return; + } + + //Same Server + if (possible != null) + { + + if(!_plugin.getPreferencesManager().Get(possible).PartyRequests) + { + caller.sendMessage(F.main("Party> ", F.name(target) + " is not accepting invites at this time.")); + return; + } + + if (party == null) + { + if(_plugin.getParty(target) != null) + { + Lang.PLAYER_IN_DIFFERENT_PARTY.send(caller, target); + return; + } + if(_plugin.getInviteManager().isInvitedTo(possible.getUniqueId(), caller.getName())) + { + Lang.ALREADY_INVITED.send(caller, target); + return; + } + Lang.INVITE_SUCCESS_PLAYER.send(caller, possible.getName()); + } else + { + if(!party.getOwner().equalsIgnoreCase(caller.getName())) + { + Lang.NOT_OWNER.send(caller); + return; + } + if(_plugin.getInviteManager().isInvitedTo(possible.getUniqueId(), party.getName())) + { + Lang.ALREADY_INVITED.send(caller, target); + return; + } + if(party.getMembers().contains(target)) + { + Lang.ALREADY_MEMBER.send(caller, target); + return; + } + if(_plugin.getParty(target) != null) + { + Lang.PLAYER_IN_DIFFERENT_PARTY.send(caller, target); + return; + } + if(party.getMembers().size() >= party.getSize()) + { + Lang.PARTY_FULL.send(caller); + return; + } + + Lang.SUCCESS_INVITE.send(party, caller.getName(), target); + } + + UUID uuid = possible.getUniqueId(); + + Lang.INVITE_RECEIVED.send(possible, caller.getName(), caller.getName()); + + _plugin.getInviteManager().inviteTo(uuid, caller.getName(), caller.getName(), _plugin.getServerName()); + + _plugin.getInviteManager().sendAcceptOrDeny(possible, caller.getName()); + return; + } + //Not on the same server + _plugin.getRedisManager().findAndInvite(target, caller.getName()); + } + + /** + * Responds to a pending invite + * + * @param caller The player who initiated the request + * @param target The player's target + * @param accept true If the player has accepted the invite + */ + public void respondToInvite(Player caller, String target, boolean accept) + { + if(_plugin.getParty(caller) != null) + { + Lang.ALREADY_IN.send(caller); + caller.sendMessage(F.main("Party", "Please leave your party before joining!")); + return; + } + + PartyInviteManager inviteManager = _plugin.getInviteManager(); + + if (!inviteManager.isInvitedTo(caller.getUniqueId(), target)) + { + //He isn't invited to this party. + Lang.NOT_INVITED.send(caller, target); + return; + } + if(!accept) + { + caller.sendMessage(F.main("Party", "You have denied the invite to " + F.name(target)) + "'s party."); + } + inviteManager.respondToInvite(caller, target, accept); + } + + /** + * Kicks a player from the callers party + * + * @param caller The player who initiated the request + * @param target The player's target + */ + public void forceRemove(Player caller, String target) + { + Party party = _plugin.getParty(caller); + + if (party == null) + { + Lang.NO_PARTY.send(caller); + return; + } + + if (!party.getOwner().equalsIgnoreCase(caller.getName())) + { + Lang.NOT_OWNER.send(caller); + return; + } + + Player playerTarget = Bukkit.getPlayerExact(target); + + if (playerTarget == null) + { + Lang.NOT_MEMBER.send(caller, target); + return; + } + + Party targetParty = _plugin.getParty(playerTarget); + + if (targetParty == null ||!party.getMembers().contains(target)) + { + Lang.NOT_MEMBER.send(caller, target); + return; + } + + removeFromParty(playerTarget.getUniqueId(), PartyRemoveReason.KICKED); + + Lang.REMOVE_PLAYER_KICK.send(targetParty); + } + + /** + * Leaves the players current party if he is in one + * + * @param caller The player who wishes to leave his party + */ + public void leaveParty(Player caller) + { + Party party = _plugin.getParty(caller); + + if (party == null) + { + Lang.NO_PARTY.send(caller); + return; + } + + removeFromParty(caller.getUniqueId(), PartyRemoveReason.LEFT); + Lang.LEFT.send(caller); + } + + /** + * Disbands a players current party, assuming he is the leader + * + * @param caller The player who wishes to disband his party + */ + public void disband(Player caller) + { + Party party = _plugin.getParty(caller); + + if (party == null) + { + Lang.NO_PARTY.send(caller); + return; + } + + if (!party.getOwner().equalsIgnoreCase(caller.getName())) + { + Lang.NOT_OWNER.send(caller); + return; + } + caller.sendMessage(F.main("Party", "You have disbanded your party.")); + disbandParty(party); + } + + public void addToParty(UUID uuid, Party party) + { + _plugin.getPlayerParties().put(uuid, party); + Player player = Bukkit.getPlayer(uuid); + party.onPlayerAdd(player.getName()); + if(!party.getMembersByUUID().contains(uuid)) + { + party.getMembersByUUID().add(uuid); + } + } + + public void addToPartyOnTransfer(UUID uuid, Party party) + { + _plugin.getPlayerParties().put(uuid, party); + } + + public void addToParty(Player player, Party party) + { + addToParty(player.getUniqueId(), party); + } + + public void removeForTransfer(UUID uuid) + { + Party party = _plugin.getPlayerParties().remove(uuid); + if(party == null) + { + return; + } + String player = Bukkit.getPlayer(uuid).getName(); + party.onPlayerRemove(player, PartyRemoveReason.OTHER); + } + + public void removeFromParty(UUID uuid, PartyRemoveReason reason) + { + Party party = _plugin.getPlayerParties().remove(uuid); + if(party == null) + { + return; + } + + Player player = Bukkit.getPlayer(uuid); + + if(player.getOpenInventory() != null) + { + if (Menu.get(player.getUniqueId()) != null) + { + player.closeInventory(); + Menu.remove(player.getUniqueId()); + } + } + + if(reason == PartyRemoveReason.DISBANDED_BY_OWNER) + { + return; + } + party.getMembers().remove(player.getName()); + party.getMembersByUUID().remove(uuid); + party.onPlayerRemove(player.getName(), reason); + + int size = party.getMembers().size(); + if(size <= 1) + { + if(size == 0) + { + _plugin.removeParty(party); + return; + } + _plugin.getPlayerParties().remove(Bukkit.getPlayerExact(party.getMembers().get(0)).getUniqueId()); + party.onPlayerRemove(party.getMembers().get(0), PartyRemoveReason.DISBANDED); + _plugin.removeParty(party); + } + } + + public void removeFromParty(Player player, PartyRemoveReason reason) + { + removeFromParty(player.getUniqueId(), reason); + } + + public void disbandParty(Party party) + { + List members = Lists.newArrayList(party.getMembersByUUID()); + Lang.DISBANDED_BY_OWNER.send(party); + members.stream().forEach(player -> removeFromParty(player, PartyRemoveReason.DISBANDED_BY_OWNER)); + party.getMembers().clear(); + party.getMembersByUUID().clear(); + _plugin.removeParty(party); + } + + public void transferOwner(String newOwner, String oldOwner) + { + Party party = _plugin.getParties().remove(oldOwner); + if(party == null) + { + return; + } + _plugin.getParties().put(newOwner, party); + party.setOwner(newOwner); + party.getMembers().remove(oldOwner); + party.getMembers().add(oldOwner); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java new file mode 100644 index 000000000..4f1d01473 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyRedisManager.java @@ -0,0 +1,296 @@ +package mineplex.core.party.manager; + +import com.google.common.collect.Maps; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import mineplex.core.common.util.F; +import mineplex.core.party.Lang; +import mineplex.core.party.Party; +import mineplex.core.party.PartyManager; +import mineplex.core.party.constants.InviteResponse; +import mineplex.core.party.constants.JoinResponseReason; +import mineplex.core.party.event.PartyDataReceivedEvent; +import mineplex.core.party.redis.PartyRedisListener; +import mineplex.core.party.redis.RedisMessageType; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import static mineplex.core.party.redis.RedisMessageType.INVITE_PLAYER_REQUEST; +import static mineplex.core.party.redis.RedisMessageType.PARTY_INFO; + +/** + * Redis system for Parties + */ +public class PartyRedisManager +{ + protected final Gson GSON = new GsonBuilder().create(); + + protected static final String CHANNEL_BASE = "party-pubsub"; + protected static final String FIND_PLAYERS_CHANNEL = "party-player-finder"; + private final Map TASKS = Maps.newHashMap(); + + private final PartyManager _plugin; + private final JedisPool _writePool; + private final String _channel; + private final String _serverName; + + public PartyRedisManager(PartyManager plugin, String serverName, JedisPool writePool, JedisPool readPool) + { + _plugin = plugin; + _serverName = serverName; + _writePool = writePool; + _channel = CHANNEL_BASE + "-" + serverName; + + plugin.runAsync(() -> { + try (Jedis jedis = readPool.getResource()) + { + jedis.subscribe(new PartyRedisListener(this), _channel, FIND_PLAYERS_CHANNEL); + } + }); + } + + /** + * Send a message to a specific server + * + * @param server The destination server + * @param messageType The message to send + * @param args The arguments accompanying the request + */ + public void publish(String server, RedisMessageType messageType, String... args) + { + _plugin.runAsync(() -> { + try (Jedis jedis = _writePool.getResource()) + { + jedis.publish(CHANNEL_BASE + "-" + server, messageType.name() + "@" + messageType.format(args)); + } + }); + } + + /** + * Handle a message received on this server + * + * @param messageType The type of message received + * @param message The contents of the request + */ + public void handle(RedisMessageType messageType, String message) + { + if (messageType == PARTY_INFO) + { + handlePartyInfo(message); + return; + } + String[] contents = message.split(","); + if (contents.length < 3) + { + return; + } + String first = contents[0]; + String second = contents[1]; + String third = contents[2]; + Bukkit.getScheduler().runTask(_plugin.getPlugin(), () -> { + switch (messageType) + { + case INVITE_PLAYER_REQUEST: + _plugin.getInviteManager().handleInviteRequest(second, third, first); + break; + + case INVITE_PLAYER_RESPONSE: + _plugin.getInviteManager().handleInviteResponse(first, second, UUID.fromString(third), InviteResponse.valueOf(contents[3].toUpperCase())); + break; + + case PLAYER_FIND_REQUEST: + Player player = Bukkit.getPlayerExact(second); + + if (player == null) + { + return; + } + + if(_plugin.getParty(player) != null) + { + publish(first, RedisMessageType.INVITE_PLAYER_ALREADY_IN_PARTY, _serverName, player.getName(), player.getUniqueId().toString(), third); + return; + } + + if(!_plugin.getPreferencesManager().Get(player).PartyRequests) + { + publish(first, RedisMessageType.INVITE_PLAYER_NOT_ACCEPTING_INVITES, _serverName, player.getName(), player.getUniqueId().toString(), third); + return; + } + + publish(first, RedisMessageType.PLAYER_FIND_RESPONSE, _serverName, player.getName(), player.getUniqueId().toString(), third); + break; + + case INVITE_PLAYER_ALREADY_IN_PARTY: + handleAlreadyIn(second, contents); + break; + + case INVITE_PLAYER_NOT_ACCEPTING_INVITES: + handleNotAccepting(second, contents); + break; + + case PLAYER_FIND_RESPONSE: + UUID uuid = UUID.fromString(third); + BukkitTask task = TASKS.remove(second); + + if (task != null) + { + task.cancel(); + } + + Player inviter = Bukkit.getPlayerExact(contents[3]); + if (_plugin.getInviteManager().isInvitedTo(uuid, inviter.getName())) + { + Lang.ALREADY_INVITED.send(inviter, second); + return; + } + if (_plugin.getParty(inviter) == null) + { + Lang.INVITE_SUCCESS_PLAYER.send(inviter, second); + } else + { + Lang.SUCCESS_INVITE.send(_plugin.getParty(inviter), inviter.getName(), second); + } + _plugin.getInviteManager().inviteTo(uuid, inviter.getName(), inviter.getName(), _plugin.getServerName()); + publish(first, INVITE_PLAYER_REQUEST, _serverName, inviter.getName(), second); + break; + + case PREJOIN_SERVER_REQUEST: + _plugin.getJoinManager().handleJoinRequest(first, Integer.valueOf(third), second, Boolean.valueOf(contents[3])); + break; + + case PREJOIN_SERVER_RESPONSE: + _plugin.getJoinManager().handleJoinResponse(first, third, JoinResponseReason.valueOf(second.toUpperCase())); + break; + } + }); + + } + + private void handleNotAccepting(String second, String[] contents) + { + BukkitTask task = TASKS.remove(second); + + if (task != null) + { + task.cancel(); + } + + Player inviter = Bukkit.getPlayerExact(contents[3]); + inviter.sendMessage(F.main("Party", F.name(second) + " is not accepting invites at this time.")); + } + + private void handleAlreadyIn(String second, String[] contents) + { + BukkitTask task = TASKS.remove(second); + + if (task != null) + { + task.cancel(); + } + + Player inviter = Bukkit.getPlayerExact(contents[3]); + Lang.ALREADY_IN.send(inviter, second); + } + + /** + * Initiates inviting a player who is no on the same server + * + * @param player The player target + * @param sender The sending player + */ + public void findAndInvite(String player, String sender) + { + Bukkit.getPlayerExact(sender).sendMessage(F.main("Party", "Locating " + F.elem(player) + "...")); + TASKS.put(player, new BukkitRunnable() + { + @Override + public void run() + { + TASKS.remove(player); + Player senderPlayer = Bukkit.getPlayerExact(sender); + if (senderPlayer == null) + { + cancel(); + return; + } + if (Bukkit.getPlayerExact(player) != null) + { + cancel(); + return; + } + senderPlayer.sendMessage(F.main("Party", "Could not locate " + F.elem(player) + ".")); + } + }.runTaskLater(_plugin.getPlugin(), 20L * 5)); + + _plugin.runAsync(() -> { + try (Jedis jedis = _writePool.getResource()) + { + jedis.publish(FIND_PLAYERS_CHANNEL, RedisMessageType.PLAYER_FIND_REQUEST.format(_serverName, player, sender)); + } + }); + } + + /** + * Serializes and sends a party to another server + * + * @param server The destination server + * @param party The party to be sent + */ + public void sendPartyInfo(String server, Party party) + { + publish(server, PARTY_INFO, GSON.toJson(party)); + List members = party.getMembersByUUID(); + party.getMembersByUUID().forEach(uuid -> _plugin.getMethodManager().removeForTransfer(uuid)); + members.stream().map(Bukkit::getPlayer).forEach(player1 -> + { + player1.leaveVehicle(); + player1.eject(); + _plugin.getPortal().sendPlayerToServer(player1, server, true); + }); + _plugin.removeParty(party); + } + + /** + * Deserialize and store a received party's information + * @param json + */ + public void handlePartyInfo(String json) + { + new BukkitRunnable() + { + @Override + public void run() + { + Party party = GSON.fromJson(json, Party.class); + _plugin.addParty(party); + party.getMembersByUUID().forEach(s -> _plugin.getMethodManager().addToPartyOnTransfer(s, party)); + Bukkit.getServer().getPluginManager().callEvent(new PartyDataReceivedEvent(party)); + } + }.runTaskLater(_plugin.getPlugin(), 10L); + } + + /** + * @return This servers name + */ + public String getServerName() + { + return _serverName; + } + + /** + * @return The channel constant for finding players + */ + public String getFinder() + { + return FIND_PLAYERS_CHANNEL; + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyRedisListener.java b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyRedisListener.java new file mode 100644 index 000000000..f4c3b4d20 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyRedisListener.java @@ -0,0 +1,30 @@ +package mineplex.core.party.redis; + +import mineplex.core.party.manager.PartyRedisManager; +import redis.clients.jedis.JedisPubSub; + +/** + * Handles incoming messages into the Party Redis System + */ +public class PartyRedisListener extends JedisPubSub +{ + + private final PartyRedisManager _redisManager; + + public PartyRedisListener(PartyRedisManager redisManager) + { + _redisManager = redisManager; + } + + @Override + public void onMessage(String channel, String message) + { + if(channel.equalsIgnoreCase(_redisManager.getFinder())) + { + _redisManager.handle(RedisMessageType.PLAYER_FIND_REQUEST, message); + return; + } + RedisMessageType type = RedisMessageType.valueOf(message.split("@")[0].toUpperCase()); + _redisManager.handle(type, message.split("@")[1]); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/RedisMessageType.java b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/RedisMessageType.java new file mode 100644 index 000000000..533f62c75 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/RedisMessageType.java @@ -0,0 +1,63 @@ +package mineplex.core.party.redis; + +/** + * Messages sent within the redis messaging system + * And their corresponding arguments + */ +public enum RedisMessageType +{ + + //Message: SERVER_FROM,PLAYER_TARGET,PLAYER_SENDER + PLAYER_FIND_REQUEST(1, "{0},{1},{2}"), + //Message: SERVER_ON,PLAYER_TARGET_NAME,PLAYER_TARGET_UUID,PLAYER_SENDER + PLAYER_FIND_RESPONSE(2, "{0},{1},{2},{3}"), + + //Message: SERVER_FROM,PLAYER_SENDER,PLAYER_TARGET + INVITE_PLAYER_REQUEST(3, "{0},{1},{2}"), + //Message: PLAYER_SENDER,PLAYER_TARGET_NAME,PLAYER_TARGET_UUID,RESPONSE + INVITE_PLAYER_RESPONSE(4, "{0},{1},{2},{3}"), + //Message: PLAYER_SENDER,PLAYER_TARGET_NAME,PLAYER_TARGET_UUID,RESPONSE + INVITE_PLAYER_ALREADY_IN_PARTY(5, "{0},{1},{2},{3}"), + //Message: PLAYER_SENDER,PLAYER_TARGET_NAME,PLAYER_TARGET_UUID,RESPONSE + INVITE_PLAYER_NOT_ACCEPTING_INVITES(5, "{0},{1},{2},{3}"), + + //Message: SERVER_FROM,PLAYER_INITIATING,PARTY_SIZE,_CAN_JOIN_FULL + PREJOIN_SERVER_REQUEST(6, "{0},{1},{2},{3}"), + //Message: PLAYER_INITIATING,REASON,SERVER + PREJOIN_SERVER_RESPONSE(7, "{0},{1},{2}"), + + //Message: JSON Party + PARTY_INFO(8, "{0}"), + TEST_CONN(9, "{0}") + ; + + private int _id; + private String _contents; + + RedisMessageType(int id, String contents) + { + _id = id; + _contents = contents; + } + + public int getId() + { + return _id; + } + + /** + * Format this message + * @param args The contents to be sent with this message + * @return A formatted message + */ + public String format(String... args) + { + String message = _contents; + for(int i = 0; i < args.length; i++) + { + message = message.replace("{" + i + "}", args[i]); + } + return message; + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/RedisPartyData.java b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/RedisPartyData.java deleted file mode 100644 index cec09d728..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/RedisPartyData.java +++ /dev/null @@ -1,33 +0,0 @@ -package mineplex.core.party.redis; - -import mineplex.core.party.Party; -import mineplex.serverdata.commands.ServerCommand; - -public class RedisPartyData extends ServerCommand -{ - private String[] _players; - private String _leader; - private String _previousServer; - - public RedisPartyData(Party party, String previousServer) - { - _players = party.GetPlayers().toArray(new String[0]); - _leader = party.GetLeader(); - _previousServer = previousServer; - } - - public String getPreviousServer() - { - return _previousServer; - } - - public String[] getPlayers() - { - return _players; - } - - public String getLeader() - { - return _leader; - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/RedisPartyHandler.java b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/RedisPartyHandler.java deleted file mode 100644 index e88aeb675..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/RedisPartyHandler.java +++ /dev/null @@ -1,30 +0,0 @@ -package mineplex.core.party.redis; - -import mineplex.core.party.Party; -import mineplex.core.party.PartyManager; -import mineplex.serverdata.commands.CommandCallback; -import mineplex.serverdata.commands.ServerCommand; - -public class RedisPartyHandler implements CommandCallback -{ - private PartyManager _partyManager; - - public RedisPartyHandler(PartyManager partyManager) - { - _partyManager = partyManager; - } - - @Override - public void run(ServerCommand command) - { - final RedisPartyData data = (RedisPartyData) command; - - _partyManager.getPlugin().getServer().getScheduler().runTask(_partyManager.getPlugin(), new Runnable() - { - public void run() - { - _partyManager.addParty(new Party(_partyManager, data)); - } - }); - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/Button.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/Button.java new file mode 100644 index 000000000..fe5d4468d --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/Button.java @@ -0,0 +1,45 @@ +package mineplex.core.party.ui; + +import mineplex.core.party.PartyManager; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + +/** + * An abstract class for managing buttons inside of menus + */ +public abstract class Button +{ + + private ItemStack _item; + private PartyManager _plugin; + + public Button(ItemStack item, PartyManager plugin) + { + this._item = item; + _plugin = plugin; + } + + /** + * The method called when a players clicks the slot + * + * @param player The player who clicked + */ + public abstract void onClick(Player player, ClickType clickType); + + public ItemStack getItemStack() + { + return _item; + } + + public void setItemStack(ItemStack item) + { + this._item = item; + } + + public PartyManager getPlugin() + { + return _plugin; + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/Menu.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/Menu.java new file mode 100644 index 000000000..3775d46e9 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/Menu.java @@ -0,0 +1,272 @@ +package mineplex.core.party.ui; + +import mineplex.core.common.util.C; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.party.PartyManager; +import mineplex.core.party.ui.button.IconButton; +import net.md_5.bungee.api.ChatColor; +import org.bukkit.Bukkit; +import org.bukkit.DyeColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryView; +import org.bukkit.inventory.ItemStack; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +/** + * A class to manage dynamic creation of GUI's + */ +public abstract class Menu +{ + + protected static final Button PANE = new IconButton(new ItemBuilder(Material.STAINED_GLASS_PANE) + .setTitle(" ") + .setData(DyeColor.LIGHT_BLUE.getWoolData()) + .build(), null); + + protected static final Button PURCHASE_MORE_SLOTS = new IconButton(new ItemBuilder(Material.REDSTONE_BLOCK) + .setTitle(C.cRed + C.Bold + "Locked!") + .setLore(" ", C.cGray + "Purchase a rank @ mineplex.com/shop", C.cGray + "Purchasing a rank increases your", C.cGray + "party size to allow 10 people!") + .build(), null); + + protected static final Button[] EMPTY = new Button[54]; + protected static Map MENUS = new HashMap<>(); + private String _name; + private Button[] _buttons; + protected PartyManager _plugin; + + public Menu(String name, PartyManager plugin) + { + _name = name; + _buttons = EMPTY; + _plugin = plugin; + } + + public static Menu get(UUID name) + { + return MENUS.get(name); + } + + /** + * Create an icon (no click action) + * + * @param item The itemstack ti display + * @return The created button + */ + protected Button create(ItemStack item) + { + return new IconButton(item, _plugin); + } + + public String getName() + { + return ChatColor.translateAlternateColorCodes('&', _name); + } + + public Button[] addPanes(Button[] buttons) + { + for (int i = 0; i < 9; i++) + { + if (buttons[i] == null) + { + buttons[i] = PANE; + } + + if(buttons.length == 9) + { + continue; + } + + if (buttons[i + buttons.length - 9] == null) + { + buttons[i + buttons.length - 9] = PANE; + } + + if (i == 0 || i == 8) + { + for (int a = 9; a < buttons.length; a += 9) + { + buttons[i + a] = PANE; + } + } + } + return buttons; + } + + /** + * Open and setup the inventory for the player to view + * Store a reference to it inside a map for retrieving later + * + * @param player The player who we wish to show the GUI to + */ + public void open(Player player) + { + setButtons(setUp(player)); + + if (MENUS.get(player.getUniqueId()) != null) + { + MENUS.remove(player.getUniqueId()); + } + + MENUS.put(player.getUniqueId(), this); + + int size = (_buttons.length + 8) / 9 * 9; + Inventory inventory = Bukkit.createInventory(player, size, getName()); + + for (int i = 0; i < _buttons.length; i++) + { + if (_buttons[i] == null) + { + continue; + } + + ItemStack item = _buttons[i].getItemStack(); + + inventory.setItem(i, item); + } + player.openInventory(inventory); + } + + /** + * Set up the GUI with buttons + * + * @return The setup button array + */ + protected abstract Button[] setUp(Player player); + + public Button[] getButtons() + { + return _buttons; + } + + public void setButtons(Button[] buttons) + { + _buttons = buttons; + } + + /** + * Retrieve the button based off the slot + * + * @param slot The slot in the inventory + * @return The button corresponding to that slot + */ + public Button getButton(int slot) + { + try + { + return _buttons[slot]; + } catch (ArrayIndexOutOfBoundsException e) + { + //There isn't a button there, so no need to throw an error + //e.printStackTrace(); + return null; + } + } + + /** + * Replace a button, or create a new button dynamically + * Update the players GUI + * + * @param slot The slot to set the new button + * @param button The reference to the button + * @param player The player whose GUI we'll be updating + */ + public void setButton(int slot, Button button, Player player) + { + try + { + _buttons[slot] = button; + } catch (ArrayIndexOutOfBoundsException ignored) + { + ignored.printStackTrace(); + } + update(player); + } + + /** + * Refresh the players view, allows to change what the player sees, without opening and closing the GUI + * + * @param player The player whose view you wish to update + */ + public void update(Player player) + { + InventoryView view = player.getOpenInventory(); + + if (view == null) + { + return; + } + + if (!view.getTitle().equalsIgnoreCase(getName())) + { + return; + } + + Inventory inventory = view.getTopInventory(); + for (int i = 0; i < _buttons.length; i++) + { + if (_buttons[i] == null) + { + continue; + } + + ItemStack item = _buttons[i].getItemStack(); + + inventory.setItem(i, item); + } + } + + /** + * Reset this players current menu's buttons and refresh the page + * + * @param player The player whose view you wish to update + */ + public void resetAndUpdate(Player player) + { + InventoryView view = player.getOpenInventory(); + + if (view == null) + { + return; + } + + if (!view.getTitle().equalsIgnoreCase(getName())) + { + return; + } + + Inventory inventory = view.getTopInventory(); + Button[] buttons = setUp(player); + for (int i = 0; i < buttons.length; i++) + { + if (buttons[i] == null) + { + continue; + } + + ItemStack item = buttons[i].getItemStack(); + + inventory.setItem(i, item); + } + } + + + public void setTitle(String title) + { + _name = title; + } + + public void onClose(Player player) + { + MENUS.remove(player.getUniqueId()); + } + + public static Menu remove(UUID uniqueId) + { + return MENUS.remove(uniqueId); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/MenuListener.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/MenuListener.java new file mode 100644 index 000000000..fb28a5a7c --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/MenuListener.java @@ -0,0 +1,57 @@ +package mineplex.core.party.ui; + +import mineplex.core.party.ui.button.PartyMemberIcon; +import mineplex.core.party.ui.menus.PartyOwnerMenu; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; + +/** + * Listener for the Menu system + */ +public class MenuListener implements Listener +{ + + @EventHandler + public void onClick(InventoryClickEvent event) + { + String name = event.getInventory().getName(); + Player player = (Player) event.getWhoClicked(); + Menu gui = Menu.get(player.getUniqueId()); + + if (gui == null) + { + return; + } + + if (!gui.getName().equalsIgnoreCase(name)) + { + return; + } + + Button button = gui.getButton(event.getRawSlot()); + + event.setCancelled(true); + event.setResult(Event.Result.DENY); + + if (button == null) + { + return; + } + + if(button instanceof PartyMemberIcon) + { + if(!(gui instanceof PartyOwnerMenu)) + { + return; + } + ((PartyMemberIcon) button).onClick(player, event.getCurrentItem()); + return; + } + + button.onClick(player, event.getClick()); + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/IconButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/IconButton.java new file mode 100644 index 000000000..0e80c09cd --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/IconButton.java @@ -0,0 +1,26 @@ +package mineplex.core.party.ui.button; + +import mineplex.core.party.PartyManager; +import mineplex.core.party.ui.Button; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + +/** + * Representation of a purely cosmetic icon + * IE: When clicked, this button does not execute any action + */ +public class IconButton extends Button +{ + + public IconButton(ItemStack item, PartyManager plugin) + { + super(item, plugin); + } + + @Override + public void onClick(Player player, ClickType clickType) + { + + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/PartyMemberIcon.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/PartyMemberIcon.java new file mode 100644 index 000000000..5be48d2c9 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/PartyMemberIcon.java @@ -0,0 +1,67 @@ +package mineplex.core.party.ui.button; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilServer; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.party.Party; +import mineplex.core.party.event.PartyMemberKickGUIEvent; +import mineplex.core.party.ui.button.tools.PartyButton; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + +/** + * The button representing a Party member. + */ +public class PartyMemberIcon extends PartyButton +{ + + private ItemStack _itemStack; + + public PartyMemberIcon(String player, Party party, boolean owner) + { + super(null, party, null); + ItemBuilder builder = new ItemBuilder(Material.SKULL_ITEM, 1, (byte) 3) + .setTitle(C.cYellow + player) + .setPlayerHead(player); + if(owner) + { + builder.addLore(" ", C.cGreenB + "Leader"); + } + _itemStack = builder.build(); + } + + @Override + public ItemStack getItemStack() + { + return _itemStack; + } + + /** + * Called when a player clicks one of the member icons + * + * @param clicker The player who clicked + * @param clicked The itemstack he clicked + */ + public void onClick(Player clicker, ItemStack clicked) + { + if (!getParty().isOwnerKickMode()) + { + return; + } + if(!getParty().getOwner().equalsIgnoreCase(clicker.getName())) + { + return; + } + String name = ChatColor.stripColor(clicked.getItemMeta().getDisplayName()); + UtilServer.getPluginManager().callEvent(new PartyMemberKickGUIEvent(getParty(), name, clicker)); + } + + @Override + public void onClick(Player player, ClickType clickType) + { + + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/LeavePartyButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/LeavePartyButton.java new file mode 100644 index 000000000..1b409a082 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/LeavePartyButton.java @@ -0,0 +1,39 @@ +package mineplex.core.party.ui.button.tools; + +import mineplex.core.common.util.C; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.party.PartyManager; +import mineplex.core.party.ui.Button; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + +/** + * Leaves a players current party + */ +public class LeavePartyButton extends Button +{ + + private static final ItemStack ITEM = new ItemBuilder(Material.REDSTONE_BLOCK) + .setTitle(C.cYellow + "Leave Party") + .setLore(" ", C.cRed + "Shift-Left-Click" + C.cGray + " to leave your party.") + .build(); + + public LeavePartyButton(PartyManager plugin) + { + super(ITEM, plugin); + } + + @Override + public void onClick(Player player, ClickType clickType) + { + if(clickType != ClickType.SHIFT_LEFT) + { + return; + } + getPlugin().getMethodManager().leaveParty(player); + player.closeInventory(); + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/PartyButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/PartyButton.java new file mode 100644 index 000000000..463754279 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/PartyButton.java @@ -0,0 +1,26 @@ +package mineplex.core.party.ui.button.tools; + +import mineplex.core.party.Party; +import mineplex.core.party.PartyManager; +import mineplex.core.party.ui.Button; +import org.bukkit.inventory.ItemStack; + +/** + * A wrapper for all buttons which need to interact with a specific party + */ +public abstract class PartyButton extends Button +{ + + private Party _party; + + public PartyButton(ItemStack itemStack, Party party, PartyManager plugin) + { + super(itemStack, plugin); + _party = party; + } + + public Party getParty() + { + return _party; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/BackButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/BackButton.java new file mode 100644 index 000000000..6ac82bc6a --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/BackButton.java @@ -0,0 +1,34 @@ +package mineplex.core.party.ui.button.tools.invite; + +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.party.PartyManager; +import mineplex.core.party.ui.Button; +import mineplex.core.party.ui.menus.PartyMainMenu; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + +/** + * Sends a player back to the main page + */ +public class BackButton extends Button +{ + + private static ItemStack ITEM = new ItemBuilder(Material.BED) + .setTitle(ChatColor.GRAY + "\u21FD Go Back") + .build(); + + public BackButton(PartyManager plugin) + { + super(ITEM, plugin); + } + + @Override + public void onClick(Player player, ClickType clickType) + { + player.closeInventory(); + new PartyMainMenu(getPlugin()).open(player); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/DenyAllButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/DenyAllButton.java new file mode 100644 index 000000000..e39faaca2 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/DenyAllButton.java @@ -0,0 +1,35 @@ +package mineplex.core.party.ui.button.tools.invite; + +import mineplex.core.common.util.C; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.party.PartyManager; +import mineplex.core.party.ui.Button; +import mineplex.core.party.ui.menus.PartyInvitesMenu; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + +/** + * Deny's all invites currently pending + */ +public class DenyAllButton extends Button +{ + + private static final ItemStack ITEM = new ItemBuilder(Material.REDSTONE_BLOCK) + .setTitle(C.cRed + "Delete all Invites") + .setLore(" ", C.cGray + "This will remove all pending invites.") + .build(); + + public DenyAllButton(PartyManager plugin) + { + super(ITEM, plugin); + } + + @Override + public void onClick(Player player, ClickType clickType) + { + getPlugin().getInviteManager().getAllInvites(player).forEach(inviteData -> getPlugin().getMethodManager().respondToInvite(player, inviteData.getInvitedTo(), false)); + new PartyInvitesMenu(getPlugin()).open(player); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/FilterButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/FilterButton.java new file mode 100644 index 000000000..2a2e5d4ff --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/FilterButton.java @@ -0,0 +1,54 @@ +package mineplex.core.party.ui.button.tools.invite; + +import mineplex.core.common.util.C; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.party.PartyManager; +import mineplex.core.party.ui.Button; +import mineplex.core.party.ui.menus.input.InviteFilterMenu; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + +/** + * Filters all current pending invites and displays only the results to a player + */ +public class FilterButton extends Button +{ + + private static final ItemStack ITEM = new ItemBuilder(Material.NAME_TAG) + .setTitle(C.cYellow + "Filter Invites") + .setLore(" ", + C.cGray + "Click to bring up an Anvil GUI", + C.cGray + "where you type and filter", + C.cGray + "Party invites by their name", + " ", + C.cGreen + "Input \"Clear Filter\" to remove the filter") + .build(); + + public FilterButton(PartyManager plugin) + { + super(ITEM, plugin); + } + + public FilterButton(String filter, PartyManager plugin) + { + super(new ItemBuilder(Material.NAME_TAG) + .setTitle(C.cYellow + "Filter Invites") + .setLore(" ", C.cWhite + "Active Filter: " + C.cGreen + filter, " ", + C.cGray + "Click to bring up an Anvil GUI", + C.cGray + "where you type and filter", + C.cGray + "Party invites by their name", + " ", + C.cGreen + "Input \"Clear Filter\" to remove the filter") + .setGlow(true) + .build(), plugin); + } + + @Override + public void onClick(Player player, ClickType clickType) + { + new InviteFilterMenu(getPlugin(), player, null).openInventory(); + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/InviteButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/InviteButton.java new file mode 100644 index 000000000..edc97abb3 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/InviteButton.java @@ -0,0 +1,42 @@ +package mineplex.core.party.ui.button.tools.invite; + +import mineplex.core.common.util.C; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.party.PartyManager; +import mineplex.core.party.ui.Button; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; + +/** + * Represents an invitation, to which a player can accept or deny + */ +public class InviteButton extends Button +{ + + private String _name; + + public InviteButton(String name, PartyManager plugin) + { + super(new ItemBuilder(Material.SKULL_ITEM) + .setTitle(C.cYellow + name) + .setLore(" ", C.cYellow + "Right-Click " + C.cGray + "to deny the invite", C.cYellow + "Left-Click " + C.cGray + "to accept the invite") + .setData((short) 3) + .setPlayerHead(name) + .build(), plugin); + _name = name; + } + + @Override + public void onClick(Player player, ClickType clickType) + { + if(clickType == ClickType.LEFT) + { + getPlugin().getMethodManager().respondToInvite(player, _name, true); + } else if(clickType == ClickType.RIGHT) + { + getPlugin().getMethodManager().respondToInvite(player, _name, false); + } + player.closeInventory(); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/NextPageButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/NextPageButton.java new file mode 100644 index 000000000..1b370911e --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/NextPageButton.java @@ -0,0 +1,49 @@ +package mineplex.core.party.ui.button.tools.invite; + +import mineplex.core.common.util.C; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.party.InviteData; +import mineplex.core.party.PartyManager; +import mineplex.core.party.ui.Button; +import mineplex.core.party.ui.button.IconButton; +import mineplex.core.party.ui.menus.PartyInvitesMenu; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + +import java.util.List; + +/** + * Shows the next page of invites for a player + */ +public class NextPageButton extends Button +{ + + private static final ItemStack ITEM = new ItemBuilder(Material.SIGN).setTitle(C.cYellow + "Next Page").build(); + + private final PartyInvitesMenu _menu; + + public NextPageButton(PartyInvitesMenu menu, PartyManager plugin) + { + super(ITEM, plugin); + _menu = menu; + } + + @Override + public void onClick(Player player, ClickType clickType) + { + _menu.setButton(45, new PrevPageButton(_menu, getPlugin())); + _menu.setCurrentPage(_menu.getCurrentPage() + 1); + if(_menu.getCurrentPage() == _menu.getPagesNeeded()) + { + _menu.setButton(53, new IconButton(new ItemStack(Material.AIR), getPlugin())); + } + List data = _menu.getDataForPage(_menu.getCurrentPage()); + for(int i = 0; i < data.size(); i++) + { + _menu.setButton(i + _menu.getStartingSlot(), new InviteButton(data.get(i).getInvitedTo(), getPlugin())); + } + _menu.update(player); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/PrevPageButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/PrevPageButton.java new file mode 100644 index 000000000..3400a86cd --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/invite/PrevPageButton.java @@ -0,0 +1,48 @@ +package mineplex.core.party.ui.button.tools.invite; + +import mineplex.core.common.util.C; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.party.InviteData; +import mineplex.core.party.PartyManager; +import mineplex.core.party.ui.Button; +import mineplex.core.party.ui.button.IconButton; +import mineplex.core.party.ui.menus.PartyInvitesMenu; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + +import java.util.List; + +/** + * Shows the previous page of invites for a player + */ +public class PrevPageButton extends Button +{ + + private static final ItemStack ITEM = new ItemBuilder(Material.SIGN).setTitle(C.cYellow + "Previous Page").build(); + + private final PartyInvitesMenu _menu; + + public PrevPageButton(PartyInvitesMenu menu, PartyManager plugin) + { + super(ITEM, plugin); + _menu = menu; + } + + @Override + public void onClick(Player player, ClickType clickType) + { + _menu.setCurrentPage(_menu.getCurrentPage() - 1); + if(_menu.getCurrentPage() == 0) + { + _menu.setButton(45, new IconButton(new ItemStack(Material.AIR), getPlugin())); + } + List data = _menu.getDataForPage(_menu.getCurrentPage()); + for(int i = 0; i < data.size(); i++) + { + _menu.setButton(i + _menu.getStartingSlot(), new InviteButton(data.get(i).getInvitedTo(), getPlugin())); + } + _menu.update(player); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/main/InvitePlayerButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/main/InvitePlayerButton.java new file mode 100644 index 000000000..162912d7b --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/main/InvitePlayerButton.java @@ -0,0 +1,34 @@ +package mineplex.core.party.ui.button.tools.main; + +import mineplex.core.common.util.C; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.party.PartyManager; +import mineplex.core.party.ui.Button; +import mineplex.core.party.ui.menus.input.PartyInvitePlayerMenu; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + +/** + * Invites a player to a new party + */ +public class InvitePlayerButton extends Button +{ + + private static final ItemStack ITEM = new ItemBuilder(Material.NAME_TAG) + .setTitle(C.cYellow + "Invite a Player") + .setLore(" ", C.cGray + "Invites a player to join", C.cGray + "you in a new party.") + .build(); + + public InvitePlayerButton(PartyManager plugin) + { + super(ITEM, plugin); + } + + @Override + public void onClick(Player player, ClickType clickType) + { + new PartyInvitePlayerMenu(getPlugin(), player, null).openInventory(); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/main/ViewInvitesButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/main/ViewInvitesButton.java new file mode 100644 index 000000000..3ae1c6cf7 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/main/ViewInvitesButton.java @@ -0,0 +1,34 @@ +package mineplex.core.party.ui.button.tools.main; + +import mineplex.core.common.util.C; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.party.PartyManager; +import mineplex.core.party.ui.Button; +import mineplex.core.party.ui.menus.PartyInvitesMenu; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + +/** + * Opens the {@code {@link PartyInvitesMenu}} + */ +public class ViewInvitesButton extends Button +{ + + private static final ItemStack ITEM = new ItemBuilder(Material.BOOK) + .setTitle(C.cYellow + "View Invites") + .setLore(" ", C.cGray + "Manage invites to parties.") + .build(); + + public ViewInvitesButton(PartyManager plugin) + { + super(ITEM, plugin); + } + + @Override + public void onClick(Player player, ClickType clickType) + { + new PartyInvitesMenu(getPlugin()).open(player); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/AddPlayerButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/AddPlayerButton.java new file mode 100644 index 000000000..e010089bd --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/AddPlayerButton.java @@ -0,0 +1,36 @@ +package mineplex.core.party.ui.button.tools.owner; + +import mineplex.core.common.util.C; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.party.Party; +import mineplex.core.party.PartyManager; +import mineplex.core.party.ui.button.tools.PartyButton; +import mineplex.core.party.ui.menus.input.PartyInvitePlayerMenu; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + +/** + * Sends an invitation to a specific player + */ +public class AddPlayerButton extends PartyButton +{ + + private static final ItemStack ITEM = new ItemBuilder(Material.SIGN) + .setTitle(C.cYellow + "Invite a Player") + .setLore(" ", C.cGray + "Brings up the Inviting Anvil!", C.cGray + "Simply type a player's name", C.cGray + "and click the paper to invite him") + .build(); + + public AddPlayerButton(PartyManager plugin, Party party) + { + super(ITEM, party, plugin); + } + + @Override + public void onClick(Player player, ClickType clickType) + { + new PartyInvitePlayerMenu(getPlugin(), player, getParty()).openInventory(); + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/DisbandPartyButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/DisbandPartyButton.java new file mode 100644 index 000000000..5c6ad0923 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/DisbandPartyButton.java @@ -0,0 +1,38 @@ +package mineplex.core.party.ui.button.tools.owner; + +import mineplex.core.common.util.C; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.party.PartyManager; +import mineplex.core.party.ui.Button; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + +/** + * Disbands a party + */ +public class DisbandPartyButton extends Button +{ + + private static final ItemStack ITEM = new ItemBuilder(Material.BARRIER) + .setTitle(C.cRedB + "Disband your party") + .setLore(" ", C.cGray + "This will erase your party!", C.cRed + "Shift-Right-Click" + C.cGray + " to disband.") + .build(); + + public DisbandPartyButton(PartyManager plugin) + { + super(ITEM, plugin); + } + + @Override + public void onClick(Player player, ClickType clickType) + { + if(clickType != ClickType.SHIFT_RIGHT) + { + return; + } + getPlugin().getMethodManager().disband(player); + player.closeInventory(); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/KickPlayerButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/KickPlayerButton.java new file mode 100644 index 000000000..03f02fed2 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/KickPlayerButton.java @@ -0,0 +1,56 @@ +package mineplex.core.party.ui.button.tools.owner; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.party.Party; +import mineplex.core.party.ui.Menu; +import mineplex.core.party.ui.button.tools.PartyButton; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + +/** + * Toggles {@code {@link Party#isOwnerKickMode()}} + */ +public class KickPlayerButton extends PartyButton +{ + + private static final ItemStack ITEM_OFF = new ItemBuilder(Material.IRON_AXE) + .setTitle(C.cYellow + "Kick Players") + .setLore(" ", F.elem("Right-Click") + " to enter " + C.cGreen + "Kick Mode", + C.cGray + "While activated, click on a player's head", C.cGray + "to remove them from the party") + .build(); + + private static final ItemStack ITEM_ON = new ItemBuilder(Material.IRON_AXE) + .setTitle(C.cYellow + "Kick Players") + .setLore(" ", F.elem("Right-Click") + " to leave " + C.cRed + "Kick Mode", + C.cGray + "While activated, click on a player's head", C.cGray + "to remove them from the party") + .setGlow(true) + .build(); + + + public KickPlayerButton(Party party) + { + super(ITEM_OFF, party, null); + } + + @Override + public void onClick(Player player, ClickType clickType) + { + if(clickType != ClickType.RIGHT) + { + return; + } + getParty().setOwnerKickMode(!getParty().isOwnerKickMode()); + if (getParty().isOwnerKickMode()) + { + setItemStack(ITEM_ON); + } else + { + setItemStack(ITEM_OFF); + } + Menu.get(player.getUniqueId()).update(player); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/SelectServerButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/SelectServerButton.java new file mode 100644 index 000000000..dbbd0a032 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/SelectServerButton.java @@ -0,0 +1,35 @@ +package mineplex.core.party.ui.button.tools.owner; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilServer; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.party.Party; +import mineplex.core.party.event.PartySelectServerEvent; +import mineplex.core.party.ui.button.tools.PartyButton; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + +/** + * Opens the server selection menu + */ +public class SelectServerButton extends PartyButton +{ + + private static final ItemStack ITEM = new ItemBuilder(Material.COMPASS) + .setTitle(C.cYellow + "Select Server") + .setLore(" ", C.cGray + "Brings up the Server Selection GUI") + .build(); + + public SelectServerButton(Party party) + { + super(ITEM, party, null); + } + + @Override + public void onClick(Player player, ClickType clickType) + { + UtilServer.getPluginManager().callEvent(new PartySelectServerEvent(player)); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/TransferOwnerButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/TransferOwnerButton.java new file mode 100644 index 000000000..5d49eae44 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/owner/TransferOwnerButton.java @@ -0,0 +1,36 @@ +package mineplex.core.party.ui.button.tools.owner; + +import mineplex.core.common.util.C; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.party.Party; +import mineplex.core.party.PartyManager; +import mineplex.core.party.ui.button.tools.PartyButton; +import mineplex.core.party.ui.menus.input.PartyTransferOwnerMenu; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + +/** + * Transfers ownership of a party to another player + */ +public class TransferOwnerButton extends PartyButton +{ + + private static final ItemStack ITEM = new ItemBuilder(Material.BOOK_AND_QUILL) + .setTitle(C.cYellow + "Transfer Ownership") + .setLore(" ", C.cGray + "Transfers ownership of the party", C.cGray + "to another player", + " ", C.cDRed + "This cannot be undone!") + .build(); + + public TransferOwnerButton(Party party, PartyManager plugin) + { + super(ITEM, party, plugin); + } + + @Override + public void onClick(Player player, ClickType clickType) + { + new PartyTransferOwnerMenu(getPlugin(), player, getParty()).openInventory(); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/view/SuggestPlayerButton.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/view/SuggestPlayerButton.java new file mode 100644 index 000000000..90c2aa8dc --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/button/tools/view/SuggestPlayerButton.java @@ -0,0 +1,35 @@ +package mineplex.core.party.ui.button.tools.view; + +import mineplex.core.common.util.C; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.party.Party; +import mineplex.core.party.PartyManager; +import mineplex.core.party.ui.button.tools.PartyButton; +import mineplex.core.party.ui.menus.input.PlayerSuggestPlayerMenu; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + +/** + * Suggest a new player to be invited + */ +public class SuggestPlayerButton extends PartyButton +{ + + private static final ItemStack ITEM = new ItemBuilder(Material.BOOK_AND_QUILL) + .setTitle(C.cYellow + "Suggest Player") + .setLore(" ", C.cGray + "Suggest a player for the owner to invite") + .build(); + + public SuggestPlayerButton(Party party, PartyManager plugin) + { + super(ITEM, party, plugin); + } + + @Override + public void onClick(Player player, ClickType clickType) + { + new PlayerSuggestPlayerMenu(getPlugin(), player, getParty()).openInventory(); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyInvitesMenu.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyInvitesMenu.java new file mode 100644 index 000000000..eb0e4f626 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyInvitesMenu.java @@ -0,0 +1,191 @@ +package mineplex.core.party.ui.menus; + +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.party.InviteData; +import mineplex.core.party.PartyManager; +import mineplex.core.party.ui.Button; +import mineplex.core.party.ui.Menu; +import mineplex.core.party.ui.button.IconButton; +import mineplex.core.party.ui.button.tools.invite.*; +import org.bukkit.DyeColor; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Player; + +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * The menu showing all pending invites for a player + */ +public class PartyInvitesMenu extends Menu +{ + + private final IconButton NO_INVITES = new IconButton(new ItemBuilder(Material.STAINED_GLASS_PANE) + .setData(DyeColor.RED.getWoolData()) + .setTitle(C.cRedB + "No Invites") + .build(), null); + + private final int SLOTS_PER_PAGE = 27; + private final int STARTING_SLOT = 18; + private final int BACK_BUTTON_SLOT = 0; + private final int DENY_ALL_BUTTON_SLOW = 4; + private final int FILTER_BUTTON_SLOT = 8; + private final int NEXT_PAGE_SLOT = 53; + private int _currentPage; + private int _pagesNeeded; + + private Map> _pagesOfData; + private List _data; + + private String _filterBy; + + public PartyInvitesMenu(PartyManager plugin) + { + super("Invites", plugin); + } + + public PartyInvitesMenu(PartyManager plugin, String filterBy) + { + this(plugin); + _filterBy = filterBy; + } + + @Override + protected Button[] setUp(Player player) + { + Button[] buttons = new Button[54]; + boolean showFiltered = false; + + buttons[BACK_BUTTON_SLOT] = new BackButton(_plugin); + + List all = (List) _plugin.getInviteManager().getAllInvites(player); + + if (all == null || all.isEmpty()) + { + for (int i = 10; i < 44; i++) + { + buttons[i] = NO_INVITES; + } + player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, .6f); + return addPanes(buttons); + } + + buttons[DENY_ALL_BUTTON_SLOW] = new DenyAllButton(_plugin); + + if (_filterBy == null || _filterBy.isEmpty()) + { + buttons[FILTER_BUTTON_SLOT] = new FilterButton(_plugin); + } else + { + showFiltered = true; + buttons[FILTER_BUTTON_SLOT] = new FilterButton(_filterBy, _plugin); + } + + if (showFiltered) + { + all = all.stream().filter(inviteData -> inviteData.getInvitedTo().contains(_filterBy)).collect(Collectors.toList()); + } + + if (showFiltered && all.isEmpty()) + { + for (int i = 10; i < 44; i++) + { + buttons[i] = new IconButton(new ItemBuilder(Material.STAINED_GLASS_PANE) + .setData(DyeColor.RED.getWoolData()) + .setTitle(C.cRedB + "No Invites Found") + .setLore(" ", C.cGray + "The filter " + F.name(_filterBy) + " had no results.") + .build(), _plugin); + } + player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, .6f); + return addPanes(buttons); + } + + _data = all; + + if (all.size() > SLOTS_PER_PAGE) + { + int pagesNeeded = 0; + int size = all.size(); + while (size > SLOTS_PER_PAGE) + { + pagesNeeded++; + size -= SLOTS_PER_PAGE; + } + buttons[NEXT_PAGE_SLOT] = new NextPageButton(this, _plugin); + + _pagesNeeded = pagesNeeded; + _pagesOfData = Maps.newHashMap(); + + int page = 0; + + List newData = Lists.newArrayList(); + int total = all.size(); + for (int i = 0; i < pagesNeeded; i++) + { + for (int s = 0; s < total; s++) + { + newData.add(all.remove(i)); + if (i > SLOTS_PER_PAGE) + { + _pagesOfData.put(page++, newData); + newData.clear(); + total -= SLOTS_PER_PAGE; + break; + } + } + } + //Add pages + } else + { + for (int i = 0; i < all.size(); i++) + { + String to = all.get(i).getInvitedTo(); + buttons[STARTING_SLOT + i] = new InviteButton(to, _plugin); + } + } + + + return addPanes(buttons); + } + + public void setButton(int slot, Button button) + { + getButtons()[slot] = button; + } + + public List getDataForPage(int page) + { + return _pagesOfData.get(page); + } + + public int getStartingSlot() + { + return STARTING_SLOT; + } + + public int getCurrentPage() + { + return _currentPage; + } + + public void setCurrentPage(int currentPage) + { + _currentPage = currentPage; + } + + public List getData() + { + return _data; + } + + public int getPagesNeeded() + { + return _pagesNeeded; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyMainMenu.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyMainMenu.java new file mode 100644 index 000000000..619e2f1f7 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyMainMenu.java @@ -0,0 +1,36 @@ +package mineplex.core.party.ui.menus; + +import mineplex.core.party.PartyManager; +import mineplex.core.party.ui.Button; +import mineplex.core.party.ui.Menu; +import mineplex.core.party.ui.button.tools.main.InvitePlayerButton; +import mineplex.core.party.ui.button.tools.main.ViewInvitesButton; +import org.bukkit.entity.Player; + +/** + * The main GUI for parties. + */ +public class PartyMainMenu extends Menu +{ + + private final int INV_SIZE = 9; + + private final int INVITE_PLAYER_BUTTON_SLOT = 3; + private final int VIEW_INVITES_BUTTON_SLOT = 5; + + public PartyMainMenu(PartyManager plugin) + { + super("Mineplex Parties", plugin); + } + + @Override + protected Button[] setUp(Player player) + { + Button[] buttons = new Button[INV_SIZE]; + + buttons[INVITE_PLAYER_BUTTON_SLOT] = new InvitePlayerButton(_plugin); + buttons[VIEW_INVITES_BUTTON_SLOT] = new ViewInvitesButton(_plugin); + + return buttons; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyOwnerMenu.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyOwnerMenu.java new file mode 100644 index 000000000..70380082e --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyOwnerMenu.java @@ -0,0 +1,85 @@ +package mineplex.core.party.ui.menus; + +import mineplex.core.party.Party; +import mineplex.core.party.PartyManager; +import mineplex.core.party.ui.Button; +import mineplex.core.party.ui.Menu; +import mineplex.core.party.ui.button.PartyMemberIcon; +import mineplex.core.party.ui.button.tools.LeavePartyButton; +import mineplex.core.party.ui.button.tools.owner.AddPlayerButton; +import mineplex.core.party.ui.button.tools.owner.DisbandPartyButton; +import mineplex.core.party.ui.button.tools.owner.KickPlayerButton; +import mineplex.core.party.ui.button.tools.owner.SelectServerButton; +import mineplex.core.party.ui.button.tools.owner.TransferOwnerButton; +import org.bukkit.entity.Player; + +/** + * The display menu for managing parties by the owner + */ +public class PartyOwnerMenu extends Menu +{ + + private final int STARTING_SLOT = 20; + private final int CUT_OFF_SLOT = 25; + private final int SKIP_TO_SLOT = 29; + private final int ADD_PLAYER_BUTTON_SLOT = 1; + private final int KICK_PLAYER_BUTTON_SLOT = 4; + private final int TRANSFER_OWNER_BUTTON_SLOT = 7; + private final int SELECT_SERVER_BUTTON_SLOT = 46; + private final int LEAVE_PARTY_BUTTON_SLOT = 49; + private final int DISBAND_PARTY_BUTTON_SLOW = 52; + + private Party _party; + + public PartyOwnerMenu(Party party, PartyManager plugin) + { + super("Manage Party", plugin); + _party = party; + //We want this disabled by default + if(_party.isOwnerKickMode()) + { + _party.setOwnerKickMode(false); + } + } + + @Override + protected Button[] setUp(Player player) + { + Button[] buttons = new Button[54]; + //Tools + buttons[ADD_PLAYER_BUTTON_SLOT] = new AddPlayerButton(_plugin, _party); + //Kick player + buttons[KICK_PLAYER_BUTTON_SLOT] = new KickPlayerButton(_party); + //Transfer ownership + buttons[TRANSFER_OWNER_BUTTON_SLOT] = new TransferOwnerButton(_party, _plugin); + //Go to server + buttons[SELECT_SERVER_BUTTON_SLOT] = new SelectServerButton(_party); + //Leave party + buttons[LEAVE_PARTY_BUTTON_SLOT] = new LeavePartyButton(_plugin); + //Disband + buttons[DISBAND_PARTY_BUTTON_SLOW] = new DisbandPartyButton(_plugin); + + int slot = STARTING_SLOT; + //Players + for (int i = 0; i < _party.getMembers().size(); i++) + { + if (slot == CUT_OFF_SLOT) + { + slot = SKIP_TO_SLOT; + } + String member = _party.getMembers().get(i); + buttons[slot++] = new PartyMemberIcon(member, _party, member.equalsIgnoreCase(_party.getOwner())); + } + + if(_party.getSize() == 5) + { + for(int i = 29; i < 34; i++) + { + buttons[i] = PURCHASE_MORE_SLOTS; + } + } + + + return addPanes(buttons); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyViewMenu.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyViewMenu.java new file mode 100644 index 000000000..5fc4cff5b --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/PartyViewMenu.java @@ -0,0 +1,55 @@ +package mineplex.core.party.ui.menus; + +import mineplex.core.party.Party; +import mineplex.core.party.PartyManager; +import mineplex.core.party.ui.Button; +import mineplex.core.party.ui.Menu; +import mineplex.core.party.ui.button.PartyMemberIcon; +import mineplex.core.party.ui.button.tools.LeavePartyButton; +import mineplex.core.party.ui.button.tools.view.SuggestPlayerButton; +import org.bukkit.entity.Player; + +/** + * The menu a player see's when he is a member, and not an owner, of a party. + */ +public class PartyViewMenu extends Menu +{ + + private final int STARTING_SLOT = 20; + private final int CUT_OFF_SLOT = 25; + private final int SKIP_TO_SLOT = 29; + private final int LEAVE_PARTY_BUTTON_SLOT = 3; + private final int SUGGEST_PLAYER_BUTTON_SLOT = 5; + + private Party _party; + + public PartyViewMenu(Party party, PartyManager plugin) + { + super(party.getName() + "'s Party", plugin); + _party = party; + } + + @Override + protected Button[] setUp(Player player) + { + Button[] buttons = new Button[54]; + //Tools + buttons[LEAVE_PARTY_BUTTON_SLOT] = new LeavePartyButton(_plugin); + //Suggest Player + buttons[SUGGEST_PLAYER_BUTTON_SLOT] = new SuggestPlayerButton(_party, _plugin); + + int slot = STARTING_SLOT; + //Players + for (int i = 0; i < _party.getMembers().size(); i++) + { + if (slot == CUT_OFF_SLOT) + { + slot = SKIP_TO_SLOT; + } + String member = _party.getMembers().get(i); + buttons[slot++] = new PartyMemberIcon(member, _party, member.equalsIgnoreCase(_party.getOwner())); + } + + return addPanes(buttons); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/input/InviteFilterMenu.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/input/InviteFilterMenu.java new file mode 100644 index 000000000..24de3bc87 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/input/InviteFilterMenu.java @@ -0,0 +1,30 @@ +package mineplex.core.party.ui.menus.input; + +import mineplex.core.party.Party; +import mineplex.core.party.PartyManager; +import mineplex.core.party.ui.menus.PartyInvitesMenu; +import mineplex.core.anvilMenu.PlayerInputActionMenu; +import org.bukkit.entity.Player; + +/** + * The anvil menu for filtering the players invite menu + */ +public class InviteFilterMenu extends PlayerInputActionMenu +{ + + public InviteFilterMenu(PartyManager partyManager, Player player, Party party) + { + super(partyManager, player, party); + } + + @Override + public void inputReceived(String name) + { + _player.closeInventory(); + if(name.equalsIgnoreCase("Clear Filter") || name.equalsIgnoreCase(" ")) + { + name = null; + } + new PartyInvitesMenu((PartyManager) _plugin, name).open(_player); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/input/PartyInvitePlayerMenu.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/input/PartyInvitePlayerMenu.java new file mode 100644 index 000000000..4e30ebc07 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/input/PartyInvitePlayerMenu.java @@ -0,0 +1,42 @@ +package mineplex.core.party.ui.menus.input; + +import mineplex.core.anvilMenu.player.PlayerNameMenu; +import mineplex.core.party.Party; +import mineplex.core.party.PartyManager; +import mineplex.core.party.ui.menus.PartyOwnerMenu; +import org.bukkit.Sound; +import org.bukkit.entity.Player; + +/** + * The anvil menu for inviting a player to a party + */ +public class PartyInvitePlayerMenu extends PlayerNameMenu +{ + + private PartyManager _partyManager; + + public PartyInvitePlayerMenu(PartyManager partyManager, Player player, Party party) + { + super(partyManager, partyManager.getClientManager(), player, party); + _partyManager = partyManager; + } + + @Override + public void onSuccess(String name) + { + _partyManager.getMethodManager().invite(_player, name); + _player.playSound(_player.getLocation(), Sound.NOTE_PLING, 1, 1.6f); + _player.closeInventory(); + if (_party == null) + { + return; + } + new PartyOwnerMenu(_party, _partyManager).open(_player); + } + + @Override + public void onFail(String name) + { + + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/input/PartyTransferOwnerMenu.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/input/PartyTransferOwnerMenu.java new file mode 100644 index 000000000..91305bfdc --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/input/PartyTransferOwnerMenu.java @@ -0,0 +1,43 @@ +package mineplex.core.party.ui.menus.input; + +import mineplex.core.anvilMenu.player.PlayerNameMenu; +import mineplex.core.party.Lang; +import mineplex.core.party.Party; +import mineplex.core.party.PartyManager; +import org.bukkit.entity.Player; + +/** + * + */ +public class PartyTransferOwnerMenu extends PlayerNameMenu +{ + + private PartyManager _partyManager; + + public PartyTransferOwnerMenu(PartyManager partyManager, Player player, Party party) + { + super(partyManager, partyManager.getClientManager(), player, party); + _partyManager = partyManager; + } + + + @Override + public void onSuccess(String name) + { + if(!_party.contains(name)) + { + Lang.NOT_MEMBER.send(_player, name); + return; + } + _partyManager.getMethodManager().transferOwner(name, _player.getName()); + Lang.TRANSFER_OWNER.send(_party, _player.getName(), name); + _player.closeInventory(); + _player.chat("/party"); + } + + @Override + public void onFail(String name) + { + + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/input/PlayerSuggestPlayerMenu.java b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/input/PlayerSuggestPlayerMenu.java new file mode 100644 index 000000000..d6fb40f38 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/ui/menus/input/PlayerSuggestPlayerMenu.java @@ -0,0 +1,61 @@ +package mineplex.core.party.ui.menus.input; + +import mineplex.core.anvilMenu.player.PlayerNameMenu; +import mineplex.core.common.jsonchat.ChildJsonMessage; +import mineplex.core.common.jsonchat.ClickEvent; +import mineplex.core.common.jsonchat.HoverEvent; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.party.Lang; +import mineplex.core.party.Party; +import mineplex.core.party.PartyManager; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +/** + * The Anvil Menu for handling suggestions + */ +public class PlayerSuggestPlayerMenu extends PlayerNameMenu +{ + + public PlayerSuggestPlayerMenu(PartyManager partyManager, Player player, Party party) + { + super(partyManager, partyManager.getClientManager(), player, party); + } + + @Override + public void onSuccess(String name) + { + if(_party == null || _party.getOwner() == null) + { + Lang.NO_PARTY.send(_player); + return; + } + + if(_party.contains(name)) + { + Lang.ALREADY_MEMBER.send(_player, name); + return; + } + + Player player = Bukkit.getPlayerExact(_party.getOwner()); + + _party.sendMessage(C.mHead + "Party> " + F.name(_player.getName()) + " has suggested " + F.name(name) + " be invited."); + + ChildJsonMessage message = new ChildJsonMessage("").extra(F.main("Party", "Click ")); + message.add(F.link("Invite " + name)) + .hover(HoverEvent.SHOW_TEXT, C.cGreen + "Clicking this will invite " + C.cYellow + name + C.cGreen + " to the party") + .click(ClickEvent.RUN_COMMAND, "/partyinvite " + name); + message.add(C.mBody + " to invite them"); + message.sendToPlayer(player); + + _player.closeInventory(); + _player.chat("/party"); + } + + @Override + public void onFail(String name) + { + + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/portal/Portal.java b/Plugins/Mineplex.Core/src/mineplex/core/portal/Portal.java index d5a24913f..813744f5d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/portal/Portal.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/portal/Portal.java @@ -93,37 +93,33 @@ public class Portal extends MiniPlugin final boolean override = serverName.equalsIgnoreCase("Lobby"); final Rank playerRank = _clientManager.Get(player).GetRank(); - + + if(event.isCancel() && !event.isDraggedByParty()) + { + return; + } + if (override) { sendPlayer(player, serverName); } + else { - runAsync(new Runnable() - { - public void run() - { - final MinecraftServer server = _repository.getServerStatus(serverName); - - if (server == null) - return; - - Bukkit.getServer().getScheduler().runTask(_plugin, new Runnable() + runAsync(() -> { + final MinecraftServer server = _repository.getServerStatus(serverName); + + if (server == null) + return; + + Bukkit.getServer().getScheduler().runTask(_plugin, () -> { + if (server.getPlayerCount() < server.getMaxPlayerCount() || playerRank.has(Rank.ULTRA)) { - public void run() - { - if (server.getPlayerCount() < server.getMaxPlayerCount() || playerRank.has(Rank.ULTRA)) - { - sendPlayer(player, serverName); - } - else - UtilPlayer.message( - player, - F.main(getName(), C.cGold + serverName + C.cRed + " is full!")); - } - }); - } + sendPlayer(player, serverName); + } + else + UtilPlayer.message(player, F.main(getName(), C.cGold + serverName + C.cRed + " is full!")); + }); }); } } @@ -140,20 +136,10 @@ public class Portal extends MiniPlugin if (callback == null) return; - Bukkit.getScheduler().runTaskAsynchronously(getPlugin(), new Runnable() - { - public void run() - { - final boolean serverExists = ServerManager.getServerRepository(_region).serverExists(serverName); - - Bukkit.getScheduler().runTask(getPlugin(), new Runnable() - { - public void run() - { - callback.run(serverExists); - } - }); - } + Bukkit.getScheduler().runTaskAsynchronously(getPlugin(), () -> { + final boolean serverExists = ServerManager.getServerRepository(_region).serverExists(serverName); + + Bukkit.getScheduler().runTask(getPlugin(), () -> callback.run(serverExists)); }); } @@ -205,16 +191,8 @@ public class Portal extends MiniPlugin player.sendPluginMessage(getPlugin(), "BungeeCord", b.toByteArray()); _connectingPlayers.add(player.getName()); - getScheduler().scheduleSyncDelayedTask(getPlugin(), new Runnable() - { - public void run() - { - _connectingPlayers.remove(player.getName()); - } - }, 20L); + getScheduler().scheduleSyncDelayedTask(getPlugin(), () -> _connectingPlayers.remove(player.getName()), 20L); - UtilPlayer.message( - player, - F.main(getName(), "You have been sent from " + C.cGold + _serverName + C.cGray + " to " + C.cGold + serverName)); + UtilPlayer.message(player, F.main(getName(), "You have been sent from " + C.cGold + _serverName + C.cGray + " to " + C.cGold + serverName)); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/portal/ServerTransferEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/portal/ServerTransferEvent.java index 94262b8d7..e2dc4c667 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/portal/ServerTransferEvent.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/portal/ServerTransferEvent.java @@ -11,6 +11,7 @@ public class ServerTransferEvent extends Event private Player _player; private String _server; private boolean _draggedByParty; + private boolean _cancel; public ServerTransferEvent(Player player, String server, boolean draggedByParty) { @@ -24,6 +25,11 @@ public class ServerTransferEvent extends Event return _draggedByParty; } + public void setDraggedByParty(boolean draggedByParty) + { + _draggedByParty = draggedByParty; + } + public HandlerList getHandlers() { return _handlers; @@ -44,4 +50,13 @@ public class ServerTransferEvent extends Event return _server; } + public boolean isCancel() + { + return _cancel; + } + + public void setCancel(boolean cancel) + { + _cancel = cancel; + } } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java index 37a50cbb3..da590e9b6 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java @@ -56,6 +56,7 @@ import mineplex.core.valentines.ValentinesGiftManager; import mineplex.core.youtube.YoutubeManager; import mineplex.hub.commands.*; import mineplex.hub.modules.*; +import mineplex.hub.modules.nonpremium.NonPremiumManager; import mineplex.hub.profile.gui.GUIProfile; import mineplex.hub.tutorial.TutorialManager; import mineplex.minecraft.game.classcombat.Skill.event.SkillTriggerEvent; @@ -243,6 +244,8 @@ public class HubManager extends MiniClientPlugin _valentinesManager = new ValentinesManager(plugin, clientManager, donationManager); + new NonPremiumManager(plugin, clientManager); + try { @@ -584,9 +587,9 @@ public class HubManager extends MiniClientPlugin if (rank != Rank.ALL) rankStr = rank.getTag(true, true) + " "; //Party Chat - if (event.getMessage().charAt(0) == '@') + if (event.getMessage().charAt(0) == '#') { - Party party = _partyManager.GetParty(player); + Party party = _partyManager.getParty(player); if (party != null) { event.getRecipients().clear(); @@ -594,7 +597,7 @@ public class HubManager extends MiniClientPlugin event.setMessage(event.getMessage().substring(1, event.getMessage().length())); event.setFormat(levelStr + C.cDPurple + C.Bold + "Party " + C.cWhite + C.Bold + playerName + " " + C.cPurple + "%2$s"); - for (String name : party.GetPlayers()) + for (String name : party.getMembers()) { Player other = UtilPlayer.searchExact(name); @@ -623,10 +626,6 @@ public class HubManager extends MiniClientPlugin component.addExtra(playerNameText); component.addExtra(" " + ChatColor.WHITE + event.getMessage()); -// JsonMessage jsonMessage = new JsonMessage(levelStr) -// .extra(JSONObject.escape(rankStr)).hover("show_text", rank.getColor() + rank.getTag(true, true) + ChatColor.WHITE + "\n" + rank.getDescription()) -// .add(JSONObject.escape(C.cYellow + playerName + " " + ChatColor.WHITE + event.getMessage())); - for (Player other : UtilServer.getPlayers()) { if (_tutorialManager.InTutorial(other)) @@ -635,9 +634,7 @@ public class HubManager extends MiniClientPlugin continue; } - // event.setMessage(event.getMessage()); - // event.setFormat(levelStr + rankStr + C.cYellow + playerName + " " + C.cWhite + "%2$s"); - if(!event.isCancelled()) + if (!event.isCancelled()) other.spigot().sendMessage(component); } event.setCancelled(true); @@ -712,9 +709,6 @@ public class HubManager extends MiniClientPlugin for (Player player : UtilServer.getPlayers()) { - //Dont Waste Time - if (_partyManager.GetParty(player) != null) - continue; //Return to Main Scoreboard if (!player.getScoreboard().equals(_scoreboards.get(player))) diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/nonpremium/MessageRepository.java b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/nonpremium/MessageRepository.java new file mode 100644 index 000000000..d42fcef34 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/nonpremium/MessageRepository.java @@ -0,0 +1,84 @@ +package mineplex.hub.modules.nonpremium; + +import mineplex.core.progression.util.SQLStatement; +import mineplex.serverdata.database.DBPool; +import org.bukkit.Bukkit; +import org.bukkit.plugin.java.JavaPlugin; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; + +/** + * + */ +public class MessageRepository +{ + + private static final String SCHEMA = "CREATE TABLE IF NOT EXISTS nonPremiumJoinMessage (message VARCHAR(256));"; + + private static final String QUERY = "SELECT `message` FROM `nonPremiumJoinMessage`;"; + private static final String UPDATE = "UPDATE `nonPremiumJoinMessage` SET `message` = ?;"; + private static final String INSERT = "INSERT INTO `nonPremiumJoinMessage` VALUES(?);"; + + private final JavaPlugin _plugin; + private String _message; + + public MessageRepository(JavaPlugin plugin) + { + _plugin = plugin; + } + + /** + * Update the message globally. + * + * @param message The new string literal message + */ + public void updateMessage(String message) + { + _message = message; + async(() -> { + try (Connection connection = DBPool.getAccount().getConnection()) + { + ResultSet resultSet = new SQLStatement(QUERY).prepare(connection).executeQuery(); + + if (!resultSet.next()) + { + new SQLStatement(INSERT).set(1, message).prepare(connection).executeUpdate(); + + } else + { + new SQLStatement(UPDATE).set(1, message).prepare(connection).executeUpdate(); + } + } catch (SQLException e) + { + e.printStackTrace(); + } + }); + } + + private void async(Runnable runnable) + { + Bukkit.getScheduler().runTaskAsynchronously(_plugin, runnable); + } + + public String getMessage() + { + if (_message == null) + { + try (Connection connection = DBPool.getAccount().getConnection()) + { + ResultSet resultSet = new SQLStatement(QUERY).prepare(connection).executeQuery(); + if (resultSet == null || !resultSet.next()) + { + return null; + } + _message = resultSet.getString(1); + } catch (SQLException e) + { + e.printStackTrace(); + } + } + return _message; + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/nonpremium/NPUMCommand.java b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/nonpremium/NPUMCommand.java new file mode 100644 index 000000000..cb4796759 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/nonpremium/NPUMCommand.java @@ -0,0 +1,47 @@ +package mineplex.hub.modules.nonpremium; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +/** + * + */ +public class NPUMCommand extends CommandBase +{ + + public NPUMCommand(NonPremiumManager plugin) + { + super(plugin, Rank.ADMIN, "updatemessage"); + } + + @Override + public void Execute(Player caller, String[] args) + { + if(!Plugin.getClientManager().Get(caller).GetRank().has(Rank.ADMIN)) { + caller.sendMessage(C.cRed + "No."); + return; + } + + if(args.length == 0) { + caller.sendMessage(F.main("NPUM", "Invalid Command Arguments. Usage: /updatemessage \"Message here\". Use '&' for color codes. Spaces are allowed.")); + return; + } + + StringBuilder message = new StringBuilder(); + + for(int i = 0; i < args.length; i++) { + message.append(args[i]); + if((i + 1) != args.length) { + message.append(" "); + } + } + + Plugin.setMessage(message.toString(), true); + caller.sendMessage(F.main("NPUM", "Non-Premium User message updated. New message: ")); + caller.sendMessage(ChatColor.translateAlternateColorCodes('&', message.toString())); + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/nonpremium/NonPremiumManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/nonpremium/NonPremiumManager.java new file mode 100644 index 000000000..78967ecde --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/nonpremium/NonPremiumManager.java @@ -0,0 +1,84 @@ +package mineplex.hub.modules.nonpremium; + +import mineplex.core.MiniPlugin; +import mineplex.core.account.CoreClientManager; +import mineplex.core.common.Rank; +import mineplex.core.common.util.C; +import mineplex.serverdata.commands.ServerCommandManager; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.plugin.java.JavaPlugin; + +/** + * + */ +public class NonPremiumManager extends MiniPlugin +{ + + private static final String LINE = C.cDGreenB + C.Strike + "============================================="; + + private String _message; + private MessageRepository _messageRepository; + private CoreClientManager _clientManager; + + public NonPremiumManager(JavaPlugin plugin, CoreClientManager clientManager) + { + super("NonPremiumPlayerManager", plugin); + addCommand(new NPUMCommand(this)); + _clientManager = clientManager; + _messageRepository = new MessageRepository(plugin); + _message = _messageRepository.getMessage(); + UpdateMessageHandler handler = new UpdateMessageHandler(this); + ServerCommandManager.getInstance().registerCommandType(UpdateMessageCommand.class, handler); + } + + @EventHandler + public void onJoin(PlayerJoinEvent event) + { + Player player = event.getPlayer(); + Rank rank = _clientManager.Get(player).GetRank(); + + if (_message == null) + { + return; + } + + if (rank != Rank.ALL) + { + return; + } + + getPlugin().getServer().getScheduler().runTaskLater(getPlugin(), () -> { + player.sendMessage(" "); + player.sendMessage(LINE); + player.sendMessage(" "); + player.sendMessage(ChatColor.translateAlternateColorCodes('&', _message)); + player.sendMessage(" "); + player.sendMessage(LINE); + player.sendMessage(" "); + player.sendMessage(" "); + }, 5L); + } + + public void setMessage(String message, boolean updateDB) + { + _message = message; + if (!updateDB) + { + return; + } + _messageRepository.updateMessage(message); + ServerCommandManager.getInstance().publishCommand(new UpdateMessageCommand(message, getServer())); + } + + public CoreClientManager getClientManager() + { + return _clientManager; + } + + public String getServer() { + return getPlugin().getConfig().getString("serverstatus.name"); + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/nonpremium/UpdateMessageCommand.java b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/nonpremium/UpdateMessageCommand.java new file mode 100644 index 000000000..c0033eaf0 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/nonpremium/UpdateMessageCommand.java @@ -0,0 +1,28 @@ +package mineplex.hub.modules.nonpremium; + +import mineplex.serverdata.commands.ServerCommand; + +/** + * + */ +public class UpdateMessageCommand extends ServerCommand +{ + + private String _message; + private String _from; + + public UpdateMessageCommand(String message, String from) { + _message = message; + _from = from; + } + + public String getMessage() + { + return _message; + } + + public String getFrom() + { + return _from; + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/nonpremium/UpdateMessageHandler.java b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/nonpremium/UpdateMessageHandler.java new file mode 100644 index 000000000..19b11bf36 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/nonpremium/UpdateMessageHandler.java @@ -0,0 +1,29 @@ +package mineplex.hub.modules.nonpremium; + +import mineplex.serverdata.commands.CommandCallback; +import mineplex.serverdata.commands.ServerCommand; + +/** + * + */ +public class UpdateMessageHandler implements CommandCallback +{ + + private final NonPremiumManager _manager; + + public UpdateMessageHandler(NonPremiumManager manager) { + _manager = manager; + } + + @Override + public void run(ServerCommand command) + { + if(!(command instanceof UpdateMessageCommand)) { + return; + } + if(_manager.getServer().equalsIgnoreCase(((UpdateMessageCommand) command).getFrom())) { + return; + } + _manager.setMessage(((UpdateMessageCommand) command).getMessage(), false); + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/queue/ui/QueuePage.java b/Plugins/Mineplex.Hub/src/mineplex/hub/queue/ui/QueuePage.java index f0a5122cb..7a44aee11 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/queue/ui/QueuePage.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/queue/ui/QueuePage.java @@ -1,10 +1,6 @@ package mineplex.hub.queue.ui; -import java.util.ArrayList; -import java.util.List; - import mineplex.core.account.CoreClientManager; -import mineplex.core.common.util.UtilPlayer; import mineplex.core.donation.DonationManager; import mineplex.core.party.Party; import mineplex.core.shop.item.IButton; @@ -12,12 +8,15 @@ import mineplex.core.shop.item.ShopItem; import mineplex.core.shop.page.ShopPageBase; import mineplex.hub.queue.PlayerMatchStatus; import mineplex.hub.queue.QueueManager; - +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; +import java.util.List; +import java.util.stream.Collectors; + public class QueuePage extends ShopPageBase { private boolean _closeOnNextUpdate; @@ -131,32 +130,17 @@ public class QueuePage extends ShopPageBase private void queuePlayer(int gameType, Player player) { - Party party = getPlugin().getPartyManager().GetParty(player); - - if (party != null) - { - if (player.getName().equals(party.GetLeader())) - { - List players = new ArrayList(); - - for (String name : party.GetPlayers()) - { - Player partyPlayer = UtilPlayer.searchExact(name); - - if (partyPlayer == null) - continue; - - players.add(partyPlayer); - } - - getPlugin().queuePlayer(gameType, players.toArray(new Player[]{})); - } - } - else + Party party = getPlugin().getPartyManager().getParty(player); + if(party == null) { getPlugin().queuePlayer(gameType, player); + return; + } + if(party.getOwner().equalsIgnoreCase(player.getName())) + { + List players = party.getMembers().stream().map(Bukkit::getPlayerExact).collect(Collectors.toList()); + getPlugin().queuePlayer(gameType, players.toArray(new Player[players.size()])); } - buildPage(); } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/queue/ui/QueueShop.java b/Plugins/Mineplex.Hub/src/mineplex/hub/queue/ui/QueueShop.java index 33b2c6bbd..7f1b163fc 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/queue/ui/QueueShop.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/queue/ui/QueueShop.java @@ -1,7 +1,5 @@ package mineplex.hub.queue.ui; -import java.util.Iterator; - import mineplex.core.account.CoreClientManager; import mineplex.core.common.util.C; import mineplex.core.common.util.F; @@ -11,12 +9,13 @@ import mineplex.core.shop.page.ShopPageBase; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.hub.queue.QueueManager; - import org.bukkit.ChatColor; import org.bukkit.Sound; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import java.util.Iterator; + public class QueueShop extends ShopBase { public QueueShop(QueueManager plugin, CoreClientManager clientManager, mineplex.core.donation.DonationManager donationManager, String name) @@ -33,9 +32,9 @@ public class QueueShop extends ShopBase @Override protected boolean canOpenShop(Player player) { - Party party = getPlugin().getPartyManager().GetParty(player); + Party party = getPlugin().getPartyManager().getParty(player); - if (party != null && !player.getName().equalsIgnoreCase(party.GetLeader())) + if (party != null && !player.getName().equalsIgnoreCase(party.getOwner())) { player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, .6f); player.sendMessage(F.main("Party", "Only Party Leaders can join games.")); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java index 3e0ac74e7..32ba26c92 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java @@ -13,6 +13,8 @@ import java.util.Set; import mineplex.core.boosters.BoosterManager; import mineplex.core.brawl.fountain.BrawlShopProvider; +import mineplex.core.party.Lang; +import mineplex.core.party.event.PartySelectServerEvent; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -67,7 +69,7 @@ import mineplex.serverdata.data.ServerGroup; public class ServerManager extends MiniDbClientPlugin implements BrawlShopProvider { - private static final Long FREE_PORTAL_TIMER = 20000L; + private static final Long FREE_PORTAL_TIMER = -1L; private static final Long BETA_PORTAL_TIMER = 120000L; private static final Random random = new Random(); @@ -352,7 +354,13 @@ public class ServerManager extends MiniDbClientPlugin implement { return _serverInfoMap.get(serverName); } - + + @EventHandler + public void onClickCompassPartyIcon(PartySelectServerEvent event) + { + _quickShop.attemptShopOpen(event.getPlayer()); + } + @EventHandler public void updatePages(UpdateEvent event) { @@ -512,17 +520,23 @@ public class ServerManager extends MiniDbClientPlugin implement return _partyManager; } - public void selectServer(org.bukkit.entity.Player player, ServerInfo serverInfo) + public void selectServer(Player player, ServerInfo serverInfo) { - Party party = _partyManager.GetParty(player); - - if (party == null || player.getName().equals(party.GetLeader())) + Party party = _partyManager.getParty(player); + if(party != null) { - player.leaveVehicle(); - player.eject(); - - _portal.sendPlayerToServer(player, serverInfo.Name); + if(!party.getOwner().equalsIgnoreCase(player.getName())) + { + Lang.NOT_OWNER_SERVER.send(player); + return; + } + _partyManager.getJoinManager().requestServerJoin(serverInfo.Name, party); + return; } + player.leaveVehicle(); + player.eject(); + + _portal.sendPlayerToServer(player, serverInfo.Name); } /** @@ -578,7 +592,7 @@ public class ServerManager extends MiniDbClientPlugin implement } /** - * @param serverType - the type of server that should be fetched + * @param serverKey - the type of server that should be fetched * @return the best server that a new player should join according to a {@code serverType} constraint. */ public ServerInfo getBestServer(Player player, String serverKey) @@ -735,32 +749,9 @@ public class ServerManager extends MiniDbClientPlugin implement public int getRequiredSlots(Player player, String serverType) { int slots = 0; - - Party party = _partyManager.GetParty(player); - - if (party != null) - { - if (player.getName().equals(party.GetLeader())) - { - for (String name : party.GetPlayers()) - { - Player partyPlayer = UtilPlayer.searchExact(name); - - if (partyPlayer == null) - continue; - - if (_clientManager.Get(partyPlayer).GetRank().has(Rank.ULTRA) || _donationManager.Get(partyPlayer.getName()).OwnsUnknownPackage(serverType + " ULTRA")) - continue; - - slots++; - } - } - } - else - { - if (!_clientManager.Get(player).GetRank().has(Rank.ULTRA) && !_donationManager.Get(player.getName()).OwnsUnknownPackage(serverType + " ULTRA")) - slots++; - } + + if (!_clientManager.Get(player).GetRank().has(Rank.ULTRA) && !_donationManager.Get(player.getName()).OwnsUnknownPackage(serverType + " ULTRA")) + slots++; return slots; } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcPage.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcPage.java index 34ce492a1..18df137c9 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcPage.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcPage.java @@ -92,6 +92,10 @@ public class ServerNpcPage extends ShopPageInventory { @@ -41,9 +40,9 @@ public class ServerNpcShop extends ShopBase @Override protected boolean canOpenShop(Player player) { - Party party = getPlugin().getPartyManager().GetParty(player); - - if (party != null && !player.getName().equalsIgnoreCase(party.GetLeader())) + Party party = getPlugin().getPartyManager().getParty(player); + + if (party != null && !player.getName().equalsIgnoreCase(party.getOwner())) { player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, .6f); player.sendMessage(F.main("Party", "Only Party Leaders can join games.")); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClanMoveServerShop.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClanMoveServerShop.java index e85528ee8..84f99ce39 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClanMoveServerShop.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClanMoveServerShop.java @@ -1,8 +1,5 @@ package mineplex.hub.server.ui.clans; -import org.bukkit.Sound; -import org.bukkit.entity.Player; - import mineplex.core.account.CoreClientManager; import mineplex.core.common.util.F; import mineplex.core.donation.DonationManager; @@ -12,6 +9,8 @@ import mineplex.core.shop.page.ShopPageBase; import mineplex.game.clans.core.repository.ClanRepository; import mineplex.game.clans.core.repository.tokens.SimpleClanToken; import mineplex.hub.server.ServerManager; +import org.bukkit.Sound; +import org.bukkit.entity.Player; public class ClanMoveServerShop extends ShopBase { @@ -37,7 +36,7 @@ public class ClanMoveServerShop extends ShopBase @Override protected boolean canOpenShop(Player player) { - Party party = getPlugin().getPartyManager().GetParty(player); + Party party = getPlugin().getPartyManager().getParty(player); if (party != null) { diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClansServerShop.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClansServerShop.java index f5590b095..6d6926a16 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClansServerShop.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClansServerShop.java @@ -1,8 +1,5 @@ package mineplex.hub.server.ui.clans; -import org.bukkit.Sound; -import org.bukkit.entity.Player; - import mineplex.core.account.CoreClientManager; import mineplex.core.common.util.F; import mineplex.core.donation.DonationManager; @@ -11,6 +8,8 @@ import mineplex.core.shop.ShopBase; import mineplex.core.shop.page.ShopPageBase; import mineplex.game.clans.core.repository.ClanRepository; import mineplex.hub.server.ServerManager; +import org.bukkit.Sound; +import org.bukkit.entity.Player; public class ClansServerShop extends ShopBase { @@ -32,7 +31,7 @@ public class ClansServerShop extends ShopBase @Override protected boolean canOpenShop(Player player) { - Party party = getPlugin().getPartyManager().GetParty(player); + Party party = getPlugin().getPartyManager().getParty(player); if (party != null) { diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/GameType.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/GameType.java index a6a4c2880..c0deac097 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/GameType.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/GameType.java @@ -38,6 +38,7 @@ public enum GameType Micro("Micro Battle"), MineStrike("MineStrike"), MineWare("MineWare"), + MinecraftLeague("MCL"), MilkCow("Milk the Cow"), MonsterLeague("MonsterLeague"), MonsterMaze("Monster Maze"), @@ -53,6 +54,7 @@ public enum GameType SmashDomination("Super Smash Mobs Domination", "Super Smash Mobs"), Snake("Snake"), SneakyAssassins("Sneaky Assassins"), + SpeedBuilders("SpeedBuilders"), SnowFight("Snow Fight"), Spleef("Super Spleef"), SpleefTeams("Super Spleef Teams"), diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/GameTypeInfo.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/GameTypeInfo.java new file mode 100644 index 000000000..7ff04194b --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/GameTypeInfo.java @@ -0,0 +1,60 @@ +package mineplex.mapparser; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import net.md_5.bungee.api.ChatColor; +import org.bukkit.entity.Player; + +import java.util.List; + +/** + * + */ +public class GameTypeInfo +{ + + private final String LINE = C.cAqua + C.Bold + C.Strike + "========================================"; + + private GameType _gameType; + private List _info; + + public GameTypeInfo(GameType gameType, List info) + { + _gameType = gameType; + _info = info; + } + + public void addInfo(String info) + { + _info.add(info); + } + + public void remove(int index) + { + _info.remove(index); + } + + public List getInfo() + { + return _info; + } + + public void sendInfo(Player player) + { + player.sendMessage(LINE); + player.sendMessage(" "); + player.sendMessage(F.elem(_gameType.GetName())); + player.sendMessage(" "); + for(String s : _info) + { + player.sendMessage(ChatColor.translateAlternateColorCodes('&', s)); + } + player.sendMessage(" "); + player.sendMessage(LINE); + } + + public GameType getGameType() + { + return _gameType; + } +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapData.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapData.java index 3248ac842..a87e4e8b9 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapData.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapData.java @@ -1,5 +1,11 @@ package mineplex.mapparser; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; +import mineplex.core.common.util.UtilWorld; +import org.bukkit.Location; +import org.bukkit.entity.Player; + import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.DataInputStream; @@ -7,30 +13,39 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileWriter; import java.io.InputStreamReader; -import java.util.HashSet; +import java.util.Collections; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; -import org.bukkit.entity.Player; - -public class MapData +public class MapData { public String MapFolder; + public boolean _currentlyLive; + public boolean _locked; + public Map _warps; public GameType MapGameType = null; public String MapName = "null"; public String MapCreator = "null"; - public HashSet AdminList; - + public Set AdminList; + public MapData(String mapFolder) { MapFolder = mapFolder; - AdminList = new HashSet(); - + AdminList = Sets.newHashSet(); + _warps = Maps.newHashMap(); + _currentlyLive = false; + if ((new File(MapFolder + File.separator + "Map.dat")).exists()) + { Read(); - else + } else + { Write(); + } } public void Read() @@ -43,46 +58,74 @@ public class MapData DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); - while ((line = br.readLine()) != null) + while ((line = br.readLine()) != null) { String[] tokens = line.split(":"); if (tokens.length < 2) + { continue; + } if (tokens[0].length() == 0) + { continue; + } + + if(tokens[0].equalsIgnoreCase("locked")) + { + _locked = tokens[1].equalsIgnoreCase("true"); + continue; + } + + if (tokens[0].equalsIgnoreCase("currentlyLive")) + { + _currentlyLive = tokens[1].equalsIgnoreCase("true"); + continue; + } + + if (tokens[0].equalsIgnoreCase("warps")) + { + for (String s : tokens[1].split(";")) + { + String[] str = s.split("@"); + _warps.put(str[0], UtilWorld.strToLoc(str[1])); + } + continue; + } //Name & Author if (tokens[0].equalsIgnoreCase("MAP_NAME")) { MapName = tokens[1]; + continue; } - else if (tokens[0].equalsIgnoreCase("MAP_AUTHOR")) + + if (tokens[0].equalsIgnoreCase("MAP_AUTHOR")) { MapCreator = tokens[1]; + continue; } - else if (tokens[0].equalsIgnoreCase("GAME_TYPE")) + + if (tokens[0].equalsIgnoreCase("GAME_TYPE")) { try { MapGameType = GameType.valueOf(tokens[1] == null ? "Unknown" : tokens[1]); - } - catch (Exception e) + } catch (Exception e) { MapGameType = GameType.Unknown; } + continue; } - else if (tokens[0].equalsIgnoreCase("ADMIN_LIST") || tokens[0].equalsIgnoreCase("BUILD_LIST")) + if (tokens[0].equalsIgnoreCase("ADMIN_LIST") || tokens[0].equalsIgnoreCase("BUILD_LIST")) { - for (String cur : tokens[1].split(",")) - AdminList.add(cur); + Collections.addAll(AdminList, tokens[1].split(",")); } } in.close(); - } - catch (Exception e) + } catch (Exception e) { e.printStackTrace(); System.err.println("Line: " + line); @@ -97,39 +140,60 @@ public class MapData FileWriter fstream = new FileWriter(MapFolder + File.separator + "Map.dat"); BufferedWriter out = new BufferedWriter(fstream); - out.write("MAP_NAME:"+MapName); + out.write("MAP_NAME:" + MapName); out.write("\n"); - out.write("MAP_AUTHOR:"+MapCreator); + out.write("MAP_AUTHOR:" + MapCreator); out.write("\n"); - out.write("GAME_TYPE:"+MapGameType); - + out.write("GAME_TYPE:" + MapGameType); + String adminList = ""; + for (String cur : AdminList) + { adminList += cur + ","; - + } + out.write("\n"); - out.write("ADMIN_LIST:"+adminList); + out.write("ADMIN_LIST:" + adminList); + out.write("\n"); + out.write("currentlyLive:" + _currentlyLive); + out.write("\n"); + out.write("warps:" + warpsToString()); out.close(); - } - catch (Exception e) + } catch (Exception e) { e.printStackTrace(); } } - public boolean HasAccess(Player player) + public String warpsToString() + { + StringBuilder builder = new StringBuilder(); + int i = 0; + for (Entry entry : _warps.entrySet()) + { + builder.append(entry.getKey()).append("@").append(UtilWorld.locToStr(entry.getValue())); + if (++i != _warps.size()) + { + builder.append(","); + } + } + return builder.toString(); + } + + public boolean HasAccess(Player player) { return AdminList.contains(player.getName()) || player.isOp(); } - - public boolean CanJoin(Player player) + + public boolean CanJoin(Player player) { - return true; + return !_locked || (player.isOp() || AdminList.contains(player.getName())); } public boolean CanRename(Player player) { - return true; + return !_locked || (player.isOp() || AdminList.contains(player.getName())); } } diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java index 86a7e7b6c..9105e8ea6 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java @@ -1,222 +1,141 @@ package mineplex.mapparser; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; import mineplex.core.common.util.C; -import mineplex.core.common.util.Callback; import mineplex.core.common.util.F; -import mineplex.core.common.util.MapUtil; import mineplex.core.common.util.UtilBlock; -import mineplex.core.common.util.UtilEvent; -import mineplex.core.common.util.UtilEvent.ActionType; -import mineplex.core.common.util.UtilGear; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; -import mineplex.core.common.util.UtilTime; -import mineplex.core.common.util.UtilWorld; -import mineplex.mapparser.command.*; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.GameMode; +import mineplex.mapparser.command.AddLoreCommand; +import mineplex.mapparser.command.AddSplashTextCommand; +import mineplex.mapparser.command.AdminCommand; +import mineplex.mapparser.command.AuthorCommand; +import mineplex.mapparser.command.ClearLoreCommand; +import mineplex.mapparser.command.CopyCommand; +import mineplex.mapparser.command.CopySchematicsCommand; +import mineplex.mapparser.command.CreateCommand; +import mineplex.mapparser.command.CurrentlyLiveCommand; +import mineplex.mapparser.command.DeleteCommand; +import mineplex.mapparser.command.GameTypeCommand; +import mineplex.mapparser.command.HubCommand; +import mineplex.mapparser.command.InfoCommand; +import mineplex.mapparser.command.ItemNameCommand; +import mineplex.mapparser.command.ListCommand; +import mineplex.mapparser.command.LockCommand; +import mineplex.mapparser.command.MapCommand; +import mineplex.mapparser.command.NameCommand; +import mineplex.mapparser.command.PMCommand; +import mineplex.mapparser.command.ParseCommand200; +import mineplex.mapparser.command.ParseCommand400; +import mineplex.mapparser.command.ParseCommand600; +import mineplex.mapparser.command.PlayerHeadCommand; +import mineplex.mapparser.command.RefreshWorldEditCommand; +import mineplex.mapparser.command.RenameCommand; +import mineplex.mapparser.command.SaveCommand; +import mineplex.mapparser.command.SetSpawnCommand; +import mineplex.mapparser.command.SpawnCommand; +import mineplex.mapparser.command.WarpCommand; +import mineplex.mapparser.command.WorldsCommand; +import mineplex.mapparser.module.Module; +import mineplex.mapparser.module.modules.CommandModule; +import mineplex.mapparser.module.modules.EventModule; +import mineplex.mapparser.module.modules.MMMazeModule; +import mineplex.mapparser.module.modules.SignModule; +import mineplex.mapparser.module.modules.TreeToolModule; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.LivingEntity; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.block.Action; -import org.bukkit.event.block.BlockBurnEvent; -import org.bukkit.event.block.BlockFadeEvent; -import org.bukkit.event.block.BlockFormEvent; -import org.bukkit.event.block.BlockIgniteEvent; -import org.bukkit.event.block.BlockIgniteEvent.IgniteCause; -import org.bukkit.event.block.BlockSpreadEvent; -import org.bukkit.event.block.LeavesDecayEvent; -import org.bukkit.event.block.SignChangeEvent; -import org.bukkit.event.entity.EntitySpawnEvent; -import org.bukkit.event.player.AsyncPlayerChatEvent; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerMoveEvent; -import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.util.Vector; -public class MapParser extends JavaPlugin implements Listener +import java.io.File; +import java.io.IOException; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +public class MapParser extends JavaPlugin { private WorldManager _worldManager; private Parse _curParse = null; - private HashMap _mapData = new HashMap(); - private HashSet _mapsBeingZipped = new HashSet(); - private List _commands = new ArrayList(); + private final Map, Module> _modules = Maps.newHashMap(); + private final Map _infoMap = Maps.newHashMap(); + private final Map _mapData = Maps.newHashMap(); + public final Set _mapsBeingZipped = Sets.newHashSet(); + private List _additionalText = Lists.newArrayList(); private Location _spawnLocation; - private HashMap _permissionMap = new HashMap(); @Override public void onEnable() { _worldManager = new WorldManager(this); - getServer().getPluginManager().registerEvents(this, this); - getServer().getWorlds().get(0).setSpawnLocation(0, 106, 0); _spawnLocation = new Location(getServer().getWorlds().get(0), 0, 106, 0); //Updates getServer().getScheduler().scheduleSyncRepeatingTask(this, new Ticker(this), 1, 1); - _commands.add(new AuthorCommand(this)); - _commands.add(new AdminCommand(this)); - _commands.add(new CopySchematicsCommand(this)); - _commands.add(new CreateCommand(this)); - _commands.add(new DeleteCommand(this)); - _commands.add(new GameTypeCommand(this)); - _commands.add(new HubCommand(this)); - _commands.add(new ListCommand(this)); - _commands.add(new MapCommand(this)); - _commands.add(new NameCommand(this)); - _commands.add(new ParseCommand200(this)); - _commands.add(new ParseCommand400(this)); - _commands.add(new ParseCommand600(this)); - _commands.add(new RenameCommand(this)); - _commands.add(new SaveCommand(this)); - _commands.add(new WorldsCommand(this)); - _commands.add(new CopyCommand(this)); - _commands.add(new SpawnCommand(this)); - _commands.add(new SetSpawnCommand(this)); - _commands.add(new ItemNameCommand(this)); - _commands.add(new AddLoreCommand(this)); - _commands.add(new ClearLoreCommand(this)); + CommandModule commandModule = new CommandModule(this); + new EventModule(this); + new MMMazeModule(this); + new SignModule(this); + new TreeToolModule(this); + + commandModule.add(new AuthorCommand(this)); + commandModule.add(new AdminCommand(this)); + commandModule.add(new CopySchematicsCommand(this)); + commandModule.add(new CreateCommand(this)); + commandModule.add(new DeleteCommand(this)); + commandModule.add(new GameTypeCommand(this)); + commandModule.add(new HubCommand(this)); + commandModule.add(new ListCommand(this)); + commandModule.add(new MapCommand(this)); + commandModule.add(new NameCommand(this)); + commandModule.add(new ParseCommand200(this)); + commandModule.add(new ParseCommand400(this)); + commandModule.add(new ParseCommand600(this)); + commandModule.add(new RenameCommand(this)); + commandModule.add(new SaveCommand(this)); + commandModule.add(new WorldsCommand(this)); + commandModule.add(new CopyCommand(this)); + commandModule.add(new SpawnCommand(this)); + commandModule.add(new SetSpawnCommand(this)); + commandModule.add(new ItemNameCommand(this)); + commandModule.add(new AddLoreCommand(this)); + commandModule.add(new ClearLoreCommand(this)); + commandModule.add(new InfoCommand(this)); + commandModule.add(new LockCommand(this)); + commandModule.add(new PlayerHeadCommand(this)); + commandModule.add(new RefreshWorldEditCommand(this)); + commandModule.add(new WarpCommand(this)); + commandModule.add(new CurrentlyLiveCommand(this)); + commandModule.add(new AddSplashTextCommand(this)); + commandModule.add(new PMCommand(this)); + + loadInfo(); + addSplashText(); } @Override public void onDisable() { - - } - - @EventHandler - public void PlayerJoin(PlayerJoinEvent event) - { - Player player = event.getPlayer(); - - player.teleport(getSpawnLocation()); - - ResetInventory(event.getPlayer()); - - DisplayHelp(player); + _infoMap.values().forEach(this::saveInfo); + saveSplashText(); } - @EventHandler - public void permissionUpdate(TickEvent event) + public Parse getCurParse() { - for (Player player : UtilServer.getPlayers()) - { - permissionSet(player); - } - } - - public void permissionSet(Player player) - { - boolean hasPermission = GetData(player.getWorld().getName()).HasAccess(player); - - if (!_permissionMap.containsKey(player) || _permissionMap.get(player) != hasPermission) - { - for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) - { - player.addAttachment(plugin, "worldedit.*", hasPermission); - player.addAttachment(plugin, "voxelsniper.sniper", hasPermission); - player.addAttachment(plugin, "voxelsniper.brush.*", hasPermission); - player.addAttachment(plugin, "coloredsigns.format", hasPermission); - } - - _permissionMap.put(player, hasPermission); - - UtilPlayer.message(player, "Plugin Permissions: " + F.tf(hasPermission)); - } - } - - - public void DisplayHelp(Player player) - { - UtilPlayer.message(player, F.main("Parser", "Listing Commands;")); - UtilPlayer.message(player, F.value("Parameters", "Parameters: = Required, [?] = Optional")); - UtilPlayer.message(player, F.value("/hub", "Return to hub world")); - UtilPlayer.message(player, " "); - UtilPlayer.message(player, F.value("/name ", "Set name for current map")); - UtilPlayer.message(player, F.value("/author ", "Set author for current map")); - UtilPlayer.message(player, F.value("/gametype ", "Set gametype for current map")); - UtilPlayer.message(player, " "); - UtilPlayer.message(player, F.value("/admin ", "Toggle admin for player on map")); - UtilPlayer.message(player, " "); - UtilPlayer.message(player, F.value("/create [gametype]", "Creates a new map")); - UtilPlayer.message(player, F.value("/delete [gametype]", "Deletes an existing map")); - UtilPlayer.message(player, F.value("/copy ", "Copies an existing map")); - UtilPlayer.message(player, " "); - UtilPlayer.message(player, F.value("/list", "List maps")); - UtilPlayer.message(player, F.value("/map [gametype]", "Teleport to a map")); - UtilPlayer.message(player, " "); - UtilPlayer.message(player, C.cYellow + "Documentation: " + C.cGreen + "http://tinyurl.com/mpxmaps"); - - } - - @EventHandler - public void Command(PlayerCommandPreprocessEvent event) - { - Player player = event.getPlayer(); - - String[] parts = event.getMessage().split(" "); - String commandLabel = parts[0].substring(1); - String[] args = new String[parts.length - 1]; - System.arraycopy(parts, 1, args, 0, parts.length - 1); - - if (_curParse != null) - { - UtilPlayer.message(player, F.main("Parser", "Cannot use commands during Map Parse!")); - return; - } - if (event.getMessage().toLowerCase().startsWith("/help")) - { - event.setCancelled(true); - - DisplayHelp(player); - } - - for (BaseCommand command : _commands) - { - for (String alias : command.getAliases()) - { - if (alias.equalsIgnoreCase(commandLabel)) - { - event.setCancelled(true); - - if (!command.execute(player, commandLabel, args)) - { - UtilPlayer.message(player, F.main("Parser", "Invalid Input.")); - UtilPlayer.message(player, F.elem(command.getUsage())); - } - - return; - } - } - } + return _curParse; } public void sendValidGameTypes(Player player) @@ -233,128 +152,105 @@ public class MapParser extends JavaPlugin implements Listener player.sendMessage(gameTypes); } - @EventHandler - public void ParseUpdate(TickEvent event) + public GameTypeInfo getInfo(GameType type) { - if (_curParse == null) - return; + return _infoMap.get(type); + } - if (_curParse.Update()) + private void addSplashText() + { + File file = new File(getDataFolder(), "join-text.yml"); + if(!file.exists()) { - Announce("Parse Completed!"); - - Announce("Cleaning and Creating ZIP..."); - try { - _worldManager.finalizeParsedWorld(_curParse.getWorld()); - } - catch (Exception e) + file.createNewFile(); + } catch (IOException e) { - Announce("Creating ZIP Failed! Please Try Again!"); e.printStackTrace(); } - - _curParse = null; } - } - - @EventHandler - public void DisableCreatures(EntitySpawnEvent event) - { - if (event.getEntityType() == EntityType.DROPPED_ITEM || event.getEntity() instanceof LivingEntity) - event.setCancelled(true); - } - - @EventHandler - public void DisableBurn(BlockBurnEvent event) - { - event.setCancelled(true); - } - - @EventHandler - public void DisableIgnite(BlockIgniteEvent event) - { - if (event.getCause() == IgniteCause.LAVA || event.getCause() == IgniteCause.SPREAD) - event.setCancelled(true); - } - - @EventHandler - public void DisableFire(BlockSpreadEvent event) - { - event.setCancelled(true); - } - - @EventHandler - public void DisableFade(BlockFadeEvent event) - { - event.setCancelled(true); - } - - @EventHandler - public void DisableDecay(LeavesDecayEvent event) - { - event.setCancelled(true); - } - - @EventHandler - public void DisableIceForm(BlockFormEvent event) - { - event.setCancelled(true); - } - - @EventHandler - public void Updates(PlayerMoveEvent event) - { - for (World world : this.getServer().getWorlds()) + FileConfiguration config = YamlConfiguration.loadConfiguration(file); + List messages = config.getStringList("messages"); + if(messages == null) { - if (world.getName().toLowerCase().contains("halloween")) - world.setTime(16000); - else - world.setTime(8000); - world.setStorm(false); + messages = Lists.newArrayList(); } - - - if (event.getPlayer().getGameMode() != GameMode.CREATIVE) - event.getPlayer().setGameMode(GameMode.CREATIVE); + _additionalText = messages; } - @EventHandler - public void SaveUnloadWorlds(TickEvent event) + private void saveSplashText() { - for (final World world : getServer().getWorlds()) + File file = new File(getDataFolder(), "join-text.yml"); + if(!file.exists()) { - if (world.getName().equalsIgnoreCase("world")) - continue; - - if (world.getName().startsWith("parse_")) - continue; - - if (!world.getName().startsWith("map")) - continue; - - if (world.getPlayers().isEmpty()) + try { - Announce("Saving & Closing World: " + F.elem(world.getName())); - MapUtil.UnloadWorld(this, world, true); - - _mapsBeingZipped.add(world.getName()); - System.out.println("Starting backup of " + world); - BackupTask backupTask = new BackupTask(this, world.getName(), new Callback() - { - @Override - public void run(Boolean data) - { - System.out.println("Finished backup of " + world); - _mapsBeingZipped.remove(world.getName()); - } - }); + file.createNewFile(); + } catch (IOException e) + { + e.printStackTrace(); } } + FileConfiguration config = YamlConfiguration.loadConfiguration(file); + config.set("messages", _additionalText); + try + { + config.save(file); + } catch (IOException e) + { + e.printStackTrace(); + } } - public void Announce(String msg) + private void loadInfo() + { + File file = new File(getDataFolder(), "info.yml"); + if(!file.exists()) + { + try + { + file.createNewFile(); + } catch (IOException e) + { + e.printStackTrace(); + } + } + FileConfiguration config = YamlConfiguration.loadConfiguration(file); + + for(String s : config.getKeys(false)) + { + GameType gameType = GameType.valueOf(s); + List messages = config.getStringList(s); + _infoMap.put(gameType, new GameTypeInfo(gameType, messages)); + } + } + + private void saveInfo(GameTypeInfo info) + { + File file = new File(getDataFolder(), "info.yml"); + if(!file.exists()) + { + try + { + file.createNewFile(); + } catch (IOException e) + { + e.printStackTrace(); + } + } + FileConfiguration config = YamlConfiguration.loadConfiguration(file); + config.set(info.getGameType().name(), info.getInfo()); + try + { + config.save(file); + } catch (IOException e) + { + e.printStackTrace(); + } + } + + public void announce(String msg) { for (Player player : UtilServer.getPlayers()) { @@ -364,19 +260,17 @@ public class MapParser extends JavaPlugin implements Listener System.out.println("[Announce] " + msg); } - public boolean DoesMapExist(String mapName, GameType gameType) + public boolean doesMapExist(String mapName, GameType gameType) { - return DoesMapExist(getWorldString(mapName, gameType)); + return doesMapExist(getWorldString(mapName, gameType)); } - public boolean DoesMapExist(String worldName) + public boolean doesMapExist(String worldName) { File file = new File(worldName); - if (file.exists() && file.isDirectory()) - return true; + return file.exists() && file.isDirectory(); - return false; } public String getShortWorldName(String worldName) @@ -389,12 +283,7 @@ public class MapParser extends JavaPlugin implements Listener return worldName; } - public World GetMapWorld(String mapName, GameType gameType) - { - return GetMapWorld(getWorldString(mapName, gameType)); - } - - public World GetMapWorld(String worldName) + public World getMapWorld(String worldName) { for (World world : this.getServer().getWorlds()) { @@ -414,14 +303,14 @@ public class MapParser extends JavaPlugin implements Listener { name = name.toLowerCase(); - List maps = new LinkedList(); + List maps = new LinkedList<>(); boolean matchesExact = false; for (GameType type : GameType.values()) { File mapsFolder = new File("map" + File.separator + type.GetName()); - if (!mapsFolder.exists()) + if (!mapsFolder.exists() || mapsFolder.listFiles() == null) continue; for (File file : mapsFolder.listFiles()) @@ -456,7 +345,7 @@ public class MapParser extends JavaPlugin implements Listener return maps; } - public MapData GetData(String mapName) + public MapData getData(String mapName) { if (_mapData.containsKey(mapName)) return _mapData.get(mapName); @@ -473,17 +362,6 @@ public class MapParser extends JavaPlugin implements Listener return _spawnLocation; } - public void ResetInventory(Player player) - { - // UtilInv.Clear(player); - // - // player.getInventory().addItem(new ItemStack(Material.STONE_SWORD)); - // player.getInventory().addItem(new ItemStack(Material.STONE_SPADE)); - // player.getInventory().addItem(new ItemStack(Material.STONE_PICKAXE)); - // player.getInventory().addItem(new ItemStack(Material.STONE_AXE)); - // player.getInventory().addItem(new ItemStack(Material.WOOD_AXE)); - } - public WorldManager getWorldManager() { return _worldManager; @@ -494,346 +372,12 @@ public class MapParser extends JavaPlugin implements Listener _curParse = parse; } - @EventHandler - public void Chat(AsyncPlayerChatEvent event) - { - event.setCancelled(true); - - String world = C.cDGreen + C.Bold + getShortWorldName(event.getPlayer().getWorld().getName()); - - - - String name = C.cYellow + event.getPlayer().getName(); - if (GetData(event.getPlayer().getWorld().getName()).HasAccess(event.getPlayer())) - name = C.cGreen + event.getPlayer().getName(); - - String grayName = C.cBlue + event.getPlayer().getName(); - String grayWorld = C.cBlue + C.Bold + event.getPlayer().getWorld().getName(); - - for (Player player : UtilServer.getPlayers()) - { - if (player.getWorld().equals(event.getPlayer().getWorld())) - { - player.sendMessage(world + ChatColor.RESET + " " + name + ChatColor.RESET + " " + event.getMessage()); - } - else - { - player.sendMessage(grayWorld + ChatColor.RESET + " " + grayName + ChatColor.RESET + " " + C.cGray + event.getMessage()); - } - - } - - System.out.println(world + ChatColor.RESET + " " + name + ChatColor.RESET + " " + event.getMessage()); - } - - @EventHandler(priority = EventPriority.LOWEST) - public void InteractCancel(PlayerInteractEvent event) - { - //Permission - if (!GetData(event.getPlayer().getWorld().getName()).HasAccess(event.getPlayer())) - { - event.setCancelled(true); - } - } - - @EventHandler(priority = EventPriority.LOWEST) - public void commandCancel(PlayerCommandPreprocessEvent event) - { - if (event.getMessage().startsWith("/tp") || - event.getMessage().startsWith("/hub") || - event.getMessage().startsWith("/list") || - event.getMessage().startsWith("/map") || - event.getMessage().startsWith("/create") || - event.getMessage().startsWith("/copy") || - event.getMessage().startsWith("/delete")) - return; - - //Permission - if (!GetData(event.getPlayer().getWorld().getName()).HasAccess(event.getPlayer())) - { - UtilPlayer.message(event.getPlayer(), F.main("Parser", "You do not have Build-Access for this Map.")); - event.setCancelled(true); - } - } - - public HashSet getMapsBeingZipped() + public Set getMapsBeingZipped() { return _mapsBeingZipped; } - - @EventHandler - public void Join(PlayerJoinEvent event) - { - event.setJoinMessage(F.sys("Player Join", event.getPlayer().getName())); - } - - @EventHandler - public void Join(PlayerQuitEvent event) - { - event.setQuitMessage(F.sys("Player Quit", event.getPlayer().getName())); - } - - @EventHandler(priority = EventPriority.LOWEST) - public void TeleportCommand(PlayerCommandPreprocessEvent event) - { - if (!event.getMessage().toLowerCase().startsWith("/tp")) - return; - - Player player = event.getPlayer(); - - String[] tokens = event.getMessage().split(" "); - - if (tokens.length != 2) - { - return; - } - - event.setCancelled(true); - - Player target = UtilPlayer.searchOnline(player, tokens[1], true); - if (target != null) - { - UtilPlayer.message(player, F.main("Game", "You teleported to " + F.name(target.getName()) + ".")); - player.teleport(target); - } - } - - @EventHandler(priority = EventPriority.LOWEST) - public void FlySpeed(PlayerCommandPreprocessEvent event) - { - if (!event.getMessage().toLowerCase().startsWith("/speed")) - return; - - Player player = event.getPlayer(); - - String[] tokens = event.getMessage().split(" "); - - if (tokens.length != 2) - { - return; - } - - event.setCancelled(true); - - try - { - float speed = Float.parseFloat(tokens[1]); - - player.setFlySpeed(speed); - - UtilPlayer.message(player, F.main("Game", "Fly Speed set to " + F.elem("" + speed) + ".")); - } - catch (Exception e) - { - UtilPlayer.message(player, F.main("Game", "Invalid Speed Input.")); - } - } - - private HashMap>> treeHistory = new HashMap>>(); - - @EventHandler(priority = EventPriority.HIGHEST) - public void treeRemover(PlayerInteractEvent event) - { - if (event.isCancelled()) - return; - - //Permission - if (!GetData(event.getPlayer().getWorld().getName()).HasAccess(event.getPlayer())) - { - return; - } - - Player player = event.getPlayer(); - - if (!UtilGear.isMat(player.getItemInHand(), Material.NETHER_STAR)) - return; - - event.setCancelled(true); - - //Remove - if (event.getAction() == Action.LEFT_CLICK_BLOCK) - { - if (event.getClickedBlock().getType() != Material.LOG) - { - player.sendMessage(C.cRed + C.Bold + "TreeTool: " + ChatColor.RESET + "Left-Click on Log"); - return; - } - - HashSet toRemove = searchLog(new HashSet(), event.getClickedBlock()); - - if (toRemove.isEmpty()) - { - player.sendMessage(C.cRed + C.Bold + "TreeTool: " + ChatColor.RESET + "Left-Click on Log"); - return; - } - - HashSet history = new HashSet(); - - for (Block block : toRemove) - { - history.add(new BlockData(block)); - - block.setType(Material.AIR); - } - - if (!treeHistory.containsKey(player)) - treeHistory.put(player, new ArrayList>()); - - treeHistory.get(player).add(0, history); - - player.sendMessage(C.cRed + C.Bold + "TreeTool: " + ChatColor.RESET + "Tree Removed"); - - while (treeHistory.get(player).size() > 10) - treeHistory.get(player).remove(10); - } - else if (UtilEvent.isAction(event, ActionType.R)) - { - if (!treeHistory.containsKey(player) || treeHistory.get(player).isEmpty()) - { - player.sendMessage(C.cGreen + C.Bold + "TreeTool: " + ChatColor.RESET + "No Tree History"); - return; - } - - HashSet datas = treeHistory.get(player).remove(0); - - for (BlockData data : datas) - data.restore(); - - player.sendMessage(C.cGreen + C.Bold + "TreeTool: " + ChatColor.RESET + "Tree Restored"); - } - } - - @EventHandler - public void mmMazeParser(PlayerInteractEvent event) - { - if (event.isCancelled()) - return; - - if (event.getAction() != Action.LEFT_CLICK_BLOCK) return; - - //Permission - if (!GetData(event.getPlayer().getWorld().getName()).HasAccess(event.getPlayer())) - { - return; - } - - Player player = event.getPlayer(); - - if (!UtilGear.isMat(player.getItemInHand(), Material.WEB)) - return; - - event.setCancelled(true); - - // parse - - Block clicked = event.getClickedBlock(); - Location center = clicked.getLocation(); - Location lowestCorner = center.clone().subtract(49, 0, 49); - - // 0 = air or other - // 1 = path - quartz - // 2 = mob spawn - gold - // 3 = safe spawn - stone - - int[][] maze = new int[99][99]; - - /*Iterator iter = blocks.iterator(); - while(iter.hasNext()) - { - Block b = iter.next(); - switch (b.getType()) { - case QUARTZ_BLOCK: - maze[x][y] = 1; - break; - - case GOLD_BLOCK: - maze[x][y] = 2; - break; - - case STONE: - maze[x][y] = 3; - break; - - default: - maze[x][y] = 0; - break; - } - x++; - if(x > 99) - { - y++; - x = 0; - } - if(y > 99) - { - System.out.println("y > 99"); - break; - } - }*/ - - for (int i = 0; i < 99; i++) - for (int j = 0; j < 99; j++) - maze[i][j] = getMMParseValue(lowestCorner.clone().add(j, 0, i).getBlock().getType()); - - //Save - try - { - FileWriter fstream = new FileWriter(GetData(player.getWorld().getName()).MapFolder + File.separator + "Maze.dat"); - BufferedWriter out = new BufferedWriter(fstream); - - out.write("private static final int[][] PARSED_MAZE = {" + System.lineSeparator()); - for (int j[] : maze) - { - out.write("{"); - boolean first = true; - for (int k : j) - { - if(!first) out.write(","); - out.write(k + ""); - - first = false; - } - out.write("}," + System.lineSeparator()); - } - out.write("};" + System.lineSeparator()); - - out.close(); - } - catch (Exception e) - { - player.sendMessage(C.cRed + C.Bold + "MMMazeParse: " + ChatColor.RESET + "An error has occured, see console."); - e.printStackTrace(); - } - player.sendMessage(C.cGreen + C.Bold + "MMMazeParse: " + ChatColor.RESET + "Maze parsed."); - } - private int getMMParseValue(Material m) - { - switch (m) { - case QUARTZ_BLOCK: - return 1; - - case GOLD_BLOCK: - return 2; - - case STONE: - return 3; - - case DIRT: - return 4; - - case COBBLESTONE: - return 5; - - case BRICK: - return 6; - - default: - return 0; - } - } - - private HashSet searchLog(HashSet blocks, Block current) + public Set searchLog(Set blocks, Block current) { //Not Tree if (current.getType() != Material.LOG && current.getType() != Material.LEAVES) @@ -860,110 +404,23 @@ public class MapParser extends JavaPlugin implements Listener return blocks; } - long lastUse = 0; - @EventHandler(priority = EventPriority.LOWEST) - public void leaptest(PlayerInteractEvent event) + public Map, Module> getModules() { - - if (event.getPlayer().getItemInHand() == null) - return; - - if (event.getPlayer().getItemInHand().getType() != Material.FEATHER) - return; - - if (System.currentTimeMillis() - lastUse < 800) - { - Bukkit.broadcastMessage("Cooldown"); - return; - } - - - lastUse = System.currentTimeMillis(); - - Vector vel = event.getPlayer().getLocation().getDirection().multiply(1.2); - vel.add(new Vector(0,0.6,0)); - - event.getPlayer().setVelocity(vel); + return _modules; } - @EventHandler(priority = EventPriority.LOWEST) - public void signChangeLog(SignChangeEvent event) + public void setInfo(GameType gameType, GameTypeInfo info) { - if (GetData(event.getPlayer().getWorld().getName()).HasAccess(event.getPlayer())) - { - ArrayList text = new ArrayList(); - - text.add("Date: " + UtilTime.now()); - text.add("Player: " + event.getPlayer().getName()); - text.add("Location: " + UtilWorld.locToStrClean(event.getBlock().getLocation())); - for (int i=0 ; i text = new ArrayList(); - - text.add("Date: " + UtilTime.now()); - text.add("Player: " + event.getPlayer().getName()); - text.add("Location: " + UtilWorld.locToStrClean(event.getPlayer().getLocation())); - text.add("Message: " + event.getMessage()); - - writeSignCommandLog(text, event.getPlayer().getWorld()); - } - } - - public void writeSignCommandLog(ArrayList text, World world) - { - try - { - File file = new File(world.getName() + "/" + "command_sign_log.txt"); - if (!file.exists()) - file.createNewFile(); - - FileWriter fw = new FileWriter(file.getAbsoluteFile(), true); - BufferedWriter bw = new BufferedWriter(fw); - - bw.write("\n\n"); - for (String line : text) - bw.write("\n" + line); - - bw.close(); - } - catch (Exception e) - { - e.printStackTrace(); - } - } - - public void writeSignLog(ArrayList text, World world) + public List getAdditionalText() { - try - { - File file = new File(world.getName() + "/" + "sign_log.txt"); + return _additionalText; + } - if (!file.exists()) - file.createNewFile(); - - FileWriter fw = new FileWriter(file.getAbsoluteFile(), true); - BufferedWriter bw = new BufferedWriter(fw); - - bw.write("\n\n"); - for (String line : text) - bw.write("\n" + line); - - bw.close(); - } - catch (Exception e) - { - e.printStackTrace(); - } + public void addAdditionalText(String s) + { + _additionalText.add(s); } } diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/Parse.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/Parse.java index 79d74e141..27184accb 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/Parse.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/Parse.java @@ -1,16 +1,8 @@ package mineplex.mapparser; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; - import mineplex.core.common.util.F; import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilWorld; - import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; @@ -19,6 +11,13 @@ import org.bukkit.block.BlockFace; import org.bukkit.block.Sign; import org.bukkit.material.Wool; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; + public class Parse { //Parse Data @@ -59,14 +58,14 @@ public class Parse _size = size; for (String arg : args) - Host.Announce("Parse Arg: " + F.elem(arg)); + Host.announce("Parse Arg: " + F.elem(arg)); Initialize(); } private void Initialize() { - Host.Announce("Commencing Parse of World: " + F.elem(_world.getName())); + Host.announce("Commencing Parse of World: " + F.elem(_world.getName())); //Take BlockID Arguments for (String arg : _args) @@ -77,7 +76,7 @@ public class Parse } catch (Exception e) { - Host.Announce("Invalid Data ID: " + F.elem(arg)); + Host.announce("Invalid Data ID: " + F.elem(arg)); } } @@ -102,7 +101,7 @@ public class Parse _processed++; if (_processed % 10000000 == 0) - Host.Announce("Scanning World: " + F.elem((int)(_processed/1000000) + "M of " + (int)(((_size*2)*(_size*2)*256)/1000000) + "M")); + Host.announce("Scanning World: " + F.elem((int)(_processed/1000000) + "M of " + (int)(((_size*2)*(_size*2)*256)/1000000) + "M")); Block block = _world.getBlockAt(_callLoc.getBlockX()+_x, _y, _callLoc.getBlockZ()+_z); @@ -144,7 +143,7 @@ public class Parse } catch (Exception e) { - Host.Announce("Invalid Sign Data: " + UtilWorld.locToStr(block.getLocation())); + Host.announce("Invalid Sign Data: " + UtilWorld.locToStr(block.getLocation())); } //Add @@ -176,21 +175,21 @@ public class Parse if (_cornerA == null) { _cornerA = wool.getLocation(); - Host.Announce("Corner A: " + UtilWorld.locToStrClean(_cornerA)); + Host.announce("Corner A: " + UtilWorld.locToStrClean(_cornerA)); } else if (_cornerB == null) { _cornerB = wool.getLocation(); - Host.Announce("Corner B: " + UtilWorld.locToStrClean(_cornerB)); + Host.announce("Corner B: " + UtilWorld.locToStrClean(_cornerB)); } else { - Host.Announce("More than 2 Corner Markers:"); - Host.Announce("Corner A: " + UtilWorld.locToStrClean(_cornerA)); - Host.Announce("Corner B: " + UtilWorld.locToStrClean(_cornerB)); - Host.Announce("Excess: " + UtilWorld.locToStrClean(wool.getLocation())); + Host.announce("More than 2 Corner Markers:"); + Host.announce("Corner A: " + UtilWorld.locToStrClean(_cornerA)); + Host.announce("Corner B: " + UtilWorld.locToStrClean(_cornerB)); + Host.announce("Excess: " + UtilWorld.locToStrClean(wool.getLocation())); } //Remove Blocks @@ -414,7 +413,7 @@ public class Parse if (_cornerA == null || _cornerB == null) { - Host.Announce("Missing Corner Locations! Defaulted to -256 to +256."); + Host.announce("Missing Corner Locations! Defaulted to -256 to +256."); _cornerA = new Location(_world, -256, 0, -256); _cornerB = new Location(_world, 256, 0, 256); @@ -487,12 +486,12 @@ public class Parse } catch (Exception e) { - Host.Announce("Error: File Write Error"); + Host.announce("Error: File Write Error"); e.printStackTrace(); } - Host.Announce("WorldConfig.dat Saved."); + Host.announce("WorldConfig.dat Saved."); return true; } diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/WorldManager.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/WorldManager.java index 8658ae526..56e3b7218 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/WorldManager.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/WorldManager.java @@ -1,18 +1,17 @@ package mineplex.mapparser; +import mineplex.core.common.util.MapUtil; +import mineplex.core.common.util.ZipUtil; +import org.apache.commons.io.FileUtils; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.WorldCreator; + import java.io.File; import java.io.IOException; import java.nio.file.Paths; import java.util.ArrayList; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.WorldCreator; - -import mineplex.core.common.util.MapUtil; -import mineplex.core.common.util.ZipUtil; -import org.apache.commons.io.FileUtils; - public class WorldManager { private MapParser Host; @@ -99,7 +98,7 @@ public class WorldManager FileUtils.deleteQuietly(new File(world.getName() + File.separator + file.getName())); } - MapData data = Host.GetData(world.getName().replace("parse", "map")); + MapData data = Host.getData(world.getName().replace("parse", "map")); GameType gameType = data.MapGameType; String fileName = gameType + "_" + data.MapName + ".zip"; diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/AddSplashTextCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/AddSplashTextCommand.java new file mode 100644 index 000000000..652785f33 --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/AddSplashTextCommand.java @@ -0,0 +1,58 @@ +package mineplex.mapparser.command; + +import mineplex.core.common.util.C; +import mineplex.mapparser.MapParser; +import net.md_5.bungee.api.ChatColor; +import org.bukkit.entity.Player; + +/** + * + */ +public class AddSplashTextCommand extends BaseCommand +{ + + public AddSplashTextCommand(MapParser plugin) + { + super(plugin, "addtext"); + setUsage("/addText "); + } + + @Override + public boolean execute(Player player, String alias, String[] args) + { + if(!player.isOp()) + { + player.sendMessage(C.cRed + "You cannot do this command!"); + return true; + } + + if(args.length == 0) + { + return false; + } + + if(args[0].equalsIgnoreCase("clear")) + { + getPlugin().getAdditionalText().clear(); + player.sendMessage(C.cRed + "Cleared all text."); + return true; + } + + StringBuilder builder = new StringBuilder(); + + for (int i = 0; i < args.length; i++) + { + builder.append(args[i]); + if ((i + 1) != args.length) + { + builder.append(" "); + } + } + + getPlugin().addAdditionalText(builder.toString()); + player.sendMessage(C.cGreen + "Added text!"); + player.sendMessage(ChatColor.translateAlternateColorCodes('&', builder.toString())); + + return true; + } +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/AdminCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/AdminCommand.java index 40af0b55b..ad52b7f98 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/AdminCommand.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/AdminCommand.java @@ -36,7 +36,7 @@ public class AdminCommand extends BaseCommand } //Permission - if (!getPlugin().GetData(world.getName()).HasAccess(player)) + if (!getPlugin().getData(world.getName()).HasAccess(player)) { message(player, "You are not on Admin-List for this Map."); return true; @@ -46,21 +46,21 @@ public class AdminCommand extends BaseCommand if (player != null) { - MapData data = getPlugin().GetData(world.getName()); + MapData data = getPlugin().getData(world.getName()); if (data.AdminList.contains(other.getName())) { data.AdminList.remove(other.getName()); data.Write(); - getPlugin().Announce("Admin-List for " + F.elem(world.getName()) + " (" + other.getName() + " = " + F.tf(false) + ")"); + getPlugin().announce("Admin-List for " + F.elem(world.getName()) + " (" + other.getName() + " = " + F.tf(false) + ")"); } else { data.AdminList.add(other.getName()); data.Write(); - getPlugin().Announce("Admin-List for " + F.elem(world.getName()) + " (" + other.getName() + " = " + F.tf(true) + ")"); + getPlugin().announce("Admin-List for " + F.elem(world.getName()) + " (" + other.getName() + " = " + F.tf(true) + ")"); } } return true; diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/AuthorCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/AuthorCommand.java index 3dabd87c9..c267e7d4d 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/AuthorCommand.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/AuthorCommand.java @@ -4,7 +4,6 @@ import org.bukkit.World; import org.bukkit.entity.Player; import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilPlayer; import mineplex.mapparser.MapData; import mineplex.mapparser.MapParser; @@ -41,18 +40,18 @@ public class AuthorCommand extends BaseCommand } //Permission - if (!getPlugin().GetData(world.getName()).HasAccess(player)) + if (!getPlugin().getData(world.getName()).HasAccess(player)) { message(player, "You do not have Build-Access on this Map."); return true; } - MapData data = getPlugin().GetData(world.getName()); + MapData data = getPlugin().getData(world.getName()); data.MapCreator = authorName; data.Write(); - getPlugin().Announce("Map Author for " + F.elem(world.getName()) + " set to " + F.elem(authorName) + "."); + getPlugin().announce("Map Author for " + F.elem(world.getName()) + " set to " + F.elem(authorName) + "."); return true; } diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/CopyCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/CopyCommand.java index 3448f8545..4354a90a1 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/CopyCommand.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/CopyCommand.java @@ -50,19 +50,19 @@ public class CopyCommand extends BaseCommand String worldName = getPlugin().getWorldString(originalMapName, originalGametype); String newWorldName = getPlugin().getWorldString(newMapName, newGameType); - if (!getPlugin().DoesMapExist(worldName)) + if (!getPlugin().doesMapExist(worldName)) { message(player, "Could not find a map with the name " + F.elem(originalMapName) + " of type " + F.elem(originalGametype.toString())); return true; } - if (getPlugin().DoesMapExist(newWorldName)) + if (getPlugin().doesMapExist(newWorldName)) { message(player, "Destination map already exists " + F.elem(newMapName) + " of type " + F.elem(newGameType.toString())); return true; } - World world = getPlugin().GetMapWorld(worldName); + World world = getPlugin().getMapWorld(worldName); if (world != null) { diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/CreateCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/CreateCommand.java index 2f44c7558..28ff49418 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/CreateCommand.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/CreateCommand.java @@ -1,18 +1,16 @@ package mineplex.mapparser.command; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.mapparser.GameType; +import mineplex.mapparser.MapData; +import mineplex.mapparser.MapParser; import org.bukkit.Bukkit; -import org.bukkit.Location; import org.bukkit.World; import org.bukkit.WorldCreator; import org.bukkit.WorldType; import org.bukkit.entity.Player; -import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilPlayer; -import mineplex.mapparser.GameType; -import mineplex.mapparser.MapData; -import mineplex.mapparser.MapParser; - /** * Created by Shaun on 8/16/2014. */ @@ -28,7 +26,7 @@ public class CreateCommand extends BaseCommand { if (args.length < 1) { - message(player, "Invalid Input. " + F.elem("/create ")); + message(player, "Invalid Input. " + F.elem("/create [-v]")); return true; } @@ -36,21 +34,38 @@ public class CreateCommand extends BaseCommand String worldName = "map/" + gameType.GetName() + "/" + args[0]; - if (getPlugin().DoesMapExist(worldName)) + if (getPlugin().doesMapExist(worldName)) { message(player, "Map name is already in use!"); return true; } - getPlugin().Announce("Creating World: " + F.elem(worldName)); + boolean voidWorld = false; + + if (args.length == 2) + { + voidWorld = args[1].equalsIgnoreCase("-v"); + } + WorldCreator worldCreator = new WorldCreator(worldName); worldCreator.environment(World.Environment.NORMAL); worldCreator.type(WorldType.FLAT); + if (voidWorld) + { + //Cheeky little trick, saves time and energy. + worldCreator.generatorSettings("3;minecraft:air;2"); + getPlugin().announce("Creating World: " + F.elem(worldName) + " -" + C.cRed + "VOID"); + } + else + { + getPlugin().announce("Creating World: " + F.elem(worldName)); + } + worldCreator.generateStructures(false); World world = Bukkit.getServer().createWorld(worldCreator); - + world.setSpawnLocation(0, 100, 0); message(player, "Teleporting to World: " + F.elem(worldName)); @@ -58,7 +73,7 @@ public class CreateCommand extends BaseCommand player.teleport(world.getSpawnLocation()); //Give Access - MapData mapData = getPlugin().GetData(worldName); + MapData mapData = getPlugin().getData(worldName); mapData.AdminList.add(player.getName()); mapData.MapGameType = gameType; mapData.Write(); diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/CurrentlyLiveCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/CurrentlyLiveCommand.java new file mode 100644 index 000000000..7244346b9 --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/CurrentlyLiveCommand.java @@ -0,0 +1,38 @@ +package mineplex.mapparser.command; + +import mineplex.core.common.util.C; +import mineplex.mapparser.MapData; +import mineplex.mapparser.MapParser; +import org.bukkit.entity.Player; + +/** + * + */ +public class CurrentlyLiveCommand extends BaseCommand +{ + + public CurrentlyLiveCommand(MapParser plugin, String... aliases) + { + super(plugin, "islive", "setlive"); + } + + @Override + public boolean execute(Player player, String alias, String[] args) + { + MapData data = getPlugin().getData(player.getWorld().getName()); + + if(data == null) + { + player.sendMessage(C.cRed + "There was an error with your map."); + return true; + } + + if(alias.equalsIgnoreCase("setlive")) + { + data._currentlyLive = true; + } + + player.sendMessage(C.cGray + "Currently Live: " + (data._currentlyLive ? C.cGreen + "True" : C.cRed + "False")); + return true; + } +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/DeleteCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/DeleteCommand.java index 4128c38e8..59b357c42 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/DeleteCommand.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/DeleteCommand.java @@ -44,21 +44,21 @@ public class DeleteCommand extends BaseCommand final String worldName = getPlugin().getWorldString(mapName, gameType); - if (!getPlugin().DoesMapExist(worldName)) + if (!getPlugin().doesMapExist(worldName)) { message(player, "Map does not exist: " + F.elem(worldName)); return true; } - if (!getPlugin().GetData(worldName).HasAccess(player)) + if (!getPlugin().getData(worldName).HasAccess(player)) { message(player, "You do not have Build-Access on this Map."); return true; } - if (getPlugin().GetMapWorld(worldName) != null) + if (getPlugin().getMapWorld(worldName) != null) { - World world = getPlugin().GetMapWorld(worldName); + World world = getPlugin().getMapWorld(worldName); //Teleport Out for (Player other : world.getPlayers()) @@ -73,9 +73,9 @@ public class DeleteCommand extends BaseCommand boolean deleted = FileUtils.deleteQuietly(new File(worldName)); if (deleted) - getPlugin().Announce("Deleted World: " + F.elem(worldName)); + getPlugin().announce("Deleted World: " + F.elem(worldName)); else - getPlugin().Announce("Failed to delete World: " + F.elem(worldName)); + getPlugin().announce("Failed to delete World: " + F.elem(worldName)); return true; } diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/GameTypeCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/GameTypeCommand.java index 098eed8c3..edf2482a9 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/GameTypeCommand.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/GameTypeCommand.java @@ -2,13 +2,11 @@ package mineplex.mapparser.command; import java.io.File; -import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Player; import mineplex.core.common.util.F; import mineplex.core.common.util.MapUtil; -import mineplex.core.common.util.UtilPlayer; import mineplex.mapparser.GameType; import mineplex.mapparser.MapData; import mineplex.mapparser.MapParser; @@ -41,7 +39,7 @@ public class GameTypeCommand extends BaseCommand } //Permission - if (!getPlugin().GetData(world.getName()).HasAccess(player)) + if (!getPlugin().getData(world.getName()).HasAccess(player)) { message(player, "You do not have Build-Access on this Map."); return true; @@ -59,7 +57,7 @@ public class GameTypeCommand extends BaseCommand return true; } - if (getPlugin().DoesMapExist(getPlugin().getShortWorldName(world.getName()), type)) + if (getPlugin().doesMapExist(getPlugin().getShortWorldName(world.getName()), type)) { message(player, "A world with the same name already exists for the new gametype: " + type.GetName()); return true; @@ -85,11 +83,11 @@ public class GameTypeCommand extends BaseCommand message(player, "Map " + world.getName() + " renamed to " + newName); - MapData data = getPlugin().GetData(newName); + MapData data = getPlugin().getData(newName); data.MapGameType = type; data.Write(); - getPlugin().Announce("GameType for " + F.elem(newName) + " set to " + F.elem(args[0]) + "."); + getPlugin().announce("GameType for " + F.elem(newName) + " set to " + F.elem(args[0]) + "."); return true; } diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/InfoCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/InfoCommand.java new file mode 100644 index 000000000..f5fa36ac1 --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/InfoCommand.java @@ -0,0 +1,81 @@ +package mineplex.mapparser.command; + +import com.google.common.collect.Lists; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.mapparser.GameType; +import mineplex.mapparser.GameTypeInfo; +import mineplex.mapparser.MapParser; +import org.bukkit.entity.Player; + +/** + * + */ +public class InfoCommand extends BaseCommand +{ + + public InfoCommand(MapParser plugin) + { + super(plugin, "info"); + setUsage("/info & /info addInfo "); + } + + @Override + public boolean execute(Player player, String alias, String[] args) + { + if (args.length == 1) + { + String gameRaw = args[0]; + GameType gameType; + try + { + gameType = GameType.match(gameRaw); + } catch (Exception e) + { + player.sendMessage(C.cRed + "Invalid Game Type: " + gameRaw); + return true; + } + GameTypeInfo info = getPlugin().getInfo(gameType); + if (info == null) + { + player.sendMessage(C.cRed + "No info found for " + gameType.GetName()); + return true; + } + info.sendInfo(player); + return true; + } + if (args.length >= 3 && args[0].equalsIgnoreCase("addInfo")) + { + String gameRaw = args[1]; + GameType gameType; + try + { + gameType = GameType.match(gameRaw); + } catch (Exception e) + { + player.sendMessage(C.cRed + "Invalid Game Type: " + gameRaw); + return true; + } + GameTypeInfo info = getPlugin().getInfo(gameType); + StringBuilder builder = new StringBuilder(); + for (int i = 2; i < args.length; i++) + { + builder.append(args[i]); + if ((i + 1) != args.length) + { + builder.append(" "); + } + } + if (info == null) + { + info = new GameTypeInfo(gameType, Lists.newArrayList()); + getPlugin().setInfo(gameType, info); + } + + info.addInfo(builder.toString()); + player.sendMessage(C.cGray + "Added new info to " + F.elem(gameRaw)); + return true; + } + return false; + } +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/LockCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/LockCommand.java new file mode 100644 index 000000000..a8dd0082d --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/LockCommand.java @@ -0,0 +1,35 @@ +package mineplex.mapparser.command; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.mapparser.MapData; +import mineplex.mapparser.MapParser; +import org.bukkit.entity.Player; + +/** + * + */ +public class LockCommand extends BaseCommand +{ + + public LockCommand(MapParser plugin) + { + super(plugin, "lock"); + } + + @Override + public boolean execute(Player player, String alias, String[] args) + { + MapData data = getPlugin().getData(player.getWorld().getName()); + + if(data == null) + { + player.sendMessage(C.cRed + "There was an error with your map."); + return true; + } + + data._locked = !data._locked; + player.sendMessage(F.tf(data._locked) + " lock for world " + player.getWorld().getName()); + return true; + } +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/MapCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/MapCommand.java index a229e5e07..6c504b634 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/MapCommand.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/MapCommand.java @@ -1,19 +1,18 @@ package mineplex.mapparser.command; -import java.io.File; -import java.util.List; - -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.WorldCreator; -import org.bukkit.entity.Player; - import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; import mineplex.mapparser.GameType; import mineplex.mapparser.MapData; import mineplex.mapparser.MapParser; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.WorldCreator; +import org.bukkit.entity.Player; + +import java.io.File; +import java.util.List; /** * Created by Shaun on 8/15/2014. @@ -45,8 +44,9 @@ public class MapCommand extends BaseCommand if (possibleMaps.size() == 0) { message(player, "No maps found with the name: " + F.elem(args[0])); + return true; } - else if (possibleMaps.size() > 1) + if (possibleMaps.size() > 1) { message(player, "Found more than one possible match:"); for (String s : possibleMaps) @@ -91,10 +91,10 @@ public class MapCommand extends BaseCommand System.out.println("Could not delete uid.dat for " + worldName); } - World world = getPlugin().GetMapWorld(worldName); + World world = getPlugin().getMapWorld(worldName); if (world == null) { - if (getPlugin().DoesMapExist(worldName)) + if (getPlugin().doesMapExist(worldName)) { world = Bukkit.createWorld(new WorldCreator(worldName)); } @@ -113,7 +113,7 @@ public class MapCommand extends BaseCommand } //Permission - if (!getPlugin().GetData(world.getName()).CanJoin(player)) + if (!getPlugin().getData(world.getName()).CanJoin(player)) { message(player, "You do not have Join-Access on this Map."); return true; @@ -124,7 +124,7 @@ public class MapCommand extends BaseCommand player.teleport(new Location(world, 0, 106, 0)); - MapData data = getPlugin().GetData(worldName); + MapData data = getPlugin().getData(worldName); UtilPlayer.message(player, F.value("Map Name", data.MapName)); UtilPlayer.message(player, F.value("Author", data.MapCreator)); diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/NameCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/NameCommand.java index 580c088da..a7988c3ff 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/NameCommand.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/NameCommand.java @@ -4,7 +4,6 @@ import org.bukkit.World; import org.bukkit.entity.Player; import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilPlayer; import mineplex.mapparser.MapData; import mineplex.mapparser.MapParser; @@ -43,18 +42,18 @@ public class NameCommand extends BaseCommand mapName = mapName.trim(); //Permission - if (!getPlugin().GetData(world.getName()).HasAccess(player)) + if (!getPlugin().getData(world.getName()).HasAccess(player)) { message(player, "You do not have Build-Access on this Map."); return true; } - MapData data = getPlugin().GetData(world.getName()); + MapData data = getPlugin().getData(world.getName()); data.MapName = mapName; data.Write(); - getPlugin().Announce("Map Name for " + F.elem(world.getName()) + " set to " + F.elem(mapName) + "."); + getPlugin().announce("Map Name for " + F.elem(world.getName()) + " set to " + F.elem(mapName) + "."); return true; } diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/PMCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/PMCommand.java new file mode 100644 index 000000000..82a72b071 --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/PMCommand.java @@ -0,0 +1,52 @@ +package mineplex.mapparser.command; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilServer; +import mineplex.mapparser.MapParser; +import org.bukkit.Sound; +import org.bukkit.entity.Player; + +/** + * + */ +public class PMCommand extends BaseCommand +{ + public PMCommand(MapParser plugin) + { + super(plugin, "m", "message"); + } + + @Override + public boolean execute(Player player, String alias, String[] args) + { + if(!player.isOp()) + { + player.sendMessage(C.cRed + "You are not allowed to do that!"); + return true; + } + + if(args.length == 0) + { + player.sendMessage(C.cRed + "Please put a message in!"); + return true; + } + + StringBuilder builder = new StringBuilder(); + for(String s : args) + { + builder.append(s).append(" "); + } + for(Player ops : UtilServer.getPlayers()) + { + if(!ops.isOp()) + { + continue; + } + ops.sendMessage(F.main("Message", builder.toString().trim())); + ops.playSound(ops.getLocation(), Sound.NOTE_PLING, 1.0f, 1.0f); + } + + return true; + } +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ParseCommand200.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ParseCommand200.java index 91b88a840..9cd58144b 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ParseCommand200.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ParseCommand200.java @@ -32,7 +32,7 @@ public class ParseCommand200 extends BaseCommand World world = parseLoc.getWorld(); - MapData data = getPlugin().GetData(world.getName()); + MapData data = getPlugin().getData(world.getName()); if (data.MapName.equals("null") || data.MapCreator.equals("null") || data.MapGameType.equals("null")) { @@ -57,7 +57,7 @@ public class ParseCommand200 extends BaseCommand } //Parse the World - getPlugin().setCurrentParse(new Parse(getPlugin(), parseableWorld, args, parseLoc, getPlugin().GetData(parseLoc.getWorld().getName()), 200)); + getPlugin().setCurrentParse(new Parse(getPlugin(), parseableWorld, args, parseLoc, getPlugin().getData(parseLoc.getWorld().getName()), 200)); return true; } diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ParseCommand400.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ParseCommand400.java index 02f0a0493..d08d60103 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ParseCommand400.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ParseCommand400.java @@ -32,7 +32,7 @@ public class ParseCommand400 extends BaseCommand World world = parseLoc.getWorld(); - MapData data = getPlugin().GetData(world.getName()); + MapData data = getPlugin().getData(world.getName()); if (data.MapName.equals("null") || data.MapCreator.equals("null") || data.MapGameType.equals("null")) { @@ -57,7 +57,7 @@ public class ParseCommand400 extends BaseCommand } //Parse the World - getPlugin().setCurrentParse(new Parse(getPlugin(), parseableWorld, args, parseLoc, getPlugin().GetData(parseLoc.getWorld().getName()), 400)); + getPlugin().setCurrentParse(new Parse(getPlugin(), parseableWorld, args, parseLoc, getPlugin().getData(parseLoc.getWorld().getName()), 400)); return true; } diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ParseCommand600.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ParseCommand600.java index 9271553ef..daa28b4fa 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ParseCommand600.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ParseCommand600.java @@ -32,7 +32,7 @@ public class ParseCommand600 extends BaseCommand World world = parseLoc.getWorld(); - MapData data = getPlugin().GetData(world.getName()); + MapData data = getPlugin().getData(world.getName()); if (data.MapName.equals("null") || data.MapCreator.equals("null") || data.MapGameType.equals("null")) { @@ -57,7 +57,7 @@ public class ParseCommand600 extends BaseCommand } //Parse the World - getPlugin().setCurrentParse(new Parse(getPlugin(), parseableWorld, args, parseLoc, getPlugin().GetData(parseLoc.getWorld().getName()), 600)); + getPlugin().setCurrentParse(new Parse(getPlugin(), parseableWorld, args, parseLoc, getPlugin().getData(parseLoc.getWorld().getName()), 600)); return true; } diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/PlayerHeadCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/PlayerHeadCommand.java new file mode 100644 index 000000000..d0a7a485d --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/PlayerHeadCommand.java @@ -0,0 +1,37 @@ +package mineplex.mapparser.command; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.mapparser.MapParser; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.SkullMeta; + +/** + * + */ +public class PlayerHeadCommand extends BaseCommand +{ + + public PlayerHeadCommand(MapParser plugin, String... aliases) + { + super(plugin, "playerhead"); + } + + @Override + public boolean execute(Player player, String alias, String[] args) + { + if(args.length == 1) { + String name = args[0]; + ItemStack itemStack = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3); + SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); + meta.setOwner(name); + itemStack.setItemMeta(meta); + player.getInventory().addItem(itemStack); + player.sendMessage(C.cGray + "Given " + F.elem(name) + "'s head"); + return true; + } + return false; + } +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/RefreshWorldEditCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/RefreshWorldEditCommand.java new file mode 100644 index 000000000..8cfbf1c6e --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/RefreshWorldEditCommand.java @@ -0,0 +1,31 @@ +package mineplex.mapparser.command; + +import mineplex.core.common.util.F; +import mineplex.mapparser.MapParser; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + +/** + * + */ +public class RefreshWorldEditCommand extends BaseCommand +{ + + public RefreshWorldEditCommand(MapParser plugin) + { + super(plugin, "refreshworldedit", "refreshwe", "wefresh"); + setUsage("/refreshwe"); + } + + @Override + public boolean execute(Player player, String alias, String[] args) + { + Bukkit.broadcastMessage(F.name(player.getName()) + " is reloading World Edit"); + Plugin plugin = getPlugin().getServer().getPluginManager().getPlugin("WorldEdit"); + plugin.onDisable(); + plugin.onEnable(); + Bukkit.broadcastMessage(F.name(player.getName()) + " has reloaded World Edit"); + return true; + } +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/RenameCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/RenameCommand.java index ae95e8ec4..b2e539bb4 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/RenameCommand.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/RenameCommand.java @@ -2,7 +2,6 @@ package mineplex.mapparser.command; import java.io.File; -import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Player; @@ -25,7 +24,7 @@ public class RenameCommand extends BaseCommand public boolean execute(Player player, String alias, String[] args) { World world = player.getWorld(); - MapData data = getPlugin().GetData(world.getName()); + MapData data = getPlugin().getData(world.getName()); if (data == null) { diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/SaveCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/SaveCommand.java index 4f2658660..c201f152c 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/SaveCommand.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/SaveCommand.java @@ -48,11 +48,11 @@ public class SaveCommand extends BaseCommand } String worldName = possibleMaps.get(0); - World world = getPlugin().GetMapWorld(worldName); + World world = getPlugin().getMapWorld(worldName); if (world != null) { - if (!getPlugin().GetData(worldName).HasAccess(player)) + if (!getPlugin().getData(worldName).HasAccess(player)) { message(player, "You do not have Build-Access on this Map."); return true; @@ -71,7 +71,7 @@ public class SaveCommand extends BaseCommand return true; } - getPlugin().Announce("Saved World: " + F.elem(args[0])); + getPlugin().announce("Saved World: " + F.elem(args[0])); return true; } diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/WarpCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/WarpCommand.java new file mode 100644 index 000000000..dd533e4d8 --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/WarpCommand.java @@ -0,0 +1,82 @@ +package mineplex.mapparser.command; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilWorld; +import mineplex.mapparser.MapData; +import mineplex.mapparser.MapParser; +import org.bukkit.Location; +import org.bukkit.entity.Player; + +import java.util.Map; + +/** + * + */ +public class WarpCommand extends BaseCommand +{ + + public WarpCommand(MapParser plugin) + { + super(plugin, "warp"); + setUsage("/warp & /warp "); + } + + @Override + public boolean execute(Player player, String alias, String[] args) + { + MapData data = getPlugin().getData(player.getWorld().getName()); + + if(data == null) + { + player.sendMessage(C.cRed + "There was an error with your map."); + return true; + } + + Map warps = data._warps; + + if(args.length == 1) + { + if(args[0].equalsIgnoreCase("list")) + { + for(String s : warps.keySet()) + { + player.sendMessage(F.elem(s) + " @ " + F.elem(UtilWorld.locToStrClean(warps.get(s)))); + } + return true; + } + + Location location = warps.get(args[0].toLowerCase()); + + if(location == null){ + player.sendMessage(C.cRed + "Unknown warp!"); + return true; + } + + player.sendMessage(C.cGray + "Warping to " + F.elem(args[0])); + player.teleport(location); + return true; + } + + if(args.length == 2) + { + if(!args[0].equalsIgnoreCase("set")) + { + player.sendMessage(C.cRed + "Please use " + F.elem("/warp set ") + C.cRed + " to set a warp"); + return true; + } + String warp = args[1].toLowerCase(); + if(warps.containsKey(warp)) + { + player.sendMessage(C.cRed + "That warp already exists!"); + return true; + } + warps.put(warp, player.getLocation()); + player.sendMessage(C.cGray + "Created a new warp: " + F.elem(warp)); + return true; + } + + return false; + } + +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/Module.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/Module.java new file mode 100644 index 000000000..0862b4b3c --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/Module.java @@ -0,0 +1,50 @@ +package mineplex.mapparser.module; + +import mineplex.core.common.util.C; +import mineplex.mapparser.MapData; +import mineplex.mapparser.MapParser; +import net.md_5.bungee.api.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.event.Listener; + +/** + * + */ +public abstract class Module implements Listener +{ + + private MapParser _plugin; + private String _name; + + public Module(String name, MapParser plugin) { + _name = name; + _plugin = plugin; + register(); + plugin.getModules().put(this.getClass(), this); + } + + public void register() + { + _plugin.getServer().getPluginManager().registerEvents(this, _plugin); + } + + public MapParser getPlugin() + { + return _plugin; + } + + public MapData GetData(String world) + { + return getPlugin().getData(world); + } + + public void displayHelp(Player player) + { + MapData data = GetData(player.getWorld().getName()); + player.sendMessage(C.cGray + "Currently Live: " + (data._currentlyLive ? C.cGreen + "True" : C.cRed + "False")); + for(String s : getPlugin().getAdditionalText()) + { + player.sendMessage(ChatColor.translateAlternateColorCodes('&', s)); + } + } +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/CommandModule.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/CommandModule.java new file mode 100644 index 000000000..368b24df9 --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/CommandModule.java @@ -0,0 +1,99 @@ +package mineplex.mapparser.module.modules; + +import com.google.common.collect.Maps; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import mineplex.mapparser.MapParser; +import mineplex.mapparser.command.BaseCommand; +import mineplex.mapparser.module.Module; +import org.bukkit.GameMode; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; + +import java.util.Map; + +/** + * + */ +public class CommandModule extends Module +{ + private Map _commands = Maps.newHashMap(); + private Map _commandsByAlias = Maps.newHashMap(); + + public CommandModule(MapParser plugin) + { + super("Commands", plugin); + } + + @EventHandler + public void onCommand(PlayerCommandPreprocessEvent event) + { + Player player = event.getPlayer(); + + String[] parts = event.getMessage().split(" "); + String commandLabel = parts[0].substring(1); + String[] args = new String[parts.length - 1]; + System.arraycopy(parts, 1, args, 0, parts.length - 1); + + if (getPlugin().getCurParse() != null) + { + UtilPlayer.message(player, F.main("Parser", "Cannot use commands during Map Parse!")); + return; + } + if (event.getMessage().toLowerCase().startsWith("/help")) + { + event.setCancelled(true); + + displayHelp(player); + return; + } + + if (commandLabel.equalsIgnoreCase("gmc")) + { + player.setGameMode(GameMode.CREATIVE); + event.setCancelled(true); + return; + } + if (commandLabel.equalsIgnoreCase("gms")) + { + player.setGameMode(GameMode.SURVIVAL); + event.setCancelled(true); + return; + } + if (commandLabel.equalsIgnoreCase("gmsp")) + { + player.setGameMode(GameMode.SPECTATOR); + event.setCancelled(true); + return; + } + + BaseCommand baseCommand = _commands.get(commandLabel.toLowerCase()); + + if (baseCommand == null) + { + baseCommand = _commandsByAlias.get(commandLabel.toLowerCase()); + if (baseCommand == null) + { + return; + } + } + + event.setCancelled(true); + + if (!baseCommand.execute(player, commandLabel, args)) + { + UtilPlayer.message(player, F.main("Parser", "Invalid Input.")); + UtilPlayer.message(player, F.elem(baseCommand.getUsage())); + } + } + + public void add(BaseCommand baseCommand) + { + _commands.put(baseCommand.getAliases().get(0).toLowerCase(), baseCommand); + for (String label : baseCommand.getAliases()) + { + _commandsByAlias.put(label.toLowerCase(), baseCommand); + } + } +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/EventModule.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/EventModule.java new file mode 100644 index 000000000..3f62f9337 --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/EventModule.java @@ -0,0 +1,354 @@ +package mineplex.mapparser.module.modules; + +import com.google.common.collect.Lists; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.MapUtil; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; +import mineplex.mapparser.BackupTask; +import mineplex.mapparser.MapData; +import mineplex.mapparser.MapParser; +import mineplex.mapparser.Parse; +import mineplex.mapparser.TickEvent; +import mineplex.mapparser.module.Module; +import org.bukkit.ChatColor; +import org.bukkit.Sound; +import org.bukkit.World; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.BlockBurnEvent; +import org.bukkit.event.block.BlockFadeEvent; +import org.bukkit.event.block.BlockFormEvent; +import org.bukkit.event.block.BlockIgniteEvent; +import org.bukkit.event.block.BlockIgniteEvent.IgniteCause; +import org.bukkit.event.block.BlockSpreadEvent; +import org.bukkit.event.block.LeavesDecayEvent; +import org.bukkit.event.entity.EntitySpawnEvent; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +import java.util.List; + +/** + * + */ +public class EventModule extends Module +{ + + private List _updated = Lists.newArrayList(); + + public EventModule(MapParser plugin) + { + super("Events", plugin); + } + + @EventHandler + public void PlayerJoin(PlayerJoinEvent event) + { + Player player = event.getPlayer(); + + player.teleport(getPlugin().getSpawnLocation()); + + displayHelp(player); + } + + @EventHandler + public void onTick(TickEvent event) + { + for (World world : getPlugin().getServer().getWorlds()) + { + if (_updated.contains(world)) + { + continue; + } + if (world.getName().toLowerCase().contains("halloween")) + { + world.setTime(16000); + } else + { + world.setTime(8000); + } + _updated.add(world); + world.setStorm(false); + world.setGameRuleValue("doDaylightCycle", "false"); + } + } + + @EventHandler + public void onParseUpdate(TickEvent event) + { + if (getPlugin().getCurParse() == null) + { + return; + } + + Parse parse = getPlugin().getCurParse(); + + if (parse.Update()) + { + getPlugin().announce("Parse Completed!"); + + getPlugin().announce("Cleaning and Creating ZIP..."); + + try + { + getPlugin().getWorldManager().finalizeParsedWorld(parse.getWorld()); + } catch (Exception e) + { + getPlugin().announce("Creating ZIP Failed! Please Try Again!"); + e.printStackTrace(); + } + + getPlugin().setCurrentParse(null); + } + } + + @EventHandler + public void SaveUnloadWorlds(TickEvent event) + { + for (World world : getPlugin().getServer().getWorlds()) + { + if (world.getName().equalsIgnoreCase("world")) + { + continue; + } + + if (world.getName().startsWith("parse_")) + { + continue; + } + + if (!world.getName().startsWith("map")) + { + continue; + } + + if (world.getPlayers().isEmpty()) + { + getPlugin().announce("Saving & Closing World: " + F.elem(world.getName())); + MapUtil.UnloadWorld(getPlugin(), world, true); + _updated.remove(world); + getPlugin()._mapsBeingZipped.add(world.getName()); + System.out.println("Starting backup of " + world); + new BackupTask(getPlugin(), world.getName(), data -> + { + System.out.println("Finished backup of " + world); + getPlugin()._mapsBeingZipped.remove(world.getName()); + }); + } + } + } + + @EventHandler + public void Chat(AsyncPlayerChatEvent event) + { + event.setCancelled(true); + + String world = C.cDGreen + C.Bold + getPlugin().getShortWorldName(event.getPlayer().getWorld().getName()); + + String name = C.cYellow + event.getPlayer().getName(); + if (getPlugin().getData(event.getPlayer().getWorld().getName()).HasAccess(event.getPlayer())) + { + name = C.cGreen + event.getPlayer().getName(); + } + + String grayName = C.cBlue + event.getPlayer().getName(); + String grayWorld = C.cBlue + C.Bold + event.getPlayer().getWorld().getName(); + + for (Player player : UtilServer.getPlayers()) + { + if (player.getWorld().equals(event.getPlayer().getWorld())) + { + player.sendMessage(world + ChatColor.RESET + " " + name + ChatColor.RESET + " " + event.getMessage()); + } else + { + player.sendMessage(grayWorld + ChatColor.RESET + " " + grayName + ChatColor.RESET + " " + C.cGray + event.getMessage()); + } + + } + + System.out.println(world + ChatColor.RESET + " " + name + ChatColor.RESET + " " + event.getMessage()); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void InteractCancel(PlayerInteractEvent event) + { + if (event.getPlayer().isOp()) + { + return; + } + //Permission + if (!getPlugin().getData(event.getPlayer().getWorld().getName()).HasAccess(event.getPlayer())) + { + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void TeleportCommand(PlayerCommandPreprocessEvent event) + { + if (!event.getMessage().toLowerCase().startsWith("/tp")) + { + return; + } + + Player player = event.getPlayer(); + + String[] tokens = event.getMessage().split(" "); + + if (tokens.length != 2) + { + return; + } + + event.setCancelled(true); + + Player target = UtilPlayer.searchOnline(player, tokens[1], true); + if (target != null) + { + MapData data = getPlugin().getData(target.getWorld().getName()); + if(!data.CanJoin(player)) + { + player.sendMessage(C.cRed + "That server is currently locked, and you don't have access to it."); + return; + } + UtilPlayer.message(player, F.main("Game", "You teleported to " + F.name(target.getName()) + ".")); + player.teleport(target); + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void commandCancel(PlayerCommandPreprocessEvent event) + { + if (event.getMessage().startsWith("/tp") || + event.getMessage().startsWith("/hub") || + event.getMessage().startsWith("/list") || + event.getMessage().startsWith("/map") || + event.getMessage().startsWith("/create") || + event.getMessage().startsWith("/copy") || + event.getMessage().startsWith("/delete")) + { + return; + } + + //Permission + if (!getPlugin().getData(event.getPlayer().getWorld().getName()).HasAccess(event.getPlayer())) + { + UtilPlayer.message(event.getPlayer(), F.main("Parser", "You do not have Build-Access for this Map.")); + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void FlySpeed(PlayerCommandPreprocessEvent event) + { + if (!event.getMessage().toLowerCase().startsWith("/speed")) + { + return; + } + + Player player = event.getPlayer(); + + String[] tokens = event.getMessage().split(" "); + + if (tokens.length != 2) + { + return; + } + + event.setCancelled(true); + + try + { + float speed = Float.parseFloat(tokens[1]); + + player.setFlySpeed(speed); + + UtilPlayer.message(player, F.main("Game", "Fly Speed set to " + F.elem("" + speed) + ".")); + } catch (Exception e) + { + UtilPlayer.message(player, F.main("Game", "Invalid Speed Input.")); + } + } + + //################################################################################################# + //# # + //# Simple methods # + //# # + //# # + //################################################################################################# + + @EventHandler + public void Join(PlayerJoinEvent event) + { + Player player = event.getPlayer(); + if (player.getName().equalsIgnoreCase("TadahTech")) + { + event.setJoinMessage(C.cGreenB + "Your build server Saviour, TIMOTHY! has arrived, please take a moment to thank him."); + getPlugin().getServer().getOnlinePlayers().forEach(o -> o.playSound(o.getLocation(), Sound.AMBIENCE_THUNDER, 1.0F, 1.0F)); + return; + } + event.setJoinMessage(F.sys("Player Join", event.getPlayer().getName())); + } + + @EventHandler + public void Join(PlayerQuitEvent event) + { + event.setQuitMessage(F.sys("Player Quit", event.getPlayer().getName())); + } + + @EventHandler + public void onDroppedItemSpawn(EntitySpawnEvent event) + { + if (event.getEntityType() != EntityType.ARMOR_STAND) + { + event.setCancelled(true); + } + } + + + @EventHandler + public void DisableBurn(BlockBurnEvent event) + { + event.setCancelled(true); + } + + @EventHandler + public void DisableIgnite(BlockIgniteEvent event) + { + if (event.getCause() == IgniteCause.LAVA || event.getCause() == IgniteCause.SPREAD) + { + event.setCancelled(true); + } + } + + @EventHandler + public void DisableFire(BlockSpreadEvent event) + { + event.setCancelled(true); + } + + @EventHandler + public void DisableFade(BlockFadeEvent event) + { + event.setCancelled(true); + } + + @EventHandler + public void DisableDecay(LeavesDecayEvent event) + { + event.setCancelled(true); + } + + @EventHandler + public void DisableIceForm(BlockFormEvent event) + { + event.setCancelled(true); + } +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/MMMazeModule.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/MMMazeModule.java new file mode 100644 index 000000000..0160c923b --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/MMMazeModule.java @@ -0,0 +1,127 @@ +package mineplex.mapparser.module.modules; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilGear; +import mineplex.mapparser.MapParser; +import mineplex.mapparser.module.Module; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; + +/** + * + */ +public class MMMazeModule extends Module +{ + + public MMMazeModule(MapParser plugin) + { + super("MM-Maze", plugin); + } + + + @EventHandler + public void mmMazeParser(PlayerInteractEvent event) + { + if (event.isCancelled()) + return; + + if (event.getAction() != Action.LEFT_CLICK_BLOCK) return; + + //Permission + if (!GetData(event.getPlayer().getWorld().getName()).HasAccess(event.getPlayer())) + { + return; + } + + Player player = event.getPlayer(); + + if (!UtilGear.isMat(player.getItemInHand(), Material.WEB)) + return; + + event.setCancelled(true); + + // parse + + Block clicked = event.getClickedBlock(); + Location center = clicked.getLocation(); + Location lowestCorner = center.clone().subtract(49, 0, 49); + + // 0 = air or other + // 1 = path - quartz + // 2 = mob spawn - gold + // 3 = safe spawn - stone + + int[][] maze = new int[99][99]; + + for (int i = 0; i < 99; i++) + for (int j = 0; j < 99; j++) + maze[i][j] = getMMParseValue(lowestCorner.clone().add(j, 0, i).getBlock().getType()); + + //Save + try + { + FileWriter fstream = new FileWriter(GetData(player.getWorld().getName()).MapFolder + File.separator + "Maze.dat"); + BufferedWriter out = new BufferedWriter(fstream); + + out.write("private static final int[][] PARSED_MAZE = {" + System.lineSeparator()); + for (int j[] : maze) + { + out.write("{"); + boolean first = true; + for (int k : j) + { + if(!first) out.write(","); + out.write(k + ""); + + first = false; + } + out.write("}," + System.lineSeparator()); + } + out.write("};" + System.lineSeparator()); + + out.close(); + } + catch (Exception e) + { + player.sendMessage(C.cRed + C.Bold + "MMMazeParse: " + ChatColor.RESET + "An error has occured, see console."); + e.printStackTrace(); + } + player.sendMessage(C.cGreen + C.Bold + "MMMazeParse: " + ChatColor.RESET + "Maze parsed."); + } + + private int getMMParseValue(Material m) + { + switch (m) { + case QUARTZ_BLOCK: + return 1; + + case GOLD_BLOCK: + return 2; + + case STONE: + return 3; + + case DIRT: + return 4; + + case COBBLESTONE: + return 5; + + case BRICK: + return 6; + + default: + return 0; + } + } +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/SignModule.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/SignModule.java new file mode 100644 index 000000000..47e4d5aed --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/SignModule.java @@ -0,0 +1,112 @@ +package mineplex.mapparser.module.modules; + +import mineplex.core.common.util.UtilTime; +import mineplex.core.common.util.UtilWorld; +import mineplex.mapparser.MapParser; +import mineplex.mapparser.module.Module; +import org.bukkit.World; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.SignChangeEvent; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.util.ArrayList; + +/** + * + */ +public class SignModule extends Module +{ + public SignModule(MapParser plugin) + { + super("Sign", plugin); + } + + + @EventHandler(priority = EventPriority.LOWEST) + public void signChangeLog(SignChangeEvent event) + { + if (GetData(event.getPlayer().getWorld().getName()).HasAccess(event.getPlayer())) + { + ArrayList text = new ArrayList<>(); + + text.add("Date: " + UtilTime.now()); + text.add("Player: " + event.getPlayer().getName()); + text.add("Location: " + UtilWorld.locToStrClean(event.getBlock().getLocation())); + for (int i = 0; i < event.getLines().length; i++) + { + text.add("Line " + i + ": " + event.getLines()[i]); + } + writeSignLog(text, event.getPlayer().getWorld()); + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void signCommand(PlayerCommandPreprocessEvent event) + { + if (event.getMessage().toLowerCase().contains("set")) + { + ArrayList text = new ArrayList<>(); + + text.add("Date: " + UtilTime.now()); + text.add("Player: " + event.getPlayer().getName()); + text.add("Location: " + UtilWorld.locToStrClean(event.getPlayer().getLocation())); + text.add("Message: " + event.getMessage()); + + writeSignCommandLog(text, event.getPlayer().getWorld()); + } + } + + public void writeSignCommandLog(ArrayList text, World world) + { + try + { + File file = new File(world.getName() + "/" + "command_sign_log.txt"); + + if (!file.exists()) + { + file.createNewFile(); + } + + FileWriter fw = new FileWriter(file.getAbsoluteFile(), true); + BufferedWriter bw = new BufferedWriter(fw); + + bw.write("\n\n"); + for (String line : text) + bw.write("\n" + line); + + bw.close(); + } catch (Exception e) + { + e.printStackTrace(); + } + } + + public void writeSignLog(ArrayList text, World world) + { + try + { + File file = new File(world.getName() + "/" + "sign_log.txt"); + + if (!file.exists()) + { + file.createNewFile(); + } + + FileWriter fw = new FileWriter(file.getAbsoluteFile(), true); + BufferedWriter bw = new BufferedWriter(fw); + + bw.write("\n\n"); + for (String line : text) + bw.write("\n" + line); + + bw.close(); + } catch (Exception e) + { + e.printStackTrace(); + } + } +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/TreeToolModule.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/TreeToolModule.java new file mode 100644 index 000000000..8e6df1c01 --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/TreeToolModule.java @@ -0,0 +1,119 @@ +package mineplex.mapparser.module.modules; + +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; +import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilEvent; +import mineplex.core.common.util.UtilEvent.ActionType; +import mineplex.core.common.util.UtilGear; +import mineplex.mapparser.BlockData; +import mineplex.mapparser.MapParser; +import mineplex.mapparser.module.Module; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; + +/** + * + */ +public class TreeToolModule extends Module +{ + + private Map>> _treeHistory = Maps.newHashMap(); + + public TreeToolModule(MapParser plugin) + { + super("TreeTool", plugin); + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void treeRemover(PlayerInteractEvent event) + { + if (event.isCancelled()) + { + return; + } + + //Permission + if (!getPlugin().getData(event.getPlayer().getWorld().getName()).HasAccess(event.getPlayer())) + { + return; + } + + Player player = event.getPlayer(); + + if (!UtilGear.isMat(player.getItemInHand(), Material.NETHER_STAR)) + { + return; + } + + event.setCancelled(true); + + //Remove + if (event.getAction() == Action.LEFT_CLICK_BLOCK) + { + if (event.getClickedBlock().getType() != Material.LOG) + { + player.sendMessage(C.cRed + C.Bold + "TreeTool: " + ChatColor.RESET + "Left-Click on Log"); + return; + } + + Set toRemove = getPlugin().searchLog(Sets.newHashSet(), event.getClickedBlock()); + + if (toRemove.isEmpty()) + { + player.sendMessage(C.cRed + C.Bold + "TreeTool: " + ChatColor.RESET + "Left-Click on Log"); + return; + } + + Set history = Sets.newHashSet(); + + for (Block block : toRemove) + { + history.add(new BlockData(block)); + + block.setType(Material.AIR); + } + + if (!_treeHistory.containsKey(player.getUniqueId())) + { + _treeHistory.put(player.getUniqueId(), Lists.newArrayList()); + } + + _treeHistory.get(player.getUniqueId()).add(0, history); + + player.sendMessage(C.cRed + C.Bold + "TreeTool: " + ChatColor.RESET + "Tree Removed"); + + while (_treeHistory.get(player.getUniqueId()).size() > 10) + { + _treeHistory.get(player.getUniqueId()).remove(10); + } + + } else if (UtilEvent.isAction(event, ActionType.R)) + { + if (!_treeHistory.containsKey(player.getUniqueId()) || _treeHistory.get(player.getUniqueId()).isEmpty()) + { + player.sendMessage(C.cGreen + C.Bold + "TreeTool: " + ChatColor.RESET + "No Tree History"); + return; + } + + Set datas = _treeHistory.get(player.getUniqueId()).remove(0); + + datas.forEach(BlockData::restore); + + player.sendMessage(C.cGreen + C.Bold + "TreeTool: " + ChatColor.RESET + "Tree Restored"); + } + } + +} diff --git a/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/damage/DamageManager.java b/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/damage/DamageManager.java index 304394625..c679ba060 100644 --- a/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/damage/DamageManager.java +++ b/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/damage/DamageManager.java @@ -8,6 +8,24 @@ import java.util.Arrays; import java.util.HashMap; import java.util.Map; +import mineplex.core.MiniPlugin; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilAction; +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilEnt; +import mineplex.core.common.util.UtilEvent; +import mineplex.core.common.util.UtilGear; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; +import mineplex.core.disguise.DisguiseManager; +import mineplex.core.npc.NpcManager; +import mineplex.minecraft.game.core.combat.CombatManager; +import mineplex.minecraft.game.core.condition.ConditionManager; +import mineplex.minecraft.game.core.damage.compatibility.NpcProtectListener; +import net.minecraft.server.v1_8_R3.DamageSource; +import net.minecraft.server.v1_8_R3.EntityHuman; +import net.minecraft.server.v1_8_R3.EntityLiving; + import org.bukkit.EntityEffect; import org.bukkit.GameMode; import org.bukkit.Location; @@ -30,24 +48,6 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; -import mineplex.core.MiniPlugin; -import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilAction; -import mineplex.core.common.util.UtilAlg; -import mineplex.core.common.util.UtilEnt; -import mineplex.core.common.util.UtilEvent; -import mineplex.core.common.util.UtilGear; -import mineplex.core.common.util.UtilPlayer; -import mineplex.core.common.util.UtilServer; -import mineplex.core.disguise.DisguiseManager; -import mineplex.core.npc.NpcManager; -import mineplex.minecraft.game.core.combat.CombatManager; -import mineplex.minecraft.game.core.condition.ConditionManager; -import mineplex.minecraft.game.core.damage.compatibility.NpcProtectListener; -import net.minecraft.server.v1_8_R3.DamageSource; -import net.minecraft.server.v1_8_R3.EntityHuman; -import net.minecraft.server.v1_8_R3.EntityLiving; - public class DamageManager extends MiniPlugin { private CombatManager _combatManager; @@ -545,21 +545,14 @@ public class DamageManager extends MiniPlugin origin = event.GetDamagerEntity(true).getLocation(); if (event.getKnockbackOrigin() != null) origin = event.getKnockbackOrigin(); + else if (event.GetProjectile() != null) + origin = event.GetProjectile().getLocation(); //Vec Vector trajectory = UtilAlg.getTrajectory2d(origin, event.GetDamageeEntity().getLocation()); trajectory.multiply(0.6 * knockback); trajectory.setY(Math.abs(trajectory.getY())); - - //Special handling for projectiles - if(event.GetProjectile() != null && event.getKnockbackOrigin() == null) - { - trajectory = event.GetProjectile().getVelocity(); - trajectory.setY(0); - trajectory.multiply(0.6 * knockback / trajectory.length()); - trajectory.setY(0.5); - } - + //Apply double vel = 0.2 + trajectory.length() * 0.8; diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/redis/counter/Counter.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/redis/counter/Counter.java index 208491b4b..af6a05043 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/redis/counter/Counter.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/redis/counter/Counter.java @@ -1,5 +1,8 @@ package mineplex.serverdata.redis.counter; +import mineplex.serverdata.Region; +import mineplex.serverdata.servers.ConnectionData; + import java.util.concurrent.atomic.AtomicLong; /** @@ -14,26 +17,25 @@ public class Counter private final AtomicLong _count = new AtomicLong(0); // The System.currentTimeMillis() when cached count was last updated private volatile long _lastUpdated; - // The maximum time to wait before syncing the count with repository - private final long _syncTime; // The unique key to reference this counter private final String _dataKey; // Redis repository to store the count private final CounterRedisRepository _redisRepository; - public Counter(String dataKey, long syncTime) + public Counter(ConnectionData writeConnection, ConnectionData readConnection, Region region, String dataKey) { _dataKey = dataKey; - _syncTime = syncTime; - _redisRepository = new CounterRedisRepository(dataKey); + _redisRepository = new CounterRedisRepository(writeConnection, readConnection, region, dataKey); } public Counter(String dataKey) { - this(dataKey, 5000); // 5 seconds + _dataKey = dataKey; + _redisRepository = new CounterRedisRepository(dataKey); } + /** * Add a value to the counter and return the new counter value. This method is thread-safe and interacts * directly with the atomic value stored in redis. The value returned from redis is then returned @@ -51,25 +53,26 @@ public class Counter } /** - * Get the latest count of the counter. This will use the last cached value for the counter, or if - * the last cached count hasn't been updated in the {@link #_syncTime} period it will pull the latest - * count from the redis repository and use that value. + * Get the latest cached count from the counter. This value will not be changed until {@link #addAndGet(long)} + * or {@link #updateCount} is called. * * @return The counter count */ public long getCount() { - if (System.currentTimeMillis() - _lastUpdated > _syncTime) - { - updateCount(_redisRepository.getCount()); - } - return _count.get(); } /** - * Reset the counter back to 0. This will take a maximum time of {@link #_syncTime} to propagate - * across all instances of this counter. Immediately updates the redis repository. + * Update the cached count to reflect the count in redis. This should be called async + */ + public void updateCount() + { + updateCount(_redisRepository.getCount()); + } + + /** + * Reset the counter back to 0. Immediately updates the redis repository. * * @return The value of the counter before it was reset */ diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/redis/counter/CounterRedisRepository.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/redis/counter/CounterRedisRepository.java index 96a1cb0e3..69561aed8 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/redis/counter/CounterRedisRepository.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/redis/counter/CounterRedisRepository.java @@ -2,6 +2,7 @@ package mineplex.serverdata.redis.counter; import mineplex.serverdata.Region; import mineplex.serverdata.redis.RedisRepository; +import mineplex.serverdata.servers.ConnectionData; import redis.clients.jedis.Jedis; /** @@ -12,13 +13,18 @@ public class CounterRedisRepository extends RedisRepository { private String _dataKey; + public CounterRedisRepository(ConnectionData writeConnection, ConnectionData readConnection, Region region, String dataKey) + { + super(writeConnection, readConnection, region); + + _dataKey = dataKey; + } + public CounterRedisRepository(String dataKey) { super(Region.ALL); _dataKey = dataKey; - -// setNX(); } /** diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/redis/counter/GoalCounter.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/redis/counter/GoalCounter.java index 8d14e56f0..38bb33d1a 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/redis/counter/GoalCounter.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/redis/counter/GoalCounter.java @@ -1,5 +1,8 @@ package mineplex.serverdata.redis.counter; +import mineplex.serverdata.Region; +import mineplex.serverdata.servers.ConnectionData; + import java.util.ArrayList; import java.util.List; @@ -18,17 +21,31 @@ public class GoalCounter extends Counter private List _listeners; - public GoalCounter(String dataKey, long syncTime, long goal) + public GoalCounter(ConnectionData writeConnection, ConnectionData readConnection, Region region, String dataKey, long goal) { - super(dataKey, syncTime); + super(writeConnection, readConnection, region, dataKey); + init(goal); + } + + public GoalCounter(String dataKey, long goal) + { + super(dataKey); + + init(goal); + } + + private void init(long goal) + { _completed = false; _goal = goal; - _listeners = new ArrayList<>(); + + updateCount(); + _lastMilestone = (int) getFillPercent(); - update(); + updateMilestone(); } /** @@ -78,7 +95,7 @@ public class GoalCounter extends Counter /** * Update {@link #_completed} and notify listeners if it has completed */ - private void update() + private void updateMilestone() { int currentMilestone = (int) getFillPercent(); @@ -95,7 +112,7 @@ public class GoalCounter extends Counter { super.updateCount(newCount); - update(); + updateMilestone(); } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java index 76a31e27e..bcd04629c 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java @@ -9,6 +9,7 @@ import mineplex.core.elo.EloTeam; import mineplex.core.itemstack.ItemBuilder; import mineplex.core.packethandler.IPacketHandler; import mineplex.core.packethandler.PacketInfo; +import mineplex.core.party.Party; import mineplex.core.recharge.Recharge; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; @@ -1145,8 +1146,7 @@ public abstract class Game implements Listener { return team.GetSize() < PlayersPerTeam; } - return Manager.IsTeamBalance() ? team.GetSize() < Math.max(1, UtilServer.getPlayers().length / GetTeamList().size()) - : true; + return !Manager.IsTeamBalance() || team.GetSize() < Math.max(1, UtilServer.getPlayers().length / GetTeamList().size()); } @EventHandler diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/chat/GameChatManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/chat/GameChatManager.java index 2bb9542fb..996fc364c 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/chat/GameChatManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/chat/GameChatManager.java @@ -1,19 +1,5 @@ package nautilus.game.arcade.managers.chat; -import java.text.DecimalFormat; -import java.util.AbstractMap; -import java.util.Collection; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.Map; - -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.AsyncPlayerChatEvent; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; - import mineplex.core.account.CoreClient; import mineplex.core.common.Rank; import mineplex.core.common.jsonchat.JsonMessage; @@ -25,8 +11,21 @@ import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.game.Game; import nautilus.game.arcade.game.Game.GameState; import nautilus.game.arcade.game.GameTeam; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.jooq.tools.json.JSONObject; +import java.text.DecimalFormat; +import java.util.AbstractMap; +import java.util.Collection; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.Map; + public class GameChatManager implements Listener { @@ -122,31 +121,31 @@ public class GameChatManager implements Listener rankStr = rank.getTag(true, true) + " " + C.Reset; } - if (event.getMessage().charAt(0) == '@') + //Party Chat + if (event.getMessage().charAt(0) == '#') { - //Party Chat - Party party = _manager.getPartyManager().GetParty(sender); - + Party party = _manager.getPartyManager().getParty(sender); if (party != null) { event.getRecipients().clear(); - rankStr = C.cDPurpleB + "Party " + C.Reset; - event.setMessage(event.getMessage().substring(1, event.getMessage().length())); - event.setFormat(levelStr + rankStr + C.cWhiteB + senderName + " " + C.cPurple + "%2$s"); + event.setFormat(levelStr + C.cDPurple + C.Bold + "Party " + C.cWhite + C.Bold + event.getPlayer().getName() + " " + C.cPurple + "%2$s"); - format = event.getFormat().split(rankStr)[0]; - name = C.cWhiteB + sender.getName() + C.Reset; - message = event.getFormat().split(sender.getName())[1].replace("%2$s", "") + _manager.GetChat().getFilteredMessage(sender, event.getMessage()); - - if(safeSend(sender, format, rankStr, rank, name, message, party.GetPlayersOnline())) + for (String member : party.getMembers()) { - event.setCancelled(true); - } + Player other = UtilPlayer.searchExact(member); - return; + if (other != null) + event.getRecipients().add(other); + } } + else + { + UtilPlayer.message(sender, F.main("Party", "You are not in a Party.")); + event.setCancelled(true); + } + return; } event.setFormat(levelStr + rankStr + senderName + " " + C.cWhite + "%2$s");