/** * @param String containing item * @return Itemstack parsed from the string */ public ItemStack parseItem(String string) { String[] args = string.split(" "); int id = hg.isNumeric(args[0]) ? Integer.parseInt(args[0]) : (Material.getMaterial(args[0].toUpperCase()) == null ? Material.AIR : Material.getMaterial(args[0].toUpperCase())) .getId(); return new ItemStack(id, 1, Short.parseShort(args[1])); }
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { List<Gamer> gamers = pm.getAliveGamers(); ArrayList<String> gamerNames = new ArrayList<String>(); for (Gamer game : gamers) gamerNames.add(game.getPlayer().getDisplayName()); Collections.sort(gamerNames); String gamersName = "No gamers"; if (gamerNames.size() > 0) gamersName = StringUtils.join(gamerNames, ChatColor.GRAY + ", " + ChatColor.GRAY); sender.sendMessage( String.format( cm.getCommandPlayers(), gamers.size(), (pm.getGamers().size() - gamers.size()), gamersName)); if (hg.currentTime >= 0) sender.sendMessage( String.format(cm.getCommandPlayersTimeStatusStarted(), hg.returnTime(hg.currentTime))); else sender.sendMessage( String.format(cm.getCommandPlayersTimeStatusStarting(), hg.returnTime(hg.currentTime))); return true; }
public void manageDeath(PlayerKilledEvent event) { Gamer killed = event.getKilled(); final Player p = killed.getPlayer(); p.setHealth(20); if (event.isCancelled()) return; for (HumanEntity human : p.getInventory().getViewers()) human.closeInventory(); p.leaveVehicle(); p.eject(); p.setLevel(0); p.setExp(0F); if (event.getDeathMessage().equals(ChatColor.stripColor(event.getDeathMessage()))) event.setDeathMessage(ChatColor.DARK_RED + event.getDeathMessage()); event.setDeathMessage( this.formatDeathMessage( event.getDeathMessage().replace("%Remaining%", "" + (getAliveGamers().size() - 1)), p)); if (event.getKillerPlayer() != null) { event.getKillerPlayer().addKill(); event.setDeathMessage( this.formatDeathMessage(event.getDeathMessage(), event.getKillerPlayer().getPlayer())); } Bukkit.broadcastMessage(event.getDeathMessage()); int reward = hg.getPrize(getAliveGamers().size()); if (reward > 0) killed.addBalance(reward); hg.cannon(); killed.clearInventory(); World world = p.getWorld(); for (ItemStack item : event.getDrops()) { if (item == null || item.getType() == Material.AIR || item.containsEnchantment(EnchantmentManager.UNLOOTABLE)) continue; else if (item.hasItemMeta()) world .dropItemNaturally(event.getDropsLocation(), item.clone()) .getItemStack() .setItemMeta(item.getItemMeta()); else world.dropItemNaturally(event.getDropsLocation(), item); } setSpectator(killed); ScoreboardManager.makeScore( "Main", DisplaySlot.SIDEBAR, cm.getScoreboardPlayersLength(), getAliveGamers().size()); hg.checkWinner(); p.setVelocity(new Vector()); for (PotionEffect effect : p.getActivePotionEffects()) p.removePotionEffect(effect.getType()); p.teleport(p.getWorld().getHighestBlockAt(p.getLocation()).getLocation().clone().add(0, 10, 0)); p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 40, 9), true); p.sendBlockChange(p.getLocation(), Material.PORTAL.getId(), (byte) 0); p.sendBlockChange(p.getLocation(), Material.AIR.getId(), (byte) 0); for (Entity entity : p.getWorld().getEntities()) { if (entity instanceof Tameable && ((Tameable) entity).isTamed() && ((Tameable) entity).getOwner().getName().equals(p.getName())) { if (entity instanceof Wolf) ((Wolf) entity).setSitting(true); else if (entity instanceof Ocelot) ((Ocelot) entity).setSitting(true); else entity.remove(); } if (entity instanceof Creature && ((Creature) entity).getTarget() == p) ((Creature) entity).setTarget(null); } if (HungergamesApi.getConfigManager().getMainConfig().isKickOnDeath() && !p.hasPermission("hungergames.spectate")) p.kickPlayer(String.format(cm.getKickDeathMessage(), event.getDeathMessage())); HungergamesApi.getAbilityManager().unregisterPlayer(p); HungergamesApi.getInventoryManager().updateSpectatorHeads(); }
/** Reload the config. This doesn't reload some values however */ public void loadConfig() { hg.saveDefaultConfig(); final TranslationManager cm = HungergamesApi.getTranslationManager(); if (Bukkit.getServer().getAllowEnd() && hg.getConfig().getBoolean("DisableEnd", true)) { YamlConfiguration config = YamlConfiguration.loadConfiguration(new File("bukkit.yml")); config.set("settings.allow-end", false); try { config.save(new File("bukkit.yml")); } catch (IOException e) { e.printStackTrace(); } System.out.println(cm.getLoggerDisabledEnd()); } ReflectionManager rm = HungergamesApi.getReflectionManager(); if (hg.getServer().getAllowNether() && hg.getConfig().getBoolean("DisableNether", true)) { rm.setPropertiesConfig("allow-nether", false); rm.savePropertiesConfig(); System.out.println(cm.getLoggerDisabledNether()); } if (hg.getServer().getSpawnRadius() > 0 && hg.getConfig().getBoolean("ChangeSpawnLimit", true)) { rm.setPropertiesConfig("spawn-protection", 0); rm.savePropertiesConfig(); System.out.println(cm.getLoggerChangedSpawnRadius()); } if ((Integer) rm.getPropertiesConfig("max-build-height", 128) > 128 && hg.getConfig().getBoolean("ChangeHeightLimit", true)) { rm.setPropertiesConfig("max-build-height", 128); rm.savePropertiesConfig(); System.out.println(cm.getLoggerChangedHeightLimit()); } currentVersion = "v" + hg.getDescription().getVersion(); if (hg.getConfig().getBoolean("CheckUpdates")) Bukkit.getScheduler() .scheduleAsyncDelayedTask( hg, new Runnable() { public void run() { try { checkUpdate(); } catch (Exception ex) { System.out.print( String.format(cm.getLoggerFailedToCheckUpdate(), ex.getMessage())); } } }); hg.currentTime = -Math.abs(hg.getConfig().getInt("Countdown", 270)); mysqlEnabled = hg.getConfig().getBoolean("UseMySql", false); displayScoreboards = hg.getConfig().getBoolean("Scoreboards", false); displayMessages = hg.getConfig().getBoolean("Messages", true); minPlayers = hg.getConfig().getInt("MinPlayers", 2); fireSpread = hg.getConfig().getBoolean("DisableFireSpread", false); wonBroadcastsDelay = hg.getConfig().getInt("WinnerBroadcastingDelay"); gameShutdownDelay = hg.getConfig().getInt("GameShutdownDelay"); feastSize = hg.getConfig().getInt("FeastSize", 20); invincibility = hg.getConfig().getInt("Invincibility", 120); chestLayers = hg.getConfig().getInt("ChestLayers", 500); timeTillFeast = hg.getConfig().getInt("TimeTillFeast", 500); spectatorChat = !hg.getConfig().getBoolean("SpectatorChat", true); shortenNames = hg.getConfig().getBoolean("ShortenNames"); spectators = hg.getConfig().getBoolean("Spectators", true); kickOnDeath = hg.getConfig().getBoolean("KickOnDeath"); mushroomStew = hg.getConfig().getBoolean("MushroomStew", false); mushroomStewRestores = hg.getConfig().getInt("MushroomStewRestores", 5); kitSelector = hg.getConfig().getBoolean("EnableKitSelector", true); feastTnt = hg.getConfig().getBoolean("FeastTnt", true); feastGround = parseItem(hg.getConfig().getString("FeastGround")); feast = parseItem(hg.getConfig().getString("Feast")); generatePillars = hg.getConfig().getBoolean("Pillars", true); feastInsides = parseItem(hg.getConfig().getString("FeastInsides")); pillarCorner = parseItem(hg.getConfig().getString("PillarCorner")); pillarInsides = parseItem(hg.getConfig().getString("PillarInsides")); forceCords = hg.getConfig().getBoolean("ForceCords", true); x = hg.getConfig().getInt("ForceX", 0); z = hg.getConfig().getInt("ForceZ", 0); kitSelectorIcon = parseItem(hg.getConfig().getString("KitSelectorIcon")); if (kitSelectorIcon == null) kitSelectorIcon = new ItemStack(Material.FEATHER); kitSelectorBack = parseItem(hg.getConfig().getString("KitSelectorForward")); if (kitSelectorBack == null) kitSelectorBack = new ItemStack(Material.SUGAR_CANE_BLOCK); kitSelectorForward = parseItem(hg.getConfig().getString("KitSelectorBack")); if (kitSelectorForward == null) kitSelectorForward = new ItemStack(Material.SUGAR_CANE_BLOCK); spectatorItemBack = parseItem(hg.getConfig().getString("SpectatorInventoryForward")); if (spectatorItemBack == null) spectatorItemBack = new ItemStack(Material.SUGAR_CANE_BLOCK); spectatorItemForwards = parseItem(hg.getConfig().getString("SpectatorInventoryBack")); if (spectatorItemForwards == null) spectatorItemForwards = new ItemStack(Material.SUGAR_CANE_BLOCK); kitSelectorDynamicSize = hg.getConfig().getBoolean("KitSelectorDynamicSize"); kitSelectorInventorySize = hg.getConfig().getInt("KitSelectorInventorySize"); mobSpawnChance = hg.getConfig().getInt("MobSpawnChance"); if (hg.getConfig().contains("CommandsToRunBeforeShutdown")) commandsToRunBeforeShutdown = hg.getConfig().getStringList("CommandsToRunBeforeShutdown"); else commandsToRunBeforeShutdown = new ArrayList<String>(); disableMetrics = hg.getConfig().getBoolean("DisableMetrics"); flyPreGame = hg.getConfig().getBoolean("FlyPregame"); if (hg.getConfig().getBoolean("ChangeAlivePrefix")) alivePrefix = hg.getConfig().getString("AlivePrefix"); if (hg.getConfig().getBoolean("ChangeSpectatingPrefix")) spectatingPrefix = hg.getConfig().getString("SpectatingPrefix"); invisSpectators = !hg.getConfig().getBoolean("InvisibleSpectators"); // Create the times where it broadcasts and advertises the feast feastBroadcastTimes.clear(); for (int i = 1; i < 6; i++) feastBroadcastTimes.add(i); feastBroadcastTimes.add(30); feastBroadcastTimes.add(15); feastBroadcastTimes.add(10); invincibilityBroadcastTimes.clear(); // Create the times where it advertises invincibility for (int i = 1; i <= 5; i++) invincibilityBroadcastTimes.add(i); invincibilityBroadcastTimes.add(30); invincibilityBroadcastTimes.add(15); invincibilityBroadcastTimes.add(10); // Create the times where it advertises when the game starts gameStartingBroadcastTimes.clear(); for (int i = 1; i <= 5; i++) gameStartingBroadcastTimes.add(-i); gameStartingBroadcastTimes.add(-30); gameStartingBroadcastTimes.add(-15); gameStartingBroadcastTimes.add(-10); }