Java Code Examples for org.bukkit.block.Sign#getLines()

The following examples show how to use org.bukkit.block.Sign#getLines() . 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: SignButtons.java    From VoxelGamesLibv2 with MIT License 6 votes vote down vote up
@EventHandler
public void signInteract(@Nonnull PlayerInteractEvent event) {
    if (event.getAction() != Action.RIGHT_CLICK_BLOCK || event.getClickedBlock() == null) {
        return;
    }
    // is block a sign?
    if (event.getClickedBlock().getState() instanceof Sign) {
        User user = userHandler.getUser(event.getPlayer().getUniqueId()).orElseThrow(() -> new UserException(
                "Unknown user " + event.getPlayer().getDisplayName() + "(" + event.getPlayer().getUniqueId() + ")"));
        Sign sign = (Sign) event.getClickedBlock().getState();
        for (int i = 0; i < sign.getLines().length; i++) {
            String line = sign.getLines()[i];
            for (String key : getButtons().keySet()) {
                if (line.contains("[" + key + "]")) {
                    //TODO implement perm check
                    getButtons().get(key).execute(user, event.getClickedBlock());
                }
            }
        }
    }
}
 
Example 2
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 3
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 4
Source File: SignData.java    From DungeonsXL with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Loads all signs from the file to the instance.
 *
 * @param instance the instance where the signs are
 */
public void deserializeSigns(InstanceWorld instance) {
    try {
        ObjectInputStream os = new ObjectInputStream(new FileInputStream(file));

        int length = os.readInt();
        for (int i = 0; i < length; i++) {
            int x = os.readInt();
            int y = os.readInt();
            int z = os.readInt();

            Block block = instance.getWorld().getBlockAt(x, y, z);
            BlockState state = block.getState();
            if (state instanceof Sign) {
                Sign sign = (Sign) state;
                String[] lines = sign.getLines();
                instance.createDungeonSign(sign, lines);

                if (lines[0].equalsIgnoreCase("[lobby]")) {
                    instance.setLobbyLocation(block.getLocation());
                }
            }
        }

        os.close();

    } catch (IOException exception) {
        exception.printStackTrace();
    }
}
 
Example 5
Source File: DEditWorld.java    From DungeonsXL with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void registerSign(Block block) {
    if (block.getState() instanceof Sign) {
        Sign sign = (Sign) block.getState();
        String[] lines = sign.getLines();

        if (lines[0].equalsIgnoreCase("[lobby]")) {
            setLobbyLocation(block.getLocation());
        }
    }
}
 
Example 6
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 7
Source File: WarRegen.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
public static String blockSignString(Sign sign) {
	String out = ":";
	
	for (String str : sign.getLines()) {
		out += str+",";
	}
	
	return out;
}
 
Example 8
Source File: SignUpdateTask.java    From GriefDefender with MIT License 4 votes vote down vote up
@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 9
Source File: ContainerShop.java    From QuickShop-Reremake with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns a list of signs that are attached to this shop (QuickShop and blank signs only)
 *
 * @return a list of signs that are attached to this shop (QuickShop and blank signs only)
 */
@Override
public @NotNull List<Sign> getSigns() {
    List<Sign> signs = new ArrayList<>(4);
    if (this.getLocation().getWorld() == null) {
        return signs;
    }
    Block[] blocks = new Block[4];
    blocks[0] = location.getBlock().getRelative(BlockFace.EAST);
    blocks[1] = location.getBlock().getRelative(BlockFace.NORTH);
    blocks[2] = location.getBlock().getRelative(BlockFace.SOUTH);
    blocks[3] = location.getBlock().getRelative(BlockFace.WEST);
    String adminShopHeader =
            MsgUtil.getMessageOfflinePlayer("signs.header", null,MsgUtil.getMessageOfflinePlayer(
                    "admin-shop", Bukkit.getOfflinePlayer(this.getOwner())));
    String signHeaderUsername =
            MsgUtil.getMessageOfflinePlayer("signs.header", null, this.ownerName(true));
    for (Block b : blocks) {
        if (b == null) {
            Util.debugLog("Null signs in the queue, skipping");
            continue;
        }

        if (!(b.getState() instanceof Sign)) {
            continue;
        }
        if (!isAttached(b)) {
            continue;
        }
        Sign sign = (Sign) b.getState();
        String[] lines = sign.getLines();
        String header = lines[0];
        if (lines[0].isEmpty() && lines[1].isEmpty() && lines[2].isEmpty() && lines[3].isEmpty() ){
            signs.add(sign); //NEW SIGN
            continue;
        }
        if (header.contains(adminShopHeader) || header.contains(signHeaderUsername)) {
            signs.add(sign);
            continue; //TEXT SIGN
        }
        //Empty or matching the header
    }

    //            if (currentLine.contains(signHeader) || currentLine.isEmpty()) {
    //                signs.add(sign);
    //            } else {
    //                boolean text = false;
    //                for (String s : sign.getLines()) {
    //                    if (!s.isEmpty()) {
    //                        text = true;
    //                        break;
    //                    }
    //                }
    //                if (!text) {
    //                    signs.add(sign);
    //                }
    //            }
    //        }
    return signs;
}