Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/main/java/com/MrEngMan/ExplodeMe/ExplodeMe.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class ExplodeMe extends JavaPlugin implements Listener {

private boolean debug;
private float blockExplodeCheckRadius;
private boolean protectEnderDragon;

// When plugin is first enabled
@SuppressWarnings("static-access")
Expand All @@ -44,6 +45,7 @@ public void reloadTheConfig() {
reloadConfig();
debug = getConfig().getBoolean("debug", false);
blockExplodeCheckRadius = getConfig().getInt("block-explode-check-radius", 10);
protectEnderDragon = getConfig().getBoolean("protect-ender-dragon", true);

}

Expand Down Expand Up @@ -91,5 +93,9 @@ public boolean isDebugEnabled() {
return debug;
}

public boolean isEnderDragonProtected() {
return protectEnderDragon;
}


}
30 changes: 27 additions & 3 deletions src/main/java/com/MrEngMan/ExplodeMe/listeners/Listeners.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.bukkit.event.entity.EntityDamageByBlockEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.metadata.MetadataValue;
Expand Down Expand Up @@ -58,8 +57,8 @@ public void onPlayerInteract(PlayerInteractEvent event) {
blockExplosionCauseList.add(new LocationUUIDPair(block.getLocation(), player.getUniqueId()));
}

// If it's a respawn anchor in the overworld
else if (blockIsRespawnAnchor && block.getLocation().getWorld().getEnvironment() == World.Environment.NORMAL) {
// If it's a respawn anchor in the overworld or end (they explode outside the nether)
else if (blockIsRespawnAnchor && (block.getLocation().getWorld().getEnvironment() == World.Environment.NORMAL || block.getLocation().getWorld().getEnvironment() == World.Environment.THE_END)) {
RespawnAnchor respawnAnchor = ((RespawnAnchor)block.getBlockData());
if(respawnAnchor.getCharges() > 0) {

Expand Down Expand Up @@ -149,6 +148,31 @@ public void onEntityDamageByBlock(EntityDamageByBlockEvent event) {

}

// Ender Dragon damaged by block explosion
else if (damagedEntity.getType() == EntityType.ENDER_DRAGON && event.getCause() == EntityDamageEvent.DamageCause.BLOCK_EXPLOSION) {

// Check if Ender Dragon protection is enabled
if (ExplodeMe.getPlugin().isEnderDragonProtected()) {
Utils.debugPrint(Utils.SendChatMessage("&3Check cause list for Ender Dragon: " + blockExplosionCauseList.toString()));

// Check if there's a nearby bed/respawn anchor explosion
boolean foundBedOrAnchorExplosion = false;
for(LocationUUIDPair locationUUIDPair : blockExplosionCauseList) {
if(locationUUIDPair.location.getWorld() == damagedEntity.getWorld() && locationUUIDPair.location.distance(damagedEntity.getLocation()) <= ExplodeMe.getPlugin().getBlockExplodeCheckRadius()) {
foundBedOrAnchorExplosion = true;
break;
}
}

// Cancel damage if it's from a bed or respawn anchor explosion
if (foundBedOrAnchorExplosion) {
Utils.debugPrint(Utils.SendChatMessage("&eProtected Ender Dragon from bed/respawn anchor explosion"));
event.setCancelled(true);
} else {
Utils.debugPrint(Utils.SendChatMessage("&eEnder Dragon damaged by non-bed/anchor explosion"));
}
}
}
}

@EventHandler(priority = EventPriority.LOW)
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ no-permission-message: '&8[&7ExplodeMe&8] &cSorry, you don''t have permission to
# How far can players be to a bed/respawn anchor to consider them in the area of influence
block-explode-check-radius: 10

# Prevent bed and respawn anchor explosions from damaging the Ender Dragon
protect-ender-dragon: false

# Print debug messages to console (leave as false)
debug: false