p.sendmessage not working

Discussion in 'Plugin Development' started by Luca0212, Sep 30, 2020.

  1. Offline

    Luca0212

    Hello im trying to fix my code a bit, but im a lil confused rn.

    Maybe u could take a look and tell me whats wrong :)

    Code:
    import org.bukkit.event.EventHandler;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.Bukkit;
    import org.bukkit.event.block.Action;
    import de.max.SilentLobby.Core.Main;
    import org.bukkit.Material;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.Listener;
    
    public class InteractListener implements Listener{
        @EventHandler
        public void onClick(final PlayerInteractEvent e) {
            final Player p = e.getPlayer();
            if (e.getItem() != null && e.getItem().hasItemMeta() && e.getItem().getItemMeta().hasDisplayName()) {
                if (p.getItemInHand().getType() == Material.TNT) {
                    if (p.getItemInHand().getItemMeta().getDisplayName().equals(Main.getInstance.mainItem) && p.hasPermission("Sl.use") && (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK)) {
                        e.setCancelled(true);
                        p.teleport(Main.getInstance.filemanager.getSilentLocation());
                        p.sendMessage(String.valueOf(Main.getInstance.pr) + "You're now on the Silent-Lobby.");
                        Bukkit.getScheduler().scheduleSyncDelayedTask((Plugin)Main.getInstance, (Runnable)new InteractListener$1(p), 10L);
                    }
                }else
                    p.sendMessage(Main.getInstance.pr + "Not set a");
                {
            }
            }
            else if (e.getItem() != null && e.getItem().hasItemMeta() && e.getItem().getItemMeta().hasDisplayName()) {
                    if (p.getItemInHand().getType() == Material.NETHER_STAR) {
                    if (p.getItemInHand().getItemMeta().getDisplayName().equals(Main.getInstance.mainItemName) && p.hasPermission("Sl.use") && (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK)) {
                    e.setCancelled(true);
                    p.teleport(Main.getInstance.filemanager.getSpawnLocation());
                    p.sendMessage(String.valueOf(Main.getInstance.pr) + "You're now on the Lobby.");
                    p.getInventory().setItem(Main.getInstance.ItemSlot - 1, Main.getInstance.methode.createItem(Material.TNT, 0, 1, Main.getInstance.ItemName));
                    Bukkit.getScheduler().scheduleSyncDelayedTask((Plugin)Main.getInstance, (Runnable)new InteractListener$2(p), 10L);
                    }
                }else
                    p.sendMessage(Main.getInstance.pr + "Not set b");
                {
                }
            }    
        }
    }
    Yea i know its a lil messed up gonna fix that too.

    Anyways, the problem simply is that all players which are clicking the tnt are getting this error
    Code:
    Could not pass event PlayerInteractEvent to SilentLobbyBukkit v3.4
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot.jar:git-Spigot-21fe707-e1ebe52]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-21fe707-e1ebe52]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-21fe707-e1ebe52]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-21fe707-e1ebe52]
    at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:228) [spigot.jar:git-Spigot-21fe707-e1ebe52]
    at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:195) [spigot.jar:git-Spigot-21fe707-e1ebe52]
    at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:191) [spigot.jar:git-Spigot-21fe707-e1ebe52]
    at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:717) [spigot.jar:git-Spigot-21fe707-e1ebe52]
    at net.minecraft.server.v1_8_R3.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:52) [spigot.jar:git-Spigot-21fe707-e1ebe52]
    at net.minecraft.server.v1_8_R3.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:1) [spigot.jar:git-Spigot-21fe707-e1ebe52]
    at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-21fe707-e1ebe52]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_241]
    at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_241]
    at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot.jar:git-Spigot-21fe707-e1ebe52]
    at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715) [spigot.jar:git-Spigot-21fe707-e1ebe52]
    at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot.jar:git-Spigot-21fe707-e1ebe52]
    at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot.jar:git-Spigot-21fe707-e1ebe52]
    at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot.jar:git-Spigot-21fe707-e1ebe52]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_241]
    Caused by: java.lang.IllegalArgumentException: Name cannot be null
    at org.apache.commons.lang.Validate.notNull(Validate.java:192) ~[spigot.jar:git-Spigot-21fe707-e1ebe52]
    at org.bukkit.craftbukkit.v1_8_R3.CraftServer.getWorld(CraftServer.java:1014) ~[spigot.jar:git-Spigot-21fe707-e1ebe52]
    at org.bukkit.Bukkit.getWorld(Bukkit.java:496) ~[spigot.jar:git-Spigot-21fe707-e1ebe52]
    at de.max.SilentLobby.Manager.FileManager.getSilentLocation(FileManager.java:129) ~[?:?]
    at de.max.SilentLobby.Listener.InteractListener.onClick(InteractListener.java:21) ~[?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_241]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_241]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_241]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_241]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot.jar:git-Spigot-21fe707-e1ebe52]
    ... 18 more
    But players clicking the Nether-Star are getting the Message [Not set a].
    Can someone explain what im doing wrong? Maybe im just stupid rn

    Greetings
     
    Last edited by a moderator: Sep 30, 2020
  2. Online

    timtower Moderator Moderator

  3. Offline

    Luca0212

    Well yea i kinda want it to be null. If the location isnt set the player should recive the message that its not set yet.
     
  4. Online

    timtower Moderator Moderator

    @Luca0212 Then you should not call getWorld if the worldname is still null.
     
  5. Offline

    Luca0212

    Well its jus kinda i can set the locations via command

    i got a filemanager maybe that can help


    Code:
    import org.bukkit.World;
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.entity.Player;
    import de.max.SilentLobby.Core.Main;
    import java.io.IOException;
    import org.bukkit.configuration.file.YamlConfiguration;
    import java.io.File;
    
    public class FileManager
    {
        public File ordner;
        public File configFile;
        public File locationFile;
        public YamlConfiguration cfg;
        public YamlConfiguration lfg;
     
     
        public FileManager() {
            this.ordner = new File("plugins//SilentLobby");
            this.configFile = new File("plugins//SilentLobby//einstellungen.yml");
            this.locationFile = new File("plugins//SilentLobby//location.yml");;
            this.cfg = YamlConfiguration.loadConfiguration(this.configFile);
            this.lfg = YamlConfiguration.loadConfiguration(this.locationFile);
        }
     
        public void createFile() {
            if (!this.ordner.exists()) {
                this.ordner.mkdir();
            }
            if (!this.configFile.exists()) {
                try {
                    this.configFile.createNewFile();
                    this.setDefault();
                }
                catch (IOException arg2) {
                    arg2.printStackTrace();
                }
            }
            if (!this.locationFile.exists()) {
                try {
                    this.locationFile.createNewFile();
                }
                catch (IOException arg3) {
                    arg3.printStackTrace();
                }
            }
        }
     
        public void setDefault() {
            this.cfg.options().copyDefaults(true);
            this.cfg.options().header(
                            "#############################################" + "\n" +
                            "#              - SilentLobby -              #" + "\n" +
                            "#############################################" + "\n" +
                            "Version 1.0" + "\n" +
                            "#############################################" + "\n");
            this.cfg.addDefault("Settings.SilentModusSlot", (Object)3);
            this.cfg.addDefault("Settings.ItemSlot", (Object)5);
            this.cfg.addDefault("Settings.LobbyWelt", (Object)"Lobby");
            this.cfg.addDefault("Settings.SilentWelt", (Object)"Silent");
            this.cfg.addDefault("Settings.LobbyItemName", (Object)"&cLobby ");
            this.cfg.addDefault("Settings.SilentItemName", (Object)"&cSilent-Lobby ");
            this.save();
        } 
        public void getSilentSlot() {
            Main.getInstance.SilentSlot = this.cfg.getInt("Settings.SilentModusSlot");
        }
     
        public void getItemSlot() {
            Main.getInstance.ItemSlot = this.cfg.getInt("Settings.ItemSlot");
        }
     
        public void getAllowedWorld() {
            Main.getInstance.allowedWorld = this.cfg.getString("Settings.LobbyWelt");
        }
     
        public void getMainLobby() {
            Main.getInstance.mainLobby = this.cfg.getString("Settings.SilentWelt");
        }
     
        public void getMainItemName() {
            Main.getInstance.mainItemName = this.cfg.getString("Settings.LobbyItemName").replaceAll("&", "§");
        }
        public void getItemName() {
            Main.getInstance.mainItem = this.cfg.getString("Settings.SilentItemName").replaceAll("&", "§");
        }
    
     
        public void setMainLobby(final Player p) {
            this.lfg.set("Silent.World", (Object)p.getWorld().getName());
            this.lfg.set("Silent.X", (Object)p.getLocation().getX());
            this.lfg.set("Silent.Y", (Object)p.getLocation().getY());
            this.lfg.set("Silent.Z", (Object)p.getLocation().getZ());
            this.lfg.set("Silent.Yaw", (Object)p.getLocation().getYaw());
            this.lfg.set("Silent.Pitch", (Object)p.getLocation().getPitch());
            this.saveLfg();
        }
     
        public void setLobby(final Player p) {
            this.lfg.set("Spawn.World", (Object)p.getWorld().getName());
            this.lfg.set("Spawn.X", (Object)p.getLocation().getX());
            this.lfg.set("Spawn.Y", (Object)p.getLocation().getY());
            this.lfg.set("Spawn.Z", (Object)p.getLocation().getZ());
            this.lfg.set("Spawn.Yaw", (Object)p.getLocation().getYaw());
            this.lfg.set("Spawn.Pitch", (Object)p.getLocation().getPitch());
            this.saveLfg();
        }
     
        public Location getSpawnLocation() {
            final World w = Bukkit.getWorld(this.lfg.getString("Spawn.World"));
            final double x = this.lfg.getDouble("Spawn.X");
            final double y = this.lfg.getDouble("Spawn.Y");
            final double z = this.lfg.getDouble("Spawn.Z");
            final Location loc = new Location(w, x, y, z);
            loc.setYaw((float)this.lfg.getInt("Spawn.Yaw"));
            loc.setPitch((float)this.lfg.getInt("Spawn.Pitch"));
            return loc;
         
        }
     
        public Location getSilentLocation() {
            final World w = Bukkit.getWorld(this.lfg.getString("Silent.World"));
            final double x = this.lfg.getDouble("Silent.X");
            final double y = this.lfg.getDouble("Silent.Y");
            final double z = this.lfg.getDouble("Silent.Z");
            final Location loc = new Location(w, x, y, z);
            loc.setYaw((float)this.lfg.getInt("Silent.Yaw"));
            loc.setPitch((float)this.lfg.getInt("Silent.Pitch"));
            return loc;
        }
     
        public void save() {
            try {
                this.cfg.save(this.configFile);
            }
            catch (IOException arg1) {
                arg1.printStackTrace();
            }
        }
     
        public void saveLfg() {
            try {
                this.lfg.save(this.locationFile);
            }
            catch (IOException arg1) {
                arg1.printStackTrace();
            }
        }
    }
    So if the location isnt set player geta the message
     
  6. Online

    timtower Moderator Moderator

    @Luca0212 getSilentLocation is using a string "Silent.World", but you never check if it is set or not.
     
  7. Offline

    Luca0212

    Well but then im confused why its working with the nether star cause there are no diffrents
     
  8. Online

    timtower Moderator Moderator

    You are never checking if the point exists either.
     
  9. Offline

    Luca0212

    Well i tryed checking the locations, but I’m still getting the same error
     
  10. Online

    timtower Moderator Moderator

    @Luca0212 Please post your updated code.
     

Share This Page