Add "allow-world-in-broadcastworld" option

Allows players to send broadcasts to a specified world by running `/broadcastworld [world] <message>` if enabled.

This is disabled by default in old configs to avoid confusion between updates.
This commit is contained in:
md678685 2018-08-27 10:19:46 +01:00
parent e642192461
commit 2806156cf4
4 changed files with 50 additions and 2 deletions

View File

@ -308,4 +308,6 @@ public interface ISettings extends IConf {
boolean isConfirmCommandEnabledByDefault(String commandName);
boolean isCompassTowardsHomePerm();
boolean isAllowWorldInBroadcastworld();
}

View File

@ -537,6 +537,7 @@ public class Settings implements net.ess3.api.ISettings {
unprotectedSigns = _getUnprotectedSign();
defaultEnabledConfirmCommands = _getDefaultEnabledConfirmCommands();
isCompassTowardsHomePerm = _isCompassTowardsHomePerm();
isAllowWorldInBroadcastworld = _isAllowWorldInBroadcastworld();
}
private List<Integer> itemSpawnBl = new ArrayList<Integer>();
@ -1459,4 +1460,15 @@ public class Settings implements net.ess3.api.ISettings {
public boolean isCompassTowardsHomePerm() {
return isCompassTowardsHomePerm;
}
private boolean isAllowWorldInBroadcastworld;
private boolean _isAllowWorldInBroadcastworld() {
return config.getBoolean("allow-world-in-broadcastworld", false);
}
@Override
public boolean isAllowWorldInBroadcastworld() {
return isAllowWorldInBroadcastworld;
}
}

View File

@ -27,7 +27,25 @@ public class Commandbroadcastworld extends EssentialsCommand {
@Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
sendBroadcast(user.getWorld().getName(), user.getDisplayName(), getFinalArg(args, 0));
World world = user.getWorld();
String message = getFinalArg(args, 0);
if (args.length < 1) {
throw new NotEnoughArgumentsException();
} else if (args.length > 1 && ess.getSettings().isAllowWorldInBroadcastworld()) {
World argWorld = ess.getWorld(args[0]);
if (argWorld != null) {
world = argWorld;
message = getFinalArg(args, 1);
}
}
if (world == null) {
world = user.getWorld();
message = getFinalArg(args, 0);
}
sendBroadcast(world.getName(), user.getDisplayName(), message);
}
@Override
@ -43,6 +61,9 @@ public class Commandbroadcastworld extends EssentialsCommand {
if (world == null) {
throw new Exception(tl("invalidWorld"));
}
if (message.isEmpty()) {
throw new NotEnoughArgumentsException();
}
sendToWorld(world, tl("broadcast", FormatUtil.replaceFormat(message).replace("\\n", "\n"), name));
}
@ -63,7 +84,15 @@ public class Commandbroadcastworld extends EssentialsCommand {
@Override
protected List<String> getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) {
return Collections.emptyList(); // The argument is only for non-players
if (args.length == 1 && ess.getSettings().isAllowWorldInBroadcastworld()) {
List<String> worlds = Lists.newArrayList();
for (World world : server.getWorlds()) {
worlds.add(world.getName());
}
return worlds;
} else {
return Collections.emptyList();
}
}
@Override

View File

@ -529,6 +529,11 @@ tpa-accept-cancellation: 120
# Allow players to set hats by clicking on their helmet slot.
allow-direct-hat: true
# Allow in-game players to specify a world when running /broadcastworld.
# If false, running /broadcastworld in-game will always send a message to the player's current world.
# This doesn't affect running the command from the console, where a world is always required.
allow-world-in-broadcastworld: true
############################################################
# +------------------------------------------------------+ #
# | EssentialsHome | #