* ALLOT of bug fixes. Can't split them!

This commit is contained in:
Steffion 2013-08-17 20:08:33 +02:00
parent 4fdbdf6e65
commit 946a20c647
7 changed files with 275 additions and 78 deletions

View File

@ -24,6 +24,10 @@ public class ArenaHandler {
for (String arenaName : W.arenas.getFile().getKeys(false)) {
W.arenaList.add((Arena) W.arenas.getFile().get(arenaName));
}
for (Arena arena : W.arenaList) {
ScoreboardHandler.createScoreboard(arena);
}
}
public static void sendMessage(Arena arena, String message, Boolean tag,
@ -86,20 +90,63 @@ public class ArenaHandler {
}
arena.playersInArena.add(player);
W.pLocation.put(player,
player.getLocation());
W.pGameMode.put(player,
player.getGameMode());
// OLD WAY OF SETTING A PLAYER'S DATA.
// W.pLocation.put(player,
// player.getLocation());
// W.pGameMode.put(player,
// player.getGameMode());
//
// player.teleport(arena.lobbyWarp);
// player.setGameMode(GameMode.SURVIVAL);
//
// W.pInventory.put(player, player
// .getInventory().getContents());
// player.getInventory().clear();
// player.updateInventory();
// W.pArmor.put(player,
// player.getInventory()
// .getArmorContents());
// player.getInventory().setHelmet(
// new ItemStack(Material.AIR));
// player.getInventory().setChestplate(
// new ItemStack(Material.AIR));
// player.getInventory().setLeggings(
// new ItemStack(Material.AIR));
// player.getInventory().setBoots(
// new ItemStack(Material.AIR));
// W.pEXP.put(player, player.getExp());
// player.setExp(0);
// W.pEXPL.put(player, player.getLevel());
// player.setLevel(0);
// W.pHealth.put(player,
// player.getHealth());
// player.setHealth(20);
// W.pFood.put(player,
// player.getFoodLevel());
// player.setFoodLevel(20);
PlayerArenaData pad = new PlayerArenaData(
player.getLocation(),
player.getGameMode(), player
.getInventory()
.getContents(), player
.getInventory()
.getArmorContents(),
player.getExp(), player.getLevel(),
player.getHealth(),
player.getFoodLevel(),
player.getActivePotionEffects());
W.pData.put(player, pad);
player.teleport(arena.lobbyWarp);
player.setGameMode(GameMode.SURVIVAL);
W.pInventory.put(player, player
.getInventory().getContents());
player.getActivePotionEffects().clear();
player.setFoodLevel(20);
player.setHealth(20);
player.setLevel(arena.timer);
player.setExp(0);
player.getInventory().clear();
player.updateInventory();
W.pArmor.put(player, player.getInventory()
.getArmorContents());
player.getInventory().setHelmet(
new ItemStack(Material.AIR));
player.getInventory().setChestplate(
@ -108,14 +155,11 @@ public class ArenaHandler {
new ItemStack(Material.AIR));
player.getInventory().setBoots(
new ItemStack(Material.AIR));
W.pEXP.put(player, player.getExp());
player.setExp(0);
W.pEXPL.put(player, player.getLevel());
player.setLevel(0);
W.pHealth.put(player, player.getHealth());
player.setHealth(20);
W.pFood.put(player, player.getFoodLevel());
player.setFoodLevel(20);
player.updateInventory();
if (W.dcAPI.isDisguised(player)) {
W.dcAPI.undisguisePlayer(player);
}
ArenaHandler.sendFMessage(arena,
ConfigC.normal_joinJoinedArena,
@ -176,18 +220,31 @@ public class ArenaHandler {
if (arena.seekers.contains(player)) {
arena.seekers.remove(player);
}
if (arena.playersInArena.size() <= arena.minPlayers) {
if (arena.gameState.equals(ArenaState.STARTING)) {
arena.gameState = ArenaState.WAITING;
arena.timer = 0;
ArenaHandler.sendFMessage(arena,
ConfigC.warning_lobbyNeedAtleast, true, "1-"
+ arena.minPlayers);
} else {
if (arena.playersInArena.size() < arena.minPlayers
&& arena.gameState.equals(ArenaState.STARTING)) {
arena.gameState = ArenaState.WAITING;
arena.timer = 0;
ArenaHandler.sendFMessage(arena,
ConfigC.warning_lobbyNeedAtleast, true, "1-"
+ arena.minPlayers);
}
if (arena.playersInArena.size() <= 1
&& arena.gameState == ArenaState.INGAME) {
if (arena.seekers.size() >= arena.playersInArena.size()) {
ArenaHandler.seekersWin(arena);
} else {
ArenaHandler.hidersWin(arena);
}
} else if (arena.seekers.size() <= 0
}
if (arena.seekers.size() >= arena.playersInArena.size()) {
ArenaHandler.seekersWin(arena);
}
if (arena.seekers.size() <= 0
&& arena.gameState == ArenaState.INGAME) {
Player seeker = arena.playersInArena.get(W.random
.nextInt(arena.playersInArena.size()));
@ -205,34 +262,63 @@ public class ArenaHandler {
}
}
// OLD WAY OF RESETTING A PLAYER'S DATA.
// player.getInventory().clear();
// player.getInventory().setContents(W.pInventory.get(player));
// player.updateInventory();
// W.pInventory.remove(player);
// player.getInventory().setArmorContents(W.pArmor.get(player));
// W.pArmor.remove(player);
// player.setExp(W.pEXP.get(player));
// W.pEXP.remove(player);
// player.setLevel(W.pEXPL.get(player));
// W.pEXPL.remove(player);
// player.setHealth(W.pHealth.get(player));
// W.pHealth.remove(player);
// player.setFoodLevel(W.pFood.get(player));
// W.pFood.remove(player);
// W.pBlock.remove(player);
//
// player.teleport(W.pLocation.get(player));
//
// player.setGameMode(W.pGameMode.get(player));
// W.pGameMode.remove(player);
// W.pLocation.remove(player);
PlayerArenaData pad = new PlayerArenaData(null, null, null, null,
null, null, null, null, null);
if (W.pData.get(player) != null) {
pad = W.pData.get(player);
}
player.getInventory().clear();
player.getInventory().setContents(W.pInventory.get(player));
player.getInventory().setContents(pad.pInventory);
player.getInventory().setArmorContents(pad.pArmor);
player.updateInventory();
W.pInventory.remove(player);
player.getInventory().setArmorContents(W.pArmor.get(player));
W.pArmor.remove(player);
player.setExp(W.pEXP.get(player));
W.pEXP.remove(player);
player.setLevel(W.pEXPL.get(player));
W.pEXPL.remove(player);
player.setHealth(W.pHealth.get(player));
W.pHealth.remove(player);
player.setFoodLevel(W.pFood.get(player));
W.pFood.remove(player);
W.pBlock.remove(player);
player.setExp(pad.pEXP);
player.setLevel(pad.pEXPL);
player.setHealth(pad.pHealth);
player.setFoodLevel(pad.pFood);
player.addPotionEffects(pad.pPotionEffects);
player.teleport(pad.pLocation);
player.setGameMode(pad.pGameMode);
player.teleport(W.pLocation.get(player));
player.setGameMode(W.pGameMode.get(player));
W.pGameMode.remove(player);
W.pLocation.remove(player);
W.pData.remove(player);
for (Player pl : Bukkit.getOnlinePlayers()) {
pl.showPlayer(player);
if (W.hiddenLoc.get(player) != null) {
Block pBlock = W.hiddenLoc.get(player).getBlock();
pl.sendBlockChange(pBlock.getLocation(), Material.AIR,
(byte) 0);
if (W.hiddenLocWater.get(player) != null) {
Block pBlock = W.hiddenLoc.get(player).getBlock();
if (W.hiddenLocWater.get(player)) {
pl.sendBlockChange(pBlock.getLocation(),
Material.STATIONARY_WATER, (byte) 0);
} else {
pl.sendBlockChange(pBlock.getLocation(),
Material.AIR, (byte) 0);
}
}
}
if (W.dcAPI.isDisguised(player)) {
@ -263,8 +349,6 @@ public class ArenaHandler {
public static void seekersWin(Arena arena) {
ArenaHandler.sendFMessage(arena, ConfigC.normal_winSeekers, true);
for (Player player : arena.playersInArena) {
playerLeaveArena(player, false, false);
player.playSound(player.getLocation(), Sound.LEVEL_UP, 1, 1);
if (arena.seekersWinCommands != null) {
for (String command : arena.seekersWinCommands) {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(),
@ -273,16 +357,21 @@ public class ArenaHandler {
}
}
arena.playersInArena.clear();
arena.seekers.clear();
for (Player player : arena.playersInArena) {
playerLeaveArena(player, false, false);
player.playSound(player.getLocation(), Sound.LEVEL_UP, 1, 1);
}
arena.gameState = ArenaState.WAITING;
arena.timer = 0;
arena.playersInArena.clear();
}
public static void hidersWin(Arena arena) {
ArenaHandler.sendFMessage(arena, ConfigC.normal_winHiders, true);
for (Player player : arena.playersInArena) {
playerLeaveArena(player, false, false);
player.playSound(player.getLocation(), Sound.LEVEL_UP, 1, 1);
if (!arena.seekers.contains(player)) {
if (arena.hidersWinCommands != null) {
for (String command : arena.hidersWinCommands) {
@ -294,21 +383,30 @@ public class ArenaHandler {
}
}
arena.playersInArena.clear();
arena.seekers.clear();
for (Player player : arena.playersInArena) {
playerLeaveArena(player, false, false);
player.playSound(player.getLocation(), Sound.LEVEL_UP, 1, 1);
}
arena.gameState = ArenaState.WAITING;
arena.gameTime = 0;
arena.timer = 0;
arena.playersInArena.clear();
}
public static void stopArena(Arena arena) {
ArenaHandler.sendFMessage(arena, ConfigC.warning_arenaStopped, true);
arena.seekers.clear();
for (Player player : arena.playersInArena) {
playerLeaveArena(player, false, false);
player.playSound(player.getLocation(), Sound.LEVEL_UP, 1, 1);
}
arena.playersInArena.clear();
arena.seekers.clear();
arena.gameState = ArenaState.WAITING;
arena.gameTime = 0;
arena.timer = 0;
arena.playersInArena.clear();
}
}

View File

@ -451,6 +451,17 @@ public class BlockHunt extends JavaPlugin implements Listener {
true);
}
for (Player pl : Bukkit
.getOnlinePlayers()) {
if (!pl.equals(player)) {
pl.hidePlayer(player);
pl.sendBlockChange(
pBlock.getLocation(),
block.getType(),
(byte) block
.getDurability());
}
}
}
} else {
Block pBlock = player.getLocation()
@ -468,7 +479,7 @@ public class BlockHunt extends JavaPlugin implements Listener {
if (W.hiddenLocWater
.get(player) != null) {
if (W.hiddenLocWater
.get(player) == true) {
.get(player)) {
pl.sendBlockChange(
pBlock.getLocation(),
Material.STATIONARY_WATER,
@ -528,7 +539,7 @@ public class BlockHunt extends JavaPlugin implements Listener {
pl.setGameMode(GameMode.SURVIVAL);
}
ScoreboardHandler.doScoreboard(arena);
ScoreboardHandler.updateScoreboard(arena);
}
SignsHandler.updateSigns();

View File

@ -3,6 +3,7 @@ package nl.Steffion.BlockHunt.Commands;
import java.util.ArrayList;
import nl.Steffion.BlockHunt.Arena;
import nl.Steffion.BlockHunt.ScoreboardHandler;
import nl.Steffion.BlockHunt.W;
import nl.Steffion.BlockHunt.Arena.ArenaState;
import nl.Steffion.BlockHunt.Managers.CommandC;
@ -11,6 +12,7 @@ import nl.Steffion.BlockHunt.Managers.MessageM;
import nl.Steffion.BlockHunt.Managers.PlayerM;
import nl.Steffion.BlockHunt.Managers.PlayerM.PermsC;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@ -40,12 +42,15 @@ public class CMDcreate extends DefaultCMD {
new ArrayList<String>(),
new ArrayList<Player>(),
ArenaState.WAITING, 0,
new ArrayList<Player>());
new ArrayList<Player>(), Bukkit
.getScoreboardManager()
.getNewScoreboard());
W.arenas.getFile().set(args[1], arena);
W.arenas.save();
W.signs.load();
W.arenaList.add((Arena) arena);
ScoreboardHandler.createScoreboard(arena);
MessageM.sendFMessage(player,
ConfigC.normal_createCreatedArena, true,

View File

@ -1,13 +1,14 @@
package nl.Steffion.BlockHunt.Listeners;
import nl.Steffion.BlockHunt.Arena;
import nl.Steffion.BlockHunt.ArenaHandler;
import nl.Steffion.BlockHunt.Arena.ArenaState;
import nl.Steffion.BlockHunt.Managers.ConfigC;
import nl.Steffion.BlockHunt.ArenaHandler;
import nl.Steffion.BlockHunt.W;
import nl.Steffion.BlockHunt.Managers.ConfigC;
import org.bukkit.Effect;
import org.bukkit.GameMode;
import org.bukkit.Sound;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -43,8 +44,10 @@ public class OnEntityDamageByEntityEvent implements Listener {
&& !arena.seekers.contains(player)) {
event.setCancelled(true);
} else {
player.getWorld().playSound(player.getLocation(),
Sound.HURT_FLESH, 1, 1);
player.getWorld().playEffect(player.getLocation(),
Effect.BOW_FIRE, 0);
Effect.ENDER_SIGNAL, 0);
if (event.getDamage() >= player.getHealth()) {
player.setHealth(20);

View File

@ -0,0 +1,35 @@
package nl.Steffion.BlockHunt;
import java.util.Collection;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
public class PlayerArenaData {
public Location pLocation;
public GameMode pGameMode;
public ItemStack[] pInventory;
public ItemStack[] pArmor;
public Float pEXP;
public Integer pEXPL;
public Double pHealth;
public Integer pFood;
public Collection<PotionEffect> pPotionEffects;
public PlayerArenaData (Location pLocation, GameMode pGameMode,
ItemStack[] pInventory, ItemStack[] pArmor, Float pEXP,
Integer pEXPL, Double pHealth, Integer pFood,
Collection<PotionEffect> pPotionEffects) {
this.pLocation = pLocation;
this.pGameMode = pGameMode;
this.pInventory = pInventory;
this.pArmor = pArmor;
this.pEXP = pEXP;
this.pEXPL = pEXPL;
this.pHealth = pHealth;
this.pFood = pFood;
this.pPotionEffects = pPotionEffects;
}
}

View File

@ -1,5 +1,6 @@
package nl.Steffion.BlockHunt;
import nl.Steffion.BlockHunt.Arena.ArenaState;
import nl.Steffion.BlockHunt.Managers.MessageM;
import org.bukkit.Bukkit;
@ -10,8 +11,13 @@ import org.bukkit.scoreboard.Score;
import org.bukkit.scoreboard.Scoreboard;
public class ScoreboardHandler {
public static void doScoreboard(Arena arena) {
Scoreboard board = Bukkit.getScoreboardManager().getNewScoreboard();
public static void createScoreboard(Arena arena) {
Scoreboard board = arena.scoreboard;
if (board.getObjective(arena.arenaName) != null) {
updateScoreboard(arena);
return;
}
Objective object = board.registerNewObjective(arena.arenaName, "dummy");
object.setDisplaySlot(DisplaySlot.SIDEBAR);
object.setDisplayName(MessageM.replaceAll(MessageM.CType.TAG()));
@ -24,9 +30,40 @@ public class ScoreboardHandler {
Score hiders = object.getScore(Bukkit.getOfflinePlayer(MessageM
.replaceAll("%NHiders:")));
hiders.setScore(arena.playersInArena.size() - arena.seekers.size());
if (arena.gameState == ArenaState.INGAME) {
for (Player pl : arena.playersInArena) {
pl.setScoreboard(board);
}
} else {
for (Player pl : arena.playersInArena) {
pl.setScoreboard(Bukkit.getScoreboardManager()
.getNewScoreboard());
}
}
}
for (Player pl : arena.playersInArena) {
pl.setScoreboard(board);
public static void updateScoreboard(Arena arena) {
Scoreboard board = arena.scoreboard;
Objective object = board.getObjective(DisplaySlot.SIDEBAR);
object.setDisplayName(MessageM.replaceAll(MessageM.CType.TAG()));
Score timeleft = object.getScore(Bukkit.getOfflinePlayer(MessageM
.replaceAll("%ATime left:")));
timeleft.setScore(arena.timer);
Score seekers = object.getScore(Bukkit.getOfflinePlayer(MessageM
.replaceAll("%NSeekers:")));
seekers.setScore(arena.seekers.size());
Score hiders = object.getScore(Bukkit.getOfflinePlayer(MessageM
.replaceAll("%NHiders:")));
hiders.setScore(arena.playersInArena.size() - arena.seekers.size());
if (arena.gameState == ArenaState.INGAME) {
for (Player pl : arena.playersInArena) {
pl.setScoreboard(board);
}
} else {
for (Player pl : arena.playersInArena) {
pl.setScoreboard(Bukkit.getScoreboardManager()
.getNewScoreboard());
}
}
}

View File

@ -8,7 +8,6 @@ import nl.Steffion.BlockHunt.Managers.ConfigM;
import nl.Steffion.BlockHunt.Managers.MessageM;
import nl.Steffion.BlockHunt.Serializables.LocationSerializable;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@ -38,16 +37,25 @@ public class W {
public static DisguiseCraftAPI dcAPI;
public static HashMap<Player, Integer> seekertime = new HashMap<Player, Integer>();
public static HashMap<Player, Location> pLocation = new HashMap<Player, Location>();
public static HashMap<Player, GameMode> pGameMode = new HashMap<Player, GameMode>();
public static HashMap<Player, ItemStack[]> pInventory = new HashMap<Player, ItemStack[]>();
public static HashMap<Player, ItemStack[]> pArmor = new HashMap<Player, ItemStack[]>();
public static HashMap<Player, Float> pEXP = new HashMap<Player, Float>();
public static HashMap<Player, Integer> pEXPL = new HashMap<Player, Integer>();
public static HashMap<Player, Double> pHealth = new HashMap<Player, Double>();
public static HashMap<Player, Integer> pFood = new HashMap<Player, Integer>();
public static HashMap<Player, ItemStack> pBlock = new HashMap<Player, ItemStack>();
public static HashMap<Player, PlayerArenaData> pData = new HashMap<Player, PlayerArenaData>();
// public static HashMap<Player, Location> pLocation = new HashMap<Player,
// Location>();
// public static HashMap<Player, GameMode> pGameMode = new HashMap<Player,
// GameMode>();
// public static HashMap<Player, ItemStack[]> pInventory = new
// HashMap<Player, ItemStack[]>();
// public static HashMap<Player, ItemStack[]> pArmor = new HashMap<Player,
// ItemStack[]>();
// public static HashMap<Player, Float> pEXP = new HashMap<Player, Float>();
// public static HashMap<Player, Integer> pEXPL = new HashMap<Player,
// Integer>();
// public static HashMap<Player, Double> pHealth = new HashMap<Player,
// Double>();
// public static HashMap<Player, Integer> pFood = new HashMap<Player,
// Integer>();
public static HashMap<Player, ItemStack> pBlock = new HashMap<Player, ItemStack>();
public static HashMap<Player, Location> moveLoc = new HashMap<Player, Location>();
public static HashMap<Player, Location> hiddenLoc = new HashMap<Player, Location>();
public static HashMap<Player, Boolean> hiddenLocWater = new HashMap<Player, Boolean>();