NMS-free fake explosion.

This commit is contained in:
Olof Larsson 2012-12-20 15:17:28 +01:00
parent 0a15dae2a4
commit 5d193587ed
2 changed files with 36 additions and 15 deletions

View File

@ -8,6 +8,8 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByBlockEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerQuitEvent;
@ -19,6 +21,7 @@ import com.massivecraft.mcore5.event.MCoreAfterPlayerTeleportEvent;
import com.massivecraft.mcore5.event.MCorePlayerLeaveEvent;
import com.massivecraft.mcore5.store.Coll;
import com.massivecraft.mcore5.store.PlayerColl;
import com.massivecraft.mcore5.util.SmokeUtil;
public class InternalListener implements Listener
{
@ -48,6 +51,24 @@ public class InternalListener implements Listener
}
}*/
// -------------------------------------------- //
// EXPLOSION FX
// -------------------------------------------- //
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void explosionFx(EntityDamageByBlockEvent event)
{
// If an entity is taking damage from a block explosion ...
DamageCause cause = event.getCause();
if (cause != DamageCause.BLOCK_EXPLOSION) return;
// ... and that explosion is a fake ...
if (SmokeUtil.fakeExplosion == false) return;
// ... then cancel the event and the damage.
event.setCancelled(true);
}
// -------------------------------------------- //
// AFTER EVENTS
// -------------------------------------------- //

View File

@ -1,19 +1,10 @@
package com.massivecraft.mcore5.util;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Random;
import net.minecraft.server.v1_4_5.ChunkPosition;
import net.minecraft.server.v1_4_5.MinecraftServer;
import net.minecraft.server.v1_4_5.Packet60Explosion;
import org.bukkit.Bukkit;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_4_5.CraftServer;
import org.bukkit.craftbukkit.v1_4_5.CraftWorld;
// http://mc.kev009.com/Protocol
// -----------------------------
@ -92,18 +83,27 @@ public class SmokeUtil
}
// Fake Explosion ========
public static void fakeExplosion(Location location)
{
fakeExplosion(location, (Bukkit.getViewDistance()+1)*16*2);
fakeExplosion(location, 4F);
}
public static Boolean fakeExplosion = false;
public static void fakeExplosion(Location location, float power)
{
synchronized (fakeExplosion)
{
fakeExplosion = true;
location.getWorld().createExplosion(location.getX(), location.getY(), location.getZ(), power, false, false);
fakeExplosion = false;
}
}
@Deprecated
public static void fakeExplosion(Location location, int viewDistance)
{
List<ChunkPosition> chunkPositions = new ArrayList<ChunkPosition>();
Packet60Explosion packet = new Packet60Explosion(location.getX(),location.getY(), location.getZ(), 0.1f, chunkPositions, null);
CraftServer craftServer = (CraftServer) Bukkit.getServer();
MinecraftServer minecraftServer = craftServer.getServer();
minecraftServer.getServerConfigurationManager().sendPacketNearby(location.getX(), location.getY(), location.getZ(), viewDistance, ((CraftWorld)location.getWorld()).getHandle().dimension, packet);
fakeExplosion(location);
}
// -------------------------------------------- //