Skip to content

Commit

Permalink
Release 4.2.0
Browse files Browse the repository at this point in the history
- working release 4.2.0
  • Loading branch information
Grzybol authored Apr 10, 2024
2 parents a71b184 + c288f6e commit 95bdd99
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 54 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.1.48-SNAPSHOT</version>
<version>4.2.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>BetterElo</name>
Expand Down
27 changes: 21 additions & 6 deletions src/main/java/betterbox/mine/game/betterelo/BetterElo.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,7 @@ public void onEnable() {
}
killAllCustomMobs();

new BukkitRunnable() {
@Override
public void run() {
//loadAndKillCustomMobsFromCache();
}
}.runTaskLater(this, 20);
checkMobsExistence();

}

Expand Down Expand Up @@ -628,5 +623,25 @@ public void registerCustomMob(Entity entity, CustomMobs.CustomMob customMob) {
public CustomMobs.CustomMob getCustomMobFromEntity(Entity entity) {
return customMobsMap.get(entity);
}
public void checkMobsExistence() {
new BukkitRunnable() {
@Override
public void run() {
// Użyj iteratora, aby uniknąć ConcurrentModificationException podczas usuwania
Iterator<Map.Entry<Entity, CustomMobs.CustomMob>> iterator = customMobsMap.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<Entity, CustomMobs.CustomMob> entry = iterator.next();
if (entry.getKey().isDead() || !entry.getKey().isValid()) {
pluginLogger.log(PluginLogger.LogLevel.INFO, "BetterElo. mob "+entry.getKey()+" is dead or does not exists, removing from the list and from the spawner "+entry.getValue().spawnerName);
// Mob nie istnieje, więc możemy go usunąć z mapy
customMobs.decreaseMobCount(entry.getValue().spawnerName);
iterator.remove();

// Tutaj możesz również zaimplementować logikę re-spawnu lub inne akcje
}
}
}
}.runTaskTimer(this, 0L, 20L * 60); // Uruchom co 1 minutę (20 ticków = 1 sekunda)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ private boolean handleReloadCommand(CommandSender sender){
customMobsFileManager.loadSpawners();
pluginLogger.log(PluginLogger.LogLevel.INFO,"BetterElo spawners.yml reloaded");
customMobs.loadCustomMobs();
//customMobsFileManager.loadCustomDrops();
return true;
}else {
pluginLogger.log(PluginLogger.LogLevel.DEBUG,"BetterEloCommand: handleReloadCommand: sender " + sender + " dont have permission to use /br tl");
Expand Down Expand Up @@ -682,7 +683,7 @@ private void handleHelpCommand(CommandSender sender){
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 killallmobs - kills all custom mobs");
sender.sendMessage(ChatColor.AQUA + "/be spawnmob <mobname> <amount> - spawn given custom mob");
}
}
private void handleTimeLeft(CommandSender sender){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,4 +398,5 @@ public void spawnCustomMob(Location location, String mobName) {
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
Expand Down Expand Up @@ -186,45 +187,6 @@ public void saveItemStackData(YamlConfiguration mobData, String path, ItemStack
}
}


/*
public CustomMobs.CustomMob loadCustomMob(JavaPlugin plugin, FileRewardManager dropFileManager, String mobName) {
File customMobsFolder = new File(plugin.getDataFolder(), "customMobs");
File mobFile = new File(customMobsFolder, mobName + ".yml");
if (!mobFile.exists()) {
plugin.getLogger().warning("Plik dla mobka " + mobName + " nie istnieje!");
return null;
}
YamlConfiguration mobData = YamlConfiguration.loadConfiguration(mobFile);
// Wczytanie wyposażenia z pliku
ItemStack helmet = loadItemStack(mobData, "equipment.helmet");
ItemStack chestplate = loadItemStack(mobData, "equipment.chestplate");
ItemStack leggings = loadItemStack(mobData, "equipment.leggings");
ItemStack boots = loadItemStack(mobData, "equipment.boots");
// Wczytanie pozostałych danych
double armor = mobData.getDouble("armor");
int hp = mobData.getInt("hp");
double speed = mobData.getDouble("speed");
double attackDamage = mobData.getDouble("attackDamage");
String entityTypeString = mobData.getString("type");
EntityType entityType = EntityType.valueOf(entityTypeString);
// Wczytanie niestandardowych metadanych i ustawienie spawnerName
Map<String, Object> customMetadata = (Map<String, Object>) mobData.getConfigurationSection("customMetadata").getValues(false);
//customMetadata.put("SpawnerName", spawnerName); // Dopisanie nazwy spawnera
// Utworzenie instancji CustomMob
// Zakładamy, że LivingEntity jest nullem, ponieważ tworzymy moba bez konkretnej encji w świecie
CustomMobs.CustomMob customMob = new CustomMobs.CustomMob(plugin, dropFileManager, mobName, entityType, helmet, chestplate, leggings, boots, armor, hp, speed, attackDamage, customMetadata);
return customMob;
}
*/
public CustomMobs.CustomMob loadCustomMob(JavaPlugin plugin, FileRewardManager dropFileManager, File mobFile) {
//File customMobsFolder = new File(plugin.getDataFolder(), "customMobs");
//File mobFile = new File(customMobsFolder, mobName + ".yml");
Expand Down Expand Up @@ -342,18 +304,27 @@ public HashMap<Double, ItemStack> loadCustomDrops(String dropTableName) {
return drops;
}

FileConfiguration dropTableConfig = YamlConfiguration.loadConfiguration(dropTableFile);
YamlConfiguration dropTableConfig = YamlConfiguration.loadConfiguration(dropTableFile);

dropTableConfig.getKeys(false).forEach(key -> {
String itemPath = dropTableConfig.getString(key + ".itemPath");
double dropChance = dropTableConfig.getDouble(key + ".dropChance");
pluginLogger.log(PluginLogger.LogLevel.DROP, "CustomMobsFileManager.loadCustomDrops itemPath: " + itemPath+", dropChance: "+dropChance);
boolean AvgDmgBonus = dropTableConfig.getBoolean(key + ".avgDmgBonus");
pluginLogger.log(PluginLogger.LogLevel.DROP, "CustomMobsFileManager.loadCustomDrops itemPath: " + itemPath+", dropChance: "+dropChance+", avgDmgBonus: "+AvgDmgBonus);
File itemFile = new File(plugin.getDataFolder(), itemPath);
if (itemFile.exists()) {
try {
FileConfiguration itemConfig = YamlConfiguration.loadConfiguration(itemFile);
ItemStack itemStack = itemConfig.getItemStack("item");
if (itemStack != null) {
if(AvgDmgBonus){
ItemMeta meta = itemStack.getItemMeta();
List<String> lore = new ArrayList<>();
lore.add("AvgDmgBonus");
meta.setLore(lore);
itemStack.setItemMeta(meta);
pluginLogger.log(PluginLogger.LogLevel.DROP, "CustomMobsFileManager.loadCustomDrops added AvgDmgBonus lore ");
}
drops.put(dropChance, itemStack);
pluginLogger.log(PluginLogger.LogLevel.DROP, "CustomMobsFileManager.loadCustomDrops item: " + itemStack);
}
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 @@ -968,6 +968,25 @@ public void onMobDeath(EntityDeathEvent event) {
double rolledCance = Math.random();
double dropChance = entry.getKey()/100;
if ( rolledCance< dropChance) { // entry.getKey() to szansa na drop
ItemStack item = entry.getValue();
ItemMeta meta = entry.getValue().getItemMeta();
if (meta.hasLore()) {
List<String> lore = meta.getLore();
for (int i = 0; i < lore.size(); i++) {
// Sprawdź, czy linia zawiera szukany tekst
if (lore.get(i).contains("AvgDmgBonus")) {
// Zastąp znalezioną linię nowym tekstem
String AvgDmgBonus = CustomMobs.dropAverageDamage();
lore.set(i, AvgDmgBonus);
pluginLogger.log(PluginLogger.LogLevel.DROP, "Event.onMobDeath Added AvgDmgBonus: "+AvgDmgBonus);
break; // Przerwij pętlę, jeśli chcesz zastąpić tylko pierwsze wystąpienie

}
}
// Zapisz zmodyfikowane lore z powrotem do metadanych przedmiotu
meta.setLore(lore);
item.setItemMeta(meta);
}
drops.add(entry.getValue());
pluginLogger.log(PluginLogger.LogLevel.DROP, "Event.onMobDeath Added item from dropTable to the drops. dropChance: "+dropChance+", rolledChance: "+rolledCance);
}else{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public void saveRewards(String fileName, List<ItemStack> rewards) {
}
}
public void saveCustomDrops(String fileName, List<ItemStack> rewards) {
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "FileRewardManager.saveCustomDrops called, fileName: "+fileName);
File customDropsFolder = new File(plugin.getDataFolder() + File.separator + "customDrops");
if (!customDropsFolder.exists()) {
customDropsFolder.mkdirs();
Expand Down Expand Up @@ -152,7 +153,9 @@ public void saveCustomDrops(String fileName, List<ItemStack> rewards) {
String itemPath = "customDrops/" + itemFileName;
dropTableConfig.set("Item" + index + ".itemPath", itemPath);
dropTableConfig.set("Item" + index + ".dropChance", 0.00); // Tutaj można ustawić faktyczną szansę na drop
dropTableConfig.set("Item" + index + ".itemName: ", item.displayName()); // Tutaj można ustawić faktyczną szansę na drop
String itemNameString = item.getType().toString();
dropTableConfig.set("Item" + index + ".itemName", itemNameString); // Tutaj można ustawić faktyczną szansę na drop
dropTableConfig.set("Item" + index + ".avgDmgBonus", false); // Tutaj można ustawić faktyczną szansę na drop
index++;
} catch (IOException e) {
pluginLogger.log(PluginLogger.LogLevel.ERROR, "Nie można zapisać przedmiotu: " + e.getMessage());
Expand All @@ -161,6 +164,7 @@ public void saveCustomDrops(String fileName, List<ItemStack> rewards) {

try {
dropTableConfig.save(dropTableFile);
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "dropTableConfig saved ");
} catch (IOException e) {
pluginLogger.log(PluginLogger.LogLevel.ERROR, "Nie można zapisać tabeli dropów: " + e.getMessage());
}
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/betterbox/mine/game/betterelo/GuiManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class GuiManager implements Listener {
private final PluginLogger pluginLogger;
public String periodType = null;
private String rewardType;
private String dropTableName;
private String dropTable;

private final DataManager dataManager;
public GuiManager(FileRewardManager fileRewardManager, PluginLogger pluginLogger, BetterElo mainClass, DataManager dataManager) {
Expand All @@ -47,8 +47,10 @@ public void openMainGui(Player player) {
//createItem(inv, Material.EMERALD, 14, "dropTable", "Create new Drop Table");
player.openInventory(inv);
}
public void openDroptableGui(Player player, String dropTable_Name) {
dropTableName= dropTable_Name;
public void openDroptableGui(Player player, String dropTableName) {

dropTable= dropTableName;
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.openDroptableGui called. dropTableName:"+dropTableName+", dropTable: "+dropTable);
Inventory inv = Bukkit.createInventory(null, 9, "Set Rewards");
createItem(inv, Material.EMERALD, 4, "dropTable", "Create new Drop Table");
player.openInventory(inv);
Expand Down Expand Up @@ -124,7 +126,8 @@ public void onInventoryClick(InventoryClickEvent event) {
String fileName=periodType+"_"+rewardType;
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClick calling fileRewardManager.saveRewards("+fileName+",itemsToSave)");
if(periodType.equals("dropTable")){
fileName=dropTableName;
fileName=dropTable;
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClick droptable: "+fileName);
fileRewardManager.saveCustomDrops(fileName, itemsToSave);
}else{
fileRewardManager.saveRewards(fileName, itemsToSave);
Expand Down

0 comments on commit 95bdd99

Please sign in to comment.