My Plugin Wont do anything!

Discussion in 'Plugin Development' started by GabeGaming11, Mar 1, 2015.

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


    OK, I'm very new to java and plugins so please don't act like I'm being stupid about this post
    I have written a plugin and it does nothing in test. Once you have entered the command, the plugin is supposed to detect every tick if you are close to a villager. When you are within one block radius, you get knocked back away from it. Please help

    package me.gabegaming11.novillagerpush;
    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Player;
    import org.bukkit.entity.Villager;
    import org.bukkit.scheduler.BukkitScheduler;
    import org.bukkit.util.Vector;
    public class NoVillagerPush extends JavaPlugin {
        public void onEnable() {
        public void onDisable() {
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if(!(sender instanceof Player)) {
                sender.sendMessage("You must be a player to run this command!");
                return false;
            Player player = (Player) sender;
            if(label.equalsIgnoreCase("NPVJOIN")) {
            return false;
        public void onCmdJoin(Player player) {
            BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
            scheduler.scheduleSyncRepeatingTask(this, new Runnable() {
                public void run() {
                    for(Entity e : player.getNearbyEntities(1.0, 1.0, 1.0)) {
                        if(e instanceof Villager) {
                            Vector unitVector = player.getLocation().toVector().subtract(e.getLocation().toVector().normalize());
            }, 0L, 1L);
  2. Offline


    It's a pretty bad way. use cmd.getName() against label. I'm not too good in Vectors so I don't know the other part of code is good or not, but I think you wouldn't use Scheduler. Try PlayerMoveEvent against.
    On command put a player's name to a HashMap with true, and on playermoveevent, look the map, if contains the player's name, and it's true, then do the for loop for nearby entities.

    The other possible problem is the plugin.yml. Could you post it here?
  3. Offline


    my plugin.yml I'm sure is good but ok:
    name: NoVillagerPush
    main: me.gabegaming11.novillagerpush.NoVillagerPush
    version: 1.0
    description: enables the plugin for you!
    usage: /<command>


    there is indention but it wont show up. The indentation is made with spaces and not tabs!


    The command was just to start off the schedule but if there is an event, ill use that instead, ill post what happens after testing this!

    {{Posts merged by Myrathi}}
    Last edited by a moderator: Mar 1, 2015
  4. Offline


    With your method, its gunna get VERY ugly if a player goes too close to multiple villagers.
  5. Offline


    The player wont get anywhere near one villager at a time, its a hub design
  6. @GabeGaming11 I know that you're new and all, but there are so many things wrong with your class.
    1. Don't use commandLabel... Use cmd.getName().equalsIgnoreCase("commandName") {}
    2. You're checking if the player is an instanceof Player before the command is ran... Then when the command is ran, it's not going to check if the player is an instanceof Player....
    3. You're returning false. When the command is done, all it will return is /NPVJOIN
    4. What is onCmdJoin(player) supposed to do?
    5. If there are multiple villagers near a player, it's going to get ugly.
    mine-care likes this.
  7. Offline


    This is how you debug.

    • Put Sytem.out.println("Test"); in your omEnable(); If the message does not show, that means that your whole plugin is not being read.
    • Put System.out.println("Test2"); in your onCommand; If the message does not show there, that mean the command isn't even being read.
    • Do this for all possible spots where the problem could be.
Thread Status:
Not open for further replies.

Share This Page