Hi i need to create join sign to my minigame, i tried Player interact event and check line 0 but that didnt work so i tried lots of forums and no one was working... im on 1.16.5 Any ideas?? Btw sorry for my english.
https://www.spigotmc.org/threads/right-click-sign.220047/ If this isn't working then post code and errors if any.
@davidclue I tried it before and it didnt work, so i tried it now and it didnt work again Here is my code: Code: @EventHandler public void onPlayerClickSign(PlayerInteractEvent event){ Player p = event.getPlayer(); if(event.getClickedBlock().getType() == Material.BIRCH_WALL_SIGN||event.getClickedBlock().getType() == Material.BIRCH_SIGN){ if(event.getAction() == Action.RIGHT_CLICK_BLOCK){ Sign sign = (Sign) event.getClickedBlock().getState(); //^^ .getState(); really important if(sign.getLine(1).equalsIgnoreCase( "[KITPVP]")){ p.sendMessage("Test"); sign.update(); } } } } I tried Leggacy signs too and that give me this error: I have it registered in my main class. sorry for my enlish
Your code works just fine when I tested it, it might be the imports you might have chosen the wrong ones please make sure you chose these imports, and if not then post the whole class and your onEnable method. Code: import org.bukkit.block.Sign; import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.EventHandler;
I dont know why but it dont work so: That is my sign here is my full class: Code: package org.Amaspot.KitPvP.PlayerManager; import java.util.UUID; import org.Amaspot.KitPvP.PlayerManager.Kits.KitAssasin; import org.Amaspot.KitPvP.PlayerManager.Kits.KitDefault; import org.Amaspot.KitPvP.PlayerManager.Kits.KitGiver; import org.Amaspot.commons.SettingsManager; import org.Amaspot.commons.commands.lobbyport; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Material; import org.bukkit.block.Sign; 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.event.player.PlayerMoveEvent; public class PlayersInGame implements Listener { private SettingsManager settings; private KitGiver KG; public PlayersInGame(SettingsManager settings, KitGiver KG) { this.settings = settings; this.KG = KG; } @EventHandler public void onPlayerClickSign(PlayerInteractEvent event){ Player p = event.getPlayer(); if(event.getClickedBlock().getType() == Material.BIRCH_WALL_SIGN||event.getClickedBlock().getType() == Material.BIRCH_SIGN){ if(event.getAction() == Action.RIGHT_CLICK_BLOCK){ Sign sign = (Sign) event.getClickedBlock().getState(); //^^ .getState(); really important if(sign.getLine(1).equalsIgnoreCase( "[KITPVP]")){ p.sendMessage("Test"); sign.update(); } } } } @EventHandler public void PlayerUnderY(PlayerMoveEvent event) { Player p = (Player) event.getPlayer(); if (!(PlayersInGameList.InGame.contains(p.getUniqueId()))) { if (p.getGameMode() == GameMode.SURVIVAL) { if ((p.getLocation().getY() <= settings.getData().getDouble("Yenter")) && (p.getWorld() == Bukkit.getServer().getWorld(UUID.fromString(settings.getData().getString("WorldUID"))))) { lobbyport.hubers.remove(p.getUniqueId()); PlayersInGameList.InKit.remove(p.getUniqueId()); PlayersInGameList.InGame.add(p.getUniqueId()); p.getInventory().clear(); if (KitDefault.DefaultKit.containsKey(p)) KG.GiveDefault(p); if (KitAssasin.AssasinKit.containsKey(p)) KG.GiveAssasin(p); } } } } } and here my onEnable method: Code: public void onEnable() { settings = new SettingsManager(); KG = new KitGiver(settings); settings.setup(this); @SuppressWarnings("unused") lobbyport lobbyport = org.Amaspot.commons.Main.lobbyport; Bukkit.getPluginManager().registerEvents(new PlayersInGame(settings, KG), this); Bukkit.getPluginManager().registerEvents(new GameChanges(), this); Bukkit.getPluginManager().registerEvents(new KitSelector(), this); Bukkit.getPluginManager().registerEvents(new KitDefault(KG), this); Bukkit.getPluginManager().registerEvents(new BlockManager(this, settings), this); this.getCommand("KitPvPset").setExecutor(new SetCommand(settings)); this.getCommand("KitPvP").setExecutor(new JoinCommand(settings)); getLogger().info("KitPvP is now enabled"); } and here is my Sign in minecraft Line 33 is this : Code: if(event.getClickedBlock().getType() == Material.BIRCH_WALL_SIGN||event.getClickedBlock().getType() == Material.BIRCH_SIGN) But with some called LEGACY_SIGN_WALL POST etc
I already have it so here is my plugin.yml : Code: main: org.Amaspot.KitPvP.Main name: AmaspotKitPvP version: '1.0' api-version: 1.16 description: 'A custom KitPvP plugin for Amaspot' depend: - AmaspotCommons commands: KitPvPset: description: 'command for set the arena' KitPvP: description: 'Join a kitpvp'
@KaaaaJ you will probably get that NullPointer when you interact with air. Confirm that your if statement is getting triggered when you click the sign by printing something, regardless of the first line of the sign.
Oh sorry to everyone, im so stupid, not too to think line 1 is line one but i think there vas 0 not 1 now its working. So thank you for helping etc... and for other who found this forum here is my fianl code: Code: @EventHandler public void onPlayerClickSign(PlayerInteractEvent event){ Player p = event.getPlayer(); if(event.getClickedBlock().getType() == Material.BIRCH_SIGN||event.getClickedBlock().getType() == Material.BIRCH_WALL_SIGN){ if(event.getAction() == Action.RIGHT_CLICK_BLOCK){ Sign sign = (Sign) event.getClickedBlock().getState(); //^^ .getState(); really important if(sign.getLine(1).equalsIgnoreCase( "[KITPVP]")){ p.sendMessage("Test"); sign.update(); } } } } and for last sorry for my english