Java Code Examples for org.bukkit.event.block.SignChangeEvent#getPlayer()

The following examples show how to use org.bukkit.event.block.SignChangeEvent#getPlayer() . 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 vote down vote up
@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: SignEvents.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onSignChanged(SignChangeEvent e) {
    if (e.isCancelled() || e.getPlayer() == null
            || !plugin.getWorldManager().isSkyAssociatedWorld(e.getPlayer().getWorld())
            || !e.getLines()[0].equalsIgnoreCase("[usb]")
            || e.getLines()[1].trim().isEmpty()
            || !e.getPlayer().hasPermission("usb.island.signs.place")
            || !(e.getBlock().getType() == SkyBlockMenu.WALL_SIGN_MATERIAL)
            || !(e.getBlock().getState() instanceof Sign)
            ) {
        return;
    }
    Sign sign = (Sign) e.getBlock().getState();

    if(sign.getBlock().getState().getBlockData() instanceof WallSign) {
        WallSign data = (WallSign) sign.getBlock().getState().getBlockData();
        BlockFace attached = data.getFacing().getOppositeFace();
        Block wallBlock = sign.getBlock().getRelative(attached);
        if (isChest(wallBlock)) {
            logic.addSign(sign, e.getLines(), (Chest) wallBlock.getState());
        }
    }
}
 
Example 3
Source File: ClaimSignListener.java    From Guilds with MIT License 5 votes vote down vote up
@EventHandler
public void onSignChange(SignChangeEvent event) {
    Player player = event.getPlayer();

    if (!event.getLine(0).equalsIgnoreCase("[Guild Claim]"))
        return;

    if (!player.hasPermission("guilds.claimsigns.place") && !player.hasPermission("worldguard.region.redefine.*")) {
        guilds.getCommandManager().getCommandIssuer(player).sendInfo(Messages.CLAIM__SIGN_NO_PERMISSION);
        event.setCancelled(true);
        return;
    }

    if (!settingsManager.getProperty(ClaimSettings.CLAIM_SIGNS)) {
        guilds.getCommandManager().getCommandIssuer(player).sendInfo(Messages.CLAIM__SIGN_NOT_ENABLED);
        event.setCancelled(true);
        return;
    }

    if (event.getLine(1).isEmpty() || event.getLine(2).isEmpty()) {
        guilds.getCommandManager().getCommandIssuer(player).sendInfo(Messages.CLAIM__SIGN_INVALID_FORMAT);
        event.setCancelled(true);
        return;
    }

    if (!ClaimUtils.checkAlreadyExist(wrapper, player, event.getLine(1))) {
        guilds.getCommandManager().getCommandIssuer(player).sendInfo(Messages.CLAIM__SIGN_INVALID_REGION);
        event.setCancelled(true);
        return;
    }
    guilds.getCommandManager().getCommandIssuer(player).sendInfo(Messages.CLAIM__SIGN_PLACED, "{region}", event.getLine(1), "{price}", event.getLine(2));
}
 
Example 4
Source File: SignListener.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onSignChange(SignChangeEvent sce) {
  String firstLine = sce.getLine(0).trim();
  if (!"[bw]".equals(firstLine)) {
    return;
  }

  Player player = sce.getPlayer();
  if (!player.hasPermission("bw.setup")) {
    return;
  }

  String gameName = sce.getLine(1).trim();
  Game game = BedwarsRel.getInstance().getGameManager().getGame(gameName);

  if (game == null) {
    String notfound = BedwarsRel._l("errors.gamenotfoundsimple");
    if (notfound.length() > 16) {
      String[] splitted = notfound.split(" ", 4);
      for (int i = 0; i < splitted.length; i++) {
        sce.setLine(i, ChatColor.RED + splitted[i]);
      }
    } else {
      sce.setLine(0, ChatColor.RED + notfound);
      sce.setLine(1, "");
      sce.setLine(2, "");
      sce.setLine(3, "");
    }

    return;
  }

  sce.setCancelled(true);
  game.addJoinSign(sce.getBlock().getLocation());
  game.updateSigns();
}
 
Example 5
Source File: GlobalProtectionListener.java    From DungeonsXL with GNU General Public License v3.0 5 votes vote down vote up
@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 6
Source File: PlayerListener.java    From AuthMeReloaded with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onSignChange(SignChangeEvent event) {
    Player player = event.getPlayer();
    if (listenerService.shouldCancelEvent(player)) {
        event.setCancelled(true);
    }
}
 
