Solved Minigame Help

Discussion in 'Plugin Development' started by AcePilot10, Mar 3, 2015.

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

    AcePilot10

    So I have a good knowledge of Java (at least I think) and I have attempted to to make a simple small minigame. Iv'e tried to use my own code with the influence of tutorials so that's why i'm scared I made some mistakes. So the minigame is BoneBasher. Basically you just hit other players with a bone that knockback 25. The part iv'e had doubts in is the Arena class. All I want is the ability to create arenas. I only have two classes commands(main class), and Arena class. Here's my code.
    Code:
    package me.AcePilot10.BoneBasher;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Commands extends JavaPlugin implements Listener {
       
        @Override
        public void onEnable() {
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
            this.getLogger().info("BoneBasher has been enabled!");
        }
       
        public boolean onCommand(CommandSender sender, Command cmd,
                String label, String[] args) {
            Player player = (Player) sender;
           
            if(cmd.getName().equalsIgnoreCase("bb")) {
               
                if(args.length == 2 || args[1].equalsIgnoreCase("create")) {
                    sender.sendMessage(ChatColor.BLUE + "Attempting to create arena " + args[2]);   
                    Arena.createArena(player.getLocation(), args[2]);
                    sender.sendMessage(ChatColor.GREEN + "Success!");
                }
               
                if(args.length != 2) {
                    sender.sendMessage(ChatColor.RED + "Too little args");
                    return true;
                }
               
                else if(args.length == 2 || args[1].equalsIgnoreCase("join")) {
                    Arena.teleportToSpawn(args[2]);   
                }
               
                if(args.length != 2) {
                    sender.sendMessage(ChatColor.RED + "Too little args");
                    return true;
                }
            }
            return false;
        }
    Code:
    package me.AcePilot10.BoneBasher;
    
    import java.util.ArrayList;
    
    import org.bukkit.Location;
    import org.bukkit.entity.Player;
    
    public class Arena {
       
        ArrayList<Player> inArena = new ArrayList<Player>();
       
        private static Location loc;
        private static String ID;   
       
        public Arena(Location loc, String ID) {
            loc = Arena.loc;
            ID = Arena.ID;
        }
       
        public Location getLocation() {
            return Arena.loc;
        }
       
        public String getID() {
            return Arena.ID;
        }
       
        public static Arena createArena(Location loc, String ID) {
            loc = Arena.loc;
            ID = Arena.ID;
            Arena a = new Arena(loc, ID);
            return a;
        }
       
        public static Location teleportToSpawn(String ID) {
            ID = Arena.ID;
            if(ID != null);
            return loc;
        }
       
        public boolean isIngame(Player player) {
            if(inArena.contains(player)) {
            }
            return isIngame(player);
        }
    }
    
     
  2. Offline

    Skionz

    @AcePilot10 You never actually asked what you need help with, but I have some things to point out.
    1. Don't blindly cast anything
    2. Check array lengths before using a value stored in one
    3. Enable messages are redundant as Bukkit does this for you
    4. Remove the static. You currently can only have one arena.
     
  3. Offline

    AcePilot10

    how would I be able to have multiple arenas and save them as a String?

    oops sorry double posted by accident

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 13, 2016
  4. A little example, you can found a lot of tuts searching a bit .
    Code:java
    1.  
    2. public class Arena() {
    3.  
    4. public static List<Arena> arenas = new ArrayList<>();
    5.  
    6. private String name;
    7.  
    8. public Arena(String name) {
    9. this.name = name;
    10. arenas.add(this);
    11. }
    12.  
    13. public String getName() {
    14. return this.name;
    15. }
    16. public void setName(String name) {
    17. this.name = name;
    18. }
    19. }
    20.  

    Usage:
    Code:java
    1.  
    2. Arena arena = new Arena("test");
    3.  
     
  5. Offline

    AcePilot10

    @MaTaMoR_ @Skionz thanks so much for the help :D now i can finish the minigame!
     
  6. Offline

    MordorKing78

    @AcePilot10 Please mark the thread as solved so other developers won't go over a post that is already solved.
     
Thread Status:
Not open for further replies.

Share This Page