Skip to content
Browse files

Added kill count. Added burn control!

  • Loading branch information...
1 parent 50e582e commit 06f5cae2ef0ddaca725b33c3c6e3aac7bc987748 @brad811 committed May 20, 2011
View
76 src/com/bradsproject/com/bradsproject/BradleyJewell/bMobs/bMobs.java
@@ -8,6 +8,8 @@
import java.util.List;
import java.util.Map;
+import org.bukkit.Location;
+import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.command.Command;
@@ -46,14 +48,17 @@ public void onEnable()
PluginManager pm = getServer().getPluginManager();
pm.registerEvent(Event.Type.ENTITY_TARGET, entityListener, Priority.Normal, this);
pm.registerEvent(Event.Type.CREATURE_SPAWN, entityListener, Priority.Normal, this);
+ pm.registerEvent(Event.Type.ENTITY_COMBUST, entityListener, Priority.Normal, this);
+
pm.registerEvent(Event.Type.WORLD_LOAD, worldListener, Priority.Normal, this);
+
setupPermissions();
parseConfig();
- long delay = 200L;
- long period = 200L;
+ long delay = 10L;
+ long period = 10L;
getServer().getScheduler().scheduleSyncRepeatingTask(this, new bMobsKillerTask(this), delay, period);
// EXAMPLE: Custom code, here we just output some info so we can check
@@ -199,30 +204,71 @@ public boolean isEntityMatch(LivingEntity e, String type)
return false;
}
- public void kill(World world, String type)
+ public int kill(World world, String type)
{
List<LivingEntity> mobs = world.getLivingEntities();
+ int numKilled = 0;
for(LivingEntity m : mobs)
{
if(type.equals("animals") || type.equals("all"))
{
if(isAnimal(m))
{
m.remove();
+ numKilled++;
}
else if(isMonster(m))
{
m.remove();
+ numKilled++;
}
}
else
{
if(isEntityMatch(m, type))
{
m.remove();
+ numKilled++;
}
}
}
+ return numKilled;
+ }
+
+ public boolean shouldBurn(Entity entity)
+ {
+ for(Mob mob : worlds.get(entity.getWorld().getName()).mobs)
+ {
+ if(mob.type.equals(entity.toString().toLowerCase().replace("craft", "")))
+ {
+ if(mob.burn && isInSunlight(entity))
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ public boolean isInSunlight(Entity entity)
+ {
+ for(int y = 127; y > entity.getLocation().getY() + 2; y--)
+ {
+ Location loc = new Location(entity.getWorld(), entity.getLocation().getX(), y, entity.getLocation().getZ());
+ if(entity.getWorld().getBlockAt(loc).getType() != Material.AIR
+ && entity.getWorld().getBlockAt(loc).getType() != Material.GLASS)
+ {
+ return false;
+ }
+ }
+ if(entity.getLocation().getBlock().getLightLevel() < 15)
+ return false;
+
+ return true;
}
public void reload()
@@ -251,39 +297,39 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel,
try {
if(args[0].equalsIgnoreCase("monsters") || args[0].equalsIgnoreCase("mobs"))
{
- kill(player.getWorld(), "monsters");
- player.sendMessage("All monsters have been killed!");
+ int numKilled = kill(player.getWorld(), "monsters");
+ player.sendMessage("All "+ numKilled +" monsters have been killed!");
return true;
}
else if(args[0].equalsIgnoreCase("animals"))
{
- kill(player.getWorld(), "animals");
- player.sendMessage("All animals have been killed!");
+ int numKilled = kill(player.getWorld(), "animals");
+ player.sendMessage("All "+ numKilled +" animals have been killed!");
return true;
}
else if(args[0].equalsIgnoreCase("all"))
{
- kill(player.getWorld(), "all");
- player.sendMessage("All creatures have been killed!");
+ int numKilled = kill(player.getWorld(), "all");
+ player.sendMessage("All "+ numKilled +" creatures have been killed!");
return true;
}
else
{
- kill(player.getWorld(), args[0].toLowerCase());
- player.sendMessage("All "+ args[0].toLowerCase() +"(s) have been killed!");
+ int numKilled = kill(player.getWorld(), args[0].toLowerCase());
+ player.sendMessage("All "+ numKilled +" "+ args[0].toLowerCase() +"(s) have been killed!");
return true;
}
}
catch(CommandException e)
{
- kill(player.getWorld(), "monsters");
- player.sendMessage("All monsters have been killed!");
+ int numKilled = kill(player.getWorld(), "monsters");
+ player.sendMessage("All "+ numKilled +" monsters have been killed!");
return true;
}
catch(NullPointerException e)
{
- kill(player.getWorld(), "monsters");
- player.sendMessage("All monsters have been killed!");
+ int numKilled = kill(player.getWorld(), "monsters");
+ player.sendMessage("All "+ numKilled +" monsters have been killed!");
return true;
}
}
View
15 src/com/bradsproject/com/bradsproject/BradleyJewell/bMobs/bMobsEntityListener.java
@@ -3,8 +3,11 @@
import java.util.Random;
import org.bukkit.World;
+import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
+import org.bukkit.entity.Player;
import org.bukkit.event.entity.CreatureSpawnEvent;
+import org.bukkit.event.entity.EntityCombustEvent;
import org.bukkit.event.entity.EntityListener;
import org.bukkit.event.entity.EntityTargetEvent;
@@ -48,6 +51,18 @@ public void onEntityTarget(EntityTargetEvent event)
}
@Override
+ public void onEntityCombust(EntityCombustEvent event)
+ {
+ Entity entity = event.getEntity();
+ if(entity instanceof Player)
+ return;
+ if(!plugin.shouldBurn(entity))
+ {
+ event.setCancelled(true);
+ }
+ }
+
+ @Override
public void onCreatureSpawn(CreatureSpawnEvent event)
{
World world = event.getLocation().getWorld();
View
9 src/com/bradsproject/com/bradsproject/BradleyJewell/bMobs/bMobsKillerTask.java
@@ -5,6 +5,7 @@
import java.util.Map.Entry;
import org.bukkit.entity.LivingEntity;
+import org.bukkit.entity.Player;
public class bMobsKillerTask implements Runnable
{
@@ -24,12 +25,18 @@ public void run()
List<LivingEntity> entities = world.getValue().world.getLivingEntities();
for(LivingEntity entity : entities)
{
+ if(entity instanceof Player)
+ continue;
+
if(!plugin.handleEntity(entity, world.getValue().world))
{
// check to burn the mob
+ if(plugin.shouldBurn(entity))
+ {
+ entity.setFireTicks(100);
+ }
}
}
}
}
-
}

0 comments on commit 06f5cae

Please sign in to comment.
Something went wrong with that request. Please try again.