Fixes the issue of "auto-bowing" in OITQ
This commit is contained in:
Sam 2016-05-31 01:46:50 +01:00
parent 55317730fa
commit 6db4c3acc7

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.UUID;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
@ -30,6 +31,7 @@ import nautilus.game.arcade.stats.SharpShooterStatTracker;
import nautilus.game.arcade.stats.WinWithoutBowStatTracker; import nautilus.game.arcade.stats.WinWithoutBowStatTracker;
import nautilus.game.arcade.stats.WinWithoutDyingStatTracker; import nautilus.game.arcade.stats.WinWithoutDyingStatTracker;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Sound; import org.bukkit.Sound;
@ -48,10 +50,11 @@ public class Quiver extends SoloGame
private HashMap<Player, Integer> _combo = new HashMap<Player, Integer>(); private HashMap<Player, Integer> _combo = new HashMap<Player, Integer>();
private HashMap<Player, Integer> _bestCombo = new HashMap<Player, Integer>(); private HashMap<Player, Integer> _bestCombo = new HashMap<Player, Integer>();
private HashMap<Player, Long> _deathTime = new HashMap<Player, Long>(); private HashMap<Player, Long> _deathTime = new HashMap<Player, Long>();
private HashMap<UUID, Integer> _bowTime = new HashMap<>();
private Objective _scoreObj; private Objective _scoreObj;
public Quiver(ArcadeManager manager) public Quiver(ArcadeManager manager)
{ {
super(manager, GameType.Quiver, super(manager, GameType.Quiver,
@ -81,9 +84,9 @@ public class Quiver extends SoloGame
this.BlockBreakAllow.add(20); this.BlockBreakAllow.add(20);
this.BlockBreakAllow.add(Material.STAINED_GLASS_PANE.getId()); this.BlockBreakAllow.add(Material.STAINED_GLASS_PANE.getId());
this.BlockBreakAllow.add(Material.STAINED_GLASS.getId()); this.BlockBreakAllow.add(Material.STAINED_GLASS.getId());
this.DeathSpectateSecs = 1; this.DeathSpectateSecs = 1;
_scoreObj = Scoreboard.GetScoreboard().registerNewObjective("Kills", "dummy"); _scoreObj = Scoreboard.GetScoreboard().registerNewObjective("Kills", "dummy");
_scoreObj.setDisplaySlot(DisplaySlot.BELOW_NAME); _scoreObj.setDisplaySlot(DisplaySlot.BELOW_NAME);
@ -91,7 +94,7 @@ public class Quiver extends SoloGame
new WinWithoutDyingStatTracker(this, "Perfectionist"), new WinWithoutDyingStatTracker(this, "Perfectionist"),
new SharpShooterStatTracker(this), new SharpShooterStatTracker(this),
new WinWithoutBowStatTracker(this, "WhatsABow") new WinWithoutBowStatTracker(this, "WhatsABow")
); );
registerChatStats( registerChatStats(
Kills, Kills,
@ -101,7 +104,7 @@ public class Quiver extends SoloGame
Assists, Assists,
DamageTaken, DamageTaken,
DamageDealt DamageDealt
); );
} }
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)
@ -109,38 +112,67 @@ public class Quiver extends SoloGame
{ {
if (event.GetState() != GameState.Live) if (event.GetState() != GameState.Live)
return; return;
for (Player player : GetPlayers(true)) for (Player player : GetPlayers(true))
{ {
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(262, (byte)0, 1, F.item("Super Arrow"))); player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(262, (byte)0, 1, F.item("Super Arrow")));
player.playSound(player.getLocation(), Sound.PISTON_EXTEND, 3f, 2f); player.playSound(player.getLocation(), Sound.PISTON_EXTEND, 3f, 2f);
_bowTime.put(player.getUniqueId(), 0);
} }
} }
@EventHandler
public void onUpdate(UpdateEvent event)
{
if(event.getType() != UpdateType.TICK)
return;
for(Player player : GetPlayers(true))
{
if(UtilPlayer.isChargingBow(player))
{
_bowTime.put(player.getUniqueId(), _bowTime.get(player.getUniqueId()) + 1);
}
else
{
_bowTime.put(player.getUniqueId(), 0);
}
}
}
@EventHandler @EventHandler
public void BowShoot(EntityShootBowEvent event) public void BowShoot(EntityShootBowEvent event)
{ {
Bukkit.broadcastMessage(event.getEventName());
if (!(event.getProjectile() instanceof Arrow)) if (!(event.getProjectile() instanceof Arrow))
return; return;
Arrow arrow = (Arrow)event.getProjectile(); Arrow arrow = (Arrow)event.getProjectile();
if (arrow.getShooter() == null) if (arrow.getShooter() == null)
return; return;
if (!(arrow.getShooter() instanceof Player)) if (!(arrow.getShooter() instanceof Player))
return; return;
Player shooter = (Player) arrow.getShooter();
//If the player has a full charge but they haven't been holding the bow for more than 20 ticks
if(_bowTime.get(shooter.getUniqueId()) < 20 && event.getForce() == 1)
{
event.setCancelled(true);
return;
}
if (!_deathTime.containsKey(arrow.getShooter())) if (!_deathTime.containsKey(arrow.getShooter()))
return; return;
if (UtilTime.elapsed(_deathTime.get(arrow.getShooter()), 1000)) if (UtilTime.elapsed(_deathTime.get(arrow.getShooter()), 1000))
return; return;
event.getProjectile().remove(); event.getProjectile().remove();
final Player player = (Player)arrow.getShooter(); final Player player = (Player)arrow.getShooter();
Manager.getPlugin().getServer().getScheduler().scheduleSyncDelayedTask(Manager.getPlugin(), new Runnable() Manager.getPlugin().getServer().getScheduler().scheduleSyncDelayedTask(Manager.getPlugin(), new Runnable()
{ {
public void run() public void run()
@ -149,7 +181,7 @@ public class Quiver extends SoloGame
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(262, (byte)0, 1, F.item("Super Arrow"))); player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(262, (byte)0, 1, F.item("Super Arrow")));
} }
}, 10); }, 10);
} }
@EventHandler @EventHandler
@ -159,7 +191,7 @@ public class Quiver extends SoloGame
{ {
_deathTime.put((Player)event.GetEvent().getEntity(), System.currentTimeMillis()); _deathTime.put((Player)event.GetEvent().getEntity(), System.currentTimeMillis());
} }
if (event.GetLog().GetKiller() == null) if (event.GetLog().GetKiller() == null)
return; return;
@ -170,7 +202,7 @@ public class Quiver extends SoloGame
if (player == null) return; if (player == null) return;
int amount = 1; int amount = 1;
if (GetKit(player) instanceof KitSlamShot) if (GetKit(player) instanceof KitSlamShot)
{ {
if (Manager.GetCondition().HasCondition(event.GetEvent().getEntity(), ConditionType.FALLING, null)) if (Manager.GetCondition().HasCondition(event.GetEvent().getEntity(), ConditionType.FALLING, null))
@ -178,7 +210,7 @@ public class Quiver extends SoloGame
amount = 2; amount = 2;
} }
} }
//New Arrow //New Arrow
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(262, (byte)0, amount, F.item("Super Arrow"))); player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(262, (byte)0, amount, F.item("Super Arrow")));
player.playSound(player.getLocation(), Sound.PISTON_EXTEND, 3f, 2f); player.playSound(player.getLocation(), Sound.PISTON_EXTEND, 3f, 2f);
@ -192,9 +224,9 @@ public class Quiver extends SoloGame
{ {
if (!(event.GetEvent().getEntity() instanceof Player)) if (!(event.GetEvent().getEntity() instanceof Player))
return; return;
Player player = (Player)event.GetEvent().getEntity(); Player player = (Player)event.GetEvent().getEntity();
if (!_combo.containsKey(player)) if (!_combo.containsKey(player))
return; return;
@ -235,7 +267,7 @@ public class Quiver extends SoloGame
_scoreObj.getScore(player.getName()).setScore(1); _scoreObj.getScore(player.getName()).setScore(1);
} }
private void AnnounceCombo(Player player, int combo) private void AnnounceCombo(Player player, int combo)
{ {
String killType = null; String killType = null;
if (combo == 20) killType = "PERFECT RUN"; if (combo == 20) killType = "PERFECT RUN";
@ -252,13 +284,13 @@ public class Quiver extends SoloGame
//Announce //Announce
for (Player other : UtilServer.getPlayers()) for (Player other : UtilServer.getPlayers())
{ {
UtilPlayer.message(other, F.main("Game", C.cGreen + C.Bold + player.getName() + ChatColor.RESET + " got " + UtilPlayer.message(other, F.main("Game", C.cGreen + C.Bold + player.getName() + ChatColor.RESET + " got " +
F.elem(C.cAqua + C.Bold + killType +" (" + combo + " Kills)!"))); F.elem(C.cAqua + C.Bold + killType +" (" + combo + " Kills)!")));
other.playSound(other.getLocation(), Sound.ENDERDRAGON_GROWL, 1f + (combo/10f), 1f + (combo/10f)); other.playSound(other.getLocation(), Sound.ENDERDRAGON_GROWL, 1f + (combo/10f), 1f + (combo/10f));
} }
} }
private void SortScores() private void SortScores()
{ {
for (int i=0 ; i<_ranks.size() ; i++) for (int i=0 ; i<_ranks.size() ; i++)
{ {
@ -282,7 +314,7 @@ public class Quiver extends SoloGame
event.AddMod("Projectile", "Instagib", 9001, false); event.AddMod("Projectile", "Instagib", 9001, false);
event.SetKnockback(false); event.SetKnockback(false);
event.GetProjectile().remove(); event.GetProjectile().remove();
} }
@ -294,10 +326,10 @@ public class Quiver extends SoloGame
return; return;
SortScores(); SortScores();
//Wipe Last //Wipe Last
Scoreboard.Reset(); Scoreboard.Reset();
Scoreboard.WriteBlank(); Scoreboard.WriteBlank();
//Write New //Write New
@ -305,7 +337,7 @@ public class Quiver extends SoloGame
{ {
Scoreboard.WriteOrdered("Score", C.cGreen + score.Player.getName(), score.Kills, true); Scoreboard.WriteOrdered("Score", C.cGreen + score.Player.getName(), score.Kills, true);
} }
Scoreboard.Draw(); Scoreboard.Draw();
} }
@ -344,7 +376,7 @@ public class Quiver extends SoloGame
for (Player player : _bestCombo.keySet()) for (Player player : _bestCombo.keySet())
{ {
int combo = _bestCombo.get(player); int combo = _bestCombo.get(player);
if (combo >= 20) AddGems(player, 40, "PERFECT - 20 Kill Combo", false, false); if (combo >= 20) AddGems(player, 40, "PERFECT - 20 Kill Combo", false, false);
else if (combo >= 13) AddGems(player, 24, "GODLIKE - 13 Kill Combo", false, false); else if (combo >= 13) AddGems(player, 24, "GODLIKE - 13 Kill Combo", false, false);
else if (combo >= 11) AddGems(player, 20, "UNSTOPPABLE - 11 Kill Combo", false, false); else if (combo >= 11) AddGems(player, 20, "UNSTOPPABLE - 11 Kill Combo", false, false);
@ -353,7 +385,7 @@ public class Quiver extends SoloGame
else if (combo >= 5) AddGems(player, 8, "MEGA KILL - 5 Kill Combo", false, false); else if (combo >= 5) AddGems(player, 8, "MEGA KILL - 5 Kill Combo", false, false);
else if (combo >= 3) AddGems(player, 4, "TRIPLE KILL - 3 Kill Combo", false, false); else if (combo >= 3) AddGems(player, 4, "TRIPLE KILL - 3 Kill Combo", false, false);
} }
//Participation //Participation
for (Player player : GetPlayers(false)) for (Player player : GetPlayers(false))
if (player.isOnline()) if (player.isOnline())
@ -363,14 +395,14 @@ public class Quiver extends SoloGame
AnnounceEnd(places); AnnounceEnd(places);
} }
} }
@Override @Override
public List<Player> getWinners() public List<Player> getWinners()
{ {
if (GetState().ordinal() >= GameState.End.ordinal()) if (GetState().ordinal() >= GameState.End.ordinal())
{ {
SortScores(); SortScores();
//Set Places //Set Places
ArrayList<Player> places = new ArrayList<Player>(); ArrayList<Player> places = new ArrayList<Player>();
for (int i=0 ; i<_ranks.size() ; i++) for (int i=0 ; i<_ranks.size() ; i++)