Skip to content

Commit

Permalink
🏷 4.0.0: Remove logs and selectable ToggleSaraShow/Hide
Browse files Browse the repository at this point in the history
Packets are backwards-compatible, but APIs are not.
  • Loading branch information
acrylic-style committed Sep 6, 2022
1 parent 28a287f commit 60cbce0
Show file tree
Hide file tree
Showing 13 changed files with 176 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@
import net.azisaba.azipluginmessaging.api.protocol.message.EncryptionMessage;
import net.azisaba.azipluginmessaging.api.protocol.message.Message;
import net.azisaba.azipluginmessaging.api.protocol.message.PlayerMessage;
import net.azisaba.azipluginmessaging.api.protocol.message.PlayerWithServerMessage;
import net.azisaba.azipluginmessaging.api.protocol.message.ProxyboundCheckRankExpirationMessage;
import net.azisaba.azipluginmessaging.api.protocol.message.ProxyboundClearPrefixMessage;
import net.azisaba.azipluginmessaging.api.protocol.message.ProxyboundGiveNitroSaraMessage;
import net.azisaba.azipluginmessaging.api.protocol.message.ProxyboundGiveSaraMessage;
import net.azisaba.azipluginmessaging.api.protocol.message.ProxyboundSetPrefixMessage;
import net.azisaba.azipluginmessaging.api.protocol.message.ProxyboundSetRankMessage;
import net.azisaba.azipluginmessaging.api.protocol.message.ProxyboundToggleSaraHideMessage;
import net.azisaba.azipluginmessaging.api.protocol.message.ProxyboundToggleSaraShowMessage;
import net.azisaba.azipluginmessaging.api.protocol.message.ServerboundActionResponseMessage;
import net.azisaba.azipluginmessaging.api.protocol.message.ServerboundCheckRankExpirationMessage;
import net.azisaba.azipluginmessaging.api.server.PacketSender;
Expand Down Expand Up @@ -73,8 +74,8 @@ public final class Protocol<T extends MessageHandler<M>, M extends Message> {
public static final Protocol<ProxyboundGiveGamingSaraPacket, PlayerMessage> P_GIVE_GAMING_SARA = new Protocol<>(PacketFlow.TO_PROXY, 0x03, new ProxyboundGiveGamingSaraPacket());
public static final Protocol<ProxyboundGiveSaraPacket, ProxyboundGiveSaraMessage> P_GIVE_SARA = new Protocol<>(PacketFlow.TO_PROXY, 0x04, new ProxyboundGiveSaraPacket());
public static final Protocol<ProxyboundToggleGamingSaraPacket, PlayerMessage> P_TOGGLE_GAMING_SARA = new Protocol<>(PacketFlow.TO_PROXY, 0x05, new ProxyboundToggleGamingSaraPacket());
public static final Protocol<ProxyboundToggleSaraHidePacket, PlayerMessage> P_TOGGLE_SARA_HIDE = new Protocol<>(PacketFlow.TO_PROXY, 0x06, new ProxyboundToggleSaraHidePacket()); // non-contextual
public static final Protocol<ProxyboundToggleSaraShowPacket, PlayerWithServerMessage> P_TOGGLE_SARA_SHOW = new Protocol<>(PacketFlow.TO_PROXY, 0x07, new ProxyboundToggleSaraShowPacket()); // contextual
public static final Protocol<ProxyboundToggleSaraHidePacket, ProxyboundToggleSaraHideMessage> P_TOGGLE_SARA_HIDE = new Protocol<>(PacketFlow.TO_PROXY, 0x06, new ProxyboundToggleSaraHidePacket()); // non-contextual
public static final Protocol<ProxyboundToggleSaraShowPacket, ProxyboundToggleSaraShowMessage> P_TOGGLE_SARA_SHOW = new Protocol<>(PacketFlow.TO_PROXY, 0x07, new ProxyboundToggleSaraShowPacket()); // contextual
public static final Protocol<ProxyboundSetPrefixPacket, ProxyboundSetPrefixMessage> P_SET_PREFIX = new Protocol<>(PacketFlow.TO_PROXY, 0x08, new ProxyboundSetPrefixPacket()); // may be contextual
public static final Protocol<ProxyboundClearPrefixPacket, ProxyboundClearPrefixMessage> P_CLEAR_PREFIX = new Protocol<>(PacketFlow.TO_PROXY, 0x09, new ProxyboundClearPrefixPacket()); // may be contextual
public static final Protocol<ProxyboundGiveNitroSaraPacket, ProxyboundGiveNitroSaraMessage> P_GIVE_NITRO_SARA = new Protocol<>(PacketFlow.TO_PROXY, 0x0A, new ProxyboundGiveNitroSaraPacket());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public void handle(@NotNull PacketSender sender, @NotNull ProxyboundSetRankMessa
for (String group : groups) {
if (LuckPermsUtil.findParentNode(nodes, group, msg.getServer()) != null) {
if (groups.indexOf(group) >= rankIndex) {
api.getMessagingService().ifPresent(service -> service.pushUserUpdate(user));
throw new IllegalArgumentException(msg.getPlayer().getUsernameOrUniqueId() +
" already inherits the same or higher rank in the track: " + msg.getRank());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import net.azisaba.azipluginmessaging.api.util.LuckPermsUtil;
import net.luckperms.api.LuckPerms;
import net.luckperms.api.LuckPermsProvider;
import net.luckperms.api.actionlog.Action;
import net.luckperms.api.model.data.DataType;
import net.luckperms.api.model.data.NodeMap;
import net.luckperms.api.model.user.User;
Expand All @@ -18,8 +17,6 @@

import java.io.DataInputStream;
import java.io.IOException;
import java.time.Instant;
import java.util.UUID;

public class ProxyboundToggleGamingSaraPacket implements ProxyMessageHandler<PlayerMessage> {
@Override
Expand All @@ -38,35 +35,21 @@ public static void toggle(@NotNull PacketSender sender, @NotNull PlayerMessage m
if (user == null || user.getUsername() == null) {
throw new IllegalArgumentException("User " + msg.getPlayer().getUniqueId() + " could not be found in the LuckPerms database.");
}
String username = user.getUsername();
NodeMap map = user.getData(DataType.NORMAL);
Node nodeChange = LuckPermsUtil.findParentNode(map, "change" + name, null);
if (nodeChange == null) {
Protocol.S_ACTION_RESPONSE.sendPacket(sender, new ServerboundActionResponseMessage(msg.getPlayer().getUniqueId(), "\u00a7c権限がありません。皿を持ってるのにこのメッセージが出る場合は公式Discordのサポートまでお問い合わせください。"));
throw new MissingPermissionException("User " + msg.getPlayer().getUniqueId() + " does not have the group 'change" + name + "'.");
}
char p;
Node node = LuckPermsUtil.findParentNode(map, name, null);
if (node != null) {
map.remove(node);
Protocol.S_ACTION_RESPONSE.sendPacket(sender, new ServerboundActionResponseMessage(msg.getPlayer().getUniqueId(), "\u00a7a" + name + "皿を非表示にしました。"));
p = '-';
} else {
LuckPermsUtil.addGroup(map, name, null, -1);
Protocol.S_ACTION_RESPONSE.sendPacket(sender, new ServerboundActionResponseMessage(msg.getPlayer().getUniqueId(), "\u00a7a" + name + "皿を表示しました。"));
p = '+';
}
api.getUserManager().saveUser(user);
api.getMessagingService().ifPresent(service -> service.pushUserUpdate(user));
api.getActionLogger().submit(
Action.builder()
.targetType(Action.Target.Type.USER)
.timestamp(Instant.now())
.source(new UUID(0L, 0L))
.sourceName("AziPluginMessaging@" + api.getServerName())
.target(msg.getPlayer().getUniqueId())
.targetName(username)
.description("Toggled " + p + name + " for " + username)
.build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

import net.azisaba.azipluginmessaging.api.exception.MissingPermissionException;
import net.azisaba.azipluginmessaging.api.protocol.Protocol;
import net.azisaba.azipluginmessaging.api.protocol.message.PlayerMessage;
import net.azisaba.azipluginmessaging.api.protocol.message.ProxyboundToggleSaraHideMessage;
import net.azisaba.azipluginmessaging.api.protocol.message.ServerboundActionResponseMessage;
import net.azisaba.azipluginmessaging.api.server.PacketSender;
import net.azisaba.azipluginmessaging.api.server.ServerConnection;
import net.azisaba.azipluginmessaging.api.util.LuckPermsUtil;
import net.luckperms.api.LuckPerms;
import net.luckperms.api.LuckPermsProvider;
import net.luckperms.api.actionlog.Action;
import net.luckperms.api.model.data.DataType;
import net.luckperms.api.model.data.NodeMap;
import net.luckperms.api.model.user.User;
Expand All @@ -19,60 +18,45 @@

import java.io.DataInputStream;
import java.io.IOException;
import java.time.Instant;
import java.util.UUID;

public class ProxyboundToggleSaraHidePacket implements ProxyMessageHandler<PlayerMessage> {
public class ProxyboundToggleSaraHidePacket implements ProxyMessageHandler<ProxyboundToggleSaraHideMessage> {
@Override
public @NotNull PlayerMessage read(@NotNull ServerConnection server, @NotNull DataInputStream in) throws IOException {
return PlayerMessage.read(in);
public @NotNull ProxyboundToggleSaraHideMessage read(@NotNull ServerConnection server, @NotNull DataInputStream in) throws IOException {
return ProxyboundToggleSaraHideMessage.read(in);
}

@Override
public void handle(@NotNull PacketSender sender, @NotNull PlayerMessage msg) {
public void handle(@NotNull PacketSender sender, @NotNull ProxyboundToggleSaraHideMessage msg) {
LuckPerms api = LuckPermsProvider.get();
User user = api.getUserManager().loadUser(msg.getPlayer().getUniqueId()).join();
if (user == null || user.getUsername() == null) {
throw new IllegalArgumentException("User " + msg.getPlayer().getUniqueId() + " could not be found in the LuckPerms database.");
}
String username = user.getUsername();
NodeMap map = user.getData(DataType.NORMAL);
boolean modified = false;
Track track = api.getTrackManager().createAndLoadTrack("sara").join();
for (String groupName : track.getGroups()) {
int yen = Integer.parseInt(groupName.replace("yen", ""));
long yen = Long.parseLong(groupName.replace("yen", ""));
if (!msg.getGroups().isEmpty() && !msg.getGroups().contains(yen)) {
continue;
}
Node nodeSara = LuckPermsUtil.findParentNode(map, groupName, null);
Node nodeHideSara = LuckPermsUtil.findParentNode(map, "hide" + yen, null);
String desc = null;
if (nodeSara != null) {
// hide
map.remove(nodeSara);
if (nodeHideSara == null) {
LuckPermsUtil.addGroup(map, "hide" + yen, null, -1);
}
modified = true;
desc = "Toggled " + groupName + " -> hide" + yen + " for " + username;
Protocol.S_ACTION_RESPONSE.sendPacket(sender, new ServerboundActionResponseMessage(msg.getPlayer().getUniqueId(), "\u00a7a" + yen + "円皿を非表示にしました。"));
} else if (nodeHideSara != null) {
// show
map.remove(nodeHideSara);
LuckPermsUtil.addGroup(map, groupName, null, -1);
modified = true;
desc = "Toggled hide" + yen + " -> " + groupName + " for " + username;
Protocol.S_ACTION_RESPONSE.sendPacket(sender, new ServerboundActionResponseMessage(msg.getPlayer().getUniqueId(), "\u00a7a" + yen + "円皿を表示しました。"));
}
if (desc != null) {
api.getActionLogger().submit(
Action.builder()
.targetType(Action.Target.Type.USER)
.timestamp(Instant.now())
.source(new UUID(0L, 0L))
.sourceName("AziPluginMessaging@" + api.getServerName())
.target(msg.getPlayer().getUniqueId())
.targetName(username)
.description(desc)
.build());
}
}
if (!modified) {
Protocol.S_ACTION_RESPONSE.sendPacket(sender, new ServerboundActionResponseMessage(msg.getPlayer().getUniqueId(), "\u00a7c権限がありません。皿を持ってるのにこのメッセージが出る場合は公式Discordのサポートまでお問い合わせください。"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
import net.azisaba.azipluginmessaging.api.AziPluginMessagingConfig;
import net.azisaba.azipluginmessaging.api.exception.MissingPermissionException;
import net.azisaba.azipluginmessaging.api.protocol.Protocol;
import net.azisaba.azipluginmessaging.api.protocol.message.PlayerWithServerMessage;
import net.azisaba.azipluginmessaging.api.protocol.message.ProxyboundToggleSaraShowMessage;
import net.azisaba.azipluginmessaging.api.protocol.message.ServerboundActionResponseMessage;
import net.azisaba.azipluginmessaging.api.server.PacketSender;
import net.azisaba.azipluginmessaging.api.server.ServerConnection;
import net.azisaba.azipluginmessaging.api.util.LuckPermsUtil;
import net.luckperms.api.LuckPerms;
import net.luckperms.api.LuckPermsProvider;
import net.luckperms.api.actionlog.Action;
import net.luckperms.api.model.data.DataType;
import net.luckperms.api.model.data.NodeMap;
import net.luckperms.api.model.user.User;
Expand All @@ -20,59 +19,46 @@

import java.io.DataInputStream;
import java.io.IOException;
import java.time.Instant;
import java.util.Objects;
import java.util.UUID;

public class ProxyboundToggleSaraShowPacket implements ProxyMessageHandler<PlayerWithServerMessage> {
public class ProxyboundToggleSaraShowPacket implements ProxyMessageHandler<ProxyboundToggleSaraShowMessage> {
@Override
public @NotNull PlayerWithServerMessage read(@NotNull ServerConnection server, @NotNull DataInputStream in) throws IOException {
public @NotNull ProxyboundToggleSaraShowMessage read(@NotNull ServerConnection server, @NotNull DataInputStream in) throws IOException {
String serverName = server.getServerInfo().getName();
String s = AziPluginMessagingConfig.saraShowServers.get(serverName);
Objects.requireNonNull(s, "server is null (saraShowServers entry in config.yml is missing)");
return PlayerWithServerMessage.read(s, in);
return ProxyboundToggleSaraShowMessage.read(s, in);
}

@Override
public void handle(@NotNull PacketSender sender, @NotNull PlayerWithServerMessage msg) {
public void handle(@NotNull PacketSender sender, @NotNull ProxyboundToggleSaraShowMessage msg) {
LuckPerms api = LuckPermsProvider.get();
User user = api.getUserManager().loadUser(msg.getPlayer().getUniqueId()).join();
if (user == null || user.getUsername() == null) {
throw new IllegalArgumentException("User " + msg.getPlayer().getUniqueId() + " could not be found in the LuckPerms database.");
}
String username = user.getUsername();
NodeMap map = user.getData(DataType.NORMAL);
boolean modified = false;
Track track = api.getTrackManager().createAndLoadTrack("sara").join();
for (String groupName : track.getGroups()) {
int yen = Integer.parseInt(groupName.replace("yen", ""));
long yen = Long.parseLong(groupName.replace("yen", ""));
if (!msg.getGroups().isEmpty() && !msg.getGroups().contains(yen)) {
continue;
}
Node nodeSara = LuckPermsUtil.findParentNode(map, groupName, null);
Node nodeHideSara = LuckPermsUtil.findParentNode(map, "hide" + yen, null);
if (nodeSara != null || nodeHideSara != null) {
String actionDesc;
Node nodeSaraShow = LuckPermsUtil.findParentNode(map, "show" + yen + "yen", msg.getServer());
if (nodeSaraShow != null) {
// hide
map.remove(nodeSaraShow);
actionDesc = "Removed show" + yen + "yen from " + username + " in server=" + msg.getServer();
Protocol.S_ACTION_RESPONSE.sendPacket(sender, new ServerboundActionResponseMessage(msg.getPlayer().getUniqueId(), "\u00a7a" + yen + "円皿を非表示にしました。"));
} else {
// show
LuckPermsUtil.addGroup(map, "show" + yen + "yen", msg.getServer(), -1);
actionDesc = "Added show" + yen + "yen to " + username + " in server=" + msg.getServer();
Protocol.S_ACTION_RESPONSE.sendPacket(sender, new ServerboundActionResponseMessage(msg.getPlayer().getUniqueId(), "\u00a7a" + yen + "円皿を表示しました。"));
}
modified = true;
api.getActionLogger().submit(
Action.builder()
.targetType(Action.Target.Type.USER)
.timestamp(Instant.now())
.source(new UUID(0L, 0L))
.sourceName("AziPluginMessaging@" + api.getServerName())
.target(msg.getPlayer().getUniqueId())
.targetName(username)
.description(actionDesc)
.build());
}
}
if (!modified) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package net.azisaba.azipluginmessaging.api.protocol.message;

import net.azisaba.azipluginmessaging.api.entity.Player;
import net.azisaba.azipluginmessaging.api.entity.SimplePlayer;
import org.jetbrains.annotations.NotNull;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

public class ProxyboundToggleSaraHideMessage extends PlayerMessage {
private final Set<Long> groups;

public ProxyboundToggleSaraHideMessage(@NotNull Player player, @NotNull Set<Long> groups) {
super(player);
this.groups = groups;
}

@NotNull
public Set<Long> getGroups() {
return groups;
}

@Override
public void write(@NotNull DataOutputStream out) throws IOException {
super.write(out);
out.writeInt(groups.size());
for (long group : groups) {
out.writeLong(group);
}
}

public static @NotNull ProxyboundToggleSaraHideMessage read(@NotNull DataInputStream in) throws IOException {
Player player = SimplePlayer.read(in);
if (in.available() == 0) {
// backward compatibility
return new ProxyboundToggleSaraHideMessage(player, Collections.emptySet());
}
int size = in.readInt();
Set<Long> groups = new HashSet<>(size);
for (int i = 0; i < size; i++) {
groups.add(in.readLong());
}
return new ProxyboundToggleSaraHideMessage(player, groups);
}
}
Loading

0 comments on commit 60cbce0

Please sign in to comment.