org.bukkit.block.Sign Java Examples

The following examples show how to use org.bukkit.block.Sign. 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 BedWars with GNU Lesser General Public License v3.0 7 votes vote down vote up
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
    if (event.isCancelled()) {
        return;
    }

    if (event.getBlock().getState() instanceof Sign) {
        Location loc = event.getBlock().getLocation();
        if (manager.isSignRegistered(loc)) {
            if (event.getPlayer().hasPermission(owner.getSignCreationPermission())) {
                manager.unregisterSign(loc);
            } else {
                event.getPlayer().sendMessage(owner.returnTranslate("sign_can_not_been_destroyed"));
                event.setCancelled(true);
            }
        }
    }

}
 
Example #2
Source File: SignListener.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
    if (event.isCancelled()) {
        return;
    }

    if (event.getBlock().getState() instanceof Sign) {
        Location loc = event.getBlock().getLocation();
        if (manager.isSignRegistered(loc)) {
            if (event.getPlayer().hasPermission(owner.getSignCreationPermission())) {
                manager.unregisterSign(loc);
            } else {
                event.getPlayer().sendMessage(owner.returnTranslate("sign_can_not_been_destroyed"));
                event.setCancelled(true);
            }
        }
    }

}
 
Example #3
Source File: SignUtil.java    From GriefDefender with MIT License 6 votes vote down vote up
public static void updateSignRentable(Claim claim, Sign sign) {
    if (!isRentSign(claim, sign)) {
        return;
    }


    final PaymentType paymentType = claim.getEconomyData().getPaymentType();
    List<String> colorLines = new ArrayList<>(4);
    colorLines.add(ChatColor.translateAlternateColorCodes('&', "&7[&bGD&7-&1rent&7]"));
    colorLines.add(ChatColor.translateAlternateColorCodes('&', LegacyComponentSerializer.legacy().serialize(MessageCache.getInstance().ECONOMY_SIGN_RENT_DESCRIPTION)));
    colorLines.add(ChatColor.translateAlternateColorCodes('&', "&4$" + claim.getEconomyData().getRentRate()));

    for (int i = 0; i < colorLines.size(); i++) {
        sign.setLine(i, colorLines.get(i));
    }
    sign.update();
}
 
Example #4
Source File: SignListener.java    From ChestCommands with GNU General Public License v3.0 6 votes vote down vote up
@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 #5
Source File: SignUtil.java    From GriefDefender with MIT License 6 votes vote down vote up
private static Consumer<CommandSender> createSaleConfirmationConsumer(CommandSender src, Claim claim, Sign sign, double price) {
    return confirm -> {
        claim.getEconomyData().setSalePrice(price);
        claim.getEconomyData().setForSale(true);
        claim.getEconomyData().setSaleSignPosition(VecHelper.toVector3i(sign.getLocation()));
        claim.getData().save();
        List<String> lines = new ArrayList<>(4);
        lines.add(ChatColor.translateAlternateColorCodes('&', "&7[&bGD&7-&1sell&7]"));
        lines.add(ChatColor.translateAlternateColorCodes('&', LegacyComponentSerializer.legacy().serialize(MessageCache.getInstance().ECONOMY_SIGN_SELL_DESCRIPTION)));
        lines.add(ChatColor.translateAlternateColorCodes('&', "&4$" + String.format("%.2f", price)));
        lines.add(ChatColor.translateAlternateColorCodes('&', LegacyComponentSerializer.legacy().serialize(MessageCache.getInstance().ECONOMY_SIGN_SELL_FOOTER)));

        for (int i = 0; i < lines.size(); i++) {
            sign.setLine(i, lines.get(i));
        }
        sign.update();
        final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.ECONOMY_CLAIM_SALE_CONFIRMED,
                ImmutableMap.of("amount", price));
        GriefDefenderPlugin.sendMessage(src, message);
    };
}
 
