package cx.sfy.TheBridge.listeners; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Sign; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.SignChangeEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; import cx.sfy.TheBridge.Main; import cx.sfy.TheBridge.game.Game; import cx.sfy.TheBridge.game.GameFour; import cx.sfy.TheBridge.game.Game.State; import cx.sfy.TheBridge.game.GameFour.FState;; public class SetupListener implements Listener { Main plugin; public SetupListener(Main plugin) { this.plugin = plugin; } @SuppressWarnings("deprecation") @EventHandler public void onInteract(PlayerInteractEvent e) { Player p = e.getPlayer(); if (p.getItemInHand() == null || p.getItemInHand().getType() == Material.AIR) { return; } ItemStack item = p.getItemInHand(); if (item.getType() == Material.BLAZE_ROD && item.getItemMeta().getDisplayName().equalsIgnoreCase("§eSetup TheBridge")) { if (e.getAction().equals(Action.LEFT_CLICK_BLOCK)) { plugin.getSM().setMax(p, e.getClickedBlock().getLocation()); e.setCancelled(true); } if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) { plugin.getSM().setMin(p, e.getClickedBlock().getLocation()); e.setCancelled(true); } } } @EventHandler public void onSignChange(SignChangeEvent e) { Player p = e.getPlayer(); if (!p.hasPermission("bridges.admin")) { return; } if (e.getLine(0).equals("[bridges]")) { if (e.getLine(1).toLowerCase().equals("normal")) { String game = e.getLine(2); Sign sign = (Sign)e.getBlock().getState(); if (plugin.getGM().getGameByName(game) == null) { p.sendMessage("§cThis Game not exits."); return; } Game gname = plugin.getGM().getGameByName(game); plugin.getSIM().createSign(e.getBlock().getLocation(), game, sign); e.setLine(0, plugin.getLang().get("signs.normal.line-1").replaceAll("", getState(gname.getState())).replaceAll("", game).replaceAll("", String.valueOf(gname.getPlayers())).replaceAll("", String.valueOf(gname.getMax()))); e.setLine(1, plugin.getLang().get("signs.normal.line-2").replaceAll("", getState(gname.getState())).replaceAll("", game).replaceAll("", String.valueOf(gname.getPlayers())).replaceAll("", String.valueOf(gname.getMax()))); e.setLine(2, plugin.getLang().get("signs.normal.line-3").replaceAll("", getState(gname.getState())).replaceAll("", game).replaceAll("", String.valueOf(gname.getPlayers())).replaceAll("", String.valueOf(gname.getMax()))); e.setLine(3, plugin.getLang().get("signs.normal.line-4").replaceAll("", getState(gname.getState())).replaceAll("", game).replaceAll("", String.valueOf(gname.getPlayers())).replaceAll("", String.valueOf(gname.getMax()))); p.sendMessage("§aSign Normal added."); } else if (e.getLine(1).toLowerCase().equals("four")) { String game = e.getLine(2); Sign sign = (Sign)e.getBlock().getState(); if (plugin.getGM().getGameFourByName(game) == null) { p.sendMessage("§cThis Game not exits."); return; } GameFour gname = plugin.getGM().getGameFourByName(game); plugin.getSIM().createFourSign(e.getBlock().getLocation(), game, sign); e.setLine(0, plugin.getLang().get("signs.four.line-1").replaceAll("", getState(gname.getState())).replaceAll("", game).replaceAll("", String.valueOf(gname.getPlayers().size())).replaceAll("", String.valueOf(gname.getMax()))); e.setLine(1, plugin.getLang().get("signs.four.line-2").replaceAll("", getState(gname.getState())).replaceAll("", game).replaceAll("", String.valueOf(gname.getPlayers().size())).replaceAll("", String.valueOf(gname.getMax()))); e.setLine(2, plugin.getLang().get("signs.four.line-3").replaceAll("", getState(gname.getState())).replaceAll("", game).replaceAll("", String.valueOf(gname.getPlayers().size())).replaceAll("", String.valueOf(gname.getMax()))); e.setLine(3, plugin.getLang().get("signs.four.line-4").replaceAll("", getState(gname.getState())).replaceAll("", game).replaceAll("", String.valueOf(gname.getPlayers().size())).replaceAll("", String.valueOf(gname.getMax()))); p.sendMessage("§aSign Four added."); } } } protected String getState(State state) { if (state == State.WAITING) { return plugin.getLang().get("states.waiting"); } if (state == State.STARTING) { return plugin.getLang().get("states.starting"); } if (state == State.PREGAME) { return plugin.getLang().get("states.pregame"); } if (state == State.INGAME) { return plugin.getLang().get("states.ingame"); } if (state == State.FINISH) { return plugin.getLang().get("states.finish"); } if (state == State.RESTARTING) { return plugin.getLang().get("states.restarting"); } return ""; } protected String getState(FState state) { if (state == FState.WAITING) { return plugin.getLang().get("states.waiting"); } if (state == FState.STARTING) { return plugin.getLang().get("states.starting"); } if (state == FState.PREGAME) { return plugin.getLang().get("states.pregame"); } if (state == FState.INGAME) { return plugin.getLang().get("states.ingame"); } if (state == FState.FINISH) { return plugin.getLang().get("states.finish"); } if (state == FState.RESTARTING) { return plugin.getLang().get("states.restarting"); } return ""; } @EventHandler public void onBreak(BlockBreakEvent e) { Player p = e.getPlayer(); if (!p.hasPermission("bridges.admin")) { return; } if (plugin.getSIM().getSigns().keySet().contains(e.getBlock().getLocation())) { plugin.getSigns().set("signs.normal." + plugin.getSIM().getSigns().get(e.getBlock().getLocation()).getGame(), null); plugin.getSigns().save(); p.sendMessage("§cSign normal removed."); } else if (plugin.getSIM().getFourSigns().keySet().contains(e.getBlock().getLocation())) { plugin.getSigns().set("signs.four." + plugin.getSIM().getFourSigns().get(e.getBlock().getLocation()).getGame(), null); plugin.getSigns().save(); p.sendMessage("§cSign four removed."); } } public String getLocationString(Location loc){ String world = loc.getWorld().getName(); double x = loc.getX(); double y = loc.getY(); double z = loc.getZ(); float yaw = loc.getYaw(); float pitch = loc.getPitch(); return world + ";" + x + ";" + y + ";" + z + ";" + yaw + ";" + pitch; } }