Skip to content

Commit

Permalink
Fixed spam in console,
Browse files Browse the repository at this point in the history
Fixed errors, when player tries join to the arena.
  • Loading branch information
pixkk committed Nov 1, 2022
1 parent 76d00c4 commit 00fdf14
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 45 deletions.
50 changes: 29 additions & 21 deletions src/com/tigerhix/vampirez/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import java.util.List;
import java.util.Random;

import static com.tigerhix.vampirez.Reason.INITIATIVE;


public class Game
{
Expand Down Expand Up @@ -72,28 +74,34 @@ public static void join(final Arena arena, final Gamer gamer) {
arena.broadcast(ChatColor.GREEN+"[VampireZ] "+ ChatColor.GOLD + gamer.name + " "+plugin.message.get().get("joined") +" (" + arena.gamers.size() + "/" + Config.maxPlayer + ")");
gamer.playing = arena;
final Player player = gamer.getPlayer();
Game.plugin.inventories.put(player.getName(), player.getInventory().getContents());
player.getInventory().clear();
Utils.updateInventoryLater(player);
World worldName = player.getLocation().getWorld();
worldName.setGameRule(GameRule.DO_IMMEDIATE_RESPAWN, true);
worldName.setGameRule(GameRule.SHOW_DEATH_MESSAGES, false);
try {
player.teleport(arena.lobbySpawn);
Game.plugin.inventories.put(player.getName(), player.getInventory().getContents());
player.getInventory().clear();
Utils.updateInventoryLater(player);
World worldName = player.getLocation().getWorld();
worldName.setGameRule(GameRule.DO_IMMEDIATE_RESPAWN, true);
worldName.setGameRule(GameRule.SHOW_DEATH_MESSAGES, false);

player.getInventory().setItem(8, ItemTemplate.SLIME_BALL.getItem());
player.setExp(0.0f);
player.setLevel(0);
player.setGameMode(GameMode.ADVENTURE);
player.setAllowFlight(false);
player.teleport(arena.lobbySpawn);

scoreboardgame(Bukkit.getScoreboardManager(), gamer.getPlayer(), arena, arena.gamers.size());
player.getInventory().setItem(8, ItemTemplate.SLIME_BALL.getItem());
player.setExp(0.0f);
player.setLevel(0);
player.setGameMode(GameMode.ADVENTURE);
player.setAllowFlight(false);

player.sendMessage(ChatColor.GREEN+"[VampireZ] "+ ChatColor.GOLD + ""+plugin.message.get().get("you-are-joined") +" "+plugin.message.get().get("map-name") +" "+ChatColor.GREEN+ "\""+ namearena+"\"");
if (arena.gamers.size() == Config.minPlayer) {
ready(arena, Config.minSeconds);
}
if (arena.gamers.size() == Config.maxPlayer) {
ready(arena, Config.maxSeconds);


scoreboardgame(Bukkit.getScoreboardManager(), gamer.getPlayer(), arena, arena.gamers.size());

player.sendMessage(ChatColor.GREEN+"[VampireZ] "+ ChatColor.GOLD + ""+plugin.message.get().get("you-are-joined") +" "+plugin.message.get().get("map-name") +" "+ChatColor.GREEN+ "\""+ namearena+"\"");
if (arena.gamers.size() == Config.minPlayer) {
ready(arena, Config.minSeconds);
}
if (arena.gamers.size() == Config.maxPlayer) {
ready(arena, Config.maxSeconds);
}
}catch (IllegalArgumentException e) {
leave(gamer, INITIATIVE);
}
}

Expand All @@ -102,7 +110,7 @@ public static void leave(final Gamer gamer, final String reason) {

final Arena arena = gamer.playing;
arena.gamers.remove(gamer);
if (reason.equals(Reason.INITIATIVE)) {
if (reason.equals(INITIATIVE)) {
arena.broadcastOthers(ChatColor.GREEN+"[VampireZ] "+ ChatColor.GOLD + plugin.message.get().get("player") + ChatColor.GOLD + " " + gamer.name + " "+ plugin.message.get().get("left-the-game") +" " +" (" + arena.gamers.size() + "/" + Config.maxPlayer + ")", gamer);
}
if (reason.equals(Reason.OPERATOR)) {
Expand Down
48 changes: 24 additions & 24 deletions src/com/tigerhix/vampirez/Listeners.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,16 @@ public void onPlayerChat(final AsyncPlayerChatEvent evt) {

}

@SuppressWarnings("deprecation")
@EventHandler
public void onLampOff(final BlockRedstoneEvent evt) {
for (final Sign sign : Listeners.plugin.signs.values()) {
final Block notifier = sign.block.getRelative(BlockFace.UP).getRelative(((Directional)sign.block.getType().getNewData(sign.block.getData())).getFacing().getOppositeFace());
if (notifier.getLocation().getBlockX() == evt.getBlock().getLocation().getBlockX() && notifier.getLocation().getBlockY() == evt.getBlock().getLocation().getBlockY() && notifier.getLocation().getBlockZ() == evt.getBlock().getLocation().getBlockZ()) {
evt.setNewCurrent(5);
}
}
}
// @SuppressWarnings("deprecation")
// @EventHandler
// public void onLampOff(final BlockRedstoneEvent evt) {
// for (final Sign sign : Listeners.plugin.signs.values()) {
// final Block notifier = sign.block.getRelative(BlockFace.UP).getRelative(((Directional)sign.block.getType().getNewData(sign.block.getData())).getFacing().getOppositeFace());
// if (notifier.getLocation().getBlockX() == evt.getBlock().getLocation().getBlockX() && notifier.getLocation().getBlockY() == evt.getBlock().getLocation().getBlockY() && notifier.getLocation().getBlockZ() == evt.getBlock().getLocation().getBlockZ()) {
// evt.setNewCurrent(5);
// }
// }
// }

@EventHandler
public void onRightClickShop(final PlayerInteractEvent evt) {
Expand Down Expand Up @@ -381,20 +381,20 @@ public void onBreakDoor(final EntityBreakDoorEvent evt) {
}
}

@SuppressWarnings("deprecation")
@EventHandler
public void onStep(final PlayerInteractEvent evt) {
if (Utils.getGamer(evt.getPlayer()) == null) {
return;
}
if (Utils.getGamer(evt.getPlayer()).playing == null) {
return;
}
if (evt.getAction() != Action.PHYSICAL || evt.getClickedBlock().getType() != Material.LEGACY_SOIL) {
return;
}
evt.setCancelled(true);
}
// @SuppressWarnings("deprecation")
// @EventHandler
// public void onStep(final PlayerInteractEvent evt) {
// if (Utils.getGamer(evt.getPlayer()) == null) {
// return;
// }
// if (Utils.getGamer(evt.getPlayer()).playing == null) {
// return;
// }
// if (evt.getAction() != Action.PHYSICAL || evt.getClickedBlock().getType() != Material.LEGACY_SOIL) {
// return;
// }
// evt.setCancelled(true);
// }

@EventHandler
public void onPlaceBlock(final BlockPlaceEvent evt) {
Expand Down

0 comments on commit 00fdf14

Please sign in to comment.