From ee22274ef54ca3f3100ce2527e2848b03535ed63 Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Wed, 23 Mar 2016 16:02:06 -0500 Subject: [PATCH 01/14] Removed Stacker debug messages. --- Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java | 6 ------ .../src/mineplex/hub/modules/StackerManager.java | 2 -- 2 files changed, 8 deletions(-) diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java index e960df477..985e8c5f3 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java @@ -1091,13 +1091,7 @@ public class HubManager extends MiniClientPlugin if (UtilTime.elapsed(_portalTime.get(playerName), 5000)) { playerNameIterator.remove(); - continue; } - - Player player = Bukkit.getPlayerExact(playerName); - - if (player != null) - System.out.println(playerName + "'s location: " + player.getLocation().toString()); } } } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/StackerManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/StackerManager.java index 70880b4e0..532058fa2 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/StackerManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/StackerManager.java @@ -277,8 +277,6 @@ public class StackerManager extends MiniPlugin implements IThrown UtilPlayer.message(thrower, F.main("Stacker", "You threw " + F.name(UtilEnt.getName(throwee)) + ".")); UtilPlayer.message(throwee, F.main("Stacker", "You were thrown by " + F.name(thrower.getName()) + ".")); - - System.out.println("Stacker throw (" + thrower.getName() + ") -> (" + UtilEnt.getName(throwee) + ")"); UtilAction.velocity(throwee, thrower.getLocation().getDirection(), 1.8, false, 0, 0.3, 2, false); From 29966195ee099cf22715fef10b7a8ed2581eeffb Mon Sep 17 00:00:00 2001 From: William Burns Date: Sat, 26 Mar 2016 13:07:41 -0400 Subject: [PATCH 02/14] Create an API for sending Slack message to multiple teams and channels. --- .../src/mineplex/core/MiniPlugin.java | 10 +- .../src/mineplex/core/slack/SlackAPI.java | 129 ++++++++++++ .../mineplex/core/slack/SlackAttachment.java | 14 ++ .../src/mineplex/core/slack/SlackMessage.java | 194 ++++++++++++++++++ .../src/mineplex/core/slack/SlackTeam.java | 79 +++++++ .../src/mineplex/core/thread/ThreadPool.java | 19 ++ 6 files changed, 437 insertions(+), 8 deletions(-) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/slack/SlackAPI.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/slack/SlackAttachment.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/slack/SlackMessage.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/slack/SlackTeam.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/thread/ThreadPool.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/MiniPlugin.java b/Plugins/Mineplex.Core/src/mineplex/core/MiniPlugin.java index dbad6fbdb..3477b742c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/MiniPlugin.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/MiniPlugin.java @@ -1,27 +1,21 @@ package mineplex.core; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitScheduler; -import com.google.common.util.concurrent.ThreadFactoryBuilder; import mineplex.core.command.CommandCenter; import mineplex.core.command.ICommand; import mineplex.core.common.util.F; import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilTime.TimeUnit; +import mineplex.core.thread.ThreadPool; public abstract class MiniPlugin implements Listener { - private static final ExecutorService threadPool = Executors.newCachedThreadPool( - new ThreadFactoryBuilder().setNameFormat("MiniPlugin Async %1$d").build()); - protected String _moduleName = "Default"; protected JavaPlugin _plugin; protected NautHashMap _commands; @@ -113,7 +107,7 @@ public abstract class MiniPlugin implements Listener public void runAsync(Runnable runnable) { // Instead of using - threadPool.execute(runnable); + ThreadPool.ASYNC.execute(runnable); } public void runAsync(Runnable runnable, long time) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/slack/SlackAPI.java b/Plugins/Mineplex.Core/src/mineplex/core/slack/SlackAPI.java new file mode 100644 index 000000000..9bce0f192 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/slack/SlackAPI.java @@ -0,0 +1,129 @@ +package mineplex.core.slack; + +import java.io.BufferedReader; +import java.io.DataOutputStream; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLEncoder; + +import com.google.gson.JsonObject; +import mineplex.core.thread.ThreadPool; + +/** + * An API for sending and handling Slack messages. + */ +public class SlackAPI +{ + // Default emoji. + public static final String DEFAULT_ICON = ":mineplex:"; + + // Singular instance. + private static SlackAPI _instance; + + // Don't allow instantiation elsewhere. + private SlackAPI() {} + + /** + * Sends a message asynchronously to a Slack channel. + * + * @param team The team which contains the target channel. + * @param channel The target channel for the message. + * @param message The message to be displayed. + * @param customTitle Whether or not to use a custom title for the message. + * If false the default team title is used. + */ + public void sendMessage(SlackTeam team, String channel, SlackMessage message, boolean customTitle) + { + ThreadPool.ASYNC.execute(() -> + { + // Set message title. + if (!customTitle) + { + message.setUsername(team.getTitle()); + message.setIcon(DEFAULT_ICON); + } + + // Set message channel. + JsonObject msg = message.toJson(); + msg.addProperty("channel", channel); + + // Run the call. + runWebCall(team, msg); + }); + } + + /** + * Runs a web call to a specified Slack incoming-hook. + * + * @param team The team to run the call on. + * @param call The call to be run. + */ + private String runWebCall(SlackTeam team, JsonObject call) + { + HttpURLConnection connection = null; + try + { + // Create connection. + URL url = new URL(team.getURL()); + connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("POST"); + connection.setConnectTimeout(5000); + connection.setUseCaches(false); + connection.setDoInput(true); + connection.setDoOutput(true); + + // Setup payload. + String payload = "payload=" + URLEncoder.encode(call.toString(), "UTF-8"); + + // Send request. + DataOutputStream dos = new DataOutputStream(connection.getOutputStream()); + dos.writeBytes(payload); + dos.flush(); + dos.close(); + + // Receive response. + InputStream is = connection.getInputStream(); + BufferedReader rd = new BufferedReader(new InputStreamReader(is)); + String line; + String response = ""; + while ((line = rd.readLine()) != null) + { + response += line + "\n"; + } + + rd.close(); + return response.toString(); + } + catch (Exception e) + { + e.printStackTrace(); + } + finally + { + if (connection != null) + { + // Terminate connection. + connection.disconnect(); + } + } + + return "500 Error"; + } + + /** + * Gets the singular instance of the Slack API. + * + * @return The {@link SlackAPI} instance. + */ + public static SlackAPI getInstance() + { + if (_instance == null) + { + _instance = new SlackAPI(); + } + + return _instance; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/slack/SlackAttachment.java b/Plugins/Mineplex.Core/src/mineplex/core/slack/SlackAttachment.java new file mode 100644 index 000000000..a42d9a405 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/slack/SlackAttachment.java @@ -0,0 +1,14 @@ +package mineplex.core.slack; + +/** + * Attached content for a {@link SlackMessage}. + */ +public class SlackAttachment +{ + private String _color; + + private String _authorName; + private String _authorIcon; + + private String _title; +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/slack/SlackMessage.java b/Plugins/Mineplex.Core/src/mineplex/core/slack/SlackMessage.java new file mode 100644 index 000000000..60cd5739e --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/slack/SlackMessage.java @@ -0,0 +1,194 @@ +package mineplex.core.slack; + +import java.util.ArrayList; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; + +/** + * A message to be sent through the {@link SlackAPI}. + */ +public class SlackMessage +{ + private String _username; + private String _icon; + + private String _content; + private ArrayList _attachments; + + /** + * Class constructor. + * + * @param content The content of the message. + */ + public SlackMessage(String content) + { + _icon = SlackAPI.DEFAULT_ICON; + _content = content; + _attachments = new ArrayList<>(); + } + + /** + * Class constructor. + * + * @param username The username of the message. + * @param content The content of the message. + */ + public SlackMessage(String username, String content) + { + _username = username; + _icon = SlackAPI.DEFAULT_ICON; + _content = content; + _attachments = new ArrayList<>(); + } + + /** + * Class constructor. + * + * @param username The username of the message. + * @param icon The icon/emoji of the message. + * @param content The content of the message. + */ + public SlackMessage(String username, String icon, String content) + { + _username = username; + _icon = ":" + icon + ":"; + _content = content; + _attachments = new ArrayList<>(); + } + + /** + * Converts the message to JSON format. + * + * @return The {@link SlackMessage} in the form of a {@link JsonObject}. + */ + public JsonObject toJson() + { + JsonObject msg = new JsonObject(); + + if (_username != null) + { + msg.addProperty("username", _username); + } + + if (_icon != null) + { + msg.addProperty("icon_emoji", _icon); + } + + if (_content != null) + { + msg.addProperty("text", _content); + } + + if (!_attachments.isEmpty()) + { + JsonArray attachments = new JsonArray(); + for (SlackAttachment attachment : _attachments) + { + //attachments.add(attachment.toJson()); + //TODO + } + + msg.add("attachments", attachments); + } + + return msg; + } + + /** + * Gets the username that displays as a title. + * + * @return The username in use. + */ + public String getUsername() + { + return _username; + } + + /** + * Sets the username that displays as a title. + * + * @param username The username to use. + */ + public void setUsername(String username) + { + _username = username; + } + + /** + * Gets the icon that displays with the title. + * + * @return The icon in use. + */ + public String getIcon() + { + return _icon; + } + + /** + * Sets the icon that displays with the title. + * + * @param icon The icon to use. + */ + public void setIcon(String icon) + { + _icon = icon; + } + + /** + * Gets the content of the message. + * + * @return The content of the message. + */ + public String getContent() + { + return _content; + } + + /** + * Sets the content of the message. + * + * @param content The content of the message. + */ + public void setContent(String content) + { + _content = content; + } + + /** + * Gets the attachments of the message. + * + * @return A list of attachments. + */ + public ArrayList getAttachments() + { + return _attachments; + } + + /** + * Adds an attachment to the Slack message. + * + * @param attachment The attachment to add. + */ + public void addAttachment(SlackAttachment attachment) + { + if (!_attachments.contains(attachment)) + { + _attachments.add(attachment); + } + } + + /** + * Removes an attachment from the Slack message. + * + * @param attachment The attachment to remove. + */ + public void removeAttachment(SlackAttachment attachment) + { + if (_attachments.contains(attachment)) + { + _attachments.remove(attachment); + } + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/slack/SlackTeam.java b/Plugins/Mineplex.Core/src/mineplex/core/slack/SlackTeam.java new file mode 100644 index 000000000..965346791 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/slack/SlackTeam.java @@ -0,0 +1,79 @@ +package mineplex.core.slack; + +/** + * An enumeration of Mineplex Slack teams. + */ +public enum SlackTeam +{ + // Dev team - mineplex.slack.com + DEVELOPER("Mineplex Dev", "T045RUM7F", "B0VK6GFKN", "6GxwJsDfEpbVnQl8pYuEyq5T"), + + // QA team - mineplexqa.slack.com + QA("Mineplex QA", "todo", "todo", "todo"), // TODO: new details + + ; + + private String _title; + private String _id1; + private String _id2; + private String _token; + + SlackTeam(String title, String id1, String id2, String token) + { + _title = title; + _id1 = id1; + _id2 = id2; + _token = token; + } + + /** + * Gets the title that will be displayed that the top of each + * {@link SlackMessage}. + * + * @return The title of this team. + */ + public String getTitle() + { + return _title; + } + + /** + * Gets the first ID of this Slack team. + * + * @return The individual first ID. + */ + public String getId1() + { + return _id1; + } + + /** + * Gets the second ID of this Slack team. + * + * @return The individual second ID. + */ + public String getId2() + { + return _id2; + } + + /** + * Gets the token key of this Slack team. + * + * @return The individual and secret token. + */ + public String getToken() + { + return _token; + } + + /** + * Gets the web hook in the form of a URL. + * + * @return The URL as a string. + */ + public String getURL() + { + return "https://hooks.slack.com/services/" + getId1() + "/" + getId2() + "/" + getToken(); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/thread/ThreadPool.java b/Plugins/Mineplex.Core/src/mineplex/core/thread/ThreadPool.java new file mode 100644 index 000000000..7e9af44b1 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/thread/ThreadPool.java @@ -0,0 +1,19 @@ +package mineplex.core.thread; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +import com.google.common.util.concurrent.ThreadFactoryBuilder; + +/** + * A collection of threads for different uses. + */ +public class ThreadPool +{ + + // Async Thread + public static ExecutorService ASYNC = Executors.newCachedThreadPool( + new ThreadFactoryBuilder().setNameFormat("MiniPlugin Async %1$d").build() + ); + +} From c1adb7e1bc3e4ec80d5228b4fe795add96fe4a83 Mon Sep 17 00:00:00 2001 From: William Burns Date: Sat, 26 Mar 2016 13:12:59 -0400 Subject: [PATCH 03/14] Remove Slack attachment functionality (for now). --- .../mineplex/core/slack/SlackAttachment.java | 14 ----- .../src/mineplex/core/slack/SlackMessage.java | 55 ------------------- 2 files changed, 69 deletions(-) delete mode 100644 Plugins/Mineplex.Core/src/mineplex/core/slack/SlackAttachment.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/slack/SlackAttachment.java b/Plugins/Mineplex.Core/src/mineplex/core/slack/SlackAttachment.java deleted file mode 100644 index a42d9a405..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/slack/SlackAttachment.java +++ /dev/null @@ -1,14 +0,0 @@ -package mineplex.core.slack; - -/** - * Attached content for a {@link SlackMessage}. - */ -public class SlackAttachment -{ - private String _color; - - private String _authorName; - private String _authorIcon; - - private String _title; -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/slack/SlackMessage.java b/Plugins/Mineplex.Core/src/mineplex/core/slack/SlackMessage.java index 60cd5739e..ad0ce7de4 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/slack/SlackMessage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/slack/SlackMessage.java @@ -1,8 +1,5 @@ package mineplex.core.slack; -import java.util.ArrayList; - -import com.google.gson.JsonArray; import com.google.gson.JsonObject; /** @@ -14,7 +11,6 @@ public class SlackMessage private String _icon; private String _content; - private ArrayList _attachments; /** * Class constructor. @@ -25,7 +21,6 @@ public class SlackMessage { _icon = SlackAPI.DEFAULT_ICON; _content = content; - _attachments = new ArrayList<>(); } /** @@ -39,7 +34,6 @@ public class SlackMessage _username = username; _icon = SlackAPI.DEFAULT_ICON; _content = content; - _attachments = new ArrayList<>(); } /** @@ -54,7 +48,6 @@ public class SlackMessage _username = username; _icon = ":" + icon + ":"; _content = content; - _attachments = new ArrayList<>(); } /** @@ -81,18 +74,6 @@ public class SlackMessage msg.addProperty("text", _content); } - if (!_attachments.isEmpty()) - { - JsonArray attachments = new JsonArray(); - for (SlackAttachment attachment : _attachments) - { - //attachments.add(attachment.toJson()); - //TODO - } - - msg.add("attachments", attachments); - } - return msg; } @@ -155,40 +136,4 @@ public class SlackMessage { _content = content; } - - /** - * Gets the attachments of the message. - * - * @return A list of attachments. - */ - public ArrayList getAttachments() - { - return _attachments; - } - - /** - * Adds an attachment to the Slack message. - * - * @param attachment The attachment to add. - */ - public void addAttachment(SlackAttachment attachment) - { - if (!_attachments.contains(attachment)) - { - _attachments.add(attachment); - } - } - - /** - * Removes an attachment from the Slack message. - * - * @param attachment The attachment to remove. - */ - public void removeAttachment(SlackAttachment attachment) - { - if (_attachments.contains(attachment)) - { - _attachments.remove(attachment); - } - } } From 9969b7d783e9085982a87bdd379644ad3b4b51c6 Mon Sep 17 00:00:00 2001 From: Cheese Date: Sat, 2 Apr 2016 11:39:40 +1100 Subject: [PATCH 04/14] support for resource packs for different MC versions --- .../core/common/MinecraftVersion.java | 8 ++++ .../mineplex/core/common/util/UtilPlayer.java | 9 ++++ .../resourcepack/ResourcePackManager.java | 44 +++++++++++++----- .../src/nautilus/game/arcade/GameType.java | 45 ++++++++++++++----- .../src/nautilus/game/arcade/game/Game.java | 2 +- .../game/games/minestrike/MineStrike.java | 2 +- .../game/arcade/managers/GameFlagManager.java | 3 +- 7 files changed, 88 insertions(+), 25 deletions(-) create mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/MinecraftVersion.java diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/MinecraftVersion.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/MinecraftVersion.java new file mode 100644 index 000000000..d95ae1d36 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/MinecraftVersion.java @@ -0,0 +1,8 @@ +package mineplex.core.common; + +public enum MinecraftVersion +{ + ALL, + Version1_9, + Version1_8 +} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java index db6e9b2a4..7b7ee06bd 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java @@ -27,6 +27,7 @@ import org.bukkit.potion.PotionEffect; import org.bukkit.util.BlockIterator; import org.bukkit.util.Vector; +import mineplex.core.common.MinecraftVersion; import net.minecraft.server.v1_8_R3.EntityPlayer; import net.minecraft.server.v1_8_R3.Packet; import net.minecraft.server.v1_8_R3.PlayerConnection; @@ -814,4 +815,12 @@ public class UtilPlayer { ((CraftPlayer) player).getHandle().setWingsDeployAt(distance); } + + public static MinecraftVersion getVersion(Player player) + { + if (is1_9(player)) + return MinecraftVersion.Version1_9; + + return MinecraftVersion.Version1_8; + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/resourcepack/ResourcePackManager.java b/Plugins/Mineplex.Core/src/mineplex/core/resourcepack/ResourcePackManager.java index 31b41dd06..2ba415206 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/resourcepack/ResourcePackManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/resourcepack/ResourcePackManager.java @@ -16,6 +16,8 @@ import org.bukkit.plugin.java.JavaPlugin; import com.google.common.base.Objects; import mineplex.core.MiniPlugin; +import mineplex.core.common.MinecraftVersion; +import mineplex.core.common.Pair; import mineplex.core.common.jsonchat.ClickEvent; import mineplex.core.common.jsonchat.JsonMessage; import mineplex.core.common.util.C; @@ -31,7 +33,7 @@ import mineplex.serverdata.commands.ServerCommandManager; public class ResourcePackManager extends MiniPlugin implements CommandCallback { - private String _resourcePackUrl; + private Pair[] _resourcePackUrls; private boolean _resourcePackRequired; private NautHashMap _resourcePackUsers = new NautHashMap(); private NautHashMap _resourcePackNoResponse = new NautHashMap(); @@ -45,13 +47,32 @@ public class ResourcePackManager extends MiniPlugin implements CommandCallback ServerCommandManager.getInstance().registerCommandType("RedisUnloadResPack", RedisUnloadResPack.class, this); } + + public void setPlayerPack(Player player) + { + MinecraftVersion version = UtilPlayer.getVersion(player); + + if (_resourcePackUrls == null || _resourcePackUrls.length == 0) + return; + + for (Pair entry : _resourcePackUrls) + { + if (entry.getLeft() == version || entry.getLeft() == MinecraftVersion.ALL) + { + player.setResourcePack(entry.getRight()); + return; + } + } + + player.setResourcePack(_resourcePackUrls[0].getRight()); + } @EventHandler public void ResourcePackJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); - if (_resourcePackUrl == null) + if (_resourcePackUrls == null) { return; } @@ -62,7 +83,8 @@ public class ResourcePackManager extends MiniPlugin implements CommandCallback } _resourcePackUsers.put(player.getName(), false); - player.setResourcePack(_resourcePackUrl); + + setPlayerPack(player); } @EventHandler @@ -89,14 +111,15 @@ public class ResourcePackManager extends MiniPlugin implements CommandCallback // Send it again, enforce it! _resourcePackNoResponse.put(player.getName(), System.currentTimeMillis()); - player.setResourcePack(_resourcePackUrl); + + setPlayerPack(player); } } @EventHandler public void onResourcePackStatus(PlayerResourcePackStatusEvent event) { - if (_resourcePackUrl == null) + if (_resourcePackUrls == null) { return; } @@ -176,19 +199,19 @@ public class ResourcePackManager extends MiniPlugin implements CommandCallback returnHubNoResPack(player); } - public void setResourcePack(String resourcePack, boolean forceResourcePack) + public void setResourcePack(Pair[] resourcePack, boolean forceResourcePack) { - if (Objects.equal(resourcePack, _resourcePackUrl) && forceResourcePack == _resourcePackRequired) + if (Objects.equal(resourcePack, _resourcePackUrls) && forceResourcePack == _resourcePackRequired) { return; } _resourcePackNoResponse.clear(); _resourcePackUsers.clear(); - _resourcePackUrl = resourcePack == null || resourcePack.isEmpty() ? null : resourcePack; + _resourcePackUrls = resourcePack == null || (resourcePack.length == 0) ? null : resourcePack; _resourcePackRequired = forceResourcePack; - if (_resourcePackUrl == null || _resourcePackUrl.isEmpty()) + if (_resourcePackUrls == null || _resourcePackUrls.length == 0) { _resourcePackRequired = false; @@ -207,7 +230,8 @@ public class ResourcePackManager extends MiniPlugin implements CommandCallback } _resourcePackUsers.put(player.getName(), false); - player.setResourcePack(_resourcePackUrl); + + setPlayerPack(player); } } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java index 03e7f96d7..e3e5cdadd 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java @@ -1,5 +1,10 @@ package nautilus.game.arcade; +import java.util.AbstractMap; +import java.util.Map.Entry; + +import mineplex.core.common.MinecraftVersion; +import mineplex.core.common.Pair; import mineplex.core.game.GameCategory; import mineplex.core.game.GameDisplay; import nautilus.game.arcade.game.Game; @@ -82,25 +87,38 @@ public enum GameType ChampionsCTF(ChampionsCTF.class, GameDisplay.ChampionsCTF), ChampionsDominate(ChampionsDominate.class, GameDisplay.ChampionsDominate), ChampionsTDM(ChampionsTDM.class, GameDisplay.ChampionsTDM), - Christmas(Christmas.class, GameDisplay.Christmas, "http://file.mineplex.com/ResChristmas.zip", true), + Christmas(Christmas.class, GameDisplay.Christmas, new Pair[] + { + Pair.create(MinecraftVersion.ALL, "http://file.mineplex.com/ResChristmas.zip") + }, true), DeathTag(DeathTag.class, GameDisplay.DeathTag), DragonEscape(DragonEscape.class, GameDisplay.DragonEscape), DragonEscapeTeams(DragonEscapeTeams.class, GameDisplay.DragonEscapeTeams), DragonRiders(DragonRiders.class, GameDisplay.DragonRiders), Dragons(Dragons.class, GameDisplay.Dragons), DragonsTeams(DragonsTeams.class, GameDisplay.DragonsTeams), - Draw(Draw.class, GameDisplay.Draw, "http://chivebox.com/mineplex/ResDrawMyThing.zip", true), + Draw(Draw.class, GameDisplay.Draw, new Pair[] + { + Pair.create(MinecraftVersion.ALL, "http://chivebox.com/mineplex/ResDrawMyThing.zip") + }, true), ElytraRings(ElytraRings.class, GameDisplay.ElytraRings), Evolution(Evolution.class, GameDisplay.Evolution), Gravity(Gravity.class, GameDisplay.Gravity), - Halloween(Halloween.class, GameDisplay.Halloween, "http://file.mineplex.com/ResHalloween.zip", true), + Halloween(Halloween.class, GameDisplay.Halloween, new Pair[] + { + Pair.create(MinecraftVersion.ALL, "http://file.mineplex.com/ResHalloween.zip") + }, true), HideSeek(HideSeek.class, GameDisplay.HideSeek), HoleInTheWall(HoleInTheWall.class, GameDisplay.HoleInTheWall), Horse(Horse.class, GameDisplay.Horse), Lobbers(BombLobbers.class, GameDisplay.Lobbers), Micro(Micro.class, GameDisplay.Micro), MilkCow(MilkCow.class, GameDisplay.MilkCow), - MineStrike(MineStrike.class, GameDisplay.MineStrike, "http://chivebox.com/mineplex/ResMinestrike.zip", true), + MineStrike(MineStrike.class, GameDisplay.MineStrike, new Pair[] + { + Pair.create(MinecraftVersion.Version1_8, "http://chivebox.com/mineplex/ResMinestrike.zip"), + Pair.create(MinecraftVersion.Version1_9, "http://chivebox.com/mineplex/ResMinestrike19.zip") + }, true), MineWare(MineWare.class, GameDisplay.MineWare), OldMineWare(OldMineWare.class, GameDisplay.OldMineWare), Paintball(Paintball.class, GameDisplay.Paintball), @@ -128,7 +146,10 @@ public enum GameType TurfWars(TurfForts.class, GameDisplay.TurfWars), UHC(UHC.class, GameDisplay.UHC), WitherAssault(WitherGame.class, GameDisplay.WitherAssault), - Wizards(Wizards.class, GameDisplay.Wizards, "http://file.mineplex.com/ResWizards.zip", true), + Wizards(Wizards.class, GameDisplay.Wizards, new Pair[] + { + Pair.create(MinecraftVersion.ALL, "http://file.mineplex.com/ResWizards.zip") + }, true), ZombieSurvival(ZombieSurvival.class, GameDisplay.ZombieSurvival), Build(Build.class, GameDisplay.Build), Cards(Cards.class, GameDisplay.Cards), @@ -158,7 +179,7 @@ public enum GameType boolean _enforceResourcePack; GameType[] _mapSource; boolean _ownMaps; - String _resourcePack; + Pair[] _resourcePacks; Class _gameClass; private int _gameId; // Unique identifying id for this gamemode (used for statistics) @@ -169,7 +190,7 @@ public enum GameType this(gameClass, display, null, false, null, true); } - GameType(Class gameClass, GameDisplay display, String resourcePackUrl, boolean enforceResourcePack) + GameType(Class gameClass, GameDisplay display, Pair[] resourcePackUrl, boolean enforceResourcePack) { this(gameClass, display, resourcePackUrl, enforceResourcePack, null, true); } @@ -179,11 +200,11 @@ public enum GameType this(gameClass, display, null, false, mapSource, ownMap); } - GameType(Class gameClass, GameDisplay display, String resourcePackUrl, boolean enforceResourcePack, GameType[] mapSource, boolean ownMaps) + GameType(Class gameClass, GameDisplay display, Pair[] resourcePackUrls, boolean enforceResourcePack, GameType[] mapSource, boolean ownMaps) { _display = display; _gameClass = gameClass; - _resourcePack = resourcePackUrl; + _resourcePacks = resourcePackUrls; _enforceResourcePack = enforceResourcePack; _mapSource = mapSource; _ownMaps = ownMaps; @@ -199,11 +220,11 @@ public enum GameType return _enforceResourcePack; } - public String getResourcePackUrl() + public Pair[] getResourcePackUrls() { - return _resourcePack; + return _resourcePacks; } - + public GameType[] getMapSource() { return _mapSource; 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 79e46c510..ed8899996 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 @@ -401,7 +401,7 @@ public abstract class Game implements Listener new ExperienceStatTracker(this), new WinStatTracker(this), new LoseStatTracker(this), new DamageDealtStatTracker( this), new DamageTakenStatTracker(this), new GamesPlayedStatTracker(this)); - Manager.getResourcePackManager().setResourcePack(gameType.getResourcePackUrl(), gameType.isEnforceResourcePack()); + Manager.getResourcePackManager().setResourcePack(gameType.getResourcePackUrls(), gameType.isEnforceResourcePack()); _useEntityPacketHandler = new IPacketHandler() { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/MineStrike.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/MineStrike.java index c4cbf7053..3931b7f3d 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/MineStrike.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/MineStrike.java @@ -3124,7 +3124,7 @@ public class MineStrike extends TeamGame } else if (event.getMessage().equalsIgnoreCase("/rpon")) { - event.getPlayer().setResourcePack(GetType().getResourcePackUrl()); + Manager.getResourcePackManager().setPlayerPack(event.getPlayer()); UtilPlayer.message(event.getPlayer(), F.main("Resource Pack", "Resource Pack: " + C.cGreen + "Enabled")); UtilPlayer.message(event.getPlayer(), F.main("Resource Pack", "Type " + F.elem("/rpoff") + " to disable.")); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameFlagManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameFlagManager.java index ff47122fb..9ddacd156 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameFlagManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameFlagManager.java @@ -3,6 +3,7 @@ package nautilus.game.arcade.managers; import java.util.HashMap; import mineplex.core.antihack.AntiHack; +import mineplex.core.common.MinecraftVersion; import mineplex.core.common.Rank; import mineplex.core.common.util.C; import mineplex.core.common.util.F; @@ -1204,7 +1205,7 @@ public class GameFlagManager implements Listener if (Manager.GetGame() == null) return; - if (Manager.GetGame().GetType().getResourcePackUrl() == null) + if (Manager.GetGame().GetType().getResourcePackUrls() == null || Manager.GetGame().GetType().getResourcePackUrls().length == 0) return; UtilTextMiddle.display(C.cGold + C.Bold + Manager.GetGame().GetType().GetName(), "Make sure you accept the Resource Pack", 20, 120, 20, event.getPlayer()); From 8f959a73ebc7c29f7062b1fd69ecda4f12e672f3 Mon Sep 17 00:00:00 2001 From: Cheese Date: Sat, 2 Apr 2016 12:46:25 +1100 Subject: [PATCH 05/14] debug --- .../src/mineplex/core/resourcepack/ResourcePackManager.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/resourcepack/ResourcePackManager.java b/Plugins/Mineplex.Core/src/mineplex/core/resourcepack/ResourcePackManager.java index 2ba415206..0cc20fd4f 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/resourcepack/ResourcePackManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/resourcepack/ResourcePackManager.java @@ -60,11 +60,13 @@ public class ResourcePackManager extends MiniPlugin implements CommandCallback if (entry.getLeft() == version || entry.getLeft() == MinecraftVersion.ALL) { player.setResourcePack(entry.getRight()); + player.sendMessage("A: " + entry.getRight()); return; } } player.setResourcePack(_resourcePackUrls[0].getRight()); + player.sendMessage("B: " + _resourcePackUrls[0].getRight()); } @EventHandler From fecd3c1eaa266c23c6a92931c4ac7e5d049f34da Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Mon, 4 Apr 2016 23:28:38 +1000 Subject: [PATCH 06/14] Final changes --- .../game/clans/clans/ClansManager.java | 49 ++++++----- .../clans/clans/regions/ClansRegions.java | 2 +- .../game/clans/gameplay/Gameplay.java | 85 ++++++++++--------- .../game/clans/spawn/travel/TravelPage.java | 16 ++-- .../game/clans/tutorial/TutorialManager.java | 2 + .../clans/tutorial/command/FinishCommand.java | 2 +- .../clans/tutorial/command/StartCommand.java | 2 +- .../tutorial/command/TutorialCommand.java | 2 +- .../tutorials/clans/ClansMainTutorial.java | 17 ++-- .../hub/server/ui/clans/ClansServerPage.java | 14 ++- .../hub/server/ui/clans/ClansServerShop.java | 2 +- .../src/nautilus/game/arcade/GameType.java | 1 - 12 files changed, 109 insertions(+), 85 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java index 233b267e2..4eccc43ce 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java @@ -357,27 +357,27 @@ public class ClansManager extends MiniClientPluginimplements IRelati List jumpOffHolograms = Arrays.asList( // West Spawn - new Location(Spawn.getSpawnWorld(), 8, 204, 359), - new Location(Spawn.getSpawnWorld(), 34, 204, 390), - new Location(Spawn.getSpawnWorld(), 8, 204, 418), - new Location(Spawn.getSpawnWorld(), -25, 204, 390), + new Location(Spawn.getSpawnWorld(), 8, 200, 359), + new Location(Spawn.getSpawnWorld(), 34, 200, 390), + new Location(Spawn.getSpawnWorld(), 8, 200, 418), + new Location(Spawn.getSpawnWorld(), -25, 200, 390), // East Spawn - new Location(Spawn.getSpawnWorld(), 34, 207, -393), - new Location(Spawn.getSpawnWorld(), 8, 207, -365), - new Location(Spawn.getSpawnWorld(), -25, 207, -393), - new Location(Spawn.getSpawnWorld(), 8, 207, -424) + new Location(Spawn.getSpawnWorld(), 34, 200, -393), + new Location(Spawn.getSpawnWorld(), 8, 200, -365), + new Location(Spawn.getSpawnWorld(), -25, 200, -393), + new Location(Spawn.getSpawnWorld(), 8, 200, -424) ); List welcomeHolograms = Arrays.asList( - new Location(Spawn.getSpawnWorld(), 17, 204, 390), - new Location(Spawn.getSpawnWorld(), 8, 204, 399), - new Location(Spawn.getSpawnWorld(), 0, 204, 390), - new Location(Spawn.getSpawnWorld(), 8, 204, 381), - new Location(Spawn.getSpawnWorld(), 8, 207, -384), - new Location(Spawn.getSpawnWorld(), 0, 207, -393), - new Location(Spawn.getSpawnWorld(), 8, 207, -402), - new Location(Spawn.getSpawnWorld(), 17, 207, -393) + new Location(Spawn.getSpawnWorld(), 17, 200, 390), + new Location(Spawn.getSpawnWorld(), 8, 200, 399), + new Location(Spawn.getSpawnWorld(), 0, 200, 390), + new Location(Spawn.getSpawnWorld(), 8, 200, 381), + new Location(Spawn.getSpawnWorld(), 8, 200, -384), + new Location(Spawn.getSpawnWorld(), 0, 200, -393), + new Location(Spawn.getSpawnWorld(), 8, 200, -402), + new Location(Spawn.getSpawnWorld(), 17, 200, -393) ); for (Location location : jumpOffHolograms) @@ -824,9 +824,14 @@ public class ClansManager extends MiniClientPluginimplements IRelati } List recipients = new ArrayList<>(); + + String message = event.getMessage();//_chat.getFilteredMessage(event.getPlayer(), event.getMessage()); for (Player other : event.getRecipients()) { + if (_tutorial.inTutorial(other)) + continue; + ClanInfo otherClan = _clanUtility.getClanByPlayer(other); if (otherClan == null) @@ -835,14 +840,12 @@ public class ClansManager extends MiniClientPluginimplements IRelati } else { - String message = _chat.getFilteredMessage(event.getPlayer(), event.getMessage()); ClanRelation rel = _clanUtility.rel(clan, otherClan); - other.sendMessage(rank + rel.getColor(true) + clan.getName() + " " + rel.getColor(false) + event.getPlayer().getName() + " " + C.cWhite + message); } } - recipients.forEach(p -> p.sendMessage(String.format(rank + C.cGold + clan.getName() + " " + C.cYellow + "%s " + C.cWhite + "%s", event.getPlayer().getName(), event.getMessage()))); + recipients.forEach(p -> p.sendMessage(String.format(rank + C.cGold + clan.getName() + " " + C.cYellow + "%s " + C.cWhite + "%s", event.getPlayer().getName(), message))); recipients.clear(); } @@ -1168,12 +1171,14 @@ public class ClansManager extends MiniClientPluginimplements IRelati @EventHandler(priority = EventPriority.HIGHEST) public void onJoin(PlayerLoginEvent event) { - if (true) + Rank rank = _clientManager.Get(event.getPlayer()).GetRank(); + + if (rank.has(Rank.MODERATOR)) { - return; + event.allow(); + event.setResult(PlayerLoginEvent.Result.ALLOWED); } - Rank rank = _clientManager.Get(event.getPlayer()).GetRank(); if (UtilServer.getPlayers().length >= UtilServer.getServer().getMaxPlayers() && !rank.has(Rank.ADMIN) && !event.getPlayer().isWhitelisted() && !event.getPlayer().isOp()) { event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Clans Beta is full! Try again soon"); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/regions/ClansRegions.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/regions/ClansRegions.java index 8ee9a773c..ee09e4677 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/regions/ClansRegions.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/regions/ClansRegions.java @@ -42,7 +42,7 @@ public class ClansRegions extends MiniPlugin public final static int SPAWN_RADIUS = 3; // Radius of spawn claim area (measured in chunks) public final static int SHOP_RADIUS = 5; // Radius of shop claim area (measured in chunks) public final static int FIELDS_RADIUS = 7; // Radius of fields claim area (measured in chunks) - public final static int BORDERLANDS_RADIUS = 50; // Radius of borderlands claim area (measured in chunks) + public final static int BORDERLANDS_RADIUS = 85; // Radius of borderlands claim area (measured in chunks) public static final int BORDER_RADIUS = 1319; private ClansManager _manager; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java index eee7092d4..392273fa9 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java @@ -54,6 +54,7 @@ import mineplex.core.common.util.UtilEvent; import mineplex.core.common.util.UtilEvent.ActionType; import mineplex.core.common.util.UtilGear; import mineplex.core.common.util.UtilInv; +import mineplex.core.common.util.UtilItem; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; @@ -582,46 +583,50 @@ public class Gameplay extends MiniPlugin } } -// @EventHandler(priority = EventPriority.LOWEST) -// public void replantTree(BlockBreakEvent event) -// { -// final Block block = event.getBlock(); -// -// if (_clansManager.getClanUtility().getClaim(block.getLocation()) != null) -// { -// return; -// } -// -// if (!UtilItem.isLog(block.getType())) -// { -// return; -// } -// -// if (UtilItem.isLog(block.getRelative(BlockFace.DOWN).getType())) -// { -// return; -// } -// -// if (UtilItem.isLeaf(block.getRelative(BlockFace.DOWN).getType())) -// { -// return; -// } -// -// if (block.getRelative(BlockFace.DOWN).getType() != Material.DIRT && block.getRelative(BlockFace.DOWN).getType() != Material.GRASS) -// { -// return; -// } -// -// final byte data = block.getData(); -// -// UtilServer.getServer().getScheduler().scheduleSyncDelayedTask(getPlugin(), new Runnable() { -// public void run() -// { -// block.setType(Material.SAPLING); -// block.setData(data); -// } -// }, 20 * 5); -// } + @EventHandler(priority = EventPriority.LOWEST) + public void replantTree(BlockBreakEvent event) + { + final Block block = event.getBlock(); + + if (_clansManager.getClanUtility().getClaim(block.getLocation()) != null) + { + return; + } + + if (!UtilItem.isLog(block.getType())) + { + return; + } + + if (UtilItem.isLog(block.getRelative(BlockFace.DOWN).getType())) + { + return; + } + + if (UtilItem.isLeaf(block.getRelative(BlockFace.DOWN).getType())) + { + return; + } + + if (block.getRelative(BlockFace.DOWN).getType() != Material.DIRT && block.getRelative(BlockFace.DOWN).getType() != Material.GRASS) + { + return; + } + + final byte data = block.getData(); + + UtilServer.getServer().getScheduler().scheduleSyncDelayedTask(getPlugin(), new Runnable() { + public void run() + { + Material mat = block.getRelative(BlockFace.DOWN).getType(); + if (mat == Material.DIRT || mat == Material.GRASS) + { + block.setType(Material.SAPLING); + block.setData(data); + } + } + }, 20 * 10); + } @EventHandler public void killRain(WeatherChangeEvent event) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/spawn/travel/TravelPage.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/spawn/travel/TravelPage.java index d111c78d8..6140d1ad2 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/spawn/travel/TravelPage.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/spawn/travel/TravelPage.java @@ -38,7 +38,7 @@ public class TravelPage extends ShopPageBase @Override protected void buildPage() { - addTravelLocation(Spawn.getNorthSpawn(), getPlayer().getLocation().distance(Spawn.getNorthSpawn()) <= 64 ? Material.SKULL_ITEM : Material.IRON_SWORD, (getPlayer().getLocation().distance(Spawn.getNorthSpawn()) <= 64 ? C.cRedB : C.cGreenB) + "East Spawn", new String[] { + addTravelLocation(Spawn.getNorthSpawn(), getPlayer().getLocation().distance(Spawn.getNorthSpawn()) <= 64 ? Material.SKULL_ITEM : Material.IRON_SWORD, (getPlayer().getLocation().distance(Spawn.getNorthSpawn()) <= 64 ? C.cRedB : C.cGreenB) + "North Spawn", new String[] { C.cWhite + "Spawns are locations where", C.cWhite + "you respawn after dying.", " ", @@ -46,9 +46,9 @@ public class TravelPage extends ShopPageBase C.cWhite + "as they are Safe Zones.", getPlayer().getLocation().distance(Spawn.getSouthSpawn()) <= 64 ? " " : "", getPlayer().getLocation().distance(Spawn.getNorthSpawn()) <= 64 ? C.cRed + "You are already here." : "", - }, 14 + 10, getPlayer().getLocation().distance(Spawn.getNorthSpawn()) <= 64 ? (byte) 3 : (byte) 0); + }, 4, getPlayer().getLocation().distance(Spawn.getNorthSpawn()) <= 64 ? (byte) 3 : (byte) 0); - addTravelLocation(Spawn.getSouthSpawn(), getPlayer().getLocation().distance(Spawn.getSouthSpawn()) <= 64 ? Material.SKULL_ITEM : Material.IRON_SWORD, (getPlayer().getLocation().distance(Spawn.getSouthSpawn()) <= 64 ? C.cRedB : C.cGreenB) + "West Spawn", new String[] { + addTravelLocation(Spawn.getSouthSpawn(), getPlayer().getLocation().distance(Spawn.getSouthSpawn()) <= 64 ? Material.SKULL_ITEM : Material.IRON_SWORD, (getPlayer().getLocation().distance(Spawn.getSouthSpawn()) <= 64 ? C.cRedB : C.cGreenB) + "South Spawn", new String[] { C.cWhite + "Spawns are locations where", C.cWhite + "you respawn after dying.", " ", @@ -56,23 +56,23 @@ public class TravelPage extends ShopPageBase C.cWhite + "as they are Safe Zones.", getPlayer().getLocation().distance(Spawn.getSouthSpawn()) <= 64 ? " " : "", getPlayer().getLocation().distance(Spawn.getSouthSpawn()) <= 64 ? C.cRed + "You are already here." : "", - }, 12 + 8, getPlayer().getLocation().distance(Spawn.getSouthSpawn()) <= 64 ? (byte) 3 : (byte) 0); + }, 22 + 9 + 9, getPlayer().getLocation().distance(Spawn.getSouthSpawn()) <= 64 ? (byte) 3 : (byte) 0); - addTravelLocation(Spawn.getWestTown(), ClanIcon.CASTLE.getMaterial(), C.cDGreenB + "North Shop", new String[] { + addTravelLocation(Spawn.getWestTown(), ClanIcon.CASTLE.getMaterial(), C.cDGreenB + "West Shop", new String[] { C.cWhite + "Shops are locations where you", C.cWhite + "can buy and sell all sorts of goods.", " ", C.cWhite + "You cannot be attacked here,", C.cWhite + "as they are Safe Zones.", - }, 4, ClanIcon.CASTLE.getData()); + }, 12 + 8, ClanIcon.CASTLE.getData()); - addTravelLocation(Spawn.getEastTown(), ClanIcon.CASTLE.getMaterial(), C.cDGreenB + "South Shop", new String[] { + addTravelLocation(Spawn.getEastTown(), ClanIcon.CASTLE.getMaterial(), C.cDGreenB + "East Shop", new String[] { C.cWhite + "Shops are locations where you", C.cWhite + "can buy and sell all sorts of goods.", " ", C.cWhite + "You cannot be attacked here,", C.cWhite + "as they are Safe Zones.", - }, 22 + 9 + 9, ClanIcon.CASTLE.getData()); + }, 14 + 10, ClanIcon.CASTLE.getData()); final ClanInfo clan = _plugin.getClan(getPlayer()); Outpost outpost = _plugin.getSiegeManager().getOutpostManager().Get(clan); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialManager.java index 3fc5c825b..29609b670 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialManager.java @@ -65,7 +65,9 @@ public class TutorialManager extends MiniPlugin implements ScoreboardElement Player recipient = recipients.next(); if (inTutorial(recipient)) + { recipients.remove(); + } } return Boolean.FALSE; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/command/FinishCommand.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/command/FinishCommand.java index be204fd2e..92decfb05 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/command/FinishCommand.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/command/FinishCommand.java @@ -10,7 +10,7 @@ public class FinishCommand extends CommandBase { public FinishCommand(TutorialManager plugin) { - super(plugin, Rank.MODERATOR, "finish", "end"); + super(plugin, Rank.DEVELOPER, "finish", "end"); } @Override diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/command/StartCommand.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/command/StartCommand.java index 859503bbc..2e100d21b 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/command/StartCommand.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/command/StartCommand.java @@ -13,7 +13,7 @@ public class StartCommand extends CommandBase { public StartCommand(TutorialManager plugin) { - super(plugin, Rank.MODERATOR, "start"); + super(plugin, Rank.DEVELOPER, "start"); } @Override diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/command/TutorialCommand.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/command/TutorialCommand.java index a2814ddd3..cf38bd009 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/command/TutorialCommand.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/command/TutorialCommand.java @@ -13,7 +13,7 @@ public class TutorialCommand extends MultiCommandBase { public TutorialCommand(TutorialManager plugin) { - super(plugin, Rank.MODERATOR, "tutorial", "tut"); + super(plugin, Rank.DEVELOPER, "tutorial", "tut"); AddCommand(new StartCommand(plugin)); AddCommand(new FinishCommand(plugin)); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/ClansMainTutorial.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/ClansMainTutorial.java index af19d1e42..21352c599 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/ClansMainTutorial.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/ClansMainTutorial.java @@ -129,16 +129,19 @@ public class ClansMainTutorial extends Tutorial //ClansManager.getInstance().getPvpTimer().unpause(player); - _taskManager.completedTask(new Callback() + if (!_taskManager.hasCompletedTask(player, getTaskIdentifier())) { - @Override - public void run(Boolean data) + _taskManager.completedTask(new Callback() { + @Override + public void run(Boolean data) + { - GoldManager.getInstance().addGold(player, 32000); - UtilPlayer.message(player, F.main("Clans", "You have earned " + F.elem(32000 + " Gold") + " for finishing the tutorial!")); - } - }, player, getTaskIdentifier()); + GoldManager.getInstance().addGold(player, 32000); + UtilPlayer.message(player, F.main("Clans", "You have earned " + F.elem(32000 + " Gold") + " for finishing the tutorial!")); + } + }, player, getTaskIdentifier()); + } /* ClansManager.getInstance().runAsync(() -> { diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClansServerPage.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClansServerPage.java index 137fa6322..e11a7fbec 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClansServerPage.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClansServerPage.java @@ -1,6 +1,8 @@ package mineplex.hub.server.ui.clans; import java.util.Collection; +import java.util.Comparator; +import java.util.TreeSet; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -10,6 +12,7 @@ import org.bukkit.event.inventory.ClickType; import mineplex.core.account.CoreClientManager; import mineplex.core.common.util.C; import mineplex.core.common.util.Callback; +import mineplex.core.common.util.UtilAlg; import mineplex.core.donation.DonationManager; import mineplex.core.shop.item.DisplayButton; import mineplex.core.shop.item.IButton; @@ -32,7 +35,7 @@ public class ClansServerPage extends ShopPageBase servers = getPlugin().getServerList("Clans"); + Collection servers = UtilAlg.sortSet(getPlugin().getServerList("Clans"), new Comparator() + { + @Override + public int compare(ServerInfo o1, ServerInfo o2) + { + return o1.Name.compareTo(o2.Name); + } + }); int currentSlot = 9; for (ServerInfo server : servers) 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 a3241e2cc..0cb09411c 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 @@ -24,7 +24,7 @@ public class ClansServerShop extends ShopBase public ClansServerShop(ServerManager plugin, CoreClientManager clientManager, DonationManager donationManager) { - super(plugin, clientManager, donationManager, "Clans Alpha"); + super(plugin, clientManager, donationManager, "Clans Beta"); _repository = new ClanRepository(plugin.getPlugin(), plugin.getStatusManager().getCurrentServerName()); } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java index 03e7f96d7..e18567d91 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java @@ -243,5 +243,4 @@ public enum GameType { return _display.getKitGameName(); } - } \ No newline at end of file From 228a00169654b9589438f91c7cd3b0ab0476d6f5 Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Mon, 4 Apr 2016 10:01:50 -0500 Subject: [PATCH 07/14] Added Shift Left clicking to the ban list for Cannon :D --- .../src/mineplex/game/clans/clans/siege/weapon/Cannon.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java index 1b7f3f0c9..ea9bb2cad 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java @@ -221,13 +221,14 @@ public class Cannon extends SiegeWeapon return; } - if (event.getClick() == ClickType.SHIFT_RIGHT) + if (event.getClick() == ClickType.SHIFT_RIGHT || event.getClick() == ClickType.SHIFT_RIGHT) { if(_inventory.getViewers().contains(event.getWhoClicked())) { event.setCancelled(true); //block shift right clicking tnt into this inventory getClans().runSyncLater(() -> ((Player) event.getWhoClicked()).updateInventory(), 1L); } + return; } From 91ddac964317e68bfbcab02ae50b0e551621d065 Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Mon, 4 Apr 2016 10:30:59 -0500 Subject: [PATCH 08/14] Added world checking for boundary stuff. --- .../tutorial/tutorials/clans/ClansMainTutorial.java | 3 +++ .../clans/objective/goals/clan/BuildHouseGoal.java | 9 --------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/ClansMainTutorial.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/ClansMainTutorial.java index 21352c599..f26a6ac72 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/ClansMainTutorial.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/ClansMainTutorial.java @@ -220,6 +220,9 @@ public class ClansMainTutorial extends Tutorial public boolean isIn(Location location, TutorialRegion region, Bounds bounds) { + if (region.getOrigin().getWorld() != location.getWorld()) + return false; + List locs = region.getLocationMap().getGoldLocations(bounds.getDataLocColor()); return UtilAlg.inBoundingBox(location, locs.get(0), locs.get(1)); } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/clan/BuildHouseGoal.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/clan/BuildHouseGoal.java index 250e6d96e..4c26307cb 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/clan/BuildHouseGoal.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/clan/BuildHouseGoal.java @@ -3,15 +3,10 @@ package mineplex.game.clans.tutorial.tutorials.clans.objective.goals.clan; import java.util.List; import org.bukkit.DyeColor; -import org.bukkit.Effect; import org.bukkit.Material; -import org.bukkit.Sound; -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.BlockBreakEvent; -import org.bukkit.event.block.BlockDamageEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.inventory.ItemStack; @@ -20,9 +15,7 @@ import com.google.common.collect.Lists; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; import mineplex.game.clans.clans.ClansManager; -import mineplex.game.clans.tutorial.TutorialRegion; import mineplex.game.clans.tutorial.objective.ObjectiveGoal; -import mineplex.game.clans.tutorial.tutorials.clans.ClansMainTutorial; import mineplex.game.clans.tutorial.tutorials.clans.objective.ClanObjective; public class BuildHouseGoal extends ObjectiveGoal @@ -98,6 +91,4 @@ public class BuildHouseGoal extends ObjectiveGoal event.setCancelled(true); } } - - } From 781c4bfdbd39108f2933d2f3c4ca620fae44642e Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Mon, 4 Apr 2016 10:31:13 -0500 Subject: [PATCH 09/14] Removed db call off main thread for ClanServerPage --- .../hub/server/ui/clans/ClansServerPage.java | 30 ++++++++++++------- .../hub/server/ui/clans/ClansServerShop.java | 6 ---- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClansServerPage.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClansServerPage.java index e11a7fbec..d597dbc82 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClansServerPage.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClansServerPage.java @@ -27,8 +27,6 @@ import mineplex.serverdata.data.DataRepository; public class ClansServerPage extends ShopPageBase { - - //private DataRepository _repository; // Stores the name of the last Clans server a player was on private ClanRepository _repository; private int _accountId; @@ -46,21 +44,33 @@ public class ClansServerPage extends ShopPageBase() + getPlugin().runAsync(new Runnable() + { + public void run() + { + _repository.retrievePlayersClan(_accountId, new Callback() { @Override public void run(SimpleClanToken data) { - if (data != null) + getPlugin().runSync(new Runnable() { - buildClanPage(data); - } - else - { - buildNoClanPage(); - } + public void run() + { + if (data != null) + { + buildClanPage(data); + } + else + { + buildNoClanPage(); + } + } + }); } }); + } + }); } private void buildClanPage(SimpleClanToken clan) 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 0cb09411c..b74a37acd 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 @@ -2,24 +2,18 @@ package mineplex.hub.server.ui.clans; import org.bukkit.Sound; import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.block.Action; -import org.bukkit.event.player.PlayerInteractEvent; import mineplex.core.account.CoreClientManager; -import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.donation.DonationManager; import mineplex.core.party.Party; import mineplex.core.shop.ShopBase; 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; public class ClansServerShop extends ShopBase { - private ClanRepository _repository; public ClansServerShop(ServerManager plugin, CoreClientManager clientManager, DonationManager donationManager) From 1b1e6f6ef5fbec7a1cd43db14a41a642a265edf3 Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Mon, 4 Apr 2016 13:45:20 -0500 Subject: [PATCH 10/14] Moved the redis operation before asking for a mysql connection --- .../account/repository/AccountRepository.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/repository/AccountRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/account/repository/AccountRepository.java index 8ec8ecb31..856c5e8a0 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/account/repository/AccountRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/account/repository/AccountRepository.java @@ -60,17 +60,11 @@ public class AccountRepository extends MinecraftRepository public int login(final List loginProcessors, final UUID uuid, final String name) { // First we try to grab the account id from cache - this saves an extra trip to database - int accountId = -1; + int accountId = PlayerCache.getInstance().getAccountId(uuid); try (Connection connection = getConnection(); Statement statement = connection.createStatement()) { - int cachedId = PlayerCache.getInstance().getAccountId(uuid); - if (cachedId > 0) - { - accountId = cachedId; - System.out.println("Loaded Account ID From Cache [" + name + " - " + accountId + "]"); - } - else + if (accountId <= 0) { // Player was not found in cache, we need to grab the account id from database statement.execute("SELECT id FROM accounts WHERE accounts.uuid = '" + uuid + "' LIMIT 1;"); @@ -100,6 +94,10 @@ public class AccountRepository extends MinecraftRepository accountId = tempList.get(0); } } + else + { + System.out.println(name + " Loaded Account ID From Cache [" + name + " - " + accountId + "]"); + } final int finalId = accountId; final String uuidString = uuid.toString(); @@ -109,7 +107,7 @@ public class AccountRepository extends MinecraftRepository loginString += loginProcessors.parallelStream().map(processor -> processor.getQuery(finalId, uuidString, name)).collect(Collectors.joining()); statement.execute(loginString); - + statement.getUpdateCount(); statement.getMoreResults(); From e2baf2b56c15096a5f3692db49c81c6f17f1c142 Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Mon, 4 Apr 2016 13:46:00 -0500 Subject: [PATCH 11/14] Updated Clans to use the new ResourcePackManager.setResourcePack method. --- .../src/mineplex/game/clans/Clans.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java index 8385bc856..de9a0c8c3 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java @@ -14,6 +14,8 @@ import mineplex.core.antihack.AntiHack; import mineplex.core.blockrestore.BlockRestore; import mineplex.core.chat.Chat; import mineplex.core.command.CommandCenter; +import mineplex.core.common.MinecraftVersion; +import mineplex.core.common.Pair; import mineplex.core.common.events.ServerShutdownEvent; import mineplex.core.delayedtask.DelayedTask; import mineplex.core.donation.DonationManager; @@ -130,7 +132,11 @@ public class Clans extends JavaPlugin new Explosion(this, blockRestore); new InventoryManager(this, _clientManager); ResourcePackManager resourcePackManager = new ResourcePackManager(this, portal); - resourcePackManager.setResourcePack("http://phinary.ca/ResClans.zip", "http://phinary.ca/ResClans19.zip", true); + resourcePackManager.setResourcePack(new Pair[] + { + Pair.create(MinecraftVersion.Version1_8, "http://phinary.ca/ResClans.zip"), + Pair.create(MinecraftVersion.Version1_9, "http://phinary.ca/ResClans19.zip") + }, true); // Enable custom-gear related managers new CustomTagFix(this, packetHandler); From a91ef68978edbe971194aea1579dd4ba83e549f4 Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Mon, 4 Apr 2016 13:46:39 -0500 Subject: [PATCH 12/14] Fixed CCM in WarPointEvasion. Removed debug message; NOT RIDER --- .../clans/clans/siege/weapon/SiegeWeapon.java | 1 - .../clans/warpoints/WarPointEvasion.java | 73 +++++++++++++------ 2 files changed, 49 insertions(+), 25 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java index 472363459..11520d2dc 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java @@ -758,7 +758,6 @@ public abstract class SiegeWeapon implements Listener { if (!event.getPlayer().equals(_rider)) { - System.out.println("NOT RIDER"); return; } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/warpoints/WarPointEvasion.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/warpoints/WarPointEvasion.java index e3f066e3c..dee5e2ac6 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/warpoints/WarPointEvasion.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/warpoints/WarPointEvasion.java @@ -3,8 +3,6 @@ package mineplex.game.clans.clans.warpoints; import com.google.common.collect.Maps; import mineplex.core.MiniPlugin; import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilPlayer; -import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTime; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; @@ -12,75 +10,102 @@ import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.event.*; import org.bukkit.Bukkit; import org.bukkit.Chunk; -import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.plugin.java.JavaPlugin; import java.util.HashMap; +import java.util.Iterator; import java.util.UUID; -public class WarPointEvasion extends MiniPlugin{ +public class WarPointEvasion extends MiniPlugin +{ private HashMap _chunkCooldown; private HashMap _playerCooldown; private final long COOLDOWN_TIME = 1000 * 60 * 10; - public WarPointEvasion(JavaPlugin plugin) { + public WarPointEvasion(JavaPlugin plugin) + { super("WP Evasion", plugin); + _chunkCooldown = Maps.newHashMap(); _playerCooldown = Maps.newHashMap(); } @EventHandler - public void updateCooldown(UpdateEvent event) { + public void updateCooldown(UpdateEvent event) + { if(!event.getType().equals(UpdateType.SEC)) return; - _chunkCooldown.keySet().stream().filter(chunk -> UtilTime.elapsed(_chunkCooldown.get(chunk), COOLDOWN_TIME)).forEach(chunk -> _chunkCooldown.remove(chunk)); + for (Iterator chunkIterator = _chunkCooldown.keySet().iterator(); chunkIterator.hasNext();) + { + Chunk chunk = chunkIterator.next(); + + if (UtilTime.elapsed(_chunkCooldown.get(chunk), COOLDOWN_TIME)) + chunkIterator.remove(); + } - _playerCooldown.keySet().stream().filter(player -> UtilTime.elapsed(_playerCooldown.get(player), COOLDOWN_TIME)).forEach(player -> { - _playerCooldown.remove(player); - if(Bukkit.getOfflinePlayer(player).isOnline()) { - if(ClansManager.getInstance().getClan(Bukkit.getPlayer(player)) == null) { - Bukkit.getPlayer(player).sendMessage(F.main("Clans", "You can now create a clan.")); + + for (Iterator uuidIterator = _playerCooldown.keySet().iterator(); uuidIterator.hasNext();) + { + UUID uuid = uuidIterator.next(); + + if (UtilTime.elapsed(_playerCooldown.get(uuid), COOLDOWN_TIME)) + { + uuidIterator.remove(); + + Player player = Bukkit.getPlayer(uuid); + if (player.isOnline()) + { + if(ClansManager.getInstance().getClan(player) == null) + { + player.sendMessage(F.main("Clans", "You can now create a clan.")); + } } - } - }); + } + } } @EventHandler - public void onClaim(PlayerPreClaimTerritoryEvent event) { + public void onClaim(PlayerPreClaimTerritoryEvent event) + { Chunk chunk = event.getClaimedChunk(); - if(_chunkCooldown.containsKey(chunk)) { + + if(_chunkCooldown.containsKey(chunk)) + { event.setCancelled(true); event.getClaimer().sendMessage(F.main("Clans", "You cannot claim this chunk for another " + UtilTime.convertString(COOLDOWN_TIME - (System.currentTimeMillis() - _chunkCooldown.get(chunk)), 1, UtilTime.TimeUnit.MINUTES))); } } @EventHandler - public void onunClaim(PlayerUnClaimTerritoryEvent event) { - Chunk chunk = event.getUnClaimedChunk(); - _chunkCooldown.put(chunk, System.currentTimeMillis()); - + public void onunClaim(PlayerUnClaimTerritoryEvent event) + { + _chunkCooldown.put(event.getUnClaimedChunk(), System.currentTimeMillis()); } @EventHandler - public void onClanDisband(ClanDisbandedEvent event) { + public void onClanDisband(ClanDisbandedEvent event) + { _playerCooldown.put(event.getDisbander().getUniqueId(), System.currentTimeMillis()); } @EventHandler - public void onClanLeave(ClanLeaveEvent event) { + public void onClanLeave(ClanLeaveEvent event) + { _playerCooldown.put(event.getPlayer().getUuid(), System.currentTimeMillis()); } @EventHandler - public void onClanCreate(ClanCreatedEvent event) { + public void onClanCreate(ClanCreatedEvent event) + { if (event.getFounder() == null) return; - if (_playerCooldown.containsKey(event.getFounder().getUniqueId())) { + if (_playerCooldown.containsKey(event.getFounder().getUniqueId())) + { event.setCancelled(true); event.getFounder().sendMessage(F.main("Clans", "You cannot create a clan for another " + UtilTime.convertString(COOLDOWN_TIME - (System.currentTimeMillis() - _playerCooldown.get(event.getFounder().getUniqueId())), 1, UtilTime.TimeUnit.MINUTES))); } From 60010f90b466065596fd14b6a913f1c782ee7d08 Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Mon, 4 Apr 2016 13:47:45 -0500 Subject: [PATCH 13/14] Load simple clan token on player login to reduce overhead. Increased dbpool connections to 4 --- .../mineplex/hub/server/ServerManager.java | 45 ++++++++++++++----- .../server/ui/clans/ClanMoveServerShop.java | 1 - .../hub/server/ui/clans/ClansServerPage.java | 41 ++++------------- .../hub/server/ui/clans/ClansServerShop.java | 2 +- .../mineplex/serverdata/database/DBPool.java | 4 +- .../serverdata/database/RepositoryBase.java | 2 +- 6 files changed, 47 insertions(+), 48 deletions(-) diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java index d6a21481f..6e07ae2b3 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java @@ -1,5 +1,7 @@ package mineplex.hub.server; +import java.sql.ResultSet; +import java.sql.SQLException; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -26,7 +28,7 @@ import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; -import mineplex.core.MiniPlugin; +import mineplex.core.MiniDbClientPlugin; import mineplex.core.account.CoreClientManager; import mineplex.core.common.Rank; import mineplex.core.common.util.C; @@ -48,10 +50,10 @@ import mineplex.core.shop.ShopBase; import mineplex.core.status.ServerStatusManager; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; +import mineplex.game.clans.core.repository.tokens.SimpleClanToken; import mineplex.hub.HubManager; import mineplex.hub.modules.StackerManager; import mineplex.hub.queue.QueueManager; -import mineplex.hub.queue.ui.QueueShop; import mineplex.hub.server.ui.LobbyShop; import mineplex.hub.server.ui.QuickShop; import mineplex.hub.server.ui.ServerCountSorter; @@ -61,7 +63,7 @@ import mineplex.serverdata.Region; import mineplex.serverdata.data.MinecraftServer; import mineplex.serverdata.data.ServerGroup; -public class ServerManager extends MiniPlugin +public class ServerManager extends MiniDbClientPlugin { private static final Long FREE_PORTAL_TIMER = 20000L; private static final Long BETA_PORTAL_TIMER = 120000L; @@ -77,8 +79,6 @@ public class ServerManager extends MiniPlugin private PartyManager _partyManager; private ServerStatusManager _statusManager; private HubManager _hubManager; - private StackerManager _stackerManager; - private QueueManager _queueManager; private NautHashMap _queueCooldowns = new NautHashMap(); private NautHashMap> _serverKeyInfoMap = new NautHashMap>(); @@ -93,7 +93,6 @@ public class ServerManager extends MiniPlugin // Join Time for Free Players Timer private NautHashMap _joinTime = new NautHashMap(); - private QueueShop _domShop; private QuickShop _quickShop; private LobbyShop _lobbyShop; @@ -103,7 +102,7 @@ public class ServerManager extends MiniPlugin public ServerManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, Portal portal, PartyManager partyManager, ServerStatusManager statusManager, HubManager hubManager, StackerManager stackerManager, QueueManager queueManager) { - super("Server Manager", plugin); + super("Server Manager", plugin, clientManager); _clientManager = clientManager; _donationManager = donationManager; @@ -111,8 +110,6 @@ public class ServerManager extends MiniPlugin _partyManager = partyManager; _statusManager = statusManager; _hubManager = hubManager; - _stackerManager = stackerManager; - _queueManager = queueManager; plugin.getServer().getMessenger().registerOutgoingPluginChannel(plugin, "BungeeCord"); @@ -120,7 +117,6 @@ public class ServerManager extends MiniPlugin _quickShop = new QuickShop(this, clientManager, donationManager, "Quick Menu"); _lobbyShop = new LobbyShop(this, clientManager, donationManager, "Lobby Menu"); - //_domShop = new new QueueShop(_queueManager, clientManager, donationManager, "Dominate"); // TODO: Find more appropriate place to initialize Clans server shop? _clansShop = new ClansServerShop(this, _clientManager, _donationManager); @@ -918,4 +914,33 @@ public class ServerManager extends MiniPlugin { return _serverNpcShopMap.get("Valentines Vendetta"); } + + @Override + public String getQuery(int accountId, String uuid, String name) + { + return "SELECT clans.name, accountClan.clanRole, clanServer.serverName, clans.id FROM accountClan INNER JOIN clans ON clans.id = accountClan.clanId INNER JOIN clanServer ON clans.serverId = clanServer.id WHERE accountClan.accountId = " + accountId + "?;"; + } + + @Override + public void processLoginResultSet(String playerName, int accountId, ResultSet resultSet) throws SQLException + { + SimpleClanToken clanToken = new SimpleClanToken(); + + while (resultSet.next()) + { + String clanName = resultSet.getString(1); + String clanRole = resultSet.getString(2); + String homeServer = resultSet.getString(3); + int clanId = resultSet.getInt(4); + clanToken = new SimpleClanToken(clanName, clanRole, homeServer, clanId); + } + + Set(playerName, clanToken); + } + + @Override + protected SimpleClanToken AddPlayer(String player) + { + return new SimpleClanToken(); + } } 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 d8fb30e91..e85528ee8 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 @@ -4,7 +4,6 @@ import org.bukkit.Sound; import org.bukkit.entity.Player; import mineplex.core.account.CoreClientManager; -import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.donation.DonationManager; import mineplex.core.party.Party; diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClansServerPage.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClansServerPage.java index d597dbc82..fe5ceaeea 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClansServerPage.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClansServerPage.java @@ -27,16 +27,10 @@ import mineplex.serverdata.data.DataRepository; public class ClansServerPage extends ShopPageBase { - private ClanRepository _repository; - private int _accountId; - public ClansServerPage(ServerManager plugin, ClansServerShop shop, CoreClientManager clientManager, - DonationManager donationManager, Player player, ClanRepository repository) + DonationManager donationManager, Player player) { super(plugin, shop, clientManager, donationManager, "Clans Beta", player, 54); - - _repository = repository; - _accountId = clientManager.getAccountId(player); buildPage(); } @@ -44,33 +38,14 @@ public class ClansServerPage extends ShopPageBase() - { - @Override - public void run(SimpleClanToken data) - { - getPlugin().runSync(new Runnable() - { - public void run() - { - if (data != null) - { - buildClanPage(data); - } - else - { - buildNoClanPage(); - } - } - }); - } - }); - } - }); + buildClanPage(getPlugin().Get(_player)); + } + else + { + buildNoClanPage(); + } } private void buildClanPage(SimpleClanToken clan) 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 b74a37acd..f5590b095 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 @@ -26,7 +26,7 @@ public class ClansServerShop extends ShopBase @Override protected ShopPageBase> buildPagesFor(Player player) { - return new ClansServerPage(getPlugin(), this, getClientManager(), getDonationManager(), player, _repository); + return new ClansServerPage(getPlugin(), this, getClientManager(), getDonationManager(), player); } @Override diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/DBPool.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/DBPool.java index f69fabe62..4a01218f1 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/DBPool.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/DBPool.java @@ -29,8 +29,8 @@ public final class DBPool source.setUrl(url); source.setUsername(username); source.setPassword(password); - source.setMaxTotal(3); - source.setMaxIdle(3); + source.setMaxTotal(4); + source.setMaxIdle(4); source.setTimeBetweenEvictionRunsMillis(180 * 1000); source.setSoftMinEvictableIdleTimeMillis(180 * 1000); diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/RepositoryBase.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/RepositoryBase.java index e4b2d688c..28650bc01 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/RepositoryBase.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/RepositoryBase.java @@ -143,7 +143,7 @@ public abstract class RepositoryBase } protected void executeQuery(String query, ResultSetCallable callable, Column...columns) - { + { // Automatic resource management for handling/closing objects. try ( Connection connection = getConnection(); From 02459c6a10214ca06c65c7de667e5915c5053ef3 Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Mon, 4 Apr 2016 13:48:26 -0500 Subject: [PATCH 14/14] Fixed bad implementation of IncognitoManager that was locking up threads. Temporarily disabled MessageManager's handling of Incognito. --- .../core/incognito/IncognitoManager.java | 41 ++++++++++----- .../repository/IncognitoRepository.java | 51 ++----------------- .../mineplex/core/message/MessageManager.java | 3 ++ .../repository/tokens/SimpleClanToken.java | 4 +- 4 files changed, 37 insertions(+), 62 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/incognito/IncognitoManager.java b/Plugins/Mineplex.Core/src/mineplex/core/incognito/IncognitoManager.java index 664415263..db73b3b55 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/incognito/IncognitoManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/incognito/IncognitoManager.java @@ -1,5 +1,8 @@ package mineplex.core.incognito; +import java.sql.ResultSet; +import java.sql.SQLException; + import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -10,6 +13,7 @@ import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.MiniClientPlugin; +import mineplex.core.MiniDbClientPlugin; import mineplex.core.account.CoreClientManager; import mineplex.core.common.util.C; import mineplex.core.common.util.F; @@ -23,7 +27,7 @@ import mineplex.core.packethandler.PacketHandler; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; -public class IncognitoManager extends MiniClientPlugin +public class IncognitoManager extends MiniDbClientPlugin { private CoreClientManager _clientManager; private IncognitoRepository _repository; @@ -32,9 +36,9 @@ public class IncognitoManager extends MiniClientPlugin public IncognitoManager(JavaPlugin plugin, CoreClientManager clientManager, PacketHandler packetHandler) { - super("Incognito", plugin); + super("Incognito", plugin, clientManager); - _repository = new IncognitoRepository(this, clientManager); + _repository = new IncognitoRepository(this); _clientManager = clientManager; Instance = this; @@ -66,7 +70,7 @@ public class IncognitoManager extends MiniClientPlugin } } - runAsync(() -> _repository.SetStatus(_clientManager.getAccountId(caller), enabled)); + runAsync(() -> _repository.setStatus(_clientManager.getAccountId(caller), enabled)); return enabled; } @@ -76,8 +80,10 @@ public class IncognitoManager extends MiniClientPlugin { if (event.getType() != UpdateType.FAST) { - UtilServer.getPlayersCollection().forEach(player -> { - UtilServer.getPlayersCollection().forEach(other -> { + UtilServer.getPlayersCollection().forEach(player -> + { + UtilServer.getPlayersCollection().forEach(other -> + { if (Get(other).Status && !_clientManager.hasRank(player, _clientManager.Get(other).GetRank())) player.hidePlayer(other); @@ -91,14 +97,6 @@ public class IncognitoManager extends MiniClientPlugin } } - @EventHandler(priority = EventPriority.LOWEST) - public void ClientLoad(AsyncPlayerPreLoginEvent event) - { - _clientManager.getRepository().getAccountId(event.getUniqueId(), accountId -> { - Get(event.getName()).Status = _repository.GetStatus(accountId.intValue()); - }); - } - @EventHandler(priority = EventPriority.HIGHEST) public void Join(PlayerJoinEvent event) { @@ -155,4 +153,19 @@ public class IncognitoManager extends MiniClientPlugin { return _repository; } + + @Override + public String getQuery(int accountId, String uuid, String name) + { + return "SELECT * FROM incognitoStaff WHERE accountId = " + accountId + ";"; + } + + @Override + public void processLoginResultSet(String playerName, int accountId, ResultSet resultSet) throws SQLException + { + while (resultSet.next()) + { + Get(playerName).Status = resultSet.getInt("status") == 1; + } + } } \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/incognito/repository/IncognitoRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/incognito/repository/IncognitoRepository.java index 1032eb809..21f03b062 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/incognito/repository/IncognitoRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/incognito/repository/IncognitoRepository.java @@ -1,8 +1,5 @@ package mineplex.core.incognito.repository; -import mineplex.core.account.CoreClientManager; -import mineplex.core.common.util.EnclosedObject; -import mineplex.core.common.util.UUIDFetcher; import mineplex.core.database.MinecraftRepository; import mineplex.core.incognito.IncognitoManager; import mineplex.serverdata.database.DBPool; @@ -11,57 +8,18 @@ import mineplex.serverdata.database.column.ColumnInt; public class IncognitoRepository extends MinecraftRepository { private static final String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS incognitoStaff (accountId INT NOT NULL, status TINYINT(1) DEFAULT '0', PRIMARY KEY (accountId));"; - private static final String GET_STATUS = "SELECT * FROM incognitoStaff WHERE accountId = ?;"; private static final String INSERT_STATUS = "INSERT INTO incognitoStaff (accountId, status) VALUES (?, ?);"; private static final String UPDATE_STATUS = "UPDATE incognitoStaff SET status=? WHERE accountId=?;"; - private IncognitoManager _incognitoManager; - - private CoreClientManager _clientManager; - - public IncognitoRepository(IncognitoManager incognitoManager, CoreClientManager clientManager) + public IncognitoRepository(IncognitoManager incognitoManager) { super(incognitoManager.getPlugin(), DBPool.getAccount()); - - _clientManager = clientManager; - - _incognitoManager = incognitoManager; } - public void SetStatus(int accountId, boolean status) + public void setStatus(int accountId, boolean status) { - // Prevent duplicate entries for individuals - executeQuery(GET_STATUS, result -> { - if (result.next()) - executeUpdate(UPDATE_STATUS, new ColumnInt("status", status ? 1 : 0), new ColumnInt("accountId", accountId)); - else - executeUpdate(INSERT_STATUS, new ColumnInt("accountId", accountId), new ColumnInt("status", status ? 1 : 0)); - }, new ColumnInt("accountId", accountId)); - } - - public boolean GetStatus(int accountId) - { - EnclosedObject status = new EnclosedObject<>(); - - executeQuery(GET_STATUS, result -> { - if (result.next()) - status.Set(result.getInt("status") == 1 ? Boolean.TRUE : Boolean.FALSE); - else - status.Set(Boolean.FALSE); - }, new ColumnInt("accountId", accountId)); - - return status.Get().booleanValue(); - } - - public boolean GetStatus(String name) - { - EnclosedObject accountId = new EnclosedObject<>(); - - _clientManager.getRepository().getAccountId(UUIDFetcher.getUUIDOf(name), id -> - accountId.Set(id) - ); - - return GetStatus(accountId.Get().intValue()); + if (executeUpdate(UPDATE_STATUS, new ColumnInt("accountId", accountId)) <= 0) + executeInsert(INSERT_STATUS, null, new ColumnInt("accountId", accountId), new ColumnInt("status", status ? 1 : 0)); } protected void initialize() @@ -72,5 +30,4 @@ public class IncognitoRepository extends MinecraftRepository protected void update() { } - } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/message/MessageManager.java b/Plugins/Mineplex.Core/src/mineplex/core/message/MessageManager.java index 774a65138..8e1790063 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/message/MessageManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/message/MessageManager.java @@ -553,11 +553,14 @@ public class MessageManager extends MiniClientPlugin @Override public void run() { + // TODO Newgarbo wrote this stuff inefficiently and for sake of time and thousands of players i'm going to just comment this out + /* if (IncognitoManager.Instance.getRepository().GetStatus(playerTarget)) { UtilPlayer.message(sender, F.main("Online Player Search", F.elem("0") + " matches for [" + F.elem(target) + "].")); return; } + */ runSync(new Runnable() { diff --git a/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/tokens/SimpleClanToken.java b/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/tokens/SimpleClanToken.java index 70757bd98..e7fd13ca0 100644 --- a/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/tokens/SimpleClanToken.java +++ b/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/tokens/SimpleClanToken.java @@ -3,7 +3,7 @@ package mineplex.game.clans.core.repository.tokens; public class SimpleClanToken { - private String _clanName; + private String _clanName = ""; public String getClanName() { return _clanName; } private String _clanRole; @@ -22,4 +22,6 @@ public class SimpleClanToken _homeServer = homeServer; _clanId = clanId; } + + public SimpleClanToken() { } }