This commit is contained in:
parent
713749dc78
commit
6de72981e6
2 changed files with 32 additions and 1 deletions
|
@ -9,21 +9,43 @@ import finalforeach.cosmicreach.networking.server.ServerSingletons;
|
|||
import io.netty.channel.ChannelHandlerContext;
|
||||
import net.pietru.cookie_utils.api.TextCommands;
|
||||
import net.pietru.cookie_utils.setups.Setup;
|
||||
import net.pietru.cookie_utils.utils.MessageInfo;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Mixin(MessagePacket.class)
|
||||
public class MessagePacketMixin {
|
||||
@Shadow
|
||||
public String playerUniqueId;
|
||||
@Shadow public String message;
|
||||
|
||||
private static Map<String, MessageInfo> ply_msgs = new HashMap<>();
|
||||
|
||||
@Inject(method = "handle", at = @At("HEAD"), cancellable = true)
|
||||
private void event_on_message(CallbackInfo ci, @Local NetworkIdentity identity, @Local ChannelHandlerContext ctx){
|
||||
if (identity.getSide() != NetworkSide.CLIENT) {
|
||||
if (ply_msgs.containsKey(playerUniqueId)){
|
||||
MessageInfo msg = ply_msgs.get(playerUniqueId);
|
||||
long time = System.currentTimeMillis();
|
||||
if (msg.last_msg+msg.msg_delay>time || msg.last_msg_txt.equals(message)) {
|
||||
msg.msg_delay += 1000;
|
||||
ci.cancel();
|
||||
} else
|
||||
msg.msg_delay=1000;
|
||||
|
||||
msg.last_msg = System.currentTimeMillis();
|
||||
msg.last_msg_txt=message;
|
||||
} else {
|
||||
ply_msgs.put(playerUniqueId,new MessageInfo());
|
||||
}
|
||||
|
||||
if (identity.getSide() != NetworkSide.CLIENT && ci.isCancelled()) {
|
||||
Account account = ServerSingletons.getAccount(identity);
|
||||
if (message.startsWith(":")) {
|
||||
String cmd = message.replaceFirst(":","");
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
package net.pietru.cookie_utils.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class MessageInfo {
|
||||
public long last_msg = 0;
|
||||
public long msg_delay = 0;
|
||||
public String last_msg_txt = "";
|
||||
}
|
Loading…
Reference in a new issue