user4758973
user4758973

Reputation: 3

Change what a sign says with a command

When I run a certain command, I need the sign that I'm looking at to change.

Here is my current code:

if (cmd.getName().equalsIgnoreCase("ft")) {
        if (!(p.hasPermission("ft.use"))) {
            p.sendMessage(ChatColor.RED + "You do not have permission.");
            return true;
        } else {
            Sign sign = (Sign) p.getTargetBlock(null, 10).getState();
            if (args.length == 0) {
                p.sendMessage(ChatColor.RED + "Usage: /ft <name> <1/2/3/4>");
                return true;
            } else if (args.length == 2) {
                String name = args[0];
                String id = args[1];
                if (args[1].equalsIgnoreCase("1")) {
                    if (getConfig().get("FastTravel." + name + "." + 1) != null) {
                        p.sendMessage(ChatColor.RED + args[0] + " 1 already exists please use another ID.");
                        return true;        
                    }else {
                        if(getConfig().get("FastTravel.Price") != null){
                        sign.setLine(0, "[FastTravel]");
                        sign.setLine(1, name + " 1");
                        sign.setLine(3, (String) getConfig().get("FastTravel.Price"));
                        p.sendMessage(ChatColor.GREEN + "You set the FastTravel sign '" + name + " 1'.");
                        getConfig().set("FastTravel." + args[0] +"."+ 1, p.getLocation());
                        saveConfig();
                        return true;
                        }else {
                            p.sendMessage(ChatColor.RED + "The price for FastTravel has not been set.");
                            p.sendMessage(ChatColor.RED + "Please set the price by using /setprice <price>");
                            return true;
                        }
                    }
                }
            }
        }

So if someone was to type the command /ft Test 1, the sign that they were looking at would look like this:

Line1: [FastTravel]
Line2: Test 1
Line3: (Blank)
Line4: Price

All the p.sendMessage()s are working fine, but the sign isn't changing.

Upvotes: 0

Views: 52

Answers (1)

Jojodmo
Jojodmo

Reputation: 23616

If you want to update the sign's text, you have to call sign.update(true) after setting its lines:

//set the sign's text
sign.setLine(0, "[FastTravel]");
sign.setLine(1, name + " 1");
sign.setLine(3, (String) getConfig().get("FastTravel.Price"));

//update the sign
sign.update(true);

Upvotes: 2

Related Questions