Spawn

Discussion in 'Plugin Development' started by NoSpanMan, Oct 20, 2015.

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

    NoSpanMan

    I have 2 teams and 2 spawnlocations in the config. But how can i let them spawn there?

    I already tried it with setspawnlocation but that didn't work.
    I already tried to do with a playerrespawnevent and then check wich team the player in is. And after that the config cordinates.
     
  2. Offline

    Scimiguy

    @NoSpanMan
    Just teleport them there when they respawn using PlayerRespawnEvent
     
  3. Offline

    NoSpanMan

    I put in the topic that i already tried that but they spawn in the world spawn then not the good spawn.
     
  4. Offline

    Scimiguy

    @NoSpanMan
    Try putting it in a BukkitRunnable() with a 1 tick delay.
     
  5. Offline

    NoSpanMan

    Can you tell me why?
     
  6. Offline

    DoggyCode™

    Because you might not be fully "respawned" when the event is ran. Make sure you're actually spawned and in the world. A little delay could do this.
     
  7. Offline

    NoSpanMan

    So then i need to create a playerrespawnevent then check in wich team the player is and then start the 1 second delay and then tp?
     
  8. Offline

    Scimiguy

  9. @NoSpanMan
    If you tried in PlayerRespawnEvent to teleport the Player to the location, it won't work, because the respawn event also teleports the player just after. Using PlayerRespawnEvent#setRespawnLocation(Location) you can set the location where the player respawns.
     
    DoggyCode™ likes this.
  10. Offline

    NoSpanMan

    Already tried. This dont work.

    What i made:
    Code:
      public void respawn(Player p) {
            new BukkitRunnable() {
            
             public void run() {
               if (number != -1) {
                 if(number != 0) {
                   number--;
                 } else {
                   for(Player p : Bukkit.getOnlinePlayers()){
                  
                     if(inBuggs.contains(p.getName())) {
                       World w = Bukkit.getServer().getWorld(getConfig().getString("spawnB.world"));
                         int x = getConfig().getInt("spawnB.x");
                         int y = getConfig().getInt("spawnB.y");
                         int z = getConfig().getInt("spawnB.z");
                         Location BuggSpawn = new Location(w, x, y, z);
                        
                         p.teleport(BuggSpawn);
                     } else {
                       World w = Bukkit.getServer().getWorld(getConfig().getString("spawnD.world"));
                         int x = getConfig().getInt("spawnD.x");
                         int y = getConfig().getInt("spawnD.y");
                         int z = getConfig().getInt("spawnD.z");
                         Location DevSpawn = new Location(w, x, y, z);
                        
                         p.teleport(DevSpawn);
                     }
                  
                   respawn = 1;
                   cancel();
                     }
                   }
                 }
               }
             }.runTaskTimer(this, 0, 20); // 20L = 1sec
       }
    
    And:

    Code:
      @EventHandler
       public void onRespawn(PlayerRespawnEvent e) {
         respawn(e.getPlayer());
       }
    
    And:
    Code:
      int respawn = 1;
    
    Is this good? (i cant test right now)
     
  11. Offline

    Xerox262

    Why did setSpawnLocation not work? You should really be using that over this.
     
  12. Offline

    NoSpanMan

    Then i have 1 question. How can i let it happen when the game stats when the timer is done that he sets the spawn. How can i set a spawnlocation outside an event?

    EDIT:
    I understand im gonna try it.

    I can only do setbedspawnlocation.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 29, 2015
  13. Offline

    Xerox262

    it's PlayerRespawnEvent#setRespawnLocation(Location); are you doing Player instead? How're you calling it?
     
  14. Offline

    NoSpanMan

    Yeah but how can i set it when the game starts? Because there is no event running by starting the game.
     
  15. Offline

    Xerox262

    Is there something you can call to see if the game has started? something like Game.isStarted() or Game.isRunning()
     
  16. Offline

    NoSpanMan

    Nope.
     
  17. Offline

    Xerox262

    What's this?
    inBuggs.contains(p.getName())
    if there's one for the other team then you could just use that
     
  18. Offline

    NoSpanMan

    Code:
      @EventHandler
       public void onRespawn(PlayerRespawnEvent e) {
         Player p = e.getPlayer();
         
         if(inBuggs.contains(p.getName())) {
           World w = Bukkit.getServer().getWorld(getConfig().getString("SpawnB.world"));
           int x = getConfig().getInt("SpawnB.x");
           int y = getConfig().getInt("SpawnB.y");
           int z = getConfig().getInt("SpawnB.z");
           Location spawnBuggs = (new Location(w, x, y, z));
           e.setRespawnLocation(spawnBuggs);
         } else {
           World w = Bukkit.getServer().getWorld(getConfig().getString("SpawnD.world"));
           int x = getConfig().getInt("SpawnD.x");
           int y = getConfig().getInt("SpawnD.y");
           int z = getConfig().getInt("SpawnD.z");
           Location SpawnDevs = (new Location(w, x, y, z));
           e.setRespawnLocation(SpawnDevs);
         }
       }
    
    Is this good? I made it but does they spawn now right?
     
  19. Offline

    Xerox262

    The else is going to mean that everyone who is not in the bugs team will respawn at the dev spawn, if you have an arraylist containing the players in the devteam then you should use an else if instead of an else. This is something you should know, it is very basic Java.
     
  20. Offline

    NoSpanMan

    Yeah i understand but its not a problem :). But i gonna change it to else if :D. But is the rest of the code good?
     
  21. Offline

    Xerox262

    Yea, the rest is good.
     
  22. Offline

    NoSpanMan

    I spawnt not good..... Everyone spawns at the same spawn and i dont set that spawn. The team spawns on a very diffirent place.

    I have a code but i can't place the hole code here. Do you want to help me please send me then a private message with your skype or place it here.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 29, 2015
  23. Offline

    mythbusterma

    @NoSpanMan

    No. You can't.

    You either post it here or we won't help you. Read the forum rules.
     
  24. Offline

    NoSpanMan

    Im gonna post it but i know that you guys it dont gonna understand:
    Code:
    final ArrayList<String> inLobby = new ArrayList<String>();
       final ArrayList<String> inDevs = new ArrayList<String>();
       final ArrayList<String> inBuggs = new ArrayList<String>();
       private List<Integer> bullets = new ArrayList<>();
       
       int devs = 0;
       int buggs = 0;
       int lobby = 0;
       
       int number = 30;
       int gameTime = 900;
       
       int devscore = 0;
       int buggscore = 50;
       
       int Capture1 = 100;
       int Capture2 = 100;
       int Capture3 = 100;
       int general = 100;
    
      public void Check(Player p) {
         if(devs > buggs) {
           if(inLobby.contains(p.getName())) {
             
           } else {
             lobby++;
             inLobby.add(p.getName());
             }
           inBuggs.add(p.getName());
           buggs++;
           sendMessage(DB + lobby + "/16 " + p.getName() + " joined the buggs");
           Genoeg();
         } else {
           if(inLobby.contains(p.getName())) {
             
           } else {
             lobby++;
             inLobby.add(p.getName());
             }
           inDevs.add(p.getName());
           devs++;
           sendMessage(DB + lobby + "/16 " + p.getName() + " joined the devs");
           
           if(lobby <= 2) {
             Genoeg();
           } else {
             
           }
         }
       }
    
      public void Genoeg() {
       if(lobby >= 2) {
         sendMessage(DB + "The game starts in 30 seconds");
          new BukkitRunnable() {
             
             public void run() {
               if (number != -1) {
                 if(number != 0) {
                   number--;
                   if(number > 10) {
                     
                   } else {
                     sendMessage(DB + "The game starts in " + number);
                   }
                 } else {
                   if(lobby >= 2) {
                     sendMessage(DB + "The game is starting...");
                     
                     for(Player p : Bukkit.getOnlinePlayers()){
                     
                       if(inDevs.contains(p.getName())) {
                         World w = Bukkit.getServer().getWorld(getConfig().getString("spawnD.world"));
                           int x = getConfig().getInt("spawnD.x");
                           int y = getConfig().getInt("spawnD.y");
                           int z = getConfig().getInt("spawnD.z");
                           p.teleport(new Location(w, x, y, z));
                           armourDevs(p);
                       } else if(inBuggs.contains(p.getName())){
                         World w = Bukkit.getServer().getWorld(getConfig().getString("spawnB.world"));
                           int x = getConfig().getInt("spawnB.x");
                           int y = getConfig().getInt("spawnB.y");
                           int z = getConfig().getInt("spawnB.z");
                           p.teleport(new Location(w, x, y, z));
                           armourBuggs(p);
                       } else {
                         
                       }
                       
                       p.setScoreboard(timerBoard);
                       startTime();
                   
                     number = 30;
                     cancel();
                       }
                     } else {
                       sendMessage(DB + "There are not enough players to start.");
                       cancel();
                       number = 30;
                     }
                   }
                 }
               }
             }.runTaskTimer(this, 0, 20L); // 20L = 1sec
           } else {
             
           }
       }
    
    public void startTime() {
          this.countdown = new BukkitRunnable() {
             
             public void run() {
               for(Player p : Bukkit.getOnlinePlayers()){
               if (gameTime != -1) {
                 if(gameTime != 0) {
                   final Score score = o.getScore(Bukkit.getOfflinePlayer(ChatColor.GREEN + "Time:"));
                   final Score devsS = o.getScore(Bukkit.getOfflinePlayer(ChatColor.GREEN + "Devs:"));
                   final Score buggsS = o.getScore(Bukkit.getOfflinePlayer(ChatColor.GREEN + "Buggs:"));
                   if(gameTime <= 60) {
                     score.setScore(gameTime);
                     devsS.setScore(devscore);
                     buggsS.setScore(buggscore);
                     
                     if(buggscore <= 0) {
                       sendMessage(DB + "The buggs has won the game!");
                       End(p);
                       cancel();
                     } else {
                       
                     }
                     
                     if(devscore >= 3) {
                       sendMessage(DB + "The devs has won the game!");
                       End(p);
                       cancel();
                     } else {
                       
                     }
                   } else {
                     score.setScore(gameTime / 60);
                     devsS.setScore(devscore);
                     buggsS.setScore(buggscore);
                     
                     if(buggscore <= 0) {
                       sendMessage(DB + "The buggs has won the game!");
                       End(p);
                       cancel();
                     } else {
                       
                     }
                     
                     if(hasBeenCaptured3 == true) {
                       sendMessage(DB + "The devs has won the game!");
                       
                       End(p);
                       cancel();
                     } else {
                       
                     }
                   }
                   
                   devsS.setScore(devscore);
                   buggsS.setScore(buggscore);
                     
                   gameTime--;
                 } else {
                     sendMessage(DB + "The buggs has won the game");
                     End(p);
                     cancel();
                   }
                 }
               }
             }
             };
             this.countdown.runTaskTimer(this, 0, 20L); // 20L = 1sec
       }
       
       public void End(Player p) {
         World w = Bukkit.getServer().getWorld(getConfig().getString("LeavePoint.world"));
         int x = getConfig().getInt("LeavePoint.x");
         int y = getConfig().getInt("LeavePoint.y");
         int z = getConfig().getInt("LeavePoint.z");
         p.teleport(new Location(w, x, y, z));
         
         inLobby.remove(p.getName());
         if(inDevs.contains(p.getName())) {
             inDevs.remove(p.getName());
         } else if(inBuggs.contains(p.getName())){
           inBuggs.remove(p.getName());
         }
         
         devs = 0;
         buggs = 0;
         lobby = 0;
         
         number = 30;
         gameTime = 900;
         
         devscore = 0;
         buggscore = 50;
         
         Capture1 = 100;
         Capture2 = 100;
         Capture3 = 100;
         general = 100;
         
         hasBeenCaptured1 = false;
         hasBeenCaptured2 = false;
         hasBeenCaptured3 = false;
         
         p.getInventory().clear();
       }
       
       @EventHandler(priority = EventPriority.NORMAL)
      public void PlayerDamageReceive(EntityDamageByEntityEvent e) {
      if(e.getEntity() instanceof Player) {
      Player damaged = (Player) e.getEntity();
       
      if(e.getDamager() instanceof Player) {
      Player damager = (Player) e.getDamager();
       
      if((damaged.getHealth()-e.getDamage()) <= 10) {
       
      //Killed
       
      if(inBuggs.contains(damaged.getName())) {
             World w = Bukkit.getServer().getWorld(getConfig().getString("SpawnB.world"));
             int x = getConfig().getInt("SpawnB.x");
             int y = getConfig().getInt("SpawnB.y");
             int z = getConfig().getInt("SpawnB.z");
             damaged.teleport(new Location(w, x, y, z));
      e.setCancelled(true);
      damaged.setHealth(20);
      sendMessage(DB + damaged.getName() + " was killed by " + damager.getName());
      } else if(inDevs.contains(damaged.getName())) {
             World w = Bukkit.getServer().getWorld(getConfig().getString("SpawnD.world"));
             int x = getConfig().getInt("SpawnD.x");
             int y = getConfig().getInt("SpawnD.y");
             int z = getConfig().getInt("SpawnD.z");
             damaged.teleport(new Location(w, x, y, z));
             buggscore--;
      e.setCancelled(true);
      damaged.setHealth(20);
      sendMessage(DB + damaged.getName() + " was killed by " + damager.getName());
      }
      }
      }
      }
      }
    
    Commands:
    Code:
      public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
         if(cmd.getName().equalsIgnoreCase("Join")) {
             Player p = (Player) sender;
             if(!plugin.inLobby.contains(p.getName())) {
             plugin.Check(p);
             
             plugin.teleport(p);
           } else {
             p.sendMessage(plugin.DB + ChatColor.RED + "You already in a game");
           }
         }
         return false;
       }
    }
    
    The buggs:
    By < 10hp check there happens nothing.:
    Code:
    @EventHandler(priority = EventPriority.NORMAL)
      public void PlayerDamageReceive(EntityDamageByEntityEvent e) {
      if(e.getEntity() instanceof Player) {
      Player damaged = (Player) e.getEntity();
       
      if(e.getDamager() instanceof Player) {
      Player damager = (Player) e.getDamager();
       
      if((damaged.getHealth()-e.getDamage()) <= 10) {
       
      //Killed
       
      if(inBuggs.contains(damaged.getName())) {
             World w = Bukkit.getServer().getWorld(getConfig().getString("SpawnB.world"));
             int x = getConfig().getInt("SpawnB.x");
             int y = getConfig().getInt("SpawnB.y");
             int z = getConfig().getInt("SpawnB.z");
             damaged.teleport(new Location(w, x, y, z));
      e.setCancelled(true);
      damaged.setHealth(20);
      sendMessage(DB + damaged.getName() + " was killed by " + damager.getName());
      } else if(inDevs.contains(damaged.getName())) {
             World w = Bukkit.getServer().getWorld(getConfig().getString("SpawnD.world"));
             int x = getConfig().getInt("SpawnD.x");
             int y = getConfig().getInt("SpawnD.y");
             int z = getConfig().getInt("SpawnD.z");
             damaged.teleport(new Location(w, x, y, z));
             buggscore--;
      e.setCancelled(true);
      damaged.setHealth(20);
      sendMessage(DB + damaged.getName() + " was killed by " + damager.getName());
      }
      }
      }
      }
      }
    
    When the game ends because the time is over or something the bugteam dont get removed/get teleporded or something.
    The gametimer goes very fast and the lobby timer normal.

    This is the reason i want to do it on skype you guys (i think so) gonna never understand this.
     
  25. Offline

    Scimiguy

    @NoSpanMan
    So does it get past this line:
    if(e.getDamager() instanceof Player) {
    ?
     
  26. Offline

    NoSpanMan

    Yeah and then he stops.
     
  27. Offline

    Scimiguy

    @NoSpanMan
    Then your player has more than 10 health
     
  28. Offline

    NoSpanMan

    No because i can dead him
     
  29. Offline

    Scimiguy

    do a debug message to console with Player.getHealth() and see what comes up
    @NoSpanMan
     
  30. Offline

    NoSpanMan

    Error:
    Code:
    [12:53:57 ERROR]: Could not pass event EntityDamageByEntityEvent to Debugger v1.
    0
    org.bukkit.event.EventException
      at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:302) ~[craftbukkit.jar:git-Bukkit-4a7472d]
      at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62) ~[craftbukkit.jar:git-Bukkit-4a7472d]
      at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:501) [craftbukkit.jar:git-Bukkit-4a7472d]
      at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:486) [craftbukkit.jar:git-Bukkit-4a7472d]
      at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callEvent(Craf
    tEventFactory.java:86) [craftbukkit.jar:git-Bukkit-4a7472d]
      at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callEntityDama
    geEvent(CraftEventFactory.java:536) [craftbukkit.jar:git-Bukkit-4a7472d]
      at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.handleEntityDa
    mageEvent(CraftEventFactory.java:449) [craftbukkit.jar:git-Bukkit-4a7472d]
      at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.handleLivingEn
    tityDamageEvent(CraftEventFactory.java:568) [craftbukkit.jar:git-Bukkit-4a7472d]
    
      at net.minecraft.server.v1_8_R3.EntityLiving.d(EntityLiving.java:1092) [
    craftbukkit.jar:git-Bukkit-4a7472d]
      at net.minecraft.server.v1_8_R3.EntityHuman.d(EntityHuman.java:853) [cra
    ftbukkit.jar:git-Bukkit-4a7472d]
      at net.minecraft.server.v1_8_R3.EntityLiving.damageEntity(EntityLiving.j
    ava:733) [craftbukkit.jar:git-Bukkit-4a7472d]
      at net.minecraft.server.v1_8_R3.EntityHuman.damageEntity(EntityHuman.jav
    a:794) [craftbukkit.jar:git-Bukkit-4a7472d]
      at net.minecraft.server.v1_8_R3.EntityPlayer.damageEntity(EntityPlayer.j
    ava:481) [craftbukkit.jar:git-Bukkit-4a7472d]
      at net.minecraft.server.v1_8_R3.EntityHuman.attack(EntityHuman.java:995)
     [craftbukkit.jar:git-Bukkit-4a7472d]
      at net.minecraft.server.v1_8_R3.EntityPlayer.attack(EntityPlayer.java:10
    48) [craftbukkit.jar:git-Bukkit-4a7472d]
      at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java
    :1289) [craftbukkit.jar:git-Bukkit-4a7472d]
      at net.minecraft.server.v1_8_R3.PacketPlayInUseEntity.a(SourceFile:52) [
    craftbukkit.jar:git-Bukkit-4a7472d]
      at net.minecraft.server.v1_8_R3.PacketPlayInUseEntity.a(SourceFile:11) [
    craftbukkit.jar:git-Bukkit-4a7472d]
      at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:1
    3) [craftbukkit.jar:git-Bukkit-4a7472d]
      at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [
    ?:1.8.0_60]
      at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_60]
      at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [craftbukki
    t.jar:git-Bukkit-4a7472d]
      at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:6
    73) [craftbukkit.jar:git-Bukkit-4a7472d]
      at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:3
    35) [craftbukkit.jar:git-Bukkit-4a7472d]
      at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:6
    29) [craftbukkit.jar:git-Bukkit-4a7472d]
      at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java
    :537) [craftbukkit.jar:git-Bukkit-4a7472d]
      at java.lang.Thread.run(Unknown Source) [?:1.8.0_60]
    Caused by: java.lang.IllegalArgumentException: Name cannot be null
      at org.apache.commons.lang.Validate.notNull(Validate.java:192) ~[craftbu
    kkit.jar:git-Bukkit-4a7472d]
      at org.bukkit.craftbukkit.v1_8_R3.CraftServer.getWorld(CraftServer.java:
    968) ~[craftbukkit.jar:git-Bukkit-4a7472d]
      at me.koekjeee.debugger.Main.PlayerDamageReceive(Main.java:580) ~[?:?]
      at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source) ~[?:?]
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1
    .8.0_60]
      at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_60]
      at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:300) ~[craftbukkit.jar:git-Bukkit-4a7472d]
      ... 26 more
    
    Event:
    Code:
    @EventHandler(priority = EventPriority.NORMAL)
      public void PlayerDamageReceive(EntityDamageByEntityEvent e) {
      if(e.getEntity() instanceof Player) {
      Player damaged = (Player) e.getEntity();
       
      System.out.print(damaged.getHealth());
       
      if(e.getDamager() instanceof Player) {
      Player damager = (Player) e.getDamager();
       
      if((damaged.getHealth()-e.getDamage()) <= 10) {
       
      //Killed
       
      if(inBuggs.contains(damaged.getName())) {
             World w = Bukkit.getServer().getWorld(getConfig().getString("SpawnB.world"));
             int x = getConfig().getInt("SpawnB.x");
             int y = getConfig().getInt("SpawnB.y");
             int z = getConfig().getInt("SpawnB.z");
             damaged.teleport(new Location(w, x, y, z));
      e.setCancelled(true);
      damaged.setHealth(20);
      sendMessage(DB + damaged.getName() + " was killed by " + damager.getName());
      } else if(inDevs.contains(damaged.getName())) {
             World w = Bukkit.getServer().getWorld(getConfig().getString("SpawnD.world"));
             int x = getConfig().getInt("SpawnD.x");
             int y = getConfig().getInt("SpawnD.y");
             int z = getConfig().getInt("SpawnD.z");
             damaged.teleport(new Location(w, x, y, z));
             buggscore--;
      e.setCancelled(true);
      damaged.setHealth(20);
      sendMessage(DB + damaged.getName() + " was killed by " + damager.getName());
      }
      }
      }
      }
      }
    
     
Thread Status:
Not open for further replies.

Share This Page