Plugin [Need Help]

Discussion in 'Plugin Development' started by Josh014, Dec 18, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Josh014

    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
    1. for (String playername : join) {
    2. Player Gamer = plugin.getServer().getPlayerExact(playername);
    3. if (Gamer != null) {
    4. Gamer.teleport(new Location(world, xe, ye, ze, yawe, pitche));
    5. Gamer.setLevel(0);
    6. Gamer.setGameMode(GameMode.SURVIVAL);
    7. }
    8. else if(Gamer == null){
    9. player.sendMessage("Nope");
    10. }
    11. }


    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
    1. @EventHandler
    2. public void onPlayerDamage(EntityDamageByEntityEvent event){
    3. Player player = (Player) event.getEntity();
    4. Player damager = (Player) event.getDamager();
    5. Boolean PvP = false;
    6.  
    7. if(join.contains(player.getName()) || join.contains(damager.getName())){
    8. if(PvP){
    9. event.setCancelled(false);
    10. }
    11. else if(!PvP){
    12. event.setCancelled(true);
    13. }
    14. }
    15. else if(!join.contains(player.getName()) || !join.contains(damager.getName())){
    16. event.setCancelled(true);
    17. }
    18. }


    Code to start:
    Code:java
    1. if(args[0].equalsIgnoreCase("start")){
    2. if(player.hasPermission("mcpevent.host")){
    3.  
    4. if(!join.isEmpty()){
    5. if(host.contains(player.getName())){
    6. for (String playername : join) {
    7. Player Gamer = plugin.getServer().getPlayerExact(playername);
    8. if (Gamer != null) {
    9. Gamer.teleport(new Location(world, x, y, z, yaw, pitch));
    10. PvP = true;
    11. Bukkit.broadcastMessage(BStart);
    12. }
    13. else if(Gamer == null){
    14. player.sendMessage("Nope");
    15. }
    16. }
    17. }
    18. else if(!host.contains(player.getName())){
    19. player.sendMessage(NotHost);
    20. }
    21. }
    22. else if(join.isEmpty()){
    23. player.sendMessage(No1);
    24. }
    25. }
    26. else if(!player.hasPermission("mcpevent.host")){
    27. player.sendMessage(NoPerms);
    28. }
    29. }


    Code to put a player in an arraylist:
    Code:java
    1. if(args[0].equalsIgnoreCase("join")){
    2. if(player.hasPermission("mcpevent.join")){
    3.  
    4. if(plugin.getConfig().get("Game") != null){
    5. if(!join.contains(player.getName())){
    6. if(host.contains(player.getName())){
    7. player.sendMessage(Hoster);
    8. }
    9. boolean empty = true;
    10. for(ItemStack slot : pi.getContents()){
    11. if(slot != null) empty = false;
    12. }
    13. for(ItemStack slot : pi.getArmorContents()){
    14. if(slot == new ItemStack(Material.AIR)) empty = false;
    15. }
    16. if(empty){
    17. /*
    18.   * Code when join \/
    19.   */
    20. plugin.getConfig().set("Game.Players.Names." + player.getName(), "");
    21. join.add(player.getName());
    22. Bukkit.broadcastMessage(BJoin);
    23. player.teleport(new Location(world, x, y, z, yaw, pitch));
    24. player.setLevel(intlives);
    25. pi.addItem(stick);
    26. plugin.saveConfig();
    27. player.setGameMode(GameMode.ADVENTURE);
    28. /*
    29.   * Code when join /\
    30.   */
    31. }
    32. else if(!empty){
    33. player.sendMessage(clearInv);
    34. }
    35. }
    36. else if(join.contains(player.getName())){
    37. player.sendMessage(AlreadyIG);
    38. }
    39. }
    40. else if(plugin.getConfig().get("Game") == null){
    41. player.sendMessage(NoGame);
    42. }
    43. }
    44.  
    45. else if(!player.hasPermission("mcpevent.join")){
    46. player.sendMessage(NoPerms);
    47. }
    48. }


    It would be great if you could help me with this.


    Thank you,
     
  2. Offline

    TheUpdater

    want to get all players that are not in your arraylist?
     
  3. Offline

    Josh014

    TheUpdater I want to get all the players in the arraylist and then tp them or set their xp levels to 0.
     
  4. Offline

    TheUpdater


    PHP:
    for(Player inarraylist THEARRAYLISTNAME){
    inarraylist.teleport(LOCATION)
    inarraylist.setLevel(LEVEL)
    }
     
  5. Offline

    Josh014

    TheUpdater
    Yea that is what I use but it doesn't work somehow.
     
  6. Offline

    TheUpdater

    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.
     
    Last edited by a moderator: Jun 5, 2016
  7. Offline

    Josh014

    TheUpdater look at my last code I put in my post. And I use this is the Arraylist:
    Code:java
    1. 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
     
  8. Offline

    TheUpdater

    this
    PHP:
    Set<Stringjoin = new HashSet<String>();
    saves players name try
    PHP:
    Set<Playerjoin = new HashSetPlayer>();
     
  9. Offline

    Josh014

    TheUpdater
    How can I add players to it then?
    Just: join.add(player);?
     
  10. Offline

    TheUpdater

    yup
     
  11. Offline

    Josh014

    TheUpdater
    And then this: ?

    Code:java
    1. for (Player Gamer : join) {
    2. if (Gamer != null) {
    3. Gamer.teleport(new Location(world, xe, ye, ze, yawe, pitche));
    4. Gamer.setLevel(0);
    5. Gamer.setGameMode(GameMode.SURVIVAL);
    6. }
    7. else if(Gamer == null){
    8. player.sendMessage("Nope");
    9. }
     
  12. Offline

    cummo15

    Josh014 You should only extend JavaPlugin in your main class.
     
  13. Offline

    Josh014

    cummo15
    I have to because I use this:
    Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
     
  14. Offline

    cummo15

    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.
     
  15. Offline

    Josh014

    cummo15
    So this?
    public class Commands extends Main implements Listener {
     
  16. Offline

    cummo15

    Josh014 No, just put "plugin" instead of "this" as you already have your main class instance from your constructor.
     
  17. Offline

    Josh014

    TheUpdater
    Alright I changed everything now but it still won't work. It doesn't teleport the players
     
  18. Offline

    L33m4n123

    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
    1. 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.
     
  19. Offline

    cummo15

    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.
     
  20. Offline

    Josh014

    L33m4n123
    I got this:
    Code:java
    1. int x = plugin.getConfig().getInt("Game.Coords.x");
    2. int y = plugin.getConfig().getInt("Game.Coords.y");
    3. int z = plugin.getConfig().getInt("Game.Coords.z");
    4. int pitch = plugin.getConfig().getInt("Game.Coords.pitch");
    5. int yaw = plugin.getConfig().getInt("Game.Coords.yaw");
    6.  
    7. int xe = plugin.getConfig().getInt("End.Coords.x");
    8. int ye = plugin.getConfig().getInt("End.Coords.y");
    9. int ze = plugin.getConfig().getInt("End.Coords.z");
    10. int pitche = plugin.getConfig().getInt("End.Coords.pitch");
    11. 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.
     
  21. Offline

    The_Doctor_123

    Josh014
    Erm, yaw/pitch are floats, not ints. Although, I don't think that's your problem.
     
  22. Offline

    Josh014

    The_Doctor_123
    Nope I don't think so too because I use this on different plugins too.
     
  23. Offline

    The_Doctor_123

    Josh014
    It's not the problem but you will decrease accuracy drastically by converting a float to an int.
     
  24. Offline

    Josh014

    The_Doctor_123 so what would you suggest? Oh and btw do you know why the pvp part won't work? :3
     
  25. Offline

    sgavster

  26. Offline

    Josh014

    The_Doctor_123
    Alright I changed the "int" into "float". But the pvp part and the teleport part still doesn't work. :/
     
  27. Offline

    Josh014

  28. Offline

    Josh014

    Bump ._.
     
Thread Status:
Not open for further replies.

Share This Page