Implementing BONUS: Clickable Chat Links.
This commit is contained in:
parent
3636255e8a
commit
d9110b4e3b
@ -30,9 +30,11 @@ public class HubRepository
|
|||||||
private static String RETRIEVE_NEWS_ENTRIES = "SELECT newsString, newsPosition FROM newsList;";
|
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 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 = "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 SET_NEWS_ENTRY = "UPDATE newsList SET newsString = ? WHERE newsPosition = ?;";
|
||||||
private static String DELETE_NEWS_ENTRY = "DELETE FROM newsList 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 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;
|
private Connection _connection = null;
|
||||||
|
|
||||||
@ -279,6 +281,7 @@ public class HubRepository
|
|||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//preparedStatement = _connection.prepareStatement(DELETE_RECALC_NEWS_ENTRY);
|
||||||
preparedStatement = _connection.prepareStatement(DELETE_NEWS_ENTRY);
|
preparedStatement = _connection.prepareStatement(DELETE_NEWS_ENTRY);
|
||||||
preparedStatement.setInt(1, newsPosition);
|
preparedStatement.setInt(1, newsPosition);
|
||||||
result = preparedStatement.executeUpdate();
|
result = preparedStatement.executeUpdate();
|
||||||
|
@ -11,6 +11,7 @@ import mineplex.core.common.util.C;
|
|||||||
import mineplex.core.common.util.Callback;
|
import mineplex.core.common.util.Callback;
|
||||||
import mineplex.core.common.util.F;
|
import mineplex.core.common.util.F;
|
||||||
import mineplex.core.common.util.UtilPlayer;
|
import mineplex.core.common.util.UtilPlayer;
|
||||||
|
import mineplex.core.common.util.UtilServer;
|
||||||
import mineplex.hub.HubManager;
|
import mineplex.hub.HubManager;
|
||||||
import mineplex.hub.modules.NewsManager;
|
import mineplex.hub.modules.NewsManager;
|
||||||
|
|
||||||
@ -35,8 +36,8 @@ public class NewsCommand extends CommandBase<HubManager>
|
|||||||
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cWhite + "news add <newsEntry>" + C.cGray + " - Adds specified news entry string to database at end of table."));
|
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cWhite + "news add <newsEntry>" + 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 delete #" + C.cGray + " - Removes specified (numbered) news entry string from database."));
|
||||||
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cWhite + "news set # <newsEntry>" + C.cGray + " - Updates specified (numbered) news entry string in database."));
|
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cWhite + "news set # <newsEntry>" + 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!"));
|
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;
|
return;
|
||||||
}
|
}
|
||||||
else if (args.length == 1 && args[0].equalsIgnoreCase("list"))
|
else if (args.length == 1 && args[0].equalsIgnoreCase("list"))
|
||||||
{
|
{
|
||||||
@ -56,12 +57,11 @@ public class NewsCommand extends CommandBase<HubManager>
|
|||||||
{
|
{
|
||||||
String newsPosition = iterator.next();
|
String newsPosition = iterator.next();
|
||||||
newsStrings[Integer.parseInt(newsPosition) - 1] = newsEntries.get(newsPosition);
|
newsStrings[Integer.parseInt(newsPosition) - 1] = newsEntries.get(newsPosition);
|
||||||
//iterator.remove();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < newsStrings.length; i++)
|
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)
|
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;
|
final int newsPosition;
|
||||||
try
|
try
|
||||||
|
Loading…
Reference in New Issue
Block a user