diff --git a/pom.xml b/pom.xml
index 5072984..3daa192 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
betterbox.mine.game
BetterElo
- 4.6.4-SNAPSHOT
+ 4.7.1-SNAPSHOT
jar
BetterElo
@@ -18,6 +18,32 @@
+
+ org.apache.maven.plugins
+ maven-shade-plugin
+ 3.1.0
+
+
+
+ org.bstats
+
+ betterbox.mine.game.betterelo
+
+
+
+
+
+ package
+
+ shade
+
+
+ false
+
+
+
+
+
org.apache.maven.plugins
maven-jar-plugin
@@ -30,6 +56,7 @@
+
org.apache.maven.plugins
maven-compiler-plugin
@@ -40,22 +67,9 @@
-
- org.apache.maven.plugins
- maven-shade-plugin
- 3.2.4
-
-
- package
-
- shade
-
-
- false
-
-
-
-
+
+
+
org.codehaus.mojo
@@ -113,28 +127,34 @@
+
+
me.filoghost.holographicdisplays
holographicdisplays-api
3.0.0
provided
+
net.kyori
adventure-platform-bukkit
4.3.2
+
org.eclipse.jetty
jetty-server
9.4.43.v20210629
+
io.papermc.paper
paper-api
1.18.2-R0.1-SNAPSHOT
provided
+
me.clip
placeholderapi
@@ -156,5 +176,13 @@
7.0.4
provided
+
+
+ org.bstats
+ bstats-bukkit
+ 3.0.2
+ compile
+
+
diff --git a/src/main/java/betterbox/mine/game/betterelo/BetterElo.java b/src/main/java/betterbox/mine/game/betterelo/BetterElo.java
index e42d0e6..0617f5a 100644
--- a/src/main/java/betterbox/mine/game/betterelo/BetterElo.java
+++ b/src/main/java/betterbox/mine/game/betterelo/BetterElo.java
@@ -3,7 +3,9 @@
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.protection.flags.Flags;
import me.clip.placeholderapi.libs.kyori.adventure.platform.facet.Facet;
+import org.bstats.bukkit.Metrics;
import org.bukkit.*;
+import org.bukkit.attribute.Attribute;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Entity;
@@ -14,6 +16,8 @@
import net.kyori.adventure.text.Component;
import net.kyori.adventure.title.Title;
import org.bukkit.inventory.meta.ItemMeta;
+import org.bukkit.persistence.PersistentDataContainer;
+import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
@@ -34,6 +38,8 @@
import org.checkerframework.checker.units.qual.C;
public final class BetterElo extends JavaPlugin {
+ HashMap mobTasks = new HashMap<>();
+ private static BetterElo instance;
private PluginLogger pluginLogger;
private DataManager dataManager;
public final Map customMobsMap = new HashMap<>();
@@ -59,6 +65,7 @@ public final class BetterElo extends JavaPlugin {
//public static final Flag NO_ELO_FLAG = new StateFlag("noElo", false);
public static StateFlag IS_ELO_ALLOWED;
private String folderPath;
+ private NamespacedKey mobDefenseKey,mobDamageKey,averageDamageKey;
@Override
public void onLoad() {
getLogger().info("Registering custom WorldGuard flags.");
@@ -75,6 +82,12 @@ public void onLoad() {
@Override
public void onEnable() {
+ int pluginId = 22747; // Zamień na rzeczywisty ID twojego pluginu na bStats
+ Metrics metrics = new Metrics(this, pluginId);
+ this.mobDefenseKey = new NamespacedKey(this, "mob_defense");
+ this.mobDamageKey = new NamespacedKey(this, "mob_damage");
+ this.averageDamageKey = new NamespacedKey(this, "average_damage");
+ instance = this;
createPluginFolders();
createExampleDropTablesFiles();
createExampleDropsFiles();
@@ -502,6 +515,13 @@ public void run() {
pluginLogger.log(PluginLogger.LogLevel.ERROR, "BetterElo: scheduleRewards exception: "+e.getMessage());
}
}
+ public static BetterElo getInstance() {
+ return instance;
+ }
+ public CustomMobs.CustomMob getCustomMob(String mobName) {
+ // Zwróć customowego moba na podstawie nazwy
+ return customMobsMap.get(mobName);
+ }
public void stopEvent(){
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "BetterElo.stopEvent called");
if(isEventEnabled) {
@@ -750,11 +770,46 @@ public void removeAndKillAllCustomMobs() {
}
public void registerCustomMob(Entity entity, CustomMobs.CustomMob customMob) {
pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "BetterElo.registerCustomMob calleed. entity: "+entity+", customMob: "+customMob);
+ schedulePercentageHealthRegeneration(customMob.entity, customMob.regenSeconds, customMob.regenPercent);
customMobsMap.put(entity, customMob);
}
public void unregisterCustomMob(Entity entity) {
pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "BetterElo.unregisterCustomMob calleed. entity: "+entity);
customMobsMap.remove(entity);
+ if (mobTasks.containsKey(entity)) {
+ mobTasks.get(entity).cancel(); // Anuluje zadanie
+ mobTasks.remove(entity); // Usuwa referencję do zadania z mapy
+ }
+ }
+ public void schedulePercentageHealthRegeneration(LivingEntity mob, int regenSeconds, double regenPercentage) {
+ // Usuń istniejące zadanie regeneracji dla tego moba, jeśli istnieje
+ if (mobTasks.containsKey(mob)) {
+ mobTasks.get(mob).cancel();
+ }
+
+ // Utwórz nowe zadanie regeneracji
+ BukkitTask task = new BukkitRunnable() {
+ @Override
+ public void run() {
+ if (System.currentTimeMillis() - mob.getLastDamage() >= regenSeconds * 1000L) { // Przekształcenie sekund na milisekundy
+ double maxHealth = mob.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
+ double regenAmount = maxHealth * (regenPercentage / 100.0);
+ double newHealth = Math.min(mob.getHealth() + regenAmount, maxHealth);
+ mob.setHealth(newHealth);
+ }
+ }
+ }.runTaskTimer(this, 0L, regenSeconds * 20L); // Uruchamia zadanie co regenSeconds sekund
+
+ // Przechowuje zadanie dla tego moba
+ mobTasks.put(mob, task);
+ }
+
+ // Opcjonalnie, metoda do anulowania zadania regeneracji dla moba
+ public void cancelHealthRegeneration(LivingEntity mob) {
+ if (mobTasks.containsKey(mob)) {
+ mobTasks.get(mob).cancel();
+ mobTasks.remove(mob);
+ }
}
public CustomMobs.CustomMob getCustomMobFromEntity(Entity entity) {
@@ -797,5 +852,139 @@ public void run() {
}
}.runTaskTimer(this, 0L, 20L * 10); // Uruchom co 1 minutę (20 ticków = 1 sekunda)
}
+ public void addMobDefenseAttribute(ItemStack item, int value){
+ pluginLogger.log(PluginLogger.LogLevel.DEBUG, "BetterElo.addMobDefenseAttribute called with value: "+value);
+ if (item != null && item.hasItemMeta()) {
+ if(!item.hasItemMeta()){
+ item.setItemMeta(Bukkit.getItemFactory().getItemMeta(item.getType()));
+ }
+ ItemMeta meta = item.getItemMeta();
+ PersistentDataContainer dataContainer = meta.getPersistentDataContainer();
+ dataContainer.set(mobDefenseKey, PersistentDataType.INTEGER, value);
+ item.setItemMeta(meta);
+ pluginLogger.log(PluginLogger.LogLevel.DEBUG, "BetterElo.addMobDefenseAttribute value "+value+" was added to the item "+item);
+ }else{
+ pluginLogger.log(PluginLogger.LogLevel.WARNING, "BetterElo.addMobDefenseAttribute null item!"+item);
+ }
+ }
+ public void addMobDamageAttribute(ItemStack item, String value){
+ pluginLogger.log(PluginLogger.LogLevel.DEBUG, "BetterElo.addMobDamageAttribute called with value: "+value);
+ if (item != null && item.hasItemMeta()) {
+ if(!item.hasItemMeta()){
+ item.setItemMeta(Bukkit.getItemFactory().getItemMeta(item.getType()));
+ }
+ ItemMeta meta = item.getItemMeta();
+ PersistentDataContainer dataContainer = meta.getPersistentDataContainer();
+ dataContainer.set(mobDamageKey, PersistentDataType.STRING, value);
+ item.setItemMeta(meta);
+ pluginLogger.log(PluginLogger.LogLevel.DEBUG, "BetterElo.addMobDamageAttribute value "+value+" was added to the item "+item);
+ }else{
+ pluginLogger.log(PluginLogger.LogLevel.WARNING, "BetterElo.addMobDamageAttribute null item!"+item);
+ }
+ }
+ public void addAverageDamageAttribute(ItemStack item, int value){
+ pluginLogger.log(PluginLogger.LogLevel.DEBUG, "BetterElo.addAverageDamageAttribute called with value: "+value);
+ if (item != null ) {
+ if(!item.hasItemMeta()){
+ item.setItemMeta(Bukkit.getItemFactory().getItemMeta(item.getType()));
+ }
+ ItemMeta meta = item.getItemMeta();
+ PersistentDataContainer dataContainer = meta.getPersistentDataContainer();
+ dataContainer.set(averageDamageKey, PersistentDataType.INTEGER, value);
+ item.setItemMeta(meta);
+ pluginLogger.log(PluginLogger.LogLevel.DEBUG, "BetterElo.addAverageDamageAttribute value "+value+" was added to the item "+item);
+ }else{
+ pluginLogger.log(PluginLogger.LogLevel.WARNING, "BetterElo.addAverageDamageAttribute null item!"+item);
+ }
+ }
+ public int[] getMobDamageAttribute(ItemStack item) {
+ if (item != null && item.hasItemMeta()) {
+ ItemMeta meta = item.getItemMeta();
+ PersistentDataContainer dataContainer = meta.getPersistentDataContainer();
+ if (dataContainer.has(mobDamageKey, PersistentDataType.STRING)) {
+ String damageRange = dataContainer.get(mobDamageKey, PersistentDataType.STRING);
+ String[] parts = damageRange.split("-");
+ int minDamage = Integer.parseInt(parts[0]);
+ int maxDamage = Integer.parseInt(parts[1]);
+ return new int[]{minDamage, maxDamage};
+ }
+ }
+ return new int[]{0, 0};
+ }
+
+ public int getMobDefenseAttribute(List wornItems) {
+ int totalDefense = 0;
+
+ for (ItemStack item : wornItems) {
+ if (item != null && item.hasItemMeta()) {
+ ItemMeta meta = item.getItemMeta();
+ PersistentDataContainer dataContainer = meta.getPersistentDataContainer();
+ if (dataContainer.has(mobDefenseKey, PersistentDataType.INTEGER)) {
+ totalDefense += dataContainer.get(mobDefenseKey, PersistentDataType.INTEGER);
+ }
+ }
+ }
+
+ return totalDefense;
+ }
+
+ public int getAverageDamageAttribute(List wornItems) {
+ int totalDamage = 0;
+
+ for (ItemStack item : wornItems) {
+ if (item != null && item.hasItemMeta()) {
+ ItemMeta meta = item.getItemMeta();
+ PersistentDataContainer dataContainer = meta.getPersistentDataContainer();
+ if (dataContainer.has(averageDamageKey, PersistentDataType.INTEGER)) {
+ totalDamage += dataContainer.get(averageDamageKey, PersistentDataType.INTEGER);
+ }
+ }
+ }
+
+ return totalDamage;
+ }
+ public int getAverageDamageAttribute(ItemStack item) {
+ int totalDamage = 0;
+
+ if (item != null && item.hasItemMeta()) {
+ ItemMeta meta = item.getItemMeta();
+ PersistentDataContainer dataContainer = meta.getPersistentDataContainer();
+ if (dataContainer.has(averageDamageKey, PersistentDataType.INTEGER)) {
+ totalDamage += dataContainer.get(averageDamageKey, PersistentDataType.INTEGER);
+ }
+ }
+
+ return totalDamage;
+ }
+ public boolean hasMobDamageAttribute(ItemStack item) {
+ if (item != null && item.hasItemMeta()) {
+ ItemMeta meta = item.getItemMeta();
+ PersistentDataContainer dataContainer = meta.getPersistentDataContainer();
+ if (dataContainer.has(mobDamageKey, PersistentDataType.STRING)) {
+ return true;
+ }
+ }
+ return false;
+ }
+ public boolean hasMobDefenseAttribute(ItemStack item) {
+ if (item != null && item.hasItemMeta()) {
+ ItemMeta meta = item.getItemMeta();
+ PersistentDataContainer dataContainer = meta.getPersistentDataContainer();
+ if (dataContainer.has(mobDefenseKey, PersistentDataType.INTEGER)) {
+ return true;
+ }
+ }
+ return false;
+ }
+ public boolean hasAverageDamageAttribute(ItemStack item) {
+ if (item != null && item.hasItemMeta()) {
+ ItemMeta meta = item.getItemMeta();
+ PersistentDataContainer dataContainer = meta.getPersistentDataContainer();
+ if (dataContainer.has(averageDamageKey, PersistentDataType.INTEGER)) {
+ return true;
+ }
+ }
+ return false;
+ }
}
diff --git a/src/main/java/betterbox/mine/game/betterelo/BetterEloCommand.java b/src/main/java/betterbox/mine/game/betterelo/BetterEloCommand.java
index 977475e..4e1597e 100644
--- a/src/main/java/betterbox/mine/game/betterelo/BetterEloCommand.java
+++ b/src/main/java/betterbox/mine/game/betterelo/BetterEloCommand.java
@@ -384,71 +384,82 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
}
case 3:
- if (sender.isOp()&& Objects.equals(args[0], "spawnmob")){
- pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS,"BetterEloCommand.OnCommand calling handleCustomMobsCommands(sender)");
- try{
- handleCustomMobsCommands(sender, args[1], Integer.parseInt(args[2]));
- }catch (Exception e){
- pluginLogger.log(PluginLogger.LogLevel.ERROR,"BetterEloCommand.OnCommand spawnmob command generated exception: "+e);
- }
+ if (sender.isOp()) {
+ switch (args[0]) {
+ case "spawnmob":
+ pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "BetterEloCommand.OnCommand calling handleCustomMobsCommands(sender)");
+ try {
+ handleCustomMobsCommands(sender, args[1], Integer.parseInt(args[2]));
+ } catch (Exception e) {
+ pluginLogger.log(PluginLogger.LogLevel.ERROR, "BetterEloCommand.OnCommand spawnmob command generated exception: " + e);
+ }
+ break;
- }
- if ((sender.hasPermission("betterelo.flamethrower") || sender.isOp()) && sender instanceof Player && Objects.equals(args[0], "flamethrower")) {
- Player player = ((Player) sender).getPlayer();
- assert player != null;
- ItemStack itemInHand = player.getInventory().getItemInMainHand();
- if (itemInHand.getType().isAir()) {
- sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo]" + ChatColor.DARK_RED + "You must hold an item in your hand to add Antyweb lore!");
- return true;
- }
- int radius;
- int distance;
- try {
- // Spróbuj przekonwertować argument na liczbę
- radius = Integer.parseInt(args[1]);
- } catch (NumberFormatException e) {
- sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo]" + ChatColor.DARK_RED +"Invalid radius! Please provide a number.");
- return true;
- }
- try {
- // Spróbuj przekonwertować argument na liczbę
- distance = Integer.parseInt(args[2]);
- } catch (NumberFormatException e) {
- sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo]" + ChatColor.DARK_RED +"Invalid radius! Please provide a number.");
- return true;
- }
- addFlamethrowerLore(player, itemInHand, radius, distance);
- }
- if (sender.isOp()&& Objects.equals(args[0], "holo")&& Objects.equals(args[1], "delete")&&args[2].equals("event")){
- hologramEvent.delete();
- //hologramEvent.isDeleted();
- sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo]" + ChatColor.AQUA + "Holo for Event removed! " + hologramEvent.isDeleted());
- eventHoloTask.cancel();
- }
- if (sender.isOp()&& Objects.equals(args[0], "startevent")){
- int eventDuration = Integer.parseInt(args[1]);
- String eventUnit = args[2];
- pluginLogger.log(PluginLogger.LogLevel.DEBUG,"BetterEloCommand.onCommand.event called. Duration:"+args[1]+" timeUnit:"+args[2]);
- betterElo.eventDuration= Integer.parseInt(args[1]);
- betterElo.eventUnit=args[2];
- betterElo.isEventEnabled=true;
- pluginLogger.log(PluginLogger.LogLevel.DEBUG,"BetterElo: onEnable: Planowanie nagród event...");
- long periodMillis =0;
- if(Objects.equals(eventUnit, "h")) {
- periodMillis = TimeUnit.HOURS.toMillis(eventDuration);
- }else if(Objects.equals(eventUnit, "m")){
- periodMillis = TimeUnit.MINUTES.toMillis(eventDuration);
- }else{
- pluginLogger.log(PluginLogger.LogLevel.ERROR,"BetterEloCommand.onCommand.event: eventUnit: "+eventUnit);
+ case "startevent":
+ int eventDuration;
+ try {
+ eventDuration = Integer.parseInt(args[1]);
+ } catch (NumberFormatException e) {
+ pluginLogger.log(PluginLogger.LogLevel.ERROR, "Invalid event duration: " + args[1]);
+ sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo]" + ChatColor.DARK_RED + " Invalid event duration!");
+ return true;
+ }
+
+ String eventUnit = args[2];
+ pluginLogger.log(PluginLogger.LogLevel.DEBUG, "BetterEloCommand.onCommand.event called. Duration:" + args[1] + " timeUnit:" + args[2]);
+ betterElo.eventDuration = eventDuration;
+ betterElo.eventUnit = eventUnit;
+ betterElo.isEventEnabled = true;
+ pluginLogger.log(PluginLogger.LogLevel.DEBUG, "BetterElo: onEnable: Planowanie nagród event...");
+
+ long periodMillis = 0;
+ switch (eventUnit) {
+ case "h":
+ periodMillis = TimeUnit.HOURS.toMillis(eventDuration);
+ break;
+ case "m":
+ periodMillis = TimeUnit.MINUTES.toMillis(eventDuration);
+ break;
+ default:
+ pluginLogger.log(PluginLogger.LogLevel.ERROR, "BetterEloCommand.onCommand.event: eventUnit: " + eventUnit);
+ sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo]" + ChatColor.DARK_RED + " Invalid time unit!");
+ return true;
+ }
+
+ pluginLogger.log(PluginLogger.LogLevel.DEBUG, "BetterEloCommand.onCommand.event: scheduling event rewards periodMillis:" + periodMillis);
+ betterElo.scheduleRewards("event", periodMillis, false);
+ betterElo.rewardStates.put("event", true);
+ betterElo.loadRewards();
+ pluginLogger.log(PluginLogger.LogLevel.DEBUG, "BetterEloCommand.onCommand.event: calling betterElo.updateLastScheduledTime(event)");
+ betterElo.updateLastScheduledTime("event");
+ sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo]" + ChatColor.AQUA + " Event started! Duration " + eventDuration + " " + eventUnit);
+ break;
+
+ case "setattribute":
+ Player player = (Player) sender;
+ ItemStack item = player.getInventory().getItemInMainHand();
+ if(item!=null&&!item.getType().equals("AIR")){
+ switch (args[1]){
+ case "mobdefense":
+ betterElo.addMobDefenseAttribute(item, Integer.parseInt(args[2]));
+ sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo]" + ChatColor.AQUA + " MobDefense attribute set with value "+args[2]);
+ break;
+ case "mobdamage":
+ betterElo.addMobDamageAttribute(item, args[2]);
+ sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo]" + ChatColor.AQUA + " mobdamage attribute set with value "+args[2]);
+ break;
+ case "averagedamage":
+ betterElo.addAverageDamageAttribute(item, Integer.parseInt(args[2]));
+ sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo]" + ChatColor.AQUA + " averagedamage attribute set with value "+args[2]);
+ break;
+ }
+ }
+
+ default:
+ sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo]" + ChatColor.DARK_RED + " You don't have permission to use that command!");
+ break;
}
- pluginLogger.log(PluginLogger.LogLevel.DEBUG,"BetterEloCommand.onCommand.event: scheduling event rewards periodMillis:"+periodMillis);
- betterElo.scheduleRewards("event", periodMillis, false);
- betterElo.rewardStates.put("event", true);
- betterElo.loadRewards();
- pluginLogger.log(PluginLogger.LogLevel.DEBUG,"BetterEloCommand.onCommand.event: calling betterElo.updateLastScheduledTime(event)");
- betterElo.updateLastScheduledTime("event");
- sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo]" + ChatColor.AQUA + " Event started! Duration "+eventDuration+" "+eventUnit);
- }else{
+ } else {
sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo]" + ChatColor.DARK_RED + " You don't have permission to use that command!");
return true;
}
diff --git a/src/main/java/betterbox/mine/game/betterelo/CustomMobs.java b/src/main/java/betterbox/mine/game/betterelo/CustomMobs.java
index af0420f..2e631bc 100644
--- a/src/main/java/betterbox/mine/game/betterelo/CustomMobs.java
+++ b/src/main/java/betterbox/mine/game/betterelo/CustomMobs.java
@@ -15,6 +15,8 @@
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.metadata.MetadataValue;
+import org.bukkit.persistence.PersistentDataContainer;
+import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
@@ -27,6 +29,7 @@
public class CustomMobs {
private Map customMobsMap = new HashMap<>();
+
private final PluginLogger pluginLogger;
private final JavaPlugin plugin;
private final BetterElo betterElo;
@@ -45,16 +48,18 @@ static class CustomMob {
ItemStack helmet, chestplate, leggings, boots, weapon;
//HashMap< Double,ItemStack> dropTable;
List dropTable;
- double armor, speed, attackDamage, EMKSchance;
- int hp, attackSpeed, defense;
+ double armor, speed, attackDamage, EMKSchance, regenPercent, knockbackResistance;
+ String passengerMobName; // Nowe pole dla nazwy pasażera
+ int hp, attackSpeed, defense, regenSeconds;
Map customMetadata; // Nowe pole do przechowywania niestandardowych metadanych
JavaPlugin plugin;
CustomMobsFileManager dropFileManager;
- CustomMob(JavaPlugin plugin, CustomMobsFileManager dropFileManager, String mobName, EntityType entityType, ItemStack helmet, ItemStack chestplate, ItemStack leggings, ItemStack boots, ItemStack weapon, double armor, int hp, double speed, double attackDamage, int attackSpeed, Map customMetadata, String dropTableName, Boolean dropEMKS, double EMKSchance, int defense) {
+ CustomMob(JavaPlugin plugin, CustomMobsFileManager dropFileManager, String mobName, EntityType entityType, ItemStack helmet, ItemStack chestplate, ItemStack leggings, ItemStack boots, ItemStack weapon, double armor, int hp, double speed, double attackDamage, int attackSpeed, Map customMetadata, String dropTableName, int defense, String passengerMobName, int regenSeconds,double regenPercent, double knockbackResistance) {
this.plugin = plugin;
- this.dropEMKS = dropEMKS;
- this.EMKSchance = EMKSchance;
+ this.regenSeconds=regenSeconds;
+ this.regenPercent=regenPercent;
+ this.passengerMobName=passengerMobName;
this.mobName = mobName;
this.entity = entity;
if (weapon != null) {
@@ -88,13 +93,36 @@ static class CustomMob {
this.defense = defense;
this.attackDamage = attackDamage;
this.customMetadata = customMetadata;
+ this.knockbackResistance = knockbackResistance;
//setupMob();
}
- CustomMob(JavaPlugin plugin, CustomMobsFileManager dropFileManager, String mobName, EntityType entityType, double armor, int hp, double speed, double attackDamage, int attackSpeed, Map customMetadata, String dropTableName, Boolean dropEMKS, double EMKSchance, int defense) {
+ CustomMob(JavaPlugin plugin, CustomMobsFileManager dropFileManager, String mobName, EntityType entityType, double armor, int hp, double speed, double attackDamage, int attackSpeed, Map customMetadata, String dropTableName, int defense, int regenSeconds,double regenPercent, double knockbackResistance) {
+ this.plugin = plugin;
+ this.regenSeconds=regenSeconds;
+ this.regenPercent=regenPercent;
+ this.mobName = mobName;
+ this.entity = entity;
+ this.entityType = entityType;
+ this.dropFileManager = dropFileManager;
+ this.dropTableName = dropTableName;
+ //this.dropTable = dropFileManager.loadCustomDrops(dropTableName);
+ this.dropTable = dropFileManager.loadCustomDropsv2(dropTableName);
+ this.armor = armor;
+ this.hp = hp;
+ this.attackSpeed = attackSpeed;
+ this.speed = speed;
+ this.defense = defense;
+ this.attackDamage = attackDamage;
+ this.customMetadata = customMetadata;
+ this.knockbackResistance = knockbackResistance;
+ //setupMob();
+ }
+ CustomMob(JavaPlugin plugin, CustomMobsFileManager dropFileManager, String mobName, EntityType entityType, double armor, int hp, double speed, double attackDamage, int attackSpeed, Map customMetadata, String dropTableName, int defense, String passengerMobName,int regenSeconds,double regenPercent, double knockbackResistance) {
this.plugin = plugin;
- this.dropEMKS = dropEMKS;
- this.EMKSchance = EMKSchance;
+ this.regenSeconds=regenSeconds;
+ this.knockbackResistance = knockbackResistance;
+ this.regenPercent=regenPercent;
this.mobName = mobName;
this.entity = entity;
this.entityType = entityType;
@@ -102,6 +130,7 @@ static class CustomMob {
this.dropTableName = dropTableName;
//this.dropTable = dropFileManager.loadCustomDrops(dropTableName);
this.dropTable = dropFileManager.loadCustomDropsv2(dropTableName);
+ this.passengerMobName = passengerMobName;
this.armor = armor;
this.hp = hp;
this.attackSpeed = attackSpeed;
@@ -115,32 +144,48 @@ static class CustomMob {
// Metoda do stworzenia i ustawienia encji moba
public void spawnMob(Location location) {
if (this.entityType == null) {
- plugin.getLogger().warning("EntityType nie jest ustawiony dla " + mobName);
+ plugin.getLogger().warning("EntityType not set for " + mobName);
return;
}
this.entity = (LivingEntity) location.getWorld().spawnEntity(location, entityType);
+
setupMob(); // Teraz wywołujemy setupMob() po stworzeniu encji
((BetterElo) plugin).registerCustomMob(this.entity, this);
+
}
+ public Entity getEntity(){
+ return entity;
+ }
+
public CustomMob cloneForSpawn(Location spawnLocation, String mobType) {
CustomMob newMob = null;
- if (mobType.equals("SKELETON") || mobType.equals("ZOMBIE")) {
+ if (mobType.equals("SKELETON") || mobType.equals("ZOMBIE") || mobType.equals("STRAY")|| mobType.equals("HUSK")|| mobType.equals("WITHER_SKELETON")) {
newMob = new CustomMob(this.plugin, this.dropFileManager, this.mobName, this.entityType,
this.helmet.clone(), this.chestplate.clone(),
this.leggings.clone(), this.boots.clone(), this.weapon.clone(),
this.armor, this.hp, this.speed,
- this.attackDamage, this.attackSpeed, new HashMap<>(this.customMetadata), this.dropTableName, this.dropEMKS, this.EMKSchance, this.defense);
+ this.attackDamage, this.attackSpeed, new HashMap<>(this.customMetadata), this.dropTableName, this.defense, this.passengerMobName, this.regenSeconds, this.regenPercent, this.knockbackResistance);
newMob.spawnMob(spawnLocation);
} else {
newMob = new CustomMob(this.plugin, this.dropFileManager, this.mobName, this.entityType,
this.armor, this.hp, this.speed,
- this.attackDamage, this.attackSpeed, new HashMap<>(this.customMetadata), this.dropTableName, this.dropEMKS, this.EMKSchance, this.defense);
+ this.attackDamage, this.attackSpeed, new HashMap<>(this.customMetadata), this.dropTableName, this.defense, this.regenSeconds, this.regenPercent, this.knockbackResistance);
newMob.spawnMob(spawnLocation);
}
return newMob;
}
+ public CustomMob cloneForSpawn(Location spawnLocation) {
+
+ CustomMob newMob = null;
+ newMob = new CustomMob(this.plugin, this.dropFileManager, this.mobName, this.entityType,
+ this.armor, this.hp, this.speed,
+ this.attackDamage, this.attackSpeed, new HashMap<>(this.customMetadata), this.dropTableName, this.defense, this.passengerMobName, this.regenSeconds, this.regenPercent, this.knockbackResistance);
+ newMob.spawnMob(spawnLocation);
+
+ return newMob;
+ }
private void setupMob() {
if (entity == null) {
@@ -164,6 +209,7 @@ private void setupMob() {
entity.setHealth(hp);
entity.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).setBaseValue(speed);
entity.getAttribute(Attribute.GENERIC_ATTACK_DAMAGE).setBaseValue(attackDamage);
+ entity.getAttribute(Attribute.GENERIC_KNOCKBACK_RESISTANCE).setBaseValue(knockbackResistance); // Ustawienie knockbackResistance
//plugin.getLogger().info("attackSpeed: "+attackSpeed);
//entity.getAttribute(Attribute.GENERIC_ATTACK_SPEED).setBaseValue(attackSpeed);
@@ -182,9 +228,11 @@ public String getMobName() {
}
+
}
+
public CustomMobs(PluginLogger pluginLogger, JavaPlugin plugin, CustomMobsFileManager fileManager, FileRewardManager fileRewardManager, BetterElo betterElo) {
this.plugin = plugin;
this.betterElo = betterElo;
@@ -222,7 +270,7 @@ public void updateCustomMobName(LivingEntity mob) {
mob.setCustomNameVisible(true);
}
- public static String dropAverageDamage() {
+ public static int dropAverageDamage() {
// Używamy funkcji wykładniczej do zmniejszenia prawdopodobieństwa wyższych wartości
double x = -Math.log(random.nextDouble()) / 10.0; // Dostosuj parametr 10.0, aby zmienić rozkład
//double y = random.
@@ -231,7 +279,7 @@ public static String dropAverageDamage() {
// Ograniczamy wartość bonusu do maksymalnie 60%
bonus = Math.min(bonus, 60);
- return "§6§lAverage Damage +" + bonus + "%";
+ return bonus;
}
public void spawnCustomMobFromSpawner() {
@@ -503,10 +551,7 @@ public void loadCustomMobs() {
}
}
- public CustomMob getCustomMob(String mobName) {
- // Zwróć customowego moba na podstawie nazwy
- return customMobsMap.get(mobName);
- }
+
public Entity getEntityForCustomMob(CustomMob customMob) {
// Sprawdzenie, czy przypisana encja do moba istnieje
if (customMob != null && customMob.entity != null) {
@@ -521,10 +566,27 @@ public void spawnCustomMob(Location location, String spawnerName, String mobName
CustomMob templateMob = customMobsMap.get(mobName);
if (templateMob != null) {
Location adjustedLocation = adjustLocationToAirAbove(location);
- CustomMob newMob = templateMob.cloneForSpawn(adjustedLocation, templateMob.entityType.toString());
- newMob.customMetadata.put("SpawnerName", spawnerName);
- newMob.spawnerName = spawnerName;
- //newMob.dropTable = fileManager.loadCustomDrops(newMob.dropTableName);
+ CustomMob newMob=null;
+
+ if(templateMob.passengerMobName!=null){
+ newMob = templateMob.cloneForSpawn(adjustedLocation);
+ newMob.customMetadata.put("SpawnerName", spawnerName);
+ newMob.spawnerName = spawnerName;
+ CustomMob passengerTemplateMob = customMobsMap.get(templateMob.passengerMobName);
+ if(passengerTemplateMob!=null) {
+ pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "CustomMobs.spawnCustomMob spawning newMob.passengerMobName: "+newMob.passengerMobName);
+ CustomMob newPassengerMob = passengerTemplateMob.cloneForSpawn(adjustedLocation, passengerTemplateMob.entityType.toString());
+ pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "CustomMobs.spawnCustomMob newMob.passengerMobName: "+newMob.passengerMobName+" spawned, adding as passenger");
+ newMob.entity.addPassenger(newPassengerMob.entity);
+ newPassengerMob.customMetadata.put("SpawnerName", spawnerName);
+ newPassengerMob.spawnerName = spawnerName;
+ spawnedMobsMap.put(newPassengerMob.entity.getUniqueId(), spawnerName);
+ }
+ }else{
+ newMob = templateMob.cloneForSpawn(adjustedLocation, templateMob.entityType.toString());
+ newMob.customMetadata.put("SpawnerName", spawnerName);
+ newMob.spawnerName = spawnerName;
+ }
pluginLogger.log(PluginLogger.LogLevel.DROP, "CustomMobs.spawnCustomMob newMob.dropTablename: "+newMob.dropTableName+", newMob.dropTable: "+newMob.dropTable);
pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "CustomMobs.spawnCustomMob newMob.spawnerName: "+newMob.spawnerName);
try{
@@ -543,10 +605,21 @@ public void spawnCustomMob(Location location, String mobName) {
pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "CustomMobs.spawnCustomMob called, mobName: " + mobName+", location: "+location+", mobtype: "+templateMob.entityType.toString());
if (templateMob != null) {
Location adjustedLocation = adjustLocationToAirAbove(location);
- CustomMob newMob = templateMob.cloneForSpawn(adjustedLocation, templateMob.entityType.toString());
- //newMob.dropTable = fileManager.loadCustomDrops(newMob.dropTableName);
- pluginLogger.log(PluginLogger.LogLevel.DROP, "CustomMobs.spawnCustomMob newMob.dropTablename: "+newMob.dropTableName+", newMob.dropTable: "+newMob.dropTable);
- pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "CustomMobs.spawnCustomMob newMob.spawnerName: "+newMob.spawnerName);
+ CustomMob newMob = null;
+
+ pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "CustomMobs.spawnCustomMob newMob.passengerMobName: "+templateMob.passengerMobName);
+ if(templateMob.passengerMobName!=null){
+ newMob = templateMob.cloneForSpawn(adjustedLocation);
+ CustomMob passengerTemplateMob = customMobsMap.get(templateMob.passengerMobName);
+ if(passengerTemplateMob!=null) {
+ pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "CustomMobs.spawnCustomMob spawning newMob.passengerMobName: "+newMob.passengerMobName);
+ CustomMob newPassengerMob = passengerTemplateMob.cloneForSpawn(adjustedLocation, passengerTemplateMob.entityType.toString());
+ pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "CustomMobs.spawnCustomMob newMob.passengerMobName: "+newMob.passengerMobName+" spawned, adding as passenger");
+ newMob.entity.addPassenger(newPassengerMob.entity);
+ }
+ }else{
+ newMob = templateMob.cloneForSpawn(adjustedLocation, templateMob.entityType.toString());
+ }
} else {
pluginLogger.log(PluginLogger.LogLevel.ERROR, "CustomMobs.spawnCustomMob failed, mob not found: " + mobName);
}
@@ -554,4 +627,6 @@ public void spawnCustomMob(Location location, String mobName) {
+
+
}
diff --git a/src/main/java/betterbox/mine/game/betterelo/CustomMobsFileManager.java b/src/main/java/betterbox/mine/game/betterelo/CustomMobsFileManager.java
index 0a48424..ed0d0f7 100644
--- a/src/main/java/betterbox/mine/game/betterelo/CustomMobsFileManager.java
+++ b/src/main/java/betterbox/mine/game/betterelo/CustomMobsFileManager.java
@@ -48,6 +48,7 @@ static class SpawnerData {
int mobCount;
int spawnedMobCount; // Counter for spawned mobs
int maxMobs;
+ String passengerMobName; // Nazwa CustomMob jako pasażer
SpawnerData(String spawnerName, String location, String mobName, int cooldown, int mobCount, int maxMobs, int maxDistance) {
this.spawnerName = spawnerName;
@@ -59,6 +60,17 @@ static class SpawnerData {
this.maxDistance = maxDistance;
this.spawnedMobCount = 0; // Initialize the spawned mob counter to 0
}
+ SpawnerData(String spawnerName, String location, String mobName, String passengerMobName, int cooldown, int mobCount, int maxMobs, int maxDistance) {
+ this.spawnerName = spawnerName;
+ this.location = location;
+ this.mobName = mobName;
+ this.passengerMobName = passengerMobName; // Inicjalizacja z nazwą CustomMob jako pasażer
+ this.cooldown = cooldown;
+ this.mobCount = mobCount;
+ this.maxMobs = maxMobs;
+ this.maxDistance = maxDistance;
+ this.spawnedMobCount = 0;
+ }
public int getSpawnedMobCount() {
return this.spawnedMobCount;
}
@@ -172,9 +184,12 @@ public void loadSpawners() {
//default 20 blocks
int maxDistance = 20;
maxDistance=spawnerSection.getInt("maxDistance");
+
+ String passengerMobName = spawnerSection.getString("passengerMobName", null);
+
// Zapisywanie danych spawnera do struktury w pamięci
- spawnersData.put(key, new SpawnerData(key,location, mobName, cooldown,mobCount, maxMobs,maxDistance));
- pluginLogger.log(PluginLogger.LogLevel.INFO, "Spawner "+key+" with mobName: "+mobName+", location: ("+location+"), cooldown: "+cooldown+", mobsPerSpawn: "+mobCount+", maxMobs: "+maxMobs+" loaded!");
+ spawnersData.put(key, new SpawnerData(key, location, mobName, passengerMobName, cooldown, mobCount, maxMobs, maxDistance));
+ pluginLogger.log(PluginLogger.LogLevel.INFO, "Spawner " + key + " loaded with passenger " + passengerMobName);
}
}
pluginLogger.log(PluginLogger.LogLevel.INFO, "Loaded spawners data from file.");
@@ -207,7 +222,7 @@ public int getMaxDistance(String spawnerName){
return spawnerData.maxDistance;
} else {
// If the spawnerName is not found, log an error and return a default value or throw an exception
- pluginLogger.log(PluginLogger.LogLevel.ERROR, "Spawner '" + spawnerName + "' not found.");
+ pluginLogger.log(PluginLogger.LogLevel.ERROR, "getMaxDistance Spawner '" + spawnerName + "' not found.");
return 20; // or any other default value that indicates an error
}
}
@@ -219,7 +234,7 @@ public String getSpawnerMobName(String spawnerName){
return spawnerData.mobName;
} else {
// If the spawnerName is not found, log an error and return a default value or throw an exception
- pluginLogger.log(PluginLogger.LogLevel.ERROR, "Spawner '" + spawnerName + "' not found.");
+ pluginLogger.log(PluginLogger.LogLevel.ERROR, "getSpawnerMobName Spawner '" + spawnerName + "' not found.");
return null; // or any other default value that indicates an error
}
}
@@ -231,7 +246,7 @@ public String getSpawnerLocation(String spawnerName){
return spawnerData.location;
} else {
// If the spawnerName is not found, log an error and return a default value or throw an exception
- pluginLogger.log(PluginLogger.LogLevel.ERROR, "Spawner '" + spawnerName + "' not found.");
+ pluginLogger.log(PluginLogger.LogLevel.ERROR, "getSpawnerLocation Spawner '" + spawnerName + "' not found.");
return null; // or any other default value that indicates an error
}
}
@@ -244,7 +259,7 @@ public int getSpawnerCooldown(String spawnerName) {
return spawnerData.cooldown;
} else {
// If the spawnerName is not found, log an error and return a default value or throw an exception
- pluginLogger.log(PluginLogger.LogLevel.ERROR, "Spawner '" + spawnerName + "' not found.");
+ pluginLogger.log(PluginLogger.LogLevel.ERROR, "getSpawnerCooldown Spawner '" + spawnerName + "' not found.");
return -1; // or any other default value that indicates an error
}
}
@@ -256,7 +271,7 @@ public int getSpawnerMaxMobs(String spawnerName){
return spawnerData.maxMobs;
} else {
// If the spawnerName is not found, log an error and return a default value or throw an exception
- pluginLogger.log(PluginLogger.LogLevel.ERROR, "Spawner '" + spawnerName + "' not found.");
+ pluginLogger.log(PluginLogger.LogLevel.ERROR, "getSpawnerMaxMobs Spawner '" + spawnerName + "' not found.");
return -1; // or any other default value that indicates an error
}
}
@@ -288,7 +303,7 @@ public CustomMobs.CustomMob loadCustomMob(JavaPlugin plugin, FileRewardManager d
ItemStack boots=null;
ItemStack weapon=null;
pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "CustomMobsFileManager.loadCustomMob entityTypeString: "+entityTypeString);
- if (entityTypeString.equals("SKELETON")||entityTypeString.equals("ZOMBIE")) {// Wczytanie wyposażenia z pliku
+ if (entityTypeString.equals("SKELETON")||entityTypeString.equals("ZOMBIE")|| entityTypeString.equals("STRAY")|| entityTypeString.equals("WITHER_SKELETON") || entityTypeString.equals("WITHER_SKELETON")|| entityTypeString.equals("HUSK")) {// Wczytanie wyposażenia z pliku
pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "CustomMobsFileManager.loadCustomMob mob is ZOMBIE or SKELETON");
helmet = loadItemStack(mobData, "equipment.helmet");
chestplate = loadItemStack(mobData, "equipment.chestplate");
@@ -301,20 +316,12 @@ public CustomMobs.CustomMob loadCustomMob(JavaPlugin plugin, FileRewardManager d
int hp = mobData.getInt("hp");
double speed = mobData.getDouble("speed");
double attackDamage = mobData.getDouble("attackDamage");
- double EKMSchance = 0.0d;
- boolean dropEMKS = false;
int attackSpeed = 1;
+ int regenSeconds= 5;
+ double regenPercent = 5, knockbackResistance=0;
int defense = 0;
+ String passengerMobName=null;
-
- if(mobData.contains("dropEMKS")){
- dropEMKS = mobData.getBoolean("dropEMKS");
- pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "CustomMobsFileManager.loadCustomMob loaded dropEMKS:" + dropEMKS);
- }
- if(mobData.contains("EMKSchance")){
- EKMSchance = mobData.getDouble("EMKSchance");
- pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "CustomMobsFileManager.loadCustomMob loaded EKMSchance:" + EKMSchance);
- }
if(mobData.contains("attackSpeed")){
attackSpeed = mobData.getInt("attackSpeed");
pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "CustomMobsFileManager.loadCustomMob loaded AttackSpeed:" + attackSpeed);
@@ -327,11 +334,27 @@ public CustomMobs.CustomMob loadCustomMob(JavaPlugin plugin, FileRewardManager d
armor = mobData.getDouble("armor");
pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "CustomMobsFileManager.loadCustomMob loaded armor:" + armor);
}
+ if(mobData.contains("passengerMobName")){
+ passengerMobName = mobData.getString("passengerMobName");
+ pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "CustomMobsFileManager.loadCustomMob loaded passengerMobName:" + passengerMobName);
+ }
+ if(mobData.contains("regenSeconds")){
+ regenSeconds = mobData.getInt("regenSeconds");
+ pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "CustomMobsFileManager.loadCustomMob loaded regenSeconds:" + regenSeconds);
+ }
+ if(mobData.contains("regenPercent")){
+ regenPercent = mobData.getInt("regenPercent");
+ pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "CustomMobsFileManager.loadCustomMob loaded regenPercent:" + regenPercent);
+ }
+ if(mobData.contains("knockbackResistance")){
+ knockbackResistance = mobData.getDouble("knockbackResistance");
+ pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "CustomMobsFileManager.loadCustomMob loaded knockbackResistance:" + knockbackResistance);
+ }
String mobName = mobData.getString("mobName");
String dropTableName = mobData.getString("dropTable");
- pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "CustomMobsFileManager.loadCustomMob armor:" + armor + ", hp: " + hp + ", speed: " + speed + ", attackDamage: " + attackDamage + ", type: " + entityTypeString+", dropEMKS: "+dropEMKS+", EKMSchance: "+EKMSchance+", dropTablename: "+dropTableName);
+ pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "CustomMobsFileManager.loadCustomMob armor:" + armor + ", hp: " + hp + ", speed: " + speed + ", attackDamage: " + attackDamage + ", type: " + entityTypeString+", dropTablename: "+dropTableName+", passengerMobName: "+passengerMobName+", regenSeconds: "+regenSeconds+", regenPercent: "+regenPercent);
EntityType entityType = EntityType.valueOf(entityTypeString);
// Wczytanie niestandardowych metadanych i ustawienie spawnerName
@@ -341,12 +364,20 @@ public CustomMobs.CustomMob loadCustomMob(JavaPlugin plugin, FileRewardManager d
// Utworzenie instancji CustomMob
// Zakładamy, że LivingEntity jest nullem, ponieważ tworzymy moba bez konkretnej encji w świecie
CustomMobs.CustomMob customMob=null;
- if (entityTypeString.equals("SKELETON")||entityTypeString.equals("ZOMBIE")){
- pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "CustomMobsFileManager.loadCustomMob mob is ZOMBIE or SKELETON");
- customMob = new CustomMobs.CustomMob(plugin, this, mobName, entityType, helmet, chestplate, leggings, boots,weapon, armor, hp, speed, attackDamage,attackSpeed, customMetadata, dropTableName, dropEMKS, EKMSchance, defense);
-
- }else{
- customMob = new CustomMobs.CustomMob(plugin, this, mobName, entityType, armor, hp, speed, attackDamage,attackSpeed, customMetadata, dropTableName, dropEMKS, EKMSchance, defense);
+ if (entityTypeString.equals("SKELETON")||entityTypeString.equals("ZOMBIE")|| entityTypeString.equals("STRAY")|| entityTypeString.equals("WITHER_SKELETON")|| entityTypeString.equals("HUSK")){
+ pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "CustomMobsFileManager.loadCustomMob mob is ZOMBIE or SKELETON or STRAY");
+ customMob = new CustomMobs.CustomMob(plugin, this, mobName, entityType, helmet, chestplate, leggings, boots,weapon, armor, hp, speed, attackDamage,attackSpeed, customMetadata, dropTableName, defense,null, regenSeconds,regenPercent,knockbackResistance);
+ if(passengerMobName!=null) {
+ pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "CustomMobsFileManager.loadCustomMob passengerMobName: " + passengerMobName);
+ customMob = new CustomMobs.CustomMob(plugin, this, mobName, entityType, helmet, chestplate, leggings, boots,weapon, armor, hp, speed, attackDamage,attackSpeed, customMetadata, dropTableName, defense, passengerMobName, regenSeconds,regenPercent,knockbackResistance);
+ }
+ }else if(passengerMobName!=null){
+ pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "CustomMobsFileManager.loadCustomMob passengerMobName: "+passengerMobName);
+ customMob = new CustomMobs.CustomMob(plugin, this, mobName, entityType, armor, hp, speed, attackDamage,attackSpeed, customMetadata, dropTableName, defense,passengerMobName, regenSeconds,regenPercent,knockbackResistance);
+ }
+ else{
+ pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "CustomMobsFileManager.loadCustomMob normal mob");
+ customMob = new CustomMobs.CustomMob(plugin, this, mobName, entityType, armor, hp, speed, attackDamage,attackSpeed, customMetadata, dropTableName, defense, regenSeconds,regenPercent,knockbackResistance);
}
diff --git a/src/main/java/betterbox/mine/game/betterelo/Event.java b/src/main/java/betterbox/mine/game/betterelo/Event.java
index cc9e9f7..04b834a 100644
--- a/src/main/java/betterbox/mine/game/betterelo/Event.java
+++ b/src/main/java/betterbox/mine/game/betterelo/Event.java
@@ -39,6 +39,7 @@
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
+import org.jetbrains.annotations.Nullable;
import java.text.DecimalFormat;
import java.time.Duration;
@@ -49,6 +50,7 @@ public class Event implements Listener {
private final JavaPlugin plugin;
private final PluginLogger pluginLogger;
private final BetterElo betterElo;
+ private Map lastAttackTimes = new HashMap<>();
private BetterRanksCheaters cheaters;
private ExtendedConfigManager configManager;
private HashMap lastFireworkUsage = new HashMap<>();
@@ -151,8 +153,7 @@ private double handleKillEvent(String rankingType, Player victim, Player killer)
// Metoda do aktualizacji czasu ostatniego uderzenia
public void updateLastHitTime(Player player) {
- pluginLogger.log(PluginLogger.LogLevel.KILL_EVENT, "Event: updateLastHitTime called");
- pluginLogger.log(PluginLogger.LogLevel.KILL_EVENT, "Event: updateLastHitTime saving "+player.getUniqueId()+" "+System.currentTimeMillis());
+ //pluginLogger.log(PluginLogger.LogLevel.KILL_EVENT, "Event: updateLastHitTime saving "+player.getUniqueId()+" "+System.currentTimeMillis());
lastHitTime.put(player.getUniqueId(), System.currentTimeMillis());
}
@@ -479,6 +480,9 @@ public void onBreak(BlockBreakEvent event) {
@EventHandler
public void onBlockPlace(BlockPlaceEvent event) {
pluginLogger.log(PluginLogger.LogLevel.BLOCK_PLACE,"Event.onBlockPlace: called");
+ if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
+ return; // Exit if the player is in Creative mode
+ }
try {
Block block = event.getBlockPlaced();
Player player = event.getPlayer();
@@ -494,8 +498,37 @@ public void onBlockPlace(BlockPlaceEvent event) {
pluginLogger.log(PluginLogger.LogLevel.ERROR,"Event.onBlockPlace: "+e.getMessage());
}
}
+ private LivingEntity getTargetEntity(Player player) {
+ // Prosta implementacja do uzyskania celu ataku gracza
+ // Można użyć ray tracingu, aby określić, w co gracz celuje
+ Vector direction = player.getEyeLocation().getDirection().normalize();
+ for (int i = 0; i < 5; i++) { // Sprawdzenie w promieniu 5 bloków
+ Vector targetPos = player.getEyeLocation().add(direction.clone().multiply(i)).toVector();
+ for (LivingEntity entity : player.getWorld().getLivingEntities()) {
+ if (entity.getLocation().toVector().distance(targetPos) < 1.0) { // Sprawdzenie odległości od celu
+ return entity;
+ }
+ }
+ }
+ return null;
+ }
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerInteract(PlayerInteractEvent event) {
+
+ /*
+ if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) {
+ if(betterElo.hasMobDamageAttribute(event.getPlayer().getInventory().getItemInMainHand())) {
+ Player player = event.getPlayer();
+ LivingEntity target = getTargetEntity(player); // Musisz zaimplementować tę metodę do uzyskania celu
+ if (target != null) {
+ double damage = 2.0; // Ustawienie wartości obrażeń
+ target.damage(damage, player);
+ }
+ }
+ }
+
+ */
+
pluginLogger.log(PluginLogger.LogLevel.PLAYER_INTERACT,"Event.onPlayerInteract called");
Player player = event.getPlayer();
ItemStack itemInHand = player.getInventory().getItemInMainHand();
@@ -1001,25 +1034,28 @@ public void onMobDeath(EntityDeathEvent event) {
ItemStack item = dropItem.getItemStack();
ItemMeta meta = item.getItemMeta();
pluginLogger.log(PluginLogger.LogLevel.DROP, "Event.onMobDeath dropItem.isAvgDmgBonus(): "+dropItem.isAvgDmgBonus());
- int i=0;
if (dropItem.isAvgDmgBonus()) {
- List lore = meta.getLore();
- // Zastąp znalezioną linię nowym tekstem
- String AvgDmgBonus = CustomMobs.dropAverageDamage();
- if(lore!=null) {
- lore.add(AvgDmgBonus);
- }else{
- lore.set(0,AvgDmgBonus);
- }
- pluginLogger.log(PluginLogger.LogLevel.DROP, "Event.onMobDeath Added AvgDmgBonus: "+AvgDmgBonus);
+ int AvgDmgBonus = CustomMobs.dropAverageDamage();
- pluginLogger.log(PluginLogger.LogLevel.DROP, "Event.onMobDeath lore to save: "+lore);
- // Zapisz zmodyfikowane lore z powrotem do metadanych przedmiotu
+ List lore = meta.getLore();
+ if (lore == null) {
+ lore = new ArrayList<>();
+ }
+ lore.add("§6§lAverage Damage +"+AvgDmgBonus+"%");
meta.setLore(lore);
+ pluginLogger.log(PluginLogger.LogLevel.DROP, "Event.onMobDeath item: "+item);
item.setItemMeta(meta);
+ pluginLogger.log(PluginLogger.LogLevel.DROP, "Event.onMobDeath AvgDmgBonus: "+AvgDmgBonus+", hasAverageDamageAttribute(item):"+betterElo.hasAverageDamageAttribute(item));
+ betterElo.addAverageDamageAttribute(item,AvgDmgBonus);
+ pluginLogger.log(PluginLogger.LogLevel.DROP, "Event.onMobDeath AvgDmgBonus: "+AvgDmgBonus+", hasAverageDamageAttribute(item):"+betterElo.hasAverageDamageAttribute(item)+", getAverageDamageAttribute: "+betterElo.getAverageDamageAttribute(item));
+
}
+
+ pluginLogger.log(PluginLogger.LogLevel.DROP, "Event.onMobDeath item: "+item);
drops.add(item);
+ pluginLogger.log(PluginLogger.LogLevel.DROP, "Event.onMobDeath drops.toArray()[0]: "+drops.toArray()[0]);
+
pluginLogger.log(PluginLogger.LogLevel.DROP, "Event.onMobDeath Added item from dropTable to the drops. dropChance: "+dropChance+", rolledChance: "+rolledCance);
}else{
pluginLogger.log(PluginLogger.LogLevel.DROP,"Event.onMobDeath Item from dropTable not added, chance failed. dropChance: "+dropChance+", rolledChance: "+rolledCance);
@@ -1035,16 +1071,6 @@ public void onMobDeath(EntityDeathEvent event) {
}else {
pluginLogger.log(PluginLogger.LogLevel.WARNING,"Event.onMobDeath customMob object is null!");
}
- if(customMob.dropEMKS) {
- double EMKSchance = 0.00;
- EMKSchance = customMob.EMKSchance/100;
- double randomValue = Math.random();
- pluginLogger.log(PluginLogger.LogLevel.DROP, "Event.onMobDeath EMKS drop chance: " + EMKSchance + ", randomValue: " + randomValue);
- if (randomValue <= EMKSchance) {
- drops.add(dropMobKillerSword());
- pluginLogger.log(PluginLogger.LogLevel.DROP, "Event.onMobDeath EMKS sword added");
- }
- }
}
@@ -1052,88 +1078,142 @@ public void onMobDeath(EntityDeathEvent event) {
}
- }
- private ItemStack dropMobKillerSword(){
- int minDamage = 25 + (int) (Math.random() * 40); // Losuje wartość od 10 do 100
- int maxDamage = minDamage + (int) (Math.random() * (131 - minDamage)); // Losuje wartość od minDamage do 100
-
- // Dodaj swój niestandardowy drop
- ItemStack sword = new ItemStack(Material.DIAMOND_SWORD);
- ItemMeta meta = sword.getItemMeta();
- pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS,"Event.dropMobKillerSword sword created");
- if (meta != null) {
- pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS,"Event.dropMobKillerSword");
- meta.setDisplayName("§6§lEpic Mob Slayer Sword");
- List lore = new ArrayList<>();
- lore.add("§6§lMob Damage " + minDamage + "-" + maxDamage);
- lore.add(CustomMobs.dropAverageDamage());
- meta.setLore(lore);
- meta.setUnbreakable(true);
- sword.setItemMeta(meta);
- return sword;
- }else{
-
- pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS,"Event.dropMobKillerSword meta null");
- return null;
- }
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
- //pluginLogger.log(PluginLogger.LogLevel.KILL_EVENT, "Event.onEntityDamageByEntity onEntityDamageByEntity called");
+ long startTime = System.nanoTime();
Entity damagerEntity = event.getDamager();
Entity victimEntity = event.getEntity();
+
+ if (damagerEntity.hasMetadata("handledDamage")) {
+ pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onEntityDamageByEntity event already handled!");
+ return;
+ }
+ if (damagerEntity instanceof Player){
+ damagerEntity.setMetadata("handledDamage", new FixedMetadataValue(plugin, true));
+
+ new BukkitRunnable() {
+ @Override
+ public void run() {
+ new BukkitRunnable() {
+ @Override
+ public void run() {
+ damagerEntity.removeMetadata("handledDamage", BetterElo.getInstance());
+ }
+ }.runTask(BetterElo.getInstance());
+ }
+ }.runTaskLaterAsynchronously(BetterElo.getInstance(), 1L);
+ }
if (damagerEntity instanceof Player && victimEntity instanceof Player && !event.isCancelled()) {
Player damager = (Player) event.getDamager();
Player victim = (Player) event.getEntity();
- if (damager.hasMetadata("handledDamage")) {
- pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onEntityDamageByEntity event already handled!");
- return;
- }
- ItemStack itemInHand = damager.getInventory().getItemInMainHand();
- List equippedItems = getPlayerEquippedItems(damager);
- double averageDamageBonusPercent =0;
- averageDamageBonusPercent = getTotalAvgDmgBonus(equippedItems)/100;
+
+ int averageDamageBonusPercent = betterElo.getAverageDamageAttribute(getPlayerEquippedItems((Player) event.getDamager()));
double totalDamage = event.getDamage() + event.getDamage()*averageDamageBonusPercent;
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onEntityDamageByEntity event.getDamage(): "+event.getDamage()+", averageDamageBonusPercent: "+averageDamageBonusPercent+", totalDamage: "+totalDamage);
-
event.setDamage(totalDamage);
- //pluginLogger.log(PluginLogger.LogLevel.KILL_EVENT, "Event: onEntityDamageByEntity: calling updateLastHitTime(damager) "+damager);
-
- // Aktualizacja czasu ostatniego uderzenia
updateLastHitTime(damager);
- //pluginLogger.log(PluginLogger.LogLevel.KILL_EVENT, "Event: onEntityDamageByEntity: calling updateLastHitTime(victim) "+victim);
updateLastHitTime(victim);
- damager.setMetadata("handledDamage", new FixedMetadataValue(plugin, true));
- Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
- @Override
- public void run() {
- damager.removeMetadata("handledDamage", plugin);
- }
- }, 1L);
- return;
- }
- LivingEntity entity = (LivingEntity) event.getEntity();
- if (victimEntity.hasMetadata("CustomMob")){
- pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Event.onEntityDamageByEntity custom mob detected");
- customEntityDamageEvent(event);
- //CustomMobs.CustomMob customMob = (CustomMobs.CustomMob) entity;
- //Zombie zombie = (Zombie) entity;
- pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Event.EntityDamageEvent calling customMobs.updateZombieCustomName(zombie)");
- //customMobs.updateCustomMobName(zombie);
- if (!event.getEntity().hasMetadata("CustomMob")) {
+ }else if (victimEntity.hasMetadata("CustomMob") && damagerEntity instanceof Player){
+ Player damager = (Player) event.getDamager();
+
+ String key = damager.getUniqueId() + ":" + victimEntity.getUniqueId();
+ long currentTime = System.currentTimeMillis();
+ Long lastAttackTime = lastAttackTimes.get(key);
+
+ String metadataKey = "last-attack-time-" + victimEntity.getUniqueId().toString();
+
+ // Sprawdzenie, czy metadane istnieją i czy ostatni atak był mniej niż 10 ticków temu
+
+ if (lastAttackTime != null && (currentTime - lastAttackTime) < 500) {
+ event.setCancelled(true);
+ pluginLogger.log(PluginLogger.LogLevel.DEBUG,"Player " + damager.getName() + " tried to hit too fast!");
return;
}
+
+ pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Event.onEntityDamageByEntity custom mob damage by player detected");
+
+ int[] damageRange = betterElo.getMobDamageAttribute(damager.getInventory().getItemInMainHand());
+ int avgBonus = betterElo.getAverageDamageAttribute(getPlayerEquippedItems((Player) event.getDamager()));
+ pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Event.onEntityDamageByEntity damageRange: "+damageRange.toString()+", avgBonus: "+avgBonus);
+ customEntityDamageEvent(event,damageRange[0],damageRange[1],avgBonus);
removePlayerPlacedBlocksAsync(victimEntity);
- return;
+
+ lastAttackTimes.put(key, currentTime);
+
+ Bukkit.getScheduler().runTaskLater(BetterElo.getInstance(), () -> {
+ ((LivingEntity)event.getEntity()).setNoDamageTicks(0);
+ //((Player) event.getEntity()).damage(1D);
+ }, 1L);
+
+ }else if (damagerEntity.hasMetadata("CustomMob") && victimEntity instanceof Player) {
+ int customArmorBonus =betterElo.getMobDefenseAttribute(getPlayerEquippedItems((Player) victimEntity));
+ pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Event.EntityDamageEvent getFinalDamage: "+event.getFinalDamage()+", customArmorBonus: "+customArmorBonus);
+ event.setDamage(event.getFinalDamage()*(1-(0.004*customArmorBonus)));
+
}
- if (damagerEntity.hasMetadata("CustomMob") && victimEntity instanceof Player) {
- pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Event.EntityDamageEvent getFinalDamage: "+event.getFinalDamage());
- event.setDamage(event.getFinalDamage()*(1-(0.004*customArmorBonus((Player) victimEntity))));
+ if (victimEntity instanceof LivingEntity) {
+ LivingEntity entity = (LivingEntity) event.getEntity();
+ if (entity.hasMetadata("CustomMob")) {
+ new BukkitRunnable() {
+ @Override
+ public void run() {
+ new BukkitRunnable() {
+ @Override
+ public void run() {
+ if (!entity.isDead()) {
+ customMobs.updateCustomMobName(entity);
+ }
+ }
+ }.runTask(BetterElo.getInstance());
+ }
+ }.runTaskLaterAsynchronously(BetterElo.getInstance(), 1L);
+
+ }
}
+ long endTime = System.nanoTime();
+ long duration = endTime - startTime;
+ double durationInMillis = duration / 1_000_000.0;
+ pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onEntityDamageByEntity execution time: " + durationInMillis + " ms");
+
+
+
+
+ }
+ public void customDamageHandling(Player damager, Player victim, double initialDamage) {
+ int averageDamageBonusPercent = betterElo.getAverageDamageAttribute(getPlayerEquippedItems(damager));
+ double totalDamage = initialDamage + initialDamage * averageDamageBonusPercent;
+ pluginLogger.log(PluginLogger.LogLevel.DEBUG, "customDamageHandling initialDamage: " + initialDamage + ", averageDamageBonusPercent: " + averageDamageBonusPercent + ", totalDamage: " + totalDamage);
+ victim.damage(totalDamage, damager);
+ updateLastHitTime(damager);
+ updateLastHitTime(victim);
+ }
+ public void customEntityDamageEvent(EntityDamageByEntityEvent event,int minDamage, int maxDamage, int averageDamageBonusPercent){
+ long timer;
+ double armor=1,defense=0;
+ double averageDamage = (double) (minDamage + maxDamage) / 2; // Średnia wartość obrażeń
+ int bonusDamage = (int) (averageDamage * (averageDamageBonusPercent / 100.0)); // Obliczenie bonusu
+ double totalDamage = minDamage + random.nextInt(maxDamage - minDamage + 1) + bonusDamage; // Całkowite obrażenia
+ pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Event.customEntityDamageEvent minDamage: "+minDamage+", maxDamage: "+maxDamage+", averageDamage: "+averageDamage+", averageDamageBonusPercent: "+averageDamageBonusPercent+", bonusDamage: "+bonusDamage);
+ CustomMobs.CustomMob customMob = null;
+ customMob = betterElo.getCustomMobFromEntity(event.getEntity());
+ if(customMob!=null)
+ {
+ defense = customMob.defense;
+ armor = customMob.armor;
+ pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Event.customEntityDamageEvent from customMob object - defense: "+defense+", armor: "+armor);
+
+ }
+ double defDmgReduction= (1-(0.01*defense));
+ double finalDamage =((totalDamage-armor)*defDmgReduction);
+ if(finalDamage<=0)
+ finalDamage=0;
+ event.setDamage(finalDamage);
+ pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Event.customEntityDamageEvent finalDamage: "+finalDamage+", totalDamage: " + totalDamage+", bonusDamage: "+bonusDamage+", defDmgReduction(1-(0.01*defense)): "+defDmgReduction+", armor: "+armor);
}
public void removePlayerPlacedBlocksAsync(Entity entity) {
// Asynchronicznie przygotowujesz dane
@@ -1188,6 +1268,7 @@ public int customArmorBonus (Player player){
}
return CustomArmorBonus;
}
+
public void customEntityDamageEvent(EntityDamageByEntityEvent event){
pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Event.customEntityDamageEvent triggered");
@@ -1272,22 +1353,7 @@ public void customEntityDamageEvent(EntityDamageByEntityEvent event){
//pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Damage event cancelled due to no valid item lore");
}
- @EventHandler(priority = EventPriority.MONITOR)
- public void onDamageUpdateCustomMobHealth(EntityDamageByEntityEvent event) {
- if (event.getEntity() instanceof LivingEntity) {
- LivingEntity entity = (LivingEntity) event.getEntity();
- if (entity.hasMetadata("CustomMob")) {
- // Opóźnienie wykonania aktualizacji nazwy, aby zdążyć na aktualizację zdrowia
- Bukkit.getScheduler().runTaskLater(plugin, () -> {
- // Sprawdzenie, czy mob nadal żyje przed aktualizacją nazwy
- if (!entity.isDead()) {
- pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Event.onEntityDamageByEntity custom mob detected. Updating name.");
- customMobs.updateCustomMobName(entity);
- }
- }, 1L); // Opóźnienie o 1 tick
- }
- }
- }
+
public List getPlayerEquippedItems(Player player) {
EntityEquipment equipment = player.getEquipment();
@@ -1395,7 +1461,7 @@ public void onInventoryClick(InventoryClickEvent event) {
case "Set Rewards":
event.setCancelled(true);
guiManager.periodType = currentItem.getItemMeta().getDisplayName();
- if(guiManager.periodType.equals("dropTable")){
+ if (guiManager.periodType.equals("dropTable")) {
List currentRewards = fileRewardManager.loadRewards();
inv = Bukkit.createInventory(null, 36, "Add Items");
currentRewards.forEach(inv::addItem);
@@ -1432,23 +1498,23 @@ public void onInventoryClick(InventoryClickEvent event) {
continue;
}
ItemStack item = inventory.getItem(i);
- pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick save: item: "+item);
+ pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick save: item: " + item);
if (item != null && item.getType() != Material.AIR) {
- pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick no air save: item: "+item);
+ pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick no air save: item: " + item);
itemsToSave.add(item);
}
}
- String fileName=guiManager.periodType+"_"+guiManager.dropTable;
+ 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)");
+ 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{
+ } else {
fileRewardManager.saveCustomDrops(fileName, itemsToSave);
}
@@ -1467,94 +1533,88 @@ public void onInventoryClick(InventoryClickEvent event) {
}
}
- String fileName=guiManager.periodType+"_"+guiManager.rewardType;
- pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick calling fileRewardManager.saveRewards("+fileName+",itemsToSave)");
- fileRewardManager.saveRewards(fileName,itemsToSave);
+ 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":
- pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick Average Damage bonus re-roll");
+ pluginLogger.log(PluginLogger.LogLevel.REROLL, "Event.onInventoryClick Average Damage bonus re-roll");
- if (currentItem.getType() == Material.GREEN_WOOL && event.getSlot() == 5){
+ if (currentItem.getType() == Material.GREEN_WOOL && event.getSlot() == 5) {
playerInventory.setContents(savedInventory);
event.setCancelled(true);
- pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick Average Damage bonus re-roll clicked");
+ pluginLogger.log(PluginLogger.LogLevel.REROLL, "Event.onInventoryClick Average Damage bonus re-roll clicked");
Inventory inventory = event.getInventory();
ItemStack item0 = inventory.getItem(3);
if (item0 != null && item0.hasItemMeta()) {
-
- pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick reroll, item0: "+item0+", item0.hasItemMeta(): "+item0.hasItemMeta());
- ItemMeta meta0 = item0.getItemMeta();
- boolean slot0Condition = meta0.getLore().stream().anyMatch(line -> line.contains("Average Damage"));
- ItemMeta meta = item0.getItemMeta();
- //List lore = meta.getLore();
- pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick reroll, slot0Condition: "+slot0Condition);
-
- if (slot0Condition) {
- ItemStack result = item0.clone();
- ItemMeta resultMeta = result.getItemMeta();
- List lore = new ArrayList<>(resultMeta.getLore());
- boolean mobDamage=false;
- for (int i = 0; i < lore.size(); i++) {
- if(lore.get(i).contains("Mob Damage"))
- mobDamage=true;
- if (lore.get(i).contains("Average Damage") && mobDamage) {
- pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick reroll, Average Damage lore line found i: " + i);
- if( guiManager.checkAndRemoveEnchantItem(player)) {
- pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick reroll, player paid, re-rolling..." );
- lore.set(i, customMobs.dropAverageDamage());
- player.setMetadata("avgDmgRerolled", new FixedMetadataValue(plugin, true));
- Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
- @Override
- public void run() {
- player.removeMetadata("avgDmgRerolled", plugin);
- }
- }, 1L);
- break;
+ pluginLogger.log(PluginLogger.LogLevel.REROLL, "Event.onInventoryClick reroll, betterElo.hasMobDamageAttribute(item0): "+betterElo.hasMobDamageAttribute(item0)+", betterElo.hasAverageDamageAttribute(item0): "+betterElo.hasAverageDamageAttribute(item0));
+ ItemStack result = item0.clone();
+ ItemMeta resultMeta = result.getItemMeta();
+ List lore = new ArrayList<>(resultMeta.getLore());
+ if (betterElo.hasMobDamageAttribute(item0) && betterElo.hasAverageDamageAttribute(item0)) {
+ if (guiManager.checkAndRemoveEnchantItem(player)) {
+ int avgDmg = CustomMobs.dropAverageDamage();
+ betterElo.addAverageDamageAttribute(result, avgDmg);
+ pluginLogger.log(PluginLogger.LogLevel.REROLL, "Event.onInventoryClick reroll, player paid, re-rolling...");
+ for (int i = 0; i < lore.size(); i++) {
+ pluginLogger.log(PluginLogger.LogLevel.REROLL, "Event.onInventoryClick lore i="+i);
+ if (lore.get(i).contains("Average Damage")) {
+ pluginLogger.log(PluginLogger.LogLevel.REROLL, "Event.onInventoryClick lore i="+i+" contains Average Damage, setting avgDmg: "+avgDmg);
+ lore.set(i,"§6§lAverage Damage +" + avgDmg + "%");
}
- pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick reroll, player has no money for the re-roll." );
}
}
+ player.setMetadata("avgDmgRerolled", new FixedMetadataValue(plugin, true));
+ Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
+ @Override
+ public void run() {
+ player.removeMetadata("avgDmgRerolled", plugin);
+ }
+ }, 1L);
+
+
resultMeta.setLore(lore);
result.setItemMeta(resultMeta);
inventory.setItem(3, result);
- pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick result placed back in slot 3");
+ pluginLogger.log(PluginLogger.LogLevel.REROLL, "Event.onInventoryClick result placed back in slot 3");
+ }
+ pluginLogger.log(PluginLogger.LogLevel.REROLL, "Event.onInventoryClick reroll, player has no money for the re-roll.");
- ItemStack greenWoolItem = inventory.getItem(5);
- if (greenWoolItem != null && greenWoolItem.hasItemMeta()) {
- ItemMeta greenWoolMeta = greenWoolItem.getItemMeta();
- List greenWoolLore = greenWoolMeta.hasLore() ? new ArrayList<>(greenWoolMeta.getLore()) : new ArrayList<>();
- String avgDmgLine = lore.stream().filter(line -> line.contains("Average Damage")).findFirst().orElse("Average Damage +0%");
+ ItemStack greenWoolItem = inventory.getItem(5);
- // 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 (greenWoolItem != null && greenWoolItem.hasItemMeta()) {
+ ItemMeta greenWoolMeta = greenWoolItem.getItemMeta();
+ List greenWoolLore = greenWoolMeta.hasLore() ? new ArrayList<>(greenWoolMeta.getLore()) : new ArrayList<>();
+ String avgDmgLine = lore.stream().filter(line -> line.contains("Average Damage")).findFirst().orElse("Average Damage +0%");
- 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 + ">");
+ // 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;
}
+ }
- greenWoolMeta.setLore(greenWoolLore);
- greenWoolItem.setItemMeta(greenWoolMeta);
- inventory.setItem(5, greenWoolItem);
+ 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);
- }
}
}
@@ -1601,36 +1661,40 @@ public void onEntityMove(EntityMoveEvent event) {
if (customMob != null) {
Location entityLocation = entity.getLocation();
- String spawnerLocationString = customMobsFileManager.getSpawnerLocation(customMob.spawnerName);
- Location spawnerLocation = customMobs.getLocationFromString(spawnerLocationString);
-
- int maxDistance = customMobsFileManager.getMaxDistance(customMob.spawnerName);
- if(maxDistance==0){
- maxDistance=20;
- }
- if (spawnerLocation==null){
- return;
- }
- if (entityLocation.distance(spawnerLocation) > maxDistance) {
- // Teleportacja entity z powrotem do spawnerLocation
- pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "Event.onEntityMove teleporting mob: "+customMob.mobName);
- while (spawnerLocation.getBlock().getType() != Material.AIR) {
- spawnerLocation.add(0, 1, 0); // Zwiększ y o 1
- if (spawnerLocation.getBlockY() > spawnerLocation.getWorld().getMaxHeight()) {
- // Jeśli przekraczamy maksymalną wysokość, przerwij pętlę, aby uniknąć pętli nieskończonej
- System.out.println("Reached the top of the world without finding an AIR block.");
- break;
+ if (customMob.spawnerName!=null) {
+ String spawnerLocationString = customMobsFileManager.getSpawnerLocation(customMob.spawnerName);
+ Location spawnerLocation = customMobs.getLocationFromString(spawnerLocationString);
+ int maxDistance = customMobsFileManager.getMaxDistance(customMob.spawnerName);
+ if(maxDistance==0){
+ maxDistance=20;
+ }
+ if (spawnerLocation==null){
+ return;
+ }
+ if (entityLocation.distance(spawnerLocation) > maxDistance) {
+ // Teleportacja entity z powrotem do spawnerLocation
+ pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "Event.onEntityMove teleporting mob: "+customMob.mobName);
+ while (spawnerLocation.getBlock().getType() != Material.AIR) {
+ spawnerLocation.add(0, 1, 0); // Zwiększ y o 1
+ if (spawnerLocation.getBlockY() > spawnerLocation.getWorld().getMaxHeight()) {
+ // Jeśli przekraczamy maksymalną wysokość, przerwij pętlę, aby uniknąć pętli nieskończonej
+ System.out.println("Reached the top of the world without finding an AIR block.");
+ break;
+ }
}
+ spawnerLocation.add(0, 1, 0);
+ entity.teleport(spawnerLocation);
}
- spawnerLocation.add(0, 1, 0);
- entity.teleport(spawnerLocation);
}
+
+
}
}
+
}
diff --git a/src/main/java/betterbox/mine/game/betterelo/GuiManager.java b/src/main/java/betterbox/mine/game/betterelo/GuiManager.java
index fa96426..0a38cd6 100644
--- a/src/main/java/betterbox/mine/game/betterelo/GuiManager.java
+++ b/src/main/java/betterbox/mine/game/betterelo/GuiManager.java
@@ -99,48 +99,6 @@ public void openDroptableGui(Player player, String dropTableName) {
player.openInventory(inv);
}
-
- private void handleReRollEvent(InventoryClickEvent event, Inventory inv) {
- if (event.getSlot() == 2) { // Zapobieganie interakcji z wynikowym slotem
- event.setCancelled(true);
- return;
- }
-
- // Asynchroniczne sprawdzenie receptury i aktualizacja slotu wynikowego
- Bukkit.getScheduler().runTaskLater(plugin, () -> updateResultSlot(inv), 1L);
- }
-
- private void updateResultSlot(Inventory inv) {
- ItemStack item0 = inv.getItem(0);
- ItemStack item1 = inv.getItem(1);
- if (item0 != null && item1 != null && item0.hasItemMeta() && item1.hasItemMeta()) {
- ItemMeta meta0 = item0.getItemMeta();
- ItemMeta meta1 = item1.getItemMeta();
- boolean slot0Condition = meta0.getLore().stream().anyMatch(line -> line.contains("Average Damage"));
- boolean slot1Condition = meta1.getDisplayName().equals("test");
- if (slot0Condition && slot1Condition) {
- ItemStack result = item0.clone();
- ItemMeta resultMeta = result.getItemMeta();
- List lore = new ArrayList<>(resultMeta.getLore());
- boolean mobDamage = false;
- for (int i = 0; i < lore.size(); i++) {
- if(lore.get(i).contains("Mob Damage"))
- mobDamage=true;
- if (lore.get(i).contains("Average Damage")&& mobDamage) {
- lore.set(i, customMobs.dropAverageDamage());
- break;
- }
- }
- resultMeta.setLore(lore);
- result.setItemMeta(resultMeta);
- inv.setItem(2, result);
- } else {
- inv.setItem(2, new ItemStack(Material.AIR));
- }
- }
- }
-
-
public void openCustomSmithingTable(Player player) {
Inventory smithingTable = Bukkit.createInventory(player, InventoryType.SMITHING, "Re-roll Average Damage bonus");
diff --git a/src/main/java/betterbox/mine/game/betterelo/PluginLogger.java b/src/main/java/betterbox/mine/game/betterelo/PluginLogger.java
index 1a06a32..a4bc4fe 100644
--- a/src/main/java/betterbox/mine/game/betterelo/PluginLogger.java
+++ b/src/main/java/betterbox/mine/game/betterelo/PluginLogger.java
@@ -20,7 +20,7 @@ public class PluginLogger {
// Enumeracja dla poziomów logowania
public enum LogLevel {
- INFO, WARNING, ERROR,CUSTOM_MOBS, DEBUG, DEBUG_LVL2, DEBUG_LVL3,DEBUG_LVL4,CHEATERS, RANKING_REWARDS ,FLAMETHROWER,DROP,SPAWNERS, ZEPHYR, KILL_EVENT, COMMAND, PLACEHOLDER, BLOCK_BREAK, BLOCK_PLACE, PLAYER_INTERACT, ELYTRA_CHECK, ANTYWEB
+ INFO, WARNING, ERROR,CUSTOM_MOBS, DEBUG, DEBUG_LVL2, DEBUG_LVL3,DEBUG_LVL4,CHEATERS, RANKING_REWARDS ,FLAMETHROWER,DROP,SPAWNERS, ZEPHYR, KILL_EVENT, COMMAND, PLACEHOLDER, BLOCK_BREAK, BLOCK_PLACE, PLAYER_INTERACT, ELYTRA_CHECK, ANTYWEB, REROLL
}
public PluginLogger(String folderPath, Set enabledLogLevels, JavaPlugin plugin) {
@@ -57,7 +57,7 @@ public void log(String message) {
public void log(LogLevel level, String message) {
if (enabledLogLevels.contains(level)) {
// Dodanie timestampu i poziomu logowania do wiadomości
- String timestamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
+ String timestamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date());
String logMessage = timestamp + " [" + level + "] - " + message;
try (BufferedWriter writer = new BufferedWriter(new FileWriter(logFile, true))) {
diff --git a/src/main/resources/customMobs/Marksman.yml b/src/main/resources/customMobs/Marksman.yml
index cc44c75..08c8524 100644
--- a/src/main/resources/customMobs/Marksman.yml
+++ b/src/main/resources/customMobs/Marksman.yml
@@ -6,6 +6,9 @@ speed: 0.4 # movement speed
attackDamage: 10
dropTable: ExampleDropTable # tbh I don't remember which one is used in the plugin - unnecessary fields will be removed in the future releases
defense: 30 # x% damage reduction
+regenSeconds: 10
+regenPercent: 20
+knockbackResistance: 5.0
customMetadata:
CustomMob: true # leave this always as true!!
MobName: EXAMPLE BOSS - Panda # displayname COLORS/FORMATTING NOT SUPPORTED YET
diff --git a/src/main/resources/customMobs/Panda.yml b/src/main/resources/customMobs/Panda.yml
index e3c4b1e..95bbb68 100644
--- a/src/main/resources/customMobs/Panda.yml
+++ b/src/main/resources/customMobs/Panda.yml
@@ -6,6 +6,10 @@ speed: 0.4 # movement speed
attackDamage: 10
dropTable: ExampleDropTable # tbh I don't remember which one is used in the plugin - unnecessary fields will be removed in the future releases
defense: 95 # x% damage reduction
+passengerMobName: Marksman
+knockbackResistance: 5.0
+regenSeconds: 30
+regenPercent: 30
customMetadata:
CustomMob: true # leave this always as true!!
MobName: EXAMPLE BOSS - Panda # displayname COLORS/FORMATTING NOT SUPPORTED YET