From e91d76960c291c9994d3b81bad700de4635f4cd7 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Tue, 3 Feb 2015 22:03:07 +1300 Subject: [PATCH] Add a toggleable friends GUI - Chat to Inventory and back --- .../mineplex/core/friend/FriendManager.java | 23 ++++++++--- .../core/friend/command/AddFriend.java | 9 ++++- .../core/friend/command/FriendsDisplay.java | 39 +++++++++++++++++++ .../mineplex/core/friend/ui/FriendPage.java | 6 ++- .../mineplex/core/friend/ui/FriendsGUI.java | 10 ++++- .../core/preferences/PreferencesManager.java | 2 +- .../preferences/PreferencesRepository.java | 11 ++++-- .../core/preferences/UserPreferences.java | 1 + 8 files changed, 88 insertions(+), 13 deletions(-) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/friend/command/FriendsDisplay.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/friend/FriendManager.java b/Plugins/Mineplex.Core/src/mineplex/core/friend/FriendManager.java index 578719c4f..b3b9eef40 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/friend/FriendManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/friend/FriendManager.java @@ -25,6 +25,7 @@ import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTime; import mineplex.core.friend.command.AddFriend; import mineplex.core.friend.command.DeleteFriend; +import mineplex.core.friend.command.FriendsDisplay; import mineplex.core.friend.data.FriendData; import mineplex.core.friend.data.FriendRepository; import mineplex.core.friend.data.FriendStatus; @@ -49,7 +50,12 @@ public class FriendManager extends MiniDbClientPlugin _repository = new FriendRepository(plugin); _portal = portal; } - + + public PreferencesManager getPreferenceManager() + { + return _preferenceManager; + } + public Portal getPortal() { return _portal; @@ -60,6 +66,7 @@ public class FriendManager extends MiniDbClientPlugin { addCommand(new AddFriend(this)); addCommand(new DeleteFriend(this)); + addCommand(new FriendsDisplay(this)); } @Override @@ -107,8 +114,7 @@ public class FriendManager extends MiniDbClientPlugin { if (caller.getName().equalsIgnoreCase(name)) { - caller.sendMessage(F.main(getName(), ChatColor.GRAY - + "You cannot add yourself as a friend")); + caller.sendMessage(F.main(getName(), ChatColor.GRAY + "You cannot add yourself as a friend")); return; } @@ -243,7 +249,6 @@ public class FriendManager extends MiniDbClientPlugin }); } - @Deprecated public void showFriends(Player caller) { boolean isStaff = ClientManager.Get(caller).GetRank().Has(Rank.HELPER); @@ -369,7 +374,15 @@ public class FriendManager extends MiniDbClientPlugin caller.sendMessage(" "); } - caller.sendMessage(C.cAqua + C.Strike + "====================================================="); + ChildJsonMessage message = new JsonMessage("").extra(C.cAqua + C.Strike + "======================"); + + message.add(C.cDAqua + "Toggle GUI").click("run_command", "/friendsdisplay"); + + message.hover("show_text", C.cAqua + "Toggle friends to display in a inventory"); + + message.add(C.cAqua + C.Strike + "======================"); + + message.sendToPlayer(caller); } @Override diff --git a/Plugins/Mineplex.Core/src/mineplex/core/friend/command/AddFriend.java b/Plugins/Mineplex.Core/src/mineplex/core/friend/command/AddFriend.java index bb6f3aa47..706600eb6 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/friend/command/AddFriend.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/friend/command/AddFriend.java @@ -20,7 +20,14 @@ public class AddFriend extends CommandBase { if (args == null) { - new FriendsGUI(Plugin, caller); + if (Plugin.getPreferenceManager().Get(caller).friendDisplayInventoryUI) + { + new FriendsGUI(Plugin, caller); + } + else + { + Plugin.showFriends(caller); + } } else { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/friend/command/FriendsDisplay.java b/Plugins/Mineplex.Core/src/mineplex/core/friend/command/FriendsDisplay.java new file mode 100644 index 000000000..6109041f6 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/friend/command/FriendsDisplay.java @@ -0,0 +1,39 @@ +package mineplex.core.friend.command; + +import org.bukkit.Sound; +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.core.friend.FriendManager; +import mineplex.core.friend.ui.FriendsGUI; +import mineplex.core.preferences.UserPreferences; + +public class FriendsDisplay extends CommandBase +{ + public FriendsDisplay(FriendManager plugin) + { + super(plugin, Rank.ALL, "friendsdisplay"); + } + + @Override + public void Execute(Player caller, final String[] args) + { + UserPreferences preferences = Plugin.getPreferenceManager().Get(caller); + + preferences.friendDisplayInventoryUI = !preferences.friendDisplayInventoryUI; + + Plugin.getPreferenceManager().savePreferences(caller); + + caller.playSound(caller.getLocation(), Sound.NOTE_PLING, 1, 1.6f); + + if (preferences.friendDisplayInventoryUI) + { + new FriendsGUI(Plugin, caller); + } + else + { + Plugin.showFriends(caller); + } + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/friend/ui/FriendPage.java b/Plugins/Mineplex.Core/src/mineplex/core/friend/ui/FriendPage.java index e10169e3c..ada0b2688 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/friend/ui/FriendPage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/friend/ui/FriendPage.java @@ -1,5 +1,6 @@ package mineplex.core.friend.ui; +import mineplex.core.common.util.C; import mineplex.core.itemstack.ItemBuilder; import org.bukkit.Material; @@ -13,7 +14,10 @@ public enum FriendPage DELETE_FRIENDS(new ItemBuilder(Material.TNT).setTitle("Delete Friends").build(), "Delete Friends"), - SEND_REQUEST(new ItemBuilder(Material.BOOK_AND_QUILL).setTitle("Send Friend Request").build(), "Send Friend Request"); + SEND_REQUEST(new ItemBuilder(Material.BOOK_AND_QUILL).setTitle("Send Friend Request").build(), "Send Friend Request"), + + TOGGLE_DISPLAY(new ItemBuilder(Material.SIGN).setTitle(C.cGray + "Toggle friends to display in chat").build(), + "Toggle Display"); private ItemStack _icon; private String _name; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/friend/ui/FriendsGUI.java b/Plugins/Mineplex.Core/src/mineplex/core/friend/ui/FriendsGUI.java index a5c103a5a..e5d53a560 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/friend/ui/FriendsGUI.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/friend/ui/FriendsGUI.java @@ -320,7 +320,7 @@ public class FriendsGUI implements Listener _page = 0; _buttonMap.clear(); - ArrayList itemSlots = new ItemLayout("XOXOXOXOX").getItemSlots(); + ArrayList itemSlots = new ItemLayout("OXOXOXOXO").getItemSlots(); for (int i = 0; i < FriendPage.values().length; i++) { @@ -370,6 +370,14 @@ public class FriendsGUI implements Listener return; } + else if (_currentPage == FriendPage.TOGGLE_DISPLAY) + { + _player.closeInventory(); + + CommandCenter.Instance.OnPlayerCommandPreprocess(new PlayerCommandPreprocessEvent(_player, "/friendsdisplay")); + + return; + } if (_previousPage != _currentPage) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesManager.java b/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesManager.java index 309cf6d79..9bbb15bca 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesManager.java @@ -130,6 +130,6 @@ public class PreferencesManager extends MiniDbClientPlugin @Override public String getQuery(String uuid, String name) { - return "SELECT games, visibility, showChat, friendChat, privateMessaging, partyRequests, invisibility, forcefield, showMacReports, ignoreVelocity, pendingFriendRequests FROM accountPreferences WHERE accountPreferences.uuid = '" + uuid + "' LIMIT 1;"; + return "SELECT games, visibility, showChat, friendChat, privateMessaging, partyRequests, invisibility, forcefield, showMacReports, ignoreVelocity, pendingFriendRequests, friendDisplayInventoryUI FROM accountPreferences WHERE accountPreferences.uuid = '" + uuid + "' LIMIT 1;"; } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesRepository.java index 332f9b2db..9b3678016 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesRepository.java @@ -15,7 +15,7 @@ public class PreferencesRepository extends RepositoryBase { private static String CREATE_ACCOUNT_TABLE = "CREATE TABLE IF NOT EXISTS accountPreferences (id INT NOT NULL AUTO_INCREMENT, uuid VARCHAR(256), games BOOL NOT NULL DEFAULT 1, visibility BOOL NOT NULL DEFAULT 1, showChat BOOL NOT NULL DEFAULT 1, friendChat BOOL NOT NULL DEFAULT 1, privateMessaging BOOL NOT NULL DEFAULT 1, partyRequests BOOL NOT NULL DEFAULT 0, invisibility BOOL NOT NULL DEFAULT 0, forcefield BOOL NOT NULL DEFAULT 0, showMacReports BOOL NOT NULL DEFAULT 0, ignoreVelocity BOOL NOT NULL DEFAULT 0, PRIMARY KEY (id), UNIQUE INDEX uuid_index (uuid));"; private static String INSERT_ACCOUNT = "INSERT INTO accountPreferences (uuid) VALUES (?) ON DUPLICATE KEY UPDATE uuid=uuid;"; - private static String UPDATE_ACCOUNT_PREFERENCES = "UPDATE accountPreferences SET games = ?, visibility = ?, showChat = ?, friendChat = ?, privateMessaging = ?, partyRequests = ?, invisibility = ?, forcefield = ?, showMacReports = ?, ignoreVelocity = ?, pendingFriendRequests = ? WHERE uuid=?;"; + private static String UPDATE_ACCOUNT_PREFERENCES = "UPDATE accountPreferences SET games = ?, visibility = ?, showChat = ?, friendChat = ?, privateMessaging = ?, partyRequests = ?, invisibility = ?, forcefield = ?, showMacReports = ?, ignoreVelocity = ?, pendingFriendRequests = ?, friendDisplayInventoryUI = ? WHERE uuid=?;"; public PreferencesRepository(JavaPlugin plugin, String connectionString) { @@ -53,8 +53,9 @@ public class PreferencesRepository extends RepositoryBase preparedStatement.setBoolean(8, entry.getValue().HubForcefield); preparedStatement.setBoolean(9, entry.getValue().ShowMacReports); preparedStatement.setBoolean(10, entry.getValue().IgnoreVelocity); - preparedStatement.setBoolean(11, entry.getValue().PendingFriendRequests); - preparedStatement.setString(12, entry.getKey()); + preparedStatement.setBoolean(11, entry.getValue().PendingFriendRequests); + preparedStatement.setBoolean(12, entry.getValue().friendDisplayInventoryUI); + preparedStatement.setString(13, entry.getKey()); preparedStatement.addBatch(); } @@ -79,7 +80,8 @@ public class PreferencesRepository extends RepositoryBase preparedStatement.setBoolean(9, entry.getValue().ShowMacReports); preparedStatement.setBoolean(10, entry.getValue().IgnoreVelocity); preparedStatement.setBoolean(11, entry.getValue().PendingFriendRequests); - preparedStatement.setString(12, entry.getKey()); + preparedStatement.setBoolean(12, entry.getValue().friendDisplayInventoryUI); + preparedStatement.setString(13, entry.getKey()); preparedStatement.execute(); } @@ -123,6 +125,7 @@ public class PreferencesRepository extends RepositoryBase preferences.ShowMacReports = resultSet.getBoolean(9); preferences.IgnoreVelocity = resultSet.getBoolean(10); preferences.PendingFriendRequests = resultSet.getBoolean(11); + preferences.friendDisplayInventoryUI = resultSet.getBoolean(12); } return preferences; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/preferences/UserPreferences.java b/Plugins/Mineplex.Core/src/mineplex/core/preferences/UserPreferences.java index 45700ccf1..e52e7d249 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/preferences/UserPreferences.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/preferences/UserPreferences.java @@ -14,4 +14,5 @@ public class UserPreferences public boolean ShowMacReports = false; public boolean IgnoreVelocity = false; public boolean PendingFriendRequests = true; + public boolean friendDisplayInventoryUI = true; }