Example #6
Source File: SignUtil.java    From GriefDefender with MIT License 6 votes vote down vote up
public static void setClaimForSale(Claim claim, Player player, Sign sign, double price) {
    if (claim.isWilderness()) {
        GriefDefenderPlugin.sendMessage(player, MessageCache.getInstance().ECONOMY_CLAIM_NOT_FOR_SALE);
        return;
    }

    // if not owner of claim, validate perms
    if (((GDClaim) claim).allowEdit(player) != null || !player.hasPermission(GDPermissions.COMMAND_CLAIM_INFO_OTHERS)) {
        TextAdapter.sendComponent(player, MessageCache.getInstance().CLAIM_NOT_YOURS);
        return;
    }

    final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.ECONOMY_CLAIM_SALE_CONFIRMATION,
            ImmutableMap.of(
            "amount", price));
    GriefDefenderPlugin.sendMessage(player, message);

    final Component saleConfirmationText = TextComponent.builder("")
            .append("\n[")
            .append("Confirm", TextColor.GREEN)
            .append("]\n")
            .clickEvent(ClickEvent.runCommand(GDCallbackHolder.getInstance().createCallbackRunCommand(createSaleConfirmationConsumer(player, claim, sign, price))))
            .build();
    GriefDefenderPlugin.sendMessage(player, saleConfirmationText);
}
 
Example #7
Source File: ContainerShop.java    From QuickShop-Reremake with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Changes the owner of this shop to the given player.
 *
 * @param owner the new owner
 */
@Override
public void setOwner(@NotNull UUID owner) {
    OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(owner);
    //Get the sign at first
    List<Sign> signs = this.getSigns();
    //then setOwner
    this.moderator.setOwner(owner);
    //then change the sign
    for (Sign shopSign : signs) {
        shopSign.setLine(0, MsgUtil.getMessageOfflinePlayer("signs.header", offlinePlayer, ownerName(false)));
        //Don't forgot update it
        shopSign.update(true);
    }
    //Event
    Bukkit.getPluginManager().callEvent(new ShopModeratorChangedEvent(this, this.moderator));
    update();
}
 
Example #8
Source File: ExtensionLeaderboardWall.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
@Override
public LoopReturn loop(int rowIndex, SignRow.WrappedMetadataSign sign) {
          Sign bukkitSign = sign.getBukkitSign();
	if (!iterator.hasNext()) {
		return LoopReturn.RETURN;
	}
	
	Entry<String, Statistic> entry = iterator.next();
	Set<Variable> variables = Sets.newHashSet();
	entry.getValue().supply(variables, null);
	variables.add(new Variable("player", entry.getKey()));
	variables.add(new Variable("rank", index + 1));
	layoutConfig.getLayout().inflate(bukkitSign, variables);
          bukkitSign.update();

          sign.setMetadata(METADATA_ID, entry);
	
	++index;
	return LoopReturn.DEFAULT;
}
 
Example #9
Source File: Signs.java    From AnnihilationPro with MIT License 6 votes vote down vote up
private void placeSignInWorld(AnniSign asign, String[] lore)
{
	Location loc = asign.getLocation().toLocation();
	Block block = loc.getWorld().getBlockAt(loc);//asign.getLocation().toLocation().getBlock();
	if(block.getType() != Material.WALL_SIGN && block.getType() != Material.SIGN_POST)
		block.getWorld().getBlockAt(loc).setType(asign.isSignPost() ? Material.SIGN_POST : Material.WALL_SIGN);
	
	Sign sign = (Sign)block.getState();
	if(sign != null)
	{
		for(int x = 0; x < lore.length; x++)
			sign.setLine(x, lore[x]);
		org.bukkit.material.Sign matSign = new org.bukkit.material.Sign(block.getType());
		matSign.setFacingDirection(asign.getFacingDirection());
		sign.setData(matSign);
		sign.update(true);
	}
}
 
Example #10
Source File: ATM.java    From TimeIsMoney with GNU General Public License v3.0 6 votes vote down vote up
@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 #11
Source File: EconomyUtil.java    From GriefDefender with MIT License 6 votes vote down vote up
public void sellCancelConfirmation(CommandSender src, Claim claim, Sign sign) {
    final Player player = (Player) src;
    final GDClaim gdClaim = (GDClaim) claim;
    // check sell access
    if (gdClaim.allowEdit(player) != null) {
        GriefDefenderPlugin.sendMessage(player, MessageCache.getInstance().CLAIM_NOT_YOURS);
        return;
    }

    final Component sellCancelConfirmationText = TextComponent.builder()
            .append("\n[")
            .append(MessageCache.getInstance().LABEL_CONFIRM.color(TextColor.GREEN))
            .append("]\n")
            .clickEvent(ClickEvent.runCommand(GDCallbackHolder.getInstance().createCallbackRunCommand(src, createSellCancelConfirmed(src, claim, sign), true)))
            .build();
    final Component message = TextComponent.builder()
            .append(MessageCache.getInstance().ECONOMY_CLAIM_SALE_CANCEL_CONFIRMATION)
            .append("\n")
            .append(sellCancelConfirmationText)
            .build();
    GriefDefenderPlugin.sendMessage(src, message);
}
 
