Hey, I got some problems with getting the players out of an Arraylist. I use this for getting all players out of the arraylist, but it doesn't work. Code: Code:java for (String playername : join) { Player Gamer = plugin.getServer().getPlayerExact(playername); if (Gamer != null) { Gamer.teleport(new Location(world, xe, ye, ze, yawe, pitche)); Gamer.setLevel(0); Gamer.setGameMode(GameMode.SURVIVAL); } else if(Gamer == null){ player.sendMessage("Nope"); } } And I got another problem. I want to set pvp off for the players who are in the arraylist and put the pvp on when it starts for that arraylist. I use this: (I also get the message that the player isn't in the arraylist) Code when player get hit: Code:java @EventHandler public void onPlayerDamage(EntityDamageByEntityEvent event){ Player player = (Player) event.getEntity(); Player damager = (Player) event.getDamager(); Boolean PvP = false; if(join.contains(player.getName()) || join.contains(damager.getName())){ if(PvP){ event.setCancelled(false); } else if(!PvP){ event.setCancelled(true); } } else if(!join.contains(player.getName()) || !join.contains(damager.getName())){ event.setCancelled(true); } } Code to start: Code:java if(args[0].equalsIgnoreCase("start")){ if(player.hasPermission("mcpevent.host")){ if(!join.isEmpty()){ if(host.contains(player.getName())){ for (String playername : join) { Player Gamer = plugin.getServer().getPlayerExact(playername); if (Gamer != null) { Gamer.teleport(new Location(world, x, y, z, yaw, pitch)); PvP = true; Bukkit.broadcastMessage(BStart); } else if(Gamer == null){ player.sendMessage("Nope"); } } } else if(!host.contains(player.getName())){ player.sendMessage(NotHost); } } else if(join.isEmpty()){ player.sendMessage(No1); } } else if(!player.hasPermission("mcpevent.host")){ player.sendMessage(NoPerms); } } Code to put a player in an arraylist: Code:java if(args[0].equalsIgnoreCase("join")){ if(player.hasPermission("mcpevent.join")){ if(plugin.getConfig().get("Game") != null){ if(!join.contains(player.getName())){ if(host.contains(player.getName())){ player.sendMessage(Hoster); } boolean empty = true; for(ItemStack slot : pi.getContents()){ if(slot != null) empty = false; } for(ItemStack slot : pi.getArmorContents()){ if(slot == new ItemStack(Material.AIR)) empty = false; } if(empty){ /* * Code when join \/ */ plugin.getConfig().set("Game.Players.Names." + player.getName(), ""); join.add(player.getName()); Bukkit.broadcastMessage(BJoin); player.teleport(new Location(world, x, y, z, yaw, pitch)); player.setLevel(intlives); pi.addItem(stick); plugin.saveConfig(); player.setGameMode(GameMode.ADVENTURE); /* * Code when join /\ */ } else if(!empty){ player.sendMessage(clearInv); } } else if(join.contains(player.getName())){ player.sendMessage(AlreadyIG); } } else if(plugin.getConfig().get("Game") == null){ player.sendMessage(NoGame); } } else if(!player.hasPermission("mcpevent.join")){ player.sendMessage(NoPerms); } } It would be great if you could help me with this. Thank you,
TheUpdater I want to get all the players in the arraylist and then tp them or set their xp levels to 0.
PHP: for(Player inarraylist : THEARRAYLISTNAME){inarraylist.teleport(LOCATION)inarraylist.setLevel(LEVEL)}
have you stored the names or the players you cant telepor playernames make another arraylist with Player EDIT by Moderator: merged posts, please use the edit button instead of double posting.
TheUpdater look at my last code I put in my post. And I use this is the Arraylist: Code:java Set<String> join = new HashSet<String>(); Wait I'll post my whole code maybe a lot easier. Sorry if it is kinda messy http://pastebin.com/0mxYyrxM
this PHP: Set<String> join = new HashSet<String>(); saves players name try PHP: Set<Player> join = new HashSetPlayer>();
TheUpdater And then this: ? Code:java for (Player Gamer : join) { if (Gamer != null) { Gamer.teleport(new Location(world, xe, ye, ze, yawe, pitche)); Gamer.setLevel(0); Gamer.setGameMode(GameMode.SURVIVAL); } else if(Gamer == null){ player.sendMessage("Nope"); }
cummo15 I have to because I use this: Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
Josh014 Put plugin there... it needs the instance of your main class. EDIT: Your class will also need to implement CommandExecutor, you can read how to do this here.
Josh014 No, just put "plugin" instead of "this" as you already have your main class instance from your constructor.
First of all. Storing player data in a List or something simliar is always a bad Idea. Go with the Names and then get the name as you did in your first Example via Player gamer = Bukkit.getServer().getExactPlayer(playername); Second: You do not need to extend JavaPlugin for Bukkit.getScheduler().. You just need to import Bukkit. Third Code:java Gamer.teleport(new Location(world, x, y, z, yaw, pitch)); I looked at your pastebin, and I cannot see where you defined x,y,z,yaw and pitch thus that won't work.
Josh014 You're class now needs to implement CommandExecutor, look at the tutorial on the wiki. (I linked it a few posts ago.) EDIT: Looked just now and he does define x, y, z, yaw and pitch. Around line 90.
L33m4n123 I got this: Code:java int x = plugin.getConfig().getInt("Game.Coords.x");int y = plugin.getConfig().getInt("Game.Coords.y");int z = plugin.getConfig().getInt("Game.Coords.z");int pitch = plugin.getConfig().getInt("Game.Coords.pitch");int yaw = plugin.getConfig().getInt("Game.Coords.yaw"); int xe = plugin.getConfig().getInt("End.Coords.x");int ye = plugin.getConfig().getInt("End.Coords.y");int ze = plugin.getConfig().getInt("End.Coords.z");int pitche = plugin.getConfig().getInt("End.Coords.pitch");int yawe = plugin.getConfig().getInt("End.Coords.yaw"); And I got a problem with the pvp thing because if the game start pvp won't turn on for the players.
Josh014 It's not the problem but you will decrease accuracy drastically by converting a float to an int.
The_Doctor_123 Alright I changed the "int" into "float". But the pvp part and the teleport part still doesn't work. :/