Skip to content

Commit

Permalink
Merge pull request #70 from Grzybol/release-4.5.0
Browse files Browse the repository at this point in the history
Improvements
  • Loading branch information
Grzybol authored Jul 8, 2024
2 parents ca1789e + 990e3bc commit 043e1c6
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 42 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>betterbox.mine.game</groupId>
<artifactId>BetterElo</artifactId>
<version>4.4.16-SNAPSHOT</version>
<version>4.4.29-SNAPSHOT</version>
<packaging>jar</packaging>

<name>BetterElo</name>
Expand Down
90 changes: 49 additions & 41 deletions src/main/java/betterbox/mine/game/betterelo/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class Event implements Listener {
private CustomMobs customMobs;
private GuiManager guiManager;
private FileRewardManager fileRewardManager;
private int deathEventCounter;
private final Random random = new Random();
//public final long cooldownMillis = 1500; // 1.5s

Expand Down Expand Up @@ -190,17 +191,26 @@ private Player getLastAttacker(Player victim) {
}
}

@EventHandler
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerDeath(PlayerDeathEvent event) {
Player victim = event.getEntity();
if (victim.hasMetadata("handledDeath")) {
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onEntityDamageByEntity event already handled!");
if(deathEventCounter==1){
pluginLogger.log(PluginLogger.LogLevel.KILL_EVENT, "Event.onPlayerDeath event already handled!");
return;
}
deathEventCounter=1;

Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
try {


Player victim = event.getEntity();
Player killer = victim.getKiller();
if (killer.hasMetadata("handledDeath")) {
pluginLogger.log(PluginLogger.LogLevel.KILL_EVENT, "Event.onPlayerDeath event already handled! killer: "+victim.getName());
return;
}
deathEventCounter=0;

if (!cheaters.getCheatersList().contains(victim.getName()) && !cheaters.getCheatersList().contains(killer.getName())) {
pluginLogger.log(PluginLogger.LogLevel.KILL_EVENT, "Event: onPlayerDeath: victim: " + victim + " killer: " + killer);
pluginLogger.log(PluginLogger.LogLevel.KILL_EVENT, "Event: onPlayerDeath calling deathDueToCombat(victim)");
Expand All @@ -212,6 +222,8 @@ public void onPlayerDeath(PlayerDeathEvent event) {
Player lastAttacker = getLastAttacker(victim);
pluginLogger.log(PluginLogger.LogLevel.KILL_EVENT, "Event: onPlayerDeath: lastAttacker " + lastAttacker);



if (lastAttacker == null) {
/*
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event: onPlayerDeath: calling handleKillEvent" + lastAttacker);
Expand Down Expand Up @@ -281,13 +293,9 @@ 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);
killer.setMetadata("handledDeath", new FixedMetadataValue(plugin, true));
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> killer.removeMetadata("handledDeath", plugin), 2L);
pluginLogger.log(PluginLogger.LogLevel.KILL_EVENT, "Event.handleKillEvent added handledDeath metadata to "+killer.getName());


} else {
Expand Down Expand Up @@ -1114,6 +1122,10 @@ public void run() {
//Zombie zombie = (Zombie) entity;
pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Event.EntityDamageEvent calling customMobs.updateZombieCustomName(zombie)");
//customMobs.updateCustomMobName(zombie);
if (!event.getEntity().hasMetadata("CustomMob")) {
return;
}
removePlayerPlacedBlocksAsync(victimEntity);
return;
}
if (damagerEntity.hasMetadata("CustomMob") && victimEntity instanceof Player) {
Expand All @@ -1123,6 +1135,32 @@ public void run() {
}

}
public void removePlayerPlacedBlocksAsync(Entity entity) {
// Asynchronicznie przygotowujesz dane
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
List<Block> blocksToRemove = new ArrayList<>();
Block baseBlock = entity.getLocation().getBlock();

for (int x = -1; x <= 1; x++) {
for (int y = -1; y <= 2; y++) {
for (int z = -1; z <= 1; z++) {
Block relBlock = baseBlock.getRelative(x, y, z);
if (relBlock.hasMetadata("placed_by_player")) {
blocksToRemove.add(relBlock);
}
}
}
}

// Synchroniczne usuwanie bloków w głównym wątku
Bukkit.getScheduler().runTask(plugin, () -> {
for (Block block : blocksToRemove) {
block.setType(Material.AIR);
pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Removing player-placed block at " + block.getLocation());
}
});
});
}
public int customArmorBonus (Player player){
int CustomArmorBonus=0;
List<ItemStack> equippedItems = getPlayerEquippedItems(player);
Expand Down Expand Up @@ -1538,36 +1576,6 @@ public void onInventoryClose(InventoryCloseEvent event) {
}


@EventHandler
public void onEntityMove(EntityMoveEvent event) {

//pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Event.onEntityInteract called");
if (!event.getEntity().hasMetadata("CustomMob")){
return;
}
//pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Event.onEntityInteract: CustomMob CHECK PASSED");

// Pobieranie bloku, z którym wchodzi w interakcję mob
Block block = event.getTo().getBlock();
if(!block.hasMetadata("placed_by_player")){
return;
}
//pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Event.onEntityInteract: COMWEB placed_by_player CHECK PASSED");
// Sprawdzanie, czy blok to pajęczyna
if (block.getType() == Material.COBWEB) {
// Usunięcie pajęczyny, gdy mob wejdzie w nią
block.setType(Material.AIR);

// 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");
}
}

}

0 comments on commit 043e1c6

Please sign in to comment.