Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5.2 #28

Merged
merged 9 commits into from
Jan 8, 2023
Merged

5.2 #28

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@ jobs:
with:
java-version: 17
distribution: temurin
cache: gradle

- name: Make gradlew executable
run: chmod +x ./gradlew

- uses: SpraxDev/Action-SpigotMC@v4
with:
versions: 1.19.3
remapped: true

- name: Build artifacts
run: ./gradlew build
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,5 @@ run/

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar

buildtools
22 changes: 11 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
plugins {
id "java"
id "com.github.johnrengelman.shadow" version "7.1.2"
id "io.papermc.paperweight.userdev" version "1.4.1"
}

group = "com.github.kaspiandev"
version = "5.1"
version = "5.2"

repositories {
mavenCentral()
mavenLocal()
maven { url "https://repo.codemc.io/repository/maven-snapshots/" }
maven {
name = "spigotmc-repo"
Expand All @@ -24,23 +26,23 @@ repositories {
}

dependencies {
compileOnly "org.spigotmc:spigot-api:1.19.2-R0.1-SNAPSHOT"
compileOnly "org.spigotmc:spigot:1.19.3-R0.1-SNAPSHOT:remapped-mojang"
compileOnly "dev.dejvokep:boosted-yaml-spigot:1.3"
compileOnly "org.apache.commons:commons-configuration2:2.8.0"
compileOnly "com.viaversion:viaversion:4.4.1"
compileOnly "com.viaversion:viaversion:4.5.1"
compileOnly "org.apache.logging.log4j:log4j-core:2.19.0"

implementation "org.bstats:bstats-bukkit:3.0.0"
implementation "com.github.retrooper.packetevents:spigot:2.0.0-20221209.211024-75"
implementation "com.github.retrooper.packetevents:spigot:2.0.0-20230103.215431-105"

paperweightDevelopmentBundle "io.papermc.paper:dev-bundle:1.19.3-R0.1-SNAPSHOT"
}

tasks {
build {
dependsOn(shadowJar)
assemble {
dependsOn(reobfJar)
}
shadowJar {
archiveName = "AntiPopup-${version}.jar"

minimize()
relocate("io.github.retrooper.packetevents", "com.github.kaspiandev.antipopup.libs.io.github.retrooper.packetevents")
relocate("com.github.retrooper.packetevents", "com.github.kaspiandev.antipopup.libs.com.github.retrooper.packetevents")
Expand All @@ -53,8 +55,6 @@ tasks {

def targetJavaVersion = 17

jar.enabled = false

java {
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
sourceCompatibility = javaVersion
Expand All @@ -71,4 +71,4 @@ processResources {
filesMatching("plugin.yml") {
expand props
}
}
}
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.3.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
zipStorePath=wrapper/dists
89 changes: 0 additions & 89 deletions gradlew.bat

This file was deleted.

21 changes: 21 additions & 0 deletions prepare
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

btUrl="https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar"

mkdir buildtools
cd buildtools

curl -o BuildTools.jar $btUrl

echo ""
echo "----------------------------------------"
echo "Downloading complete. Building started."
echo "----------------------------------------"
sleep 3

java -jar BuildTools.jar --rev 1.19.3 --remapped

echo ""
echo "----------------------------------------"
echo "Done."
echo "----------------------------------------"
9 changes: 8 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
rootProject.name = 'AntiPopup'
pluginManagement {
repositories {
gradlePluginPortal()
maven { url = "https://repo.papermc.io/repository/maven-public/" }
}
}

rootProject.name = 'AntiPopup'
65 changes: 44 additions & 21 deletions src/main/java/com/github/kaspiandev/antipopup/AntiPopup.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.github.kaspiandev.antipopup;

import com.github.kaspiandev.antipopup.api.Api;
import com.github.kaspiandev.antipopup.listeners.KickListener;
import com.github.kaspiandev.antipopup.listeners.ChatListener;
import com.github.kaspiandev.antipopup.listeners.PacketEventsListener;
import com.github.kaspiandev.antipopup.listeners.URLListener;
import com.github.kaspiandev.antipopup.nms.PlayerListener;
import com.github.kaspiandev.antipopup.nms.v1_19_3.PlayerInjector;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import dev.dejvokep.boostedyaml.YamlDocument;
Expand All @@ -30,9 +31,8 @@

public final class AntiPopup extends JavaPlugin {

public static YamlDocument config;
static Plugin instance;
static Metrics metrics;
private static YamlDocument yamlDoc;
private static Plugin instance;

@Override
public void onLoad() {
Expand All @@ -46,7 +46,7 @@ public void onLoad() {
public void onEnable() {
instance = this;
try {
config = YamlDocument.create(new File(getDataFolder(), "config.yml"),
yamlDoc = YamlDocument.create(new File(getDataFolder(), "config.yml"),
Objects.requireNonNull(getResource("config.yml")),
GeneralSettings.DEFAULT, LoaderSettings.builder().setAutoUpdate(true).build(),
DumperSettings.DEFAULT,
Expand All @@ -58,8 +58,8 @@ public void onEnable() {
throw new RuntimeException(ex);
}

if (config.getBoolean("bstats", false)) {
metrics = new Metrics(this, 16308);
if (yamlDoc.getBoolean("bstats")) {
Metrics metrics = new Metrics(this, 16308);
metrics.addCustomChart(new SimplePie("runs_viaversion",
() -> Bukkit.getPluginManager().isPluginEnabled("ViaVersion") ? "Yes" : "No"));
getLogger().info("Loaded optional metrics.");
Expand All @@ -76,30 +76,46 @@ public void onEnable() {
}
}

if (yamlDoc.getBoolean("clickable-urls")) {
getServer().getPluginManager().registerEvents(new ChatListener(), this);
getLogger().info("Enabled URL support.");
}

PacketEvents.getAPI().getEventManager().registerListener(new PacketEventsListener());
PacketEvents.getAPI().init();
getLogger().info("Initiated PacketEvents.");

getServer().getPluginManager().registerEvents(new KickListener(), this);
if (config.getBoolean("enable-urls")) {
getServer().getPluginManager().registerEvents(new URLListener(), this);
if (yamlDoc.getBoolean("setup-mode")
&& PacketEvents.getAPI().getServerManager().getVersion().equals(ServerVersion.V_1_19_3)) {
yamlDoc.set("mode", "NMS");
yamlDoc.set("setup-mode", false);
try {
yamlDoc.save();
} catch (IOException e) {
throw new RuntimeException(e);
}
}

if (yamlDoc.getString("mode").equals("NMS")) {
if (PacketEvents.getAPI().getServerManager().getVersion().equals(ServerVersion.V_1_19_3)) {
getServer().getPluginManager().registerEvents(new PlayerListener(new PlayerInjector()), this);
}
}
getLogger().info("Listeners registered.");

Objects.requireNonNull(this.getCommand("antipopup")).setExecutor(new CommandRegister());
getLogger().info("Commands registered.");

if (config.getBoolean("filter-not-secure", true)
|| config.getBoolean("sync-time-suppress", false)) {
if (yamlDoc.getBoolean("filter-not-secure")
|| yamlDoc.getBoolean("sync-time-suppress")) {
((org.apache.logging.log4j.core.Logger) LogManager.getRootLogger()).addFilter(new LogFilter());
getLogger().info("Logger filter enabled.");
} else {
getLogger().info("Logger filter has not been enabled.");
}

Bukkit.getScheduler().runTaskLater(this, () -> {
if (config.getBoolean("auto-setup", false)) new Api(instance).setupAntiPopup(80);
if (config.getBoolean("first-run")) {
if (yamlDoc.getBoolean("auto-setup")) new Api(instance).setupAntiPopup(80);
if (yamlDoc.getBoolean("first-run")) {
try {
FileInputStream in = new FileInputStream("server.properties");
Properties props = new Properties();
Expand All @@ -114,13 +130,12 @@ public void onEnable() {
getLogger().warning("------------------------------------------------------");
}
in.close();
config.set("first-run", false);
config.save();
yamlDoc.save();
} catch (IOException io) {
io.printStackTrace();
}
}
if (config.getBoolean("ask-bstats")) {
if (yamlDoc.getBoolean("ask-bstats")) {
try {
getLogger().warning("--------------------[ READ ME PLEASE ]--------------------");
getLogger().warning("This is your first startup with AntiPopup.");
Expand All @@ -129,8 +144,8 @@ public void onEnable() {
getLogger().warning("Because I respect your freedom it's disabled by default.");
getLogger().warning("Thanks for using AntiPopup! (you will not see this again)");
getLogger().warning("----------------------------------------------------------");
config.set("ask-bstats", false);
config.save();
yamlDoc.set("ask-bstats", false);
yamlDoc.save();
} catch (IOException io) {
io.printStackTrace();
}
Expand All @@ -143,4 +158,12 @@ public void onDisable() {
PacketEvents.getAPI().terminate();
getLogger().info("Disabled PacketEvents.");
}

public static Plugin getInstance() {
return instance;
}

public static YamlDocument getYamlDoc() {
return yamlDoc;
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
package com.github.kaspiandev.antipopup;

import com.github.kaspiandev.antipopup.api.Api;
import dev.dejvokep.boostedyaml.YamlDocument;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;

import java.io.IOException;

import static com.github.kaspiandev.antipopup.AntiPopup.config;
import static com.github.kaspiandev.antipopup.AntiPopup.instance;
import static org.bukkit.Bukkit.getLogger;

public class CommandRegister implements CommandExecutor {

private final Plugin instance = AntiPopup.getInstance();
private final YamlDocument yamlDoc = AntiPopup.getYamlDoc();

@Override
public boolean onCommand(@NotNull CommandSender sender,
@NotNull Command cmd,
Expand All @@ -29,7 +32,7 @@ public boolean onCommand(@NotNull CommandSender sender,
api.setupAntiPopup(100);
} else if ("reload".equals(args[0])) {
try {
config.reload();
yamlDoc.reload();
getLogger().info("Config has been reloaded.");
} catch (IOException e) {
throw new RuntimeException(e);
Expand Down
Loading