Solved Teleport player in Map, to spawnpoints in config file

Discussion in 'Plugin Help/Development/Requests' started by MinecraftMart, Jan 12, 2015.

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

    MinecraftMart

    So let's say i have 3 players in my map with the name of the arena as an value.
    I want to teleport those 3 players to spawnpoints that i have saved in my config. But i have more than 3 spawnpoints. The spawnpoints are called 1, 2, 3, etc.

    How would i do this? I have tried several things... but i cant seem to think of anything good.
     
  2. Offline

    mythbusterma

    @MinecraftMart

    You're going to have to explain better, but from what I understand of your post, all you have to do is iterate over all the Players and iterate cyclically over the spawns.
     
  3. Offline

    MinecraftMart

    @mythbusterma

    Yeah, that is it. But how would i iterate over all the players with one certain value.

    And how would i iterate over the spawns stored in a config file.
     
  4. Offline

    mythbusterma

    @MinecraftMart

    It would probably be a lot easier if you just kept track of an "Arena" object and each one of those kept track of it's own Players.
     
  5. Offline

    MinecraftMart

    @mythbusterma

    What do you mean? Because players need to be able to create new arenas whenever they want.
     
  6. Offline

    mythbusterma

    @MinecraftMart

    And Java is quite capable of instantiating new Objects whenever it wants, it's almost like it was designed to do that.
     
  7. Offline

    MinecraftMart

    @mythbusterma

    But can i do it my way? And could you give an example?

    Bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 13, 2016
  8. Offline

    unrealdesign

    He's saying in your arena object store List<Player> and then in your main class or your class handler, save List<Arena>. Also, in your Arena class have a method called getSpawn() (which obviously returns a location of the spawn you got from the config) and another called hasPlayer(Player p) (which checks if that particular arena instance List<Player> has that pl ayer in the list). Then whenever you want to spawn your players to the arena, do a loop through all of your saved arena instances and find the one that has the correct player(s), then after that, loop through all the players and spawn them.

    Sorry if that sounded confusing, but the OOP is a lot simpler if you just type it out lol
     
  9. Offline

    MinecraftMart

    @unrealdesign
    Its a bit confusing yeah xD but for now i got this wich gives me an error

    Code:
                if(args[0].equalsIgnoreCase("start")){
                    if(game.players.containsKey(p.getUniqueId())){
                        String arenaname = game.players.get(p.getUniqueId());
                        ArrayList<UUID> listofplayer = new ArrayList<UUID>();
                        for (Entry<UUID, String> entry : game.players.entrySet())
                        {
                            if(entry.getValue().equalsIgnoreCase(arenaname)){
                                listofplayer.add(entry.getKey());
                            }
                        }
                        for(int i=0; i<listofplayer.size()+1; i++){
     THIS IS LINE 95    UUID uuid = (UUID)listofplayer.get(i);
                           for(Player player : Bukkit.getServer().getOnlinePlayers()){
                               if(player.getUniqueId().equals(uuid)){
                                   p.sendMessage(main.arenas.getString("arenas." + arenaname + "." + i+1 + ".world"));
                                  /* Location loc = new Location(world, main.arenas.getDouble("arenas." + arenaname + "." + i+1 + ".X")
                                           ,main.arenas.getDouble("arenas." + arenaname + "." + i+1 + ".Y"),
                                           main.arenas.getDouble("arenas." + arenaname + "." + i+1 + ".Z"));
                                   player.teleport(loc);*/
                               }
                           }
                        }
                    }
                }
    Error
    Code:
    [00:03:28 INFO]: MinecraftMart issued server command: /gof start
    [00:03:28 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'gof'
    in plugin GOFMinigame v1
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spi
    got_server.jar:git-Spigot-47b1dff-f233e7d]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:14
    1) ~[spigot_server.jar:git-Spigot-47b1dff-f233e7d]
            at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCommand(CraftServe
    r.java:645) ~[spigot_server.jar:git-Spigot-47b1dff-f233e7d]
            at net.minecraft.server.v1_8_R1.PlayerConnection.handleCommand(PlayerCon
    nection.java:1115) [spigot_server.jar:git-Spigot-47b1dff-f233e7d]
            at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java
    :950) [spigot_server.jar:git-Spigot-47b1dff-f233e7d]
            at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java
    :26) [spigot_server.jar:git-Spigot-47b1dff-f233e7d]
            at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java
    :53) [spigot_server.jar:git-Spigot-47b1dff-f233e7d]
            at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [spi
    got_server.jar:git-Spigot-47b1dff-f233e7d]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [
    ?:1.7.0_60]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.7.0_60]
            at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:6
    83) [spigot_server.jar:git-Spigot-47b1dff-f233e7d]
            at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:3
    16) [spigot_server.jar:git-Spigot-47b1dff-f233e7d]
            at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:6
    23) [spigot_server.jar:git-Spigot-47b1dff-f233e7d]
            at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java
    :526) [spigot_server.jar:git-Spigot-47b1dff-f233e7d]
            at java.lang.Thread.run(Unknown Source) [?:1.7.0_60]
    Caused by: java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
            at java.util.ArrayList.rangeCheck(Unknown Source) ~[?:1.7.0_60]
            at java.util.ArrayList.get(Unknown Source) ~[?:1.7.0_60]
            at nl.hotmail.mcpkmart.GOFMinigame.Command.onCommand(Command.java:95) ~[
    ?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spi
    got_server.jar:git-Spigot-47b1dff-f233e7d]
            ... 14 more
     
  10. Offline

    unrealdesign

    @MinecraftMart This forums is meant for help with the Bukkit API and not to teach basic java. What you have is a
    IndexOutOfBoundsException. Learn what this is.

    Second, don't make global variables public, it is bad practice. I'm looking at your class that has the instanced variable name "game".
     
  11. Offline

    MinecraftMart

    @unrealdesign

    I know what it is, i dont know why it is out of bounds... and i never made the instanced variable public.. I dont know how you can even see my "class" and if you didnt ment that next time ask for the full class. I will be happy to provide it.

    K it should work my way but i got an error with getting the world. It return nothing.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 13, 2016
Thread Status:
Not open for further replies.

Share This Page