Skip to content

Commit

Permalink
fix: Fix error on ReplaceableChecks in Minecraft 1.19.1
Browse files Browse the repository at this point in the history
  • Loading branch information
4drian3d committed Jul 27, 2022
1 parent 6548137 commit 47071a4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ public static boolean unicode(InfractionPlayer player, AtomicReference<String> s
event.resume();
return true;
}
if(result instanceof final ReplaceableResult replaceableResult){
string.set(replaceableResult.replaceInfraction());
if(event.shouldReplace() && result instanceof final ReplaceableResult replaceable){
string.set(replaceable.replaceInfraction());
event.setString(string.get());
}
}
Expand All @@ -138,7 +138,7 @@ public static boolean caps(InfractionPlayer player, AtomicReference<String> stri
event.resume();
return true;
}
if(result instanceof final IReplaceable replaceable){
if(event.shouldReplace() && result instanceof final IReplaceable replaceable){
string.set(replaceable.replaceInfraction());
event.setString(string.get());
}
Expand All @@ -159,7 +159,7 @@ public static boolean flood(InfractionPlayer player, AtomicReference<String> str
event.resume();
return true;
}
if(result instanceof final IReplaceable replaceable){
if(event.shouldReplace() && result instanceof final IReplaceable replaceable){
string.set(replaceable.replaceInfraction());
event.setString(string.get());
}
Expand All @@ -180,7 +180,7 @@ public static boolean regular(InfractionPlayer player, AtomicReference<String> s
event.resume();
return true;
}
if(result instanceof final IReplaceable replaceable){
if(event.shouldReplace() && result instanceof final IReplaceable replaceable){
string.set(replaceable.replaceInfraction());
event.setString(string.get());
}
Expand All @@ -195,7 +195,7 @@ public static boolean spam(InfractionPlayer player, AtomicReference<String> stri
plugin.getLogger().error("An Error ocurred on Spam Check", e);
return new Result("", false);
}).join();
if(GeneralUtils.cooldownSpamCheck(result, player, plugin.getConfig())
if (GeneralUtils.cooldownSpamCheck(result, player, plugin.getConfig())
&& GeneralUtils.callViolationEvent(new EventBundle(player, string.get(), InfractionType.SPAM, result, event.source()), plugin)
) {
event.cancel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@ public void setString(String string) {
public SourceType source() {
return SourceType.CHAT;
}

@Override
public boolean shouldReplace() {
return event.getPlayer().getProtocolVersion().getProtocol() < 760;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.velocitypowered.api.event.Continuation;
import com.velocitypowered.api.event.command.CommandExecuteEvent;
import com.velocitypowered.api.event.command.CommandExecuteEvent.CommandResult;
import com.velocitypowered.api.proxy.Player;

import me.dreamerzero.chatregulator.enums.SourceType;

Expand All @@ -27,4 +28,12 @@ public SourceType source() {
return SourceType.COMMAND;
}

@Override
public boolean shouldReplace() {
if(event.getCommandSource() instanceof Player player) {
return player.getProtocolVersion().getProtocol() < 760;
}
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ public void resume() {
}

public abstract SourceType source();

// Fixes chat messages not replaceable on Minecraft 1.19.1, muchas gracias Mojang
// https://github.com/PaperMC/Velocity/pull/772/commits/eb32a765206383a828445ba11789c9a88ca2b585#diff-841534de988d03173f1983984bc82b9fe24e2bd3296db704a3bd6412b32674ea
public abstract boolean shouldReplace();
}

0 comments on commit 47071a4

Please sign in to comment.