Java Code Examples for org.bukkit.block.Sign#getLine()
The following examples show how to use
org.bukkit.block.Sign#getLine() .
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: SignListener.java From ChestCommands with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onInteract(PlayerInteractEvent event) { if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.hasBlock() && event.getClickedBlock().getState() instanceof Sign) { Sign sign = (Sign) event.getClickedBlock().getState(); if (sign.getLine(0).equalsIgnoreCase(ChatColor.DARK_BLUE + "[menu]")) { sign.getLine(1); ExtendedIconMenu iconMenu = ChestCommands.getFileNameToMenuMap().get(BukkitUtils.addYamlExtension(sign.getLine(1))); if (iconMenu != null) { if (event.getPlayer().hasPermission(iconMenu.getPermission())) { iconMenu.open(event.getPlayer()); } else { iconMenu.sendNoPermissionMessage(event.getPlayer()); } } else { sign.setLine(0, ChatColor.RED + ChatColor.stripColor(sign.getLine(0))); event.getPlayer().sendMessage(ChestCommands.getLang().menu_not_found); } } } }
Example 2
Source File: TutorialListener.java From ServerTutorial with MIT License | 5 votes |
@EventHandler public void onPlayerInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); String name = player.getName(); if (event.getAction() != Action.PHYSICAL) { if (TutorialManager.getManager().isInTutorial(name) && TutorialManager.getManager().getCurrentTutorial (name).getViewType() != ViewType.TIME) { if (TutorialManager.getManager().getCurrentTutorial(name).getTotalViews() == TutorialManager .getManager().getCurrentView(name)) { plugin.getEndTutorial().endTutorial(player); } else { plugin.incrementCurrentView(name); TutorialUtils.getTutorialUtils().messageUtils(player); Caching.getCaching().setTeleport(player, true); player.teleport(TutorialManager.getManager().getTutorialView(name).getLocation()); } } } if ((event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_BLOCK) && !TutorialManager.getManager().isInTutorial(name)) { Block block = event.getClickedBlock(); if (block.getType() == Material.SIGN || block.getType() == Material.WALL_SIGN) { Sign sign = (Sign) block.getState(); String match = ChatColor.stripColor(TutorialUtils.color(TutorialManager.getManager().getConfigs() .signSetting())); if (sign.getLine(0).equalsIgnoreCase(match) && sign.getLine(1) != null) { plugin.startTutorial(sign.getLine(1), player); } } } }
Example 3
Source File: SignUpdateTask.java From GriefDefender with MIT License | 4 votes |
@Override public void run() { for (World world : Bukkit.getServer().getWorlds()) { final GDClaimManager claimManager = GriefDefenderPlugin.getInstance().dataStore.getClaimWorldManager(world.getUID()); Set<Claim> claimList = claimManager.getWorldClaims(); if (claimList.size() == 0) { continue; } final Iterator<Claim> iterator = new HashSet<>(claimList).iterator(); while (iterator.hasNext()) { final GDClaim claim = (GDClaim) iterator.next(); final Vector3i pos = claim.getEconomyData() == null ? null : claim.getEconomyData().getRentSignPosition(); if (pos == null || claim.getEconomyData() == null || claim.getEconomyData().getRentEndDate() == null) { continue; } final Sign sign = SignUtil.getSign(world, pos); if (SignUtil.isRentSign(claim, sign)) { final String[] lines = sign.getLines(); final String header = lines[0]; if (header == null) { // Should not happen but just in case continue; } final String timeRemaining = sign.getLine(3); final Duration duration = Duration.between(Instant.now(), claim.getEconomyData().getRentEndDate()); final long seconds = duration.getSeconds(); if (seconds <= 0) { if (claim.getEconomyData().isRented()) { final UUID renterUniqueId = claim.getEconomyData().getRenters().get(0); final GDPermissionUser renter = PermissionHolderCache.getInstance().getOrCreateUser(renterUniqueId); if (renter != null && renter.getOnlinePlayer() != null) { GriefDefenderPlugin.sendMessage(renter.getOnlinePlayer(), MessageCache.getInstance().ECONOMY_CLAIM_RENT_CANCELLED); } } sign.getBlock().setType(Material.AIR); SignUtil.resetRentData(claim); claim.getData().save(); continue; } final String remainingTime = String.format("%02d:%02d:%02d", duration.toDays(), (seconds % 86400 ) / 3600, (seconds % 3600) / 60); sign.setLine(3, ChatColor.translateAlternateColorCodes('&', "&6" + remainingTime)); sign.update(); } } } }
Example 4
Source File: SiegeEffect.java From Civs with GNU General Public License v3.0 | 4 votes |
@EventHandler public void onCustomEvent(RegionTickEvent event) { if (!event.getRegion().getEffects().containsKey(KEY) || !event.isHasUpkeep()) { return; } Region region = event.getRegion(); Location l = region.getLocation(); String damageString = region.getEffects().get(KEY); int damage = 1; if (damageString != null) { damage = Integer.parseInt(damageString); } //Check if valid siege machine position if (l.getBlock().getY() + 2 < l.getWorld().getHighestBlockAt(l).getY()) { return; } Block b = l.getBlock().getRelative(BlockFace.UP); BlockState state = b.getState(); if (!(state instanceof Sign)) { return; } //Find target Super-region Sign sign = (Sign) state; String townName = sign.getLine(0); Town town = TownManager.getInstance().getTown(townName); if (town == null) { for (Town currentTown : TownManager.getInstance().getTowns()) { if (currentTown.getName().startsWith(townName)) { town = currentTown; break; } } if (town == null) { sign.setLine(2, "invalid name"); sign.update(); return; } } //Check if too far away TownType townType = (TownType) ItemManager.getInstance().getItemType(town.getType()); double rawRadius = townType.getBuildRadius(); try { if (town.getLocation().distance(l) - rawRadius > 150) { sign.setLine(2, "out of"); sign.setLine(3, "range"); sign.update(); return; } } catch (IllegalArgumentException iae) { sign.setLine(2, "out of"); sign.setLine(3, "range"); sign.update(); return; } if (town.getPower() < 1) { return; } Location spawnLoc = l.getBlock().getRelative(BlockFace.UP, 3).getLocation(); Location loc = new Location(spawnLoc.getWorld(), spawnLoc.getX(), spawnLoc.getY() + 15, spawnLoc.getZ()); final Location loc1 = new Location(spawnLoc.getWorld(), spawnLoc.getX(), spawnLoc.getY() + 20, spawnLoc.getZ()); final Location loc2 = new Location(spawnLoc.getWorld(), spawnLoc.getX(), spawnLoc.getY() + 25, spawnLoc.getZ()); final Location loc3 = new Location(spawnLoc.getWorld(), spawnLoc.getX(), spawnLoc.getY() + 30, spawnLoc.getZ()); l.getWorld().spawnParticle(Particle.EXPLOSION_HUGE, loc, 2); l.getWorld().playSound(loc, Sound.ENTITY_GENERIC_EXPLODE, 2, 1); Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Civs.getInstance(), new Runnable() { @Override public void run() { loc1.getWorld().spawnParticle(Particle.EXPLOSION_HUGE, loc1, 2); loc1.getWorld().playSound(loc1, Sound.ENTITY_GENERIC_EXPLODE, 2, 1); } }, 5L); Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Civs.getInstance(), new Runnable() { @Override public void run() { loc2.getWorld().spawnParticle(Particle.EXPLOSION_HUGE, loc2, 2); loc2.getWorld().playSound(loc2, Sound.ENTITY_GENERIC_EXPLODE, 2, 1); } }, 10L); Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Civs.getInstance(), new Runnable() { @Override public void run() { loc3.getWorld().spawnParticle(Particle.EXPLOSION_HUGE, loc3, 2); loc3.getWorld().playSound(loc3, Sound.ENTITY_GENERIC_EXPLODE, 2, 1); } }, 15L); TownManager.getInstance().setTownPower(town, town.getPower() - damage); }
Example 5
Source File: SiegeEffect.java From Civs with GNU General Public License v3.0 | 4 votes |
@Override public boolean createRegionHandler(Block block, Player player, RegionType regionType) { if (!regionType.getEffects().containsKey(KEY) && !regionType.getEffects().containsKey(CHARGING_KEY)) { return true; } Location l = Region.idToLocation(Region.blockLocationToString(block.getLocation())); Civilian civilian = CivilianManager.getInstance().getCivilian(player.getUniqueId()); Block b = l.getBlock().getRelative(BlockFace.UP); BlockState state = b.getState(); if (!(state instanceof Sign)) { player.sendMessage(Civs.getPrefix() + LocaleManager.getInstance() .getTranslation(civilian.getLocale(), "raid-sign")); return false; } if (l.getBlock().getY() + 2 < l.getWorld().getHighestBlockAt(l).getY()) { player.sendMessage(Civs.getPrefix() + LocaleManager.getInstance().getTranslation(civilian.getLocale(), "no-blocks-above-chest").replace("$1", regionType.getName())); return false; } //Find target Super-region Sign sign = (Sign) state; String townName = sign.getLine(0); Town town = TownManager.getInstance().getTown(townName); if (town == null) { for (Town cTown : TownManager.getInstance().getTowns()) { if (cTown.getName().toLowerCase().startsWith(sign.getLine(0))) { town = cTown; break; } } } if (town == null) { sign.setLine(0, "invalid target"); sign.update(); player.sendMessage(Civs.getPrefix() + LocaleManager.getInstance() .getTranslation(civilian.getLocale(), "raid-sign")); return false; } else { sign.setLine(0, town.getName()); sign.update(); } TownType townType = (TownType) ItemManager.getInstance().getItemType(town.getType()); double rawRadius = townType.getBuildRadius(); if (town.getLocation().distance(l) - rawRadius > 150) { sign.setLine(2, "out of"); sign.setLine(3, "range"); sign.update(); return false; } for (Player p : Bukkit.getOnlinePlayers()) { Civilian civ = CivilianManager.getInstance().getCivilian(p.getUniqueId()); String siegeMachineLocalName = LocaleManager.getInstance().getTranslation(civ.getLocale(), regionType.getProcessedName() + "-name"); p.sendMessage(Civs.getPrefix() + ChatColor.RED + LocaleManager.getInstance().getTranslation( civ.getLocale(), "siege-built").replace("$1", player.getDisplayName()) .replace("$2", siegeMachineLocalName).replace("$3", town.getName())); } if (Civs.discordSRV != null) { String siegeLocalName = LocaleManager.getInstance().getTranslation(ConfigManager.getInstance().getDefaultLanguage(), regionType.getProcessedName() + "-name"); String defaultMessage = Civs.getPrefix() + ChatColor.RED + LocaleManager.getInstance().getTranslation( ConfigManager.getInstance().getDefaultLanguage(), "siege-built").replace("$1", player.getDisplayName()) .replace("$2", siegeLocalName).replace("$3", town.getName()); defaultMessage += DiscordUtil.atAllTownOwners(town); DiscordUtil.sendMessageToMainChannel(defaultMessage); } return true; }