2011-03-19 23:39:51 +01:00
|
|
|
package com.earth2me.essentials.commands;
|
|
|
|
|
2013-10-16 21:59:39 +02:00
|
|
|
import com.earth2me.essentials.CommandSource;
|
2013-05-26 17:23:11 +02:00
|
|
|
import com.earth2me.essentials.Console;
|
2011-03-19 23:39:51 +01:00
|
|
|
import com.earth2me.essentials.User;
|
2023-08-29 00:41:40 +02:00
|
|
|
import com.earth2me.essentials.messaging.IMessageRecipient;
|
2013-06-08 23:31:19 +02:00
|
|
|
import com.earth2me.essentials.utils.FormatUtil;
|
2023-08-29 00:41:40 +02:00
|
|
|
import net.ess3.api.IUser;
|
|
|
|
import net.essentialsx.api.v2.events.HelpopMessageSendEvent;
|
2011-11-18 18:42:26 +01:00
|
|
|
import org.bukkit.Server;
|
2011-03-19 23:39:51 +01:00
|
|
|
|
2023-08-29 00:41:40 +02:00
|
|
|
import java.util.ArrayList;
|
2020-08-11 20:09:22 +02:00
|
|
|
import java.util.Collections;
|
2017-06-11 02:17:43 +02:00
|
|
|
import java.util.List;
|
2015-04-15 06:06:16 +02:00
|
|
|
import java.util.logging.Level;
|
|
|
|
|
|
|
|
import static com.earth2me.essentials.I18n.tl;
|
|
|
|
|
|
|
|
public class Commandhelpop extends EssentialsCommand {
|
|
|
|
public Commandhelpop() {
|
|
|
|
super("helpop");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
|
|
|
user.setDisplayNick();
|
2023-08-29 00:41:40 +02:00
|
|
|
final String message = sendMessage(server, user, args);
|
2015-04-15 06:06:16 +02:00
|
|
|
if (!user.isAuthorized("essentials.helpop.receive")) {
|
|
|
|
user.sendMessage(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
|
2023-08-29 00:41:40 +02:00
|
|
|
sendMessage(server, Console.getInstance(), args);
|
2015-04-15 06:06:16 +02:00
|
|
|
}
|
2011-03-19 23:39:51 +01:00
|
|
|
|
2023-08-29 00:41:40 +02:00
|
|
|
private String sendMessage(final Server server, final IMessageRecipient from, final String[] args) throws Exception {
|
2015-04-15 06:06:16 +02:00
|
|
|
if (args.length < 1) {
|
|
|
|
throw new NotEnoughArgumentsException();
|
|
|
|
}
|
2023-08-29 00:41:40 +02:00
|
|
|
|
|
|
|
final String message = FormatUtil.stripFormat(getFinalArg(args, 0));
|
|
|
|
final String finalMessage = tl("helpOp", from.getDisplayName(), message);
|
|
|
|
ess.getLogger().log(Level.INFO, finalMessage);
|
|
|
|
|
|
|
|
final List<IUser> recipients = new ArrayList<>();
|
|
|
|
for (IUser user : ess.getOnlineUsers()) {
|
|
|
|
if (user.getBase().hasPermission("essentials.helpop.receive")) {
|
|
|
|
recipients.add(user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
final HelpopMessageSendEvent sendEvent = new HelpopMessageSendEvent(from, recipients, message);
|
|
|
|
ess.getServer().getPluginManager().callEvent(sendEvent);
|
|
|
|
|
|
|
|
for (IUser recipient : sendEvent.getRecipients()) {
|
|
|
|
recipient.sendMessage(finalMessage);
|
|
|
|
}
|
|
|
|
|
|
|
|
return finalMessage;
|
2015-04-15 06:06:16 +02:00
|
|
|
}
|
2017-06-11 02:17:43 +02:00
|
|
|
|
|
|
|
@Override
|
2020-10-03 19:46:05 +02:00
|
|
|
protected List<String> getTabCompleteOptions(final Server server, final CommandSource sender, final String commandLabel, final String[] args) {
|
2020-08-11 20:09:22 +02:00
|
|
|
return Collections.emptyList();
|
2017-06-11 02:17:43 +02:00
|
|
|
}
|
2011-03-19 23:39:51 +01:00
|
|
|
}
|