Skip to content

Commit

Permalink
Merge pull request #4 from Grzybol/Fixes
Browse files Browse the repository at this point in the history
Fixes, removed BetterRanks dependency
  • Loading branch information
Grzybol authored Jan 23, 2024
2 parents a54db86 + 7f0481c commit 9e9b04a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 35 deletions.
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>betterbox.mine.game</groupId>
<artifactId>BetterElo</artifactId>
<version>3.1.13-SNAPSHOT</version>
<version>3.1.19-SNAPSHOT</version>
<packaging>jar</packaging>

<name>BetterElo</name>
Expand Down Expand Up @@ -105,6 +105,11 @@
</repositories>

<dependencies>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-platform-bukkit</artifactId>
<version>4.3.2</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@

import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Set;

public class BetterRanksCheaters {
private JavaPlugin plugin;
private final PluginLogger pluginLogger;
public List<String> cheatersList;
private List<String> cheatersList;

public BetterRanksCheaters(JavaPlugin plugin, PluginLogger pluginLogger) {
this.plugin = plugin;
Expand All @@ -21,36 +22,44 @@ public BetterRanksCheaters(JavaPlugin plugin, PluginLogger pluginLogger) {
}

public void CheckCheatersFromBetterRanks() {
pluginLogger.log(PluginLogger.LogLevel.DEBUG_LVL3,"CheckCheatersFromBetterRanks called");
File dataFolder = plugin.getServer().getPluginManager().getPlugin("BetterRanks").getDataFolder();
pluginLogger.log(PluginLogger.LogLevel.DEBUG_LVL3, "CheckCheatersFromBetterRanks called");
Plugin betterRanksPlugin = plugin.getServer().getPluginManager().getPlugin("BetterRanks");
if (betterRanksPlugin == null || !betterRanksPlugin.isEnabled()) {
pluginLogger.log(PluginLogger.LogLevel.WARNING, "BetterRanks plugin is not found or is disabled.");
cheatersList.clear(); // Clear the list to ensure it's empty.
return;
}

File dataFolder = betterRanksPlugin.getDataFolder();
if (!dataFolder.exists()) {
pluginLogger.log(PluginLogger.LogLevel.WARNING, "BetterRanks plugin folder doesn't exist!");
return; // Jeśli folder danych nie istnieje, to nie ma co sprawdzać.
cheatersList.clear(); // Clear the list to ensure it's empty.
return;
}

File configFile = new File(dataFolder, "database.yml");
if (!configFile.exists()) {
pluginLogger.log(PluginLogger.LogLevel.WARNING, "BetterRanks database.yml doesn't exist!");
return; // Jeśli plik database.yml nie istnieje, to nie ma co sprawdzać.
cheatersList.clear(); // Clear the list to ensure it's empty.
return;
}


FileConfiguration config = YamlConfiguration.loadConfiguration(configFile);
Set<String> playerNames = config.getKeys(false);
pluginLogger.log(PluginLogger.LogLevel.DEBUG_LVL3,"BetterRanksCheaters: CheckCheatersFromBetterRanks checking..");
pluginLogger.log(PluginLogger.LogLevel.DEBUG_LVL3, "BetterRanksCheaters: CheckCheatersFromBetterRanks checking..");
cheatersList.clear();
for (String playerName : playerNames) {
String rank = config.getString(playerName + ".rank");
if (rank != null && rank.equalsIgnoreCase("CHEATER")) {
cheatersList.add(playerName);
pluginLogger.log(PluginLogger.LogLevel.DEBUG_LVL3,"BetterRanksCheaters: CheckCheatersFromBetterRanks: adding cheater "+playerName);
pluginLogger.log(PluginLogger.LogLevel.DEBUG_LVL3, "BetterRanksCheaters: CheckCheatersFromBetterRanks: adding cheater " + playerName);
}
}
pluginLogger.log(PluginLogger.LogLevel.DEBUG_LVL3,"BetterRanksCheaters: CheckCheatersFromBetterRanks: Cheaters found: "+ Arrays.toString(cheatersList.toArray()));
pluginLogger.log(PluginLogger.LogLevel.DEBUG_LVL3, "BetterRanksCheaters: CheckCheatersFromBetterRanks: Cheaters found: " + cheatersList);
}

public List<String> getCheatersList() {
pluginLogger.log(PluginLogger.LogLevel.DEBUG_LVL3,"BetterRanksCheaters: getCheatersList called");
pluginLogger.log(PluginLogger.LogLevel.DEBUG_LVL3, "BetterRanksCheaters: getCheatersList called");
return cheatersList;
}
}
24 changes: 6 additions & 18 deletions src/main/java/betterbox/mine/game/betterelo/ChatNotifier.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package betterbox.mine.game.betterelo;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.Bukkit;

Expand All @@ -19,24 +16,15 @@ public void run() {
// Wiadomość, którą chcesz wysłać
String message = " Remember to use /be claim to claim your rewards!";
String prefix = "[BetterElo]";
broadcastFormattedChatMessage(prefix, message);
broadcastFormattedChatMessage(prefix + message);
message = " Use /shop to get our Item-Shop link";
broadcastFormattedChatMessage(prefix, message);
broadcastFormattedChatMessage(prefix + message);
message = " Use /discord to get our Discord link";
broadcastFormattedChatMessage(prefix, message);
broadcastFormattedChatMessage(prefix + message);
}
public void broadcastFormattedChatMessage(String prefix, String message) {
Component componentPart1 = Component.text(prefix)
.color(NamedTextColor.GOLD) // Ustawienie pierwszego koloru
.decorate(TextDecoration.BOLD); // Pierwsze formatowanie

Component componentPart2 = Component.text(message)
.color(NamedTextColor.AQUA); // Ustawienie drugiego koloru

// Łączenie obu komponentów w jeden
Component finalComponent = componentPart1.append(componentPart2);

// Wysłanie komponentu do wszystkich graczy na serwerze
Bukkit.getServer().broadcast(finalComponent);;
public void broadcastFormattedChatMessage(String message) {
// Wysłanie wiadomości do wszystkich graczy na serwerze
Bukkit.getServer().broadcastMessage(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ public void ReloadConfig() {
}

public void updateConfig(String configuration) {

configFile = new File(plugin.getDataFolder(), "config.yml");

if (!configFile.exists()) {
Expand All @@ -86,17 +85,16 @@ public void updateConfig(String configuration) {
} catch (IOException e) {
pluginLogger.log(PluginLogger.LogLevel.ERROR, "Error while creating config file: " + e.getMessage());
}
updateConfig("log_level:\n - INFO\n - WARNING\n - ERROR");
}

try {
// Usunięcie istniejących linii z log_level
List<String> lines = Files.readAllLines(Paths.get(configFile.toURI()));
lines.removeIf(line -> line.trim().startsWith("log_level:"));

// Dodaj nowe zmienne konfiguracyjne
// Dodanie nowych danych konfiguracyjnych
lines.add("###################################");
lines.add(configuration);
// Tutaj możemy dodać nowe zmienne konfiguracyjne
// ...

Files.write(Paths.get(configFile.toURI()), lines);
pluginLogger.log(PluginLogger.LogLevel.INFO, "Config file updated successfully.");
Expand All @@ -105,4 +103,5 @@ public void updateConfig(String configuration) {
}
}


}

0 comments on commit 9e9b04a

Please sign in to comment.