Add a toggleable friends GUI - Chat to Inventory and back
This commit is contained in:
parent
9118aef60f
commit
e91d76960c
@ -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<FriendData>
|
||||
_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<FriendData>
|
||||
{
|
||||
addCommand(new AddFriend(this));
|
||||
addCommand(new DeleteFriend(this));
|
||||
addCommand(new FriendsDisplay(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -107,8 +114,7 @@ public class FriendManager extends MiniDbClientPlugin<FriendData>
|
||||
{
|
||||
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<FriendData>
|
||||
});
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void showFriends(Player caller)
|
||||
{
|
||||
boolean isStaff = ClientManager.Get(caller).GetRank().Has(Rank.HELPER);
|
||||
@ -369,7 +374,15 @@ public class FriendManager extends MiniDbClientPlugin<FriendData>
|
||||
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
|
||||
|
@ -20,7 +20,14 @@ public class AddFriend extends CommandBase<FriendManager>
|
||||
{
|
||||
if (args == null)
|
||||
{
|
||||
new FriendsGUI(Plugin, caller);
|
||||
if (Plugin.getPreferenceManager().Get(caller).friendDisplayInventoryUI)
|
||||
{
|
||||
new FriendsGUI(Plugin, caller);
|
||||
}
|
||||
else
|
||||
{
|
||||
Plugin.showFriends(caller);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -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<FriendManager>
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -320,7 +320,7 @@ public class FriendsGUI implements Listener
|
||||
_page = 0;
|
||||
_buttonMap.clear();
|
||||
|
||||
ArrayList<Integer> itemSlots = new ItemLayout("XOXOXOXOX").getItemSlots();
|
||||
ArrayList<Integer> 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)
|
||||
{
|
||||
|
@ -130,6 +130,6 @@ public class PreferencesManager extends MiniDbClientPlugin<UserPreferences>
|
||||
@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;";
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -14,4 +14,5 @@ public class UserPreferences
|
||||
public boolean ShowMacReports = false;
|
||||
public boolean IgnoreVelocity = false;
|
||||
public boolean PendingFriendRequests = true;
|
||||
public boolean friendDisplayInventoryUI = true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user