Few changes

This commit is contained in:
Mysticate 2015-08-09 14:34:55 -04:00
parent b9edb92c1e
commit d9a8830e75
4 changed files with 224 additions and 114 deletions

View File

@ -308,9 +308,10 @@ public class ItemBuilder
return this; return this;
} }
public void setData(short newData) public ItemBuilder setData(short newData)
{ {
this._data = newData; this._data = newData;
return this;
} }
public ItemBuilder setPotion(Potion potion) public ItemBuilder setPotion(Potion potion)

View File

@ -10,7 +10,7 @@ public class EvoToken implements Comparable<EvoToken>
public final Player Player; public final Player Player;
public int Kills = 0; public int Level = 0;
public EvoToken(Player player) public EvoToken(Player player)
{ {
@ -20,11 +20,11 @@ public class EvoToken implements Comparable<EvoToken>
@Override @Override
public int compareTo(EvoToken o) public int compareTo(EvoToken o)
{ {
if (Kills == o.Kills) if (Level == o.Level)
{ {
return 0; return 0;
} }
if (Kills > o.Kills) if (Level > o.Level)
{ {
return -1; return -1;
} }

View File

@ -7,21 +7,24 @@ import java.util.Iterator;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilEvent;
import mineplex.core.common.util.UtilEvent.ActionType;
import mineplex.core.common.util.UtilGear;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTextMiddle;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.recharge.Recharge; import mineplex.core.recharge.Recharge;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.core.combat.event.CombatDeathEvent; import mineplex.minecraft.game.core.combat.event.CombatDeathEvent;
import mineplex.minecraft.game.core.condition.Condition.ConditionType; import mineplex.minecraft.game.core.condition.Condition.ConditionType;
import mineplex.minecraft.game.core.condition.ConditionActive; import mineplex.minecraft.game.core.condition.ConditionActive;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType; import nautilus.game.arcade.GameType;
import nautilus.game.arcade.addons.compass.CompassAttemptTargetEvent;
import nautilus.game.arcade.events.GameStateChangeEvent; import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.SoloGame; import nautilus.game.arcade.game.SoloGame;
import nautilus.game.arcade.game.games.evolution.events.EvolutionAbilityUseEvent;
import nautilus.game.arcade.game.games.evolution.events.EvolutionBeginEvent; import nautilus.game.arcade.game.games.evolution.events.EvolutionBeginEvent;
import nautilus.game.arcade.game.games.evolution.events.EvolutionEndEvent; import nautilus.game.arcade.game.games.evolution.events.EvolutionEndEvent;
import nautilus.game.arcade.game.games.evolution.events.EvolutionPostEvolveEvent; import nautilus.game.arcade.game.games.evolution.events.EvolutionPostEvolveEvent;
@ -38,7 +41,6 @@ import nautilus.game.arcade.game.games.evolution.mobs.KitSnowman;
import nautilus.game.arcade.game.games.evolution.mobs.KitSpider; import nautilus.game.arcade.game.games.evolution.mobs.KitSpider;
import nautilus.game.arcade.game.games.evolution.mobs.KitWolf; import nautilus.game.arcade.game.games.evolution.mobs.KitWolf;
import nautilus.game.arcade.kit.Kit; import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.perks.event.PerkConstructorEvent;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -47,7 +49,8 @@ import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
public class Evolution extends SoloGame public class Evolution extends SoloGame
@ -66,6 +69,9 @@ public class Evolution extends SoloGame
//Platform location, viewing location. //Platform location, viewing location.
private NautHashMap<Location, Location> _evoPlatforms = new NautHashMap<Location, Location>(); private NautHashMap<Location, Location> _evoPlatforms = new NautHashMap<Location, Location>();
private ArrayList<Player> _evolutionsAvailable = new ArrayList<Player>();
private ArrayList<Player> _attemptingEvolve = new ArrayList<Player>();
public Evolution(ArcadeManager manager) public Evolution(ArcadeManager manager)
{ {
super(manager, GameType.Evolution, super(manager, GameType.Evolution,
@ -179,6 +185,8 @@ public class Evolution extends SoloGame
} }
} }
@EventHandler @EventHandler
public void showKit(GameStateChangeEvent event) public void showKit(GameStateChangeEvent event)
{ {
@ -212,18 +220,6 @@ public class Evolution extends SoloGame
_evolve = new EvolveManager(this, _evoPlatforms); _evolve = new EvolveManager(this, _evoPlatforms);
} }
@EventHandler
public void tickEvolve(UpdateEvent event)
{
if (!IsLive())
return;
if (event.getType() != UpdateType.TICK)
return;
_evolve.tick();
}
@Override @Override
public boolean HasKit(Player player, Kit kit) public boolean HasKit(Player player, Kit kit)
{ {
@ -235,73 +231,23 @@ public class Evolution extends SoloGame
return false; return false;
} }
//Boolean ending
public void upgradeKit(Player player, boolean give)
{
if (!IsAlive(player))
return;
@EventHandler(priority = EventPriority.MONITOR) EvoKit newKit = _mobKits.get(getScore(player));
public void onEvolveDamageRecieve(CustomDamageEvent event)
{
if (!IsLive())
return;
if (!(event.GetDamageeEntity() instanceof Player))
return;
if (_evolve.isEvolving(event.GetDamageePlayer()))
event.SetCancelled("Player is evolving!");
}
@EventHandler(priority = EventPriority.MONITOR)
public void onEvolveDamageDeal(CustomDamageEvent event)
{
if (!IsLive())
return;
if (!(event.GetDamagerEntity(true) instanceof Player))
return;
if (_evolve.isEvolving(event.GetDamagerPlayer(true)))
event.SetCancelled("Player is evolving!");
}
@EventHandler
public void onEvolveAbility(EvolutionAbilityUseEvent event)
{
if (!IsLive())
return;
if (_evolve.isEvolving(event.getPlayer()))
event.setCancelled(true);
}
@EventHandler
public void onEvolveCompass(CompassAttemptTargetEvent event)
{
if (!IsLive())
return;
if (_evolve.isEvolving(event.getTarget()))
event.setCancelled(true);
}
@EventHandler
public void onEvolveConstruct(PerkConstructorEvent event)
{
if (!IsLive())
return;
if (_evolve.isEvolving(event.getPlayer()))
event.setCancelled(true);
}
@EventHandler
public void onEvolveMove(PlayerMoveEvent event)
{
if (!IsLive())
return;
if (_evolve.isEvolving(event.getPlayer()))
event.getPlayer().teleport(event.getFrom());
}
SetKit(player, newKit, false);
if (give)
{
newKit.upgradeGive(player);
}
}
@EventHandler @EventHandler
public void startEvolve(EvolutionBeginEvent event) public void startEvolve(EvolutionBeginEvent event)
{ {
@ -387,37 +333,111 @@ public class Evolution extends SoloGame
return; return;
} }
EvoToken token = _tokens.get(killer.getName()); _evolutionsAvailable.add(killer);
// EvoToken token = _tokens.get(killer.getName());
//
// try
// {
// EvoKit from = _mobKits.get(token.Kills - 1); //Account for the score increase
// EvoKit to = _mobKits.get(token.Kills);
//
// _evolve.addEvolve(killer, from, to);
// }
// catch (IndexOutOfBoundsException ex)
// {
// End();
// return;
// }
}
@EventHandler
public void updateAvailableEvolutions(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
try if (!IsLive())
return;
Iterator<Player> iterator = _evolutionsAvailable.iterator();
while (iterator.hasNext())
{ {
EvoKit from = _mobKits.get(token.Kills - 1); //Account for the score increase Player player = iterator.next();
EvoKit to = _mobKits.get(token.Kills);
_evolve.addEvolve(killer, from, to); if (player == null || !player.isOnline())
} {
catch (IndexOutOfBoundsException ex) iterator.remove();
{ return;
End(); }
return;
if (!IsAlive(player))
{
iterator.remove();
return;
}
if (!_attemptingEvolve.contains(player))
{
UtilTextMiddle.display("", C.cGreen + C.Bold + "Evolution Available!");
}
if (!UtilGear.isMat(player.getInventory().getItem(7), Material.STAINED_CLAY))
{
player.getInventory().setItem(7, new ItemBuilder(Material.STAINED_CLAY).build());
}
else
{
//Rainbow effect on the clay
ItemStack item = player.getInventory().getItem(7);
byte data = UtilInv.GetData(item);
data++;
if (data > 15)
data = 0;
item.setDurability(data);
}
} }
} }
//Boolean ending @EventHandler
public void upgradeKit(Player player, boolean give) public void onInteractWithEvolve(PlayerInteractEvent event)
{ {
if (!IsAlive(player)) if (!UtilEvent.isAction(event, ActionType.R))
return; return;
EvoKit newKit = _mobKits.get(getScore(player)); if (!IsLive())
return;
SetKit(player, newKit, false);
if (event.getItem().getType() != Material.STAINED_CLAY)
if (give) return;
{
newKit.upgradeGive(player); //Make sure it's the 7 slot
} if (event.getPlayer().getInventory().getItem(7) != event.getItem())
return;
if (_attemptingEvolve.contains(event.getPlayer()))
return;
_attemptingEvolve.add(event.getPlayer());
} }
@EventHandler
public void updateAttemptingEvolve(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
if (!IsLive())
return;
Iterator<Player> iterator = _attemptingEvolve.iterator();
while (iterator.hasNext())
{
Player player = iterator.next();
}
`}
public void increaseScore(Player player) public void increaseScore(Player player)
{ {
@ -427,7 +447,7 @@ public class Evolution extends SoloGame
if (!_tokens.containsKey(player.getName())) if (!_tokens.containsKey(player.getName()))
return; return;
_tokens.get(player.getName()).Kills++; _tokens.get(player.getName()).Level++;
} }
public int getScore(Player player) public int getScore(Player player)
@ -435,7 +455,7 @@ public class Evolution extends SoloGame
if (!IsPlaying(player)) if (!IsPlaying(player))
return 0; return 0;
return _tokens.get(player.getName()).Kills; return _tokens.get(player.getName()).Level;
} }
private void End() private void End()

View File

@ -7,13 +7,25 @@ import java.util.Map.Entry;
import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.addons.compass.CompassAttemptTargetEvent;
import nautilus.game.arcade.game.games.evolution.EvoKit; import nautilus.game.arcade.game.games.evolution.EvoKit;
import nautilus.game.arcade.game.games.evolution.Evolution; import nautilus.game.arcade.game.games.evolution.Evolution;
import nautilus.game.arcade.game.games.evolution.events.EvolutionAbilityUseEvent;
import nautilus.game.arcade.kit.perks.event.PerkConstructorEvent;
import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
public class EvolveManager public class EvolveManager implements Listener
{ {
/** /**
* @author Mysticate * @author Mysticate
@ -29,6 +41,8 @@ public class EvolveManager
{ {
Host = evolution; Host = evolution;
_evolveLocs = evolveLocs; _evolveLocs = evolveLocs;
Bukkit.getPluginManager().registerEvents(this, Host.Manager.getPlugin());
} }
private PlatformToken getLocation() private PlatformToken getLocation()
@ -57,8 +71,15 @@ public class EvolveManager
return _data.get(player.getName()); return _data.get(player.getName());
} }
public void tick() @EventHandler
public void tick(UpdateEvent event)
{ {
if (event.getType() != UpdateType.TICK)
return;
if (!Host.IsLive())
return;
Iterator<Entry<String, EvolveData>> iterator = _data.entrySet().iterator(); Iterator<Entry<String, EvolveData>> iterator = _data.entrySet().iterator();
while (iterator.hasNext()) while (iterator.hasNext())
{ {
@ -92,5 +113,73 @@ public class EvolveManager
{ {
data.end(); data.end();
} }
HandlerList.unregisterAll(this);
}
@EventHandler(priority = EventPriority.MONITOR)
public void onEvolveDamageRecieve(CustomDamageEvent event)
{
if (!Host.IsLive())
return;
if (!(event.GetDamageeEntity() instanceof Player))
return;
if (isEvolving(event.GetDamageePlayer()))
event.SetCancelled("Player is evolving!");
}
@EventHandler(priority = EventPriority.MONITOR)
public void onEvolveDamageDeal(CustomDamageEvent event)
{
if (!Host.IsLive())
return;
if (!(event.GetDamagerEntity(true) instanceof Player))
return;
if (isEvolving(event.GetDamagerPlayer(true)))
event.SetCancelled("Player is evolving!");
}
@EventHandler
public void onEvolveAbility(EvolutionAbilityUseEvent event)
{
if (!Host.IsLive())
return;
if (isEvolving(event.getPlayer()))
event.setCancelled(true);
}
@EventHandler
public void onEvolveCompass(CompassAttemptTargetEvent event)
{
if (!Host.IsLive())
return;
if (isEvolving(event.getTarget()))
event.setCancelled(true);
}
@EventHandler
public void onEvolveConstruct(PerkConstructorEvent event)
{
if (!Host.IsLive())
return;
if (isEvolving(event.getPlayer()))
event.setCancelled(true);
}
@EventHandler
public void onEvolveMove(PlayerMoveEvent event)
{
if (!Host.IsLive())
return;
if (isEvolving(event.getPlayer()))
event.getPlayer().teleport(event.getFrom());
} }
} }