Permalink
Browse files

Make the plugin compatible with CraftBukkit #935 (MC 1.7.2)

The ENTITY_REGAIN_HEALTH Event is catched and cancelled if necessary
  • Loading branch information...
1 parent 0f0d293 commit cd9d25bda14c114f4da5d71ba39f69201b5839b6 @sebyx31 committed Jul 2, 2011
View
BIN NoRegen.jar
Binary file not shown.
View
2 bin/plugin.yml
@@ -1,4 +1,4 @@
name: NoRegen
main: com.garbagemule.NoRegen.NoRegen
-version: 1.0
+version: 1.1
softdepend: [MultiVerse]
View
31 src/com/garbagemule/NoRegen/NoRegen.java
@@ -10,17 +10,18 @@
import java.util.List;
import org.bukkit.World;
-import org.bukkit.craftbukkit.CraftWorld;
+import org.bukkit.event.Event;
+import org.bukkit.event.Event.Priority;
import org.bukkit.plugin.java.JavaPlugin;
public class NoRegen extends JavaPlugin
{
- public NoRegen() {}
+ public List<World> worldList = new LinkedList<World>();
+ private NoRegenEntityListener el = new NoRegenEntityListener(this);
public void onEnable()
{
File worldFile;
- List<World> worldList = new LinkedList<World>();
// FILE CHECK/CREATION
try
@@ -83,29 +84,7 @@ public void onEnable()
return;
}
- // SETTINGS
- CraftWorld cw;
- net.minecraft.server.World nmsWorld;
- for (World w : worldList)
- {
- cw = (CraftWorld) w;
-
- // If the world isn't null, get the n.m.s.World
- if (w != null)
- {
- nmsWorld = cw.getHandle();
- }
- else
- {
- System.out.println(w + " is not a real world.");
- continue;
- }
-
- /* allowMonsters = false means no monsters will spawn, and
- * spawnMonsters > 0 means health will not be regenerated. */
- nmsWorld.allowMonsters = false;
- nmsWorld.spawnMonsters = 1;
- }
+ getServer().getPluginManager().registerEvent(Event.Type.ENTITY_REGAIN_HEALTH, el, Priority.Highest, this);
System.out.println("[NoRegen] Enabled.");
}
View
24 src/com/garbagemule/NoRegen/NoRegenEntityListener.java
@@ -0,0 +1,24 @@
+package com.garbagemule.NoRegen;
+
+import org.bukkit.event.entity.EntityListener;
+import org.bukkit.event.entity.EntityRegainHealthEvent;
+import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
+
+public class NoRegenEntityListener extends EntityListener {
+
+ private NoRegen plugin;
+
+ public NoRegenEntityListener(NoRegen plugin) {
+ super();
+ this.plugin = plugin;
+ }
+
+ @Override
+ public void onEntityRegainHealth(EntityRegainHealthEvent event) {
+ if(event.getRegainReason() == RegainReason.REGEN) {
+ if(this.plugin.worldList.contains(event.getEntity().getWorld()))
+ event.setCancelled(true);
+ }
+ }
+
+}

1 comment on commit cd9d25b

@garbagemule

Exactly what I was planning on doing after getting MobArena v0.92 up and running, thank you!

Please sign in to comment.