Plugin Help How do I randomly get something from the config

Discussion in 'Plugin Help/Development/Requests' started by ObviousEmeralds, Nov 21, 2015.

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

    ObviousEmeralds

    Hey, So I'm a somewhat new plugin developer (Started 2 months ago) and now that I know a lot of things, I want to create a small mini-game. I need help with one thing though, In most mini-games (Survival games, Skywars, paintball, etc), Your spawns are on your teams side though they are random (You don't spawn on the exact same block everytime). I know how to make a command to create & save the spawnpoints to the config but how do you make it randomly choose a spawnpoint from the config and use it?

    Sorry if this is a bit confusing​
     
  2. Offline

    Mrs. bwfctower

    @ObviousEmeralds
    1. Store each spawn with a number key ("1", "2", etc).
    2. Pick a random number within the range of the number of spawns.
    3. Get the spawn with that number as the key.
    4. Do whatever you want with that spawn.
     
  3. Offline

    ObviousEmeralds

  4. Offline

    Mrs. bwfctower

  5. Offline

    ObviousEmeralds

    @Mrs. bwfctower Any way to make it do that automaticly with a command?
     
  6. Offline

    Mrs. bwfctower

    @ObviousEmeralds Create a setLocation method that takes an int and Location, and sets "spawns." + id to each of the location's values (world, x, y, z, yaw, pitch).
     
  7. Offline

    ObviousEmeralds

  8. Offline

    Mrs. bwfctower

    @ObviousEmeralds Try something. If it works, great, mark this thread as solved. If it doesn't work then post what you tried, and we'll provide you with assistance. We don't spoonfeed here, so don't ask for it.
     
  9. Offline

    ObviousEmeralds

    @Mrs. bwfctower
    My code to get the location is this:
    Code:
                if(args[0].equalsIgnoreCase("test")){
                    Random r = new Random();
                    World w = p.getWorld();
                    double loc1 = (double) getConfig().get("Spawnpoint.red.", r.nextInt(10+1));
                p.teleport( new Location(w, loc1 ,loc1 ,loc1 ));
                }
    And my config looks like:
    Code:
    Spawnpoint:
      red:
        '1':
          x: -661.7498697110026
          y: 70.0
          z: -20.31236779866728
          yaw: -331.4602355957031
          pitch: 22.35028839111328
        '2':
          x: -663.4531407048074
          y: 70.0
          z: -17.1758408637189
          yaw: -331.4602355957031
          pitch: 22.35028839111328
        '3':
          x: -665.3915705203572
          y: 70.0
          z: -13.612000976717535
          yaw: -331.4602355957031
          pitch: 22.35028839111328
        '4':
          x: -668.6757594051891
          y: 70.0
          z: -7.567237830139611
          yaw: -331.4602355957031
          pitch: 22.35028839111328
        '5':
          x: -669.2968208319704
          y: 70.0
          z: -3.7935500910095534
          yaw: -331.4602355957031
          pitch: 22.35028839111328
        '6':
          x: -669.0265312637869
          y: 70.0
          z: 0.1288653930370844
          yaw: -331.4602355957031
          pitch: 22.35028839111328
        '7':
          x: -670.6359549242227
          y: 70.0
          z: 3.087821152468579
          yaw: -331.4602355957031
          pitch: 22.35028839111328
        '8':
          x: -672.47851390825
          y: 69.0
          z: 6.48074636688971
          yaw: -331.4602355957031
          pitch: 22.35028839111328
        '9':
          x: -674.1004515667339
          y: 69.0
          z: 9.469051120387414
          yaw: -331.4602355957031
          pitch: 22.35028839111328
        '10':
          x: -673.848219715307
          y: 70.0
          z: 12.961662687570755
          yaw: -331.4602355957031
          pitch: 22.35028839111328
    My stack trace is:
    Code:
    null
    org.bukkit.command.CommandException: Unhandled exception executing command 'pvp' in plugin PvP v1.0
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit.jar:git-Bukkit-18fbb24]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:140) ~[craftbukkit.jar:git-Bukkit-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:620) ~[craftbukkit.jar:git-Bukkit-18fbb24]
        at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1106) [craftbukkit.jar:git-Bukkit-18fbb24]
        at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:966) [craftbukkit.jar:git-Bukkit-18fbb24]
        at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(SourceFile:37) [craftbukkit.jar:git-Bukkit-18fbb24]
        at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(SourceFile:9) [craftbukkit.jar:git-Bukkit-18fbb24]
        at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [craftbukkit.jar:git-Bukkit-18fbb24]
        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) [craftbukkit.jar:git-Bukkit-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:673) [craftbukkit.jar:git-Bukkit-18fbb24]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:335) [craftbukkit.jar:git-Bukkit-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:629) [craftbukkit.jar:git-Bukkit-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:537) [craftbukkit.jar:git-Bukkit-18fbb24]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_60]
    Caused by: java.lang.ClassCastException: org.bukkit.configuration.MemorySection cannot be cast to java.lang.Double
        at me.ObviousEmeralds.Pvp.MainClass.onCommand(MainClass.java:134) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit.jar:git-Bukkit-18fbb24]
        ... 15 more
    [17:02:10]

    (The "Caused by" part of the stack trace)
    Code:
    Caused by: java.lang.ClassCastException: org.bukkit.configuration.MemorySection cannot be cast to java.lang.Double
        at me.ObviousEmeralds.Pvp.MainClass.onCommand(MainClass.java:134) ~[?:?]
    
    Line 134 is
    Code:
      double loc1 = (double) getConfig().get("Spawnpoint.red.", r.nextInt(10+1));
     
  10. Offline

    teej107

  11. Offline

    ObviousEmeralds

    @teej107 Yes, I just don't know how to fix it
     
  12. Offline

    Mrs. bwfctower

  13. Offline

    ObviousEmeralds

Thread Status:
Not open for further replies.

Share This Page