Fix various bugs found in testing

This commit is contained in:
Sam 2017-04-21 21:53:16 +01:00
parent ca6789d92a
commit 2f478e46f3
5 changed files with 93 additions and 39 deletions

View File

@ -18,6 +18,7 @@ import nautilus.game.arcade.game.DebugCommand;
import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.GameTeam.PlayerState;
import nautilus.game.arcade.game.games.smash.events.SmashActivateEvent;
import nautilus.game.arcade.game.games.smash.kits.*;
import nautilus.game.arcade.game.games.smash.perks.SmashUltimate;
import nautilus.game.arcade.game.modules.compass.CompassModule;
@ -252,12 +253,12 @@ public abstract class SuperSmash extends Game
@EventHandler
public void triggerSuper(PlayerInteractEvent event)
{
if (!IsLive())
if (!IsLive() || !UtilEvent.isAction(event, UtilEvent.ActionType.R))
{
return;
}
if (event.getMaterial() != Material.NETHER_STAR)
if (event.getMaterial() != null && event.getMaterial() != Material.NETHER_STAR)
{
return;
}
@ -276,6 +277,15 @@ public abstract class SuperSmash extends Game
continue;
}
SmashActivateEvent smashActivateEvent = new SmashActivateEvent(player);
UtilServer.CallEvent(smashActivateEvent);
if (smashActivateEvent.isCancelled())
{
return;
}
UtilInv.remove(player, Material.NETHER_STAR, (byte) 0, 1);
player.setHealth(player.getMaxHealth());
@ -547,47 +557,19 @@ public abstract class SuperSmash extends Game
@EventHandler(priority = EventPriority.LOWEST)
public void abilityDescription(PlayerInteractEvent event)
{
if (event.isCancelled())
{
return;
}
Player player = event.getPlayer();
ItemStack itemStack = player.getItemInHand();
if (itemStack == null)
if (itemStack == null || itemStack.getItemMeta() == null || itemStack.getItemMeta().getDisplayName() == null || itemStack.getItemMeta().getLore() == null || !displayKitInfo(player))
{
return;
}
if (itemStack.getItemMeta() == null)
if (itemStack.getType() == Material.WATCH || itemStack.getType() == Material.BED)
{
return;
}
ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta.getDisplayName() == null)
{
return;
}
if (itemMeta.getLore() == null)
{
return;
}
if (GetState() != GameState.Recruit)
{
return;
}
displayKitInto(player);
event.setCancelled(true);
}
protected void displayKitInto(Player player)
{
for (int i = player.getItemInHand().getItemMeta().getLore().size(); i <= 7; i++)
{
UtilPlayer.message(player, "");
@ -606,6 +588,8 @@ public abstract class SuperSmash extends Game
UtilPlayer.message(player, ArcadeFormat.Line);
player.playSound(player.getLocation(), Sound.NOTE_PLING, 1f, 2f);
event.setCancelled(true);
}
@Override
@ -725,4 +709,9 @@ public abstract class SuperSmash extends Game
{
return _lives;
}
protected boolean displayKitInfo(Player player)
{
return GetState() == GameState.Recruit;
}
}

View File

@ -10,6 +10,7 @@ import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.games.smash.events.SmashActivateEvent;
import nautilus.game.arcade.game.modules.training.TrainingBot;
import nautilus.game.arcade.game.modules.training.TrainingGameModule;
import org.bukkit.ChatColor;
@ -36,6 +37,10 @@ public class SuperSmashTraining extends SuperSmash
private Location _borderA;
private Location _borderB;
private Function<Player, Boolean> safeFunction = player ->
{
return !UtilAlg.inBoundingBox(player.getLocation(), _borderA, _borderB);
};
private boolean _announceEnd;
@ -49,15 +54,11 @@ public class SuperSmashTraining extends SuperSmash
DeathSpectateSecs = 0;
PrepareTime = 500;
GiveClock = false;
Function<Player, Boolean> playerFunction = player ->
{
return !UtilAlg.inBoundingBox(player.getLocation(), _borderA, _borderB);
};
HungerSet = 20;
new TrainingGameModule()
.setSkillFunction(playerFunction)
.setDamageFunction(playerFunction)
.setSkillFunction(safeFunction)
.setDamageFunction(safeFunction)
.addBot(TrainingBot.class)
.register(this);
}
@ -156,6 +157,15 @@ public class SuperSmashTraining extends SuperSmash
{
}
@EventHandler
public void smashActivating(SmashActivateEvent event)
{
if (!safeFunction.apply(event.getPlayer()))
{
event.setCancelled(true);
}
}
@Override
public void EndCheck()
{
@ -182,6 +192,12 @@ public class SuperSmashTraining extends SuperSmash
return (long) (System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(2) + TimeUnit.MINUTES.toMillis(2) * Math.random());
}
@Override
protected boolean displayKitInfo(Player player)
{
return super.displayKitInfo(player) || !safeFunction.apply(player);
}
private void spawnInfoHologram(Location location)
{
CreatureAllowOverride = true;

View File

@ -0,0 +1,42 @@
package nautilus.game.arcade.game.games.smash.events;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
public class SmashActivateEvent extends PlayerEvent implements Cancellable
{
private static final HandlerList HANDLERS = new HandlerList();
private boolean _cancelled;
public SmashActivateEvent(Player who)
{
super(who);
}
@Override
public boolean isCancelled()
{
return _cancelled;
}
@Override
public void setCancelled(boolean b)
{
_cancelled = b;
}
public HandlerList getHandlers()
{
return HANDLERS;
}
public static HandlerList getHandlerList()
{
return HANDLERS;
}
}

View File

@ -6,6 +6,8 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
import mineplex.core.common.util.UtilServer;
import nautilus.game.arcade.game.games.smash.events.SmashActivateEvent;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;

View File

@ -284,6 +284,11 @@ public class TrainingGameModule extends Module
if (!event.isCancelled())
{
Recharge.Instance.useForce(player, RETURN_TO_SPAWN_RECHARGE, RETURN_TO_SPAWN_COOLDOWN);
if (event.GetDamagerEntity(true) instanceof Player)
{
Recharge.Instance.useForce(event.GetDamagerPlayer(true), RETURN_TO_SPAWN_RECHARGE, RETURN_TO_SPAWN_COOLDOWN);
}
}
if (_damageFunction == null)