Add back toggling the UI modes
This commit is contained in:
parent
ad88c581fd
commit
b1a5b7ffb6
@ -18,6 +18,7 @@ import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
@ -44,6 +45,7 @@ import mineplex.core.friend.ui.FriendShop;
|
||||
import mineplex.core.portal.Portal;
|
||||
import mineplex.core.preferences.Preference;
|
||||
import mineplex.core.preferences.PreferencesManager;
|
||||
import mineplex.core.preferences.UserPreferences;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.serverdata.commands.ServerCommandManager;
|
||||
@ -97,6 +99,8 @@ public class FriendManager extends MiniDbClientPlugin<List<FriendStatus>>
|
||||
return FRIEND_SORTER;
|
||||
}
|
||||
|
||||
private static final int FRIENDS_IN_CHAT = 2;
|
||||
|
||||
private final DonationManager _donationManager;
|
||||
private final PreferencesManager _preferenceManager;
|
||||
private final Portal _portal;
|
||||
@ -150,11 +154,6 @@ public class FriendManager extends MiniDbClientPlugin<List<FriendStatus>>
|
||||
return _donationManager;
|
||||
}
|
||||
|
||||
public PreferencesManager getPreferenceManager()
|
||||
{
|
||||
return _preferenceManager;
|
||||
}
|
||||
|
||||
public Portal getPortal()
|
||||
{
|
||||
return _portal;
|
||||
@ -176,11 +175,6 @@ public class FriendManager extends MiniDbClientPlugin<List<FriendStatus>>
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public void openShop(Player player)
|
||||
{
|
||||
_shop.attemptShopOpen(player);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void updateFriends(UpdateEvent event)
|
||||
{
|
||||
@ -411,7 +405,7 @@ public class FriendManager extends MiniDbClientPlugin<List<FriendStatus>>
|
||||
});
|
||||
}
|
||||
|
||||
public void toggleFavourite(Player player, String target)
|
||||
public void toggleFavourite(Player player, String target, Runnable onSuccess)
|
||||
{
|
||||
for (FriendStatus status : Get(player))
|
||||
{
|
||||
@ -421,7 +415,15 @@ public class FriendManager extends MiniDbClientPlugin<List<FriendStatus>>
|
||||
{
|
||||
if (_repository.updateFavourite(player.getName(), status.Name, !status.Favourite))
|
||||
{
|
||||
runSync(() -> player.sendMessage(F.main(getName(), F.name(status.Name) + " is " + (status.Favourite ? "no longer" : "now") + " on your favourite friends.")));
|
||||
runSync(() ->
|
||||
{
|
||||
player.sendMessage(F.main(getName(), F.name(status.Name) + " is " + (status.Favourite ? "no longer" : "now") + " on your favourite friends."));
|
||||
|
||||
if (onSuccess != null)
|
||||
{
|
||||
onSuccess.run();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@ -467,7 +469,33 @@ public class FriendManager extends MiniDbClientPlugin<List<FriendStatus>>
|
||||
viewer.spigot().sendMessage(message);
|
||||
}
|
||||
|
||||
public void showFriends(Player caller)
|
||||
public void showFriends(Player player, boolean toggle)
|
||||
{
|
||||
UserPreferences preferences = _preferenceManager.get(player);
|
||||
|
||||
if (toggle)
|
||||
{
|
||||
preferences.toggle(Preference.FRIENDS_DISPLAY_INVENTORY_UI);
|
||||
_preferenceManager.save(preferences);
|
||||
player.playSound(player.getLocation(), Sound.NOTE_PLING, 1, 1.6f);
|
||||
}
|
||||
|
||||
if (preferences.isActive(Preference.FRIENDS_DISPLAY_INVENTORY_UI))
|
||||
{
|
||||
showFriendsInUI(player);
|
||||
}
|
||||
else
|
||||
{
|
||||
showFriendsInChat(player);
|
||||
}
|
||||
}
|
||||
|
||||
public void showFriendsInUI(Player player)
|
||||
{
|
||||
_shop.attemptShopOpen(player);
|
||||
}
|
||||
|
||||
public void showFriendsInChat(Player caller)
|
||||
{
|
||||
boolean isStaff = ClientManager.Get(caller).hasPermission(Perm.JOIN_STAFF);
|
||||
boolean showPending = _preferenceManager.get(caller).isActive(Preference.PENDING_FRIEND_REQUESTS);
|
||||
@ -475,8 +503,33 @@ public class FriendManager extends MiniDbClientPlugin<List<FriendStatus>>
|
||||
List<FriendStatus> friendStatuses = Get(caller);
|
||||
friendStatuses.sort(getFriendSorter().reversed());
|
||||
|
||||
boolean compress = friendStatuses.size() > FRIENDS_IN_CHAT;
|
||||
|
||||
caller.sendMessage(C.cAqua + C.Strike + "======================[" + C.cWhiteB + "Friends" + C.cAqua + C.Strike + "]======================");
|
||||
|
||||
if (compress)
|
||||
{
|
||||
int sent = 0, pending = 0;
|
||||
|
||||
for (FriendStatus friend : friendStatuses)
|
||||
{
|
||||
switch (friend.Status)
|
||||
{
|
||||
case Sent:
|
||||
sent++;
|
||||
break;
|
||||
case Pending:
|
||||
pending++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
TextComponent compressed = new TextComponent(C.cGray + "Sent: " + F.count(sent) + " Pending: " + F.count(pending));
|
||||
compressed.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Shows all friends.")
|
||||
.create()));
|
||||
compressed.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/"));
|
||||
}
|
||||
|
||||
// Use a LinkedHashMap so we maintain insertion order
|
||||
Map<String, TextComponent> messages = new LinkedHashMap<>();
|
||||
String joinCommand = "/server ", friendCommand = "/" + AddFriend.COMMAND + " ", unfriendCommand = "/" + DeleteFriend.COMMAND + " ";
|
||||
@ -486,9 +539,19 @@ public class FriendManager extends MiniDbClientPlugin<List<FriendStatus>>
|
||||
{
|
||||
FriendStatusType type = friend.Status;
|
||||
|
||||
if (type == FriendStatusType.Blocked || type == FriendStatusType.Denied || type == FriendStatusType.Pending && !showPending)
|
||||
if (compress)
|
||||
{
|
||||
continue;
|
||||
if (type != FriendStatusType.Accepted)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (type == FriendStatusType.Blocked || type == FriendStatusType.Denied || type == FriendStatusType.Pending && !showPending)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
TextComponent message = new TextComponent("");
|
||||
|
@ -7,6 +7,7 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.command.CommandBase;
|
||||
import mineplex.core.friend.FriendManager;
|
||||
import mineplex.core.friend.FriendManager.Perm;
|
||||
import mineplex.core.preferences.Preference;
|
||||
|
||||
public class AddFriend extends CommandBase<FriendManager>
|
||||
@ -16,7 +17,7 @@ public class AddFriend extends CommandBase<FriendManager>
|
||||
|
||||
public AddFriend(FriendManager plugin)
|
||||
{
|
||||
super(plugin, FriendManager.Perm.FRIEND_COMMAND, "friends", COMMAND, "f");
|
||||
super(plugin, Perm.FRIEND_COMMAND, "friends", COMMAND, "f");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -24,14 +25,7 @@ public class AddFriend extends CommandBase<FriendManager>
|
||||
{
|
||||
if (args == null || args.length < 1)
|
||||
{
|
||||
if (Plugin.getPreferenceManager().get(caller).isActive(Preference.FRIENDS_DISPLAY_INVENTORY_UI))
|
||||
{
|
||||
Plugin.openShop(caller);
|
||||
}
|
||||
else
|
||||
{
|
||||
Plugin.showFriends(caller);
|
||||
}
|
||||
Plugin.showFriends(caller, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -6,6 +6,7 @@ import mineplex.core.command.CommandBase;
|
||||
import mineplex.core.common.util.Callback;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.friend.FriendManager;
|
||||
import mineplex.core.friend.FriendManager.Perm;
|
||||
|
||||
public class DeleteFriend extends CommandBase<FriendManager>
|
||||
{
|
||||
@ -14,7 +15,7 @@ public class DeleteFriend extends CommandBase<FriendManager>
|
||||
|
||||
public DeleteFriend(FriendManager plugin)
|
||||
{
|
||||
super(plugin, FriendManager.Perm.FRIEND_COMMAND, COMMAND);
|
||||
super(plugin, Perm.FRIEND_COMMAND, COMMAND);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -28,7 +28,7 @@ public class FriendFavouriteCommand extends CommandBase<FriendManager>
|
||||
{
|
||||
if (result != null)
|
||||
{
|
||||
Plugin.toggleFavourite(caller, result);
|
||||
Plugin.toggleFavourite(caller, result, null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1,12 +1,10 @@
|
||||
package mineplex.core.friend.command;
|
||||
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.command.CommandBase;
|
||||
import mineplex.core.friend.FriendManager;
|
||||
import mineplex.core.preferences.Preference;
|
||||
import mineplex.core.preferences.UserPreferences;
|
||||
import mineplex.core.friend.FriendManager.Perm;
|
||||
|
||||
public class FriendsDisplay extends CommandBase<FriendManager>
|
||||
{
|
||||
@ -15,27 +13,12 @@ public class FriendsDisplay extends CommandBase<FriendManager>
|
||||
|
||||
public FriendsDisplay(FriendManager plugin)
|
||||
{
|
||||
super(plugin, FriendManager.Perm.FRIEND_COMMAND, COMMAND);
|
||||
super(plugin, Perm.FRIEND_COMMAND, COMMAND);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Execute(Player caller, final String[] args)
|
||||
{
|
||||
UserPreferences preferences = Plugin.getPreferenceManager().get(caller);
|
||||
|
||||
preferences.toggle(Preference.FRIENDS_DISPLAY_INVENTORY_UI);
|
||||
|
||||
Plugin.getPreferenceManager().save(preferences);
|
||||
|
||||
caller.playSound(caller.getLocation(), Sound.NOTE_PLING, 1, 1.6f);
|
||||
|
||||
if (preferences.isActive(Preference.FRIENDS_DISPLAY_INVENTORY_UI))
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Plugin.runAsync(() -> Plugin.showFriends(caller));
|
||||
}
|
||||
Plugin.showFriends(caller, true);
|
||||
}
|
||||
}
|
@ -67,7 +67,7 @@ public class FriendMainPage extends ShopPageBase<FriendManager, FriendShop>
|
||||
@Override
|
||||
protected void buildPage()
|
||||
{
|
||||
int slot = 1;
|
||||
int slot = 0;
|
||||
|
||||
for (FriendPageType pageType : FriendPageType.values())
|
||||
{
|
||||
@ -103,6 +103,17 @@ public class FriendMainPage extends ShopPageBase<FriendManager, FriendShop>
|
||||
.openInventory();
|
||||
});
|
||||
|
||||
slot += 2;
|
||||
|
||||
addButton(slot, new ItemBuilder(Material.SIGN)
|
||||
.setTitle(C.cDAquaB + "Toggle GUI")
|
||||
.addLore("", "Click to display your friends in", "chat instead of this chest.")
|
||||
.build(), (player, clickType) ->
|
||||
{
|
||||
player.closeInventory();
|
||||
getPlugin().showFriends(player, true);
|
||||
});
|
||||
|
||||
_pageManager.buildPage();
|
||||
}
|
||||
|
||||
@ -180,7 +191,11 @@ public class FriendMainPage extends ShopPageBase<FriendManager, FriendShop>
|
||||
if (clickType.isShiftClick())
|
||||
{
|
||||
playAcceptSound(player);
|
||||
getPlugin().toggleFavourite(player, status.Name);
|
||||
getPlugin().toggleFavourite(player, status.Name, () ->
|
||||
{
|
||||
status.Favourite = !status.Favourite;
|
||||
buildItem(status, slot);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user