Implementing BONUS: Clickable Chat Links.

This commit is contained in:
Peter Miller 2014-07-15 22:31:53 -04:00
parent 3636255e8a
commit d9110b4e3b
2 changed files with 24 additions and 5 deletions

View File

@ -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();

View File

@ -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;
@ -56,12 +57,11 @@ public class NewsCommand extends CommandBase<HubManager>
{
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<HubManager>
}
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