Skip to content

Commit

Permalink
Merge pull request #69 from Grzybol/release-4.4
Browse files Browse the repository at this point in the history
Release 4.4.0
  • Loading branch information
Grzybol authored Jul 7, 2024
2 parents 0efb8f3 + 4270307 commit d24aa90
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.3.47-SNAPSHOT</version>
<version>4.4.16-SNAPSHOT</version>
<packaging>jar</packaging>

<name>BetterElo</name>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package betterbox.mine.game.betterelo;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.Style;
import net.kyori.adventure.text.format.TextDecoration;
import org.bukkit.*;
import org.bukkit.attribute.Attribute;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@

import it.unimi.dsi.fastutil.Pair;
import org.bukkit.Material;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeModifier;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

import org.bukkit.Location;

public class CustomMobsFileManager {
Expand Down Expand Up @@ -340,6 +341,29 @@ private ItemStack loadItemStack(YamlConfiguration mobData, String path) {
}
}
}
try {// Ustawienie przedmiotu jako niezniszczalnego
if (mobData.contains(path + ".unbreakable") && mobData.getBoolean(path + ".unbreakable")) {
ItemMeta meta = itemStack.getItemMeta();
meta.setUnbreakable(true);
itemStack.setItemMeta(meta);
}
}catch (Exception e){
pluginLogger.log(PluginLogger.LogLevel.ERROR, "cannot read unbreakable from file. Exception: "+e.getMessage());
}

// Wczytanie atrybutów armor i damage
try {
ItemMeta meta = itemStack.getItemMeta();
if (mobData.contains(path + ".attributes.damage")) {
meta.addAttributeModifier(Attribute.GENERIC_ATTACK_DAMAGE, new AttributeModifier(UUID.randomUUID(), "generic.attackDamage", mobData.getDouble(path + ".attributes.damage"), AttributeModifier.Operation.ADD_NUMBER, EquipmentSlot.HAND));
}
if (mobData.contains(path + ".attributes.armor")) {
meta.addAttributeModifier(Attribute.GENERIC_ARMOR, new AttributeModifier(UUID.randomUUID(), "generic.armor", mobData.getDouble(path + ".attributes.armor"), AttributeModifier.Operation.ADD_NUMBER, EquipmentSlot.CHEST));
}
itemStack.setItemMeta(meta);
} catch (Exception e) {
pluginLogger.log(PluginLogger.LogLevel.ERROR, "Error reading attributes from file. Exception: " + e.getMessage());
}

return itemStack;
}
Expand Down
72 changes: 64 additions & 8 deletions src/main/java/betterbox/mine/game/betterelo/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.kyori.adventure.title.Title;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -191,9 +192,14 @@ private Player getLastAttacker(Player victim) {

@EventHandler
public void onPlayerDeath(PlayerDeathEvent event) {
Player victim = event.getEntity();
if (victim.hasMetadata("handledDeath")) {
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onEntityDamageByEntity event already handled!");
return;
}
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
try {
Player victim = event.getEntity();

Player killer = victim.getKiller();
if (!cheaters.getCheatersList().contains(victim.getName()) && !cheaters.getCheatersList().contains(killer.getName())) {
pluginLogger.log(PluginLogger.LogLevel.KILL_EVENT, "Event: onPlayerDeath: victim: " + victim + " killer: " + killer);
Expand Down Expand Up @@ -275,6 +281,13 @@ public void onPlayerDeath(PlayerDeathEvent event) {
killer.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo] " + ChatColor.DARK_RED + "Your Elo difference in the Event ranking is too big! No reward for this one.");
}
}
victim.setMetadata("handledDeath", new FixedMetadataValue(plugin, true));
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
@Override
public void run() {
victim.removeMetadata("handledDeath", plugin);
}
}, 1L);


} else {
Expand Down Expand Up @@ -1317,7 +1330,7 @@ public void onInventoryClick(InventoryClickEvent event) {
return;
}
if(event.getCurrentItem().getType() == Material.GRAY_STAINED_GLASS_PANE || event.getCurrentItem().getType() == Material.GREEN_WOOL){
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClick green wool or blank pane clicked, cancelling..");
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick green wool or blank pane clicked, cancelling..");
event.setCancelled(true);

}
Expand All @@ -1327,7 +1340,7 @@ public void onInventoryClick(InventoryClickEvent event) {
ItemStack[] savedInventory = playerInventory.getContents();

String title = event.getView().getTitle();
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClick called. title:"+title);
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick called. title:"+title);
if (!Arrays.asList("Set Rewards", "Add Items", "Select Top", "AvgDmg bonus change").contains(title)) {
return;
}
Expand Down Expand Up @@ -1370,13 +1383,13 @@ public void onInventoryClick(InventoryClickEvent event) {
case "Add Items":
//save button check
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick Add Items");
if (currentItem.getType() == Material.GREEN_WOOL && (event.getSlot() == 35 || event.getSlot() == 53)) {
if (currentItem.getType() == Material.GREEN_WOOL && (event.getSlot() == 53)) {
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 || i == 53) { // Pomijamy slot przycisku "Save"
if (i == 53) { // Pomijamy slot przycisku "Save"
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick save button, skipping.");
continue;
}
Expand All @@ -1389,14 +1402,16 @@ public void onInventoryClick(InventoryClickEvent event) {

}

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

pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick guiManager.periodType="+guiManager.periodType);
if(guiManager.periodType.equals("dropTable")){
fileName=guiManager.dropTable;
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick droptable: "+fileName);
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick calling fileRewardManager.saveCustomDrops("+fileName+",itemsToSave)");
fileRewardManager.saveCustomDrops(fileName, itemsToSave);
}else{
fileRewardManager.saveRewards(fileName, itemsToSave);
fileRewardManager.saveCustomDrops(fileName, itemsToSave);
}

}
Expand Down Expand Up @@ -1449,6 +1464,41 @@ public void run() {
inventory.setItem(3, result);
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick result placed back in slot 3");


ItemStack greenWoolItem = inventory.getItem(5);
if (greenWoolItem != null && greenWoolItem.hasItemMeta()) {
ItemMeta greenWoolMeta = greenWoolItem.getItemMeta();
List<String> greenWoolLore = greenWoolMeta.hasLore() ? new ArrayList<>(greenWoolMeta.getLore()) : new ArrayList<>();
String avgDmgLine = lore.stream().filter(line -> line.contains("Average Damage")).findFirst().orElse("Average Damage +0%");

// Ustalanie indeksów dla "current bonus:" i wartości
int bonusIndex = -1;
for (int i = 0; i < greenWoolLore.size(); i++) {
if (greenWoolLore.get(i).equals("current bonus:")) {
bonusIndex = i;
break;
}
}

if (bonusIndex != -1 && bonusIndex + 1 < greenWoolLore.size()) {
// Aktualizujemy istniejącą wartość jeśli jest miejsce w lore
greenWoolLore.set(bonusIndex + 1, "<" + avgDmgLine + ">");
} else if (bonusIndex == -1) {
// Dodajemy nowe linie jeśli "current bonus:" nie istnieje
greenWoolLore.add("current bonus:");
greenWoolLore.add("<" + avgDmgLine + ">");
} else {
// Jeśli "current bonus:" jest na końcu listy, dodajemy wartość
greenWoolLore.add("<" + avgDmgLine + ">");
}

greenWoolMeta.setLore(greenWoolLore);
greenWoolItem.setItemMeta(greenWoolMeta);
inventory.setItem(5, greenWoolItem);


}

}
}
}
Expand Down Expand Up @@ -1511,6 +1561,12 @@ public void onEntityMove(EntityMoveEvent event) {
// Można tutaj dodać dodatkowe działania, np. wysłanie informacji do logów serwera
pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Event.onEntityInteract: Mob is removing player-placed cobweb");
}
Block blockAbove = block.getRelative(BlockFace.UP);

if (blockAbove.hasMetadata("placed_by_player") && blockAbove.getType() == Material.COBWEB) {
blockAbove.setType(Material.AIR);
pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Event.onEntityInteract: Mob is removing player-placed cobweb above");
}
}

}
Expand Down
24 changes: 20 additions & 4 deletions src/main/java/betterbox/mine/game/betterelo/FileRewardManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,22 +143,32 @@ 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()) {
pluginLogger.log(PluginLogger.LogLevel.INFO, "customDropsFolder does not exist, creating a new one");
customDropsFolder.mkdirs();
}

