Tutorial Make a minigame plugin!

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

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

    ChipDev

    Great tut :)
     
    xTrollxDudex likes this.
  2. Offline

    xTrollxDudex

    Man. I wrote this a while back, there are still mistakes xD. Thanks.
     
    Skionz likes this.
  3. Offline

    TheCakeMaster

    @xTrollxDudex
    How would I get the amount of players within a certain gameID?
     
  4. Offline

    xTrollxDudex

    PHP:
    int playersInArena ArenaManager.getInstance().getArena(gameID).getPlayers().size();
     
    TheCakeMaster likes this.
  5. Offline

    TheCakeMaster

    Thanks! Great tutorial btw
     
    xTrollxDudex likes this.
  6. Offline

    ProStriker123

    @xTrollxDudex, Am i able to add Yaw;Pitch to the serialize location?
     
  7. Offline

    xTrollxDudex

    Yes you can. Just append them after the rest. Be sure to parse them however.
     
    ProStriker123 likes this.
  8. Offline

    ProStriker123

    @xTrollxDudex, To be sure like that am i right?
    Code:
    public static String serializeLoc(Location l){
            return l.getWorld().getName()+","+l.getBlockX()+","+l.getBlockY()+","+l.getBlockZ()+","+l.getYaw()+","+l.getPitch();
        }
       
        public static Location deserializeLoc(String s){
            String[] st = s.split(",");
            return new Location(Bukkit.getWorld(st[0]), Integer.parseInt(st[1]), Integer.parseInt(st[2]), Integer.parseInt(st[3]), Integer.parseInt(st[4]), Integer.parseInt(st[5]));
        }
     
  9. Offline

    xTrollxDudex

    Looks fine!
     
  10. Offline

    AdityaTD

    @Assist Please make a Good Tutorial of TDM MiniGame!!
     
  11. @AdityaTD
    I've been meaning to continue this tutorial for a very long time now, and I actually wrote a continuation some time ago, but accidentally deleted it, I'll see if I can redo it sometime soon.
     
  12. Fist Of all i realy love this tutorial used it many times but now i got to a point i am stuck i want to write a new create message ChatColor.green + "succesfully created Arena : " and then the arena number but i dont know how to get the spesific id so my question is how do i grab the id from a arena
     
  13. Offline

    Stuperfied

    Still glad you wrote this? XD

    Great tutorial. I'm an intermediate developer about to make my first arena plugin. Rather than use trial and error to figure out the best way to go about it, I thought it would be a good idea to look at what others had come up with first.

    Its the concepts that are important to me and I like how you kept it to the bare bones. For instance, you didn't add bounds to the arena's but simply made the users current location the arena. This was confusing to me until I thought about it. Arena's usually have walls and players are either flagged as being in the game or not, der... lol. However I think i'll still add some worldedit to detect players entering and leaving in case players decide to glitch in or out of an arena.

    From your tutorial I learned that an arena is simply a spawn point and a collection of tracked players, not the big cuboid area where you need to track everything inside.

    Thanks, this helped a lot. XD
     
  14. Offline

    xTrollxDudex

    When you create an arena, an Arena object is returned. You can use getId() from the returned arena to get the id.

    Code:
    Arena newArena = ArenaManager.getInstance().createArena(location);
    int id = newArena.getId();
     
  15. Only your remove method on github isn't working...
    Great tutorial, I learned much from this! Thank you!
     
  16. Offline

    Fouzer

    Well, I have a question:

    In order to manage multiple mini-games in my server I have made the Arena class a abstract one, and any Arenas just inherit it (Exemple: ArenaSkyWars extends Arena, OR ArenaMurder extends Arena) and I just have as many objects of that subclass needed. In order to make the ArenaManager class able to manage any of those subclasses of Arenas I made the ArenaManager a interface and now my classes implement it (Exemple: ArenaManagerSkyWars implements ArenaManager, OR ArenaManagerMurder implements ArenaManager). My question is: Would you advice that was made as it is? The plugin shoud have just ONE ArenaManager class and is my job to make it polymorphic enough to accept any subclasses of Arenas? I ask because is kind of crazy to have to retrieve what kind of ArenaManager I shoud use on a Listener, Exemple:

    PHP:
    public class PlayerDeath implements Listener {

        @
    EventHandler
        
    public void onPlayerDeath(PlayerDeathEvent event) {
            
    ArenaManager arenaManager;
            
    String arenaName;
            
    int remainingPlayers;
            
    Player player event.getEntity().getPlayer();
            
    Player killer event.getEntity().getKiller();
            
    UUID playerUUID player.getUniqueId();
            
    PlusPlayer plusPlayer PlusPlayerManager.getData(playerUUID);
            
    event.setDeathMessage(null);
            if (!
    ArenaManagerSkyWars.getManager().getPlayerInArena(plusPlayer).equals(null)) {
                
    arenaManager ArenaManagerSkyWars.getManager();
                
    arenaName arenaManager.getPlayerInArena(plusPlayer);
                
    remainingPlayers ArenaManagerSkyWars.getManager().getArena(arenaName).getPlusPlayers().size() - 1;
            } else {
                
    arenaManager ArenaManagerMurder.getManager();
                
    arenaName arenaManager.getPlayerInArena(plusPlayer);
                
    remainingPlayers arenaManager.getArena(arenaName).getPlusPlayers().size() - 1;
            }

                if (
    plusPlayer.getPlayerState() == PlayerState.INGAME) {
                    
    arenaManager.removePlayer(plusPlayerPlayerState.INLOBBYarenaName);
             

            }
            }
            }
    Should I have a if check to see what subclass of ArenaManager the Listener would use? Or I'm just overcomplicating stuff and my plugin should have just one ArenaManager class that can manage any subclasses of Arena? Sorry for the bad english and I would very much apreciate your time @xTrollxDudex (OR anyone else that could help me) :)
     
    Last edited: Jan 13, 2017
  17. Offline

    xTrollxDudex

    @Fouzer
    I highly recommend that you use only one ArenaManager. Store your arenas in a collection of <Arena> since all of your subtypes extend that superclass anyways. Assuming the player is only in one arena at a time, that way, you can locate the arena based on the player list of each arena.

    You can also have a WeakHashMap<Player, Arena> if you want to look up arena by player.
     
  18. Offline

    Fouzer

    I did exactly that, the get Arena works like:

    PHP:
    public Arena getArena(String name) {
            for (
    Arena a arenas) {
                if (
    instanceof ArenaSkyWars && a.getName().equals(name)) {
                    
    ArenaSkyWars arenaSkyWars = (ArenaSkyWarsa;
                    return 
    arenaSkyWars;
                }

                if (
    instanceof ArenaMurder && a.getName().equals(name)) {
                    
    ArenaMurder arenaSkyWars = (ArenaMurdera;
                    return 
    arenaSkyWars;
                }
            }
            return 
    null;
        }
    And in each method I just check the method instance to perform different actions.
     
  19. Offline

    xTrollxDudex

    @Fouzer
    Again I recommend that you use a Map to String, Arena and return that. You do not need to cast or instance check, just return whatever arena has that name, assuming that each arena has a different name.
     
  20. Offline

    Fouzer

    Would that HashMap be <ArenaName, Arena>?
    And if I'm getting the Arena with it's name, not checking its instance or casting how would a method like add() work? I mean, if I want the add() method to Murder to be different than the one to SkyWars, wouldn't that require a instance check ,and after that a casting to be able to access a method that just exist in such class? Exemple:

    PHP:
        public void addPlayer(Player pint i) {
            
    Arena a this.getArena(i);
            if (
    == null) {
                
    p.sendMessage("Invalid arena!");
                return;
            }

            if (
    this.isInGame(p)) {
                
    p.sendMessage("Cannot join more than 1 game!");
                return;
            }
            
    a.getPlayers().add(p.getUniqueId());
            
    locs.put(p.getUniqueId(), p.getLocation());
            
    p.teleport(a.spawn);
          
            
    //For this exemple, let's suppose that I want to give different itens deppending in which minigame the player is joining.
            
    if (instanceof ArenaSkyWars) {
            
    // And if I want to acess some method/information that exists just in one of the child classses, I would have to cast it to have acess right?
            //As it follows:
            
    ArenaSkyWars arenaSkyWars = (ArenaSkyWarsa;
            
    a.methodThatJustExistsInArenaSkyWars(someparam);
                
    player.give(Material.APPLE)
            }
            if (
    instanceof ArenaMurder) {
            
    ArenaMurder arenaMurder = (ArenaMurdera;
            
    a.methodThatJustExistsInMurder(someparam);
                
    player.give(Material.GOLDEN_APPLE)
            }
        }
    If I got the hashmap right I understood your sugestions to the getArena method, but in the other methods a instance check is needed? Or not?

    Sorry for the code/english mistakes, I couldn't put the code through a IDE.
     
    Last edited: Feb 1, 2017
  21. Offline

    xTrollxDudex

    @Fouzer
    Assuming that each of your arena implementations extend Arena, then no, you don't need a cast or an instanceof check.
     
  22. Offline

    pretocki3

    @Fouzer
    How's about put getType() at Arena class then use type for check. I think it good than instanceof
     
  23. Offline

    Fouzer

    That would definitely work as well.
     
  24. @xTrollxDudex I have checked your github content of a PVP plugin.
    And there seems something wrong with the command: Remove.
    When you use the try{}catch method.
    You are setting the number to the argument giving with it.
    But what if you typ the number: 0?
    Then it just tells you nothing, (no errors or messages). Maybe you can look to this?
     
  25. Offline

    WattMann

    i don't want to be rude... but why you used "this" in static context ?
     
Thread Status:
Not open for further replies.

Share This Page