Skip to content

Commit

Permalink
1.2-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
HaHaWTH committed Sep 26, 2024
1 parent a445b39 commit 05f40e4
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 26 deletions.
14 changes: 11 additions & 3 deletions bukkit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>io.wdsj</groupId>
<artifactId>AdvancedSensitiveWords</artifactId>
<version>1.1</version>
<version>1.2</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -69,6 +69,14 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.hjug.refactorfirst.plugin</groupId>
<artifactId>refactor-first-maven-plugin</artifactId>
<version>0.5.0</version>
<configuration>
<showDetails>false</showDetails>
</configuration>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
Expand Down Expand Up @@ -315,7 +323,7 @@
<dependency>
<groupId>com.github.retrooper</groupId>
<artifactId>packetevents-spigot</artifactId>
<version>2.5.0</version>
<version>2.5.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

Expand Down Expand Up @@ -403,7 +411,7 @@
<dependency>
<groupId>io.wdsj</groupId>
<artifactId>AdvancedSensitiveWords-common</artifactId>
<version>1.1</version>
<version>1.2</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void register() {
service.registerPlugin(voiceChatExtension);
LOGGER.info("Successfully hooked into voicechat.");
} catch (Exception e) {
LOGGER.severe("Failed to register voicechat listener." +
LOGGER.warning("Failed to register voicechat listener." +
" This should not happen, please report to the author: " + e.getMessage());
}
} else {
Expand Down
16 changes: 14 additions & 2 deletions bukkit/src/main/java/io/wdsj/asw/bukkit/update/Updater.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@

import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import io.wdsj.asw.common.template.PluginVersionTemplate;

import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;

import static io.wdsj.asw.bukkit.AdvancedSensitiveWords.LOGGER;

public class Updater {
private static String currentVersion;
private static String latestVersion;
private static boolean isUpdateAvailable = false;
private static final String UPDATE_URL = "https://api.github.com/repos/HaHaWTH/AdvancedSensitiveWords/releases/latest";
private static final String currentVersionChannel = PluginVersionTemplate.VERSION_CHANNEL;

public Updater(String current) {
currentVersion = current;
Expand All @@ -24,7 +27,12 @@ public Updater(String current) {
* Note: This method will perform a network request!
* @return true if there is an update available, false otherwise
*/
@SuppressWarnings("all")
public boolean isUpdateAvailable() {
boolean isDevChannel = currentVersionChannel.equalsIgnoreCase("dev");
if (isDevChannel) {
LOGGER.info("You are running an development version of AdvancedSensitiveWords!");
}
URI uri = URI.create(UPDATE_URL);
try {
URL url = uri.toURL();
Expand All @@ -37,9 +45,13 @@ public boolean isUpdateAvailable() {
latestVersion = latest;
isUpdateAvailable = !currentVersion.equals(latest);
reader.close();
if (isDevChannel) {
LOGGER.info("Current running: " + currentVersion + "-" + currentVersionChannel + ", latest release: " + latest);
return false;
}
return isUpdateAvailable;
}
} catch (IOException e) {
} catch (Exception e) {
latestVersion = null;
isUpdateAvailable = false;
return false;
Expand Down
29 changes: 24 additions & 5 deletions bukkit/src/main/java/io/wdsj/asw/bukkit/util/SchedulingUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,68 @@

import com.github.Anon8281.universalScheduler.UniversalScheduler;
import com.github.Anon8281.universalScheduler.scheduling.tasks.MyScheduledTask;
import io.wdsj.asw.bukkit.AdvancedSensitiveWords;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.event.Event;

import java.util.concurrent.Callable;

import static io.wdsj.asw.bukkit.AdvancedSensitiveWords.getScheduler;

public class SchedulingUtils {
private SchedulingUtils() {
}
private static final boolean isFolia = UniversalScheduler.isFolia;

public static void runSyncIfFolia(Runnable runnable) {
if (isFolia) {
AdvancedSensitiveWords.getScheduler().runTask(runnable);
getScheduler().runTask(runnable);
} else {
runnable.run();
}
}

public static void runSyncAtEntityIfFolia(Entity entity, Runnable runnable) {
if (isFolia) {
AdvancedSensitiveWords.getScheduler().runTask(entity, runnable);
getScheduler().runTask(entity, runnable);
} else {
runnable.run();
}
}

public static void runSyncAtLocationIfFolia(Location location, Runnable runnable) {
if (isFolia) {
AdvancedSensitiveWords.getScheduler().runTask(location, runnable);
getScheduler().runTask(location, runnable);
} else {
runnable.run();
}
}

public static void runSyncIfEventAsync(Runnable runnable, Event event) {
if (event.isAsynchronous()) {
getScheduler().runTask(runnable);
} else {
runnable.run();
}
}

public static void runSyncIfNotOnMainThread(Runnable runnable) {
if (Bukkit.isPrimaryThread()) {
runnable.run();
} else {
getScheduler().runTask(runnable);
}
}

public static void cancelTaskSafely(MyScheduledTask task) {
if (task == null) return;
task.cancel();
}

public static <T> T callSyncMethod(Callable<T> callable) {
try {
return AdvancedSensitiveWords.getScheduler().callSyncMethod(callable).get();
return getScheduler().callSyncMethod(callable).get();
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down
19 changes: 13 additions & 6 deletions bukkit/src/main/kotlin/io/wdsj/asw/bukkit/listener/ChatListener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import io.wdsj.asw.bukkit.setting.PluginMessages
import io.wdsj.asw.bukkit.setting.PluginSettings
import io.wdsj.asw.bukkit.type.ModuleType
import io.wdsj.asw.bukkit.util.LoggingUtils
import io.wdsj.asw.bukkit.util.SchedulingUtils
import io.wdsj.asw.bukkit.util.TimingUtils
import io.wdsj.asw.bukkit.util.Utils
import io.wdsj.asw.bukkit.util.context.ChatContext
Expand Down Expand Up @@ -65,8 +66,10 @@ class ChatListener : Listener {
val endTime = System.currentTimeMillis()
TimingUtils.addProcessStatistic(endTime, startTime)
if (settingsManager.getProperty(PluginSettings.NOTICE_OPERATOR)) Notifier.notice(player, ModuleType.CHAT, originalMessage, censoredWordList)
getScheduler().runTask {
if (settingsManager.getProperty(PluginSettings.CHAT_PUNISH)) Punishment.punish(player)
if (settingsManager.getProperty(PluginSettings.CHAT_PUNISH)) {
SchedulingUtils.runSyncIfEventAsync({
Punishment.punish(player)
}, event)
}
return
} else {
Expand Down Expand Up @@ -96,7 +99,9 @@ class ChatListener : Listener {
Notifier.notice(player, ModuleType.CHAT_AI, originalMessage, unsupportedList)
}
if (settingsManager.getProperty(PluginSettings.CHAT_PUNISH) && settingsManager.getProperty(PluginSettings.OLLAMA_AI_PUNISH)) {
getScheduler().runTask { Punishment.punish(player) }
SchedulingUtils.runSyncIfEventAsync({
Punishment.punish(player)
}, event)
}
}
} catch (e: NumberFormatException) {
Expand Down Expand Up @@ -143,7 +148,9 @@ class ChatListener : Listener {
Notifier.notice(player, ModuleType.CHAT_AI, originalMessage, unsupportedList)
}
if (settingsManager.getProperty(PluginSettings.CHAT_PUNISH) && settingsManager.getProperty(PluginSettings.OPENAI_AI_PUNISH)) {
getScheduler().runTask { Punishment.punish(player) }
SchedulingUtils.runSyncIfEventAsync({
Punishment.punish(player)
}, event)
}
}
}
Expand Down Expand Up @@ -182,9 +189,9 @@ class ChatListener : Listener {
TimingUtils.addProcessStatistic(endTime, startTime)
if (settingsManager.getProperty(PluginSettings.NOTICE_OPERATOR)) Notifier.notice(player, ModuleType.CHAT, originalContext, censoredContextList)
if (settingsManager.getProperty(PluginSettings.CHAT_PUNISH)) {
getScheduler().runTask {
SchedulingUtils.runSyncIfEventAsync({
Punishment.punish(player)
}
}, event)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion bukkit/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: AdvancedSensitiveWords
version: ${project.version}
version: ${project.version}-${version.channel}
# noinspection YAMLSchemaValidation
main: ${plugin.mainClass}
api-version: '1.13'
Expand Down
4 changes: 2 additions & 2 deletions bungee/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>io.wdsj</groupId>
<artifactId>AdvancedSensitiveWords</artifactId>
<version>1.1</version>
<version>1.2</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -88,7 +88,7 @@
<dependency>
<groupId>io.wdsj</groupId>
<artifactId>AdvancedSensitiveWords-common</artifactId>
<version>1.1</version>
<version>1.2</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion bungee/src/main/resources/bungee.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
name: AdvancedSensitiveWords
version: '${project.version}'
version: '${project.version}-${version.channel}'
main: io.wdsj.asw.bungee.AdvancedSensitiveWords
2 changes: 1 addition & 1 deletion common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.wdsj</groupId>
<artifactId>AdvancedSensitiveWords</artifactId>
<version>1.1</version>
<version>1.2</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

public class PluginVersionTemplate {
public static final String VERSION = "${project.version}";
public static final String VERSION_CHANNEL = "${version.channel}";
}
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@

<groupId>io.wdsj</groupId>
<artifactId>AdvancedSensitiveWords</artifactId>
<version>1.1</version>
<version>1.2</version>
<packaging>pom</packaging>

<name>AdvancedSensitiveWords</name>

<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<version.channel>dev</version.channel> <!-- dev, release -->
</properties>

<modules>
Expand Down
4 changes: 2 additions & 2 deletions velocity/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>io.wdsj</groupId>
<artifactId>AdvancedSensitiveWords</artifactId>
<version>1.1</version>
<version>1.2</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -122,7 +122,7 @@
<dependency>
<groupId>io.wdsj</groupId>
<artifactId>AdvancedSensitiveWords-common</artifactId>
<version>1.1</version>
<version>1.2</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
@Plugin(
id = "advancedsensitivewords",
name = "AdvancedSensitiveWords",
version = PluginVersionTemplate.VERSION,
version = PluginVersionTemplate.VERSION + "-" + PluginVersionTemplate.VERSION_CHANNEL,
authors = {"HaHaWTH"}
)
public class AdvancedSensitiveWords {
Expand Down

0 comments on commit 05f40e4

Please sign in to comment.