-
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.
- Loading branch information
1 parent
4558cbc
commit f498c12
Showing
21 changed files
with
710 additions
and
168 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
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
28 changes: 28 additions & 0 deletions
28
...main/java/net/azisaba/azipluginmessaging/api/protocol/handler/ProxyboundPunishPacket.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,28 @@ | ||
package net.azisaba.azipluginmessaging.api.protocol.handler; | ||
|
||
import net.azisaba.azipluginmessaging.api.AziPluginMessagingConfig; | ||
import net.azisaba.azipluginmessaging.api.AziPluginMessagingProvider; | ||
import net.azisaba.azipluginmessaging.api.Logger; | ||
import net.azisaba.azipluginmessaging.api.protocol.Protocol; | ||
import net.azisaba.azipluginmessaging.api.protocol.message.EmptyMessage; | ||
import net.azisaba.azipluginmessaging.api.protocol.message.ProxyboundPunishMessage; | ||
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; | ||
|
||
public class ProxyboundPunishPacket implements ProxyMessageHandler<ProxyboundPunishMessage> { | ||
@Override | ||
public @NotNull ProxyboundPunishMessage read(@NotNull ServerConnection server, @NotNull DataInputStream in) throws IOException { | ||
String serverName = server.getServerInfo().getName(); | ||
serverName = AziPluginMessagingConfig.servers.getOrDefault(serverName, serverName); | ||
return ProxyboundPunishMessage.read(serverName, in); | ||
} | ||
|
||
@Override | ||
public void handle(@NotNull PacketSender sender, @NotNull ProxyboundPunishMessage msg) throws Exception { | ||
AziPluginMessagingProvider.get().getProxy().handle(msg); | ||
} | ||
} |
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
132 changes: 132 additions & 0 deletions
132
...ain/java/net/azisaba/azipluginmessaging/api/protocol/message/ProxyboundPunishMessage.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,132 @@ | ||
package net.azisaba.azipluginmessaging.api.protocol.message; | ||
|
||
import net.azisaba.azipluginmessaging.api.entity.Player; | ||
import net.azisaba.azipluginmessaging.api.entity.SimplePlayer; | ||
import net.azisaba.azipluginmessaging.api.punishment.PunishmentType; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.io.DataInputStream; | ||
import java.io.DataOutputStream; | ||
import java.io.IOException; | ||
import java.util.Objects; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
public class ProxyboundPunishMessage extends PlayerWithServerMessage { | ||
private final Player sender; | ||
private final PunishmentType type; | ||
private final String reason; | ||
private final int time; | ||
private final TimeUnit unit; | ||
|
||
public ProxyboundPunishMessage( | ||
@NotNull String server, | ||
@NotNull Player player, | ||
@NotNull Player sender, | ||
@NotNull PunishmentType type, | ||
@NotNull String reason, | ||
int time, | ||
@Nullable TimeUnit unit) { | ||
super(server, player); | ||
if (type.name().startsWith("TEMP_")) { | ||
if (time <= 0 || unit == null) { | ||
throw new IllegalArgumentException("Time and unit must be set for temporary punishments"); | ||
} | ||
} else { | ||
if (time != 0 || unit != null) { | ||
throw new IllegalArgumentException("Time and unit must not be set for permanent punishments"); | ||
} | ||
} | ||
this.sender = Objects.requireNonNull(sender, "sender"); | ||
this.type = Objects.requireNonNull(type, "type"); | ||
this.reason = Objects.requireNonNull(reason, "reason"); | ||
this.time = time; | ||
this.unit = unit; | ||
} | ||
|
||
public @NotNull Player getSender() { | ||
return sender; | ||
} | ||
|
||
public @NotNull PunishmentType getType() { | ||
return type; | ||
} | ||
|
||
public @NotNull String getReason() { | ||
return reason; | ||
} | ||
|
||
/** | ||
* Returns the duration of the punishment. If the punishment is permanent, it returns 0. | ||
* @return the duration of the punishment | ||
*/ | ||
public int getTime() { | ||
return unit == null ? 0 : time; | ||
} | ||
|
||
/** | ||
* Returns the unit of the duration. If the unit is null, it means the punishment is permanent. | ||
* @return the unit of the duration | ||
*/ | ||
public @Nullable TimeUnit getUnit() { | ||
return unit; | ||
} | ||
|
||
/** | ||
* Returns whether the punishment is temporary or not. | ||
* @return whether the punishment is temporary or not | ||
*/ | ||
public boolean isTemporary() { | ||
return getTime() > 0 && unit != null; | ||
} | ||
|
||
/** | ||
* Returns whether the punishment is permanent or not. | ||
* @return whether the punishment is permanent or not | ||
*/ | ||
public boolean isPermanent() { | ||
return !isTemporary(); // time == 0 || unit == null | ||
} | ||
|
||
@Override | ||
public void write(@NotNull DataOutputStream out) throws IOException { | ||
super.write(out); | ||
out.writeUTF(sender.getUniqueId().toString()); | ||
out.writeBoolean(sender.getUsername() != null); | ||
if (sender.getUsername() != null) { | ||
out.writeUTF(sender.getUsername()); | ||
} | ||
out.writeUTF(type.name()); | ||
out.writeUTF(reason); | ||
out.writeInt(time); | ||
out.writeBoolean(unit != null); | ||
if (unit != null) { | ||
out.writeUTF(unit.name()); | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ProxyboundPunishMessage{" + | ||
"sender=" + sender + | ||
", type=" + type + | ||
", reason='" + reason + '\'' + | ||
", time=" + time + | ||
", unit=" + unit + | ||
", server='" + server + '\'' + | ||
", player=" + player + | ||
'}'; | ||
} | ||
|
||
public static @NotNull ProxyboundPunishMessage read(@NotNull String server, @NotNull DataInputStream in) throws IOException { | ||
return new ProxyboundPunishMessage( | ||
server, | ||
SimplePlayer.read(in), | ||
SimplePlayer.read(in), | ||
PunishmentType.valueOf(in.readUTF()), | ||
in.readUTF(), | ||
in.readInt(), | ||
in.readBoolean() ? TimeUnit.valueOf(in.readUTF()) : null | ||
); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
api/src/main/java/net/azisaba/azipluginmessaging/api/punishment/PunishmentType.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,15 @@ | ||
package net.azisaba.azipluginmessaging.api.punishment; | ||
|
||
public enum PunishmentType { | ||
BAN, | ||
TEMP_BAN, | ||
IP_BAN, | ||
TEMP_IP_BAN, | ||
MUTE, | ||
TEMP_MUTE, | ||
IP_MUTE, | ||
TEMP_IP_MUTE, | ||
WARNING, | ||
CAUTION, | ||
KICK, | ||
} |
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
Binary file not shown.
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
Oops, something went wrong.