Example #12
Source File: SignListener.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onChangeSign(SignChangeEvent event) {
    if (event.isCancelled()) {
        return;
    }
    if (event.getBlock().getState() instanceof Sign) {
        Location loc = event.getBlock().getLocation();
        if (SIGN_PREFIX.contains(event.getLine(0).toLowerCase())) {
            if (event.getPlayer().hasPermission(owner.getSignCreationPermission())) {
                if (manager.registerSign(loc, event.getLine(1))) {
                    event.getPlayer().sendMessage(owner.returnTranslate("sign_successfully_created"));
                } else {
                    event.getPlayer().sendMessage(owner.returnTranslate("sign_can_not_been_created"));
                    event.setCancelled(true);
                    event.getBlock().breakNaturally();
                }
            }
        }
    }
}
 
Example #13
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 #14
Source File: Region.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
public void updateSigns(String fname) {
    if (!RedProtect.get().config.configRoot().region_settings.enable_flag_sign) {
        return;
    }
    List<Location> locs = RedProtect.get().config.getSigns(this.getID());
    if (locs.size() > 0) {
        for (Location loc : locs) {
            if (loc.getBlock().getState() instanceof Sign) {
                Sign s = (Sign) loc.getBlock().getState();
                String[] lines = s.getLines();
                if (lines[0].equalsIgnoreCase("[flag]")) {
                    if (lines[1].equalsIgnoreCase(fname) && this.name.equalsIgnoreCase(ChatColor.stripColor(lines[2]))) {
                        s.setLine(3, RedProtect.get().lang.get("region.value") + " " + ChatColor.translateAlternateColorCodes('&', RedProtect.get().lang.translBool(getFlagString(fname))));
                        s.update();
                        RedProtect.get().config.putSign(this.getID(), loc);
                    }
                } else {
                    RedProtect.get().config.removeSign(this.getID(), loc);
                }
            } else {
                RedProtect.get().config.removeSign(this.getID(), loc);
            }
        }
    }
}
 
Example #15
Source File: Cannon.java    From civcraft with GNU General Public License v2.0 6 votes vote down vote up
private void updateAngleSign(Block block) {
	Sign sign = (Sign)block.getState();
	sign.setLine(0, "YAW");
	sign.setLine(1, ""+this.angle);
	
	double a = this.angle;
	
	if (a > 0) {
		sign.setLine(2, "-->");
	} else if (a < 0){
		sign.setLine(2, "<--");
	} else {
		sign.setLine(2, "");
	}
	
	sign.setLine(3, "");
	sign.update();
}
 
Example #16
Source File: DInstanceWorld.java    From DungeonsXL with GNU General Public License v3.0 6 votes vote down vote up
@Override
public DungeonSign createDungeonSign(Sign sign, String[] lines) {
    String type = lines[0].substring(1, lines[0].length() - 1);
    try {
        Class<? extends DungeonSign> clss = plugin.getSignRegistry().get(type.toUpperCase());
        if (clss == null) {
            return null;
        }
        Constructor constructor = clss.getConstructor(DungeonsAPI.class, Sign.class, String[].class, InstanceWorld.class);
        DungeonSign dSign = (DungeonSign) constructor.newInstance(plugin, sign, lines, this);
        signs.put(sign.getBlock(), dSign);
        return dSign;

    } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException
            | IllegalArgumentException | InvocationTargetException exception) {
        MessageUtil.log(plugin, "&4Could not create a dungeon sign of the type \"" + type
                + "\". A dungeon sign implementation needs a constructor with the types (DungeonsAPI, org.bukkit.block.Sign, String[], InstanceWorld).");
        return null;
    }
}
 
