mirror of
https://github.com/garbagemule/MobArena.git
synced 2024-11-23 19:16:41 +01:00
commit
62c78cc0d2
@ -1,8 +1,8 @@
|
||||
name: MobArena
|
||||
author: garbagemule
|
||||
main: com.garbagemule.MobArena.MobArena
|
||||
version: 0.94.4.75
|
||||
softdepend: [Spout,MultiVerse,XcraftGate,Towny,Heroes,MagicSpells,Vault]
|
||||
version: 0.94.4.78
|
||||
softdepend: [Spout,MultiVerse,MultiWorld,XcraftGate,Towny,Heroes,MagicSpells,Vault]
|
||||
commands:
|
||||
ma:
|
||||
description: Base command for MobArena
|
||||
|
@ -148,7 +148,7 @@ public class ArenaImpl implements Arena
|
||||
// Classes, items and permissions
|
||||
this.classes = plugin.getArenaMaster().getClasses();
|
||||
this.attachments = new HashMap<Player,PermissionAttachment>();
|
||||
this.limitManager = new ClassLimitManager(this, classes);
|
||||
this.limitManager = new ClassLimitManager(this, classes, new ConfigSection(config, "arenas." + name + ".class-limits"));
|
||||
|
||||
// Blocks and pets
|
||||
this.repairQueue = new PriorityBlockingQueue<Repairable>(100, new RepairableComparator());
|
||||
@ -729,8 +729,7 @@ public class ArenaImpl implements Arena
|
||||
p.getInventory().removeItem(new ItemStack(Material.BONE, petAmount));
|
||||
|
||||
for (int i = 0; i < petAmount; i++) {
|
||||
Wolf wolf = (Wolf) world.spawnCreature(p.getLocation(), EntityType.WOLF);
|
||||
//Wolf wolf = (Wolf) world.spawnCreature(p.getLocation(), CreatureType.WOLF);
|
||||
Wolf wolf = (Wolf) world.spawnEntity(p.getLocation(), EntityType.WOLF);
|
||||
wolf.setTamed(true);
|
||||
wolf.setOwner(p);
|
||||
wolf.setHealth(wolf.getMaxHealth());
|
||||
|
@ -139,6 +139,14 @@ public class ArenaListener
|
||||
}
|
||||
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
// Check if the block is a sign, it might be a leaderboard
|
||||
if (event.getBlock() instanceof Sign) {
|
||||
// If the sign is the leaderboard sign, null out the config
|
||||
if (event.getBlock().getLocation().equals(arena.getRegion().getLeaderboard())) {
|
||||
arena.getRegion().set("leaderboard", null);
|
||||
}
|
||||
}
|
||||
|
||||
if (!arena.getRegion().contains(event.getBlock().getLocation()))
|
||||
return;
|
||||
|
||||
@ -631,9 +639,13 @@ public class ArenaListener
|
||||
for (PotionEffect effect : potion.getEffects()) {
|
||||
PotionEffectType type = effect.getType();
|
||||
if (type.equals(PotionEffectType.HARM) || type.equals(PotionEffectType.POISON)) {
|
||||
for (Player p : arena.getPlayersInArena()) {
|
||||
event.setIntensity(p, 0D);
|
||||
Set<LivingEntity> players = new HashSet<LivingEntity>();
|
||||
for (LivingEntity le : event.getAffectedEntities()) {
|
||||
if (le instanceof Player) {
|
||||
players.add(le);
|
||||
}
|
||||
}
|
||||
event.getAffectedEntities().removeAll(players);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -794,29 +806,39 @@ public class ArenaListener
|
||||
|
||||
// If they already had a class, make sure to change the "in use" in the Class Limit Manager
|
||||
if (oldAC != null) {
|
||||
p.sendMessage("already had a class");
|
||||
// If they picked the same sign, don't do anything
|
||||
// If they picked the same class, don't do anything
|
||||
if (oldAC.equals(newAC)) {
|
||||
p.sendMessage("picked the same class");
|
||||
return;
|
||||
}
|
||||
System.out.println("decrementing the classesInUse of " + oldAC.getName());
|
||||
classLimits.playerLeftClass(oldAC);
|
||||
// If they can join the class, decrement the previous class's count
|
||||
if (canPlayerJoinClass(newAC, p)) {
|
||||
classLimits.playerLeftClass(oldAC);
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// If they can not join the class, deny them
|
||||
if (!classLimits.canPlayerJoinClass(newAC)) {
|
||||
Messenger.tellPlayer(p, Msg.LOBBY_CLASS_FULL);
|
||||
return;
|
||||
else {
|
||||
if (!canPlayerJoinClass(newAC, p)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Increment the "in use" in the Class Limit Manager
|
||||
System.out.println("incrementing the classesInUse of " + newAC.getName());
|
||||
classLimits.playerPickedClass(newAC);
|
||||
|
||||
// Delay the inventory stuff to ensure that right-clicking works.
|
||||
delayAssignClass(p, className);
|
||||
}
|
||||
|
||||
private boolean canPlayerJoinClass(ArenaClass ac, Player p) {
|
||||
// If they can not join the class, deny them
|
||||
if (!classLimits.canPlayerJoinClass(ac)) {
|
||||
Messenger.tellPlayer(p, Msg.LOBBY_CLASS_FULL);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Increment the "in use" in the Class Limit Manager
|
||||
classLimits.playerPickedClass(ac);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void delayAssignClass(final Player p, final String className) {
|
||||
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin,new Runnable() {
|
||||
@ -873,6 +895,11 @@ public class ArenaListener
|
||||
Player p = event.getPlayer();
|
||||
|
||||
if (region.contains(from)) {
|
||||
// Players with proper admin permission can warp out
|
||||
if (p.hasPermission("mobarena.admin.teleport")) {
|
||||
return TeleportResponse.ALLOW;
|
||||
}
|
||||
|
||||
// Players not in the arena are free to warp out.
|
||||
if (!arena.inArena(p) && !arena.inLobby(p) && !arena.inSpec(p)) {
|
||||
return TeleportResponse.ALLOW;
|
||||
@ -887,6 +914,11 @@ public class ArenaListener
|
||||
return TeleportResponse.REJECT;
|
||||
}
|
||||
else if (region.contains(to)) {
|
||||
// Players with proper admin permission can warp in
|
||||
if (p.hasPermission("mobarena.admin.teleport")) {
|
||||
return TeleportResponse.ALLOW;
|
||||
}
|
||||
|
||||
if (region.isWarp(from) || region.isWarp(to) || to.equals(arena.getPlayerEntry(p))) {
|
||||
return TeleportResponse.ALLOW;
|
||||
}
|
||||
|
@ -14,14 +14,10 @@ public class ClassLimitManager
|
||||
private MobArena plugin;
|
||||
private Map<String, ArenaClass> classes;
|
||||
|
||||
public ClassLimitManager(Arena arena, Map<String, ArenaClass> classes) {
|
||||
public ClassLimitManager(Arena arena, Map<String, ArenaClass> classes, ConfigSection limits) {
|
||||
this.plugin = arena.getPlugin();
|
||||
ConfigUtils.addMissingNodes(plugin, plugin.getMAConfig(), "arenas." + arena.configName() + ".class-limits", "class-limits.yml");
|
||||
this.limits = new ConfigSection(plugin.getMAConfig(), "arenas." + arena.configName() + ".class-limits");
|
||||
//TODO figure out why limits is not loading the proper values from the config
|
||||
//TODO perhaps send along the limits config section from the ArenaImpl class?
|
||||
//TODO try to use ArenaRegion's config stuff to set up CLM properly
|
||||
|
||||
this.limits = limits;
|
||||
this.classes = classes;
|
||||
this.classLimits = new HashMap<ArenaClass, Integer>();
|
||||
this.classesInUse = new HashMap<ArenaClass, Integer>();
|
||||
@ -48,7 +44,6 @@ public class ClassLimitManager
|
||||
*/
|
||||
public void playerPickedClass(ArenaClass ac) {
|
||||
classesInUse.put(ac, classesInUse.get(ac) + 1);
|
||||
debug();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -57,7 +52,6 @@ public class ClassLimitManager
|
||||
*/
|
||||
public void playerLeftClass(ArenaClass ac) {
|
||||
classesInUse.put(ac, classesInUse.get(ac) - 1);
|
||||
debug();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -66,7 +60,12 @@ public class ClassLimitManager
|
||||
* @return true/false
|
||||
*/
|
||||
public boolean canPlayerJoinClass(ArenaClass ac) {
|
||||
debug();
|
||||
if (classLimits.get(ac) == null) {
|
||||
limits.set(ac.getName(), -1);
|
||||
classLimits.put(ac, -1);
|
||||
classesInUse.put(ac, 0);
|
||||
}
|
||||
|
||||
if (classLimits.get(ac) <= -1)
|
||||
return true;
|
||||
else if (classesInUse.get(ac) >= classLimits.get(ac))
|
||||
@ -78,16 +77,5 @@ public class ClassLimitManager
|
||||
public void clearClassesInUse() {
|
||||
classesInUse.clear();
|
||||
initInUseMap();
|
||||
debug();
|
||||
}
|
||||
|
||||
private void debug() {
|
||||
System.out.println("classesInUse:");
|
||||
for (ArenaClass ac : classesInUse.keySet())
|
||||
System.out.println(ac.getName() + " has " + classesInUse.get(ac).intValue() + " players using it.");
|
||||
System.out.println();
|
||||
System.out.println("classLimits:");
|
||||
for (ArenaClass ac : classLimits.keySet())
|
||||
System.out.println(ac.getName() + " has a limit of " + classLimits.get(ac).intValue() + " players.");
|
||||
}
|
||||
}
|
@ -52,8 +52,8 @@ public enum Msg
|
||||
LOBBY_CLASS_PICKED("You have chosen % as your class!", "%"),
|
||||
LOBBY_CLASS_RANDOM("You will get a random class on arena start."),
|
||||
LOBBY_CLASS_PERMISSION("You don't have permission to use this class!", "No permission!", Material.FENCE),
|
||||
WARP_TO_ARENA("Can't warp to the arena during battle!"),
|
||||
WARP_FROM_ARENA("Warping not allowed in the arena!"),
|
||||
WARP_TO_ARENA("Warping to the arena not allowed!"),
|
||||
WARP_FROM_ARENA("Warping from the arena not allowed!"),
|
||||
WAVE_DEFAULT("Wave #%!", "Wave #%!", Material.YELLOW_FLOWER),
|
||||
WAVE_SPECIAL("Wave #%! [SPECIAL]", "Wave #%! [SPECIAL]", Material.RED_ROSE),
|
||||
WAVE_SWARM("Wave #%! [SWARM]", "Wave #%! [SWARM]", Material.LONG_GRASS),
|
||||
|
@ -88,8 +88,7 @@ public enum MACreature
|
||||
}
|
||||
|
||||
public LivingEntity spawn(Arena arena, World world, Location loc) {
|
||||
LivingEntity e = world.spawnCreature(loc, type);
|
||||
//TODO change this to: LivingEntity e = (LivingEntity) world.spawnEntity(loc, type);
|
||||
LivingEntity e = (LivingEntity) world.spawnEntity(loc, type);
|
||||
|
||||
switch (this) {
|
||||
case SHEEP:
|
||||
|
Loading…
Reference in New Issue
Block a user