Skip to content

Commit

Permalink
Merge pull request #59 from Grzybol/release-4.3.0
Browse files Browse the repository at this point in the history
Release 4.3.0
  • Loading branch information
Grzybol authored Apr 17, 2024
2 parents 4120995 + f77909d commit b8f9b0e
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 51 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.2.61-SNAPSHOT</version>
<version>4.3.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>BetterElo</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
case 1:
switch (args[0].toLowerCase()) {
case "reroll":
handleRerollCommand(sender);
if(sender.isOp()) {
handleRerollCommand(sender);
}
break;
case "killallmobs":
if(!sender.isOp()){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ public void updateCustomMobName(LivingEntity mob) {
public static String 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.
int bonus = (int) Math.round(x * 100); // Skalowanie wyniku

// Ograniczamy wartość bonusu do maksymalnie 60%
Expand Down
65 changes: 26 additions & 39 deletions src/main/java/betterbox/mine/game/betterelo/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -1049,14 +1049,22 @@ private ItemStack dropMobKillerSword(){
return null;
}
}

@EventHandler
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
//pluginLogger.log(PluginLogger.LogLevel.KILL_EVENT, "Event.onEntityDamageByEntity onEntityDamageByEntity called");
if (event.getDamager() instanceof Player && event.getEntity() instanceof Player) {

Player damager = (Player) event.getDamager();
Player victim = (Player) event.getEntity();

ItemStack itemInHand = damager.getInventory().getItemInMainHand();
List<ItemStack> equippedItems = getPlayerEquippedItems(damager);
double averageDamageBonusPercent =0;
averageDamageBonusPercent = getTotalAvgDmgBonus(equippedItems);
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
Expand All @@ -1075,46 +1083,8 @@ public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
}


}
@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
}
}
}

/*
@EventHandler
public void EntityDamageEvent(EntityDamageEvent event) {
pluginLogger.log(PluginLogger.LogLevel.KILL_EVENT, "Event.EntityDamageEvent called");
Entity entity = event.getEntity();
if (entity instanceof LivingEntity) {
LivingEntity livingEntity = (LivingEntity) event.getEntity();
if (entity.hasMetadata("CustomZombie")) {
pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Event.EntityDamageEvent custom mob detected");
try {
//CustomMobs.CustomMob customMob = (CustomMobs.CustomMob) livingEntity;
//Zombie zombie = (Zombie) entity;
pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Event.EntityDamageEvent calling customMobs.updateZombieCustomName(zombie)");
customMobs.updateCustomMobName(livingEntity);
}catch (Exception e){
pluginLogger.log(PluginLogger.LogLevel.ERROR, "Event.EntityDamageEvent exception "+e.getMessage());
}
}
}
}

*/
public void customEntityDamageEvent(EntityDamageByEntityEvent event){
pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Event.customEntityDamageEvent triggered");

Expand Down Expand Up @@ -1168,6 +1138,23 @@ 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<ItemStack> getPlayerEquippedItems(Player player) {
EntityEquipment equipment = player.getEquipment();
List<ItemStack> equippedItems = new ArrayList<>();
Expand Down
24 changes: 14 additions & 10 deletions src/main/java/betterbox/mine/game/betterelo/GuiManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,15 @@ public void openDroptableGui(Player player, String dropTableName) {
}
@EventHandler(priority = EventPriority.LOW)
public void onInventoryClick(InventoryClickEvent event) {
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..");
event.setCancelled(true);

}
Player player = (Player) event.getWhoClicked();
ItemStack currentItem = event.getCurrentItem();
Inventory playerInventory = player.getInventory();
ItemStack[] savedInventory = playerInventory.getContents();

String title = event.getView().getTitle();
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClick called. title:"+title);
Expand All @@ -108,8 +116,8 @@ public void onInventoryClick(InventoryClickEvent event) {
}


Player player = (Player) event.getWhoClicked();
ItemStack currentItem = event.getCurrentItem();


if (currentItem == null || currentItem.getType() == Material.AIR) {
return;
}
Expand Down Expand Up @@ -178,12 +186,9 @@ public void onInventoryClick(InventoryClickEvent event) {
break;
case "AvgDmg bonus change":
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClick Average Damage bonus re-roll");
if(event.getCurrentItem().getType() == Material.GRAY_STAINED_GLASS_PANE){
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClick re-roll, blank slot manipulated, cancelling..");
event.setCancelled(true);
return;
}

if (currentItem.getType() == Material.GREEN_WOOL && event.getSlot() == 5){
playerInventory.setContents(savedInventory);
event.setCancelled(true);
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClick Average Damage bonus re-roll clicked");
Inventory inventory = event.getInventory();
Expand Down Expand Up @@ -220,9 +225,8 @@ public void onInventoryClick(InventoryClickEvent event) {
}
}
break;
}


}
}
@EventHandler
public void onInventoryClose(InventoryCloseEvent event) {
Expand Down Expand Up @@ -341,7 +345,7 @@ public boolean checkAndRemoveBetterCoins(Player player) {
private ItemStack getBetterCoinStack() {
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.getBetterCoinStack called");
Material material = Material.HONEYCOMB;
int amount = 1;
int amount = 64;

ItemStack stack = new ItemStack(material, amount);
ItemMeta meta = stack.getItemMeta();
Expand Down

0 comments on commit b8f9b0e

Please sign in to comment.