Example #17
Source File: SignUpdater.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
private void handleBlockClick(Player player, Block block) {
    if(block != null && block.getState() instanceof Sign) {
        sign(block.getLocation()).ifPresent(
            sign -> sign.connector().teleport(player)
        );
    }
}
 
Example #18
Source File: DEditPlayer.java    From DungeonsXL with GNU General Public License v3.0 5 votes vote down vote up
public void poke(Block block) {
    if (block.getState() instanceof Sign) {
        Sign sign = (Sign) block.getState();
        String[] lines = sign.getLines();
        if (lines[0].isEmpty() && lines[1].isEmpty() && lines[2].isEmpty() && lines[3].isEmpty()) {
            if (linesCopy != null) {
                SignChangeEvent event = new SignChangeEvent(block, getPlayer(), linesCopy);
                Bukkit.getPluginManager().callEvent(event);
                if (!event.isCancelled()) {
                    sign.setLine(0, event.getLine(0));
                    sign.setLine(1, event.getLine(1));
                    sign.setLine(2, event.getLine(2));
                    sign.setLine(3, event.getLine(3));
                    sign.update();
                }
            }
        } else {
            linesCopy = lines;
            MessageUtil.sendMessage(getPlayer(), DMessage.PLAYER_SIGN_COPIED.getMessage());
        }
    } else {
        String info = "" + block.getType();
        if (block.getData() != 0) {
            info = info + "," + block.getData();
        }
        MessageUtil.sendMessage(getPlayer(), DMessage.PLAYER_BLOCK_INFO.getMessage(info));
    }
}
 
Example #19
Source File: SignContent.java    From NyaaUtils with MIT License 5 votes vote down vote up
public static SignContent fromItemStack(ItemStack item) {
    SignContent content = new SignContent();
    if (item.hasItemMeta() && item.getItemMeta() instanceof BlockStateMeta) {
        BlockStateMeta blockStateMeta = (BlockStateMeta) item.getItemMeta();
        if (blockStateMeta.hasBlockState() && blockStateMeta.getBlockState() instanceof Sign) {
            Sign sign = ((Sign) blockStateMeta.getBlockState());
            for (int i = 0; i < 4; i++) {
                content.setLine(i, sign.getLine(i));
            }
        }
    }
    return content;
}
 
Example #20
Source File: SignContent.java    From NyaaUtils with MIT License 5 votes vote down vote up
public ItemStack toItemStack(ItemStack item) {
    if (item.getItemMeta() instanceof BlockStateMeta) {
        BlockStateMeta blockStateMeta = (BlockStateMeta) item.getItemMeta();
        if (blockStateMeta.getBlockState() instanceof Sign) {
            Sign sign = ((Sign) blockStateMeta.getBlockState());
            for (int i = 0; i < 4; i++) {
                sign.setLine(i, getLine(i));
            }
            blockStateMeta.setBlockState(sign);
        }
        item.setItemMeta(blockStateMeta);
    }
    return item;
}
 
Example #21
Source File: GameJoinSign.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
public Sign getSign() {
  BlockState state = this.signLocation.getBlock().getState();

  if (!(state instanceof Sign)) {
    return null;
  }

  return (Sign) state;
}
 
Example #22
Source File: WarpSigns.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Checks to see if a sign has been broken
 * @param e - event
 */
