-
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 CheckRankExpirationPacket (but these will change in the future)
- Loading branch information
1 parent
868bf66
commit 9c62824
Showing
12 changed files
with
250 additions
and
7 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
35 changes: 35 additions & 0 deletions
35
.../azisaba/azipluginmessaging/api/protocol/handler/ProxyboundCheckRankExpirationPacket.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,35 @@ | ||
package net.azisaba.azipluginmessaging.api.protocol.handler; | ||
|
||
import net.azisaba.azipluginmessaging.api.AziPluginMessagingProvider; | ||
import net.azisaba.azipluginmessaging.api.protocol.Protocol; | ||
import net.azisaba.azipluginmessaging.api.protocol.message.ProxyboundCheckRankExpirationMessage; | ||
import net.azisaba.azipluginmessaging.api.protocol.message.ServerboundCheckRankExpirationMessage; | ||
import net.azisaba.azipluginmessaging.api.server.PacketSender; | ||
import net.azisaba.azipluginmessaging.api.server.ServerConnection; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.io.DataInputStream; | ||
import java.io.IOException; | ||
import java.sql.ResultSet; | ||
|
||
public class ProxyboundCheckRankExpirationPacket implements ProxyMessageHandler<ProxyboundCheckRankExpirationMessage> { | ||
@Override | ||
public @NotNull ProxyboundCheckRankExpirationMessage read(@NotNull ServerConnection server, @NotNull DataInputStream in) throws IOException { | ||
return ProxyboundCheckRankExpirationMessage.read(in); | ||
} | ||
|
||
@Override | ||
public void handle(@NotNull PacketSender sender, @NotNull ProxyboundCheckRankExpirationMessage msg) throws Exception { | ||
long expiresAt = AziPluginMessagingProvider.get().getProxy().getPreparedStatement("SELECT `expires_at` FROM `temp_rank` WHERE `player_uuid` = ? AND `rank` = ?", ps -> { | ||
ps.setString(1, msg.getPlayer().getUniqueId().toString()); | ||
ps.setString(2, msg.getRank()); | ||
ResultSet rs = ps.executeQuery(); | ||
if (!rs.next()) { | ||
return -1L; | ||
} | ||
return rs.getLong("expires_at"); | ||
}).join(); | ||
ServerboundCheckRankExpirationMessage message = new ServerboundCheckRankExpirationMessage(msg.getPlayer(), msg.getRank(), expiresAt); | ||
Protocol.S_CHECK_RANK_EXPIRATION.sendPacket(sender, message); | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
...azisaba/azipluginmessaging/api/protocol/handler/ServerboundCheckRankExpirationPacket.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,21 @@ | ||
package net.azisaba.azipluginmessaging.api.protocol.handler; | ||
|
||
import net.azisaba.azipluginmessaging.api.AziPluginMessagingProvider; | ||
import net.azisaba.azipluginmessaging.api.protocol.message.ServerboundCheckRankExpirationMessage; | ||
import net.azisaba.azipluginmessaging.api.server.PacketSender; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.io.DataInputStream; | ||
import java.io.IOException; | ||
|
||
public class ServerboundCheckRankExpirationPacket implements ServerMessageHandler<ServerboundCheckRankExpirationMessage> { | ||
@Override | ||
public @NotNull ServerboundCheckRankExpirationMessage read(@NotNull DataInputStream in) throws IOException { | ||
return ServerboundCheckRankExpirationMessage.read(in); | ||
} | ||
|
||
@Override | ||
public void handle(@NotNull PacketSender sender, @NotNull ServerboundCheckRankExpirationMessage msg) throws Exception { | ||
AziPluginMessagingProvider.get().getServer().handle(msg); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...azisaba/azipluginmessaging/api/protocol/message/ProxyboundCheckRankExpirationMessage.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,42 @@ | ||
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.ApiStatus; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.io.DataInputStream; | ||
import java.io.DataOutputStream; | ||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
@ApiStatus.Internal // this packet WILL change | ||
public class ProxyboundCheckRankExpirationMessage extends PlayerMessage { | ||
private final String rank; | ||
|
||
public ProxyboundCheckRankExpirationMessage(@NotNull Player player, @NotNull String rank) { | ||
super(player); | ||
this.rank = Objects.requireNonNull(rank, "rank"); | ||
} | ||
|
||
/** | ||
* Returns the requested rank. | ||
* @return the rank | ||
*/ | ||
@NotNull | ||
public String getRank() { | ||
return rank; | ||
} | ||
|
||
@Override | ||
public void write(@NotNull DataOutputStream out) throws IOException { | ||
super.write(out); | ||
out.writeUTF(rank); | ||
} | ||
|
||
public static @NotNull ProxyboundCheckRankExpirationMessage read(@NotNull DataInputStream in) throws IOException { | ||
Player player = SimplePlayer.read(in); | ||
String rank = in.readUTF(); | ||
return new ProxyboundCheckRankExpirationMessage(player, rank); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
...zisaba/azipluginmessaging/api/protocol/message/ServerboundCheckRankExpirationMessage.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,64 @@ | ||
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.ApiStatus; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.io.DataInputStream; | ||
import java.io.DataOutputStream; | ||
import java.io.IOException; | ||
import java.util.Objects; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
@ApiStatus.Internal // this packet WILL change | ||
public class ServerboundCheckRankExpirationMessage extends PlayerMessage { | ||
private final String rank; | ||
private final long expiresAt; | ||
|
||
public ServerboundCheckRankExpirationMessage(@NotNull Player player, @NotNull String rank, long expiresAt) { | ||
super(player); | ||
this.rank = Objects.requireNonNull(rank, "rank"); | ||
this.expiresAt = expiresAt; | ||
} | ||
|
||
/** | ||
* Returns the rank which the server has requested. | ||
* @return the rank | ||
*/ | ||
@NotNull | ||
public String getRank() { | ||
return rank; | ||
} | ||
|
||
/** | ||
* Returns the expiration time of the player's rank in milliseconds.<br> | ||
* Special cases:<br> | ||
* <ul> | ||
* <li>Returns 0 if the rank never expires</li> | ||
* <li>Returns -1 if the player doesn't have the temporary rank.</li> | ||
* </ul> | ||
* @return expiration time | ||
*/ | ||
public long getExpiresAt() { | ||
return expiresAt; | ||
} | ||
|
||
public long getExpiresAt(@NotNull TimeUnit unit) { | ||
return unit.convert(expiresAt, TimeUnit.MILLISECONDS); | ||
} | ||
|
||
@Override | ||
public void write(@NotNull DataOutputStream out) throws IOException { | ||
super.write(out); | ||
out.writeUTF(rank); | ||
out.writeLong(expiresAt); | ||
} | ||
|
||
public static @NotNull ServerboundCheckRankExpirationMessage read(@NotNull DataInputStream in) throws IOException { | ||
Player player = SimplePlayer.read(in); | ||
String rank = in.readUTF(); | ||
long expiresAt = in.readLong(); | ||
return new ServerboundCheckRankExpirationMessage(player, rank, expiresAt); | ||
} | ||
} |
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
34 changes: 34 additions & 0 deletions
34
...src/main/java/net/azisaba/azipluginmessaging/spigot/event/CheckedRankExpirationEvent.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,34 @@ | ||
package net.azisaba.azipluginmessaging.spigot.event; | ||
|
||
import net.azisaba.azipluginmessaging.api.protocol.message.ServerboundCheckRankExpirationMessage; | ||
import org.bukkit.event.Event; | ||
import org.bukkit.event.HandlerList; | ||
import org.jetbrains.annotations.Contract; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class CheckedRankExpirationEvent extends Event { | ||
private static final HandlerList HANDLER_LIST = new HandlerList(); | ||
|
||
private final ServerboundCheckRankExpirationMessage msg; | ||
|
||
public CheckedRankExpirationEvent(@NotNull ServerboundCheckRankExpirationMessage msg) { | ||
this.msg = msg; | ||
} | ||
|
||
@NotNull | ||
public ServerboundCheckRankExpirationMessage getMsg() { | ||
return msg; | ||
} | ||
|
||
@Override | ||
public HandlerList getHandlers() { | ||
return HANDLER_LIST; | ||
} | ||
|
||
@SuppressWarnings("unused") // used by spigot | ||
@Contract(pure = true) | ||
@NotNull | ||
public static HandlerList getHandlerList() { | ||
return HANDLER_LIST; | ||
} | ||
} |
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