From 03c56535efc5acd9a6a575d9130094cf4c8e693a Mon Sep 17 00:00:00 2001 From: Mini-Chiss Date: Tue, 8 Jul 2014 18:08:37 -0700 Subject: [PATCH 1/2] MAPDATA --- .../src/mineplex/mapparser/MapData.java | 137 ++++++++++++++++++ .../src/mineplex/mapparser/MapParser.java | 14 +- 2 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapData.java diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapData.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapData.java new file mode 100644 index 000000000..5adea1189 --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapData.java @@ -0,0 +1,137 @@ +package mineplex.mapparser; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; +import java.util.HashSet; + +import org.bukkit.entity.Player; + +public class MapData +{ + public String MapFolder; + + public String GameType = "null"; + public String MapName = "null"; + public String MapCreator = "null"; + + public HashSet WhiteList; + public HashSet BuildList; + + public MapData(String mapFolder) + { + MapFolder = mapFolder; + + WhiteList = new HashSet(); + BuildList = new HashSet(); + + if ((new File(MapFolder + File.separator + "Map.dat")).exists()) + Read(); + else + Write(); + } + + public void Read() + { + String line = null; + + try + { + FileInputStream fstream = new FileInputStream(MapFolder + File.separator + "Map.dat"); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + + while ((line = br.readLine()) != null) + { + String[] tokens = line.split(":"); + + if (tokens.length < 2) + continue; + + if (tokens[0].length() == 0) + continue; + + //Name & Author + if (tokens[0].equalsIgnoreCase("MAP_NAME")) + { + MapName = tokens[1]; + } + else if (tokens[0].equalsIgnoreCase("MAP_AUTHOR")) + { + MapCreator = tokens[1]; + } + else if (tokens[0].equalsIgnoreCase("GAME_TYPE")) + { + GameType = tokens[1]; + } + else if (tokens[0].equalsIgnoreCase("WHITE_LIST")) + { + for (String cur : tokens[1].split(",")) + WhiteList.add(cur); + } + else if (tokens[0].equalsIgnoreCase("BUILD_LIST")) + { + for (String cur : tokens[1].split(",")) + BuildList.add(cur); + } + } + + in.close(); + } + catch (Exception e) + { + e.printStackTrace(); + System.err.println("Line: " + line); + } + } + + public void Write() + { + //Save + try + { + FileWriter fstream = new FileWriter(MapFolder + File.separator + "Map.dat"); + BufferedWriter out = new BufferedWriter(fstream); + + out.write("MAP_NAME:"+MapName); + out.write("\n"); + out.write("MAP_AUTHOR:"+MapCreator); + out.write("\n"); + out.write("GAME_TYPE:"+GameType); + + String whiteList = ""; + for (String cur : WhiteList) + whiteList += cur + ","; + + out.write("\n"); + out.write("WHITE_LIST:"+whiteList); + + String buildList = ""; + for (String cur : BuildList) + buildList += cur + ","; + + out.write("\n"); + out.write("BUILD_LIST:"+buildList); + + out.close(); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + public boolean CanBuild(Player player) + { + return BuildList.contains(player.getName()) || player.isOp(); + } + + public boolean CanJoin(Player player) + { + return BuildList.contains(player.getName()) || WhiteList.contains(player.getName()) || player.isOp(); + } +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java index 68f3b2d49..52ebf475f 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java @@ -92,6 +92,8 @@ public class MapParser extends JavaPlugin implements Listener UtilPlayer.message(player, F.value("/name ", "Set name for current map")); UtilPlayer.message(player, F.value("/author ", "Set author for current map")); UtilPlayer.message(player, F.value("/gametype Date: Tue, 8 Jul 2014 22:55:51 -0400 Subject: [PATCH 2/2] Initial database access and method stubbing for "news" command. --- .../simpleStats/SimpleStatsRepository.java | 2 +- .../src/mineplex/hub/HubManager.java | 10 ++- .../src/mineplex/hub/HubRepository.java | 71 +++++++++++++++++++ .../mineplex/hub/commands/NewsCommand.java | 46 ++++++++++++ .../src/mineplex/hub/modules/NewsManager.java | 5 ++ 5 files changed, 132 insertions(+), 2 deletions(-) create mode 100644 Plugins/Mineplex.Hub/src/mineplex/hub/HubRepository.java create mode 100644 Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsCommand.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/simpleStats/SimpleStatsRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/simpleStats/SimpleStatsRepository.java index bcc091054..a5001c3fd 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/simpleStats/SimpleStatsRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/simpleStats/SimpleStatsRepository.java @@ -12,7 +12,7 @@ public class SimpleStatsRepository { private static Object _connectionLock = new Object(); - private String _connectionString = "jdbc:mysql://sqlstats.mineplex.com:3306/Queue?autoReconnect=true&failOverReadOnly=false&maxReconnects=10"; + private String _connectionString = "jdbc:mysql://sqlstats.mineplex.com:3306/Mineplex?autoReconnect=true&failOverReadOnly=false&maxReconnects=10"; private String _userName = "root"; private String _password = "tAbechAk3wR7tuTh"; //try to obfuscate this in the future! diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java index 1fce65064..eb64e79dd 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java @@ -63,6 +63,7 @@ import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.hub.commands.ForcefieldRadius; import mineplex.hub.commands.GadgetToggle; +import mineplex.hub.commands.NewsCommand; import mineplex.hub.gadget.GadgetManager; import mineplex.hub.modules.*; import mineplex.hub.mount.MountManager; @@ -94,6 +95,7 @@ public class HubManager extends MiniClientPlugin private TextManager _textCreator; private ParkourManager _parkour; private PreferencesManager _preferences; + private NewsManager _news; private Location _spawn; private int _scoreboardTick = 0; @@ -129,8 +131,8 @@ public class HubManager extends MiniClientPlugin new MapManager(this); new WorldManager(this); new JumpManager(this); - new NewsManager(this); + _news = new NewsManager(this); _mountManager = new MountManager(this); _gadgetManager = new GadgetManager(this, _mountManager, petManager); @@ -152,6 +154,7 @@ public class HubManager extends MiniClientPlugin public void AddCommands() { AddCommand(new GadgetToggle(this)); + AddCommand(new NewsCommand(this)); } @EventHandler(priority = EventPriority.HIGHEST) @@ -756,6 +759,11 @@ public class HubManager extends MiniClientPlugin { this._gadgetsEnabled = _enabled; } + + public NewsManager GetNewsManager() + { + return _news; + } @Override protected void loadClientInformation(RetrieveClientInformationEvent event) diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/HubRepository.java b/Plugins/Mineplex.Hub/src/mineplex/hub/HubRepository.java new file mode 100644 index 000000000..a24ba804d --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/HubRepository.java @@ -0,0 +1,71 @@ +package mineplex.hub; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.List; + +import mineplex.core.common.util.NautHashMap; +import mineplex.core.status.ServerStatusData; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +public class HubRepository +{ + private static Object _connectionLock = new Object(); + + private String _connectionString = "jdbc:mysql://db.mineplex.com:3306/Mineplex?autoReconnect=true&failOverReadOnly=false&maxReconnects=10"; + private String _userName = "root"; + private String _password = "tAbechAk3wR7tuTh"; + + private boolean _us = true; + + private static String CREATE_NEWS_TABLE = "CREATE TABLE IF NOT EXISTS newsList (id INT NOT NULL AUTO_INCREMENT, newsString VARCHAR(256), newsPosition INT, PRIMARY KEY (id));"; + private static String RETRIEVE_NEWS_ENTRIES = "SELECT newsString, newsPosition FROM newsList;"; + private static String ADD_NEWS_ENTRY = "INSERT INTO newsList (newsString, newsPosition) VALUES(?,?);"; + private static String SET_NEWS_ENTRY = "UPDATE newsList SET newsString = ? WHERE newsPosition = ?;"; + private static String DELETE_NEWS_ENTRY = "DELETE FROM newsList WHERE newsPosition = ?;"; + + private Connection _connection = null; + + public void initialize(boolean us) + { + _us = us; + + PreparedStatement preparedStatement = null; + + try + { + Class.forName("com.mysql.jdbc.Driver"); + + _connection = DriverManager.getConnection(_connectionString, _userName, _password); + + // Create table + preparedStatement = _connection.prepareStatement(CREATE_NEWS_TABLE); + preparedStatement.execute(); + } + catch (Exception exception) + { + exception.printStackTrace(); + } + finally + { + if (preparedStatement != null) + { + try + { + preparedStatement.close(); + } + catch (SQLException e) + { + e.printStackTrace(); + } + } + } + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsCommand.java b/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsCommand.java new file mode 100644 index 000000000..1507223f9 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsCommand.java @@ -0,0 +1,46 @@ +package mineplex.hub.commands; + +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import mineplex.hub.HubManager; +import mineplex.hub.modules.NewsManager; + +public class NewsCommand extends CommandBase +{ + public NewsCommand(HubManager plugin) + { + super(plugin, Rank.ADMIN, "news"); + } + + @Override + public void Execute(Player caller, String[] args) + { + NewsManager blorp = Plugin.GetNewsManager(); + + if (args.length == 1 && args[0].equalsIgnoreCase("list")) + { + UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cGray + "Current server news messages will be listed here...")); + } + else if (args.length == 2) + { + if (args[0].equalsIgnoreCase("add")) + { + UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cGray + "This is where future messages like, '" + C.cGold + args[1] + "' will be added to server news!")); + } + else if (args[0].equalsIgnoreCase("delete")) + { + UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cGray + "This is where future messages at positions like, " + C.cGold + "'News Position: " + C.cGold + args[1] + "'" + C.cGray + " will be removed from server news!")); + } + } + else + { + UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "Your arguments are inappropriate for this command!")); + return; + } + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/NewsManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/NewsManager.java index 3da02e393..59a1f247f 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/NewsManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/NewsManager.java @@ -12,6 +12,7 @@ import mineplex.core.common.util.UtilTime; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.hub.HubManager; +import mineplex.hub.HubRepository; import mineplex.hub.mount.Mount; import mineplex.hub.mount.types.Dragon; @@ -24,6 +25,8 @@ public class NewsManager extends MiniPlugin private long _newsTime = System.currentTimeMillis(); private int _mineplexIndex = 0; + + private HubRepository _repository = new HubRepository(); public NewsManager(HubManager manager) { @@ -31,6 +34,8 @@ public class NewsManager extends MiniPlugin Manager = manager; + _repository.initialize(manager.GetPlugin().getConfig().getBoolean("serverstatus.us")); + _news = new String[] { "Champions: " + C.cYellow + C.Bold + "Team Deathmatch Beta",