Tutorial Make a minigame plugin!

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

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

    xTrollxDudex

    calebbfmv
    No. WorldEdit is really unnecessary for this purpose as it has a bunch of different features we don't need and slows down the server (even though servers have it anyways :p)

    You can always just take 2 points the player clicks on...
     
  2. Offline

    calebbfmv

    xTrollxDudex
    Yeah, but what about everything below it and above the Arena?
     
  3. Offline

    xTrollxDudex

    calebbfmv
    You can always include that in the 2 points if you want to... Actually it's all in the region checks, just check the x and z instead of y
     
    JPG2000 likes this.
  4. Offline

    calebbfmv

    Figured, but some people like the idea of WorldEdit :p.
    How would I go about setting up a lobby wall?
     
  5. Offline

    xTrollxDudex

    calebbfmv
    Use SignChamgeEvent and store the sign somewhere so when you need to update the sign you can
     
  6. Offline

    calebbfmv

    xTrollxDudex
    I got that part, but what about adding it to the board?
    The code would be nice as well.
     
  7. Offline

    xTrollxDudex

    You don't... Add it to the board.

    I think that each sign on the "wall" should be totally independent from each other.
    I don't get "adding" to the board part though. Do you mean this? https://gist.github.com/AgentTroll/640cb8dd9a17ee0de57f
     
  8. Offline

    calebbfmv

    xTrollxDudex
    No I mean along the lines of the Survival Games plugin lobby wall thing.
     
  9. Offline

    xTrollxDudex

    calebbfmv
    That? You use 2 points and Survival Games check if each of the blocks within the 2 points on the wall are all signs. Then, each time an arena is added, the next sign "in line" is updated for the arena. Check the source of survival games on github, I'm too lazy to ATM.
     
  10. Offline

    xTrollxDudex

    [UPDATE]

    OK, fixed up the repo as best as I can, go to the first page on the bottom and check it out, download and compile.

    It should stop throwing the NPE, if it doesn't then....
     
  11. Offline

    xTrollxDudex

    Did you get it to work?
     
  12. Offline

    calebbfmv

    Not yet, as I am currently beta testing it though. What I have found so far is that I can modify the signs using a task that ends the game on a timer, also much more efficient for me. What i am having problems with is setting a different name for each arena on storage.
    Code:java
    1.  
    2. @EventHandler(ignoreCancelled = true, priority = EventPriority.LOW)
    3. public void onPlayerInteract(PlayerInteractEvent event) {
    4. if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
    5. if (event.getItem() != null) {
    6. if (event.getItem().getType() == Material.BLAZE_ROD) {
    7. Player playerP = event.getPlayer();
    8. if(playerP.hasPermission("Lore.Graveyard.Create") || playerP.isOp()){
    9. Location loc1 = event.getClickedBlock().getLocation();
    10. String folder = plugin.getDataFolder().getAbsolutePath()
    11. + File.separatorChar + "graveyard";
    12. File dumb = new File(folder);
    13. if (!dumb.exists())
    14. dumb.mkdir();
    15. File playerFile = new File(plugin.getDataFolder()
    16. .getAbsolutePath()
    17. + File.separatorChar
    18. + "graveyard"
    19. + File.separatorChar
    20. + "graveyards"
    21. + ".yml");
    22. if (!playerFile.exists()) {
    23. try {
    24. playerFile.createNewFile();
    25. } catch (IOException e1) {
    26. e1.printStackTrace();
    27. }
    28. }
    29.  
    30. YamlConfiguration p = YamlConfiguration
    31. .loadConfiguration(playerFile);
    32. p.set("graveyard." + "lworld", loc1.getWorld().getName());
    33. p.set("graveyard." + "Lx", loc1.getBlockX());
    34. p.set("graveyard." + "Ly", loc1.getBlockY());
    35. p.set("graveyard." + "Lz", loc1.getBlockZ());
    36. playerP.sendMessage(ChatColor.AQUA + "Left block set.");
    37. try {
    38. p.save(playerFile);
    39. } catch (IOException e) {
    40. e.printStackTrace();
    41. }
    42. }
    43. }
    44. }
    45. }
    46. }
    47.  
    48. @EventHandler(ignoreCancelled = true, priority = EventPriority.LOW)
    49. public void onRightClick(PlayerInteractEvent event) {
    50. if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    51. if (event.getItem() != null) {
    52. if (event.getItem().getType() == Material.BLAZE_ROD) {
    53. Player playerP = event.getPlayer();
    54. if(playerP.hasPermission("Lore.Graveyard.Create") || playerP.isOp()){
    55. Location loc1 = event.getClickedBlock().getLocation();
    56. String folder = plugin.getDataFolder().getAbsolutePath()
    57. + File.separatorChar + "graveyard";
    58. File dumb = new File(folder);
    59. if (!dumb.exists())
    60. dumb.mkdir();
    61. File playerFile = new File(plugin.getDataFolder()
    62. .getAbsolutePath()
    63. + File.separatorChar
    64. + "graveyard"
    65. + File.separatorChar
    66. + "graveyards"
    67. + ".yml");
    68. if (!playerFile.exists()) {
    69. try {
    70. playerFile.createNewFile();
    71. } catch (IOException e1) {
    72. e1.printStackTrace();
    73. }
    74. }
    75.  
    76. YamlConfiguration p = YamlConfiguration
    77. .loadConfiguration(playerFile);
    78. p.set("graveyard." + "Rworld", loc1.getWorld().getName());
    79. p.set("graveyard." + "Rx", loc1.getBlockX());
    80. p.set("graveyard." + "Ry", loc1.getBlockY());
    81. p.set("graveyard." + "Rz", loc1.getBlockZ());
    82. playerP.sendMessage(ChatColor.AQUA + "Right block set.");
    83. try {
    84. p.save(playerFile);
    85. } catch (IOException e) {
    86. e.printStackTrace();
    87. }
    88. }
    89. }
    90. }
    91. }
    92. }
    93.  
     
  13. Offline

    xTrollxDudex

    calebbfmv
    Add the name parameter in the constructor and a name field in the Arena class. Then create getters and setters for that value
     
  14. Offline

    calebbfmv

    Tried that, I keep getting NPE's
     
  15. Offline

    xTrollxDudex

    calebbfmv
    You need to i utilize it after every realtor, as said in OP
     
  16. Offline

    calebbfmv

    xTrollxDudex
    Its ok, I ended up NOT needing multiple arenas.
     
  17. Offline

    Kymysto

    I have everything working and all except storing the arena information, should I store the information (such as the spawn location) in a config file during the onDisable() or should I store them when the arena is created?
     
  18. Offline

    xTrollxDudex

    Kymysto
    On creation, and as a backup, onDisable. I use both as a multi layered system, but if you want to be economical, save it in the onDisable method.
     
  19. Offline

    calebbfmv

    xTrollxDudex
    Hey man, now that I have dealt with the initial setup and everything, largely thanks to you, I need to do some more stuff, like checking if a player is in an active game, and some other things, how would you go about setting up different game modes with starting, in-session, and end game, all based on players in arena number?
     
  20. Offline

    xTrollxDudex

    calebbfmv
    Check the last page, I explain how I used an enum to have different modes of the game and stuff, you would check each time you do an action the state of the game. And update it.
     
  21. Offline

    calebbfmv

    xTrollxDudex likes this.
  22. Offline

    DailyLove

    Would the arena's and everything in the Lists and Maps save when the plugin is disabled, or when the server is reloaded. Or would I have to save it to a data.yml
     
  23. Offline

    DarkBladee12

    DailyLove You probably need to store it anywhere when the plugin disables/reloads. For example in a flatfile or a MySQL database.
     
    xTrollxDudex likes this.
  24. Offline

    xTrollxDudex

    DailyLove
    Yeah you're gonna have to store it...
     
  25. Offline

    DailyLove

    xTrollxDudex Could you post a method to save to call onDisable, that saves the inv, armor, and arenas. In a yaml file
     
  26. Offline

    xTrollxDudex

    DailyLove
    PHP:
    File file = new File(plugin.getDataFolder(), "data.yml");
    FileConfiguration fc null;

    public 
    void shutdown() {
        if(!
    plugin.getDataFolder().exists() || !file.exists() || fc == null) {
            
    plugin.getDataFolder().mkdir();
            
    file.createNewFile();
            
    fc YamlConfiguration.loadConfiguration(file);
        }
      
        
    //save inventory
        
    for(Map.Entry<StringItemStack[]> inv.entrySet()) {
           
    // fc.set("Inventory." + e.getKey(), InvTools.serialize(e.getValue())); working on this
        
    }

        
    //save armor
        
    for(Map.Entry<StringItemStack[]> armor.entrySet()) {
            
    //fc.set("Armor." + e.getKey(), InvTools.serialize(e.getValue())); working on this
        
    }
            
        
    /*arenas are automatically saved on creation. Here's a quick look back (from repository on page 1):
        if(plugin.getConfig().getString("Arenas." + num).equals(null))
            return a;
        plugin.getConfig().set("Arenas." + num, serializeLoc(l));

        if(plugin.getConfig().getIntegerList("Arenas.Arenas").contains(num))
            return a;
               
        List<Integer> list = plugin.getConfig().getIntegerList("Arenas.Arenas");
        list.add(num);
        plugin.getConfig().set("Arenas.Arenas", list);
        plugin.saveConfig();

        return a;
        */

        //you will not need to save arenas
    }

    public 
    void startup() {
        
    /*This is the load games method. Copied straight from the repo on the first page:
        arenaSize = 0;

        if(plugin.getConfig().getIntegerList("Arenas.Arenas").isEmpty()){
            return;
        }
                    
        for(int i : plugin.getConfig().getIntegerList("Arenas.Arenas")){
            Arena a = createArena(deserializeLoc(plugin.getConfig().getString(i)));
            a.getId() = i;
        }
        */
        
        
    if(!plugin.getDataFolder().exists() || !file.exists() || fc == null) {
            
    plugin.getDataFolder().mkdir();
            
    file.createNewFile();
            
    fc YamlConfiguration.loadConfiguration(file);
        }
       
        
    //load inventory
        
    ConfigurationSection inventory getConfig().getConfigurationSection("Inventory");
        if(
    inventory == null) {
            
    inventory fc.createSection("Inventory");
        }
        
    Set<Stringplayers inventory.getKeys(false);
        for(
    String player players) {
            
    inv.put(playerInvTools.deserialize(fc.getString("Inventory." player)));
        }    

        
    //load armor
        
    ConfigurationSection armor getConfig().getConfigurationSection("Armor");
        if(
    armor == null) {
            
    inventory fc.createSection("Armor");
        }
        
    Set<Stringplayer armor.getKeys(false);
        for(
    String p player) {
            
    armor.put(pInvTools.deserialize(fc.getString("Armor." player)));
        }  
    }
    Inventory method class (https://forums.bukkit.org/threads/serialize-inventory-to-single-string-and-vice-versa.92094/):
    PHP:
    import java.util.Map;
    import java.util.Map.Entry;
     
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
     
    public class 
    InvTools {
        public static 
    String serialize (Inventory invInventory)
        {
            
    String serialization invInventory.getSize() + ";";
            for (
    int i 0invInventory.getSize(); i++)
            {
                
    ItemStack is invInventory.getItem(i);
                if (
    is != null)
                {
                    
    String serializedItemStack = new String();
                   
                    
    String isType String.valueOf(is.getType().getId());
                    
    serializedItemStack += "[email protected]isType;
                   
                    if (
    is.getDurability() != 0)
                    {
                        
    String isDurability String.valueOf(is.getDurability());
                        
    serializedItemStack += ":[email protected]isDurability;
                    }
                   
                    if (
    is.getAmount() != 1)
                    {
                        
    String isAmount String.valueOf(is.getAmount());
                        
    serializedItemStack += ":[email protected]isAmount;
                    }
                   
                    
    Map<Enchantment,IntegerisEnch is.getEnchantments();
                    if (
    isEnch.size() > 0)
                    {
                        for (
    Entry<Enchantment,Integerench isEnch.entrySet())
                        {
                            
    serializedItemStack += ":[email protected]ench.getKey().getId() + "@" ench.getValue();
                        }
                    }
                   
                    
    serialization += "#" serializedItemStack ";";
                }
            }
            return 
    serialization;
        }
       
        public static 
    Inventory deserialize (String invString)
        {
            
    String[] serializedBlocks invString.split(";");
            
    String invInfo serializedBlocks[0];
            
    Inventory deserializedInventory Bukkit.getServer().createInventory(nullInteger.valueOf(invInfo));
           
            for (
    int i 1serializedBlocks.lengthi++)
            {
                
    String[] serializedBlock serializedBlocks[i].split("#");
                
    int stackPosition Integer.valueOf(serializedBlock[0]);
               
                if (
    stackPosition >= deserializedInventory.getSize())
                {
                    continue;
                }
               
                
    ItemStack is null;
                
    Boolean createdItemStack false;
               
                
    String[] serializedItemStack serializedBlock[1].split(":");
                for (
    String itemInfo serializedItemStack)
                {
                    
    String[] itemAttribute itemInfo.split("@");
                    if (
    itemAttribute[0].equals("t"))
                    {
                        
    is = new ItemStack(Material.getMaterial(Integer.valueOf(itemAttribute[1])));
                        
    createdItemStack true;
                    }
                    else if (
    itemAttribute[0].equals("d") && createdItemStack)
                    {
                        
    is.setDurability(Short.valueOf(itemAttribute[1]));
                    }
                    else if (
    itemAttribute[0].equals("a") && createdItemStack)
                    {
                        
    is.setAmount(Integer.valueOf(itemAttribute[1]));
                    }
                    else if (
    itemAttribute[0].equals("e") && createdItemStack)
                    {
                        
    is.addEnchantment(Enchantment.getById(Integer.valueOf(itemAttribute[1])), Integer.valueOf(itemAttribute[2]));
                    }
                }
                
    deserializedInventory.setItem(stackPositionis);
            }
           
            return 
    deserializedInventory;
        }
    }
     
  27. Offline

    Slideroller

    Errors still on ArenaManager.
     
  28. Offline

    xTrollxDudex

  29. Offline

    Slideroller

    What imports? the other ones? because i havent added anything i just added the arenapvp java files to eclipse :I
     
  30. Offline

    xTrollxDudex

Thread Status:
Not open for further replies.

Share This Page