mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-28 13:36:33 +01:00
Added Trigger on Mob Death
This commit is contained in:
parent
13bff0801e
commit
d0691d737a
@ -252,4 +252,8 @@ public class DMobType {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.dre.dungeonsxl.DMobType;
|
||||
import com.dre.dungeonsxl.trigger.MobTrigger;
|
||||
|
||||
public class DMob {
|
||||
|
||||
@ -33,6 +34,7 @@ public class DMob {
|
||||
if (event.getEntity() instanceof LivingEntity) {
|
||||
LivingEntity victim = (LivingEntity) event.getEntity();
|
||||
GameWorld gworld = GameWorld.get(victim.getWorld());
|
||||
String name = null;
|
||||
|
||||
if (gworld != null) {
|
||||
for (DMob dmob : gworld.dmobs) {
|
||||
@ -46,6 +48,14 @@ public class DMob {
|
||||
event.getDrops().add(item);
|
||||
}
|
||||
}
|
||||
name = dmob.type.getName();
|
||||
} else {
|
||||
name = victim.getType().getName();
|
||||
}
|
||||
|
||||
MobTrigger trigger = MobTrigger.get(name, gworld);
|
||||
if (trigger != null) {
|
||||
trigger.onTrigger();
|
||||
}
|
||||
|
||||
gworld.dmobs.remove(dmob);
|
||||
|
63
src/com/dre/dungeonsxl/trigger/MobTrigger.java
Normal file
63
src/com/dre/dungeonsxl/trigger/MobTrigger.java
Normal file
@ -0,0 +1,63 @@
|
||||
package com.dre.dungeonsxl.trigger;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.ArrayList;
|
||||
import com.dre.dungeonsxl.game.GameWorld;
|
||||
|
||||
|
||||
public class MobTrigger extends Trigger {
|
||||
|
||||
private static Map<GameWorld, ArrayList<MobTrigger>> triggers = new HashMap<GameWorld, ArrayList<MobTrigger>>();
|
||||
|
||||
private String name;
|
||||
|
||||
public MobTrigger(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void onTrigger() {
|
||||
triggered = true;
|
||||
updateDSigns();
|
||||
}
|
||||
|
||||
public void register(GameWorld gworld) {
|
||||
if (!hasTriggers(gworld)) {
|
||||
ArrayList<MobTrigger> list = new ArrayList<MobTrigger>();
|
||||
list.add(this);
|
||||
triggers.put(gworld, list);
|
||||
} else {
|
||||
triggers.get(gworld).add(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void unregister(GameWorld gworld) {
|
||||
if (hasTriggers(gworld)) {
|
||||
triggers.get(gworld).remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
public static MobTrigger getOrCreate(String name, GameWorld gworld) {
|
||||
MobTrigger trigger = get(name, gworld);
|
||||
if (trigger != null) {
|
||||
return trigger;
|
||||
}
|
||||
return new MobTrigger(name);
|
||||
}
|
||||
|
||||
public static MobTrigger get(String name, GameWorld gworld) {
|
||||
if (hasTriggers(gworld)) {
|
||||
for (MobTrigger trigger : triggers.get(gworld)) {
|
||||
if (trigger.name.equalsIgnoreCase(name)) {
|
||||
return trigger;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean hasTriggers(GameWorld gworld) {
|
||||
return !triggers.isEmpty() && triggers.containsKey(gworld);
|
||||
}
|
||||
|
||||
}
|
@ -51,6 +51,12 @@ public abstract class Trigger {
|
||||
trigger = InteractTrigger.getOrCreate(P.p.parseInt(splitted[1]), dsign.getGameWorld());
|
||||
}
|
||||
|
||||
} else if (splitted[0].equalsIgnoreCase("M")) {
|
||||
|
||||
if (splitted.length > 1) {
|
||||
trigger = MobTrigger.getOrCreate(splitted[1], dsign.getGameWorld());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return trigger;
|
||||
|
Loading…
Reference in New Issue
Block a user