Add action confirmations when using signs

- Confirmations by default for selling/unrenting by signs, not for renting/buying
- Fixed a bug with message composing which would duplicate hover/click parts.
- Added `/as message <player> <message...>` for internal/console use (not shown in help).
- Closes #50
This commit is contained in:
Thijs Wiefferink 2016-06-12 21:39:12 +02:00
parent 30faa77da9
commit 852731b1ad
6 changed files with 125 additions and 8 deletions

View File

@ -0,0 +1,79 @@
package me.wiefferink.areashop.commands;
import me.wiefferink.areashop.AreaShop;
import me.wiefferink.areashop.Utils;
import me.wiefferink.areashop.messages.Message;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class MessageCommand extends CommandAreaShop {
public MessageCommand(AreaShop plugin) {
super(plugin);
}
@Override
public String getCommandStart() {
return "areashop message";
}
@Override
public String getHelp(CommandSender target) {
if(target.hasPermission("areashop.message")) {
return "help-message";
}
return null;
}
@Override
public void execute(final CommandSender sender, final String[] args) {
if(!sender.hasPermission("areashop.message")) {
plugin.message(sender, "message-noPermission");
return;
}
if(args.length < 3) {
plugin.message(sender, "message-help");
return;
}
Player player = Bukkit.getPlayer(args[1]);
if(player == null) {
plugin.message(sender, "message-notOnline", args[1]);
return;
}
String[] messageArgs = new String[args.length-2];
System.arraycopy(args, 2, messageArgs, 0, args.length-2);
String message = StringUtils.join(messageArgs);
Message.fromString(message).send(player);
}
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
List<String> result = new ArrayList<>();
if(toComplete == 2) {
for(Player player : Utils.getOnlinePlayers()) {
result.add(player.getName());
}
}
return result;
}
}

View File

