Skip to content

Commit

Permalink
AntiPopup 8
Browse files Browse the repository at this point in the history
  • Loading branch information
KaspianDev committed May 7, 2024
1 parent b6e716f commit dbedb31
Show file tree
Hide file tree
Showing 46 changed files with 577 additions and 190 deletions.
12 changes: 9 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
plugins {
id "java"
id "com.github.johnrengelman.shadow" version "7.1.2"
id "io.github.goooler.shadow" version "${shadowVer}"
id "org.jetbrains.gradle.plugin.idea-ext" version "1.0.1"
}

dependencies {
implementation project(path: ":main", configuration: "shadow")
implementation project(path: ":spigot", configuration: "shadow")
implementation project(path: ":velocity", configuration: "shadow")
}

tasks {
Expand All @@ -18,7 +20,7 @@ tasks {

allprojects {
group = "com.github.kaspiandev.antipopup"
version = "7.3"
version = "8"

repositories {
mavenCentral()
Expand All @@ -35,6 +37,10 @@ allprojects {
name = "No."
url = "https://repo.viaversion.com"
}
maven {
name = "codemc"
url = "https://repo.codemc.io/repository/maven-releases/"
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
userdevVer=1.5.9
userdevVer=1.7.0
shadowVer=8.1.7
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
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.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
zipStorePath=wrapper/dists
Binary file added lib/packetevents-api-2.2.1.jar
Binary file not shown.
Binary file added lib/packetevents-spigot-2.2.1.jar
Binary file not shown.
Binary file added lib/packetevents-velocity-2.2.1.jar
Binary file not shown.

This file was deleted.

7 changes: 7 additions & 0 deletions nms/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
id "java"
}

dependencies {
compileOnly "org.spigotmc:spigot-api:1.19.4-R0.1-SNAPSHOT"
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.github.kaspiandev.antipopup.nms;
package com.github.kaspiandev.antipopup.spigot.nms;

import org.bukkit.entity.Player;

public interface AbstractInjector {
public interface PacketInjector {

void inject(Player player);

void uninject(Player player);

}
}
3 changes: 2 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ pluginManagement {
}

rootProject.name = "AntiPopup"
include "main", "shared", "v1.19.2", "v1.19.3", "v1.19.4", "v1.20", "v1.20.2", "v1.20.3"
include "spigot", "shared", "nms", "v1.19.2", "v1.19.3", "v1.19.4", "v1.20.1", "v1.20.2", "v1.20.4", "v1.20.6", "velocity"

10 changes: 8 additions & 2 deletions shared/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,11 @@ plugins {
}

dependencies {
compileOnly "org.spigotmc:spigot-api:1.19.3-R0.1-SNAPSHOT"
}
compileOnly "org.apache.logging.log4j:log4j-core:2.19.0"
compileOnly "net.kyori:adventure-api:4.14.0"

implementation "dev.dejvokep:boosted-yaml:1.3"
implementation "net.kyori:adventure-text-serializer-gson:4.14.0"
implementation "net.kyori:adventure-platform-bukkit:4.3.1"
implementation files("../lib/packetevents-api-2.2.1.jar")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package com.github.kaspiandev.antipopup.config;

import dev.dejvokep.boostedyaml.YamlDocument;
import dev.dejvokep.boostedyaml.dvs.versioning.BasicVersioning;
import dev.dejvokep.boostedyaml.settings.dumper.DumperSettings;
import dev.dejvokep.boostedyaml.settings.general.GeneralSettings;
import dev.dejvokep.boostedyaml.settings.loader.LoaderSettings;
import dev.dejvokep.boostedyaml.settings.updater.UpdaterSettings;

import java.io.File;
import java.io.IOException;
import java.util.Objects;

public class APConfig {

private final YamlDocument document;

public APConfig(File folder, ClassLoader loader) throws IOException {
this.document = YamlDocument.create(new File(folder, "config.yml"),
Objects.requireNonNull(loader.getResourceAsStream("config.yml")),
GeneralSettings.DEFAULT, LoaderSettings.builder().setAutoUpdate(true).build(),
DumperSettings.DEFAULT,
UpdaterSettings.builder().setVersioning(new BasicVersioning("config-version"))
.build());
}

public boolean isBstats() {
return document.getBoolean("bstats");
}

public boolean isFilterNotSecure() {
return document.getBoolean("filter-not-secure");
}

public boolean isSendHeader() {
return document.getBoolean("send-header");
}

public boolean isAutoSetup() {
return document.getBoolean("auto-setup");
}

public boolean isBlockChatReports() {
return document.getBoolean("block-chat-reports");
}

public void setBlockChatReports(boolean value) {
document.set("block-chat-reports", value);
}

public boolean isClickableUrls() {
return document.getBoolean("clickable-urls");
}

public String getPropertiesLocation() {
return document.getString("properties-location");
}

public boolean isFirstRun() {
return document.getBoolean("first-run");
}

public void setFirstRun(boolean value) {
document.set("first-run", value);
}

public boolean isAskBstats() {
return document.getBoolean("ask-bstats");
}

public void setAskBstats(boolean value) {
document.set("ask-bstats", value);
}

public boolean isSetupMode() {
return document.getBoolean("setup-mode");
}

public void setSetupMode(boolean value) {
document.set("setup-mode", value);
}

public boolean isShowPopup() {
return document.getBoolean("show-popup");
}

public void save() {
try {
document.save();
} catch (IOException ex) {
throw new RuntimeException("Could not save the config.", ex);
}
}

public void reload() {
try {
document.reload();
} catch (IOException ex) {
throw new RuntimeException("Could not reload the config.", ex);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.github.kaspiandev.antipopup.format;

public interface ChatFormat {


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.github.kaspiandev.antipopup.listener;

import com.github.kaspiandev.antipopup.platform.Platform;
import com.github.retrooper.packetevents.event.PacketListenerAbstract;
import com.github.retrooper.packetevents.event.PacketListenerPriority;
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
import com.github.retrooper.packetevents.event.PacketSendEvent;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerJoinGame;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerServerData;
import com.github.retrooper.packetevents.wrapper.status.server.WrapperStatusServerResponse;
import com.google.gson.JsonObject;

public class PacketEventsListener extends PacketListenerAbstract {

private final Platform platform;

public PacketEventsListener(Platform platform) {
super(PacketListenerPriority.LOW);
this.platform = platform;
}

@Override
public void onPacketSend(PacketSendEvent event) {
PacketTypeCommon packetType = event.getPacketType();
ClientVersion clientVersion = event.getUser().getClientVersion();
if (packetType == PacketType.Status.Server.RESPONSE
&& clientVersion.isNewerThan(ClientVersion.V_1_18_2)) {
WrapperStatusServerResponse wrapper = new WrapperStatusServerResponse(event);
JsonObject newObj = wrapper.getComponent();
newObj.addProperty("preventsChatReports", true);
wrapper.setComponent(newObj);
} else if (packetType == PacketType.Play.Server.SERVER_DATA
&& clientVersion.isOlderThan(ClientVersion.V_1_20_5)
&& !platform.getApConfig().isShowPopup()) {
WrapperPlayServerServerData wrapper = new WrapperPlayServerServerData(event);
wrapper.setEnforceSecureChat(true);
} else if (packetType == PacketType.Play.Server.JOIN_GAME
&& clientVersion.isNewerThan(ClientVersion.V_1_20_3)
&& !platform.getApConfig().isShowPopup()) {
WrapperPlayServerJoinGame wrapper = new WrapperPlayServerJoinGame(event);
wrapper.setEnforcesSecureChat(true);
} else if (packetType == PacketType.Play.Server.PLAYER_CHAT_HEADER
&& !platform.getApConfig().isSendHeader()) {
event.setCancelled(true);
}
}

@Override
public void onPacketReceive(PacketReceiveEvent event) {
PacketTypeCommon packetType = event.getPacketType();
if (packetType == PacketType.Play.Client.CHAT_SESSION_UPDATE) {
event.setCancelled(true);
}
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.github.kaspiandev.antipopup;
package com.github.kaspiandev.antipopup.log;

import dev.dejvokep.boostedyaml.YamlDocument;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Marker;
Expand All @@ -11,12 +10,9 @@

public class LogFilter implements Filter {

private final YamlDocument yamlDoc = AntiPopup.getYamlDoc();

@Override
public Filter.Result filter(LogEvent event) {
if (yamlDoc.getBoolean("filter-not-secure")
&& event.getMessage().getFormattedMessage().contains("[Not Secure]")
if (event.getMessage().getFormattedMessage().contains("[Not Secure]")
&& event.getLoggerName().equals("net.minecraft.server.MinecraftServer")
&& event.getLevel() == Level.INFO) {
LogManager.getLogger(event.getLoggerName()).log(event.getLevel(),
Expand Down Expand Up @@ -131,4 +127,4 @@ public boolean isStopped() {
return false;
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.github.kaspiandev.antipopup.platform;

import com.github.kaspiandev.antipopup.config.APConfig;

import java.util.UUID;

public abstract class Platform {

private final APConfig apConfig;

protected Platform(APConfig apConfig) {
this.apConfig = apConfig;
}

public APConfig getApConfig() {
return apConfig;
}

public abstract String getPlayerName(UUID playerUUID);

}
Loading

0 comments on commit dbedb31

Please sign in to comment.