Duels

Discussion in 'Plugin Development' started by iAstronaut, Jun 22, 2017.

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

    iAstronaut

    Hey Bukkit,

    I'm trying to make a duels plugin, and I need some help with the understanding of what's going on as I am still in early stages of learning but would really like to pull off this plugin.

    So far, I've got a basic command setup that makes sure the target is online etc etc, but there are a few things I have no idea how to do.

    If anybody could give a tutorial for making a duels plugin or even separate tutorials for the parts of Bukkit I'm yet to learn, please leave a link in your post. It'd be greatly appreciated.

    1. Arenas

    So I'll be using warps as the arenas, my only issue is making sure that these warps have certain rules as in no non-Duels commands and no breaking the map etc etc. As well as ensuring that no more than 2 players are allowed at a warp at any one time.

    2. Kits

    Are kits as easy as I'm hoping in that you just give the player the duel kit when they spawn at the warp?

    3. Betting

    A lot of my players have requested that I add a betting system to the plugin but I have no idea how this would work, other than needing to import Vault and giving the winner the cash draw.

    I understand this is a super spoonfed request, I just hope you'll share my understanding that everybody needed to start somewhere, and I've decided to start by developing quite advanced plugins so that I get to know lots of aspects of Java and Bukkit instead of just a few from making basic plugins.

    I wish you all the best, and I'd like to give an enormous thank you in advance.

    ~ iAstronaut
     
  2. Offline

    Zombie_Striker

    @iAstronaut
    No one on the bukkit forum will spoonfeed you code. However, we will guide you and point out any flaws or mistakes you may make.

    For #1
    1. Create a new class. This will be called Arena. This will store all the area data.
    2. In this class, create a field for storing the player dueling (a List of players), a boolean saying whether the duel is active, and the location of the arena (along with the two warping spots).
    3. Back in the main class, create a List of Arenas. This is how you will get all the arenas
    4. Whenever you want to create a new arena, create a new Arena instance and add it to the list.
    5. To find an open arena, for loop through the list. If the arena's boolean is equal to false, then warp them to that arena, add the players to the list, and set the boolean to true.
    6. Assuming you have a small amount of arenas, you may want to add code checking if the players have been warped to an arena. If they have not been worked, message them that there are no open arenas.
    For #2
    1. Yes, it is that simple. The best way to do this would be to just create a List of itemstacks for each kit. Just simply add all the items to the kit that you want.
    2. When a player asks for the kit, for loop through the kit and add all the itemstack's to their inventory.
    For #3
    1. Hook into vault. First, set Vault as a dependency by adding Vault to the build path (the same way you do it for Bukkit).
    2. You can find code for setting up the economy at the bottom of this post:
    3. When a player wants to bet, see if they have enough money in their balance (you can access their balance by using econ.getBalance(....) )
    4. If they do, withdraw the amount of add the amount the betted to a pool. Store which dueler' the player bet on.
    5. When the duel is over, take the money and divide it across all the players who bet on the right player.
    6. [If you allow for multiple bets/ bets of different amounts] also store the amount a person bet, and instead of dividing even across all players, give each player a percentage of the money relative to the amount that they bet.

    Code:
        private static Economy econ = null;
        private static Permission perms = null;
        private static Chat chat = null;
    
        @Override
        public void onEnable() {
            if (!setupEconomy() ) {
                log.severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
                getServer().getPluginManager().disablePlugin(this);
                return;
            }
            setupPermissions();
            setupChat();
        }
       
        private boolean setupEconomy() {
            if (getServer().getPluginManager().getPlugin("Vault") == null) {
                return false;
            }
            RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
            if (rsp == null) {
                return false;
            }
            econ = rsp.getProvider();
            return econ != null;
        }
       
        private boolean setupChat() {
            RegisteredServiceProvider<Chat> rsp = getServer().getServicesManager().getRegistration(Chat.class);
            chat = rsp.getProvider();
            return chat != null;
        }
       
        private boolean setupPermissions() {
            RegisteredServiceProvider<Permission> rsp = getServer().getServicesManager().getRegistration(Permission.class);
            perms = rsp.getProvider();
            return perms != null;
        }
        
     
  3. Offline

    Iran

    for Duels you need to create an 'Duel' Object that holds Player1 and Player2 and any other information you would like. Then you can create some sort of class that manages these duels, I usually call it DuelManager. Then I would store every duel that is started in a ArrayList. Then using the list of your duels you use events to check if players are in a duel or not and if they can break blocks, place blocks, etc (pretty much anything you'd want). Hope this helps!
     
  4. Offline

    Zombie_Striker

    @iAstronaut
    From a PM:
    In my guide for the arena classes, I recommended using a boolean which will be equal to whether the arena is active (Look at step two for #1). Just check if that boolean is equal to true to know if it is active.
     
Thread Status:
Not open for further replies.

Share This Page