Ability cleanup.

- All the core abilities have been moved into the project folders
  such that they no longer require any extraction. As such, all
  servers should have the abilities already installed and ready
  to use, regardless of setup-retardation.
- An attempt at fixing the "invisible bosses" issue; a call to
  removeBoss was replaced with getBoss - hopefully this fixes
  all the issues.
This commit is contained in:
garbagemule 2013-06-25 01:53:45 +02:00
parent 255908a7aa
commit e2bae68db1
27 changed files with 210 additions and 117 deletions

View File

@ -469,7 +469,7 @@ public class ArenaListener
ap.getStats().inc("kills");
arena.getScoreboard().addKill(p);
}
MABoss boss = monsters.removeBoss(event.getEntity());
MABoss boss = monsters.getBoss(event.getEntity());
if (boss != null) {
ItemStack reward = boss.getReward();
if (reward != null) {

View File

@ -202,8 +202,9 @@ public class MobArena extends JavaPlugin
private void loadAbilities() {
File dir = new File(this.getDataFolder(), "abilities");
if (!dir.exists()) dir.mkdir();
AbilityManager.loadAbilities(dir, getClass());
AbilityManager.loadCoreAbilities();
AbilityManager.loadAbilities(dir);
}
private void startMetrics() {

View File

@ -279,7 +279,7 @@ public class WaveParser
if (ablts != null) {
String[] parts = ablts.split(",");
for (String ability : parts) {
Ability a = AbilityManager.fromString(ability.trim());
Ability a = AbilityManager.getAbility(ability.trim());
if (a == null) {
Messenger.warning(WaveError.BOSS_ABILITY.format(ability.trim(), name, arena.configName()));
continue;

View File

@ -16,6 +16,7 @@ import javax.tools.ToolProvider;
import com.garbagemule.MobArena.Messenger;
import com.garbagemule.MobArena.util.FileUtils;
import com.garbagemule.MobArena.waves.ability.core.*;
public class AbilityManager
{
@ -23,22 +24,58 @@ public class AbilityManager
private static final String classpath = jarpath + ";" + System.getProperty("java.class.path");
private static Map<String,Ability> abilities;
private static Map<String,Class<? extends Ability>> abs;
/**
* Get an Ability by one of its aliases.
* @param name an Ability alias
* @return an Ability, if one exists with the given alias, false otherwise
* Get an instance of an ability by alias
* @param alias the alias of an ability
* @return a new Ability object, or null
*/
public static Ability fromString(String name) {
return abilities.get(name.toLowerCase().replaceAll("[-_.]", ""));
public static Ability getAbility(String alias) {
try {
Class<? extends Ability> cls = abs.get(alias.toLowerCase().replaceAll("[-_.]", ""));
return cls.newInstance();
} catch (Exception e) {
return null;
}
}
/**
* Load all the core abilities included in MobArena
*/
public static void loadCoreAbilities() {
if (abs == null) abs = new HashMap<String,Class<? extends Ability>>();
register(ChainLightning.class);
register(DisorientDistant.class);
register(DisorientNearby.class);
register(DisorientTarget.class);
register(FetchDistant.class);
register(FetchNearby.class);
register(FetchTarget.class);
register(FireAura.class);
register(Flood.class);
register(LightningAura.class);
register(LivingBomb.class);
register(ObsidianBomb.class);
register(PullDistant.class);
register(PullNearby.class);
register(PullTarget.class);
register(RootTarget.class);
register(ShootArrow.class);
register(ShootFireball.class);
register(ShufflePositions.class);
register(ThrowDistant.class);
register(ThrowNearby.class);
register(ThrowTarget.class);
register(WarpToPlayer.class);
}
/**
* Load the known abilities as well as all custom abilities from
* the specified directory.
* @param dir a directory of .class (and/or .java) files
* Load the custom abilities from the specified directory.
* @param classDir a directory of .class (and/or .java) files
*/
public static void loadAbilities(File classDir, Class<?> cls) {
public static void loadAbilities(File classDir) {
abilities = new HashMap<String,Ability>();
// Grab the source directory.
@ -56,32 +93,21 @@ public class AbilityManager
}
}
/* If there is only one file in the directory, make sure it isn't the
* src/ folder, in which case there will be no .class files to load.
* In the case of no .class files, extract the defaults. */
String[] files = classDir.list();
if (files.length == 0 || (files.length == 1 && files[0].equals("src"))) {
Messenger.info("No boss abilities found. Extracting defaults...");
extractDefaultAbilities(classDir, cls);
}
// Load all the custom abilities.
loadClasses(classDir);
}
private static void extractDefaultAbilities(File classDir, Class<?> cls) {
// Grab a list of all the class files.
List<String> resources = FileUtils.listFilesOnPath("res/abilities/", ".class");
// Check that there is stuff to extract.
if (resources == null || resources.isEmpty()) {
Messenger.severe("Couldn't extract the default boss abilities!");
return;
/**
* Register an ability by its class object
* @param cls the ability class
*/
private static void register(Class<? extends Ability> cls) {
AbilityInfo info = cls.getAnnotation(AbilityInfo.class);
if (info == null) return;
for (String alias : info.aliases()) {
abs.put(alias, cls);
}
// Extract everything.
List<File> files = FileUtils.extractResources(classDir, "abilities/", resources, cls);
Messenger.info("Extracted abilities: " + fileListToString(files, "$"));
}
private static void compileAbilities(File javaDir, File classDir) {
@ -175,7 +201,7 @@ public class AbilityManager
/**
* (Compiles and) loads all custom abilities in the given directory.
* @param dir a directory
* @param classDir a directory
*/
private static void loadClasses(File classDir) {
// Grab the class loader

View File

@ -1,12 +1,15 @@
import java.util.ArrayList;
import java.util.List;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
package com.garbagemule.MobArena.waves.ability.core;
import com.garbagemule.MobArena.framework.Arena;
import com.garbagemule.MobArena.waves.MABoss;
import com.garbagemule.MobArena.waves.ability.*;
import com.garbagemule.MobArena.waves.ability.Ability;
import com.garbagemule.MobArena.waves.ability.AbilityInfo;
import com.garbagemule.MobArena.waves.ability.AbilityUtils;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
@AbilityInfo(
name = "Chain Lightning",

View File

@ -1,9 +1,12 @@
import org.bukkit.Location;
import org.bukkit.entity.Player;
package com.garbagemule.MobArena.waves.ability.core;
import com.garbagemule.MobArena.framework.Arena;
import com.garbagemule.MobArena.waves.MABoss;
import com.garbagemule.MobArena.waves.ability.*;
import com.garbagemule.MobArena.waves.ability.Ability;
import com.garbagemule.MobArena.waves.ability.AbilityInfo;
import com.garbagemule.MobArena.waves.ability.AbilityUtils;
import org.bukkit.Location;
import org.bukkit.entity.Player;
@AbilityInfo(
name = "Disorient Distant",

View File

@ -1,10 +1,13 @@
import org.bukkit.Location;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
package com.garbagemule.MobArena.waves.ability.core;
import com.garbagemule.MobArena.framework.Arena;
import com.garbagemule.MobArena.waves.MABoss;
import com.garbagemule.MobArena.waves.ability.*;
import com.garbagemule.MobArena.waves.ability.Ability;
import com.garbagemule.MobArena.waves.ability.AbilityInfo;
import com.garbagemule.MobArena.waves.ability.AbilityUtils;
import org.bukkit.Location;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
@AbilityInfo(
name = "Disorient Nearby",

View File

@ -1,9 +1,12 @@
import org.bukkit.Location;
import org.bukkit.entity.LivingEntity;
package com.garbagemule.MobArena.waves.ability.core;
import com.garbagemule.MobArena.framework.Arena;
import com.garbagemule.MobArena.waves.MABoss;
import com.garbagemule.MobArena.waves.ability.*;
import com.garbagemule.MobArena.waves.ability.Ability;
import com.garbagemule.MobArena.waves.ability.AbilityInfo;
import com.garbagemule.MobArena.waves.ability.AbilityUtils;
import org.bukkit.Location;
import org.bukkit.entity.LivingEntity;
@AbilityInfo(
name = "Disorient Target",

View File

@ -1,9 +1,12 @@
import org.bukkit.Location;
import org.bukkit.entity.Player;
package com.garbagemule.MobArena.waves.ability.core;
import com.garbagemule.MobArena.framework.Arena;
import com.garbagemule.MobArena.waves.MABoss;
import com.garbagemule.MobArena.waves.ability.*;
import com.garbagemule.MobArena.waves.ability.Ability;
import com.garbagemule.MobArena.waves.ability.AbilityInfo;
import com.garbagemule.MobArena.waves.ability.AbilityUtils;
import org.bukkit.Location;
import org.bukkit.entity.Player;
@AbilityInfo(
name = "Fetch Distant",

View File

@ -1,9 +1,12 @@
import org.bukkit.Location;
import org.bukkit.entity.Player;
package com.garbagemule.MobArena.waves.ability.core;
import com.garbagemule.MobArena.framework.Arena;
import com.garbagemule.MobArena.waves.MABoss;
import com.garbagemule.MobArena.waves.ability.*;
import com.garbagemule.MobArena.waves.ability.Ability;
import com.garbagemule.MobArena.waves.ability.AbilityInfo;
import com.garbagemule.MobArena.waves.ability.AbilityUtils;
import org.bukkit.Location;
import org.bukkit.entity.Player;
@AbilityInfo(
name = "Fetch Nearby",

View File

@ -1,8 +1,11 @@
import org.bukkit.entity.LivingEntity;
package com.garbagemule.MobArena.waves.ability.core;
import com.garbagemule.MobArena.framework.Arena;
import com.garbagemule.MobArena.waves.MABoss;
import com.garbagemule.MobArena.waves.ability.*;
import com.garbagemule.MobArena.waves.ability.Ability;
import com.garbagemule.MobArena.waves.ability.AbilityInfo;
import com.garbagemule.MobArena.waves.ability.AbilityUtils;
import org.bukkit.entity.LivingEntity;
@AbilityInfo(
name = "Fetch Target",

View File

@ -1,8 +1,11 @@
import org.bukkit.entity.Player;
package com.garbagemule.MobArena.waves.ability.core;
import com.garbagemule.MobArena.framework.Arena;
import com.garbagemule.MobArena.waves.MABoss;
import com.garbagemule.MobArena.waves.ability.*;
import com.garbagemule.MobArena.waves.ability.Ability;
import com.garbagemule.MobArena.waves.ability.AbilityInfo;
import com.garbagemule.MobArena.waves.ability.AbilityUtils;
import org.bukkit.entity.Player;
@AbilityInfo(
name = "Fire Aura",

View File

@ -1,9 +1,12 @@
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
package com.garbagemule.MobArena.waves.ability.core;
import com.garbagemule.MobArena.framework.Arena;
import com.garbagemule.MobArena.waves.MABoss;
import com.garbagemule.MobArena.waves.ability.*;
import com.garbagemule.MobArena.waves.ability.Ability;
import com.garbagemule.MobArena.waves.ability.AbilityInfo;
import com.garbagemule.MobArena.waves.ability.AbilityUtils;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
@AbilityInfo(
name = "Flood",

View File

@ -1,9 +1,12 @@
import org.bukkit.World;
import org.bukkit.entity.Player;
package com.garbagemule.MobArena.waves.ability.core;
import com.garbagemule.MobArena.framework.Arena;
import com.garbagemule.MobArena.waves.MABoss;
import com.garbagemule.MobArena.waves.ability.*;
import com.garbagemule.MobArena.waves.ability.Ability;
import com.garbagemule.MobArena.waves.ability.AbilityInfo;
import com.garbagemule.MobArena.waves.ability.AbilityUtils;
import org.bukkit.World;
import org.bukkit.entity.Player;
@AbilityInfo(
name = "Lightning Aura",

View File

@ -1,9 +1,12 @@
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
package com.garbagemule.MobArena.waves.ability.core;
import com.garbagemule.MobArena.framework.Arena;
import com.garbagemule.MobArena.waves.MABoss;
import com.garbagemule.MobArena.waves.ability.*;
import com.garbagemule.MobArena.waves.ability.Ability;
import com.garbagemule.MobArena.waves.ability.AbilityInfo;
import com.garbagemule.MobArena.waves.ability.AbilityUtils;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
@AbilityInfo(
name = "Living Bomb",

View File

@ -1,13 +1,16 @@
package com.garbagemule.MobArena.waves.ability.core;
import com.garbagemule.MobArena.framework.Arena;
import com.garbagemule.MobArena.waves.MABoss;
import com.garbagemule.MobArena.waves.ability.Ability;
import com.garbagemule.MobArena.waves.ability.AbilityInfo;
import com.garbagemule.MobArena.waves.ability.AbilityUtils;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.LivingEntity;
import com.garbagemule.MobArena.framework.Arena;
import com.garbagemule.MobArena.waves.MABoss;
import com.garbagemule.MobArena.waves.ability.*;
@AbilityInfo(
name = "Obsidian Bomb",
aliases = {"obsidianbomb"}

View File

@ -1,10 +1,13 @@
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
package com.garbagemule.MobArena.waves.ability.core;
import com.garbagemule.MobArena.framework.Arena;
import com.garbagemule.MobArena.waves.MABoss;
import com.garbagemule.MobArena.waves.ability.*;
import com.garbagemule.MobArena.waves.ability.Ability;
import com.garbagemule.MobArena.waves.ability.AbilityInfo;
import com.garbagemule.MobArena.waves.ability.AbilityUtils;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
@AbilityInfo(
name = "Pull Distant",

View File

@ -1,10 +1,13 @@
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
package com.garbagemule.MobArena.waves.ability.core;
import com.garbagemule.MobArena.framework.Arena;
import com.garbagemule.MobArena.waves.MABoss;
import com.garbagemule.MobArena.waves.ability.*;
import com.garbagemule.MobArena.waves.ability.Ability;
import com.garbagemule.MobArena.waves.ability.AbilityInfo;
import com.garbagemule.MobArena.waves.ability.AbilityUtils;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
@AbilityInfo(
name = "Pull Nearby",

View File

@ -1,10 +1,13 @@
import org.bukkit.Location;
import org.bukkit.entity.LivingEntity;
import org.bukkit.util.Vector;
package com.garbagemule.MobArena.waves.ability.core;
import com.garbagemule.MobArena.framework.Arena;
import com.garbagemule.MobArena.waves.MABoss;
import com.garbagemule.MobArena.waves.ability.*;
import com.garbagemule.MobArena.waves.ability.Ability;
import com.garbagemule.MobArena.waves.ability.AbilityInfo;
import com.garbagemule.MobArena.waves.ability.AbilityUtils;
import org.bukkit.Location;
import org.bukkit.entity.LivingEntity;
import org.bukkit.util.Vector;
@AbilityInfo(
name = "Pull Target",

View File

@ -1,10 +1,13 @@
import org.bukkit.Location;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
package com.garbagemule.MobArena.waves.ability.core;
import com.garbagemule.MobArena.framework.Arena;
import com.garbagemule.MobArena.waves.MABoss;
import com.garbagemule.MobArena.waves.ability.*;
import com.garbagemule.MobArena.waves.ability.Ability;
import com.garbagemule.MobArena.waves.ability.AbilityInfo;
import com.garbagemule.MobArena.waves.ability.AbilityUtils;
import org.bukkit.Location;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
/**
* DISCLAIMER: The Ability source code is provided as-is, and the creator(s) of

View File

@ -1,8 +1,10 @@
import org.bukkit.entity.Arrow;
package com.garbagemule.MobArena.waves.ability.core;
import com.garbagemule.MobArena.framework.Arena;
import com.garbagemule.MobArena.waves.MABoss;
import com.garbagemule.MobArena.waves.ability.*;
import com.garbagemule.MobArena.waves.ability.Ability;
import com.garbagemule.MobArena.waves.ability.AbilityInfo;
import org.bukkit.entity.Arrow;
@AbilityInfo(
name = "Shoot Arrow",

View File

@ -1,8 +1,10 @@
import org.bukkit.entity.Fireball;
package com.garbagemule.MobArena.waves.ability.core;
import com.garbagemule.MobArena.framework.Arena;
import com.garbagemule.MobArena.waves.MABoss;
import com.garbagemule.MobArena.waves.ability.*;
import com.garbagemule.MobArena.waves.ability.Ability;
import com.garbagemule.MobArena.waves.ability.AbilityInfo;
import org.bukkit.entity.Fireball;
@AbilityInfo(
name = "Shoot Fireball",

View File

@ -1,15 +1,17 @@
package com.garbagemule.MobArena.waves.ability.core;
import com.garbagemule.MobArena.framework.Arena;
import com.garbagemule.MobArena.waves.MABoss;
import com.garbagemule.MobArena.waves.ability.Ability;
import com.garbagemule.MobArena.waves.ability.AbilityInfo;
import org.bukkit.Location;
import org.bukkit.entity.LivingEntity;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.entity.LivingEntity;
import com.garbagemule.MobArena.framework.Arena;
import com.garbagemule.MobArena.waves.MABoss;
import com.garbagemule.MobArena.waves.ability.*;
@AbilityInfo(
name = "Shuffle Positions",
aliases = {"shuffle","shufflepositions"}

View File

@ -1,10 +1,13 @@
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
package com.garbagemule.MobArena.waves.ability.core;
import com.garbagemule.MobArena.framework.Arena;
import com.garbagemule.MobArena.waves.MABoss;
import com.garbagemule.MobArena.waves.ability.*;
import com.garbagemule.MobArena.waves.ability.Ability;
import com.garbagemule.MobArena.waves.ability.AbilityInfo;
import com.garbagemule.MobArena.waves.ability.AbilityUtils;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
@AbilityInfo(
name = "Throw Distant",

View File

@ -1,10 +1,13 @@
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
package com.garbagemule.MobArena.waves.ability.core;
import com.garbagemule.MobArena.framework.Arena;
import com.garbagemule.MobArena.waves.MABoss;
import com.garbagemule.MobArena.waves.ability.*;
import com.garbagemule.MobArena.waves.ability.Ability;
import com.garbagemule.MobArena.waves.ability.AbilityInfo;
import com.garbagemule.MobArena.waves.ability.AbilityUtils;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
@AbilityInfo(
name = "Throw Nearby",

View File

@ -1,10 +1,13 @@
import org.bukkit.Location;
import org.bukkit.entity.LivingEntity;
import org.bukkit.util.Vector;
package com.garbagemule.MobArena.waves.ability.core;
import com.garbagemule.MobArena.framework.Arena;
import com.garbagemule.MobArena.waves.MABoss;
import com.garbagemule.MobArena.waves.ability.*;
import com.garbagemule.MobArena.waves.ability.Ability;
import com.garbagemule.MobArena.waves.ability.AbilityInfo;
import com.garbagemule.MobArena.waves.ability.AbilityUtils;
import org.bukkit.Location;
import org.bukkit.entity.LivingEntity;
import org.bukkit.util.Vector;
@AbilityInfo(
name = "Throw Target",

View File

@ -1,8 +1,11 @@
import org.bukkit.entity.Player;
package com.garbagemule.MobArena.waves.ability.core;
import com.garbagemule.MobArena.framework.Arena;
import com.garbagemule.MobArena.waves.MABoss;
import com.garbagemule.MobArena.waves.ability.*;
import com.garbagemule.MobArena.waves.ability.Ability;
import com.garbagemule.MobArena.waves.ability.AbilityInfo;
import com.garbagemule.MobArena.waves.ability.AbilityUtils;
import org.bukkit.entity.Player;
@AbilityInfo(
name = "Warp",