Skip to content

Commit

Permalink
Merge pull request #74 from Grzybol/release-4.6.0
Browse files Browse the repository at this point in the history
Release 4.6.0
  • Loading branch information
Grzybol authored Jul 12, 2024
2 parents 09767a3 + b799605 commit b73ab08
Show file tree
Hide file tree
Showing 20 changed files with 472 additions and 29 deletions.
2 changes: 1 addition & 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>4.4.52-SNAPSHOT</version>
<version>4.6.4-SNAPSHOT</version>
<packaging>jar</packaging>

<name>BetterElo</name>
Expand Down
124 changes: 123 additions & 1 deletion src/main/java/betterbox/mine/game/betterelo/BetterElo.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.io.Console;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.text.DecimalFormat;
import java.time.Duration;
import java.util.*;
Expand Down Expand Up @@ -73,6 +75,11 @@ public void onLoad() {

@Override
public void onEnable() {
createPluginFolders();
createExampleDropTablesFiles();
createExampleDropsFiles();
createExampleMobsFiles();
createExampleConfigFiles();
// Inicjalizacja PluginLoggera
Set<PluginLogger.LogLevel> defaultLogLevels = EnumSet.of(PluginLogger.LogLevel.INFO,PluginLogger.LogLevel.DEBUG, PluginLogger.LogLevel.WARNING, PluginLogger.LogLevel.ERROR);
folderPath = getDataFolder().getAbsolutePath();
Expand Down Expand Up @@ -143,7 +150,7 @@ public void onEnable() {
pluginLogger.log(PluginLogger.LogLevel.INFO,"Scheduling monthly ranking rewards...");
scheduleRewards("monthly", 0, true);

File dataFolder = this.getDataFolder();
File dataFolder = new File(getDataFolder(),"data");
File databaseFile = new File(dataFolder, "database.txt");
//WebRankingServer server = new WebRankingServer(databaseFile.getAbsolutePath(), 39378,pluginLogger);

Expand All @@ -156,6 +163,7 @@ public void onEnable() {
// Uzyskaj dostęp do loggera pluginu
java.util.logging.Logger logger = this.getLogger();


// Użyj loggera do rejestrowania wiadomości
logger.info("[BetterElo] Running");
logger.info("[BetterElo] Author " + this.getDescription().getAuthors());
Expand All @@ -178,6 +186,120 @@ public void onEnable() {
checkMobsExistence();

}
public void createPluginFolders() {
// Lista folderów do utworzenia
String[] folders = {"customDrops", "customDropTables", "customMobs", "logs","data"};

// Tworzenie folderów, jeśli nie istnieją
for (String folderName : folders) {
File folder = new File(getDataFolder(), folderName);
if (!folder.exists()) {
folder.mkdirs(); // Metoda mkdirs() tworzy folder oraz wszystkie wymagane nadrzędne foldery
getLogger().severe("Catalogs "+folders.toString()+" created!");
}
}
}
private void createExampleDropsFiles() {
// Tworzenie docelowego folderu, jeśli nie istnieje
File customFolder = new File(getDataFolder(), "customDrops");
if (!customFolder.exists()) {
customFolder.mkdirs();
}

// Lokalizacja docelowego pliku konfiguracyjnego
String[] fileNames = {"ExampleDropTable_item0.yml", "ExampleDropTable_item1.yml", "ExampleDropTable_item2.yml", "ExampleDropTable_item3.yml", "ExampleDropTable_item4.yml", "ExampleDropTable_item5.yml"}; // Dodaj więcej nazw plików jak potrzebujesz

for (String fileName : fileNames) {
File file = new File(customFolder, fileName);
if (!file.exists()) {
try (InputStream in = getResource("customDrops/" + fileName)) {
if (in == null) {
getLogger().severe("Resource 'customDrops/" + fileName + "' not found.");
continue;
}
Files.copy(in, file.toPath());
} catch (IOException e) {
getLogger().severe("Could not save " + fileName + " to " + file + ": " + e.getMessage());
}
}
}
}
private void createExampleDropTablesFiles() {
// Tworzenie docelowego folderu, jeśli nie istnieje
File customFolder = new File(getDataFolder(), "customDropTables");
if (!customFolder.exists()) {
customFolder.mkdirs();
}

// Lokalizacja docelowego pliku konfiguracyjnego
String[] fileNames = {"ExampleDropTable.yml"};

for (String fileName : fileNames) {
File file = new File(customFolder, fileName);
if (!file.exists()) {
try (InputStream in = getResource("customDropTables/" + fileName)) {
if (in == null) {
getLogger().severe("Resource 'customDropTables/" + fileName + "' not found.");
continue;
}
Files.copy(in, file.toPath());
} catch (IOException e) {
getLogger().severe("Could not save " + fileName + " to " + file + ": " + e.getMessage());
}
}
}
}
private void createExampleConfigFiles() {
// Tworzenie docelowego folderu, jeśli nie istnieje
File customFolder = getDataFolder();
if (!customFolder.exists()) {
customFolder.mkdirs();
}

// Lokalizacja docelowego pliku konfiguracyjnego
String[] fileNames = {"config.yml"};

for (String fileName : fileNames) {
File file = new File(customFolder, fileName);
if (!file.exists()) {
try (InputStream in = getResource(fileName)) {
if (in == null) {
getLogger().severe(fileName + "' not found.");
continue;
}
Files.copy(in, file.toPath());
} catch (IOException e) {
getLogger().severe("Could not save " + fileName + " to " + file + ": " + e.getMessage());
}
}
}
}
private void createExampleMobsFiles() {
// Tworzenie docelowego folderu, jeśli nie istnieje
File customFolder = new File(getDataFolder(), "customMobs");
if (!customFolder.exists()) {
customFolder.mkdirs();
}

// Lokalizacja docelowego pliku konfiguracyjnego
String[] fileNames = {"Marksman.yml","Panda.yml"};

for (String fileName : fileNames) {
File file = new File(customFolder, fileName);
if (!file.exists()) {
try (InputStream in = getResource("customMobs/" + fileName)) {
if (in == null) {
getLogger().severe("Resource 'customMobs/" + fileName + "' not found.");
continue;
}
Files.copy(in, file.toPath());
} catch (IOException e) {
getLogger().severe("Could not save " + fileName + " to " + file + ": " + e.getMessage());
}
}
}
}


@Override
public void onDisable() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
if (rewardItems != null && !rewardItems.isEmpty()) {
for (ItemStack item : rewardItems) {
player.getInventory().addItem(item);
sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo]" + ChatColor.AQUA + " Rewards claimed!");
pluginLogger.log(PluginLogger.LogLevel.INFO, "BetterEloCommand: claim: player: " + player.getName() + " reward: " + item);
}
rewardsConfig.set(playerName, null); // Usuń przyznane nagrody z pliku
Expand All @@ -199,9 +198,11 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
} catch (IOException e) {
pluginLogger.log(PluginLogger.LogLevel.ERROR, "BetterEloCommand: claim: Error while saving rewards configuration: " + e);
}
sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo]" + ChatColor.AQUA + " Rewards claimed!");
}else {
sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo]" + ChatColor.DARK_RED + " No rewards assigned.");
}
sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo]" + ChatColor.DARK_RED + " No rewards assigned.");
pluginLogger.log(PluginLogger.LogLevel.INFO, "BetterEloCommand: claim: player: " + player.getName() + " No rewards assigned.");

