Changes
This commit is contained in:
@@ -5,6 +5,7 @@ import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
@@ -76,7 +77,7 @@ public class Arena
|
||||
|
||||
// Arena sets/maps
|
||||
protected Set<Player> hasPaid, rewardedPlayers, notifyPlayers, randoms;
|
||||
protected Set<LivingEntity> monsters;
|
||||
protected Set<LivingEntity> monsters, explodingSheep, plaguedPigs, madCows;
|
||||
protected Set<Block> blocks;
|
||||
protected Set<Wolf> pets;
|
||||
protected Map<Player,Integer> petMap;
|
||||
@@ -117,6 +118,9 @@ public class Arena
|
||||
rewardedPlayers = new HashSet<Player>();
|
||||
hasPaid = new HashSet<Player>();
|
||||
monsters = new HashSet<LivingEntity>();
|
||||
explodingSheep = new HashSet<LivingEntity>();
|
||||
plaguedPigs = new HashSet<LivingEntity>();
|
||||
madCows = new HashSet<LivingEntity>();
|
||||
blocks = new HashSet<Block>();
|
||||
pets = new HashSet<Wolf>();
|
||||
petMap = new HashMap<Player,Integer>();
|
||||
@@ -259,7 +263,6 @@ public class Arena
|
||||
lobbyPlayers.clear();
|
||||
readyPlayers.clear();
|
||||
|
||||
//rewardMap.clear();
|
||||
monsters.clear();
|
||||
|
||||
spawnTaskId = -1;
|
||||
@@ -292,7 +295,7 @@ public class Arena
|
||||
MAUtils.clearInventory(p);
|
||||
|
||||
restoreInvAndGiveRewards(p);
|
||||
if (log.players.get(p) != null) log.players.get(p).lastWave = spawnThread.wave - 1;
|
||||
if (log.players.get(p) != null) log.players.get(p).lastWave = spawnThread.getWave() - 1;
|
||||
movePlayerToEntry(p);
|
||||
finishWithPlayer(p);
|
||||
endArena();
|
||||
@@ -302,7 +305,7 @@ public class Arena
|
||||
{
|
||||
MAUtils.clearInventory(p);
|
||||
restoreInvAndGiveRewards(p);
|
||||
log.players.get(p).lastWave = spawnThread.wave - 1;
|
||||
log.players.get(p).lastWave = spawnThread.getWave() - 1;
|
||||
|
||||
if (specOnDeath)
|
||||
{
|
||||
@@ -368,7 +371,7 @@ public class Arena
|
||||
// Stop the spawn thread.
|
||||
if (spawnThread != null)
|
||||
{
|
||||
Bukkit.getServer().getScheduler().cancelTask(spawnThread.taskId);
|
||||
Bukkit.getServer().getScheduler().cancelTask(spawnThread.getTaskId());
|
||||
Bukkit.getServer().getScheduler().cancelTask(spawnTaskId);
|
||||
spawnTaskId = -1;
|
||||
spawnThread = null;
|
||||
@@ -544,6 +547,9 @@ public class Arena
|
||||
removePets();
|
||||
removeEntities();
|
||||
monsters.clear();
|
||||
explodingSheep.clear();
|
||||
plaguedPigs.clear();
|
||||
madCows.clear();
|
||||
blocks.clear();
|
||||
pets.clear();
|
||||
}
|
||||
@@ -552,6 +558,12 @@ public class Arena
|
||||
{
|
||||
for (LivingEntity e : monsters)
|
||||
e.remove();
|
||||
for (LivingEntity e : explodingSheep)
|
||||
e.remove();
|
||||
for (LivingEntity e : plaguedPigs)
|
||||
e.remove();
|
||||
for (LivingEntity e : madCows)
|
||||
e.remove();
|
||||
}
|
||||
|
||||
private void removeBlocks()
|
||||
@@ -653,16 +665,15 @@ public class Arena
|
||||
spawnpoints = MAUtils.getArenaSpawnpoints(config, world, configName);
|
||||
|
||||
// NEW WAVES
|
||||
singleWaves = WaveUtils.getWaves(config, configName, WaveBranch.SINGLE);
|
||||
recurrentWaves = WaveUtils.getWaves(config, configName, WaveBranch.RECURRENT);
|
||||
singleWaves = WaveUtils.getWaves(this, config, WaveBranch.SINGLE);
|
||||
recurrentWaves = WaveUtils.getWaves(this, config, WaveBranch.RECURRENT);
|
||||
|
||||
|
||||
System.out.println();
|
||||
System.out.println("ARENA: " + configName);
|
||||
System.out.println("Single waves");
|
||||
int si = singleWaves.size();
|
||||
for (int i = 0; i < si; i++)
|
||||
System.out.println("- " + singleWaves.pollFirst());
|
||||
for (Wave w : singleWaves)
|
||||
System.out.println("- " + w);
|
||||
System.out.println("Reccurent waves");
|
||||
for (Wave w : recurrentWaves)
|
||||
System.out.println("- " + w);
|
||||
@@ -854,6 +865,31 @@ public class Arena
|
||||
return name;
|
||||
}
|
||||
|
||||
public World getWorld()
|
||||
{
|
||||
return world;
|
||||
}
|
||||
|
||||
public List<String> getClasses()
|
||||
{
|
||||
return classes;
|
||||
}
|
||||
|
||||
public Collection<Location> getSpawnpoints()
|
||||
{
|
||||
return spawnpoints.values();
|
||||
}
|
||||
|
||||
public int getPlayerCount()
|
||||
{
|
||||
return spawnThread.getPlayerCount();
|
||||
}
|
||||
|
||||
public void addMonster(LivingEntity e)
|
||||
{
|
||||
monsters.add(e);
|
||||
}
|
||||
|
||||
public List<Player> getAllPlayers()
|
||||
{
|
||||
List<Player> result = new LinkedList<Player>();
|
||||
@@ -884,9 +920,9 @@ public class Arena
|
||||
return;
|
||||
|
||||
// Reset the previousSize, cancel the previous timer, and start the new timer.
|
||||
spawnThread.previousSize = monsters.size();
|
||||
Bukkit.getServer().getScheduler().cancelTask(spawnThread.taskId);
|
||||
spawnThread.taskId = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin,
|
||||
spawnThread.setPreviousSize(monsters.size());
|
||||
Bukkit.getServer().getScheduler().cancelTask(spawnThread.getTaskId());
|
||||
int id = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin,
|
||||
new Runnable()
|
||||
{
|
||||
public void run()
|
||||
@@ -898,7 +934,7 @@ public class Arena
|
||||
monsters.remove(e);
|
||||
|
||||
// Compare the current size with the previous size.
|
||||
if (monsters.size() < spawnThread.previousSize || spawnThread.previousSize == 0)
|
||||
if (monsters.size() < spawnThread.getPreviousSize() || spawnThread.getPreviousSize() == 0)
|
||||
{
|
||||
resetIdleTimer();
|
||||
return;
|
||||
@@ -914,6 +950,7 @@ public class Arena
|
||||
}
|
||||
}
|
||||
}, maxIdleTime);
|
||||
spawnThread.setTaskId(id);
|
||||
}
|
||||
|
||||
public void addTrunkAndLeaves(Block b)
|
||||
@@ -1017,12 +1054,7 @@ public class Arena
|
||||
MAUtils.giveItems(p, entryFee, false, plugin);
|
||||
hasPaid.remove(p);
|
||||
}
|
||||
|
||||
public List<String> getClasses()
|
||||
{
|
||||
return classes;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The "perfect equals method" cf. "Object-Oriented Design and Patterns"
|
||||
* by Cay S. Horstmann.
|
||||
|
||||
@@ -40,7 +40,7 @@ public class ArenaLog
|
||||
|
||||
public void end()
|
||||
{
|
||||
lastWave = arena.spawnThread.wave - 1;
|
||||
lastWave = arena.spawnThread.getWave() - 1;
|
||||
endTime = new Timestamp((new Date()).getTime());
|
||||
}
|
||||
|
||||
|
||||
@@ -5,27 +5,19 @@ import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Wolf;
|
||||
import org.bukkit.entity.Ghast;
|
||||
import org.bukkit.entity.Slime;
|
||||
import org.bukkit.entity.Creeper;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Creature;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.CreatureType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.garbagemule.MobArena.MAMessages.Msg;
|
||||
import com.garbagemule.MobArena.util.WaveUtils;
|
||||
import com.garbagemule.MobArena.waves.RecurrentWave;
|
||||
import com.garbagemule.MobArena.waves.SingleWave;
|
||||
import com.garbagemule.MobArena.waves.Wave;
|
||||
|
||||
/**
|
||||
@@ -38,26 +30,28 @@ import com.garbagemule.MobArena.waves.Wave;
|
||||
*/
|
||||
public class MASpawnThread implements Runnable
|
||||
{
|
||||
protected int wave, previousSize, taskId;
|
||||
private int ran, noOfPlayers, modulo;
|
||||
private int dZombies, dSkeletons, dSpiders, dCreepers, dWolves;
|
||||
private int dPoweredCreepers, dPigZombies, dSlimes, dMonsters, dAngryWolves, dGiants, dGhasts;
|
||||
private Random random;
|
||||
private MobArena plugin;
|
||||
private Arena arena;
|
||||
private int wave, taskId, previousSize, playerCount;
|
||||
|
||||
// NEW WAVES
|
||||
/* Single waves are waves with a frequency of 0, and they only
|
||||
* spawn once. Their priority is infinity, meaning they will always
|
||||
* spawn instead of recurrent waves, if the wave numbers clash. */
|
||||
private Wave defaultWave;
|
||||
private TreeSet<SingleWave> singleWaves;
|
||||
private TreeSet<RecurrentWave> recurrentWaves;
|
||||
private TreeSet<Wave> recurrentWaves;
|
||||
private TreeSet<Wave> singleWaves;
|
||||
|
||||
public MASpawnThread(MobArena plugin, Arena arena)
|
||||
{
|
||||
this.plugin = plugin;
|
||||
this.arena = arena;
|
||||
// WAVES
|
||||
defaultWave = arena.recurrentWaves.first();
|
||||
recurrentWaves = arena.recurrentWaves;
|
||||
singleWaves = arena.singleWaves;
|
||||
|
||||
this.plugin = plugin;
|
||||
this.arena = arena;
|
||||
wave = 1;
|
||||
playerCount = arena.arenaPlayers.size();
|
||||
|
||||
/*
|
||||
modulo = arena.specialModulo;
|
||||
if (modulo <= 0) modulo = -32768;
|
||||
|
||||
@@ -84,9 +78,10 @@ public class MASpawnThread implements Runnable
|
||||
dGiants = dAngryWolves + arena.distSpecial.get("giants");
|
||||
dGhasts = dGiants + arena.distSpecial.get("ghasts");
|
||||
if (dGhasts < 1) { dPoweredCreepers = 1; dPigZombies = 2; dSlimes = 3; dMonsters = 4; dAngryWolves = 5; dGiants = 5; dGhasts = 5; }
|
||||
*/
|
||||
}
|
||||
|
||||
public void run2()
|
||||
public void run()
|
||||
{
|
||||
// Clear out all dead monsters in the monster set.
|
||||
removeDeadMonsters();
|
||||
@@ -132,7 +127,7 @@ public class MASpawnThread implements Runnable
|
||||
}
|
||||
|
||||
private void spawnWave(int wave)
|
||||
{
|
||||
{
|
||||
Wave w = null;
|
||||
|
||||
// Check the first element of the single waves.
|
||||
@@ -145,23 +140,10 @@ public class MASpawnThread implements Runnable
|
||||
else
|
||||
{
|
||||
SortedSet<Wave> matches = getMatchingRecurrentWaves(wave);
|
||||
|
||||
if (matches.isEmpty())
|
||||
w = defaultWave;
|
||||
else
|
||||
w = matches.last();
|
||||
w = matches.isEmpty() ? defaultWave : matches.last();
|
||||
}
|
||||
|
||||
w.spawn(wave, arena.spawnpoints.values());
|
||||
/*
|
||||
// Otherwise, check the recurrent waves.
|
||||
SortedSet<Wave> matches = getMatchingRecurrentWaves(wave);
|
||||
|
||||
if (matches.isEmpty())
|
||||
defaultWave.spawn(wave, arena.spawnpoints.values());
|
||||
else
|
||||
matches.last().spawn(wave, arena.spawnpoints.values());
|
||||
*/
|
||||
w.spawn(wave);
|
||||
}
|
||||
|
||||
private SortedSet<Wave> getMatchingRecurrentWaves(int wave)
|
||||
@@ -177,7 +159,46 @@ public class MASpawnThread implements Runnable
|
||||
return result;
|
||||
}
|
||||
|
||||
public void run()
|
||||
|
||||
|
||||
/*////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Getters/setters
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
public int getWave()
|
||||
{
|
||||
return wave;
|
||||
}
|
||||
|
||||
public int getTaskId()
|
||||
{
|
||||
return taskId;
|
||||
}
|
||||
|
||||
public int getPreviousSize()
|
||||
{
|
||||
return previousSize;
|
||||
}
|
||||
|
||||
public int getPlayerCount()
|
||||
{
|
||||
return playerCount;
|
||||
}
|
||||
|
||||
public void setTaskId(int taskId)
|
||||
{
|
||||
this.taskId = taskId;
|
||||
}
|
||||
|
||||
public void setPreviousSize(int previousSize)
|
||||
{
|
||||
this.previousSize = previousSize;
|
||||
}
|
||||
|
||||
/*
|
||||
public void run1()
|
||||
{
|
||||
if (arena.arenaPlayers.isEmpty())
|
||||
return;
|
||||
@@ -228,6 +249,7 @@ public class MASpawnThread implements Runnable
|
||||
wave++;
|
||||
if (arena.maxIdleTime > 0 && arena.monsters.isEmpty()) arena.resetIdleTimer();
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Rewards all players with an item from the input String.
|
||||
@@ -238,12 +260,9 @@ public class MASpawnThread implements Runnable
|
||||
{
|
||||
if (arena.log.players.get(p) == null)
|
||||
continue;
|
||||
/*if (arena.rewardMap.get(p) == null)
|
||||
continue;*/
|
||||
|
||||
ItemStack reward = MAUtils.getRandomReward(rewards);
|
||||
arena.log.players.get(p).rewards.add(reward);
|
||||
//arena.rewardMap.get(p).add(reward);
|
||||
|
||||
if (reward == null)
|
||||
{
|
||||
@@ -266,7 +285,7 @@ public class MASpawnThread implements Runnable
|
||||
/**
|
||||
* Spawns a default wave of monsters.
|
||||
*/
|
||||
private void defaultWave()
|
||||
/*private void defaultWave()
|
||||
{
|
||||
Location loc;
|
||||
List<Location> spawnpoints = getValidSpawnpoints();
|
||||
@@ -283,7 +302,7 @@ public class MASpawnThread implements Runnable
|
||||
* we're able to evaluate the random number in this way.
|
||||
* If dSpiders = 0, then dSpiders = dSkeletons, which
|
||||
* means if the random number is below that value, we will
|
||||
* spawn a skeleton and break out of the statement. */
|
||||
* spawn a skeleton and break out of the statement. */ /*
|
||||
if (ran < dZombies) mob = CreatureType.ZOMBIE;
|
||||
else if (ran < dSkeletons) mob = CreatureType.SKELETON;
|
||||
else if (ran < dSpiders) mob = CreatureType.SPIDER;
|
||||
@@ -301,12 +320,12 @@ public class MASpawnThread implements Runnable
|
||||
Creature c = (Creature) e;
|
||||
c.setTarget(getClosestPlayer(e));
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Spawns a special wave of monsters.
|
||||
*/
|
||||
private void specialWave()
|
||||
/*private void specialWave()
|
||||
{
|
||||
Location loc;
|
||||
List<Location> spawnpoints = getValidSpawnpoints();
|
||||
@@ -389,7 +408,7 @@ public class MASpawnThread implements Runnable
|
||||
// Lightning, just for effect ;)
|
||||
for (Location spawn : arena.spawnpoints.values())
|
||||
arena.world.strikeLightningEffect(spawn);
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* "Detonates" all the Creepers in the monsterSet.
|
||||
|
||||
@@ -105,6 +105,7 @@ public class MobArena extends JavaPlugin
|
||||
|
||||
config = new Configuration(file);
|
||||
config.load();
|
||||
config.setHeader(header());
|
||||
}
|
||||
|
||||
private void registerListeners()
|
||||
@@ -178,4 +179,12 @@ public class MobArena extends JavaPlugin
|
||||
public Configuration getConfig() { return config; }
|
||||
public ArenaMaster getAM() { return am; } // More convenient.
|
||||
public ArenaMaster getArenaMaster() { return am; }
|
||||
|
||||
private String header()
|
||||
{
|
||||
String sep = System.getProperty("line.separator");
|
||||
return "# MobArena v" + desc.getVersion() + " - Config-file" + sep +
|
||||
"# Read the Wiki for details on how to set up this file: http://goo.gl/F5TTc" + sep +
|
||||
"# Note: You -must- use spaces instead of tabs!";
|
||||
}
|
||||
}
|
||||
@@ -8,20 +8,15 @@ import java.util.TreeSet;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.CreatureType;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.config.Configuration;
|
||||
|
||||
import com.garbagemule.MobArena.Arena;
|
||||
import com.garbagemule.MobArena.MAUtils;
|
||||
import com.garbagemule.MobArena.MobArena;
|
||||
import com.garbagemule.MobArena.waves.RecurrentWave;
|
||||
import com.garbagemule.MobArena.waves.SingleWave;
|
||||
import com.garbagemule.MobArena.waves.Wave;
|
||||
import com.garbagemule.MobArena.waves.Wave.BossAbility;
|
||||
import com.garbagemule.MobArena.waves.Wave.BossHealth;
|
||||
import com.garbagemule.MobArena.waves.Wave.SwarmAmount;
|
||||
import com.garbagemule.MobArena.waves.Wave.WaveBranch;
|
||||
import com.garbagemule.MobArena.waves.Wave.WaveGrowth;
|
||||
import com.garbagemule.MobArena.waves.Wave.WaveType;
|
||||
import com.garbagemule.MobArena.waves.*;
|
||||
import com.garbagemule.MobArena.waves.Wave.*;
|
||||
|
||||
public class WaveUtils
|
||||
{
|
||||
@@ -59,18 +54,49 @@ public class WaveUtils
|
||||
// Else, return the valid spawnpoints.
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static Player getClosestPlayer(Arena arena, Entity e)
|
||||
{
|
||||
// Set up the comparison variable and the result.
|
||||
double dist = 0;
|
||||
double current = Double.POSITIVE_INFINITY;
|
||||
Player result = null;
|
||||
|
||||
/* Iterate through the ArrayList, and update current and result every
|
||||
* time a squared distance smaller than current is found. */
|
||||
//for (Player p : arena.livePlayers)
|
||||
for (Player p : arena.getLivingPlayers())
|
||||
{
|
||||
if (!arena.getWorld().equals(p.getWorld()))
|
||||
{
|
||||
System.out.println("[MobArena] Player '" + p.getName() + "' is not in the right world. Force leaving...");
|
||||
arena.playerLeave(p);
|
||||
MAUtils.tellPlayer(p, "You warped out of the arena world.");
|
||||
continue;
|
||||
}
|
||||
|
||||
dist = p.getLocation().distanceSquared(e.getLocation());
|
||||
if (dist < current && dist < MobArena.MIN_PLAYER_DISTANCE)
|
||||
{
|
||||
current = dist;
|
||||
result = p;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Grab and process all the waves in the config-file for the arena.
|
||||
*/
|
||||
public static TreeSet<Wave> getWaves(Configuration config, String arena, WaveBranch branch)
|
||||
public static TreeSet<Wave> getWaves(Arena arena, Configuration config, WaveBranch branch)
|
||||
{
|
||||
// Determine the branch type of the wave, and grab the appropriate comparator
|
||||
String b = branch.toString().toLowerCase();
|
||||
TreeSet<Wave> result = new TreeSet<Wave>(getComparator(branch));
|
||||
|
||||
// Grab the waves from the config-file
|
||||
String path = "arenas." + arena + ".waves." + b;
|
||||
String path = "arenas." + arena.configName() + ".waves." + b; // waves.yml, change to either "waves." + b, or simply b
|
||||
List<String> waves = config.getKeys(path);
|
||||
|
||||
// If there are any waves, process them
|
||||
@@ -80,7 +106,7 @@ public class WaveUtils
|
||||
for (String w : waves)
|
||||
{
|
||||
// path argument becomes: "arenas.<arena>.waves.<branch>.<wave>."
|
||||
wave = getWave(config, path + "." + w + ".", w, branch);
|
||||
wave = getWave(arena, config, path + "." + w + ".", w, branch);
|
||||
if (wave != null) result.add(wave);
|
||||
}
|
||||
}
|
||||
@@ -88,12 +114,12 @@ public class WaveUtils
|
||||
// If there are no waves and the type is 'recurrent', add a default wave.
|
||||
if (branch == WaveBranch.RECURRENT && (result.isEmpty() || waves == null))
|
||||
{
|
||||
RecurrentWave def = new RecurrentWave("DEF_WAVE_AUTO", 1, 1, 1);
|
||||
/*
|
||||
DefaultWave def = new DefaultWave(arena, "DEF_WAVE_AUTO", 1, 1, 1, null, null);
|
||||
def.setType(WaveType.DEFAULT);
|
||||
def.setGrowth(WaveGrowth.MEDIUM);
|
||||
def.setDefault(true);
|
||||
|
||||
result.add(def);
|
||||
*/
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -103,9 +129,9 @@ public class WaveUtils
|
||||
* Get a single wave based on the config-file, the path, and branch
|
||||
* @return A Wave object if it is well defined, null otherwise.
|
||||
*/
|
||||
private static Wave getWave(Configuration config, String path, String name, WaveBranch branch)
|
||||
private static Wave getWave(Arena arena, Configuration config, String path, String name, WaveBranch branch)
|
||||
{
|
||||
// Grab the wave type, if null, return null
|
||||
// Grab the wave type, if null or not well defined, return null
|
||||
WaveType type = WaveType.fromString(config.getString(path + "type"));
|
||||
if (type == null || !isWaveWellDefined(config, path, branch, type))
|
||||
return null;
|
||||
@@ -117,210 +143,26 @@ public class WaveUtils
|
||||
int frequency = config.getInt(path + "frequency", 0);
|
||||
int priority = config.getInt(path + "priority", 0);
|
||||
int wave = config.getInt(path + "wave", frequency);
|
||||
result = new RecurrentWave(name, wave, frequency, priority);
|
||||
|
||||
//if (type == WaveType.DEFAULT)
|
||||
result = new DefaultWave(arena, name, wave, frequency, priority, config, path);
|
||||
result.setGrowth(WaveGrowth.OLD);
|
||||
//else
|
||||
// result = new SpecialWave(arena, name, wave, frequency, priority, config, path);
|
||||
}
|
||||
else
|
||||
{
|
||||
int wave = config.getInt(path + "wave", 0);
|
||||
result = new SingleWave(name, wave);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/*
|
||||
public static RecurrentWave getRecurrentWave(Configuration config, String arena, String w)
|
||||
{
|
||||
// Grab the path
|
||||
String path = "arenas." + arena + ".waves.recurrent." + w + ".";
|
||||
|
||||
// Ensure that frequency and priority exist, otherwise return null
|
||||
int frequency = config.getInt(path + "frequency", 0);
|
||||
int priority = config.getInt(path + "priority", 0);
|
||||
if (frequency == 0 || priority == 0) return null;
|
||||
|
||||
// Grab other variables
|
||||
int wave = config.getInt(path + "wave", frequency);
|
||||
WaveType type = WaveType.fromString(config.getString(path + "type", "default"));
|
||||
WaveGrowth growth = WaveGrowth.fromString(config.getString(path + "growth", "medium"));
|
||||
|
||||
// Grab monster distribution
|
||||
//Map<CreatureType,Integer> monsters = getWaveMonsters(config, arena, path, type);
|
||||
|
||||
// Create the wave
|
||||
RecurrentWave result = new RecurrentWave(w, wave, frequency, priority, type, growth);
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static SingleWave getSingleWave(Configuration config, String arena, String w)
|
||||
{
|
||||
// Grab the path
|
||||
String path = "arenas." + arena + ".waves.single." + w + ".";
|
||||
|
||||
// Ensure that the wave number exists, otherwise return null
|
||||
int wave = config.getInt(path + "wave", 0);
|
||||
if (wave == 0) return null;
|
||||
|
||||
// Grab other variables
|
||||
|
||||
SingleWave result = new SingleWave(w, wave);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Map<CreatureType,Integer> getWaveMonsters(Configuration config, String arena, String path, String type)
|
||||
{
|
||||
Map<CreatureType,Integer> result = new HashMap<CreatureType,Integer>();
|
||||
|
||||
List<String> monsters = config.getKeys(path + "monsters");
|
||||
|
||||
// If no monsters specified, make sure to add some
|
||||
if (monsters == null)
|
||||
{
|
||||
if (type.equals("default"))
|
||||
{
|
||||
result.put(CreatureType.ZOMBIE, 10);
|
||||
result.put(CreatureType.SKELETON, 10);
|
||||
result.put(CreatureType.SPIDER, 10);
|
||||
result.put(CreatureType.CREEPER, 10);
|
||||
result.put(CreatureType.WOLF, 10);
|
||||
}
|
||||
else if (type.equals("default"))
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/*////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Comparators
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
/**
|
||||
* Get a comparator based on the WaveBranch parameter.
|
||||
*/
|
||||
public static Comparator<Wave> getComparator(WaveBranch branch)
|
||||
{
|
||||
if (branch == WaveBranch.SINGLE)
|
||||
return getSingleComparator();
|
||||
else if (branch == WaveBranch.RECURRENT)
|
||||
return getRecurrentComparator();
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Comparator that compares Wave objects by wave number.
|
||||
* If the wave numbers are equal, the waves are equal. This is to
|
||||
* DISALLOW "duplicates" in the SINGLE WAVES collection.
|
||||
* @return Comparator whose compare()-method compares wave numbers.
|
||||
*/
|
||||
public static Comparator<Wave> getSingleComparator()
|
||||
{
|
||||
return new Comparator<Wave>()
|
||||
{
|
||||
public int compare(Wave w1, Wave w2)
|
||||
{
|
||||
if (w1.getWave() < w2.getWave())
|
||||
return -1;
|
||||
else if (w1.getWave() > w2.getWave())
|
||||
return 1;
|
||||
else return 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Comparator that compares Wave objects by priority.
|
||||
* If the priorities are equal, the names are compared. This is to
|
||||
* ALLOW "duplicates" in the RECURRENT WAVES collection.
|
||||
* @return Comparator whose compare()-method compares wave priorities.
|
||||
*/
|
||||
public static Comparator<Wave> getRecurrentComparator()
|
||||
{
|
||||
return new Comparator<Wave>()
|
||||
{
|
||||
public int compare(Wave w1, Wave w2)
|
||||
{
|
||||
if (w1.getPriority() < w2.getPriority())
|
||||
return -1;
|
||||
else if (w1.getPriority() > w2.getPriority())
|
||||
return 1;
|
||||
else return w1.getName().compareTo(w2.getName());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the single waves for the given arena.
|
||||
*/
|
||||
/*public static TreeSet<SingleWave> getSingleWaves(Configuration config, String arena)
|
||||
{
|
||||
TreeSet<SingleWave> result = new TreeSet<SingleWave>();
|
||||
|
||||
List<String> waves = config.getKeys("arenas." + arena + ".waves.single");
|
||||
if (waves != null)
|
||||
{
|
||||
int wave;
|
||||
|
||||
for (String w : waves)
|
||||
{
|
||||
wave = config.getInt("arenas." + arena + ".waves.single." + w + ".wave", 0);
|
||||
if (wave == 0) continue;
|
||||
result.add(new SingleWave(w, wave));
|
||||
}
|
||||
//if (type == WaveType.DEFAULT)
|
||||
result = new DefaultWave(arena, name, wave, config, path);
|
||||
result.setGrowth(WaveGrowth.OLD);
|
||||
//else
|
||||
// result = new SpecialWave(arena, name, wave, config, path);
|
||||
}
|
||||
|
||||
return result;
|
||||
}*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the recurrent waves for the given arena.
|
||||
* If no waves are found, a default wave is added. This ensures that
|
||||
* the arena always has monsters spawning, regardless of how badly the
|
||||
* user messes up the config-file.
|
||||
*/
|
||||
/*public static TreeSet<RecurrentWave> getRecurrentWaves(Configuration config, String arena)
|
||||
{
|
||||
TreeSet<RecurrentWave> result = new TreeSet<RecurrentWave>();
|
||||
|
||||
List<String> waves = config.getKeys("arenas." + arena + ".waves.recurrent");
|
||||
if (waves != null)
|
||||
{
|
||||
int wave, frequency, priority;
|
||||
|
||||
for (String w : waves)
|
||||
{
|
||||
frequency = config.getInt("arenas." + arena + ".waves.recurrent." + w + ".frequency", 0);
|
||||
priority = config.getInt("arenas." + arena + ".waves.recurrent." + w + ".priority", 0);
|
||||
if (frequency == 0 || priority == 0) continue;
|
||||
|
||||
wave = config.getInt("arenas." + arena + ".waves.single." + w + ".wave", frequency);
|
||||
result.add(new RecurrentWave(w, wave, frequency, priority));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
RecurrentWave def = new RecurrentWave("DEF_WAVE_AUTO", 1, 1, 1);
|
||||
def.setType(WaveType.DEFAULT);
|
||||
def.setGrowth(WaveGrowth.MEDIUM);
|
||||
|
||||
RecurrentWave spec = new RecurrentWave("SPEC_WAVE_AUTO", 4, 4, 4);
|
||||
spec.setType(WaveType.SPECIAL);
|
||||
|
||||
result.add(def);
|
||||
result.add(spec);
|
||||
}
|
||||
|
||||
return result;
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
/*////////////////////////////////////////////////////////////////////
|
||||
@@ -407,7 +249,8 @@ public class WaveUtils
|
||||
|
||||
for (String monster : monsters)
|
||||
{
|
||||
if (getEnumFromString(CreatureType.class, monster) != null)
|
||||
//if (getEnumFromString(CreatureType.class, monster) != null)
|
||||
if (getEnumFromString(MACreature.class, monster) != null)
|
||||
continue;
|
||||
|
||||
MAUtils.error("Invalid monster type '" + monster + "' in " + path);
|
||||
@@ -491,7 +334,70 @@ public class WaveUtils
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Comparators
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
/**
|
||||
* Get a comparator based on the WaveBranch parameter.
|
||||
*/
|
||||
public static Comparator<Wave> getComparator(WaveBranch branch)
|
||||
{
|
||||
if (branch == WaveBranch.SINGLE)
|
||||
return getSingleComparator();
|
||||
else if (branch == WaveBranch.RECURRENT)
|
||||
return getRecurrentComparator();
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Comparator that compares Wave objects by wave number.
|
||||
* If the wave numbers are equal, the waves are equal. This is to
|
||||
* DISALLOW "duplicates" in the SINGLE WAVES collection.
|
||||
* @return Comparator whose compare()-method compares wave numbers.
|
||||
*/
|
||||
public static Comparator<Wave> getSingleComparator()
|
||||
{
|
||||
return new Comparator<Wave>()
|
||||
{
|
||||
public int compare(Wave w1, Wave w2)
|
||||
{
|
||||
if (w1.getWave() < w2.getWave())
|
||||
return -1;
|
||||
else if (w1.getWave() > w2.getWave())
|
||||
return 1;
|
||||
else return 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Comparator that compares Wave objects by priority.
|
||||
* If the priorities are equal, the names are compared. This is to
|
||||
* ALLOW "duplicates" in the RECURRENT WAVES collection.
|
||||
* @return Comparator whose compare()-method compares wave priorities.
|
||||
*/
|
||||
public static Comparator<Wave> getRecurrentComparator()
|
||||
{
|
||||
return new Comparator<Wave>()
|
||||
{
|
||||
public int compare(Wave w1, Wave w2)
|
||||
{
|
||||
if (w1.getPriority() < w2.getPriority())
|
||||
return -1;
|
||||
else if (w1.getPriority() > w2.getPriority())
|
||||
return 1;
|
||||
else return w1.getName().compareTo(w2.getName());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -1,64 +1,96 @@
|
||||
package com.garbagemule.MobArena.waves;
|
||||
|
||||
import org.bukkit.World;
|
||||
|
||||
import com.garbagemule.MobArena.Arena;
|
||||
|
||||
public abstract class AbstractWave implements Wave
|
||||
{
|
||||
private String name;
|
||||
private Arena arena;
|
||||
private World world;
|
||||
private String waveName;
|
||||
private int wave, frequency, priority;
|
||||
private WaveBranch branch;
|
||||
private WaveType type;
|
||||
private WaveGrowth growth;
|
||||
|
||||
/**
|
||||
* Basic wave constructor.
|
||||
* Constructs a wave with an initial wave number, a wave frequency, and
|
||||
* a wave priority.
|
||||
* @param name The config-file identifier
|
||||
* @param wave Initial wave number. This is the first wave number this wave can spawn at.
|
||||
* @param frequency How often the wave can spawn.
|
||||
* @param priority The priority of the wave.
|
||||
*/
|
||||
public AbstractWave(String name, int wave, int frequency, int priority)
|
||||
* @param branch The branch type (single, recurrent)
|
||||
*/
|
||||
public AbstractWave(Arena arena, String waveName, int wave, int frequency, int priority, WaveBranch branch)
|
||||
{
|
||||
this.name = name;
|
||||
this.wave = wave;
|
||||
this.frequency = frequency;
|
||||
this.priority = priority;
|
||||
this.arena = arena;
|
||||
this.world = arena.getWorld();
|
||||
this.waveName = waveName;
|
||||
this.wave = wave;
|
||||
this.frequency = frequency;
|
||||
this.priority = priority;
|
||||
this.branch = branch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default wave constructor.
|
||||
* Constructs a basic wave with additional information in the type of
|
||||
* wave and the wave growth.
|
||||
* @param wave Initial wave number. This is the first wave number this wave can spawn at.
|
||||
* @param frequency How often the wave can spawn.
|
||||
* @param priority The priority of the wave.
|
||||
* @param type The type of wave.
|
||||
* @param growth The growth rate of the wave.
|
||||
*/
|
||||
public AbstractWave(String name, int wave, int frequency, int priority, WaveType type, WaveGrowth growth)
|
||||
|
||||
// Default recurrent wave constructor
|
||||
public AbstractWave(Arena arena, String name, int wave, int frequency, int priority)
|
||||
{
|
||||
this(name, wave, frequency, priority);
|
||||
this.type = type;
|
||||
this.growth = growth;
|
||||
this(arena, name, wave, frequency, priority, WaveBranch.RECURRENT);
|
||||
}
|
||||
|
||||
// Default single wave constructor
|
||||
public AbstractWave(Arena arena, String name, int wave)
|
||||
{
|
||||
this(arena, name, wave, 0, 0, WaveBranch.SINGLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a wave matches a wave number.
|
||||
* SINGLE WAVES match, if their wave number is the same as the
|
||||
* parameter.
|
||||
* RECURRENT WAVES match, if their wave number subtracted from
|
||||
* the parameter divides the frequency. The wave number must be
|
||||
* greater than or equal to the parameter.
|
||||
* @param wave The wave number to compare
|
||||
* @return true, if the wave matches the wave number
|
||||
*/
|
||||
public boolean matches(int wave)
|
||||
{
|
||||
if (branch == WaveBranch.SINGLE)
|
||||
return this.wave == wave;
|
||||
|
||||
if (branch == WaveBranch.RECURRENT && wave >= this.wave)
|
||||
return ((wave - this.wave) % frequency == 0);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// GETTERS
|
||||
public Arena getArena()
|
||||
{
|
||||
return arena;
|
||||
}
|
||||
|
||||
public World getWorld()
|
||||
{
|
||||
return world;
|
||||
}
|
||||
|
||||
public WaveBranch getBranch()
|
||||
{
|
||||
return branch;
|
||||
}
|
||||
|
||||
public WaveType getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(WaveType type)
|
||||
{
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public WaveGrowth getGrowth()
|
||||
{
|
||||
return growth;
|
||||
}
|
||||
|
||||
public void setGrowth(WaveGrowth growth)
|
||||
{
|
||||
this.growth = growth;
|
||||
}
|
||||
|
||||
public int getWave()
|
||||
{
|
||||
@@ -77,12 +109,29 @@ public abstract class AbstractWave implements Wave
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
return waveName;
|
||||
}
|
||||
|
||||
// SETTERS
|
||||
public void setBranch(WaveBranch branch)
|
||||
{
|
||||
this.branch = branch;
|
||||
}
|
||||
|
||||
public void setType(WaveType type)
|
||||
{
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public void setGrowth(WaveGrowth growth)
|
||||
{
|
||||
this.growth = growth;
|
||||
}
|
||||
|
||||
// MISC
|
||||
public String toString()
|
||||
{
|
||||
return "[name=" + name +
|
||||
return "[name=" + waveName +
|
||||
", wave=" + wave +
|
||||
", frequency=" + frequency +
|
||||
", priority=" + priority + "]";
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
package com.garbagemule.MobArena.waves;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Creature;
|
||||
|
||||
import com.garbagemule.MobArena.waves.Wave.BossAbility;
|
||||
|
||||
public class BossWave
|
||||
public class BossWave // TODO: implement/extend something?
|
||||
{
|
||||
private Creature boss;
|
||||
private Set<BossAbility> abilities;
|
||||
@@ -32,4 +34,17 @@ public class BossWave
|
||||
{
|
||||
this.health = health;
|
||||
}
|
||||
|
||||
public void spawn(int wave, Collection<Location> spawnpoints)
|
||||
{
|
||||
// Spawn boss and adds
|
||||
// Something like this, perhaps? Pseudo-code
|
||||
// LivingEntity b = spawnCreature(bossType, random location)
|
||||
// boss = (Creature) b;
|
||||
// boss.setHealth(health);
|
||||
// for (String a : ablts)
|
||||
// abilities.add(BossAbility.fromString(a));
|
||||
// for (int i = 0; i < addCount; i++)
|
||||
// adds.add(spawnCreature(addType, bossLocation);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
package com.garbagemule.MobArena.waves;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Creature;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.util.config.Configuration;
|
||||
|
||||
import com.garbagemule.MobArena.Arena;
|
||||
import com.garbagemule.MobArena.util.WaveUtils;
|
||||
|
||||
public class DefaultWave extends AbstractWave
|
||||
{
|
||||
private int totalProbability = 0;
|
||||
private Map<Integer,MACreature> probabilities = new TreeMap<Integer,MACreature>();
|
||||
|
||||
// Recurrent
|
||||
public DefaultWave(Arena arena, String name, int wave, int frequency, int priority, Configuration config, String path)
|
||||
{
|
||||
super(arena, name, wave, frequency, priority);
|
||||
load(config, path);
|
||||
}
|
||||
|
||||
// Single
|
||||
public DefaultWave(Arena arena, String name, int wave, Configuration config, String path)
|
||||
{
|
||||
super(arena, name, wave);
|
||||
load(config, path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the wave for spawning by initializing the variables and
|
||||
* populating the collections needed.
|
||||
* @param config The config-file
|
||||
* @param path The absolute path of the wave
|
||||
*/
|
||||
public void load(Configuration config, String path)
|
||||
{
|
||||
// Extract the monster probabilities and calculate the sum
|
||||
totalProbability = 0;
|
||||
int prob;
|
||||
for (String m : config.getKeys(path + "monsters"))
|
||||
{
|
||||
prob = config.getInt(path + "monsters." + m, 1);
|
||||
totalProbability += prob;
|
||||
probabilities.put(totalProbability, MACreature.fromString(m));
|
||||
}
|
||||
}
|
||||
|
||||
public void spawn(int wave)
|
||||
{
|
||||
// Get the valid spawnpoints, and initialize counter
|
||||
List<Location> validSpawnpoints = WaveUtils.getValidSpawnpoints(getArena().getSpawnpoints(), getArena().getLivingPlayers());
|
||||
int noOfSpawnpoints = validSpawnpoints.size();
|
||||
|
||||
// Initialize the total amount of mobs to spawn
|
||||
int totalToSpawn = getGrowth().getAmount(wave, getArena().getPlayerCount());
|
||||
|
||||
// Allocate some variables
|
||||
Random random = new Random();
|
||||
int randomNumber;
|
||||
Location loc;
|
||||
|
||||
// Spawn <totalToSpawn> monsters
|
||||
for (int i = 0; i < totalToSpawn; i++)
|
||||
{
|
||||
// Grab the next location.
|
||||
loc = validSpawnpoints.get(i % noOfSpawnpoints);
|
||||
|
||||
// Grab a random number.
|
||||
randomNumber = random.nextInt(totalProbability);
|
||||
|
||||
// Find the monster that corresponds to the random number, and spawn it
|
||||
for (Map.Entry<Integer,MACreature> entry : probabilities.entrySet())
|
||||
{
|
||||
if (randomNumber > entry.getKey()) continue;
|
||||
|
||||
// Spawn and add to collection
|
||||
LivingEntity e = entry.getValue().spawn(getWorld(), loc);
|
||||
getArena().addMonster(e);
|
||||
|
||||
// Grab a random target.
|
||||
if (e instanceof Creature)
|
||||
{
|
||||
Creature c = (Creature) e;
|
||||
c.setTarget(WaveUtils.getClosestPlayer(getArena(), e));
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("WAVE SPAWN! Wave: " + wave + ", name: " + getName() + ", type: " + getType());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package com.garbagemule.MobArena.waves;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.CreatureType;
|
||||
import org.bukkit.entity.Creeper;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Slime;
|
||||
import org.bukkit.entity.Wolf;
|
||||
|
||||
import com.garbagemule.MobArena.util.WaveUtils;
|
||||
|
||||
public enum MACreature
|
||||
{
|
||||
// Default creatures
|
||||
ZOMBIES(CreatureType.ZOMBIE),
|
||||
SKELETONS(CreatureType.SKELETON),
|
||||
SPIDERS(CreatureType.SPIDER),
|
||||
CREEPERS(CreatureType.CREEPER),
|
||||
WOLVES(CreatureType.WOLF),
|
||||
|
||||
// Special creatures
|
||||
ZOMBIE_PIGMEN(CreatureType.PIG_ZOMBIE),
|
||||
POWERED_CREEPERS(CreatureType.CREEPER),
|
||||
ANGRY_WOLVES(CreatureType.WOLF),
|
||||
HUMANS(CreatureType.MONSTER),
|
||||
SLIMES(CreatureType.SLIME),
|
||||
GIANTS(CreatureType.GIANT),
|
||||
GHASTS(CreatureType.GHAST);
|
||||
|
||||
// Misc
|
||||
// EXPLODING_SHEEP(CreatureType.SHEEP), // Explode (power: 1) when close enough to players
|
||||
// PLAGUED_PIGS(CreatureType.PIG), // Damage "aura" (getNearbyEntities)
|
||||
// MAD_COWS(CreatureType.COW); // Ram/throw players
|
||||
//
|
||||
|
||||
private CreatureType type;
|
||||
|
||||
private MACreature(CreatureType type)
|
||||
{
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public CreatureType getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
public static MACreature fromString(String string)
|
||||
{
|
||||
return WaveUtils.getEnumFromString(MACreature.class, string);
|
||||
}
|
||||
|
||||
public LivingEntity spawn(World world, Location loc)
|
||||
{
|
||||
LivingEntity e = world.spawnCreature(loc, type);
|
||||
|
||||
switch (this)
|
||||
{
|
||||
case POWERED_CREEPERS:
|
||||
((Creeper) e).setPowered(true);
|
||||
break;
|
||||
case ANGRY_WOLVES:
|
||||
((Wolf) e).setAngry(true);
|
||||
break;
|
||||
case SLIMES:
|
||||
((Slime) e).setSize(2);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
public static LivingEntity spawn(MACreature creature, World world, Location loc)
|
||||
{
|
||||
LivingEntity e = world.spawnCreature(loc, creature.type);
|
||||
|
||||
switch (creature)
|
||||
{
|
||||
case POWERED_CREEPERS:
|
||||
((Creeper) e).setPowered(true);
|
||||
break;
|
||||
case ANGRY_WOLVES:
|
||||
((Wolf) e).setAngry(true);
|
||||
break;
|
||||
case SLIMES:
|
||||
((Slime) e).setSize(2);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return e;
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ public class RecurrentWave extends AbstractWave
|
||||
|
||||
public RecurrentWave(String name, int wave, int frequency, int priority, WaveType type, WaveGrowth growth)
|
||||
{
|
||||
super(name, wave, frequency, priority, type, growth);
|
||||
super(name, wave, frequency, priority, WaveBranch.RECURRENT, type, growth);
|
||||
}
|
||||
|
||||
public void spawn(int wave, Collection<Location> spawnpoints)
|
||||
@@ -28,7 +28,10 @@ public class RecurrentWave extends AbstractWave
|
||||
|
||||
public boolean matches(int wave)
|
||||
{
|
||||
return wave % getWave() + getFrequency() == 0;
|
||||
if (wave < getWave())
|
||||
return false;
|
||||
|
||||
return (wave - getWave()) % getFrequency() == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -36,6 +39,7 @@ public class RecurrentWave extends AbstractWave
|
||||
* If the priorities are equal, the names are compared. This is to
|
||||
* ALLOW "duplicates" in the RECURRENT WAVES collection.
|
||||
*/
|
||||
/*
|
||||
public int compareTo(Wave w)
|
||||
{
|
||||
if (getPriority() < w.getPriority())
|
||||
@@ -44,4 +48,5 @@ public class RecurrentWave extends AbstractWave
|
||||
return 1;
|
||||
else return getName().compareTo(w.getName());
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ public class SingleWave extends AbstractWave
|
||||
public SingleWave(String name, int wave)
|
||||
{
|
||||
super(name, wave, 0, 0);
|
||||
setBranch(WaveBranch.SINGLE);
|
||||
}
|
||||
|
||||
public void spawn(int wave, Collection<Location> spawnpoints)
|
||||
@@ -26,6 +27,7 @@ public class SingleWave extends AbstractWave
|
||||
* If the wave numbers are equal, the waves are equal. This is to
|
||||
* DISALLOW "duplicates" in the SINGLE WAVES collection.
|
||||
*/
|
||||
/*
|
||||
public int compareTo(Wave w)
|
||||
{
|
||||
if (this.getWave() < w.getWave())
|
||||
@@ -34,4 +36,5 @@ public class SingleWave extends AbstractWave
|
||||
return 1;
|
||||
else return 0;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.garbagemule.MobArena.waves;
|
||||
|
||||
import com.garbagemule.MobArena.Arena;
|
||||
|
||||
public class SpecialWave extends AbstractWave
|
||||
{
|
||||
// Recurrent
|
||||
public SpecialWave(Arena arena, String name, int wave, int frequency, int priority)
|
||||
{
|
||||
super(arena, name, wave, frequency, priority);
|
||||
}
|
||||
|
||||
// Single
|
||||
public SpecialWave(Arena arena, String name, int wave)
|
||||
{
|
||||
super(arena, name, wave);
|
||||
}
|
||||
|
||||
public void spawn(int wave)
|
||||
{
|
||||
System.out.println("WAVE SPAWN! Wave: " + wave + ", name: " + getName() + ", type: " + getType());
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,8 @@
|
||||
package com.garbagemule.MobArena.waves;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
import com.garbagemule.MobArena.util.WaveUtils;
|
||||
|
||||
public interface Wave extends Comparable<Wave>
|
||||
public interface Wave
|
||||
{
|
||||
public enum WaveBranch
|
||||
{
|
||||
@@ -25,11 +21,28 @@ public interface Wave extends Comparable<Wave>
|
||||
|
||||
public enum WaveGrowth
|
||||
{
|
||||
SLOW, MEDIUM, FAST;
|
||||
|
||||
OLD(0), SLOW(0.5), MEDIUM(0.65), FAST(0.8), PSYCHO(1.1);
|
||||
private double exp;
|
||||
|
||||
private WaveGrowth(double exp)
|
||||
{
|
||||
this.exp = exp;
|
||||
}
|
||||
|
||||
public static WaveGrowth fromString(String string)
|
||||
{
|
||||
return WaveUtils.getEnumFromString(WaveGrowth.class, string, MEDIUM);
|
||||
return WaveUtils.getEnumFromString(WaveGrowth.class, string, OLD);
|
||||
}
|
||||
|
||||
public int getAmount(int wave, int playerCount)
|
||||
{
|
||||
if (this == OLD) return wave + playerCount;
|
||||
|
||||
double pc = (double) playerCount;
|
||||
double w = (double) wave;
|
||||
|
||||
double base = Math.min(Math.ceil(pc/2) + 1, 13);
|
||||
return (int) ( base * Math.pow(w, exp) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +82,7 @@ public interface Wave extends Comparable<Wave>
|
||||
* be modified by the wave parameter.
|
||||
* @param wave Wave number
|
||||
*/
|
||||
public void spawn(int wave, Collection<Location> spawnpoints);
|
||||
public void spawn(int wave);
|
||||
|
||||
/**
|
||||
* Get the type of wave.
|
||||
@@ -106,6 +119,12 @@ public interface Wave extends Comparable<Wave>
|
||||
* @return The name
|
||||
*/
|
||||
public String getName();
|
||||
|
||||
/**
|
||||
* Set the wave's growth
|
||||
* @param growth How fast the wave will grow
|
||||
*/
|
||||
public void setGrowth(WaveGrowth growth);
|
||||
|
||||
/**
|
||||
* Check if this wave matches the wave number.
|
||||
|
||||
@@ -3,27 +3,121 @@ package com.garbagemule.register.payment;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
/**
|
||||
* Method.java
|
||||
* Interface for all sub-methods for payment.
|
||||
* Interface to be implemented by a payment method.
|
||||
*
|
||||
* @author: Nijikokun<nijikokun@gmail.com> (@nijikokun)
|
||||
* @copyright: Copyright (C) 2011
|
||||
* @license: GNUv3 Affero License <http://www.gnu.org/licenses/agpl-3.0.html>
|
||||
* @author Nijikokun <nijikokun@shortmail.com> (@nijikokun)
|
||||
* @copyright Copyright (C) 2011
|
||||
* @license AOL license <http://aol.nexua.org>
|
||||
*/
|
||||
public interface Method {
|
||||
/**
|
||||
* Encodes the Plugin into an Object disguised as the Plugin.
|
||||
* If you want the original Plugin Class you must cast it to the correct
|
||||
* Plugin, to do so you have to verify the name and or version then cast.
|
||||
*
|
||||
* <pre>
|
||||
* if(method.getName().equalsIgnoreCase("iConomy"))
|
||||
* iConomy plugin = ((iConomy)method.getPlugin());</pre>
|
||||
*
|
||||
* @return <code>Object</code>
|
||||
* @see #getName()
|
||||
* @see #getVersion()
|
||||
*/
|
||||
public Object getPlugin();
|
||||
|
||||
/**
|
||||
* Returns the actual name of this method.
|
||||
*
|
||||
* @return <code>String</code> Plugin name.
|
||||
*/
|
||||
public String getName();
|
||||
|
||||
/**
|
||||
* Returns the actual version of this method.
|
||||
*
|
||||
* @return <code>String</code> Plugin version.
|
||||
*/
|
||||
public String getVersion();
|
||||
|
||||
|
||||
/**
|
||||
* Formats amounts into this payment methods style of currency display.
|
||||
*
|
||||
* @param amount Double
|
||||
* @return <code>String</code> - Formatted Currency Display.
|
||||
*/
|
||||
public String format(double amount);
|
||||
|
||||
/**
|
||||
* Allows the verification of bank API existence in this payment method.
|
||||
*
|
||||
* @return <code>boolean</code>
|
||||
*/
|
||||
public boolean hasBanks();
|
||||
|
||||
/**
|
||||
* Determines the existence of a bank via name.
|
||||
*
|
||||
* @param bank Bank name
|
||||
* @return <code>boolean</code>
|
||||
* @see #hasBanks
|
||||
*/
|
||||
public boolean hasBank(String bank);
|
||||
|
||||
/**
|
||||
* Determines the existence of an account via name.
|
||||
*
|
||||
* @param name Account name
|
||||
* @return <code>boolean</code>
|
||||
*/
|
||||
public boolean hasAccount(String name);
|
||||
|
||||
/**
|
||||
* Check to see if an account <code>name</code> is tied to a <code>bank</code>.
|
||||
*
|
||||
* @param bank Bank name
|
||||
* @param name Account name
|
||||
* @return <code>boolean</code>
|
||||
*/
|
||||
public boolean hasBankAccount(String bank, String name);
|
||||
|
||||
/**
|
||||
* Returns a <code>MethodAccount</code> class for an account <code>name</code>.
|
||||
*
|
||||
* @param name Account name
|
||||
* @return <code>MethodAccount</code> <em>or</em> <code>Null</code>
|
||||
*/
|
||||
public MethodAccount getAccount(String name);
|
||||
|
||||
|
||||
/**
|
||||
* Returns a <code>MethodBankAccount</code> class for an account <code>name</code>.
|
||||
*
|
||||
* @param bank Bank name
|
||||
* @param name Account name
|
||||
* @return <code>MethodBankAccount</code> <em>or</em> <code>Null</code>
|
||||
*/
|
||||
public MethodBankAccount getBankAccount(String bank, String name);
|
||||
|
||||
/**
|
||||
* Checks to verify the compatibility between this Method and a plugin.
|
||||
* Internal usage only, for the most part.
|
||||
*
|
||||
* @param plugin Plugin
|
||||
* @return <code>boolean</code>
|
||||
*/
|
||||
public boolean isCompatible(Plugin plugin);
|
||||
|
||||
/**
|
||||
* Set Plugin data.
|
||||
*
|
||||
* @param plugin Plugin
|
||||
*/
|
||||
public void setPlugin(Plugin plugin);
|
||||
|
||||
/**
|
||||
* Contains Calculator and Balance functions for Accounts.
|
||||
*/
|
||||
public interface MethodAccount {
|
||||
public double balance();
|
||||
public boolean set(double amount);
|
||||
@@ -41,6 +135,9 @@ public interface Method {
|
||||
public String toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Contains Calculator and Balance functions for Bank Accounts.
|
||||
*/
|
||||
public interface MethodBankAccount {
|
||||
public double balance();
|
||||
public String getBankName();
|
||||
|
||||
@@ -1,21 +1,31 @@
|
||||
package com.garbagemule.register.payment;
|
||||
|
||||
import com.garbagemule.register.payment.methods.BOSE6;
|
||||
import com.garbagemule.register.payment.methods.BOSE7;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
/**
|
||||
* Methods.java
|
||||
* Controls the getting / setting of methods & the method of payment used.
|
||||
* The <code>Methods</code> initializes Methods that utilize the Method interface
|
||||
* based on a "first come, first served" basis.
|
||||
*
|
||||
* @author: Nijikokun<[email protected]> (@nijikokun)
|
||||
* Allowing you to check whether a payment method exists or not.
|
||||
*
|
||||
* <blockquote><pre>
|
||||
* Methods methods = new Methods();
|
||||
* </pre></blockquote>
|
||||
*
|
||||
* Methods also allows you to set a preferred method of payment before it captures
|
||||
* payment plugins in the initialization process.
|
||||
*
|
||||
* <blockquote><pre>
|
||||
* Methods methods = new Methods("iConomy");
|
||||
* </pre></blockquote>
|
||||
*
|
||||
* @author: Nijikokun <[email protected]> (@nijikokun)
|
||||
* @copyright: Copyright (C) 2011
|
||||
* @license: GNUv3 Affero License <http://www.gnu.org/licenses/agpl-3.0.html>
|
||||
* @license: AOL license <http://aol.nexua.org>
|
||||
*/
|
||||
public class Methods {
|
||||
private boolean self = false;
|
||||
@@ -25,14 +35,18 @@ public class Methods {
|
||||
private Set<String> Dependencies = new HashSet<String>();
|
||||
private Set<Method> Attachables = new HashSet<Method>();
|
||||
|
||||
/**
|
||||
* Initialize Method class
|
||||
*/
|
||||
public Methods() {
|
||||
this._init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows you to set which economy plugin is most preferred.
|
||||
* Initializes <code>Methods</code> class utilizing a "preferred" payment method check before
|
||||
* returning the first method that was initialized.
|
||||
*
|
||||
* @param preferred - preferred economy plugin
|
||||
* @param preferred Payment method that is most preferred for this setup.
|
||||
*/
|
||||
public Methods(String preferred) {
|
||||
this._init();
|
||||
@@ -42,18 +56,40 @@ public class Methods {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement all methods along with their respective name & class.
|
||||
*
|
||||
* @see #Methods()
|
||||
* @see #Methods(java.lang.String)
|
||||
*/
|
||||
private void _init() {
|
||||
this.addMethod("iConomy", new com.garbagemule.register.payment.methods.iCo4());
|
||||
this.addMethod("iConomy", new com.garbagemule.register.payment.methods.iCo6());
|
||||
this.addMethod("iConomy", new com.garbagemule.register.payment.methods.iCo5());
|
||||
this.addMethod("BOSEconomy", new BOSE6());
|
||||
this.addMethod("BOSEconomy", new BOSE7());
|
||||
this.addMethod("iConomy", new com.garbagemule.register.payment.methods.iCo4());
|
||||
this.addMethod("BOSEconomy", new com.garbagemule.register.payment.methods.BOSE6());
|
||||
this.addMethod("BOSEconomy", new com.garbagemule.register.payment.methods.BOSE7());
|
||||
this.addMethod("Essentials", new com.garbagemule.register.payment.methods.EE17());
|
||||
this.addMethod("MultiCurrency", new com.garbagemule.register.payment.methods.MCUR());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of payment method names that have been loaded
|
||||
* through the <code>_init</code> method.
|
||||
*
|
||||
* @return <code>Set<String></code> - Array of payment methods that are loaded.
|
||||
* @see #setMethod(org.bukkit.plugin.Plugin)
|
||||
*/
|
||||
public Set<String> getDependencies() {
|
||||
return Dependencies;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interprets Plugin class data to verify whether it is compatible with an existing payment
|
||||
* method to use for payments and other various economic activity.
|
||||
*
|
||||
* @param plugin Plugin data from bukkit, Internal Class file.
|
||||
* @return Method <em>or</em> Null
|
||||
*/
|
||||
public Method createMethod(Plugin plugin) {
|
||||
for (Method method: Methods) {
|
||||
if (method.isCompatible(plugin)) {
|
||||
@@ -70,17 +106,31 @@ public class Methods {
|
||||
Methods.add(method);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies if Register has set a payment method for usage yet.
|
||||
*
|
||||
* @return <code>boolean</code>
|
||||
* @see #setMethod(org.bukkit.plugin.Plugin)
|
||||
* @see #checkDisabled(org.bukkit.plugin.Plugin)
|
||||
*/
|
||||
public boolean hasMethod() {
|
||||
return (Method != null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks Plugin Class against a multitude of checks to verify it's usability
|
||||
* as a payment method.
|
||||
*
|
||||
* @param method Plugin data from bukkit, Internal Class file.
|
||||
* @return <code>boolean</code> True on success, False on failure.
|
||||
*/
|
||||
public boolean setMethod(Plugin method) {
|
||||
if(hasMethod()) return true;
|
||||
if(self) { self = false; return false; }
|
||||
|
||||
int count = 0;
|
||||
boolean match = false;
|
||||
Plugin plugin;
|
||||
Plugin plugin = null;
|
||||
PluginManager manager = method.getServer().getPluginManager();
|
||||
|
||||
for(String name: this.getDependencies()) {
|
||||
@@ -129,10 +179,22 @@ public class Methods {
|
||||
return hasMethod();
|
||||
}
|
||||
|
||||
/**
|
||||
* Grab the existing and initialized (hopefully) Method Class.
|
||||
*
|
||||
* @return <code>Method</code> <em>or</em> <code>Null</code>
|
||||
*/
|
||||
public Method getMethod() {
|
||||
return Method;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify is a plugin is disabled, only does this if we there is an existing payment
|
||||
* method initialized in Register.
|
||||
*
|
||||
* @param method Plugin data from bukkit, Internal Class file.
|
||||
* @return <code>boolean</code>
|
||||
*/
|
||||
public boolean checkDisabled(Plugin method) {
|
||||
if(!hasMethod()) return true;
|
||||
if (Method.isCompatible(method)) Method = null;
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
package com.garbagemule.register.payment.methods;
|
||||
|
||||
import com.garbagemule.register.payment.Method;
|
||||
|
||||
import cosine.boseconomy.BOSEconomy;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
/**
|
||||
* BOSEconomy 6 Implementation of Method
|
||||
*
|
||||
* @author Nijikokun <[email protected]> (@nijikokun)
|
||||
* @copyright (c) 2011
|
||||
* @license AOL license <http://aol.nexua.org>
|
||||
*/
|
||||
public class BOSE6 implements Method {
|
||||
private BOSEconomy BOSEconomy;
|
||||
|
||||
@@ -61,8 +67,8 @@ public class BOSE6 implements Method {
|
||||
}
|
||||
|
||||
public class BOSEAccount implements MethodAccount {
|
||||
private String name;
|
||||
private BOSEconomy BOSEconomy;
|
||||
private final String name;
|
||||
private final BOSEconomy BOSEconomy;
|
||||
|
||||
public BOSEAccount(String name, BOSEconomy bOSEconomy) {
|
||||
this.name = name;
|
||||
@@ -70,7 +76,7 @@ public class BOSE6 implements Method {
|
||||
}
|
||||
|
||||
public double balance() {
|
||||
return Double.valueOf(this.BOSEconomy.getPlayerMoney(this.name));
|
||||
return (double) this.BOSEconomy.getPlayerMoney(this.name);
|
||||
}
|
||||
|
||||
public boolean set(double amount) {
|
||||
@@ -123,8 +129,8 @@ public class BOSE6 implements Method {
|
||||
}
|
||||
|
||||
public class BOSEBankAccount implements MethodBankAccount {
|
||||
private String bank;
|
||||
private BOSEconomy BOSEconomy;
|
||||
private final String bank;
|
||||
private final BOSEconomy BOSEconomy;
|
||||
|
||||
public BOSEBankAccount(String bank, BOSEconomy bOSEconomy) {
|
||||
this.bank = bank;
|
||||
@@ -140,7 +146,7 @@ public class BOSE6 implements Method {
|
||||
}
|
||||
|
||||
public double balance() {
|
||||
return Double.valueOf(this.BOSEconomy.getBankMoney(bank));
|
||||
return (double) this.BOSEconomy.getBankMoney(bank);
|
||||
}
|
||||
|
||||
public boolean set(double amount) {
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
package com.garbagemule.register.payment.methods;
|
||||
|
||||
import com.garbagemule.register.payment.Method;
|
||||
|
||||
import cosine.boseconomy.BOSEconomy;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
/**
|
||||
* BOSEconomy 7 Implementation of Method
|
||||
*
|
||||
* @author Acrobot
|
||||
* @author Nijikokun <[email protected]> (@nijikokun)
|
||||
* @copyright (c) 2011
|
||||
* @license AOL license <http://aol.nexua.org>
|
||||
*/
|
||||
|
||||
public class BOSE7 implements Method {
|
||||
private BOSEconomy BOSEconomy;
|
||||
|
||||
|
||||
@@ -4,11 +4,21 @@ import com.earth2me.essentials.Essentials;
|
||||
import com.earth2me.essentials.api.Economy;
|
||||
import com.earth2me.essentials.api.NoLoanPermittedException;
|
||||
import com.earth2me.essentials.api.UserDoesNotExistException;
|
||||
import com.garbagemule.register.payment.Method;
|
||||
|
||||
import com.garbagemule.register.payment.Method;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
/**
|
||||
* Essentials 17 Implementation of Method
|
||||
*
|
||||
* @author Nijikokun <[email protected]> (@nijikokun)
|
||||
* @author Snowleo
|
||||
* @author Acrobot
|
||||
* @author KHobbits
|
||||
* @copyright (c) 2011
|
||||
* @license AOL license <http://aol.nexua.org>
|
||||
*/
|
||||
public class EE17 implements Method {
|
||||
private Essentials Essentials;
|
||||
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
package com.garbagemule.register.payment.methods;
|
||||
|
||||
import com.garbagemule.register.payment.Method;
|
||||
|
||||
import me.ashtheking.currency.Currency;
|
||||
import me.ashtheking.currency.CurrencyList;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
/**
|
||||
* MultiCurrency Method implementation.
|
||||
*
|
||||
* @author Acrobot
|
||||
* @copyright (c) 2011
|
||||
* @license AOL license <http://aol.nexua.org>
|
||||
*/
|
||||
public class MCUR implements Method {
|
||||
private Currency currencyList;
|
||||
|
||||
public Object getPlugin() {
|
||||
return this.currencyList;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "MultiCurrency";
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return "0.09";
|
||||
}
|
||||
|
||||
public String format(double amount) {
|
||||
return amount + " Currency";
|
||||
}
|
||||
|
||||
public boolean hasBanks() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasBank(String bank) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasAccount(String name) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean hasBankAccount(String bank, String name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public MethodAccount getAccount(String name) {
|
||||
return new MCurrencyAccount(name);
|
||||
}
|
||||
|
||||
public MethodBankAccount getBankAccount(String bank, String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isCompatible(Plugin plugin) {
|
||||
return plugin.getDescription().getName().equalsIgnoreCase(getName()) && plugin instanceof Currency;
|
||||
}
|
||||
|
||||
public void setPlugin(Plugin plugin) {
|
||||
currencyList = (Currency) plugin;
|
||||
}
|
||||
|
||||
public class MCurrencyAccount implements MethodAccount{
|
||||
private String name;
|
||||
|
||||
public MCurrencyAccount(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public double balance() {
|
||||
return CurrencyList.getValue((String) CurrencyList.maxCurrency(name)[0], name);
|
||||
}
|
||||
|
||||
public boolean set(double amount) {
|
||||
CurrencyList.setValue((String) CurrencyList.maxCurrency(name)[0], name, amount);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean add(double amount) {
|
||||
return CurrencyList.add(name, amount);
|
||||
}
|
||||
|
||||
public boolean subtract(double amount) {
|
||||
return CurrencyList.subtract(name, amount);
|
||||
}
|
||||
|
||||
public boolean multiply(double amount) {
|
||||
return CurrencyList.multiply(name, amount);
|
||||
}
|
||||
|
||||
public boolean divide(double amount) {
|
||||
return CurrencyList.divide(name, amount);
|
||||
}
|
||||
|
||||
public boolean hasEnough(double amount) {
|
||||
return CurrencyList.hasEnough(name, amount);
|
||||
}
|
||||
|
||||
public boolean hasOver(double amount) {
|
||||
return CurrencyList.hasOver(name, amount);
|
||||
}
|
||||
|
||||
public boolean hasUnder(double amount) {
|
||||
return CurrencyList.hasUnder(name, amount);
|
||||
}
|
||||
|
||||
public boolean isNegative() {
|
||||
return CurrencyList.isNegative(name);
|
||||
}
|
||||
|
||||
public boolean remove() {
|
||||
return CurrencyList.remove(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,19 @@
|
||||
package com.garbagemule.register.payment.methods;
|
||||
|
||||
import com.garbagemule.register.payment.Method;
|
||||
import com.nijiko.coelho.iConomy.iConomy;
|
||||
import com.nijiko.coelho.iConomy.system.Account;
|
||||
|
||||
import com.garbagemule.register.payment.Method;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
/**
|
||||
* iConomy 4 Implementation of Method
|
||||
*
|
||||
* @author Nijikokun <[email protected]> (@nijikokun)
|
||||
* @copyright (c) 2011
|
||||
* @license AOL license <http://aol.nexua.org>
|
||||
*/
|
||||
public class iCo4 implements Method {
|
||||
private iConomy iConomy;
|
||||
|
||||
@@ -51,7 +58,7 @@ public class iCo4 implements Method {
|
||||
}
|
||||
|
||||
public boolean isCompatible(Plugin plugin) {
|
||||
return plugin.getDescription().getName().equalsIgnoreCase("iconomy") && !plugin.getClass().getName().equals("com.iConomy.iConomy") && plugin instanceof iConomy;
|
||||
return plugin.getDescription().getName().equalsIgnoreCase("iconomy") && plugin.getClass().getName().equals("com.nijiko.coelho.iConomy.iConomy") && plugin instanceof iConomy;
|
||||
}
|
||||
|
||||
public void setPlugin(Plugin plugin) {
|
||||
|
||||
@@ -1,15 +1,22 @@
|
||||
package com.garbagemule.register.payment.methods;
|
||||
|
||||
import com.garbagemule.register.payment.Method;
|
||||
import com.iConomy.iConomy;
|
||||
import com.iConomy.system.Account;
|
||||
import com.iConomy.system.BankAccount;
|
||||
import com.iConomy.system.Holdings;
|
||||
import com.iConomy.util.Constants;
|
||||
|
||||
import com.garbagemule.register.payment.Method;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
/**
|
||||
* iConomy 5 Implementation of Method
|
||||
*
|
||||
* @author Nijikokun <[email protected]> (@nijikokun)
|
||||
* @copyright (c) 2011
|
||||
* @license AOL license <http://aol.nexua.org>
|
||||
*/
|
||||
public class iCo5 implements Method {
|
||||
private iConomy iConomy;
|
||||
|
||||
@@ -34,7 +41,7 @@ public class iCo5 implements Method {
|
||||
}
|
||||
|
||||
public boolean hasBank(String bank) {
|
||||
return (!hasBanks()) ? false : this.iConomy.Banks.exists(bank);
|
||||
return (hasBanks()) && this.iConomy.Banks.exists(bank);
|
||||
}
|
||||
|
||||
public boolean hasAccount(String name) {
|
||||
@@ -42,7 +49,7 @@ public class iCo5 implements Method {
|
||||
}
|
||||
|
||||
public boolean hasBankAccount(String bank, String name) {
|
||||
return (!hasBank(bank)) ? false : this.iConomy.getBank(bank).hasAccount(name);
|
||||
return (hasBank(bank)) && this.iConomy.getBank(bank).hasAccount(name);
|
||||
}
|
||||
|
||||
public MethodAccount getAccount(String name) {
|
||||
@@ -52,7 +59,7 @@ public class iCo5 implements Method {
|
||||
public MethodBankAccount getBankAccount(String bank, String name) {
|
||||
return new iCoBankAccount(this.iConomy.getBank(bank).getAccount(name));
|
||||
}
|
||||
|
||||
|
||||
public boolean isCompatible(Plugin plugin) {
|
||||
return plugin.getDescription().getName().equalsIgnoreCase("iconomy") && plugin.getClass().getName().equals("com.iConomy.iConomy") && plugin instanceof iConomy;
|
||||
}
|
||||
@@ -208,4 +215,4 @@ public class iCo5 implements Method {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
package com.garbagemule.register.payment.methods;
|
||||
|
||||
import com.iCo6.iConomy;
|
||||
import com.iCo6.system.Account;
|
||||
import com.iCo6.system.Accounts;
|
||||
import com.iCo6.system.Holdings;
|
||||
|
||||
import com.garbagemule.register.payment.Method;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
/**
|
||||
* iConomy 6 Implementation of Method
|
||||
*
|
||||
* @author Nijikokun <[email protected]> (@nijikokun)
|
||||
* @copyright (c) 2011
|
||||
* @license AOL license <http://aol.nexua.org>
|
||||
*/
|
||||
public class iCo6 implements Method {
|
||||
private iConomy iConomy;
|
||||
|
||||
public iConomy getPlugin() {
|
||||
return this.iConomy;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "iConomy";
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return "6";
|
||||
}
|
||||
|
||||
public String format(double amount) {
|
||||
return this.iConomy.format(amount);
|
||||
}
|
||||
|
||||
public boolean hasBanks() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasBank(String bank) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasAccount(String name) {
|
||||
return (new Accounts()).exists(name);
|
||||
}
|
||||
|
||||
public boolean hasBankAccount(String bank, String name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public MethodAccount getAccount(String name) {
|
||||
return new iCoAccount((new Accounts()).get(name));
|
||||
}
|
||||
|
||||
public MethodBankAccount getBankAccount(String bank, String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isCompatible(Plugin plugin) {
|
||||
try { Class.forName("com.iCo6.IO"); }
|
||||
catch(Exception e) { return false; }
|
||||
|
||||
return plugin.getDescription().getName().equalsIgnoreCase("iconomy") && plugin.getClass().getName().equals("com.iCo6.iConomy") && plugin instanceof iConomy;
|
||||
}
|
||||
|
||||
public void setPlugin(Plugin plugin) {
|
||||
iConomy = (iConomy)plugin;
|
||||
}
|
||||
|
||||
public class iCoAccount implements MethodAccount {
|
||||
private Account account;
|
||||
private Holdings holdings;
|
||||
|
||||
public iCoAccount(Account account) {
|
||||
this.account = account;
|
||||
this.holdings = account.getHoldings();
|
||||
}
|
||||
|
||||
public Account getiCoAccount() {
|
||||
return account;
|
||||
}
|
||||
|
||||
public double balance() {
|
||||
return this.holdings.getBalance();
|
||||
}
|
||||
|
||||
public boolean set(double amount) {
|
||||
if(this.holdings == null) return false;
|
||||
this.holdings.setBalance(amount);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean add(double amount) {
|
||||
if(this.holdings == null) return false;
|
||||
this.holdings.add(amount);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean subtract(double amount) {
|
||||
if(this.holdings == null) return false;
|
||||
this.holdings.subtract(amount);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean multiply(double amount) {
|
||||
if(this.holdings == null) return false;
|
||||
this.holdings.multiply(amount);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean divide(double amount) {
|
||||
if(this.holdings == null) return false;
|
||||
this.holdings.divide(amount);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean hasEnough(double amount) {
|
||||
return this.holdings.hasEnough(amount);
|
||||
}
|
||||
|
||||
public boolean hasOver(double amount) {
|
||||
return this.holdings.hasOver(amount);
|
||||
}
|
||||
|
||||
public boolean hasUnder(double amount) {
|
||||
return this.holdings.hasUnder(amount);
|
||||
}
|
||||
|
||||
public boolean isNegative() {
|
||||
return this.holdings.isNegative();
|
||||
}
|
||||
|
||||
public boolean remove() {
|
||||
if(this.account == null) return false;
|
||||
this.account.remove();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user