@EventHandler(priority = EventPriority.NORMAL)
public void onSignBreak(BlockBreakEvent e) {
    Block b = e.getBlock();
    Player player = e.getPlayer();
    if (b.getWorld().equals(ASkyBlock.getIslandWorld()) || b.getWorld().equals(ASkyBlock.getNetherWorld())) {
        if (b.getType().equals(Material.SIGN_POST) || b.getType().equals(Material.WALL_SIGN)) {
            Sign s = (Sign) b.getState();
            if (s != null) {
                //plugin.getLogger().info("DEBUG: sign found at location " + s.toString());
                if (s.getLine(0).equalsIgnoreCase(ChatColor.GREEN + plugin.myLocale().warpswelcomeLine)) {
                    // Do a quick check to see if this sign location is in
                    //plugin.getLogger().info("DEBUG: welcome sign");
                    // the list of warp signs
                    if (warpList.containsValue(s.getLocation())) {
                        //plugin.getLogger().info("DEBUG: warp sign is in list");
                        // Welcome sign detected - check to see if it is
                        // this player's sign
                        if ((warpList.containsKey(player.getUniqueId()) && warpList.get(player.getUniqueId()).equals(s.getLocation()))) {
                            // Player removed sign
                            removeWarp(s.getLocation());
                            Bukkit.getPluginManager().callEvent(new WarpRemoveEvent(plugin, s.getLocation(), player.getUniqueId()));
                        } else if (player.isOp()  || player.hasPermission(Settings.PERMPREFIX + "mod.removesign")) {
                            // Op or mod removed sign
                            Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).warpsremoved);
                            removeWarp(s.getLocation());
                            Bukkit.getPluginManager().callEvent(new WarpRemoveEvent(plugin, s.getLocation(), player.getUniqueId()));
                        } else {
                            // Someone else's sign - not allowed
                            Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).warpserrorNoRemove);
                            e.setCancelled(true);
                        }
                    }
                }
            }
        }
    }
}
 
Example #23
Source File: SignListener.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
  public void signRemoved(BlockBreakEvent event) {
      Location blockLocation = event.getBlock().getLocation();
      World w = blockLocation.getWorld();
  	Block b = w.getBlockAt(blockLocation);
if(b.getType() == Material.WALL_SIGN || b.getType() == SkyWarsReloaded.getNMS().getMaterial("SIGN_POST").getType()){
   	Sign sign = (Sign) b.getState();
   	Location loc = sign.getLocation();
   	SWRServer server = SWRServer.getSign(loc);
   	if (server != null) {
   		server.removeSign(loc);
   		event.getPlayer().sendMessage(new Messaging.MessageFormatter().format("signs.remove"));
   	}
}
  }
 
Example #24
Source File: SignClickEvent.java    From Survival-Games with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void clickHandler(PlayerInteractEvent e){

    if(!(e.getAction()==Action.RIGHT_CLICK_BLOCK || e.getAction()==Action.LEFT_CLICK_BLOCK)) return;
    

    Block clickedBlock = e.getClickedBlock(); 
    if(!(clickedBlock.getState() instanceof Sign)) return;        
    Sign thisSign = (Sign) clickedBlock.getState();
    //System.out.println("Clicked sign");
    String[] lines = thisSign.getLines();
    if(lines.length<3) return;
    if(lines[0].equalsIgnoreCase("[SurvivalGames]")) {
        e.setCancelled(true);
        try{
            if(lines[2].equalsIgnoreCase("Auto Assign")){
            	if(SettingsManager.getInstance().getConfig().getInt("randomjoin-mode", 1) == 0) {
            		GameManager.getInstance().addPlayerRandomly(e.getPlayer());			
            	}else {
            		GameManager.getInstance().autoAddPlayer(e.getPlayer());						
	}
            }
            else{
                String game = lines[2].replace("Arena ", "");
                int gameno  = Integer.parseInt(game);
                GameManager.getInstance().addPlayer(e.getPlayer(), gameno);
            }

        }catch(Exception ek){}
    }

}
 
Example #25
Source File: HuntEffect.java    From Civs with GNU General Public License v3.0 5 votes vote down vote up
private Player hasValidSign(Location l, RegionType rt, UUID uuid) {
    Player player = Bukkit.getPlayer(uuid);
    Civilian civilian = CivilianManager.getInstance().getCivilian(uuid);
    Block block = l.getBlock().getRelative(BlockFace.UP);
    BlockState state = block.getState();
    if (!(state instanceof Sign)) {
        return null;
    }

    Sign sign = (Sign) state;

    Player targetPlayer = null;
    try {
        targetPlayer = Bukkit.getPlayer(sign.getLine(0));
    } catch (Exception e) {
        block.breakNaturally();
        player.sendMessage(Civs.getPrefix() + LocaleManager.getInstance().getTranslation(civilian.getLocale(),
                "invalid-name"));
        return null;
    }
    if (targetPlayer == null || !targetPlayer.isOnline()) {
        block.breakNaturally();
        player.sendMessage(Civs.getPrefix() + LocaleManager.getInstance().getTranslation(civilian.getLocale(),
                "invalid-name"));
        return null;
    }

    if (!targetPlayer.getWorld().equals(player.getWorld())) {
        block.breakNaturally();
        player.sendMessage(Civs.getPrefix() + LocaleManager.getInstance().getTranslation(civilian.getLocale(),
                "target-not-in-world"));
        return null;
    }

    return targetPlayer;
}
 
