2014-10-18 10:54:45 +02:00
|
|
|
package com.massivecraft.factions.cmd;
|
|
|
|
|
|
|
|
import com.massivecraft.factions.FPlayer;
|
|
|
|
import com.massivecraft.factions.struct.Permission;
|
2015-01-22 00:58:33 +01:00
|
|
|
import com.massivecraft.factions.zcore.util.TL;
|
2019-09-14 21:13:01 +02:00
|
|
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
|
|
|
import com.mojang.brigadier.builder.ArgumentBuilder;
|
|
|
|
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
2014-10-25 20:22:41 +02:00
|
|
|
import org.apache.commons.lang.StringUtils;
|
2014-10-18 10:54:45 +02:00
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
public class CmdAnnounce extends FCommand {
|
|
|
|
|
2019-09-15 11:14:14 +02:00
|
|
|
public CmdAnnounce() {
|
|
|
|
super();
|
|
|
|
this.aliases.add("ann");
|
|
|
|
this.aliases.add("announce");
|
|
|
|
|
|
|
|
this.requiredArgs.add("message");
|
|
|
|
|
|
|
|
this.requirements = new CommandRequirements.Builder(Permission.ANNOUNCE)
|
|
|
|
.playerOnly()
|
|
|
|
.memberOnly()
|
|
|
|
.brigadier(AnnounceBrigadier.class)
|
|
|
|
.noErrorOnManyArgs()
|
|
|
|
.build();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void perform(CommandContext context) {
|
|
|
|
String prefix = ChatColor.GREEN + context.faction.getTag() + ChatColor.YELLOW + " [" + ChatColor.GRAY + context.player.getName() + ChatColor.YELLOW + "] " + ChatColor.RESET;
|
|
|
|
String message = StringUtils.join(context.args, " ");
|
|
|
|
|
|
|
|
for (Player player : context.faction.getOnlinePlayers()) {
|
|
|
|
player.sendMessage(prefix + message);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add for offline players.
|
|
|
|
for (FPlayer fp : context.faction.getFPlayersWhereOnline(false)) {
|
|
|
|
context.faction.addAnnouncement(fp, prefix + message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public TL getUsageTranslation() {
|
|
|
|
return TL.COMMAND_ANNOUNCE_DESCRIPTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected class AnnounceBrigadier implements BrigadierProvider {
|
|
|
|
@Override
|
|
|
|
public ArgumentBuilder<Object, ?> get(ArgumentBuilder<Object, ?> parent) {
|
|
|
|
return parent.then(RequiredArgumentBuilder.argument("message", StringArgumentType.greedyString()));
|
|
|
|
}
|
|
|
|
}
|
2019-09-14 21:13:01 +02:00
|
|
|
|
|
|
|
}
|