Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit cd9d25bda14c114f4da5d71ba39f69201b5839b6 1 parent 0f0d293
Sébastien Vaucher authored
BIN  NoRegen.jar
Binary file not shown
2  bin/plugin.yml
... ... @@ -1,4 +1,4 @@
1 1 name: NoRegen
2 2 main: com.garbagemule.NoRegen.NoRegen
3   -version: 1.0
  3 +version: 1.1
4 4 softdepend: [MultiVerse]
31 src/com/garbagemule/NoRegen/NoRegen.java
@@ -10,17 +10,18 @@
10 10 import java.util.List;
11 11
12 12 import org.bukkit.World;
13   -import org.bukkit.craftbukkit.CraftWorld;
  13 +import org.bukkit.event.Event;
  14 +import org.bukkit.event.Event.Priority;
14 15 import org.bukkit.plugin.java.JavaPlugin;
15 16
16 17 public class NoRegen extends JavaPlugin
17 18 {
18   - public NoRegen() {}
  19 + public List<World> worldList = new LinkedList<World>();
  20 + private NoRegenEntityListener el = new NoRegenEntityListener(this);
19 21
20 22 public void onEnable()
21 23 {
22 24 File worldFile;
23   - List<World> worldList = new LinkedList<World>();
24 25
25 26 // FILE CHECK/CREATION
26 27 try
@@ -83,29 +84,7 @@ public void onEnable()
83 84 return;
84 85 }
85 86
86   - // SETTINGS
87   - CraftWorld cw;
88   - net.minecraft.server.World nmsWorld;
89   - for (World w : worldList)
90   - {
91   - cw = (CraftWorld) w;
92   -
93   - // If the world isn't null, get the n.m.s.World
94   - if (w != null)
95   - {
96   - nmsWorld = cw.getHandle();
97   - }
98   - else
99   - {
100   - System.out.println(w + " is not a real world.");
101   - continue;
102   - }
103   -
104   - /* allowMonsters = false means no monsters will spawn, and
105   - * spawnMonsters > 0 means health will not be regenerated. */
106   - nmsWorld.allowMonsters = false;
107   - nmsWorld.spawnMonsters = 1;
108   - }
  87 + getServer().getPluginManager().registerEvent(Event.Type.ENTITY_REGAIN_HEALTH, el, Priority.Highest, this);
109 88
110 89 System.out.println("[NoRegen] Enabled.");
111 90 }
24 src/com/garbagemule/NoRegen/NoRegenEntityListener.java
... ... @@ -0,0 +1,24 @@
  1 +package com.garbagemule.NoRegen;
  2 +
  3 +import org.bukkit.event.entity.EntityListener;
  4 +import org.bukkit.event.entity.EntityRegainHealthEvent;
  5 +import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
  6 +
  7 +public class NoRegenEntityListener extends EntityListener {
  8 +
  9 + private NoRegen plugin;
  10 +
  11 + public NoRegenEntityListener(NoRegen plugin) {
  12 + super();
  13 + this.plugin = plugin;
  14 + }
  15 +
  16 + @Override
  17 + public void onEntityRegainHealth(EntityRegainHealthEvent event) {
  18 + if(event.getRegainReason() == RegainReason.REGEN) {
  19 + if(this.plugin.worldList.contains(event.getEntity().getWorld()))
  20 + event.setCancelled(true);
  21 + }
  22 + }
  23 +
  24 +}

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.
Something went wrong with that request. Please try again.