File customDropTablesFolder = new File(plugin.getDataFolder() + File.separator + "customDropTables");
if (!customDropTablesFolder.exists()) {
pluginLogger.log(PluginLogger.LogLevel.INFO, "customDropTablesFolder does not exist, creating a new one");
customDropTablesFolder.mkdirs();
}

File dropTableFile = new File(customDropTablesFolder, fileName + ".yml");
pluginLogger.log(PluginLogger.LogLevel.INFO, "Droptable will be saved to "+fileName+".yml");
FileConfiguration dropTableConfig = new YamlConfiguration();

int index = 0;
for (ItemStack item : rewards) {
if (item == null) {
pluginLogger.log(PluginLogger.LogLevel.ERROR, "ItemStack is null at index: " + index);
continue;
}
;
String itemFileName = fileName + "_item" + index + ".yml";
File itemFile = new File(customDropsFolder, itemFileName);
pluginLogger.log(PluginLogger.LogLevel.INFO, "Droptable "+fileName+", itemFileName "+itemFileName+", index "+index+", saving item: "+item.getItemMeta().toString());

try {
File itemFile = new File(customDropsFolder, itemFileName);
itemFile.createNewFile();
FileConfiguration itemConfig = YamlConfiguration.loadConfiguration(itemFile);
itemConfig.set("item", item);
Expand All @@ -171,17 +181,23 @@ public void saveCustomDrops(String fileName, List<ItemStack> rewards) {
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
dropTableConfig.set("Item" + index + ".description", item.getItemMeta().lore().toString()); // Tutaj można ustawić faktyczną szansę na drop
if(item.getItemMeta().hasLore()) {
dropTableConfig.set("Item" + index + ".description", item.getItemMeta().lore().toString()); // Tutaj można ustawić faktyczną szansę na drop
}
dropTableConfig.set("Item" + index + ".itemName", item.displayName().toString());

index++;
} catch (IOException e) {
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "dropTableConfig with index "+index+" saved");

} catch (Exception e) {
pluginLogger.log(PluginLogger.LogLevel.ERROR, "Cannot save the item : "+index +", error: "+ e.getMessage());
}
}

try {
dropTableConfig.save(dropTableFile);
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "dropTableConfig saved ");
} catch (IOException e) {
} catch (Exception e) {
pluginLogger.log(PluginLogger.LogLevel.ERROR, "Nie można zapisać tabeli dropów: " + e.getMessage());
}
}
Expand Down

0 comments on commit d24aa90

Please sign in to comment.