diff --git a/src/com/dre/dungeonsxl/signs/DSign.java b/src/com/dre/dungeonsxl/signs/DSign.java index 325298eb..74ab398c 100644 --- a/src/com/dre/dungeonsxl/signs/DSign.java +++ b/src/com/dre/dungeonsxl/signs/DSign.java @@ -136,6 +136,8 @@ public abstract class DSign { dSign = new SIGNRedstone(sign, gworld); } else if (lines[0].equalsIgnoreCase("[" + SIGNBlock.name + "]")) { dSign = new SIGNBlock(sign, gworld); + } else if (lines[0].equalsIgnoreCase("[" + SIGNMythicMobs.name + "]")) { + dSign = new SIGNMythicMobs(sign, gworld); } if (dSign != null && gworld != null) { diff --git a/src/com/dre/dungeonsxl/signs/SIGNMythicMobs.java b/src/com/dre/dungeonsxl/signs/SIGNMythicMobs.java new file mode 100644 index 00000000..36b4ae35 --- /dev/null +++ b/src/com/dre/dungeonsxl/signs/SIGNMythicMobs.java @@ -0,0 +1,145 @@ +package com.dre.dungeonsxl.signs; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Sign; +import org.bukkit.Location; + +import com.dre.dungeonsxl.P; +import com.dre.dungeonsxl.game.GameWorld; + +public class SIGNMythicMobs extends DSign { + + public static String name = "MythicMobs"; + public String buildPermissions = "dxl.sign.mob"; + public boolean onDungeonInit = false; + + // Variables + private String mob; + private int maxinterval = 1; + private int interval = 0; + private int amount = 1; + private boolean initialized; + private boolean active; + private int taskId = -1; + + public SIGNMythicMobs(Sign sign, GameWorld gworld) { + super(sign, gworld); + } + + @Override + public boolean check() { + String lines[] = sign.getLines(); + if (!lines[1].equals("") && !lines[2].equals("")) { + if (lines[1] != null) { + String[] atributes = lines[2].split(","); + if (atributes.length == 2) { + return true; + } + } + } + + return false; + } + + @Override + public void onInit() { + String lines[] = sign.getLines(); + if (!lines[1].equals("") && !lines[2].equals("")) { + String mob = lines[1]; + if (mob != null) { + String[] atributes = lines[2].split(","); + if (atributes.length == 2) { + this.mob = mob; + this.maxinterval = p.parseInt(atributes[0]); + this.amount = p.parseInt(atributes[1]); + } + } + } + sign.getBlock().setType(Material.AIR); + + initialized = true; + } + + @Override + public void onTrigger() { + if (initialized && !active) { + MobSpawnScheduler scheduler = new MobSpawnScheduler(this); + + taskId = p.getServer().getScheduler().scheduleSyncRepeatingTask(p, scheduler, 0L, 20L); + + active = true; + } + } + + @Override + public void onDisable() { + if (initialized && active) { + killTask(); + interval = 0; + active = false; + } + } + + public void killTask() { + if (initialized && active) { + if (taskId != -1) { + p.getServer().getScheduler().cancelTask(taskId); + taskId = -1; + } + } + } + + public class MobSpawnScheduler implements Runnable { + private SIGNMythicMobs sign; + + public MobSpawnScheduler(SIGNMythicMobs sign) { + this.sign = sign; + } + + @Override + public void run() { + if (sign.interval <= 0) { + World world = sign.sign.getWorld(); + GameWorld gworld = GameWorld.get(world); + + if (gworld != null) { + Location spawnLoc = sign.sign.getLocation().add(0.5, 0, 0.5); + double x = spawnLoc.getX(); + double y = spawnLoc.getY(); + double z = spawnLoc.getZ(); + + String command = "mm mobs spawn " + mob + " " + amount + " DXL_Game_" + gworld.id + ","+ x + "," + y + "," + z; + + Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), command); + + // Set the amount + if (amount != -1) { + if (amount > 1) { + amount--; + } else { + killTask(); + sign.remove(); + } + } + + sign.interval = sign.maxinterval; + } else { + sign.killTask(); + } + } + sign.interval--; + } + } + + @Override + public String getPermissions() { + return buildPermissions; + } + + @Override + public boolean isOnDungeonInit() { + return onDungeonInit; + } +} diff --git a/src/plugin.yml b/src/plugin.yml index 26e23650..f39e9614 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,10 +1,11 @@ name: DungeonsXL main: com.dre.dungeonsxl.P -version: 0.9.4 +version: 0.9.5-SNAPSHOT author: Frank Baumann authors: [Frank Baumann, Milan Albrecht, Tobias Schmitz, Daniel Saukel] website: http://www.dre2n.ml -softdepend: [Vault] +depend: [Vault] +softdepend: [Citizens, HolographicDisplays, HolographicMenus, InfernalMobs, MythicMobs] commands: dungeonsxl: description: Reference command for DungeonsXL.