start of AI implementation for automatic reports
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
package eu.mhsl.craftattack.spawn;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.chatMessages.ChatMessagesMain;
|
||||
import eu.mhsl.craftattack.spawn.util.ConfigUtil;
|
||||
import eu.mhsl.craftattack.spawn.worldmuseum.WorldMueseumMain;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public final class Main extends JavaPlugin {
|
||||
@ -13,16 +15,18 @@ public final class Main extends JavaPlugin {
|
||||
saveDefaultConfig();
|
||||
|
||||
// load parts
|
||||
// WorldMueseumMain.onEnable();
|
||||
ChatMessagesMain.onEnable();
|
||||
if ((boolean) ConfigUtil.getConfigUtil().getConfig().get("enableWorldMuseum")) WorldMueseumMain.onEnable();
|
||||
if ((boolean) ConfigUtil.getConfigUtil().getConfig().get("enableChatMessageOverrides")) ChatMessagesMain.onEnable();
|
||||
// if ((boolean) ConfigUtil.getConfigUtil().getConfig().get("enableProjectstart")) ProjectstartMain.onEnable();
|
||||
|
||||
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// WorldMueseumMain.onDisable();
|
||||
ChatMessagesMain.onDisable();
|
||||
if ((boolean) ConfigUtil.getConfigUtil().getConfig().get("enableWorldMuseum")) WorldMueseumMain.onDisable();
|
||||
if ((boolean) ConfigUtil.getConfigUtil().getConfig().get("enableChatMessageOverrides")) ChatMessagesMain.onDisable();
|
||||
// if ((boolean) ConfigUtil.getConfigUtil().getConfig().get("enableProjectstart")) ProjectstartMain.onDisable();
|
||||
}
|
||||
|
||||
public static Main getInstance() {
|
||||
|
@ -1,7 +1,9 @@
|
||||
package eu.mhsl.craftattack.spawn.chatMessages.listeners;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.util.ConfigUtil;
|
||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import org.bukkit.Color;
|
||||
@ -11,7 +13,11 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import java.util.Objects;
|
||||
import com.theokanning.openai.completion.CompletionRequest;
|
||||
import com.theokanning.openai.service.OpenAiService;
|
||||
|
||||
|
||||
public class PlayerChatListener implements Listener {
|
||||
@EventHandler
|
||||
@ -21,6 +27,8 @@ public class PlayerChatListener implements Listener {
|
||||
.append(sourceDisplayName.color(getPlayerColor(source)).clickEvent(ClickEvent.clickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/report " + source.getName())))
|
||||
.append(Component.text(" > ").color(TextColor.color(Color.GRAY.asRGB())))
|
||||
.append(message).color(TextColor.color(Color.SILVER.asRGB())));
|
||||
|
||||
if (ConfigUtil.getConfigUtil().isApiSwearWordCheck()) checkForSwearWord(((TextComponent) event.message()).content());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -30,6 +38,7 @@ public class PlayerChatListener implements Listener {
|
||||
.append(Component.text("↑ ").color(TextColor.color(Color.GREEN.asRGB())))
|
||||
.append(Component.text(event.getPlayer().getName()).color(getPlayerColor(event.getPlayer())))
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -50,4 +59,24 @@ public class PlayerChatListener implements Listener {
|
||||
if (player.hasPermission("chatcolor")) return TextColor.color(Color.AQUA.asRGB());
|
||||
return TextColor.color(Color.WHITE.asRGB());
|
||||
}
|
||||
|
||||
|
||||
private boolean checkForSwearWord(String msg) {
|
||||
String token = ConfigUtil.getConfigUtil().getApiToken();
|
||||
OpenAiService service = new OpenAiService(token);
|
||||
|
||||
CompletionRequest completionRequest = CompletionRequest.builder()
|
||||
.prompt("Does \"" + msg + "\" contain a swear word or ist it maybe insulting to another player? Only answer with true of false!")
|
||||
.model("text-davinci-003")
|
||||
.temperature(0D)
|
||||
.maxTokens(4)
|
||||
.topP(1D)
|
||||
.frequencyPenalty(0.5D)
|
||||
.presencePenalty(0D)
|
||||
.bestOf(1)
|
||||
.build();
|
||||
System.out.println(service.createCompletion(completionRequest).getChoices().get(0).getText());
|
||||
// Report if necessary is needed
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package eu.mhsl.craftattack.spawn.worldmuseum.util;
|
||||
package eu.mhsl.craftattack.spawn.util;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@ -13,15 +13,21 @@ public class ConfigUtil {
|
||||
private static ConfigUtil instance;
|
||||
private final File file;
|
||||
private final FileConfiguration config;
|
||||
|
||||
//loaded config variables
|
||||
private boolean apiSwearWordCheck = false;
|
||||
private String apiToken;
|
||||
|
||||
public static ConfigUtil getConfigUtil() {
|
||||
if (instance != null) return instance;
|
||||
instance = new ConfigUtil("config.yml");
|
||||
if (instance == null) instance = new ConfigUtil("config.yml");
|
||||
return instance;
|
||||
}
|
||||
private ConfigUtil(String path) {
|
||||
this.file = new File(Objects.requireNonNull(Bukkit.getPluginManager().getPlugin("spawn")).getDataFolder().getAbsolutePath() + "/" + path);
|
||||
this.config = YamlConfiguration.loadConfiguration(this.file);
|
||||
loadConfig();
|
||||
}
|
||||
|
||||
public boolean save() {
|
||||
try {
|
||||
this.config.save(this.file);
|
||||
@ -31,6 +37,12 @@ public class ConfigUtil {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void loadConfig() {
|
||||
apiSwearWordCheck = (boolean) config.get("enableSwearWordCheck");
|
||||
apiToken = (String) config.get("apiToken");
|
||||
}
|
||||
|
||||
public FileConfiguration getConfig() {
|
||||
return this.config;
|
||||
}
|
||||
@ -48,4 +60,21 @@ public class ConfigUtil {
|
||||
|
||||
return location;
|
||||
}
|
||||
|
||||
public Location getSpawnLocation() {
|
||||
List<Double> cordsList = this.config.getDoubleList("spawnLocation");
|
||||
World world = Bukkit.getWorld("world");
|
||||
double x = cordsList.get(0);
|
||||
double y = cordsList.get(1);
|
||||
double z = cordsList.get(2);
|
||||
return new Location(world, x, y, z);
|
||||
}
|
||||
|
||||
public boolean isApiSwearWordCheck() {
|
||||
return apiSwearWordCheck;
|
||||
}
|
||||
|
||||
public String getApiToken() {
|
||||
return apiToken;
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package eu.mhsl.craftattack.spawn.worldmuseum.command;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.worldmuseum.util.ConfigUtil;
|
||||
import eu.mhsl.craftattack.spawn.util.ConfigUtil;
|
||||
import eu.mhsl.craftattack.spawn.worldmuseum.util.VillagerSpawner;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.Command;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package eu.mhsl.craftattack.spawn.worldmuseum.listener;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.worldmuseum.util.ConfigUtil;
|
||||
import eu.mhsl.craftattack.spawn.util.ConfigUtil;
|
||||
import eu.mhsl.craftattack.spawn.worldmuseum.util.PlayerOnlineUtil;
|
||||
import eu.mhsl.craftattack.spawn.worldmuseum.util.PluginMessage;
|
||||
import eu.mhsl.craftattack.spawn.worldmuseum.util.VillagerSpawner;
|
||||
|
@ -1,5 +1,6 @@
|
||||
package eu.mhsl.craftattack.spawn.worldmuseum.util;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.util.ConfigUtil;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Villager;
|
||||
|
@ -1,7 +1,21 @@
|
||||
# Worldmuseum
|
||||
enableWorldMuseum: false
|
||||
villagerLocation:
|
||||
- 0 #x
|
||||
- 0 #y
|
||||
- 0 #z
|
||||
- 0 #yaw
|
||||
- 0 #pitch
|
||||
world-museum-name: worldmuseum
|
||||
world-museum-name: worldmuseum
|
||||
|
||||
# ChatMessages
|
||||
enableChatMessageOverrides: false
|
||||
enableSwearWordCheck: false
|
||||
apiToken:
|
||||
|
||||
# Porjectstart
|
||||
enableProjectstart: false
|
||||
spawnLocation:
|
||||
- 0 #x
|
||||
- 0 #y
|
||||
- 0 #z
|
||||
|
Reference in New Issue
Block a user