Skip to content

Commit

Permalink
Remove hard-coded sara groups
Browse files Browse the repository at this point in the history
  • Loading branch information
acrylic-style committed Jul 1, 2022
1 parent f696c31 commit 7b1bc09
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import net.azisaba.azipluginmessaging.api.protocol.message.ProxyboundGiveSaraMessage;
import net.azisaba.azipluginmessaging.api.server.PacketSender;
import net.azisaba.azipluginmessaging.api.server.ServerConnection;
import net.azisaba.azipluginmessaging.api.util.Constants;
import net.azisaba.azipluginmessaging.api.util.LuckPermsUtil;
import net.luckperms.api.LuckPerms;
import net.luckperms.api.LuckPermsProvider;
Expand All @@ -14,6 +13,7 @@
import net.luckperms.api.model.data.NodeMap;
import net.luckperms.api.model.user.User;
import net.luckperms.api.node.Node;
import net.luckperms.api.track.Track;
import org.jetbrains.annotations.NotNull;

import java.io.DataInputStream;
Expand All @@ -34,8 +34,10 @@ public void handle(@NotNull PacketSender sender, @NotNull ProxyboundGiveSaraMess
if (user == null || user.getUsername() == null) {
throw new IllegalArgumentException("User " + msg.getPlayer().getUniqueId() + " could not be found in the LuckPerms database.");
}
if (!Constants.SARA_GROUPS.contains(msg.getAmount())) {
throw new IllegalArgumentException("Invalid sara group: " + msg.getAmount());
String groupName = msg.getAmount() + "sara";
Track track = api.getTrackManager().createAndLoadTrack("sara").join();
if (!track.containsGroup(groupName)) {
throw new IllegalArgumentException("Group is not in a track: " + groupName);
}
String username = user.getUsername();
boolean modified = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void handle(@NotNull PacketSender sender, @NotNull ProxyboundSetRankMessa
}
boolean modified = false;
for (String group : track.getGroups()) {
if (msg.getServer().equals(group)) continue;
if (msg.getRank().equals(group)) continue;
Node node = LuckPermsUtil.findParentNode(nodes, group, msg.getServer());
if (node != null) {
nodes.remove(node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
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.Constants;
import net.azisaba.azipluginmessaging.api.util.LuckPermsUtil;
import net.luckperms.api.LuckPerms;
import net.luckperms.api.LuckPermsProvider;
Expand All @@ -15,6 +14,7 @@
import net.luckperms.api.model.data.NodeMap;
import net.luckperms.api.model.user.User;
import net.luckperms.api.node.Node;
import net.luckperms.api.track.Track;
import org.jetbrains.annotations.NotNull;

import java.io.DataInputStream;
Expand All @@ -38,26 +38,28 @@ public void handle(@NotNull PacketSender sender, @NotNull PlayerMessage msg) {
String username = user.getUsername();
NodeMap map = user.getData(DataType.NORMAL);
boolean modified = false;
for (int saraGroup : Constants.SARA_GROUPS) {
Node nodeSara = LuckPermsUtil.findParentNode(map, saraGroup + "yen", null);
Node nodeHideSara = LuckPermsUtil.findParentNode(map, "hide" + saraGroup, null);
Track track = api.getTrackManager().createAndLoadTrack("sara").join();
for (String groupName : track.getGroups()) {
int yen = Integer.parseInt(groupName.replace("yen", ""));
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" + saraGroup, null, -1);
LuckPermsUtil.addGroup(map, "hide" + yen, null, -1);
}
modified = true;
desc = "Toggled " + saraGroup + "yen -> hide" + saraGroup + " for " + username;
Protocol.S_ACTION_RESPONSE.sendPacket(sender, new ServerboundActionResponseMessage(msg.getPlayer().getUniqueId(), "\u00a7a" + saraGroup + "円皿を非表示にしました。"));
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, saraGroup + "yen", null, -1);
LuckPermsUtil.addGroup(map, groupName, null, -1);
modified = true;
desc = "Toggled hide" + saraGroup + " -> " + saraGroup + "yen for " + username;
Protocol.S_ACTION_RESPONSE.sendPacket(sender, new ServerboundActionResponseMessage(msg.getPlayer().getUniqueId(), "\u00a7a" + saraGroup + "円皿を表示しました。"));
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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
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.Constants;
import net.azisaba.azipluginmessaging.api.util.LuckPermsUtil;
import net.luckperms.api.LuckPerms;
import net.luckperms.api.LuckPermsProvider;
Expand All @@ -16,6 +15,7 @@
import net.luckperms.api.model.data.NodeMap;
import net.luckperms.api.model.user.User;
import net.luckperms.api.node.Node;
import net.luckperms.api.track.Track;
import org.jetbrains.annotations.NotNull;

import java.io.DataInputStream;
Expand Down Expand Up @@ -43,22 +43,24 @@ public void handle(@NotNull PacketSender sender, @NotNull PlayerWithServerMessag
String username = user.getUsername();
NodeMap map = user.getData(DataType.NORMAL);
boolean modified = false;
for (int saraGroup : Constants.SARA_GROUPS) {
Node nodeSara = LuckPermsUtil.findParentNode(map, saraGroup + "yen", null);
Node nodeHideSara = LuckPermsUtil.findParentNode(map, "hide" + saraGroup, null);
Track track = api.getTrackManager().createAndLoadTrack("sara").join();
for (String groupName : track.getGroups()) {
int yen = Integer.parseInt(groupName.replace("sara", ""));
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" + saraGroup + "yen", msg.getServer());
Node nodeSaraShow = LuckPermsUtil.findParentNode(map, "show" + yen + "yen", msg.getServer());
if (nodeSaraShow != null) {
// hide
map.remove(nodeSaraShow);
actionDesc = "Removed show" + saraGroup + "yen from " + username + " in server=" + msg.getServer();
Protocol.S_ACTION_RESPONSE.sendPacket(sender, new ServerboundActionResponseMessage(msg.getPlayer().getUniqueId(), "\u00a7a" + saraGroup + "円皿を非表示にしました。"));
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" + saraGroup + "yen", msg.getServer(), -1);
actionDesc = "Added show" + saraGroup + "yen to " + username + " in server=" + msg.getServer();
Protocol.S_ACTION_RESPONSE.sendPacket(sender, new ServerboundActionResponseMessage(msg.getPlayer().getUniqueId(), "\u00a7a" + saraGroup + "円皿を表示しました。"));
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(
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group = "net.azisaba.azipluginmessaging"
version = "2.2.0-SNAPSHOT"
version = "2.2.1-SNAPSHOT"

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;

@Plugin(id = "azi-plugin-messaging", name = "AziPluginMessaging", version = "1.0.0",
@Plugin(id = "azi-plugin-messaging", name = "AziPluginMessaging", version = "2.2.1-SNAPSHOT",
dependencies = @Dependency(id = "luckperms"))
public class VelocityPlugin {
@Inject
Expand Down

0 comments on commit 7b1bc09

Please sign in to comment.