-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ProxyboundGiveNitroSaraMessage and ToggleNitroSaraPacket
- Loading branch information
1 parent
7b1bc09
commit 868bf66
Showing
35 changed files
with
955 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
api/src/main/java/net/azisaba/azipluginmessaging/api/EnvironmentType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package net.azisaba.azipluginmessaging.api; | ||
|
||
public enum EnvironmentType { | ||
SPIGOT, | ||
VELOCITY, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
...va/net/azisaba/azipluginmessaging/api/protocol/handler/ProxyboundGiveNitroSaraPacket.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package net.azisaba.azipluginmessaging.api.protocol.handler; | ||
|
||
import net.azisaba.azipluginmessaging.api.AziPluginMessagingProvider; | ||
import net.azisaba.azipluginmessaging.api.Logger; | ||
import net.azisaba.azipluginmessaging.api.entity.Player; | ||
import net.azisaba.azipluginmessaging.api.entity.SimplePlayer; | ||
import net.azisaba.azipluginmessaging.api.protocol.message.ProxyboundGiveNitroSaraMessage; | ||
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; | ||
import net.luckperms.api.node.Node; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.io.DataInputStream; | ||
import java.io.IOException; | ||
import java.sql.SQLException; | ||
import java.time.Instant; | ||
import java.util.UUID; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
public class ProxyboundGiveNitroSaraPacket implements ProxyMessageHandler<ProxyboundGiveNitroSaraMessage> { | ||
private static final String NITRO_GROUP_NAME = "nitro"; | ||
|
||
@Override | ||
public @NotNull ProxyboundGiveNitroSaraMessage read(@NotNull ServerConnection server, @NotNull DataInputStream in) throws IOException { | ||
Player player = SimplePlayer.read(in); | ||
int time = in.readInt(); | ||
TimeUnit unit = TimeUnit.valueOf(in.readUTF()); | ||
return new ProxyboundGiveNitroSaraMessage(player, time, unit); | ||
} | ||
|
||
@Override | ||
public void handle(@NotNull PacketSender sender, @NotNull ProxyboundGiveNitroSaraMessage msg) throws SQLException { | ||
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."); | ||
} | ||
NodeMap map = user.getData(DataType.NORMAL); | ||
Node node = LuckPermsUtil.findParentNode(map, NITRO_GROUP_NAME, null); | ||
if (node == null) { | ||
LuckPermsUtil.addGroup(map, NITRO_GROUP_NAME, null, -1); | ||
} | ||
Node changeSara = LuckPermsUtil.findParentNode(map, "change" + NITRO_GROUP_NAME, null); | ||
if (changeSara == null) { | ||
LuckPermsUtil.addGroup(map, "change" + NITRO_GROUP_NAME, null, -1); | ||
} | ||
// add time | ||
long time = msg.getUnit().toMillis(msg.getTime()); | ||
long expiresAt = System.currentTimeMillis() + time; | ||
Logger.getCurrentLogger().info("Adding time of rank " + NITRO_GROUP_NAME + " to " + user.getUsername() + " for " + msg.getTime() + " " + msg.getUnit().name().toLowerCase()); | ||
AziPluginMessagingProvider.get().getProxy().runPreparedStatement( | ||
"INSERT INTO `temp_rank` (`player_uuid`, `rank`, `expires_at`, `clear_prefix_on_expire`) VALUES (?, ?, ?, 1) ON DUPLICATE KEY UPDATE `expires_at` = `expires_at` + ?", | ||
(ps) -> { | ||
ps.setString(1, msg.getPlayer().getUniqueId().toString()); | ||
ps.setString(2, NITRO_GROUP_NAME); | ||
ps.setLong(3, expiresAt); | ||
ps.setLong(4, time); | ||
ps.executeUpdate(); | ||
}).join(); | ||
AziPluginMessagingProvider.get().getProxy().runPreparedStatement( | ||
"INSERT INTO `temp_rank` (`player_uuid`, `rank`, `expires_at`, `clear_prefix_on_expire`) VALUES (?, ?, ?, 1) ON DUPLICATE KEY UPDATE `expires_at` = `expires_at` + ?", | ||
(ps) -> { | ||
ps.setString(1, msg.getPlayer().getUniqueId().toString()); | ||
ps.setString(2, "change" + NITRO_GROUP_NAME); | ||
ps.setLong(3, expiresAt); | ||
ps.setLong(4, time); | ||
ps.executeUpdate(); | ||
}).join(); | ||
String username = user.getUsername(); | ||
api.getUserManager().saveUser(user).join(); | ||
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("Added nitro sara to " + username + " (+" + msg.getTime() + " " + msg.getUnit().name().toLowerCase() + ")") | ||
.build()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.