Tutorial Make a minigame plugin!

Discussion in 'Resources' started by xTrollxDudex, Aug 15, 2013.

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

    xTrollxDudex

    Littledaddychop
    Plugin Development?

    I think there should be a getResoure(String) for files in the jar folder, use Input/Output streams to move the data from the jar to a new world folder.
     
  2. Offline

    jojodmo

    How would one go about removing an arena? I was thinking something like this:

    Code:java
    1. //remove arena
    2. public Arena removeArena(Location l){
    3. int num = arenaSize;
    4.  
    5. Arena ar = new Arena(l, num);
    6. arenas.remove(ar);
    7.  
    8. return ar;
    9. }


    And then for the command in my Main.class:

    Code:java
    1. int num = 0;
    2. try{
    3. num = Integer.parsInt(args[0]);
    4.  
    5. cp.sendMessage(ChatColor.GREEN + "Joining...");
    6. }
    7. cp.sendMessage(ChatColor.RED + "Invalid arena ID");
    8. }
     
  3. Offline

    xTrollxDudex

    jojodmo2010
    Again, you mat want to check out this and scroll down to 'removeArena(int)'
     
  4. Hi, I really liked the tutorial but I'm getting an error when removing an arena. I've tried the unmodified code from HitHub and the same thing happens: (error log from my modified version but I didn't change the removeArena function)
    Code:java
    1. [14:55:21 INFO]: franga2000 issued server command: /cwremove 1
    2. [14:55:21 ERROR]: null
    3. org.bukkit.command.CommandException: Unhandled exception executing command 'cwre
    4. move' in plugin CakeWars v1.0.0
    5. at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[cra
    6. ftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    7. at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:19
    8. 6) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    9. at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchCommand(CraftServe
    10. r.java:542) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    11. at net.minecraft.server.v1_7_R1.PlayerConnection.handleCommand(PlayerCon
    12. nection.java:932) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    13. at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java
    14. :814) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    15. at net.minecraft.server.v1_7_R1.PacketPlayInChat.a(PacketPlayInChat.java
    16. :28) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    17. at net.minecraft.server.v1_7_R1.PacketPlayInChat.handle(PacketPlayInChat
    18. .java:47) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    19. at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146
    20. ) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    21. at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craf
    22. tbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    23. at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:6
    24. 55) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    25. at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:2
    26. 50) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    27. at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:5
    28. 45) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    29. at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java
    30. :457) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    31. at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:6
    32. 17) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    33. Caused by: java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
    34. at java.util.ArrayList.rangeCheck(Unknown Source) ~[?:1.7.0_25]
    35. at java.util.ArrayList.remove(Unknown Source) ~[?:1.7.0_25]
    36. at com.franga2000.cakewars.ArenaManager.removeArena(ArenaManager.java:13
    37. 4) ~[?:?]
    38. at com.franga2000.cakewars.ArenaPVP.onCommand(ArenaPVP.java:76) ~[?:?]
    39. at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[cra
    40. ftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    41. ... 13 more
    42. >
    43.  

    This only happens when removing the last arena left in the config. It only removes it from Arenas but not from Arenas.Arenas.
     
  5. Offline

    xTrollxDudex

    franga2000
    You should be removing it from Arenas.Arenas, that's the list you want to remove it from, or remove that entirely.
     
  6. Offline

    Littledaddychop

    xTrollxDudex

    I need to send players to an arena but I need multiple spawn points, what would I say for a onCommand statment?
     
  7. Offline

    Jake6177

  8. Offline

    Littledaddychop

  9. Offline

    jusjus112

  10. Offline

    xTrollxDudex

    Littledaddychop
    Post a thread about it. I don't provide support for parts not included in this tutorial. It is for developers with sufficient knowledge of java and the Bukkit API to implement their own features, and if you don't have that kind of experience, you need to keep practicing before you come back.
     
  11. Offline

    jusjus112

    xTrollxDudex
    And 1 thing, i have an problem with load an arena!
    He does not load the arena with my custom cofig!
    I have for the loadarenas;
    Code:java
    1. public void loadGames(){
    2. arenaSize = 0;
    3.  
    4. if(plugin.getConfig().getIntegerList("Arenas.Arenas").isEmpty()){
    5. return;
    6. }
    7.  
    8. for(int i : plugin.getConfig().getIntegerList("Arenas.")){
    9. Arena a = reloadArena(deserializeLoc(plugin.getConfig().getString("Arenas." + i)));
    10. a.id = i;
    11. }
    12. }

    And my createarena:
    Code:java
    1. public Arena createArena(Player sender, Location l){
    2. int num = arenaSize + 1;
    3. arenaSize++;
    4.  
    5. Arena a = new Arena(l, num);
    6. arenas.add(a);
    7.  
    8. Location loc = sender.getLocation();
    9. String world = sender.getWorld().getName();
    10. int x, y, z;
    11. float yaw, pitch;
    12.  
    13. x = loc.getBlockX();
    14. y = loc.getBlockY();
    15. z = loc.getBlockZ();
    16. yaw = loc.getYaw();
    17. pitch = loc.getPitch();
    18.  
    19. plugin.getConfig().set("Arenas." + num + ".x", x);
    20. plugin.getConfig().set("Arenas." + num + ".y", y);
    21. plugin.getConfig().set("Arenas." + num + ".z", z);
    22. plugin.getConfig().set("Arenas." + num + ".yaw", yaw);
    23. plugin.getConfig().set("Arenas." + num + ".pitch", pitch);
    24. plugin.getConfig().set("Arenas." + num + ".world", world);
    25. plugin.saveConfig();
    26.  
    27. sender.sendMessage(MsgType.ARENA + "" + ChatColor.GREEN + "Created arena " + ChatColor.GOLD + num + ChatColor.GREEN + " in world " + ChatColor.GOLD + sender.getWorld().getName());
    28. return a;
    29. }
     
  12. Offline

    xTrollxDudex

    jusjus112
    Why aren't you using my serializeLoc method just for thay purpose, as well as not using the actual working code along with it?
     
  13. Offline

    jusjus112

    xTrollxDudex
    Because i will using my own config! and if i using "Arenas." it does not work
     
  14. Offline

    xTrollxDudex

    jusjus112
    When you load the arenas, the method expects a serialized string, but you have nothing there, therefore messing everything up
     
  15. xTrollxDudex
    Nice tutorial!
    I checked out your github and found some "errors" which might help others :D

    anyways in the arenaManager in the method removeArena(int i) - instead of list.remove(i); do
    Code:
    list.remove(i-1);
    
    because (fist) arena is 1 as also written in the config so for list the first one is "0"

    another small thing is that in the addPlayer(Player p, int i) method you forgot to add
    Code:
    locs.put(p.getName(), p.getLocation());
    
    to add the location of the player when he leaves the arena

    Anyways nice tutorial!!!!
     
    xTrollxDudex likes this.
  16. Offline

    xTrollxDudex

    goodstuff20
    The first one of yours is incorrect, the remove method removes the object, not at an index. It's an understandable mistake. The second one, I will fix immediately :)

    Thank you for informing me of this.
     
  17. haha sorry didnt look to close :D and no prob cheers
     
  18. Offline

    xTrollxDudex

    To you as well :)
     
    goodstuff20 likes this.
  19. Offline

    ksbdude

    xTrollxDudex
    How would I get the number of players currently in an arena?
     
  20. Offline

    xTrollxDudex

    ksbdude
    PHP:
    ArenaManager.getManager().getArena(/* Stuff */).getPlayers().size();
     
  21. Offline

    ksbdude

    xTrollxDudex

    That works great except in the command the arg could be a string...
    Just like i asked in another thread http://forums.bukkit.org/threads/turn-sign-string-into-int.222511/
    How do i turn a string that is only a number into a int???
    Code:java
    1. public class JoinCommandExecutor implements CommandExecutor {
    2. @Override
    3. public boolean onCommand(CommandSender sender, Command cmd, String label, String args[]){
    4. CommandSender p = sender;
    5. if(cmd.getName().equalsIgnoreCase("join")){
    6. if(args.length != 1){
    7. p.sendMessage("Insuffcient arguments!");
    8. return true;
    9. }
    10. int num = 0;
    11. try{
    12. num = Integer.parseInt(args[0]);
    13. p.sendMessage("Invalid arena ID");
    14. }
    15. ArenaManager.getManager().addPlayer(p, num);
    16. if(ArenaManager.getManager().getArena(args[0]).getPlayers().size() == 3){ //is there 3 players?
    17. //start game
    18. } else {
    19. //tell player how many more players are needed
    20. }
    21. return true;
    22. }
    23. return false;
    24. }
    25. }


    @xTrollxDudex
    It may also work to change the whole thing into strings so you could have names but that sounds more complex.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Dec 6, 2015
  22. Offline

    xTrollxDudex

    ksbdude
    I don't get what you are trying to ask?
     
  23. Offline

    ksbdude

    @xTrollxDudex
    Arenas cant be named. They can only be numbers.
    So I cant use a string as a way to refrence arenas even though the string is a number.

    Heres what my code looks like: http://puu.sh/6ss2A.png
     
  24. Offline

    xTrollxDudex

    ksbdude
    Use num instead of args[0], it was there for a reason :p
     
  25. Offline

    ksbdude

    Found another way around it, thanks anyways!
     
  26. Offline

    bobacadodl

    xTrollxDudex
    Just saying, you should probably make ArenaManager a proper singleton :p
     
  27. Offline

    xTrollxDudex

    If you are referring to my really long post about thread safe singletons, that should not be necessary, sir :p
     
  28. Offline

    bobacadodl

    xTrollxDudex
    Sorry, I don't know what post you're talking about. I was just saying that you should prevent people from creating multiple instances of ArenaManager.
     
    xTrollxDudex likes this.
  29. Offline

    xTrollxDudex

    bobacadodl
    Lol. This was back before I knew how to make singletons properly, thanks for the feedback :)
     
    bobacadodl likes this.
  30. Offline

    Bailey Payne

    xTrollxDudex Thanks man, this has certainly made me feel a bit more confident starting to make mini game plugins now, just gotta play around with it to really feel good before i make one, Thanks again!
     
    xTrollxDudex likes this.
Thread Status:
Not open for further replies.

Share This Page