Bawk Bawk Battles rewrite

This commit is contained in:
samczsun 2017-01-21 18:17:03 -05:00 committed by cnr
parent 16c155ffe8
commit 8a3b531a06
15 changed files with 348 additions and 341 deletions

View File

@ -102,7 +102,7 @@ public class AchievementMainPage extends ShopPageBase<AchievementManager, Achiev
protected void addAchievements(AchievementCategory category, List<String> lore, int max)
{
int achievementCount = 0;
for (int i = 0; i < Achievement.values().length && achievementCount < max; i++)
for (int i = 0; i < Achievement.values().length; i++)
{
Achievement achievement = Achievement.values()[i];
if (achievement.getCategory() == category)

View File

@ -899,7 +899,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
{
_specList.remove(event.getPlayer());
if (_game.GetTeam(event.getPlayer()) != null)
_game.GetTeam(event.getPlayer()).SetPlayerState(event.getPlayer(), PlayerState.IN);
_game.SetPlayerState(event.getPlayer(), PlayerState.IN);
}
if (isSpectator(event.getPlayer()))

View File

@ -1161,6 +1161,25 @@ public abstract class Game extends ListenerComponent implements Lifetimed
return GetKit(player).GetName().equals(kit.GetName());
}
public void disqualify(Player player)
{
RemoveTeamPreference(player);
GetPlayerKits().remove(player);
GetPlayerGems().remove(player);
//Remove Team
GameTeam team = GetTeam(player);
if (team != null)
{
if (InProgress())
SetPlayerState(player, PlayerState.OUT);
else
team.RemovePlayer(player);
}
Manager.addSpectator(player, false);
}
public boolean SetPlayerState(Player player, PlayerState state)
{
GameTeam team = GetTeam(player);
@ -1227,6 +1246,11 @@ public abstract class Game extends ListenerComponent implements Lifetimed
return false;
}
public boolean shouldHeal(Player player)
{
return true;
}
public ArrayList<Player> GetPlayers(boolean aliveOnly)
{
ArrayList<Player> players = new ArrayList<Player>();

View File

@ -5,10 +5,15 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import mineplex.core.common.Pair;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
@ -42,11 +47,13 @@ import org.bukkit.scheduler.BukkitRunnable;
import com.google.common.collect.Lists;
import mineplex.core.common.Pair;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
@ -60,12 +67,12 @@ import mineplex.core.common.util.UtilTime;
import mineplex.core.projectile.IThrown;
import mineplex.core.projectile.ProjectileUser;
import mineplex.core.recharge.Recharge;
import mineplex.core.teleport.event.MineplexTeleportEvent;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.core.condition.Condition.ConditionType;
import mineplex.minecraft.game.core.condition.events.ConditionApplyEvent;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType;
import nautilus.game.arcade.events.GamePrepareCountdownCommence;
@ -197,9 +204,9 @@ public class BawkBawkBattles extends TeamGame implements IThrown
private BawkBawkBattlesSettings _settings = new BawkBawkBattlesSettings();
private ChallengeList _list = new ChallengeList();
private Map<Player, Integer> _lives = new HashMap<>();
private List<Player> _winners = new ArrayList<Player>();
private GameTeam _playerTeam, _chickenTeam;
private Map<UUID, Integer> _lives = new HashMap<>();
private LinkedList<Player> _winners = new LinkedList<>();
private GameTeam _playerTeam;
private DeathEffect _deathEffect = new DeathEffect(this);
private ChickenAttack _chickenAttack;
private Location _chickenAttackCenter;
@ -207,6 +214,8 @@ public class BawkBawkBattles extends TeamGame implements IThrown
private List<Block> _lastChallengeBlocks;
private long _delay;
public final Set<UUID> _beingAttacked = new HashSet<>();
private List<String> _countdown = Arrays.asList(
C.cRed + C.Bold + "3",
C.cYellow + C.Bold + "2",
@ -218,8 +227,8 @@ public class BawkBawkBattles extends TeamGame implements IThrown
{
super(manager,
GameType.BawkBawkBattles,
new Kit[] { new KitBawksFood(manager) },
new String[] {
new Kit[]{new KitBawksFood(manager)},
new String[]{
"Follow Bawk Bawk's instructions in chat.",
"Complete a task first or be the last one to stay alive.",
"If you fail a challenge, you lose one life.",
@ -243,9 +252,6 @@ public class BawkBawkBattles extends TeamGame implements IThrown
DeathMessages = false;
FixSpawnFacing = false;
TeleportsDisqualify = false;
GiveClock = false;
Manager.GetCreature().SetDisableCustomDrops(true);
populateChallenges();
@ -313,40 +319,17 @@ public class BawkBawkBattles extends TeamGame implements IThrown
_chickenAttackCenter = WorldData.GetDataLocs("WHITE").get(0);
}
/*
* Team creation
*/
@EventHandler(priority = EventPriority.HIGHEST)
public void createTeams(GameStateChangeEvent event)
{
if (event.GetState() == GameState.Recruit)
{
createPlayerTeam();
}
else if (event.GetState() == GameState.Live)
{
createChickenTeam();
}
}
private void createPlayerTeam()
{
GetTeamList().clear();
_playerTeam = new GameTeam(this, "Players", ChatColor.YELLOW, new ArrayList<>());
AddTeam(_playerTeam);
}
private void createChickenTeam()
{
_chickenTeam = new GameTeam(this, "Chickens", ChatColor.GRAY, _playerTeam.GetSpawns());
_chickenTeam.SetVisible(false);
AddTeam(_chickenTeam);
}
/*
* Preparing for start
*/
@EventHandler(priority = EventPriority.HIGH)
public void prepare(GameStateChangeEvent event)
{
@ -370,7 +353,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
{
for (Player player : GetPlayers(true))
{
_lives.put(player, MAX_LIVES);
_lives.put(player.getUniqueId(), MAX_LIVES);
}
}
@ -439,7 +422,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
_challenge.getData().setSpawns(selected);
_playerTeam.SetSpawns(selected);
SpectatorSpawn = _challenge.getCenter().add(0, SPECTATOR_SPAWN_HEIGHT, 0);
SpectatorSpawn = _challenge.getCenter().add(0.5, SPECTATOR_SPAWN_HEIGHT, 0.5);
return selected;
}
@ -450,13 +433,14 @@ public class BawkBawkBattles extends TeamGame implements IThrown
resetPlayers();
addEffectsToPlayers();
teleportSpectatorsToSpawn();
clearInventories();
}
private void resetPlayers()
{
for (Player player : GetPlayers(false))
for (Player player : GetPlayers(true))
{
if (_lives.get(player) > 0)
if (_lives.containsKey(player.getUniqueId()) && _lives.get(player.getUniqueId()) > 0)
{
Manager.Clear(player);
Scoreboard.setPlayerTeam(player, _playerTeam);
@ -468,7 +452,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
{
for (Player player : GetPlayers(false))
{
if (!IsAlive(player))
if (!IsAlive(player) && !_beingAttacked.contains(player.getUniqueId()))
{
player.teleport(GetSpectatorLocation());
}
@ -543,7 +527,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
if (!IsAlive(player))
return;
if (!getPlayersAlive().contains(player))
if (!IsAlive(player))
return;
if (!PrepareFreeze)
@ -663,6 +647,14 @@ public class BawkBawkBattles extends TeamGame implements IThrown
}
}
private void clearInventories()
{
for (Player player : GetPlayers(true))
{
UtilInv.Clear(player);
}
}
private void addEffectsToPlayers()
{
for (Player player : GetPlayers(true))
@ -885,36 +877,33 @@ public class BawkBawkBattles extends TeamGame implements IThrown
if (getPlayersWithRemainingLives() <= 1)
{
if (getPlayersAlive().size() > 0)
if (GetPlayers(true).size() > 0)
{
Player additional = getPlayersAlive().get(0);
_winners.add(0, additional);
Player additional = GetPlayers(true).get(0);
_winners.addFirst(additional);
}
if (_winners.size() > 2)
{
Collections.swap(_winners, SEMIFINAL_INDEX, FINAL_INDEX);
}
List<Player> actualWinners = _winners.subList(0, Math.min(_winners.size(), 3));
if (_winners.size() >= 1)
if (actualWinners.size() >= 1)
{
AddGems(_winners.get(FIRST_WINNER_INDEX), FIRST_PLACE_GEM_REWARD, "First Place", false, false);
AddGems(actualWinners.get(FIRST_WINNER_INDEX), FIRST_PLACE_GEM_REWARD, "First Place", false, false);
if (_winners.size() >= 2)
if (actualWinners.size() >= 2)
{
AddGems(_winners.get(SECOND_WINNER_INDEX), SECOND_PLACE_GEM_REWARD, "Second Place", false, false);
AddGems(actualWinners.get(SECOND_WINNER_INDEX), SECOND_PLACE_GEM_REWARD, "Second Place", false, false);
if (_winners.size() >= 3)
if (actualWinners.size() >= 3)
{
AddGems(_winners.get(THIRD_WINNER_INDEX), THIRD_PLACE_GEM_REWARD, "Third Place", false, false);
AddGems(actualWinners.get(THIRD_WINNER_INDEX), THIRD_PLACE_GEM_REWARD, "Third Place", false, false);
}
}
}
for (Player player : super.GetPlayers(false))
for (Player player : GetPlayers(false))
AddGems(player, PARTICIPATION_GEMS, "Participation", false, false);
AnnounceEnd(_winners);
AnnounceEnd(actualWinners);
SetState(GameState.End);
}
}
@ -937,21 +926,18 @@ public class BawkBawkBattles extends TeamGame implements IThrown
private boolean canStartCrumbling()
{
int lost = _challenge.getData().getLostPlayers().size();
int current = getPlayersAlive().size();
int current = GetPlayers(true).size();
return !_settings.isCrumbling() && lost > current / CRUMBLE_DIVIDER;
}
private void announceCrumbling()
{
for (Player player : UtilServer.getPlayers())
{
if (!_chickenTeam.HasPlayer(player))
for (Player player : GetPlayers(true))
{
UtilPlayer.message(player, F.main("Game", "The map has started to crumble."));
}
}
}
/*
* Messages
@ -1006,13 +992,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
if (event.getType() != UpdateType.SEC)
return;
if (_chickenTeam == null)
return;
if (_chickenTeam.GetSize() == 0)
return;
for (Player player : _chickenTeam.GetPlayers(true))
_beingAttacked.stream().map(Bukkit::getPlayer).filter(Objects::nonNull).forEach(player ->
{
Chicken chicken = UtilMath.randomElement(_chickenAttack.getChickens());
Material feetType = chicken.getLocation().getBlock().getType();
@ -1033,7 +1013,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
Manager.GetProjectile().AddThrow(chicken, null, this, -1, true, false, false, true, CHICKEN_ATTACK_HITBOX_GROW);
}
}
});
}
@EventHandler
@ -1068,12 +1048,39 @@ public class BawkBawkBattles extends TeamGame implements IThrown
Player player = event.getEntity();
if (!_chickenTeam.HasPlayer(player))
if (IsAlive(player))
return;
_chickenAttack.kill(player, true);
}
@Override
public void disqualify(Player player)
{
RemoveTeamPreference(player);
GetPlayerKits().remove(player);
GetPlayerGems().remove(player);
//Remove Team
GameTeam team = GetTeam(player);
if (team != null)
{
if (InProgress())
{
getPlayerTeam().SetPlayerState(player, GameTeam.PlayerState.OUT);
int alive = getPlayersWithRemainingLives();
if (alive > Challenge.CHICKEN_ATTACK_CRITERIA)
getChickenAttack().start(player);
else
getChickenAttack().kill(player, true);
}
else
team.RemovePlayer(player);
}
}
@EventHandler
public void blockChickenAttackMemberDamage(EntityDamageEvent event)
{
@ -1107,8 +1114,14 @@ public class BawkBawkBattles extends TeamGame implements IThrown
for (Player player : GetPlayers(true))
{
for (Player other : _chickenTeam.GetPlayers(false))
for (Player other : GetPlayers(false))
{
if (IsAlive(other))
continue;
if (_beingAttacked.contains(other.getUniqueId()))
continue;
if (player.equals(other))
continue;
@ -1139,7 +1152,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
Player player = event.getPlayer();
if (_challenge.getData().isDone(player) && !_chickenTeam.HasPlayer(player.getName(), false))
if (_challenge.getData().isDone(player) && IsAlive(player))
{
if (event.getTo().getY() <= 0)
{
@ -1199,7 +1212,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
{
Player player = event.getPlayer();
_lives.remove(player);
_lives.remove(player.getUniqueId());
_winners.remove(player);
}
@ -1219,19 +1232,16 @@ public class BawkBawkBattles extends TeamGame implements IThrown
// }
// }
@Override
public boolean shouldHeal(Player player)
{
return !_beingAttacked.contains(player.getUniqueId());
}
/*
* Miscellaneous
*/
@EventHandler
public void blockTeleport(MineplexTeleportEvent event)
{
if (!IsLive())
return;
event.setCancelled(true);
}
@EventHandler
public void blockDeathEffectHeadModification(PlayerArmorStandManipulateEvent event)
{
@ -1349,6 +1359,9 @@ public class BawkBawkBattles extends TeamGame implements IThrown
if (event.getType() != UpdateType.FAST)
return;
if (!IsLive())
return;
Scoreboard.reset();
if (getPlayersWithRemainingLives() >= GENERIC_SCOREBOARD_PLAYER_COUNT)
@ -1430,7 +1443,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
{
Scoreboard.writeNewLine();
Scoreboard.writeGroup(super.GetPlayers(true), player ->
Scoreboard.writeGroup(GetPlayers(true), player ->
{
int lives = lives(player);
String state = definePlayerState(player);
@ -1477,74 +1490,6 @@ public class BawkBawkBattles extends TeamGame implements IThrown
return "";
}
// @EventHandler
// public void debugCommands(PlayerCommandPreprocessEvent event)
// {
// Player player = event.getPlayer();
// String message = event.getMessage();
//
// if (Manager.GetClients().hasRank(player, Rank.SNR_MODERATOR))
// {
// if (message.startsWith("/restrict"))
// {
// String[] pieces = message.split(" ");
//
// if (pieces.length > 1)
// {
// String challenge = F.combine(pieces, 1, null, false).trim();
//
// if (_list.restrict(challenge))
// {
// UtilPlayer.message(player, F.main("Game", "Restricted to " + F.elem(challenge) + " challenge."));
// }
// else
// {
// UtilPlayer.message(player, F.main("Game", "Could not find any challenge by that name."));
// }
// }
// else
// {
// UtilPlayer.message(player, F.main("Game", "All challenge restrictions were cleared."));
// _list.unrestrict();
// }
//
// event.setCancelled(true);
// }
// else if (message.startsWith("/skip"))
// {
// if (IsLive())
// {
// endCurrentChallenge();
//
// Announce(C.cAqua + C.Bold + player.getName() + " skipped this challenge.");
// }
// else
// {
// UtilPlayer.message(player, F.main("Game", "You cannot skip a challenge if the game is not started."));
// }
//
// event.setCancelled(true);
// }
// else if (message.startsWith("/lose"))
// {
// if (IsLive() && _challenge != null && IsAlive(player))
// {
// setLives(player, 0);
// _challenge.getData().addLostPlayer(player);
// _deathEffect.playDeath(player, player.getLocation());
// GetScoreboard().ResetScore(player.getName());
// _chickenAttack.start(player);
// }
// else
// {
// UtilPlayer.message(player, F.main("Game", "You cannot lose at this time."));
// }
//
// event.setCancelled(true);
// }
// }
// }
/*
* Helper methods
*/
@ -1562,10 +1507,12 @@ public class BawkBawkBattles extends TeamGame implements IThrown
public int lives(Player player)
{
if (!_lives.containsKey(player))
if (!_lives.containsKey(player.getUniqueId()))
{
return 0;
}
return _lives.get(player);
return _lives.get(player.getUniqueId());
}
/*
@ -1574,7 +1521,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
public void setLives(Player player, int amount)
{
_lives.put(player, amount);
_lives.put(player.getUniqueId(), amount);
}
/*
@ -1586,11 +1533,6 @@ public class BawkBawkBattles extends TeamGame implements IThrown
return _playerTeam;
}
public GameTeam getChickenTeam()
{
return _chickenTeam;
}
public Challenge getCurrentChallenge()
{
return _challenge;
@ -1602,14 +1544,17 @@ public class BawkBawkBattles extends TeamGame implements IThrown
}
@Override
public List<Player> getWinners()
public LinkedList<Player> getWinners()
{
return _winners;
}
public Map<Player, Integer> getLives()
@Override
public List<Player> getLosers()
{
return _lives;
List<Player> players = new ArrayList<>(UtilServer.getPlayersCollection());
players.removeAll(getWinners());
return players;
}
public BawkBawkBattlesSettings getSettings()
@ -1636,40 +1581,6 @@ public class BawkBawkBattles extends TeamGame implements IThrown
* Player related getter methods
*/
/**
* Returns the list of players contained on the player's team.
*
* @param aliveOnly Whether or not to select all players.
*/
@Override
public ArrayList<Player> GetPlayers(boolean aliveOnly)
{
if (_playerTeam != null)
return _playerTeam.GetPlayers(aliveOnly);
else
return super.GetPlayers(aliveOnly);
}
/**
* Returns the list of players that are alive.
* <br>
* Players are considered to be alive <b>after</b> they are teleported to challenge spawn locations.
*/
public ArrayList<Player> getPlayersAlive()
{
ArrayList<Player> list = new ArrayList<Player>();
for (Player player : GetPlayers(true))
{
if (!UtilPlayer.isSpectator(player))
{
list.add(player);
}
}
return list;
}
/**
* Returns the amount of players with more than one life.
*/
@ -1677,7 +1588,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
{
int amount = 0;
for (Player player : _lives.keySet())
for (Player player : GetPlayers(true))
{
if (lives(player) > 0)
{
@ -1709,7 +1620,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
{
Player player = (Player) target;
if (_chickenTeam.HasPlayer(player) && IsAlive(player))
if (_beingAttacked.contains(player.getUniqueId()))
{
player.playSound(player.getLocation(), Sound.CHICKEN_HURT, CHICKEN_HIT_PLAYER_SOUND_VOLUME, CHICKEN_HIT_PLAYER_SOUND_PITCH);
player.damage(CHICKEN_HIT_PLAYER_DAMAGE);

View File

@ -4,6 +4,13 @@ import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import net.minecraft.server.v1_8_R3.BlockPosition;
import net.minecraft.server.v1_8_R3.Blocks;
import net.minecraft.server.v1_8_R3.ChunkSection;
import net.minecraft.server.v1_8_R3.EnumSkyBlock;
import net.minecraft.server.v1_8_R3.IBlockData;
import net.minecraft.server.v1_8_R3.WorldServer;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.Effect;
@ -12,8 +19,10 @@ import org.bukkit.FireworkEffect.Type;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
@ -34,6 +43,7 @@ import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilItem;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
@ -49,6 +59,8 @@ import mineplex.core.projectile.ProjectileUser;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.core.condition.Condition.ConditionType;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.games.mineware.BawkBawkBattles;
import nautilus.game.arcade.game.games.mineware.events.ChallengeEndEvent;
import nautilus.game.arcade.game.games.mineware.events.ChallengeStartEvent;
@ -79,8 +91,8 @@ public abstract class Challenge implements Listener
private static final int BORDER_MAX_Z = 100;
private static final int COMPLETE_COUNT_DIVIDER = 2;
private static final int WINNER_ADD_CRITERIA = 3; // players
private static final int CHICKEN_ATTACK_CRITERIA = 2; // players
public static final int WINNER_ADD_CRITERIA = 3; // players
public static final int CHICKEN_ATTACK_CRITERIA = 2; // players
private static final int CHALLENGE_CLOAK_DURATION = 7777;
private static final int COMPLETION_GEMS = 3;
@ -174,7 +186,7 @@ public abstract class Challenge implements Listener
{
if (firstRun)
{
ArrayList<Player> players = Host.GetPlayers(false);
ArrayList<Player> players = Host.GetPlayers(true);
for (int i = 0; i < players.size(); i++)
{
@ -192,7 +204,7 @@ public abstract class Challenge implements Listener
}
else
{
Host.getPlayerTeam().SpawnTeleport(false);
Host.getPlayerTeam().SpawnTeleport(true);
}
}
@ -305,7 +317,7 @@ public abstract class Challenge implements Listener
@EventHandler(priority = EventPriority.MONITOR)
public void death(PlayerDeathEvent event)
{
if (!Host.IsLive() || Host.getChickenTeam().HasPlayer(event.getEntity()))
if (!Host.IsLive() || !Host.IsAlive(event.getEntity()))
return;
Player player = event.getEntity();
@ -319,17 +331,21 @@ public abstract class Challenge implements Listener
private void handleDeath(Player player)
{
int alive = Host.getPlayersWithRemainingLives();
int lives = loseLife(player);
if (lives <= 0 && alive <= WINNER_ADD_CRITERIA)
if (lives <= 0)
{
Host.getWinners().add(player);
}
Host.getPlayerTeam().SetPlayerState(player, GameTeam.PlayerState.OUT);
if (lives <= 0 && alive > CHICKEN_ATTACK_CRITERIA)
int alive = Host.getPlayersWithRemainingLives();
if (Host.lives(player) <= 0)
{
Host.getWinners().addFirst(player);
if (alive > Challenge.CHICKEN_ATTACK_CRITERIA)
Host.getChickenAttack().start(player);
else
Host.getChickenAttack().kill(player, true);
}
}
else
{
@ -355,6 +371,8 @@ public abstract class Challenge implements Listener
UtilPlayer.message(player, F.main("Game", C.cRed + "You failed to complete the task."));
Host.showLivesLeft(player);
Host.Manager.addSpectator(player, true);
if (UtilItem.matchesMaterial(player.getInventory().getItem(8), Material.WATCH))
player.getInventory().setItem(8, null);
Host.Manager.GetCondition().Factory().Cloak("Challenge Death", player, player, CHALLENGE_CLOAK_DURATION, true, true);
}
@ -400,7 +418,7 @@ public abstract class Challenge implements Listener
for (Player player : players)
{
if (!Host.getChickenTeam().HasPlayer(player) && Host.lives(player) > 0)
if (!Host.IsAlive(player) && Host.lives(player) > 0)
{
UtilTextBottom.display(C.Bold + "Next challenge will begin shortly.", player);
}
@ -523,30 +541,14 @@ public abstract class Challenge implements Listener
setCompleted(player, false);
}
protected void setLost(Player player, boolean cloak)
protected void setLost(Player player)
{
if (Data.isDone(player))
return;
Data.addLostPlayer(player);
loseLife(player);
if (cloak)
{
cloak(player, false);
}
UtilPlayer.message(player, F.main("Game", C.cRed + "You failed to complete the task."));
Host.showLivesLeft(player);
player.playSound(player.getLocation(), Sound.NOTE_BASS, LOST_SOUND_VOLUME, LOST_SOUND_PITCH);
UtilPlayer.clearPotionEffects(player);
UtilInv.Clear(player);
}
protected void setLost(Player player)
{
setLost(player, false);
handleDeath(player);
}
private void cloak(Player player, boolean completed)
@ -578,6 +580,39 @@ public abstract class Challenge implements Listener
UtilBlock.setQuick(block.getWorld(), block.getX(), block.getY(), block.getZ(), type.getId(), data);
}
public void setBlockReallyQuicklyAndDangerously(Block block, Material type, byte data)
{
World world = block.getWorld();
int x = block.getLocation().getBlockX();
int y = block.getLocation().getBlockY();
int z = block.getLocation().getBlockZ();
int i = x & 15;
int j = y;
int k = z & 15;
int cx = block.getX() >> 4;
int cz = block.getZ() >> 4;
if (!world.isChunkLoaded(cx, cz))
{
world.loadChunk(cx, cz, true);
}
WorldServer nmsWorld = ((CraftWorld) world).getHandle();
net.minecraft.server.v1_8_R3.Chunk chunk = nmsWorld.getChunkAt(x >> 4, z >> 4);
BlockPosition pos = new BlockPosition(x, y, z);
IBlockData ibd = net.minecraft.server.v1_8_R3.Block.getById(type.getId()).fromLegacyData(data);
ChunkSection chunksection = chunk.getSections()[y >> 4];
if (chunksection == null)
{
if (block != Blocks.AIR)
{
chunksection = chunk.getSections()[y >> 4] = new ChunkSection(y >> 4 << 4, !nmsWorld.worldProvider.o());
}
}
chunksection.setType(i, j & 15, k, ibd);
nmsWorld.notify(pos);
}
public void setBlock(Block block, Material type)
{
setBlock(block, type, (byte) 0);
@ -819,7 +854,7 @@ public abstract class Challenge implements Listener
public ArrayList<Player> getPlayersAlive()
{
return Host.getPlayersAlive();
return Host.GetPlayers(true);
}
public ArrayList<Player> getPlayersIn(boolean ignoreCompleted)
@ -864,7 +899,7 @@ public abstract class Challenge implements Listener
public int getArenaSize(int minBlocks)
{
int size = (int) (minBlocks + Math.ceil(Host.getPlayersWithRemainingLives() / ARENA_SIZE_DIVIDER));
return size > ARENA_SIZE_LIMIT ? ARENA_SIZE_LIMIT : size;
return Math.min(size, ARENA_SIZE_LIMIT);
}
public BawkBawkBattles getHost()

View File

@ -140,7 +140,7 @@ public abstract class TeamChallenge extends Challenge
*/
protected void autoSelectTeams()
{
ArrayList<Player> players = Host.GetPlayers(false);
ArrayList<Player> players = Host.GetPlayers(true);
Collections.shuffle(players);
int size = 0;

View File

@ -74,7 +74,7 @@ public class ChallengeBouncingBlock extends Challenge implements LogicTracker
"Bouncing Block",
"Jump and punch floating wool blocks.",
"Avoid landing on red wool.",
"First to " + SCORE_GOAL + " wins!");
"Get to " + SCORE_GOAL + " to win!");
Settings.setUseMapHeight();
}

View File

@ -57,7 +57,7 @@ public class ChallengeBuildRace extends Challenge implements LogicTracker
ChallengeType.FirstComplete,
"Build Race",
"Your inventory is filled with blocks.",
"Place them all in the ground!");
"Place them all on the ground!");
Settings.setUseMapHeight();
}

View File

@ -13,6 +13,8 @@ import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilTextBottom;
@ -32,8 +34,9 @@ public class ChallengeColorChange extends Challenge
private static final int MAP_HEIGHT = 1;
private static final long TIME_DELAY = 5000;
private static final int TIME_DELAY_DECREMENT_RATE = 100;
private static final int RESET_DELAY = 4000;
private static final int RESET_DELAY = 3750;
private static final int TIME_DELAY_DECREMENT_RATE = 600;
private static final int TIME_DELAY_MIN = 1500;
private static final int PLATFORM_MULTIPLIER = 2;
private static final int PLATFORM_SHIFT = 2;
@ -96,6 +99,12 @@ public class ChallengeColorChange extends Challenge
_stageDelay = System.currentTimeMillis() + _modifiedTimeDelay;
_currentColor = UtilMath.randomElement(_colors);
for (Player player : Host.GetPlayers(false))
{
PotionEffect nightVision = new PotionEffect(PotionEffectType.NIGHT_VISION, 100000, 1, true, false);
player.addPotionEffect(nightVision);
}
fillItem(new ItemStack(Material.STAINED_CLAY, 1, (short) _currentColor));
}
@ -105,6 +114,11 @@ public class ChallengeColorChange extends Challenge
_isFalling = false;
_lastSound = 0;
_lastGeneratedPlatforms.clear();
for (Player player : Host.GetPlayers(false))
{
player.removePotionEffect(PotionEffectType.NIGHT_VISION);
}
}
@EventHandler
@ -124,22 +138,26 @@ public class ChallengeColorChange extends Challenge
if (_isFalling)
{
removeAllPlatforms();
playFallSound();
_isFalling = false;
_modifiedTimeDelay -= TIME_DELAY_DECREMENT_RATE;
_stageDelay = System.currentTimeMillis() + _modifiedTimeDelay;
_currentColor = UtilMath.randomElement(_colors);
createMap();
addCurrentColorToInventory();
_modifiedTimeDelay -= TIME_DELAY_DECREMENT_RATE;
_modifiedTimeDelay = Math.max(_modifiedTimeDelay, TIME_DELAY_MIN);
_stageDelay = System.currentTimeMillis() + _modifiedTimeDelay;
}
else
{
_isFalling = true;
_stageDelay = System.currentTimeMillis() + RESET_DELAY;
removeDifferentColorPlatforms();
_stageDelay = System.currentTimeMillis() + RESET_DELAY;
}
}
else if (!_isFalling)
@ -210,7 +228,7 @@ public class ChallengeColorChange extends Challenge
for (int z = 0; z <= 1; z++)
{
Block block = getCenter().getBlock().getRelative(platformX + x, 0, platformZ + z);
setBlock(block, Material.STAINED_CLAY, color);
setBlockReallyQuicklyAndDangerously(block, Material.STAINED_CLAY, color);
addBlock(block);
}
}
@ -242,7 +260,28 @@ public class ChallengeColorChange extends Challenge
if (block.getData() != _currentColor)
{
resetBlock(block);
setBlockReallyQuicklyAndDangerously(block, Material.AIR, (byte) 0);
}
}
}
}
}
@SuppressWarnings("deprecation")
private void removeAllPlatforms()
{
for (Entry<Integer, Integer> platform : _lastGeneratedPlatforms)
{
for (int x = 0; x <= 1; x++)
{
for (int z = 0; z <= 1; z++)
{
Block block = getCenter().getBlock().getRelative(platform.getKey() + x, 0, platform.getValue() + z);
if (block.getType() != Material.AIR)
{
setBlockReallyQuicklyAndDangerously(block, Material.AIR, (byte) 0);
}
}
}

View File

@ -121,7 +121,6 @@ public class ChallengeEggSmash extends Challenge implements NumberTracker
remove(EntityType.FALLING_BLOCK);
}
@SuppressWarnings("deprecation")
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event)
{

View File

@ -74,7 +74,7 @@ public class ChallengeFastFood extends Challenge
ChallengeType.FirstComplete,
"Fast Food",
"Your inventory is full of food.",
"Punch to throw it in the ground.");
"Punch to throw it on the ground.");
Settings.setUseMapHeight();
}

View File

@ -14,6 +14,8 @@ import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import mineplex.core.common.util.UtilMath;
import mineplex.core.disguise.disguises.DisguiseMagmaCube;
@ -103,6 +105,11 @@ public class ChallengeLavaRun extends Challenge
_disappearingBlocks = DISSAPEARING_BLOCKS;
createLava();
disguisePlayers();
for (Player player : Host.GetPlayers(false))
{
PotionEffect nightVision = new PotionEffect(PotionEffectType.NIGHT_VISION, 100000, 1, true, false);
player.addPotionEffect(nightVision);
}
}
@Override
@ -123,6 +130,11 @@ public class ChallengeLavaRun extends Challenge
Host.Manager.GetDisguise().undisguise(player);
}
}
for (Player player : Host.GetPlayers(false))
{
player.removePotionEffect(PotionEffectType.NIGHT_VISION);
}
}
@EventHandler
@ -139,7 +151,7 @@ public class ChallengeLavaRun extends Challenge
if (_shouldMoveObsidian)
{
resetBlock(_obsidian);
setBlockReallyQuicklyAndDangerously(_obsidian, Material.AIR, (byte) 0);
generatePlatform();
_obsidian = createObsidianBlock();
blockBreakEffect(_obsidian, false);
@ -209,7 +221,7 @@ public class ChallengeLavaRun extends Challenge
for (int z = -getArenaSize(); z <= getArenaSize(); z++)
{
Block block = getCenter().getBlock().getRelative(x, MAP_HEIGHT, z);
setBlock(block, Material.GLASS);
setBlockReallyQuicklyAndDangerously(block, Material.GLASS, (byte) 0);
_platform.add(block);
addBlock(block);
}
@ -227,7 +239,7 @@ public class ChallengeLavaRun extends Challenge
for (int y = 0; y < MAP_HEIGHT; y++)
{
Block block = getCenter().getBlock().getRelative(x, y, z);
setBlock(block, Material.STATIONARY_LAVA);
setBlockReallyQuicklyAndDangerously(block, Material.STATIONARY_LAVA, (byte) 0);
addBlock(block);
}
}
@ -237,7 +249,7 @@ public class ChallengeLavaRun extends Challenge
private Block createObsidianBlock()
{
Block block = getCenter().add(UtilMath.r(_arenaStartSize), MAP_HEIGHT, UtilMath.r(_arenaStartSize)).getBlock();
setBlock(block, Material.OBSIDIAN);
setBlockReallyQuicklyAndDangerously(block, Material.OBSIDIAN, (byte) 0);
return block;
}
@ -283,14 +295,7 @@ public class ChallengeLavaRun extends Challenge
distance.put(part, part.getLocation().add(DISTANCE_XZ_ADD, 0, DISTANCE_XZ_ADD).distance(_obsidian.getLocation()));
}
Collections.sort(_platform, new Comparator<Block>()
{
@Override
public int compare(Block o1, Block o2)
{
return distance.get(o2).compareTo(distance.get(o1));
}
});
_platform.sort((o1, o2) -> distance.get(o2).compareTo(distance.get(o1)));
for (int i = 0; i < Math.min(_disappearingBlocks, _platform.size()); i++)
{
@ -299,7 +304,7 @@ public class ChallengeLavaRun extends Challenge
if (!block.equals(_obsidian)) // We do not want to remove the obsidian block.
{
_platform.remove(0);
resetBlock(block);
setBlockReallyQuicklyAndDangerously(block, Material.AIR, (byte) 0);
}
}
}

