Java Code Examples for org.bukkit.event.block.SignChangeEvent#getBlock()
The following examples show how to use
org.bukkit.event.block.SignChangeEvent#getBlock() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LWCBlockListener.java From Modern-LWC with MIT License | 6 votes |
@EventHandler public void onSignChange(SignChangeEvent event) { if (!LWC.ENABLED || event.isCancelled()) { return; } LWC lwc = plugin.getLWC(); Block block = event.getBlock(); Player player = event.getPlayer(); if (block == null) { return; } Protection protection = lwc.findProtection(block.getLocation()); if (protection == null) { return; } boolean canAccess = lwc.canAccessProtection(player, protection); if (!canAccess) { event.setCancelled(true); } }
Example 2
Source File: ATM.java From TimeIsMoney with GNU General Public License v3.0 | 6 votes |
@EventHandler public void onSignChange(final SignChangeEvent e) { final Block b = e.getBlock(); if (b.getState() instanceof Sign) { plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> { if (b.getState() instanceof Sign) { Sign sign = (Sign) e.getBlock().getState(); if (sign.getLine(0).equalsIgnoreCase("[atm]")) { if (!e.getPlayer().hasPermission("tim.atm.place")) { e.getPlayer().sendMessage(CC("&cYou dont have permissions to build ATM's!")); sign.setLine(0, ""); } else { sign.setLine(0, CC("&cATM")); sign.update(); e.getPlayer().sendMessage(CC("&2ATM created! (You can also write something in the Lines 2-4)")); } } } }, 10L); } }
Example 3
Source File: GlobalProtectionListener.java From DungeonsXL with GNU General Public License v3.0 | 5 votes |
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onSignChange(SignChangeEvent event) { Player player = event.getPlayer(); Block block = event.getBlock(); BlockState state = block.getState(); if (!(state instanceof Sign)) { return; } String[] lines = event.getLines(); // Group Signs if (plugin.getEditWorld(player.getWorld()) == null) { if (!DPermission.hasPermission(player, DPermission.SIGN)) { return; } if (!lines[0].equalsIgnoreCase(GlobalProtection.SIGN_TAG)) { return; } if (lines[1].equalsIgnoreCase(GroupSign.GROUP_SIGN_TAG)) { if (GroupSign.tryToCreate(plugin, event) != null) { event.setCancelled(true); } } else if (lines[1].equalsIgnoreCase(GameSign.GAME_SIGN_TAG)) { if (GameSign.tryToCreate(plugin, event) != null) { event.setCancelled(true); } } else if (lines[1].equalsIgnoreCase(LeaveSign.LEAVE_SIGN_TAG)) { Sign sign = (Sign) state; new LeaveSign(plugin, plugin.getGlobalProtectionCache().generateId(LeaveSign.class, sign.getWorld()), sign); event.setCancelled(true); } } }
Example 4
Source File: DSignListener.java From DungeonsXL with GNU General Public License v3.0 | 4 votes |
@EventHandler public void onSignChange(SignChangeEvent event) { String[] lines = event.getLines(); if (lines.length < 3 || !lines[0].startsWith("[")) { return; } Player player = event.getPlayer(); Block block = event.getBlock(); BlockState state = block.getState(); if (!(state instanceof Sign)) { return; } Sign sign = (Sign) state; EditWorld editWorld = api.getEditWorld(sign.getWorld()); if (editWorld == null) { return; } if (sign == null) { return; } // Override sign plugins color codes etc. sign.setLine(0, lines[0]); sign.setLine(1, lines[1]); sign.setLine(2, lines[2]); sign.setLine(3, lines[3]); if (DungeonsXL.LEGACY_SIGNS.containsKey(lines[0].substring(1, lines[0].length() - 1).toUpperCase())) { MessageUtil.sendMessage(player, ChatColor.RED + "https://erethon.de/resources/dxl-signs/deprecated.gif"); MessageUtil.sendMessage(player, ChatColor.LIGHT_PURPLE + "https://github.com/DRE2N/DungeonsXL/wiki/Legacy-support#updating"); event.setCancelled(true); event.getBlock().setType(VanillaItem.AIR.getMaterial()); return; } DungeonSign dsign = editWorld.createDungeonSign(sign, sign.getLines()); if (dsign == null) { return; } if (!DPermission.hasPermission(player, dsign.getBuildPermission())) { MessageUtil.sendMessage(player, DMessage.ERROR_NO_PERMISSIONS.getMessage()); return; } if (dsign.validate()) { editWorld.registerSign(block); MessageUtil.sendMessage(player, DMessage.PLAYER_SIGN_CREATED.getMessage()); } else { editWorld.removeDungeonSign(block); MessageUtil.sendMessage(player, DMessage.ERROR_SIGN_WRONG_FORMAT.getMessage()); } }
Example 5
Source File: MainListener.java From ArmorStandTools with MIT License | 4 votes |
@EventHandler public void onSignChange(final SignChangeEvent event) { if(event.getBlock().hasMetadata("armorStand")) { final Block b = event.getBlock(); final ArmorStand as = getArmorStand(b); if (as != null) { StringBuilder sb = new StringBuilder(); for (String line : event.getLines()) { if (line != null && line.length() > 0) { sb.append(ChatColor.translateAlternateColorCodes('&', line)); } } String input = sb.toString(); if(b.hasMetadata("setName")) { if (input.length() > 0) { as.setCustomName(input); as.setCustomNameVisible(true); } else { as.setCustomName(""); as.setCustomNameVisible(false); as.setCustomNameVisible(false); } } else if(b.hasMetadata("setSkull")) { if(MC_USERNAME_PATTERN.matcher(input).matches()) { b.setMetadata("protected", new FixedMetadataValue(plugin, true)); event.getPlayer().sendMessage(ChatColor.GOLD + Config.pleaseWait); String cmd = "minecraft:give " + event.getPlayer().getName() + " minecraft:player_head{SkullOwner:\"" + input + "\"} 1"; String current = b.getWorld().getGameRuleValue("sendCommandFeedback"); b.getWorld().setGameRuleValue("sendCommandFeedback", "false"); Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), cmd); b.getWorld().setGameRuleValue("sendCommandFeedback", current); boolean found = false; for(int slot : event.getPlayer().getInventory().all(Material.PLAYER_HEAD).keySet()) { ItemStack skull = event.getPlayer().getInventory().getItem(slot); SkullMeta sm = (SkullMeta) skull.getItemMeta(); if(sm.hasOwner() && input.equalsIgnoreCase(sm.getOwningPlayer().getName())) { as.setHelmet(skull); event.getPlayer().sendMessage(ChatColor.GREEN + Config.appliedHead + ChatColor.GOLD + " " + input); event.getPlayer().getInventory().setItem(slot, null); found = true; break; } } if(!found) { event.getPlayer().sendMessage(ChatColor.GOLD + Config.headFailed); } } else { event.getPlayer().sendMessage(ChatColor.RED + input + " " + Config.invalidName); } } } event.setCancelled(true); b.removeMetadata("armorStand", plugin); b.removeMetadata("setName", plugin); b.removeMetadata("setSkull", plugin); b.setType(Material.AIR); } }