From d9110b4e3b505fd3b726e0cf593f37601bc927f7 Mon Sep 17 00:00:00 2001 From: Peter Miller Date: Tue, 15 Jul 2014 22:31:53 -0400 Subject: [PATCH] Implementing BONUS: Clickable Chat Links. --- .../src/mineplex/hub/HubRepository.java | 3 +++ .../mineplex/hub/commands/NewsCommand.java | 26 +++++++++++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/HubRepository.java b/Plugins/Mineplex.Hub/src/mineplex/hub/HubRepository.java index 80e9c0501..e8dffc1b3 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/HubRepository.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/HubRepository.java @@ -30,9 +30,11 @@ public class HubRepository private static String RETRIEVE_NEWS_ENTRIES = "SELECT newsString, newsPosition FROM newsList;"; private static String RETRIEVE_MAX_NEWS_POSITION = "SELECT MAX(newsPosition) AS newsPosition FROM newsList;"; private static String ADD_NEWS_ENTRY = "INSERT INTO newsList (newsString, newsPosition) VALUES(?,?);"; + //private static String ADD_NEWS_ENTRY = "SET @max = (SELECT MAX(newsPosition) AS newsPosition FROM newsList);INSERT INTO newsList (newsString, newsPosition) VALUES(?,@max + 1);"; private static String SET_NEWS_ENTRY = "UPDATE newsList SET newsString = ? WHERE newsPosition = ?;"; private static String DELETE_NEWS_ENTRY = "DELETE FROM newsList WHERE newsPosition = ?;"; private static String RECALC_NEWS_POSITIONS = "UPDATE newsList SET newsPosition = newsPosition - 1 WHERE newsPosition > ?;"; + //private static String DELETE_RECALC_NEWS_ENTRY = "SET @pos = ?;SET @max = (SELECT MAX(newsPosition) AS newsPosition FROM newsList);DELETE FROM newsList WHERE newsPosition = @pos;UPDATE newsList SET newsPosition = IF(@max <> @pos, newsPosition - 1, newsPosition) WHERE newsPosition > @pos;"; private Connection _connection = null; @@ -279,6 +281,7 @@ public class HubRepository _connection = DriverManager.getConnection(_connectionString, _userName, _password); } + //preparedStatement = _connection.prepareStatement(DELETE_RECALC_NEWS_ENTRY); preparedStatement = _connection.prepareStatement(DELETE_NEWS_ENTRY); preparedStatement.setInt(1, newsPosition); result = preparedStatement.executeUpdate(); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsCommand.java b/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsCommand.java index f8084f3ab..7be9a8dee 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsCommand.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsCommand.java @@ -11,6 +11,7 @@ import mineplex.core.common.util.C; import mineplex.core.common.util.Callback; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; import mineplex.hub.HubManager; import mineplex.hub.modules.NewsManager; @@ -35,8 +36,8 @@ public class NewsCommand extends CommandBase UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cWhite + "news add " + C.cGray + " - Adds specified news entry string to database at end of table.")); UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cWhite + "news delete #" + C.cGray + " - Removes specified (numbered) news entry string from database.")); UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cWhite + "news set # " + C.cGray + " - Updates specified (numbered) news entry string in database.")); - UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cWhite + "*Please Note: " + C.cGray + "Updates to server news entries from the database are on a 4 minute refresh cycle!")); - return; + UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cWhite + "*Please Note: " + C.cGray + "Updates to server news entries from the database are on a 4 minute refresh cycle!")); + return; } else if (args.length == 1 && args[0].equalsIgnoreCase("list")) { @@ -56,12 +57,11 @@ public class NewsCommand extends CommandBase { String newsPosition = iterator.next(); newsStrings[Integer.parseInt(newsPosition) - 1] = newsEntries.get(newsPosition); - //iterator.remove(); } for (int i = 0; i < newsStrings.length; i++) { - UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cGold + "News " + (i + 1) + C.cGray + " : " + newsStrings[i])); + UtilServer.getServer().dispatchCommand(UtilServer.getServer().getConsoleSender(), "tellraw " + caller.getName() + " {\"text\":\"" + Plugin.GetName() + "> \", color:blue, \"extra\":[{\"text\":\"[DELETE] \", color:red, \"clickEvent\":{\"action\":\"run_command\",\"value\":\"/news ¢¤₦₣¡₨₥ " + (i + 1) + "\"}}, {\"text\":\"News " + (i + 1) + "\", color:gold}, {\"text\":\" : \", color:gray}, {\"text\":\"" + newsStrings[i] + "\", color:white}]}"); } } }); @@ -71,7 +71,23 @@ public class NewsCommand extends CommandBase } else if (args.length >= 2 && args.length <= 128) { - if (args[0].equalsIgnoreCase("delete") && args.length == 2) + if (args[0].equals("¢¤₦₣¡₨₥") && args.length == 2) + { + int newsPosition; + try + { + newsPosition = Integer.parseInt(args[1]); + } + catch (Exception exception) + { + UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "The specified news position is invalid!")); + return; + } + + UtilServer.getServer().dispatchCommand(UtilServer.getServer().getConsoleSender(), "tellraw " + caller.getName() + " {\"text\":\"" + Plugin.GetName() + "> \", color:blue, \"extra\":[{\"text\":\"[CONFIRM] \", color:green, \"clickEvent\":{\"action\":\"run_command\",\"value\":\"/news delete " + newsPosition + "\"}}, {\"text\":\"News Entry " + newsPosition + "\", color:gold}, {\"text\":\" deletion?\", color:gray}]}"); + return; + } + else if (args[0].equalsIgnoreCase("delete") && args.length == 2) { final int newsPosition; try