public PlayerState(final Player player) { name = player.getName(); debug.i("creating PlayerState of " + name, player); fireticks = player.getFireTicks(); foodlevel = player.getFoodLevel(); gamemode = player.getGameMode().getValue(); health = player.getHealth(); maxhealth = player.getMaxHealth(); exhaustion = player.getExhaustion(); experience = player.getExp(); explevel = player.getLevel(); saturation = player.getSaturation(); potionEffects = player.getActivePotionEffects(); flying = player.isFlying(); final ArenaPlayer aPlayer = ArenaPlayer.parsePlayer(player.getName()); final Arena arena = aPlayer.getArena(); if (arena.getArenaConfig().getBoolean(CFG.CHAT_COLORNICK)) { displayname = player.getDisplayName(); } fullReset(arena, player); final int time = arena.getArenaConfig().getInt(CFG.GENERAL_TIME); if (time != -1) { player.setPlayerTime(time, false); } }
@SuppressWarnings("deprecation") public void saveState() { bukkitPlayer.setGameMode(GameMode.SURVIVAL);//Set to survival //Define player states variables ItemStack[] contents = bukkitPlayer.getInventory().getContents(); ItemStack helmet = bukkitPlayer.getInventory().getHelmet(); ItemStack chestplate = bukkitPlayer.getInventory().getChestplate(); ItemStack leggings = bukkitPlayer.getInventory().getLeggings(); ItemStack boots = bukkitPlayer.getInventory().getBoots(); float exhaustion = bukkitPlayer.getExhaustion(); float saturation = bukkitPlayer.getSaturation(); int foodLevel = bukkitPlayer.getFoodLevel(); double health = bukkitPlayer.getHealth(); GameMode gm = bukkitPlayer.getGameMode(); Collection<PotionEffect> potionEffects = bukkitPlayer.getActivePotionEffects(); float exp = bukkitPlayer.getExp(); int level = bukkitPlayer.getLevel(); boolean fly = bukkitPlayer.getAllowFlight(); //Save state state = new PlayerState(contents, helmet, chestplate, leggings, boots, exhaustion, saturation, foodLevel, health, gm, potionEffects, exp, level, fly); //Set to default state bukkitPlayer.setFoodLevel(20); bukkitPlayer.setHealth(20.0); bukkitPlayer.setAllowFlight(false);//Disable fly mode (Essentials etc.) bukkitPlayer.setFireTicks(0); bukkitPlayer.getInventory().clear(); bukkitPlayer.getInventory().setArmorContents(new ItemStack[4]); bukkitPlayer.setLevel(0); bukkitPlayer.setExp(0); for (PotionEffect effect : bukkitPlayer.getActivePotionEffects()) { bukkitPlayer.removePotionEffect(effect.getType()); } bukkitPlayer.sendMessage(I18N._("stateSaved")); bukkitPlayer.updateInventory(); }
public GamePlayerData(Player player, boolean isPlayer) { this.name = player.getName(); this.isPlayer = isPlayer; this.originLoc = player.getLocation(); this.compassTarget = player.getCompassTarget(); this.health = player.getHealth(); this.food = player.getFoodLevel(); this.saturation = player.getSaturation(); this.inv = player.getInventory().getContents(); this.armor = player.getInventory().getArmorContents(); player.getInventory().clear(); this.exp = player.getTotalExperience(); player.setTotalExperience(0); }
@Override public float getSaturation() { return caller.getSaturation(); }
public boolean commandUse(CommandSender sender, String[] args) { Variables var = Necessities.getVar(); if (args.length == 0) { sender.sendMessage( var.getEr() + "Error: " + var.getErMsg() + "You must enter a player to view info of."); return true; } GetUUID get = Necessities.getUUID(); UUID uuid = get.getID(args[0]); if (uuid == null) { uuid = get.getOfflineID(args[0]); if (uuid == null || !Bukkit.getOfflinePlayer(uuid).hasPlayedBefore()) { sender.sendMessage( var.getEr() + "Error: " + var.getErMsg() + "That player does not exist or has not joined the server. If the player is offline, please use the full and most recent name."); return true; } } User u = Necessities.getUM().getUser(uuid); sender.sendMessage( var.getMessages() + "===== WhoIs: " + var.getObj() + u.getName() + var.getMessages() + " ====="); if (u.getPlayer() != null) sender.sendMessage( var.getMessages() + " - Nick: " + ChatColor.RESET + u.getPlayer().getDisplayName()); else { sender.sendMessage( var.getMessages() + (u.getNick() == null ? " - Name: " + ChatColor.RESET + u.getName() : " - Nick: " + ChatColor.RESET + u.getNick())); Calendar c = Calendar.getInstance(); c.setTimeInMillis(Bukkit.getOfflinePlayer(uuid).getLastPlayed()); String second = Integer.toString(c.get(Calendar.SECOND)); String minute = Integer.toString(c.get(Calendar.MINUTE)); String hour = Integer.toString(c.get(Calendar.HOUR_OF_DAY)); String day = Integer.toString(c.get(Calendar.DATE)); String month = Integer.toString(c.get(Calendar.MONTH) + 1); String year = Integer.toString(c.get(Calendar.YEAR)); hour = corTime(hour); minute = corTime(minute); second = corTime(second); sender.sendMessage( var.getMessages() + " - Seen last on " + ChatColor.RESET + month + "/" + day + "/" + year + " at " + hour + ":" + minute + " and " + second + " " + (Integer.parseInt(second) > 1 ? "seconds" : "second")); } sender.sendMessage( var.getMessages() + " - Time played: " + ChatColor.RESET + u.getTimePlayed()); sender.sendMessage(var.getMessages() + " - Rank: " + ChatColor.RESET + u.getRank().getName()); String subranks = u.getSubranks(); if (subranks != null) sender.sendMessage(var.getMessages() + " - Subranks: " + ChatColor.RESET + subranks); String permissions = u.getPermissions(); if (permissions != null) sender.sendMessage( var.getMessages() + " - Permission nodes: " + ChatColor.RESET + permissions); if (u.getPlayer() != null) { Player p = u.getPlayer(); sender.sendMessage( var.getMessages() + " - Health: " + ChatColor.RESET + (int) p.getHealth() + "/" + (int) p.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); sender.sendMessage( var.getMessages() + " - Hunger: " + ChatColor.RESET + p.getFoodLevel() + "/20 (+" + (int) p.getSaturation() + " saturation)"); sender.sendMessage( var.getMessages() + " - Exp: " + ChatColor.RESET + Utils.addCommas(p.getTotalExperience()) + " (Level " + p.getLevel() + ")"); String location = "(" + p.getWorld().getName() + ", " + p.getLocation().getBlockX() + ", " + p.getLocation().getBlockY() + ", " + p.getLocation().getBlockZ() + ")"; sender.sendMessage(var.getMessages() + " - Location: " + ChatColor.RESET + location); } if (u.getPlayer() != null) { Player p = u.getPlayer(); sender.sendMessage( var.getMessages() + " - IP Address: " + ChatColor.RESET + p.getAddress().toString().split("/")[1].split(":")[0]); sender.sendMessage( var.getMessages() + " - Gamemode: " + ChatColor.RESET + Utils.capFirst(p.getGameMode().toString())); } if (u.getPlayer() != null) { Player p = u.getPlayer(); sender.sendMessage( var.getMessages() + " - Banned: " + (p.isBanned() ? ChatColor.GREEN + "true" : ChatColor.DARK_RED + "false")); sender.sendMessage( var.getMessages() + " - Visible: " + (Necessities.getHide().isHidden(p) ? ChatColor.DARK_RED + "false" : ChatColor.GREEN + "true")); sender.sendMessage( var.getMessages() + " - OP: " + (p.isOp() ? ChatColor.GREEN + "true" : ChatColor.DARK_RED + "false")); sender.sendMessage( var.getMessages() + " - Fly mode: " + (p.isFlying() ? ChatColor.GREEN + "true " + ChatColor.RESET + " (flying)" : ChatColor.DARK_RED + "false" + ChatColor.RESET + " (not flying)")); } else { OfflinePlayer p = Bukkit.getOfflinePlayer(u.getUUID()); sender.sendMessage( var.getMessages() + " - Banned: " + (p.isBanned() ? ChatColor.GREEN + "true" : ChatColor.DARK_RED + "false")); sender.sendMessage( var.getMessages() + " - OP: " + (p.isOp() ? ChatColor.GREEN + "true" : ChatColor.DARK_RED + "false")); } sender.sendMessage( var.getMessages() + " - Muted: " + (u.isMuted() ? ChatColor.GREEN + "true" : ChatColor.DARK_RED + "false")); return true; }
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { // Console ausschließen if (!(sender instanceof Player)) { sender.sendMessage(ChatColor.RED + "You have to be a player!"); return false; } // beenden, wenn Argumente gegeben wurden if (args.length != 0) { return false; } Player player = (Player) sender; if (cmd.getName().equalsIgnoreCase("care-pack")) { if (player.hasPermission("CarePack.ever")) { PlayerInventory inventory = player.getInventory(); // Steinschwert ItemStack item = new ItemStack(272, 1); inventory.addItem(item); // 10 Holz item.setTypeId(17); item.setData(new MaterialData(0)); item.setAmount(10); inventory.addItem(item); // 4 Fackeln item.setTypeId(50); item.setAmount(4); inventory.addItem(item); // 1 Bett item.setTypeId(355); item.setAmount(1); inventory.addItem(item); // 2 Brot item.setTypeId(297); item.setAmount(2); inventory.addItem(item); // 1 Beef item.setTypeId(364); item.setAmount(1); inventory.addItem(item); return true; } else if ((player.getWorld().getTime() < 7000 && player.getWorld().getTime() > 22000) || player.getFoodLevel() < 6 || player.getSaturation() < 6) { PlayerInventory inventory = player.getInventory(); // Steinschwert ItemStack item = new ItemStack(272, 1); inventory.addItem(item); // 10 Holz item.setTypeId(17); item.setData(new MaterialData(0)); item.setAmount(10); inventory.addItem(item); // 4 Fackeln item.setTypeId(50); item.setAmount(4); inventory.addItem(item); // 1 Bett item.setTypeId(355); item.setAmount(1); inventory.addItem(item); // 2 Brot item.setTypeId(297); item.setAmount(2); inventory.addItem(item); // 1 Beef item.setTypeId(364); item.setAmount(1); inventory.addItem(item); return true; } else { player.sendMessage(ChatColor.RED + "You can't use this command now!"); return true; } } return false; }