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.HashMap;
import java.util.List;
import java.util.UUID;
import mineplex.core.common.util.C;
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.WinWithoutDyingStatTracker;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
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> _bestCombo = new HashMap<Player, Integer>();
private HashMap<Player, Long> _deathTime = new HashMap<Player, Long>();
private HashMap<UUID, Integer> _bowTime = new HashMap<>();
private Objective _scoreObj;
public Quiver(ArcadeManager manager)
public Quiver(ArcadeManager manager)
{
super(manager, GameType.Quiver,
@ -81,9 +84,9 @@ public class Quiver extends SoloGame
this.BlockBreakAllow.add(20);
this.BlockBreakAllow.add(Material.STAINED_GLASS_PANE.getId());
this.BlockBreakAllow.add(Material.STAINED_GLASS.getId());
this.DeathSpectateSecs = 1;
_scoreObj = Scoreboard.GetScoreboard().registerNewObjective("Kills", "dummy");
_scoreObj.setDisplaySlot(DisplaySlot.BELOW_NAME);
@ -91,7 +94,7 @@ public class Quiver extends SoloGame
new WinWithoutDyingStatTracker(this, "Perfectionist"),
new SharpShooterStatTracker(this),
new WinWithoutBowStatTracker(this, "WhatsABow")
);
);
registerChatStats(
Kills,
@ -101,7 +104,7 @@ public class Quiver extends SoloGame
Assists,
DamageTaken,
DamageDealt
);
);
}
@EventHandler(priority = EventPriority.HIGH)
@ -109,38 +112,67 @@ public class Quiver extends SoloGame
{
if (event.GetState() != GameState.Live)
return;
for (Player player : GetPlayers(true))
{
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(262, (byte)0, 1, F.item("Super Arrow")));
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
public void BowShoot(EntityShootBowEvent event)
{
Bukkit.broadcastMessage(event.getEventName());
if (!(event.getProjectile() instanceof Arrow))
return;
Arrow arrow = (Arrow)event.getProjectile();
if (arrow.getShooter() == null)
return;
if (!(arrow.getShooter() instanceof Player))
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()))
return;
if (UtilTime.elapsed(_deathTime.get(arrow.getShooter()), 1000))
return;
event.getProjectile().remove();
final Player player = (Player)arrow.getShooter();
Manager.getPlugin().getServer().getScheduler().scheduleSyncDelayedTask(Manager.getPlugin(), new Runnable()
{
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")));
}
}, 10);
}
@EventHandler
@ -159,7 +191,7 @@ public class Quiver extends SoloGame
{
_deathTime.put((Player)event.GetEvent().getEntity(), System.currentTimeMillis());
}
if (event.GetLog().GetKiller() == null)
return;
@ -170,7 +202,7 @@ public class Quiver extends SoloGame
if (player == null) return;
int amount = 1;
if (GetKit(player) instanceof KitSlamShot)
{
if (Manager.GetCondition().HasCondition(event.GetEvent().getEntity(), ConditionType.FALLING, null))
@ -178,7 +210,7 @@ public class Quiver extends SoloGame
amount = 2;
}
}
//New Arrow
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(262, (byte)0, amount, F.item("Super Arrow")));
player.playSound(player.getLocation(), Sound.PISTON_EXTEND, 3f, 2f);
@ -192,9 +224,9 @@ public class Quiver extends SoloGame
{
if (!(event.GetEvent().getEntity() instanceof Player))
return;
Player player = (Player)event.GetEvent().getEntity();
if (!_combo.containsKey(player))
return;
@ -235,7 +267,7 @@ public class Quiver extends SoloGame
_scoreObj.getScore(player.getName()).setScore(1);
}
private void AnnounceCombo(Player player, int combo)
private void AnnounceCombo(Player player, int combo)
{
String killType = null;
if (combo == 20) killType = "PERFECT RUN";
@ -252,13 +284,13 @@ public class Quiver extends SoloGame
//Announce
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)!")));
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++)
{
@ -282,7 +314,7 @@ public class Quiver extends SoloGame
event.AddMod("Projectile", "Instagib", 9001, false);
event.SetKnockback(false);
event.GetProjectile().remove();
}
@ -294,10 +326,10 @@ public class Quiver extends SoloGame
return;
SortScores();
//Wipe Last
Scoreboard.Reset();
Scoreboard.WriteBlank();
//Write New
@ -305,7 +337,7 @@ public class Quiver extends SoloGame
{
Scoreboard.WriteOrdered("Score", C.cGreen + score.Player.getName(), score.Kills, true);
}
Scoreboard.Draw();
}
@ -344,7 +376,7 @@ public class Quiver extends SoloGame
for (Player player : _bestCombo.keySet())
{
int combo = _bestCombo.get(player);
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 >= 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 >= 3) AddGems(player, 4, "TRIPLE KILL - 3 Kill Combo", false, false);
}
//Participation
for (Player player : GetPlayers(false))
if (player.isOnline())
@ -363,14 +395,14 @@ public class Quiver extends SoloGame
AnnounceEnd(places);
}
}
@Override
public List<Player> getWinners()
{
if (GetState().ordinal() >= GameState.End.ordinal())
{
SortScores();
//Set Places
ArrayList<Player> places = new ArrayList<Player>();
for (int i=0 ; i<_ranks.size() ; i++)