Added time in ticks where players can't move at the start of the effect

This commit is contained in:
LCastr0 2016-12-14 00:18:37 -02:00 committed by cnr
parent 651d0c5966
commit 5102227e94
2 changed files with 66 additions and 27 deletions

View File

@ -12,6 +12,7 @@ import org.bukkit.FireworkEffect;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import mineplex.core.common.util.F;
import mineplex.core.common.util.LineFormat;
import mineplex.core.common.util.UtilFirework;
import mineplex.core.common.util.UtilText;
@ -28,21 +29,21 @@ public class EternalTaunt extends TauntGadget
private static final int COOLDOWN = 30000;
private Map<UUID, List<EternalClock>> _clocks = new HashMap<>();
private Map<UUID, Integer> _ticksPerPlayer = new HashMap<>();
public EternalTaunt(GadgetManager manager)
{
super(manager, "Eternal Taunt", UtilText.splitLinesToArray(new String[]{"Placeholder"}, LineFormat.LORE),
-15, Material.GLASS, (byte) 0);
setCanPlayWithPvp(false);
setPvpCooldown(5000);
setPvpCooldown(10000);
setShouldPlay(true);
setEventType(UpdateType.TICK);
setEventType(UpdateType.FAST);
addDisabledGames(GameType.SMASH, GameType.SMASHTEAMS, GameType.SMASHDOMINATION);
setImmovable(20);
}
@Override
public void start(Player player)
public void onStart(Player player)
{
if (!Recharge.Instance.use(player, getName(), COOLDOWN, true, false, "Cosmetics"))
return;
@ -65,11 +66,11 @@ public class EternalTaunt extends TauntGadget
enableArcadeSpawnEvent = new EnableArcadeSpawnEvent(false);
Bukkit.getPluginManager().callEvent(enableArcadeSpawnEvent);
_ticksPerPlayer.put(player.getUniqueId(), 0);
Bukkit.broadcastMessage(F.main("Taunt", F.name(player.getName()) + " waited so long they turned to bones."));
}
@Override
public void play(Player player)
public void onPlay(Player player)
{
if (!_clocks.containsKey(player.getUniqueId()))
return;
@ -80,18 +81,14 @@ public class EternalTaunt extends TauntGadget
eternalClock.moveStand();
}
if (getTicks(player) >= 60)
if (getPlayerTicks(player) >= 60)
{
finish(player);
}
else
{
increaseTicks(player);
}
}
@Override
public void finish(Player player)
public void onFinish(Player player)
{
if (_clocks.containsKey(player.getUniqueId()))
{
@ -101,16 +98,4 @@ public class EternalTaunt extends TauntGadget
}
}
private int getTicks(Player player)
{
return _ticksPerPlayer.get(player.getUniqueId());
}
private void increaseTicks(Player player)
{
int ticks = getTicks(player);
ticks++;
_ticksPerPlayer.put(player.getUniqueId(), ticks);
}
}

View File

@ -3,11 +3,15 @@ package mineplex.core.gadget.types;
import java.time.YearMonth;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerMoveEvent;
import mineplex.core.gadget.GadgetManager;
import mineplex.core.gadget.gadgets.taunts.GameType;
@ -28,8 +32,12 @@ public abstract class TauntGadget extends Gadget
private boolean _shouldPlay = false;
/** Sets when the taunt will run, if set above */
private UpdateType _updateType = UpdateType.TICK;
/** Sets the amount of time in ticks the player won't be able to move */
private int _immovable = 0;
/** List of games where this item is disabled */
private List<GameType> _disabledGames = new ArrayList<>();
/** The ticks that passed since the player started the effect */
private Map<UUID, Integer> _ticksPerPlayer = new HashMap<>();
/**
* @param manager The normal GadgetManager
@ -62,11 +70,30 @@ public abstract class TauntGadget extends Gadget
super(manager, GadgetType.TAUNT, name, desc, cost, mat, data, yearMonth, 1, alternativeSalesPackageNames);
}
public abstract void start(Player player);
public void start(Player player)
{
onStart(player);
_ticksPerPlayer.put(player.getUniqueId(), 0);
}
public abstract void play(Player player);
public abstract void onStart(Player player);
public abstract void finish(Player player);
public void play(Player player)
{
onPlay(player);
int ticks = _ticksPerPlayer.get(player.getUniqueId()) + 1;
_ticksPerPlayer.put(player.getUniqueId(), ticks);
}
public abstract void onPlay(Player player);
public void finish(Player player)
{
onFinish(player);
_ticksPerPlayer.remove(player.getUniqueId());
}
public abstract void onFinish(Player player);
public void setCanPlayWithPvp(boolean canPlayWithPvp)
{
@ -93,6 +120,11 @@ public abstract class TauntGadget extends Gadget
_disabledGames.addAll(Arrays.asList(disabledGames));
}
public void setImmovable(int ticks)
{
_immovable = ticks;
}
public boolean canPlayWithPvp()
{
return _canPlayWithPvp;
@ -108,6 +140,11 @@ public abstract class TauntGadget extends Gadget
return _pvpCooldown;
}
public int getPlayerTicks(Player player)
{
return (_ticksPerPlayer.containsKey(player.getUniqueId())) ? _ticksPerPlayer.get(player.getUniqueId()) : -1;
}
@EventHandler
public void onUpdate(UpdateEvent event)
{
@ -123,4 +160,21 @@ public abstract class TauntGadget extends Gadget
}
}
@EventHandler
public void onPlayerMove(PlayerMoveEvent event)
{
if (!_ticksPerPlayer.containsKey(event.getPlayer().getUniqueId()))
return;
if (!isActive(event.getPlayer()))
return;
int ticks = _ticksPerPlayer.get(event.getPlayer().getUniqueId());
if (ticks < _immovable)
{
event.setCancelled(true);
}
}
}