Example 7
Source File: DSignListener.java    From DungeonsXL with GNU General Public License v3.0 4 votes vote down vote up
@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 8
Source File: WarpSigns.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Event handler for Sign Changes
 * 
 * @param e - event
 */
@EventHandler(priority = EventPriority.NORMAL)
public void onSignWarpCreate(SignChangeEvent e) {
    //plugin.getLogger().info("DEBUG: SignChangeEvent called");
    String title = e.getLine(0);
    Player player = e.getPlayer();
    if (player.getWorld().equals(ASkyBlock.getIslandWorld()) || player.getWorld().equals(ASkyBlock.getNetherWorld())) {
        //plugin.getLogger().info("DEBUG: Correct world");
        if (e.getBlock().getType().equals(Material.SIGN_POST) || e.getBlock().getType().equals(Material.WALL_SIGN)) {

            //plugin.getLogger().info("DEBUG: The first line of the sign says " + title);
            // Check if someone is changing their own sign
            // This should never happen !!
            if (title.equalsIgnoreCase(plugin.myLocale().warpswelcomeLine)) {
                //plugin.getLogger().info("DEBUG: Welcome sign detected");
                // Welcome sign detected - check permissions
                if (!(VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.addwarp"))) {
                    Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).warpserrorNoPerm);
                    return;
                }
                if(Settings.warpLevelsRestriction > 0 && !(ASkyBlockAPI.getInstance().getLongIslandLevel(player.getUniqueId()) > Settings.warpLevelsRestriction)){
                    Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).warpserrorNotEnoughLevel);
                    return;
                }
                // Check that the player is on their island
                if (!(plugin.getGrid().playerIsOnIsland(player, Settings.coopsCanCreateWarps))) {
                    Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).warpserrorNoPlace);
                    e.setLine(0, ChatColor.RED + plugin.myLocale().warpswelcomeLine);
                    return;
                }
                // Check if the player already has a sign
                final Location oldSignLoc = getWarp(player.getUniqueId());
                if (oldSignLoc == null) {
                    //plugin.getLogger().info("DEBUG: Player does not have a sign already");
                    // First time the sign has been placed or this is a new
                    // sign
                    if (addWarp(player.getUniqueId(), e.getBlock().getLocation())) {
                        Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).warpssuccess);
                        e.setLine(0, ChatColor.GREEN + plugin.myLocale().warpswelcomeLine);
                        for (int i = 1; i<4; i++) {
                            e.setLine(i, ChatColor.translateAlternateColorCodes('&', e.getLine(i)));
                        }
                    } else {
                        Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).warpserrorDuplicate);
                        e.setLine(0, ChatColor.RED + plugin.myLocale().warpswelcomeLine);
                        for (int i = 1; i<4; i++) {
                            e.setLine(i, ChatColor.translateAlternateColorCodes('&', e.getLine(i)));
                        }
                    }
                } else {
                    //plugin.getLogger().info("DEBUG: Player already has a Sign");
                    // A sign already exists. Check if it still there and if
                    // so,
                    // deactivate it
                    Block oldSignBlock = oldSignLoc.getBlock();
                    if (oldSignBlock.getType().equals(Material.SIGN_POST) || oldSignBlock.getType().equals(Material.WALL_SIGN)) {
                        // The block is still a sign
                        //plugin.getLogger().info("DEBUG: The block is still a sign");
                        Sign oldSign = (Sign) oldSignBlock.getState();
                        if (oldSign != null) {
                            //plugin.getLogger().info("DEBUG: Sign block is a sign");
                            if (oldSign.getLine(0).equalsIgnoreCase(ChatColor.GREEN + plugin.myLocale().warpswelcomeLine)) {
                                //plugin.getLogger().info("DEBUG: Old sign had a green welcome");
                                oldSign.setLine(0, ChatColor.RED + plugin.myLocale().warpswelcomeLine);
                                oldSign.update(true, false);
                                Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).warpsdeactivate);
                                removeWarp(player.getUniqueId());
                                Bukkit.getPluginManager().callEvent(new WarpRemoveEvent(plugin, oldSign.getLocation(), player.getUniqueId()));
                            }
                        }
                    }
                    // Set up the warp
                    if (addWarp(player.getUniqueId(), e.getBlock().getLocation())) {
                        Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).warpssuccess);
                        e.setLine(0, ChatColor.GREEN + plugin.myLocale().warpswelcomeLine);
                    } else {
                        Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).warpserrorDuplicate);
                        e.setLine(0, ChatColor.RED + plugin.myLocale().warpswelcomeLine);
                    }
                }
            }
        }
    }
}