View File

@ -386,10 +386,17 @@ public class ChallengeWaterHorror extends Challenge
TNTPrimed explosive = dropsite.getWorld().spawn(dropsite, TNTPrimed.class);
explosive.setFuseTicks(TNT_EXPLODE_AFTER * TICK_MULTIPLIER);
double str = UtilAlg.calculateVelocity(dropsite.toVector(), target.toVector(), TNT_VELOCITY_HEIGHT).length() + TNT_VELOCITY_POWER_MIN;
if (((dropsite.getX() - target.getX()) * (dropsite.getX() - target.getX()) + (dropsite.getY() - target.getY()) * (dropsite.getY() - target.getY())) < 16)
{
str = 0;
}
UtilAction.velocity(
explosive,
UtilAlg.getTrajectory2d(dropsite, target),
UtilAlg.calculateVelocity(dropsite.toVector(), target.toVector(), TNT_VELOCITY_HEIGHT).length() + TNT_VELOCITY_POWER_MIN,
str,
true,
0,
TNT_VELOCITY_HEIGHT,

View File

@ -70,8 +70,7 @@ public class ChickenAttack
public void start(Player player)
{
_host.getPlayerTeam().RemovePlayer(player);
_host.getChickenTeam().AddPlayer(player, true);
_host._beingAttacked.add(player.getUniqueId());
UtilInv.Clear(player);
_host.Manager.Clear(player);
@ -96,7 +95,7 @@ public class ChickenAttack
@Override
public void run()
{
if (_host.IsLive() && _host.getChickenTeam().HasPlayer(player) && _host.IsAlive(player))
if (_host.IsLive() && _host._beingAttacked.contains(player.getUniqueId()))
{
UtilPlayer.message(player, F.main("Game", "You have been moved to spectators."));
kill(player, false);
@ -112,6 +111,7 @@ public class ChickenAttack
public void kill(Player player, boolean inform)
{
_host.Manager.Clear(player);
_host._beingAttacked.remove(player.getUniqueId());
if (inform)
{
@ -123,7 +123,6 @@ public class ChickenAttack
@Override
public void run()
{
_host.SetPlayerState(player, PlayerState.OUT);
DisguiseChicken disguise = new DisguiseChicken(player);
disguise.setBaby();

View File

@ -857,7 +857,7 @@ public class GameFlagManager implements Listener
if (team != null)
{
if (game.InProgress())
team.SetPlayerState(event.getPlayer(), PlayerState.OUT);
game.SetPlayerState(event.getPlayer(), PlayerState.OUT);
else
team.RemovePlayer(event.getPlayer());
}
@ -896,7 +896,7 @@ public class GameFlagManager implements Listener
//Not Playing
for (Player player : UtilServer.getPlayers())
{
if (game == null || game.GetState() == GameState.Recruit || !game.IsAlive(player))
if (game == null || game.GetState() == GameState.Recruit || (!game.IsAlive(player) && game.shouldHeal(player)))
{
player.setMaxHealth(20);
player.setHealth(20);
@ -1033,21 +1033,9 @@ public class GameFlagManager implements Listener
return;
//Remove Kit
game.RemoveTeamPreference(event.getPlayer());
game.GetPlayerKits().remove(event.getPlayer());
game.GetPlayerGems().remove(event.getPlayer());
game.disqualify(event.getPlayer());
//Remove Team
GameTeam team = game.GetTeam(event.getPlayer());
if (team != null)
{
if (game.InProgress())
team.SetPlayerState(event.getPlayer(), PlayerState.OUT);
else
team.RemovePlayer(event.getPlayer());
}
Manager.addSpectator(event.getPlayer(), false);
event.setCancelled(true);
}
@EventHandler