Fix issues from testing
This commit is contained in:
parent
6f0d29b20c
commit
3387c68fc2
@ -4,12 +4,14 @@ import java.sql.ResultSet;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
@ -25,6 +27,7 @@ import org.bukkit.event.player.PlayerJoinEvent;
|
|||||||
|
|
||||||
import mineplex.core.MiniDbClientPlugin;
|
import mineplex.core.MiniDbClientPlugin;
|
||||||
import mineplex.core.ReflectivelyCreateMiniPlugin;
|
import mineplex.core.ReflectivelyCreateMiniPlugin;
|
||||||
|
import mineplex.core.account.ILoginProcessor;
|
||||||
import mineplex.core.account.permissions.Permission;
|
import mineplex.core.account.permissions.Permission;
|
||||||
import mineplex.core.account.permissions.PermissionGroup;
|
import mineplex.core.account.permissions.PermissionGroup;
|
||||||
import mineplex.core.common.util.C;
|
import mineplex.core.common.util.C;
|
||||||
@ -46,6 +49,7 @@ import mineplex.core.portal.Portal;
|
|||||||
import mineplex.core.preferences.Preference;
|
import mineplex.core.preferences.Preference;
|
||||||
import mineplex.core.preferences.PreferencesManager;
|
import mineplex.core.preferences.PreferencesManager;
|
||||||
import mineplex.core.preferences.UserPreferences;
|
import mineplex.core.preferences.UserPreferences;
|
||||||
|
import mineplex.core.recharge.Recharge;
|
||||||
import mineplex.core.updater.UpdateType;
|
import mineplex.core.updater.UpdateType;
|
||||||
import mineplex.core.updater.event.UpdateEvent;
|
import mineplex.core.updater.event.UpdateEvent;
|
||||||
import mineplex.serverdata.commands.ServerCommandManager;
|
import mineplex.serverdata.commands.ServerCommandManager;
|
||||||
@ -62,6 +66,7 @@ public class FriendManager extends MiniDbClientPlugin<List<FriendStatus>>
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static final int MAX_FRIENDS = 500;
|
private static final int MAX_FRIENDS = 500;
|
||||||
|
private static final long COOLDOWN = TimeUnit.SECONDS.toMillis(5);
|
||||||
private static final Comparator<FriendStatus> FRIEND_SORTER = (o1, o2) ->
|
private static final Comparator<FriendStatus> FRIEND_SORTER = (o1, o2) ->
|
||||||
{
|
{
|
||||||
// If not mutual
|
// If not mutual
|
||||||
@ -70,16 +75,6 @@ public class FriendManager extends MiniDbClientPlugin<List<FriendStatus>>
|
|||||||
return o1.Name.compareTo(o2.Name);
|
return o1.Name.compareTo(o2.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Favourite
|
|
||||||
if (o1.Favourite && !o2.Favourite)
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
else if (!o1.Favourite && o2.Favourite)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Online
|
// Online
|
||||||
if (o1.isOnline() && !o2.isOnline())
|
if (o1.isOnline() && !o2.isOnline())
|
||||||
{
|
{
|
||||||
@ -90,8 +85,18 @@ public class FriendManager extends MiniDbClientPlugin<List<FriendStatus>>
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Last Seen
|
// Favourite
|
||||||
return Long.compare(o1.LastSeenOnline, o2.LastSeenOnline);
|
if (o1.Favourite && !o2.Favourite)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else if (!o1.Favourite && o2.Favourite)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Name
|
||||||
|
return o1.Name.compareTo(o2.Name);
|
||||||
};
|
};
|
||||||
|
|
||||||
public static Comparator<FriendStatus> getFriendSorter()
|
public static Comparator<FriendStatus> getFriendSorter()
|
||||||
@ -108,6 +113,8 @@ public class FriendManager extends MiniDbClientPlugin<List<FriendStatus>>
|
|||||||
private final FriendRepository _repository;
|
private final FriendRepository _repository;
|
||||||
private final FriendShop _shop;
|
private final FriendShop _shop;
|
||||||
|
|
||||||
|
private final Map<UUID, FriendVisibility> _visibility;
|
||||||
|
|
||||||
private FriendManager()
|
private FriendManager()
|
||||||
{
|
{
|
||||||
super("Friends");
|
super("Friends");
|
||||||
@ -119,6 +126,8 @@ public class FriendManager extends MiniDbClientPlugin<List<FriendStatus>>
|
|||||||
_repository = new FriendRepository();
|
_repository = new FriendRepository();
|
||||||
_shop = new FriendShop(this);
|
_shop = new FriendShop(this);
|
||||||
|
|
||||||
|
_visibility = new HashMap<>();
|
||||||
|
|
||||||
generatePermissions();
|
generatePermissions();
|
||||||
|
|
||||||
ServerCommandManager.getInstance().registerCommandType(FriendAddMessage.class, command ->
|
ServerCommandManager.getInstance().registerCommandType(FriendAddMessage.class, command ->
|
||||||
@ -141,6 +150,35 @@ public class FriendManager extends MiniDbClientPlugin<List<FriendStatus>>
|
|||||||
|
|
||||||
onFriendAdd(target, command.getAccepter());
|
onFriendAdd(target, command.getAccepter());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ClientManager.addStoredProcedureLoginProcessor(new ILoginProcessor()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
return getName() + " Visibility";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void processLoginResultSet(String playerName, UUID uuid, int accountId, ResultSet resultSet) throws SQLException
|
||||||
|
{
|
||||||
|
if (resultSet.next())
|
||||||
|
{
|
||||||
|
byte visibility = resultSet.getByte("status");
|
||||||
|
|
||||||
|
if (visibility > 0 && visibility < FriendVisibility.values().length)
|
||||||
|
{
|
||||||
|
_visibility.put(uuid, FriendVisibility.values()[visibility]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getQuery(int accountId, String uuid, String name)
|
||||||
|
{
|
||||||
|
return "SELECT accountFriendData.status FROM accountFriendData WHERE accountId=" + accountId + ".";
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generatePermissions()
|
private void generatePermissions()
|
||||||
@ -159,6 +197,11 @@ public class FriendManager extends MiniDbClientPlugin<List<FriendStatus>>
|
|||||||
return _portal;
|
return _portal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public FriendVisibility getVisibility(Player player)
|
||||||
|
{
|
||||||
|
return _visibility.get(player.getUniqueId());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addCommands()
|
public void addCommands()
|
||||||
{
|
{
|
||||||
@ -175,6 +218,12 @@ public class FriendManager extends MiniDbClientPlugin<List<FriendStatus>>
|
|||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveData(String name, UUID uuid, int accountId)
|
||||||
|
{
|
||||||
|
_visibility.remove(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void updateFriends(UpdateEvent event)
|
public void updateFriends(UpdateEvent event)
|
||||||
{
|
{
|
||||||
@ -270,6 +319,11 @@ public class FriendManager extends MiniDbClientPlugin<List<FriendStatus>>
|
|||||||
|
|
||||||
public void addFriend(final Player caller, final String name)
|
public void addFriend(final Player caller, final String name)
|
||||||
{
|
{
|
||||||
|
if (!Recharge.Instance.use(caller, "Friend " + name, COOLDOWN, false, false))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (caller.getName().equalsIgnoreCase(name))
|
if (caller.getName().equalsIgnoreCase(name))
|
||||||
{
|
{
|
||||||
caller.sendMessage(F.main(getName(), "You cannot add yourself as a friend"));
|
caller.sendMessage(F.main(getName(), "You cannot add yourself as a friend"));
|
||||||
@ -371,6 +425,11 @@ public class FriendManager extends MiniDbClientPlugin<List<FriendStatus>>
|
|||||||
|
|
||||||
public void removeFriend(final Player caller, final String name)
|
public void removeFriend(final Player caller, final String name)
|
||||||
{
|
{
|
||||||
|
if (!Recharge.Instance.use(caller, "Friend " + name, COOLDOWN, false, false))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
runAsync(() ->
|
runAsync(() ->
|
||||||
{
|
{
|
||||||
_repository.removeFriend(caller.getName(), name);
|
_repository.removeFriend(caller.getName(), name);
|
||||||
@ -392,32 +451,37 @@ public class FriendManager extends MiniDbClientPlugin<List<FriendStatus>>
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVisibility(Player player, FriendVisibility visibility)
|
public void setVisibility(Player caller, FriendVisibility visibility)
|
||||||
{
|
{
|
||||||
int accountId = ClientManager.getAccountId(player);
|
int accountId = ClientManager.getAccountId(caller);
|
||||||
|
|
||||||
runAsync(() ->
|
runAsync(() ->
|
||||||
{
|
{
|
||||||
if (_repository.updateVisibility(accountId, visibility))
|
if (_repository.updateVisibility(accountId, visibility))
|
||||||
{
|
{
|
||||||
runSync(() -> player.sendMessage(F.main(getName(), "Updated your friend status to " + F.elem(visibility.getName()) + ".")));
|
runSync(() -> caller.sendMessage(F.main(getName(), "Updated your friend status to " + F.elem(visibility.getName()) + ".")));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void toggleFavourite(Player player, String target, Runnable onSuccess)
|
public void toggleFavourite(Player caller, String target, Runnable onSuccess)
|
||||||
{
|
{
|
||||||
for (FriendStatus status : Get(player))
|
if (!Recharge.Instance.use(caller, "Friend " + target, COOLDOWN, false, false))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (FriendStatus status : Get(caller))
|
||||||
{
|
{
|
||||||
if (status.Name.equals(target))
|
if (status.Name.equals(target))
|
||||||
{
|
{
|
||||||
runAsync(() ->
|
runAsync(() ->
|
||||||
{
|
{
|
||||||
if (_repository.updateFavourite(player.getName(), status.Name, !status.Favourite))
|
if (_repository.updateFavourite(caller.getName(), status.Name, !status.Favourite))
|
||||||
{
|
{
|
||||||
runSync(() ->
|
runSync(() ->
|
||||||
{
|
{
|
||||||
player.sendMessage(F.main(getName(), F.name(status.Name) + " is " + (status.Favourite ? "no longer" : "now") + " on your favourite friends."));
|
caller.sendMessage(F.main(getName(), F.name(status.Name) + " is " + (status.Favourite ? "no longer" : "now") + " on your favourite friends."));
|
||||||
|
|
||||||
if (onSuccess != null)
|
if (onSuccess != null)
|
||||||
{
|
{
|
||||||
@ -713,6 +777,8 @@ public class FriendManager extends MiniDbClientPlugin<List<FriendStatus>>
|
|||||||
|
|
||||||
TextComponent message = new TextComponent("");
|
TextComponent message = new TextComponent("");
|
||||||
|
|
||||||
|
FriendVisibility playerVisibility = getVisibility(caller);
|
||||||
|
|
||||||
for (FriendVisibility visibility : FriendVisibility.values())
|
for (FriendVisibility visibility : FriendVisibility.values())
|
||||||
{
|
{
|
||||||
TextComponent vis = new TextComponent(visibility.getName().toUpperCase());
|
TextComponent vis = new TextComponent(visibility.getName().toUpperCase());
|
||||||
@ -721,6 +787,7 @@ public class FriendManager extends MiniDbClientPlugin<List<FriendStatus>>
|
|||||||
vis.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Set your visibility to " + visibility.getName())
|
vis.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Set your visibility to " + visibility.getName())
|
||||||
.create()));
|
.create()));
|
||||||
vis.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, visiblityCommand + visibility));
|
vis.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, visiblityCommand + visibility));
|
||||||
|
vis.setUnderlined(visibility == playerVisibility);
|
||||||
|
|
||||||
if (message.getExtra() != null)
|
if (message.getExtra() != null)
|
||||||
{
|
{
|
||||||
|
@ -13,7 +13,7 @@ public class FriendFavouriteCommand extends CommandBase<FriendManager>
|
|||||||
|
|
||||||
public FriendFavouriteCommand(FriendManager plugin)
|
public FriendFavouriteCommand(FriendManager plugin)
|
||||||
{
|
{
|
||||||
super(plugin, Perm.FRIEND_COMMAND, COMMAND);
|
super(plugin, Perm.FRIEND_COMMAND, COMMAND, "ff");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -35,7 +35,7 @@ public class FriendMainPage extends ShopPageBase<FriendManager, FriendShop>
|
|||||||
REQUESTS(status -> status.Status == FriendStatusType.Pending || status.Status == FriendStatusType.Sent, new ItemBuilder(Material.RED_ROSE)
|
REQUESTS(status -> status.Status == FriendStatusType.Pending || status.Status == FriendStatusType.Sent, new ItemBuilder(Material.RED_ROSE)
|
||||||
.setTitle(C.cYellowB + "Friend Requests")
|
.setTitle(C.cYellowB + "Friend Requests")
|
||||||
.build()),
|
.build()),
|
||||||
DELETE(status -> status.Status == FriendStatusType.Accepted, new ItemBuilder(Material.TNT)
|
DELETE(status -> status.Status == FriendStatusType.Accepted && !status.Favourite, new ItemBuilder(Material.TNT)
|
||||||
.setTitle(C.cRedB + "Delete Friends")
|
.setTitle(C.cRedB + "Delete Friends")
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
@ -131,9 +131,13 @@ public class FriendMainPage extends ShopPageBase<FriendManager, FriendShop>
|
|||||||
|
|
||||||
slot = 47;
|
slot = 47;
|
||||||
|
|
||||||
|
FriendVisibility playerVisiblity = getPlugin().getVisibility(getPlayer());
|
||||||
|
|
||||||
for (FriendVisibility visibility : FriendVisibility.values())
|
for (FriendVisibility visibility : FriendVisibility.values())
|
||||||
{
|
{
|
||||||
addButton(slot, visibility.getItemStack(), (player, clickType) ->
|
addButton(slot, new ItemBuilder(visibility.getItemStack())
|
||||||
|
.setGlow(visibility == playerVisiblity)
|
||||||
|
.build(), (player, clickType) ->
|
||||||
{
|
{
|
||||||
getPlugin().setVisibility(player, visibility);
|
getPlugin().setVisibility(player, visibility);
|
||||||
player.closeInventory();
|
player.closeInventory();
|
||||||
@ -189,13 +193,13 @@ public class FriendMainPage extends ShopPageBase<FriendManager, FriendShop>
|
|||||||
statusString = C.cRed + "Offline";
|
statusString = C.cRed + "Offline";
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.addLore("Where: " + statusString);
|
builder.addLore("Where: " + statusString, "");
|
||||||
|
|
||||||
if (online)
|
if (online)
|
||||||
{
|
{
|
||||||
if (canJoin)
|
if (canJoin)
|
||||||
{
|
{
|
||||||
builder.addLore("", C.cGreen + "Click to join their server.");
|
builder.addLore(C.cGreen + "Click to join their server.", "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -204,7 +208,7 @@ public class FriendMainPage extends ShopPageBase<FriendManager, FriendShop>
|
|||||||
}
|
}
|
||||||
|
|
||||||
builder.addLore(
|
builder.addLore(
|
||||||
"Shift-Click to " + (status.Favourite ? "remove " + status.Name + " from" : "add " + status.Name + " to"),
|
"Shift-Click to " + (status.Favourite ? "remove them from" : "add them to"),
|
||||||
"your favourite friends."
|
"your favourite friends."
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -311,7 +315,7 @@ public class FriendMainPage extends ShopPageBase<FriendManager, FriendShop>
|
|||||||
|
|
||||||
if (status.Favourite)
|
if (status.Favourite)
|
||||||
{
|
{
|
||||||
colour = C.cYellow;
|
colour = C.cYellow + "★ ";
|
||||||
}
|
}
|
||||||
else if (status.isOnline())
|
else if (status.isOnline())
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user