Example #26
Source File: SignShop.java    From Shopkeepers with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean check() {
	if (!shopkeeper.getChunkData().isChunkLoaded()) {
		// only verify sign, if the chunk is currently loaded:
		return false;
	}

	Sign sign = this.getSign();
	if (sign == null) {
		String worldName = shopkeeper.getWorldName();
		int x = shopkeeper.getX();
		int y = shopkeeper.getY();
		int z = shopkeeper.getZ();

		// removing the shopkeeper, because re-spawning might fail (ex. attached block missing) or could be abused
		// (sign drop farming):
		Log.debug("Shopkeeper sign at (" + worldName + "," + x + "," + y + "," + z + ") is no longer existing! Attempting respawn now.");
		if (!this.spawn()) {
			Log.warning("Shopkeeper sign at (" + worldName + "," + x + "," + y + "," + z + ") could not be replaced! Removing shopkeeper now!");
			// delayed removal:
			Bukkit.getScheduler().runTask(ShopkeepersPlugin.getInstance(), new Runnable() {

				@Override
				public void run() {
					shopkeeper.delete();
				}
			});
		}
		return true;
	}

	// update sign content if requested:
	if (updateSign) {
		updateSign = false;
		this.updateSign();
	}

	return false;
}
 
Example #27
Source File: VersionHelper112.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
public Block getBlockRelative(Block block) {
    if (block.getState() instanceof Sign) {
        org.bukkit.material.Sign s = (org.bukkit.material.Sign) block.getState().getData();
        return block.getRelative(s.getAttachedFace());
    }
    return null;
}
 
Example #28
Source File: DebugCommand.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
public void restoresigns_cmd() {
	
	CivMessage.send(sender, "restoring....");
	for (StructureSign sign : CivGlobal.getStructureSigns()) {
		
		BlockCoord bcoord = sign.getCoord();
		Block block = bcoord.getBlock();
		ItemManager.setTypeId(block, CivData.WALL_SIGN);
		ItemManager.setData(block, sign.getDirection());
		
		Sign s = (Sign)block.getState();
		String[] lines = sign.getText().split("\n");
		
		if (lines.length > 0) {
			s.setLine(0, lines[0]);
		}
		if (lines.length > 1) {
			s.setLine(1, lines[1]);
		}
		
		if (lines.length > 2) {
			s.setLine(2, lines[2]);
		}
		
		if (lines.length > 3) {
			s.setLine(3, lines[3]);
		}
		s.update();
		
		
	}
	
	
}
 
Example #29
Source File: SignShop.java    From Shopkeepers with GNU General Public License v3.0 5 votes vote down vote up
public void updateSign() {
	Sign sign = this.getSign();
	if (sign == null) {
		updateSign = true; // request update, once the sign is available again
		return;
	}

	// line 0: header
	sign.setLine(0, Settings.signShopFirstLine);

	// line 1: shop name
	String name = shopkeeper.getName();
	String line1 = "";
	if (name != null) {
		name = this.trimToNameLength(name);
		line1 = name;
	}
	sign.setLine(1, line1);

	// line 2: owner name
	String line2 = "";
	if (shopkeeper instanceof PlayerShopkeeper) {
		line2 = ((PlayerShopkeeper) shopkeeper).getOwnerName();
	}
	sign.setLine(2, line2);

	// line 3: empty
	sign.setLine(3, "");

	// apply sign changes:
	sign.update();
}
 
Example #30
Source File: SignLayout.java    From HeavySpleef with GNU General Public License v3.0 5 votes vote down vote up
public boolean inflate(Sign sign, Set<Variable> variables) {
	for (int i = 0; i < lines.size() && i < LINE_COUNT; i++) {
		CustomizableLine line = lines.get(i);
		String lineString = line.generate(variables);
		
		sign.setLine(i, lineString);
	}

	return sign.update();
}