break;
case "timeleft":
handleTimeLeft(sender);
Expand Down Expand Up @@ -698,13 +699,14 @@ private void handleHelpCommand(CommandSender sender){
sender.sendMessage(ChatColor.AQUA + "/be holo <event/main/daily/weekly/monthly> " + ChatColor.GREEN + "- creates holo at your position.");
sender.sendMessage(ChatColor.AQUA + "/be holo delete <event/main/daily/weekly/monthly> " + ChatColor.GREEN + "- delete given holo");
sender.sendMessage(ChatColor.AQUA + "/be antyweb <radius> " + ChatColor.GREEN + "- creates antyweb effect with given radius");
sender.sendMessage(ChatColor.AQUA + "/be addelytra " + ChatColor.GREEN + "- adds Elytra Effect to the chestplate (works only with infinite Infinite Firework)");
sender.sendMessage(ChatColor.AQUA + "/be firework <power> " + ChatColor.GREEN + "- creates an Infinite Firework with given power");
sender.sendMessage(ChatColor.AQUA + "/be flamethrower <distance> <range>" + ChatColor.GREEN + "- adds Flamethrower effect");
sender.sendMessage(ChatColor.AQUA + "/be zephyr <power> " + ChatColor.GREEN + "- adds Zephyr effect");
sender.sendMessage(ChatColor.AQUA + "/be addspawner <spawnerName> <mobName> <cooldown(s)> <mobCountPerSpawn> <maxMobs>" + ChatColor.GREEN + "- creates custom mob spawner");
sender.sendMessage(ChatColor.AQUA + "/be droptable <name> - opens a GUI to create new drop table");
sender.sendMessage(ChatColor.AQUA + "/be spawnmob <mobname> <amount> - spawn given custom mob");
sender.sendMessage(ChatColor.AQUA + "/be enchantitem - gives you 1x Enchant Item");
sender.sendMessage(ChatColor.AQUA + "/be forcespawn <spawnerName> - forces a respawn of a given spawner");
}
}
private void handleTimeLeft(CommandSender sender){
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/betterbox/mine/game/betterelo/CustomMobs.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static class CustomMob {
if (weapon != null) {
this.weapon = weapon;
} else {
plugin.getLogger().warning(mobName + " does not have weapon set. Setting AIR");
//plugin.getLogger().warning(mobName + " does not have weapon set. Setting AIR");
this.weapon = new ItemStack(Material.AIR);
}

Expand Down Expand Up @@ -157,7 +157,7 @@ private void setupMob() {
if (weapon != null) {
entity.getEquipment().setItemInMainHand(weapon);
} else {
plugin.getLogger().warning(mobName + " does not have weapon set. Setting AIR");
//plugin.getLogger().warning(mobName + " does not have weapon set. Setting AIR");
entity.getEquipment().setItemInMainHand(new ItemStack(Material.AIR));
}
entity.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(hp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.*;

import org.bukkit.Location;
Expand Down Expand Up @@ -120,25 +123,23 @@ private void CreateCustomMobsFolder(String folderPath) {
pluginLogger.log(PluginLogger.LogLevel.ERROR, "CustomMobsFileManager.CreateCustomMobsFolder exception: " + e.getMessage());
}
}

private void CreateExampleSpawnersFile(File spawnersFile){
try (InputStream in = plugin.getResource("customMobs/spawners.yml")) {
if (in == null) {
plugin.getLogger().severe("Resource 'customDropTables/spawners.yml not found.");
return;
}
Files.copy(in, spawnersFile.toPath());
} catch (IOException e) {
plugin.getLogger().severe("Could not save spawners.yml to " + spawnersFile + ": " + e.getMessage());
}
}
private void CreateSpawnersFile(String folderPath) {
try {
String spawnersFileName = "spawners.yml";
spawnersFile = new File(folderPath + File.separator + "customMobs", spawnersFileName);
if (!spawnersFile.exists()) {
pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "CustomMobsFileManager.CreateSpawnersFile creating new file.");
spawnersFile.createNewFile();

// Tworzymy domyślną strukturę pliku
FileConfiguration config = YamlConfiguration.loadConfiguration(spawnersFile);
config.createSection("spawners");
config.set("spawners.exampleSpawner.location", "x y z");
config.set("spawners.exampleSpawner.mobName", "exampleMobName");
config.set("spawners.exampleSpawner.cooldown", "exampleCooldown");
config.set("spawners.exampleSpawner.mobsPerSpawn", "mobsPerSpawn");
config.set("spawners.exampleSpawner.mobsPerSpawn", "maxMobs");
// Zapisujemy zmiany do pliku
config.save(spawnersFile);
CreateExampleSpawnersFile(spawnersFile);
} else {
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "CustomMobsFileManager.CreateSpawnersFile file already exists.");
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/betterbox/mine/game/betterelo/DataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
public class DataManager {
private final JavaPlugin plugin;
private final File dataFolder;
private final File pluginDataFolder;
private final File databaseFile;
private final File dailyDatabaseFile;
private final File weeklyDatabaseFile;
Expand All @@ -23,7 +24,8 @@ public class DataManager {
public DataManager(JavaPlugin plugin, PluginLogger pluginLogger) {
this.plugin = plugin;
this.pluginLogger = pluginLogger; // Inicjalizujemy PluginLogger
this.dataFolder = plugin.getDataFolder();
this.pluginDataFolder = plugin.getDataFolder();
this.dataFolder = new File(pluginDataFolder,"data");
this.databaseFile = new File(dataFolder, "database.txt");
this.dailyDatabaseFile = new File(dataFolder, "daily_database.txt");
this.weeklyDatabaseFile = new File(dataFolder, "weekly_database.txt");
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/betterbox/mine/game/betterelo/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -1452,6 +1452,25 @@ public void onInventoryClick(InventoryClickEvent event) {
fileRewardManager.saveCustomDrops(fileName, itemsToSave);
}

}
if (currentItem.getType() == Material.GREEN_WOOL && event.getSlot() == 35) {
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick Add Items - save called.");
event.setCancelled(true);
Inventory inventory = event.getInventory();
List<ItemStack> itemsToSave = new ArrayList<>();
for (int i = 0; i < inventory.getSize(); i++) {
if (i != 35) { // Pomijamy slot przycisku "Save"
ItemStack item = inventory.getItem(i);
if (item != null && item.getType() != Material.AIR) {
itemsToSave.add(item);
}
}
}

String fileName=guiManager.periodType+"_"+guiManager.rewardType;
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick calling fileRewardManager.saveRewards("+fileName+",itemsToSave)");
fileRewardManager.saveRewards(fileName,itemsToSave);

}
break;
case "AvgDmg bonus change":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ public class FileRewardManager {
private final PluginLogger pluginLogger; // Dodajemy referencję do PluginLogger

private String rewardType;
private File dataFolder;

public FileRewardManager(JavaPlugin plugin, PluginLogger pluginLogger) {
this.plugin = plugin;
this.pluginLogger = pluginLogger; // Inicjalizujemy PluginLogger
pluginLogger.log(PluginLogger.LogLevel.DEBUG,"FileRewardManager: Inicjalizacja");
dataFolder = new File(plugin.getDataFolder(),"data");
}

public void setRewardType(String rewardType,String subType) {
Expand All @@ -47,7 +49,8 @@ public String getRewardType() {
}

public List<ItemStack> loadRewards() {
File rewardsFile = new File(plugin.getDataFolder(), rewardType + ".yml");

File rewardsFile = new File(dataFolder, rewardType + ".yml");
if (!rewardsFile.exists()) {
return new ArrayList<>(); // return empty list if the file does not exist
}
Expand All @@ -62,7 +65,7 @@ public List<ItemStack> loadRewards() {
return rewards;
}
public List<ItemStack> loadReRollCost() {
File rewardsFile = new File(plugin.getDataFolder(), "reroll.yml");
File rewardsFile = new File(dataFolder, "reroll.yml");
if (!rewardsFile.exists()) {
return new ArrayList<>(); // return empty list if the file does not exist
}
Expand All @@ -77,7 +80,7 @@ public List<ItemStack> loadReRollCost() {
return rewards;
}
public List<ItemStack> loadRewards(Player player) {
File rewardsFile = new File(plugin.getDataFolder(), rewardType + ".yml");
File rewardsFile = new File(dataFolder, rewardType + ".yml");
if (!rewardsFile.exists()) {
return new ArrayList<>(); // return empty list if the file does not exist
}
Expand All @@ -86,7 +89,7 @@ public List<ItemStack> loadRewards(Player player) {
}
public List<ItemStack> getReward(String rewardType) {
// Załaduj konfigurację z pliku dla danego typu nagrody
File rewardFile = new File(plugin.getDataFolder(), rewardType + ".yml");
File rewardFile = new File(dataFolder, rewardType + ".yml");
pluginLogger.log(PluginLogger.LogLevel.DEBUG,"FileRewardManager: getReward: rewardType:" + rewardType);
FileConfiguration rewardConfig = YamlConfiguration.loadConfiguration(rewardFile);
// Pobierz dane o nagrodzie z pliku konfiguracyjnego
Expand Down Expand Up @@ -119,7 +122,7 @@ public List<ItemStack> getReward(String rewardType) {
}
public void saveRewards(String fileName, List<ItemStack> rewards) {
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "FileRewardManager.saveRewards called. fileName: "+fileName);
File rewardsFile = new File(plugin.getDataFolder(), fileName + ".yml");
File rewardsFile = new File(dataFolder, fileName + ".yml");
if (!rewardsFile.getParentFile().exists()) {
rewardsFile.getParentFile().mkdirs(); // Tworzy katalog, jeśli nie istnieje
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public PlayerKillDatabase(PluginLogger pluginLogger) {

private void createDatabaseIfNeeded() {
pluginLogger.log(PluginLogger.LogLevel.DEBUG,"PlayerKillDatabase: createDatabaseIfNeeded called");
File databaseFile = new File("plugins/BetterElo/player_kill_database.db");
File databaseFile = new File("plugins/BetterElo/data/player_kill_database.db");
if (!databaseFile.exists()) {
createNewDatabase();
}
Expand Down
Loading

0 comments on commit b73ab08

Please sign in to comment.