Solved PlayerJoinEvent is not being called.

Discussion in 'Spigot Plugin Development' started by BadBoy6767, Sep 24, 2015.

  1. I have a plugin I made for an entire server (my server) and I'm having some troubles with it.
    All the event listening methods are working except for join(PlayerJoinEvent).
    It has an @EventHandler annotation before it and the listener is being registered:
    Code (Text):
    package org.midnightas.mctower;

    import java.io.File;
    import java.util.Arrays;
    import java.util.List;
    import java.util.Random;

    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.entity.Villager;
    import org.bukkit.entity.Villager.Profession;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.event.player.PlayerInteractEntityEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerQuitEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.plugin.java.JavaPlugin;

    import com.dsh105.echopet.api.EchoPetAPI;
    import com.xxmicloxx.NoteBlockAPI.NBSDecoder;
    import com.xxmicloxx.NoteBlockAPI.RadioSongPlayer;
    import com.xxmicloxx.NoteBlockAPI.Song;

    public class MCtower extends JavaPlugin implements Listener {

        private Song music1;
        private RadioSongPlayer player;
        private Inventory attractions = Bukkit.createInventory(null, 9, "Attractions");

        public class SetSpawn implements CommandExecutor {
            @Override
            public boolean onCommand(CommandSender sender, Command cmd, String lbl, String[] args) {
                Player p = (Player) sender;
                List<String> spawns = getConfig().getStringList("spawns");
                getConfig().set(args[0] + ".x", p.getLocation().getBlockX());
                getConfig().set(args[0] + ".y", p.getLocation().getBlockY());
                getConfig().set(args[0] + ".z", p.getLocation().getBlockZ());
                getConfig().set(args[0] + ".w", p.getLocation().getWorld().getName());
                spawns.add(args[0]);
                getConfig().set("spawns", spawns);
                saveConfig();
                return true;
            }
        }

        public class Spawn implements CommandExecutor {
            @Override
            public boolean onCommand(CommandSender sender, Command cmd, String lbl, String[] args) {
                Player p = (Player) sender;
                List<String> spawns = getConfig().getStringList("spawns");
                String s = spawns.get(new Random().nextInt(spawns.size()));
                p.teleport(new Location(Bukkit.getWorld(getConfig().getString(s + ".w")), getConfig().getInt(s + ".x"),
                        getConfig().getInt(s + ".y"), getConfig().getInt(s + ".z")));
                return true;
            }
        }

        public class DelSpawn implements CommandExecutor {
            @Override
            public boolean onCommand(CommandSender sender, Command cmd, String lbl, String[] args) {
                Player p = (Player) sender;
                List<String> spawns = getConfig().getStringList("spawns");
                getConfig().set(args[0] + ".x", null);
                getConfig().set(args[0] + ".y", null);
                getConfig().set(args[0] + ".z", null);
                getConfig().set(args[0] + ".w", null);
                spawns.remove(args[0]);
                getConfig().set("spawns", spawns);
                saveConfig();
                return true;
            }
        }

        public class Mct implements CommandExecutor {
            @Override
            public boolean onCommand(CommandSender sender, Command cmd, String lbl, String[] args) {
                Player p = (Player) sender;
                if (args[0].equalsIgnoreCase("attractions")) {
                    getConfig().set("mct.attractions.x", p.getLocation().getBlockX());
                    getConfig().set("mct.attractions.y", p.getLocation().getBlockY());
                    getConfig().set("mct.attractions.z", p.getLocation().getBlockZ());
                    getConfig().set("mct.attractions.w", p.getLocation().getWorld().getName());
                }
                return true;
            }
        }
       
        @Override
        public void onEnable() {
            music1 = NBSDecoder.parse(new File(getDataFolder(), "music1.nbs"));
            player = new RadioSongPlayer(music1);
            getConfig().options().copyDefaults(true);
            attractions.setItem(4, new ItemBuilder(Material.SLIME_BLOCK, 1, (short) 0).setName("Skydiving")
                    .setLore(Arrays.asList("§cGo to the top of the tower", "§cand jump!")).finish().get());
            Bukkit.getPluginManager().registerEvents(this, this);
            Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
                @Override
                public void run() {
                    for (Player p : Bukkit.getOnlinePlayers()) {
                        player.removePlayer(p);
                    }
                    player = new RadioSongPlayer(music1);
                    player.setVolume((byte) 1);
                    player.setPlaying(true);
                    for (Player p : Bukkit.getOnlinePlayers()) {
                        player.addPlayer(p);
                    }
                }
            }, 7200L, 7200L);
            getCommand("setspawn").setExecutor(new SetSpawn());
            getCommand("mct").setExecutor(new Mct());
            getCommand("spawn").setExecutor(new Spawn());
            getCommand("delspawn").setExecutor(new DelSpawn());
            saveConfig();
        }

        @EventHandler
        public void join(PlayerJoinEvent e) {
            Player p = e.getPlayer();
            Bukkit.getConsoleSender().sendMessage("lol");
            List<String> spawns = getConfig().getStringList("spawns");
            String s = spawns.get(new Random().nextInt(spawns.size()));
            p.teleport(new Location(Bukkit.getWorld(getConfig().getString(s + ".w")), getConfig().getInt(s + ".x"),
                    getConfig().getInt(s + ".y"), getConfig().getInt(s + ".z")));
            p.sendMessage("§aYour MCC: §f" + (getConfig().contains("money." + p.getUniqueId()) ? getConfig().getInt("money." + p.getUniqueId()) : 0));
        }

        @EventHandler
        public void leave(PlayerQuitEvent e) {
        }

        @EventHandler
        public void interactEntity(PlayerInteractEntityEvent e) {
            if (e.getRightClicked().getType() == EntityType.VILLAGER) {
                Villager villager = (Villager) e.getRightClicked();
                if (villager.getCustomName().equalsIgnoreCase("Pets") && villager.getProfession() == Profession.BUTCHER) {
                    e.setCancelled(true);
                    if (EchoPetAPI.getAPI().hasPet(e.getPlayer()))
                        e.getPlayer().sendMessage("Norman: G'day! What would you like to do with your pet?");
                    else
                        e.getPlayer().sendMessage("Norman: G'day! Would you like a pet?");
                    EchoPetAPI.getAPI().openPetSelector(e.getPlayer());
                } else if (villager.getCustomName().equalsIgnoreCase("Attractions")
                        && villager.getProfession() == Profession.BLACKSMITH) {
                    e.setCancelled(true);
                    e.getPlayer().sendMessage("Kros: 20 MCC for 1 of the 3 attractions!");
                    e.getPlayer().openInventory(attractions);
                }
            }
        }

        @EventHandler
        public void invClick(InventoryClickEvent e) {
            if (e.getInventory().getName().equalsIgnoreCase("Attractions")) {
                if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase("Skydiving")) {
                    Location l = new Location(Bukkit.getWorld(getConfig().getString("mct.attractions.w")),
                            getConfig().getInt("mct.attractions.x"), getConfig().getInt("mct.attractions.y"),
                            getConfig().getInt("mct.attractions.z"));
                    e.getWhoClicked().teleport(l);
                }
                e.setCancelled(true);
            }
        }

    }
     
    There are no errors, in Minecraft nor in the console.
    However this is weird, since the teleport in the player join event is working, but the send messages aren't working.
    The Bukkit.getConsoleSender().sendMessage("lol"); was a debug but that didn't come up in the console as well.
    So is the problem in sendMessage?
     
  2. Which version you are using?
    You can also for debbuging do: System.out.println("Lol");
     
    • Informative Informative x 1
  3. Nvm, turned out my plugin for some reason wasn't being updated even when I restarted the server, I got it fixed now, thanks ;)
     
  4. Dont forget to mark as solved