@ -54,6 +54,7 @@ public class CommandManager implements CommandExecutor, TabCompleter {
commands.add(new LinksignsCommand(plugin));
commands.add(new StackCommand(plugin));
commands.add(new SetlandlordCommand(plugin));
commands.add(new MessageCommand(plugin));
// Register commands in bukkit
plugin.getCommand("AreaShop").setExecutor(this);
@ -133,7 +134,7 @@ public class CommandManager implements CommandExecutor, TabCompleter {
}
int toCompleteNumber = args.length;
String toCompletePrefix = args[args.length-1].toLowerCase();
AreaShop.debug("toCompleteNumber=" + toCompleteNumber + ", toCompletePrefix=" + toCompletePrefix + ", length=" + toCompletePrefix.length());
//AreaShop.debug("toCompleteNumber=" + toCompleteNumber + ", toCompletePrefix=" + toCompletePrefix + ", length=" + toCompletePrefix.length());
if(toCompleteNumber == 1) {
for(CommandAreaShop c : commands) {
String begin = c.getCommandStart();
@ -162,7 +163,7 @@ public class CommandManager implements CommandExecutor, TabCompleter {
result.clear();
result.addAll(set);
}
AreaShop.debug("Tabcomplete #" + toCompleteNumber + ", prefix="+ toCompletePrefix + ", result=" + result.toString());
//AreaShop.debug("Tabcomplete #" + toCompleteNumber + ", prefix="+ toCompletePrefix + ", result=" + result.toString());
return result;
}
}

View File

@ -151,10 +151,8 @@ public class FancyMessageFormat {
}
// Find interactive lines meant for this message
List<String> interactives = new ArrayList<>();
int index = line;
while(index < message.size() && isTaggedInteractive(message.get(index))) {
interactives.add(message.get(index));
index++;
while(line < message.size() && isTaggedInteractive(message.get(line))) {
interactives.add(message.remove(line));
}
// Split the line and add the parts
int at = line;

View File

@ -153,6 +153,7 @@ signProfiles:
line4: '%price%'
rightClickPlayer:
- 'areashop rent %region%'
#- 'areashop message %clicker% %lang:confirm-rent|%region%|%' # Use this instead of the above one to confirm first
leftClickPlayer:
- 'areashop info region %region%'
rented:
@ -162,10 +163,11 @@ signProfiles:
line4: '%untilshort%'
rightClickPlayer:
- 'areashop rent %region%'
#- 'areashop message %clicker% %lang:confirm-extend|%region%|%' # Use this instead of the above one to confirm first
leftClickPlayer:
- 'areashop info region %region%'
shiftRightClickPlayer:
- 'areashop unrent %region%'
- 'areashop message %clicker% %lang:confirm-unrent|%region%|%'
forsale:
line1: '&2&l[For Sale]'
line2: '%region%'
@ -173,6 +175,7 @@ signProfiles:
line4:
rightClickPlayer:
- 'areashop buy %region%'
#- 'areashop message %clicker% %lang:confirm-buy|%region%|%' # Use this instead of the above one to confirm first
leftClickPlayer:
- 'areashop info region %region%'
resell:
@ -182,6 +185,7 @@ signProfiles:
line4: '&8%player%'
rightClickPlayer:
- 'areashop buy %region%'
#- 'areashop message %clicker% %lang:confirm-buy|%region%|%' # Use this instead of the above one to confirm first
leftClickPlayer:
- 'areashop info region %region%'
shiftRightClickPlayer:
@ -196,7 +200,7 @@ signProfiles:
leftClickPlayer:
- 'areashop info region %region%'
shiftRightClickPlayer:
- 'areashop sell %region%'
- 'areashop message %clicker% %lang:confirm-sell|%region%|%'
## Option to run certain commands when a region event happens.
## Commands at a 'before' section will execute before the region details are changed in the AreaShop system
## and before any other actions occurred (setting the owner, saving/loading schematics, etc.),

View File

@ -9,6 +9,7 @@
# ║ 5: Use '/as reload' or reload/restart your server to see the changes ║
# ╚════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝
action: "[blue][bold]<%0%>[/bold]"
button: "[bold]<%0%>[/bold]"
command:
- "[bold]%0%[/bold]"
- " hover: %lang:action|Use %1%|%"
@ -500,6 +501,36 @@ setlandlord-noPermission: "You don't have permission to set the landlord for a r
setlandlord-noRegion: "The specified region is not registered: %0%."
setlandlord-success: "%lang:landlord% has successfully been set as landlord of %lang:region%."
message-help: "/as message <player> <message...>"
message-noPermission: "You do not have permission to send AreaShop messages."
message-notOnline: "%0% is not online."
confirm-rent:
- "%lang:prefix%Are you sure you want to rent %lang:tRegion|%0%|%?[break]"
- "[darkgreen][bold]►[reset] %lang:button|Click to rent %0%|%"
- " hover: %lang:action|Rent %0%|%"
- " command: /areashop rent %0%"
confirm-extend:
- "%lang:prefix%Are you sure you want to extend %lang:tRegion|%0%|%?[break]"
- "[darkgreen][bold]►[reset] %lang:button|Click to extend %0%|%"
- " hover: %lang:action|Extend %0%|%"
- " command: /areashop rent %0%"
confirm-unrent:
- "%lang:prefix%Are you sure you want to stop renting %lang:tRegion|%0%|%?[break]"
- "[darkgreen][bold]►[reset] %lang:button|Click to stop renting %0%|%"
- " hover: %lang:action|Stop renting %0%|%"
- " command: /areashop unrent %0%"
confirm-buy:
- "%lang:prefix%Are you sure you want to buy %lang:tRegion|%0%|%?[break]"
- "[darkgreen][bold]►[reset] %lang:button|Click to buy %0%|%"
- " hover: %lang:action|Buy %0%|%"
- " command: /areashop buy %0%"
confirm-sell:
- "%lang:prefix%Are you sure you want to sell %lang:tRegion|%0%|%?[break]"
- "[darkgreen][bold]►[reset] %lang:button|Click to sell %0%|%"
- " hover: %lang:action|Sell %0%|%"
- " command: /areashop sell %0%"
timeleft-years: "%0% years"
timeleft-months: "%0% months"
timeleft-days: "%0% days"

View File

@ -56,6 +56,7 @@ permissions:
areashop.stack: true
areashop.setlandlord: true
areashop.linksigns: true
areashop.message: true
areashop.landlord.*:
description: Give access to all landlord features
children:
@ -253,4 +254,7 @@ permissions:
default: op
areashop.setlandlord:
description: Allows you to set the landlord of a region, the landlord receives all revenue
default: op
areashop.message:
description: Allows you to send AreaShop messages to players
default: op