Solved Minigame Help

Discussion in 'Plugin Development' started by ElliottOlson, Jun 18, 2014.

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

    ElliottOlson

    I am currently finalizing the code for the BowSpleef Version 1.0 release, and have come into a bug that I can't resolve. The bug is as follows:

    I have a method which handles all of the player joining events, for example: Saving Inventory, setting Gamemodes, adding to the Arena, etc... And I call this from a command and a sign. The problem is that when a player joins using a command every works perfectly, but when the player joins through the sign function, everything functions except clearing the inventory...

    I want to upload today because this is the final bug, does any one have any idea how to fix this issue?

    Thanks
     
  2. Offline

    thepaperboy99

    Try a using a runnable? That's pretty wired how it only works with a command.
     
  3. Offline

    flaaghara

    Depends on how you are checking the sign interaction and retrieving the player. To me it seems like it might just be a minor bug; post code?
     
  4. Offline

    ElliottOlson


    I am retrieving the player just by using the normal: Player p = e.getPlayer(); for the interaction event. It is setup the same way as the command just doesn't function as it should.
     
  5. Offline

    Gater12

  6. Offline

    ElliottOlson

    Sign: String arena = s.getLine(2);
    Join.join(p, arena, this.plugin);
    return;

    Command: String arena = args[1];
    Join.join(p, arena, this.plugin);
    return true;

    Join Function: Please help http://pastebin.com/gdZBzgXd

    Can anyone figure out why this function gives different outputs?

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

    ElliottOlson

    Can anyone figure out why this works differently with the same method? It would really help me out and allow me to release the plugin..
     
  8. Offline

    fireblast709

    ElliottOlson have you debugged your code? I.e. check if arena is the sane, or check what causes the inventory from not being cleared
     
  9. Offline

    teej107

    ElliottOlson Ok I was about to ask you if you are calling the same method. Can you post your join method code?
     
  10. Offline

    ElliottOlson

    It is the same arena and the exact same function, so by command it works perfectly, but then for no reason when I enter through the sign will the same function it just doesn't clear the inventory. I have no idea why it doesn't clear it. It does the code in front of it, and after it. It just doesn't clear it.

    Code:java
    1. /**
    2. * Copyright Elliott Olson (c) 2014. All Rights Reserved.
    3. * Any code contained within this document, and any associated APIs with similar brandings
    4. * are the sole property of Elliott Olson. Distribution, reproduction, taking snippits, or
    5. * claiming any contents as your own will break the terms of the license, and void any
    6. * agreements with you, the third party.
    7. */
    8. @SuppressWarnings("deprecation")
    9. public class Join {
    10.  
    11.  
    12. public static boolean join(Player player, String arena, BowSpleef plugin) {
    13. if (player.hasPermission("bs.join")) {
    14. if (BowSpleef.arena.contains("arenas." + arena)) {
    15. if (BowSpleef.arena.getBoolean("arenas." + arena + ".enabled")) {
    16. if (!BowSpleef.arena.getBoolean("arenas." + arena + ".inGame")) {
    17. //if (!(BowSpleef.inv.contains(player.getName()))) {
    18. List<String> players = BowSpleef.arena.getStringList("arenas." + arena + ".players");
    19. int max = BowSpleef.arena.getInt("arenas." + arena + ".max-players");
    20. if (players.size() == max) {
    21. player.sendMessage(BowSpleef.prefix + ChatColor.RED + "That arena is already full");
    22. }
    23. if (players.size() >= Math.round(max * 0.66D)) {
    24. CountdownEvent event = new CountdownEvent(arena);
    25.  
    26. Bukkit.getServer().getPluginManager().callEvent(event);
    27.  
    28. new Countdown(event.getArena()).runTaskTimer(plugin, 0L, 20L);
    29.  
    30. BowSpleef.arena.set("arenas." + arena + ".inGame", Boolean.valueOf(true));
    31.  
    32. plugin.saveConfig();
    33. }
    34. int gm = player.getGameMode().getValue();
    35. double health = player.getHealth();
    36. int food = player.getFoodLevel();
    37.  
    38. BowSpleef.inv.set(player.getName() + ".return.gamemode", Integer.valueOf(gm));
    39. BowSpleef.inv.set(player.getName() + ".return.health", Double.valueOf(health));
    40. BowSpleef.inv.set(player.getName() + ".return.food", Integer.valueOf(food));
    41.  
    42. player.setGameMode(GameMode.ADVENTURE);
    43. player.setHealth(player.getMaxHealth());
    44. player.setFoodLevel(20);
    45.  
    46. Location returnPos = player.getLocation();
    47. BowSpleef.inv.set(player.getName() + ".return.x", Integer.valueOf(returnPos.getBlockX()));
    48. BowSpleef.inv.set(player.getName() + ".return.y", Integer.valueOf(returnPos.getBlockY()));
    49. BowSpleef.inv.set(player.getName() + ".return.z", Integer.valueOf(returnPos.getBlockZ()));
    50. BowSpleef.inv.set(player.getName() + ".return.world", returnPos.getWorld().getName());
    51.  
    52. String inv = InventoryString.InventoryToString(player.getInventory());
    53. BowSpleef.inv.set(player.getName() + ".inventory", inv);
    54. BowSpleef.inv.set(player.getName() + ".arena", arena);
    55.  
    56. player.getInventory().clear();
    57.  
    58. World world = player.getWorld();
    59. int x = BowSpleef.arena.getInt("arenas." + arena + ".lobby.x");
    60. int y = BowSpleef.arena.getInt("arenas." + arena + ".lobby.y");
    61. int z = BowSpleef.arena.getInt("arenas." + arena + ".lobby.z");
    62. Location lobby = new Location(world, x, y, z);
    63. player.teleport(lobby);
    64.  
    65.  
    66.  
    67. JoinEvent event = new JoinEvent(player, arena);
    68. Bukkit.getServer().getPluginManager().callEvent(event);
    69.  
    70. players.add(player.getName());
    71. BowSpleef.arena.set("arenas." + arena + ".players", players);
    72. if (players.size() == Math.round(BowSpleef.arena.getInt("arenas." + arena + ".max-players") * 2 / 3)) {
    73. JoinEvent eventS = new JoinEvent(player, arena);
    74. Bukkit.getServer().getPluginManager().callEvent(eventS);
    75. }
    76. for (int p = 0; p < players.size(); p++) {
    77. Bukkit.getPlayer((String) players.get(p)).sendMessage(BowSpleef.prefix + ChatColor.GRAY + player.getName() + ChatColor.AQUA + " joined the arena!" + " " + ChatColor.GRAY + "(" + ChatColor.YELLOW + players.size() +
    78. ChatColor.GRAY + "/" + ChatColor.YELLOW + max + ChatColor.GRAY + ")");
    79. }
    80. plugin.saveConfig();
    81. return true;
    82. //}
    83. //player.sendMessage(BowSpleef.prefix + ChatColor.RED + "You are currently already in a game, leave this to join another.");
    84. // return true;
    85. }
    86. player.sendMessage(BowSpleef.prefix + ChatColor.RED + Language.cfg1.getString("language.gameInProgress"));
    87. return true;
    88. }
    89. player.sendMessage(BowSpleef.prefix + ChatColor.RED + "This game is disabled, you are not able to join this game.");
    90. return true;
    91. }
    92. player.sendMessage(BowSpleef.prefix + ChatColor.RED + "This arena is not in the configuration file.");
    93. return true;
    94. }
    95. player.sendMessage(BowSpleef.prefix + BowSpleef.noPermission);
    96. return true;
    97. }
    98.  
    99. }


    The commented section allowing you to join twice was on purpose so I could test the contents without needing 8 people.

    There you go teej107

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

    teej107

    ElliottOlson The problem is that it is not clearing the players inventory right? When you join via sign?
     
  12. Offline

    ElliottOlson

  13. Offline

    teej107

    Are there any error in the console?
     
  14. Offline

    ElliottOlson

    There are zero errors in the console... So I do not understand why this isn't working... No errors in either Signs or Commands... teej107
     
  15. Offline

    teej107

    ElliottOlson Put in some debug code and see if that executes.
     
  16. Offline

    ElliottOlson

    Could you give me an example? I have never had to add debugging code before.. teej107
     
  17. Offline

    teej107

    ElliottOlson The only reason the player's inventory won't clear is because the if test above is false. (unless it's a Bukkit bug which I doubt it is). Make sure you are passing the exact same parameters with your sign interaction as your command to ensure that they are working. To add in debug code, a simple System.out.println() message or a player.sendMessage() would be fine. Those are guaranteed to execute.
     
  18. Offline

    ElliottOlson

    The player is joining fine, all of the parameters shoot and everything is logged, with them being added to the game correctly, the only problem throughout the entire plugin is not clearing their inventories. I already have a player.sendMessage() in the plugin after they join telling them and all of the players in the game that they joined. teej107

    It correctly teleports them to the lobby of the game, and it does literally every single method that it is programmed to do except clear their inventories. teej107

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

    teej107

    ElliottOlson Add in debug code right next to your clearInventory()
     
  20. Offline

    ElliottOlson

    I added the debug code right next to it, and it successfully registered a message to the player, and it also displayed a message to the console... Seems like there is nothing wrong with it... teej107
     
  21. Offline

    teej107

    ElliottOlson Try putting the clearInventory in a sync delayed task.
     
  22. Offline

    ElliottOlson

    teej107 I attempted to do that to no avail. I have tried copying the Join Method and directly putting it in the sign and command functions. The Command function still functions properly, and the sign function does not. I honestly don't know what could be wrong.....
     
  23. Offline

    LegoPal92

    Honestly, does everyone forget about updateInventory(); ?
     
  24. Offline

    teej107

    LegoPal92 Do you need that after calling clearInventory() everytime? I thought you didn't need to.

    ElliottOlson But try that too anyways.
     
  25. Offline

    ElliottOlson

    LegoPal92 ..................... It is deprecated........... BUT IT WORKED, THANK YOU FOR REMINDING ME OF THE OBVIOUS!
     
  26. Offline

    LegoPal92

    No problem, everyone forgets. All the time. Just because it is deprecated, doesn't mean it doesn't work.
     
    Goblom likes this.
Thread Status:
Not open for further replies.

Share This Page