Plugin wont work

Discussion in 'Plugin Development' started by eternal_blaze128, Aug 7, 2013.

Thread Status:
Not open for further replies.
  1. Code:
    package me.eternal.com;
     
    import java.util.ArrayList;
     
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Egg;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Game extends JavaPlugin implements Listener{
     
        public static ArrayList<Player> playersingame = new ArrayList<Player>();
        public static int start = 121;
        public static int inGame = 301;
       
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String args[]){
            Player player = (Player) sender;
            if (cmd.getName().equalsIgnoreCase("egg")){
                playersingame.add(player);
            }
            return true;
        }
       
        @EventHandler
        public void onPlayerInteract(PlayerInteractEvent e){
            Player player = (Player) e.getPlayer();
            if (start == 0){
                if (e.getAction() == Action.RIGHT_CLICK_AIR){
                    if (e.getMaterial() == Material.WOOD_HOE){
                        player.launchProjectile(Egg.class);
                    }
                }
            }
        }
       
    }
    
    and this
    Code:
    package me.eternal.com;
     
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.Plugin;
     
    public class GameStats implements Listener{
     
        public static final String IN_LOBBY = ChatColor.DARK_GREEN + "Lobby";
        public static final String IN_Game = ChatColor.RED + "In Game";
        public static final String Restarting = ChatColor.DARK_RED + "Restarting";
        public static String main = ChatColor.YELLOW + "[" + ChatColor.GREEN + "EggWars" + ChatColor.YELLOW + "]";
       
        public void gameStart(Plugin p){
            if (Game.playersingame.size() >= 1){
                p.getServer().getScheduler().scheduleSyncRepeatingTask(p, new Runnable(){
                    public void run(){
                        if (Game.start != -1){
                            if (Game.start != 0){
                                if (Game.start == 120){
                                    for (Player pl : Game.playersingame){
                                        pl.sendMessage(main + " 2 Minutes until game starts!");
                                    }
                                }
                                if (Game.start == 90){
                                    for (Player pl : Game.playersingame){
                                        pl.sendMessage(main + " 1 Minute 30 Seconds until game starts!");
                                    }
                                }
                                if (Game.start == 60){
                                    for (Player pl : Game.playersingame){
                                        pl.sendMessage(main + " 1 Minute until game starts!");
                                    }
                                }
                                if (Game.start == 45){
                                    for (Player pl : Game.playersingame){
                                        pl.sendMessage(main + " 45 Seconds until game starts!");
                                    }
                                }
                                if (Game.start == 30){
                                    for (Player pl : Game.playersingame){
                                        pl.sendMessage(main + " 30 Seconds until game starts!");
                                    }
                                }
                                if (Game.start == 15){
                                    for (Player pl : Game.playersingame){
                                        pl.sendMessage(main + " 15 Seconds until game starts!");
                                    }
                                }
                                if (Game.start == 10){
                                    for (Player pl : Game.playersingame){
                                        pl.sendMessage(main + " 10 Seconds until game starts!");
                                    }
                                }
                                if (Game.start == 5){
                                    for (Player pl : Game.playersingame){
                                        pl.sendMessage(main + " 5 Seconds until game starts!");
                                    }
                                }
                                if (Game.start == 4){
                                    for (Player pl : Game.playersingame){
                                        pl.sendMessage(main + " 4 Seconds until game starts!");
                                    }
                                }
                                if (Game.start == 3){
                                    for (Player pl : Game.playersingame){
                                        pl.sendMessage(main + " 3 Seconds until game starts!");
                                    }
                                }
                                if (Game.start == 2){
                                    for (Player pl : Game.playersingame){
                                        pl.sendMessage(main + " 2 Seconds until game starts!");
                                    }
                                }
                                if (Game.start == 1){
                                    for (Player pl : Game.playersingame){
                                        pl.sendMessage(main + " 1 Second until game starts!");
                                    }
                                }
                                Game.start--;
                            }else{
                                for (Player pl : Game.playersingame){
                                    pl.sendMessage(main + " GO!");
                                }
                            }
                        }
                    }
                }, 0, 20);
            }
        }
       
        public void inGame(Plugin p){
            if (Game.start == 0){
                p.getServer().getScheduler().scheduleSyncRepeatingTask(p, new Runnable(){
                    public void run(){
                        if (Game.inGame != -1){
                            if (Game.inGame != 0){
                                if (Game.inGame == 300){
                                    for (Player pl : Game.playersingame){
                                        pl.sendMessage(main + " 5 Minutes until game starts!");
                                    }
                                }
                                if (Game.inGame == 240){
                                    for (Player pl : Game.playersingame){
                                        pl.sendMessage(main + " 4 Minutes until game starts!");
                                    }
                                }
                                if (Game.inGame == 180){
                                    for (Player pl : Game.playersingame){
                                        pl.sendMessage(main + " 3 Minutes until game starts!");
                                    }
                                }
                                if (Game.inGame == 120){
                                    for (Player pl : Game.playersingame){
                                        pl.sendMessage(main + " 2 Minutes until game starts!");
                                    }
                                }
                                if (Game.inGame == 60){
                                    for (Player pl : Game.playersingame){
                                        pl.sendMessage(main + " 1 Minute until game starts!");
                                    }
                                }
                                Game.inGame--;
                            }else{
                                for (Player pl : Game.playersingame){
                                    pl.sendMessage(main + " Game Over!");
                                }
                                Game.inGame--;
                            }
                        }
                    }
                }, 0, 20);
            }
        }
       
        public void gameRestart(){
            if (Game.inGame == 0){
                Game.playersingame.clear();
                Game.start = 121;
                Game.inGame = 301;
            }
        }
       
    }
    
     
  2. Offline

    david_rosales

    Create an onEnable and register your events. If you need help with onenable or registering events, a quick google search should answer that. There might be other problems but that seems to be the only one that popped out at me. Unless you have an onEnable somewhere and i missed it... hope it helps! :D
     
    eternal_blaze128 likes this.
  3. Offline

    zack6849

    in your Game class do this
    Code:
    @Override
    public void onEnable(){
         getServer().getPluginManager().registerEvents(this, this);
    }
    
     
  4. zack6849 yeah ik how to register events but the whole GameStats class isnt working

    ok now i have it all in one class
    Code:
    public ArrayList<Player> playersingame = new ArrayList<Player>();
        public int start = 121;
        public int inGame = 301;
       
        public void onEnable(){
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
            gameStart();
            inGame();
            gameRestart();
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String args[]){
            Player player = (Player) sender;
            if (cmd.getName().equalsIgnoreCase("egg")){
                playersingame.add(player);
            }
            return true;
        }
       
        @EventHandler
        public void onPlayerInteract(PlayerInteractEvent e){
            Player player = (Player) e.getPlayer();
            if (start == 0){
                if (e.getAction() == Action.RIGHT_CLICK_AIR){
                    if (e.getMaterial() == Material.WOOD_HOE){
                        player.launchProjectile(Egg.class);
                    }
                }
            }
        }
       
        public static final String IN_LOBBY = ChatColor.DARK_GREEN + "Lobby";
        public static final String IN_Game = ChatColor.RED + "In Game";
        public static final String Restarting = ChatColor.DARK_RED + "Restarting";
        public static String main = ChatColor.YELLOW + "[" + ChatColor.GREEN + "EggWars" + ChatColor.YELLOW + "]";
       
        public void gameStart(){
            if (playersingame.size() == 1){
                this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
                    public void run(){
                        if (start != -1){
                            if (start != 0){
                                if (start == 120){
                                    for (Player pl : playersingame){
                                        pl.sendMessage(main + " 2 Minutes until game starts!");
                                    }
                                }
                                if (start == 90){
                                    for (Player pl : playersingame){
                                        pl.sendMessage(main + " 1 Minute 30 Seconds until game starts!");
                                    }
                                }
                                if (start == 60){
                                    for (Player pl : playersingame){
                                        pl.sendMessage(main + " 1 Minute until game starts!");
                                    }
                                }
                                if (start == 45){
                                    for (Player pl : playersingame){
                                        pl.sendMessage(main + " 45 Seconds until game starts!");
                                    }
                                }
                                if (start == 30){
                                    for (Player pl : playersingame){
                                        pl.sendMessage(main + " 30 Seconds until game starts!");
                                    }
                                }
                                if (start == 15){
                                    for (Player pl : playersingame){
                                        pl.sendMessage(main + " 15 Seconds until game starts!");
                                    }
                                }
                                if (start == 10){
                                    for (Player pl : playersingame){
                                        pl.sendMessage(main + " 10 Seconds until game starts!");
                                    }
                                }
                                if (start == 5){
                                    for (Player pl : playersingame){
                                        pl.sendMessage(main + " 5 Seconds until game starts!");
                                    }
                                }
                                if (start == 4){
                                    for (Player pl : playersingame){
                                        pl.sendMessage(main + " 4 Seconds until game starts!");
                                    }
                                }
                                if (start == 3){
                                    for (Player pl : playersingame){
                                        pl.sendMessage(main + " 3 Seconds until game starts!");
                                    }
                                }
                                if (start == 2){
                                    for (Player pl : playersingame){
                                        pl.sendMessage(main + " 2 Seconds until game starts!");
                                    }
                                }
                                if (start == 1){
                                    for (Player pl : playersingame){
                                        pl.sendMessage(main + " 1 Second until game starts!");
                                    }
                                }
                                start--;
                            }else{
                                for (Player pl : playersingame){
                                    pl.sendMessage(main + " GO!");
                                }
                            }
                        }
                    }
                }, 0, 20);
            }
        }
       
        public void inGame(){
            if (start == 0){
                this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
                    public void run(){
                        if (inGame != -1){
                            if (inGame != 0){
                                if (inGame == 300){
                                    for (Player pl : playersingame){
                                        pl.sendMessage(main + " 5 Minutes until game starts!");
                                    }
                                }
                                if (inGame == 240){
                                    for (Player pl : playersingame){
                                        pl.sendMessage(main + " 4 Minutes until game starts!");
                                    }
                                }
                                if (inGame == 180){
                                    for (Player pl : playersingame){
                                        pl.sendMessage(main + " 3 Minutes until game starts!");
                                    }
                                }
                                if (inGame == 120){
                                    for (Player pl : playersingame){
                                        pl.sendMessage(main + " 2 Minutes until game starts!");
                                    }
                                }
                                if (inGame == 60){
                                    for (Player pl : playersingame){
                                        pl.sendMessage(main + " 1 Minute until game starts!");
                                    }
                                }
                                inGame--;
                            }else{
                                for (Player pl : playersingame){
                                    pl.sendMessage(main + " Game Over!");
                                }
                                inGame--;
                            }
                        }
                    }
                }, 0, 20);
            }
        }
       
        public void gameRestart(){
            if (inGame == 0){
                playersingame.clear();
                start = 121;
                inGame = 301;
            }
        }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  5. what about onDisable or is that not required for this?
     
  6. king_of_all96543 its not required my problem is that when i do /egg it add me to arraylist but gameStart() isnt enabling
     
  7. eternal_blaze128 o ok well i would love to help but sadly i aint that far into programming yet lol sorry
     
  8. Offline

    monkeymanboy

    I see a problem with your launching eggs with hoe I think you need to do player.getItemInHand() instead of doing
    e.getMaterial()
     
  9. the launching works fine but the game isnt starting when there is 1 player in arraylist
     
Thread Status:
Not open for further replies.

Share This Page