use of br.net.fabiozumbi12.UltimateChat.Bukkit.UCChannel in project UltimateChat by FabioZumbi12.
the class UCCommands method uchat.
private CommandCallable uchat() {
CommandSpec msgtoggle = CommandSpec.builder().arguments(GenericArguments.optional(GenericArguments.requiringPermission(GenericArguments.player(Text.of("player")), "uchat.msgtoggle.others"))).description(Text.of("Disable private messages.")).permission("uchat.cmd.msgtoggle").executor((src, args) -> {
{
if (args.<Player>getOne("player").isPresent()) {
Player p = args.<Player>getOne("player").get();
if (UChat.get().msgTogglePlayers.contains(p.getName())) {
UChat.get().msgTogglePlayers.remove(p.getName());
UChat.get().getLang().sendMessage(p, "cmd.msgtoggle.enabled");
} else {
UChat.get().msgTogglePlayers.add(p.getName());
UChat.get().getLang().sendMessage(p, "cmd.msgtoggle.disabled");
}
return CommandResult.success();
}
if (src instanceof Player) {
Player p = (Player) src;
if (UChat.get().msgTogglePlayers.contains(p.getName())) {
UChat.get().msgTogglePlayers.remove(p.getName());
UChat.get().getLang().sendMessage(p, "cmd.msgtoggle.enabled");
} else {
UChat.get().msgTogglePlayers.add(p.getName());
UChat.get().getLang().sendMessage(p, "cmd.msgtoggle.disabled");
}
} else {
throw new CommandException(Text.of("Only players can use this command or add a player name as last argument."), true);
}
return CommandResult.success();
}
}).build();
CommandSpec delchannel = CommandSpec.builder().arguments(new ChannelCommandElement(Text.of("channel"))).description(Text.of("Deletes a channel.")).permission("uchat.cmd.delchannel").executor((src, args) -> {
{
// uchat delchannel <channel>
Optional<UCChannel> optch = args.getOne("channel");
if (!optch.isPresent()) {
throw new CommandException(UChat.get().getLang().getText("channel.dontexist"), true);
}
UCChannel ch = optch.get();
List<String> toAdd = new ArrayList<>(ch.getMembers());
toAdd.forEach(m -> {
UChat.get().getDefChannel(src instanceof Player ? ((Player) src).getWorld().getName() : null).addMember(m);
// fire event
if (Sponge.getServer().getPlayer(m).isPresent()) {
PlayerChangeChannelEvent event = new PlayerChangeChannelEvent(Sponge.getServer().getPlayer(m).get(), null, UChat.get().getDefChannel(src instanceof Player ? ((Player) src).getWorld().getName() : null));
Sponge.getEventManager().post(event);
}
});
UChat.get().getConfig().delChannel(ch);
UChat.get().getLang().sendMessage(src, UChat.get().getLang().get("cmd.delchannel.success").replace("{channel}", ch.getName()));
return CommandResult.success();
}
}).build();
CommandSpec newchannel = CommandSpec.builder().arguments(GenericArguments.string(Text.of("channel")), GenericArguments.string(Text.of("alias")), GenericArguments.string(Text.of("color"))).description(Text.of("Creates a new channel channel.")).permission("uchat.cmd.newchannel").executor((src, args) -> {
{
// uchat newchannel <channel> <alias> <color>
String ch = args.<String>getOne("channel").get();
String alias = args.<String>getOne("alias").get();
String color = args.<String>getOne("color").get();
if (color.length() != 2 || !color.matches("(&([a-fk-or0-9]))$")) {
throw new CommandException(UChat.get().getLang().getText("channel.invalidcolor"), true);
}
UCChannel newch = new UCChannel(ch, alias, color);
try {
UChat.get().getConfig().addChannel(newch);
registerChannelAliases();
} catch (Exception e) {
e.printStackTrace();
}
UChat.get().getLang().sendMessage(src, UChat.get().getLang().get("cmd.newchannel.success").replace("{channel}", newch.getName()));
return CommandResult.success();
}
}).build();
CommandSpec chconfig = CommandSpec.builder().arguments(new ChannelCommandElement(Text.of("channel")), GenericArguments.choices(Text.of("key"), getChKeys()), GenericArguments.string(Text.of("value"))).description(Text.of("Edit the config of a channel.")).permission("uchat.cmd.chconfig").executor((src, args) -> {
{
// uchat chconfig <channel> <key> <value>
Optional<UCChannel> optch = args.getOne("channel");
if (!optch.isPresent()) {
throw new CommandException(UChat.get().getLang().getText("channel.dontexist"), true);
}
UCChannel ch = optch.get();
String key = args.<String>getOne("key").get();
String value = args.<String>getOne("value").get();
if (!ch.getProperties().containsKey(key)) {
throw new CommandException(UChat.get().getLang().getText("cmd.chconfig.invalidkey"), true);
}
UChat.get().getConfig().delChannel(ch);
ch.setProperty(key, value);
try {
UChat.get().getConfig().addChannel(ch);
} catch (Exception e) {
e.printStackTrace();
}
UChat.get().getLang().sendMessage(src, "cmd.chconfig.success");
return CommandResult.success();
}
}).build();
CommandSpec reload = CommandSpec.builder().description(Text.of("Command to reload uchat.")).permission("uchat.cmd.reload").executor((src, args) -> {
{
// uchat reload
try {
UChat.get().reload();
UChat.get().getLang().sendMessage(src, "plugin.reloaded");
} catch (Exception e) {
e.printStackTrace();
}
return CommandResult.success();
}
}).build();
CommandSpec clear = CommandSpec.builder().description(Text.of("Clear your chat.")).permission("uchat.cmd.clear").executor((src, args) -> {
{
if (src instanceof Player) {
Player p = (Player) src;
// uchat clear
for (int i = 0; i < 100; i++) {
p.sendMessage(Text.of(" "));
}
UChat.get().getLang().sendMessage(src, "cmd.clear.cleared");
}
return CommandResult.success();
}
}).build();
CommandSpec clearAll = CommandSpec.builder().description(Text.of("Clear the chat of all online players.")).permission("uchat.cmd.clear-all").executor((src, args) -> {
{
// uchat clear-all
for (Player play : Sponge.getServer().getOnlinePlayers()) {
for (int i = 0; i < 100; i++) {
if (!play.isOnline()) {
continue;
}
play.sendMessage(Text.of(" "));
}
}
return CommandResult.success();
}
}).build();
CommandSpec spy = CommandSpec.builder().description(Text.of("Turn on the social spy.")).permission("uchat.cmd.spy").executor((src, args) -> {
{
if (src instanceof Player) {
Player p = (Player) src;
// uchat spy
if (!UChat.get().isSpy.contains(p.getName())) {
UChat.get().isSpy.add(p.getName());
UChat.get().getLang().sendMessage(src, "cmd.spy.enabled");
} else {
UChat.get().isSpy.remove(p.getName());
UChat.get().getLang().sendMessage(src, "cmd.spy.disabled");
}
}
return CommandResult.success();
}
}).build();
CommandSpec ignorePlayer = CommandSpec.builder().arguments(GenericArguments.player(Text.of("player"))).description(Text.of("Ignore a player.")).permission("uchat.cmd.ignore.player").executor((src, args) -> {
{
if (src instanceof Player) {
Player p = (Player) src;
// uchat ignore player
Player pi = args.<Player>getOne("player").get();
if (pi.equals(p)) {
throw new CommandException(UChat.get().getLang().getText("cmd.ignore.self"), true);
}
if (!UChat.get().getPerms().canIgnore(p, pi)) {
UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("chat.cantignore"));
return CommandResult.success();
}
if (UCMessages.isIgnoringPlayers(p.getName(), pi.getName())) {
UCMessages.unIgnorePlayer(p.getName(), pi.getName());
UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("player.unignoring").replace("{player}", pi.getName()));
} else {
UCMessages.ignorePlayer(p.getName(), pi.getName());
UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("player.ignoring").replace("{player}", pi.getName()));
}
}
return CommandResult.success();
}
}).build();
CommandSpec ignoreChannel = CommandSpec.builder().arguments(new ChannelCommandElement(Text.of("channel"))).description(Text.of("Ignore a channel.")).permission("uchat.cmd.ignore.channel").executor((src, args) -> {
{
if (src instanceof Player) {
Player p = (Player) src;
// uchat ignore channel
Optional<UCChannel> optch = args.getOne("channel");
if (!optch.isPresent()) {
throw new CommandException(UChat.get().getLang().getText("channel.dontexist"), true);
}
UCChannel ch = optch.get();
if (!UChat.get().getPerms().canIgnore(p, ch)) {
UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("chat.cantignore"));
return CommandResult.success();
}
if (ch.isIgnoring(p.getName())) {
ch.unIgnoreThis(p.getName());
UChat.get().getLang().sendMessage(src, UChat.get().getLang().get("channel.notignoring").replace("{channel}", ch.getName()));
} else {
ch.ignoreThis(p.getName());
UChat.get().getLang().sendMessage(src, UChat.get().getLang().get("channel.ignoring").replace("{channel}", ch.getName()));
}
}
return CommandResult.success();
}
}).build();
CommandSpec mute = CommandSpec.builder().arguments(GenericArguments.player(Text.of("player")), GenericArguments.optional(new ChannelCommandElement(Text.of("channel")))).description(Text.of("Mute a player.")).permission("uchat.cmd.mute").executor((src, args) -> {
{
// uchat mute player channel
Player play = args.<Player>getOne("player").get();
if (args.<UCChannel>getOne("channel").isPresent()) {
UCChannel ch = args.<UCChannel>getOne("channel").get();
if (ch.isMuted(play.getName())) {
ch.unMuteThis(play.getName());
UChat.get().getLang().sendMessage(src, UChat.get().getLang().get("channel.unmuted.this").replace("{player}", play.getName()).replace("{channel}", ch.getName()));
if (play.isOnline()) {
UChat.get().getLang().sendMessage(play, UChat.get().getLang().get("channel.player.unmuted.this").replace("{channel}", ch.getName()));
}
} else {
ch.muteThis(play.getName());
UChat.get().getLang().sendMessage(src, UChat.get().getLang().get("channel.muted.this").replace("{player}", play.getName()).replace("{channel}", ch.getName()));
if (play.isOnline()) {
UChat.get().getLang().sendMessage(play, UChat.get().getLang().get("channel.player.muted.this").replace("{channel}", ch.getName()));
}
}
} else {
if (UChat.get().mutes.contains(play.getName())) {
UChat.get().mutes.remove(play.getName());
UChat.get().unMuteInAllChannels(play.getName());
UChat.get().getLang().sendMessage(src, UChat.get().getLang().get("channel.unmuted.all").replace("{player}", play.getName()));
if (play.isOnline()) {
UChat.get().getLang().sendMessage(play, "channel.player.unmuted.all");
}
} else {
UChat.get().mutes.add(play.getName());
UChat.get().muteInAllChannels(play.getName());
UChat.get().getLang().sendMessage(src, UChat.get().getLang().get("channel.muted.all").replace("{player}", play.getName()));
if (play.isOnline()) {
UChat.get().getLang().sendMessage(play, "channel.player.muted.all");
}
}
}
return CommandResult.success();
}
}).build();
CommandSpec tempmute = CommandSpec.builder().arguments(GenericArguments.integer(Text.of("time")), GenericArguments.player(Text.of("player"))).description(Text.of("Temporary mute a player.")).permission("uchat.cmd.tempmute").executor((src, args) -> {
{
// uchat tempmute time player
Player play = args.<Player>getOne("player").get();
int time = args.<Integer>getOne("time").get();
if (UChat.get().mutes.contains(play.getName())) {
UChat.get().getLang().sendMessage(src, "channel.already.muted");
} else {
UChat.get().mutes.add(play.getName());
UChat.get().muteInAllChannels(play.getName());
UChat.get().getLang().sendMessage(src, UChat.get().getLang().get("channel.tempmuted.all").replace("{player}", play.getName()).replace("{time}", String.valueOf(time)));
if (play.isOnline()) {
UChat.get().getLang().sendMessage(play, UChat.get().getLang().get("channel.player.tempmuted.all").replace("{time}", String.valueOf(time)));
}
// mute counter
Task.builder().execute(new MuteCountDown(play.getName(), time)).interval(1, TimeUnit.SECONDS).name("Mute Counter").submit(UChat.get().instance());
}
return CommandResult.success();
}
}).build();
CommandSpec help = CommandSpec.builder().description(Text.of("Se help about commands.")).executor((src, args) -> {
{
sendHelp(src);
return CommandResult.success();
}
}).build();
// uchat <args...>
return CommandSpec.builder().description(Text.of("Main command for uchat.")).executor((src, args) -> {
{
// no args
src.sendMessage(UCUtil.toText("&b---------------- " + UChat.get().instance().getName() + " " + UChat.get().instance().getVersion().get() + " ---------------"));
src.sendMessage(UCUtil.toText("&bDeveloped by &6" + UChat.get().instance().getAuthors().get(0) + "."));
src.sendMessage(UCUtil.toText("&bFor more information about the commands, type [" + "&6/uchat ?&b]."));
src.sendMessage(UCUtil.toText("&b---------------------------------------------------"));
return CommandResult.success();
}
}).child(help, "?").child(chconfig, "chconfig").child(delchannel, "delchannel").child(newchannel, "newchannel").child(reload, "reload").child(clear, "clear").child(clearAll, "clear-all").child(spy, "spy").child(CommandSpec.builder().child(ignorePlayer, "player").child(ignoreChannel, "channel").build(), "ignore").child(mute, "mute").child(tempmute, "tempmute").child(msgtoggle, "msgtoggle").build();
}
use of br.net.fabiozumbi12.UltimateChat.Bukkit.UCChannel in project UltimateChat by FabioZumbi12.
the class UCMessages method sendFancyMessage.
static MutableMessageChannel sendFancyMessage(String[] format, Text msg, UCChannel channel, CommandSource sender, CommandSource tellReceiver) {
// Execute listener:
HashMap<String, String> tags = new HashMap<>();
for (String str : UChat.get().getConfig().root().general.custom_tags) {
tags.put(str, str);
}
SendChannelMessageEvent event = new SendChannelMessageEvent(tags, format, sender, channel, msg, true);
Sponge.getEventManager().post(event);
if (event.isCancelled()) {
return null;
}
registeredReplacers = event.getResgisteredTags();
defFormat = event.getDefFormat();
String evmsg = event.getMessage().toPlain();
// send to event
MutableMessageChannel msgCh = MessageChannel.TO_CONSOLE.asMutable();
evmsg = UCChatProtection.filterChatMessage(sender, evmsg, event.getChannel());
if (evmsg == null) {
return null;
}
HashMap<CommandSource, Text> msgPlayers = new HashMap<>();
evmsg = composeColor(sender, evmsg);
Text srcText = Text.builder(event.getMessage(), evmsg).build();
if (event.getChannel() != null) {
UCChannel ch = event.getChannel();
if (sender instanceof Player && !ch.availableWorlds().isEmpty() && !ch.availableInWorld(((Player) sender).getWorld())) {
UChat.get().getLang().sendMessage(sender, UChat.get().getLang().get("channel.notavailable").replace("{channel}", ch.getName()));
return null;
}
if (!UChat.get().getPerms().channelWritePerm(sender, ch)) {
UChat.get().getLang().sendMessage(sender, UChat.get().getLang().get("channel.nopermission").replace("{channel}", ch.getName()));
return null;
}
if (!UChat.get().getPerms().hasPerm(sender, "bypass.cost") && UChat.get().getEco() != null && sender instanceof Player && ch.getCost() > 0) {
UniqueAccount acc = UChat.get().getEco().getOrCreateAccount(((Player) sender).getUniqueId()).get();
if (acc.getBalance(UChat.get().getEco().getDefaultCurrency()).doubleValue() < ch.getCost()) {
sender.sendMessage(UCUtil.toText(UChat.get().getLang().get("channel.cost").replace("{value}", "" + ch.getCost())));
return null;
} else {
acc.withdraw(UChat.get().getEco().getDefaultCurrency(), BigDecimal.valueOf(ch.getCost()), UChat.get().getVHelper().getCause(UChat.get().instance()));
}
}
int noWorldReceived = 0;
int vanish = 0;
List<Player> receivers = new ArrayList<>();
// put sender
msgPlayers.put(sender, sendMessage(sender, sender, srcText, ch, false));
msgCh.addMember(sender);
if (ch.getDistance() > 0 && sender instanceof Player) {
for (Player play : ((Player) sender).getNearbyEntities(ch.getDistance()).stream().filter(ent -> ent instanceof Player).map(p -> (Player) p).collect(Collectors.toList())) {
if (UChat.get().getPerms().channelReadPerm(play, ch)) {
if (sender.equals(play)) {
continue;
}
if (!ch.availableWorlds().isEmpty() && !ch.availableInWorld(play.getWorld())) {
continue;
}
if (ch.isIgnoring(play.getName())) {
continue;
}
if (isIgnoringPlayers(play.getName(), sender.getName())) {
noWorldReceived++;
continue;
}
if (!((Player) sender).canSee(play)) {
vanish++;
}
if (!ch.neeFocus() || ch.isMember(play)) {
msgPlayers.put(play, sendMessage(sender, play, srcText, ch, false));
receivers.add(play);
msgCh.addMember(play);
}
}
}
} else {
for (Player receiver : Sponge.getServer().getOnlinePlayers()) {
if (receiver.equals(sender) || !UChat.get().getPerms().channelReadPerm(receiver, ch) || (!ch.crossWorlds() && (sender instanceof Player && !receiver.getWorld().equals(((Player) sender).getWorld())))) {
continue;
}
if (!ch.availableWorlds().isEmpty() && !ch.availableInWorld(receiver.getWorld())) {
continue;
}
if (ch.isIgnoring(receiver.getName())) {
continue;
}
if (isIgnoringPlayers(receiver.getName(), sender.getName())) {
noWorldReceived++;
continue;
}
if (sender instanceof Player && !((Player) sender).canSee(receiver)) {
vanish++;
} else {
noWorldReceived++;
}
if (!ch.neeFocus() || ch.isMember(receiver)) {
msgPlayers.put(receiver, sendMessage(sender, receiver, srcText, ch, false));
receivers.add(receiver);
msgCh.addMember(receiver);
}
}
}
// chat spy
if (!sender.hasPermission("uchat.chat-spy.bypass")) {
for (Player receiver : Sponge.getServer().getOnlinePlayers()) {
if (!receiver.equals(sender) && !receivers.contains(receiver) && !receivers.contains(sender) && UChat.get().isSpy.contains(receiver.getName()) && UChat.get().getPerms().hasSpyPerm(receiver, ch.getName())) {
String spyformat = UChat.get().getConfig().root().general.spy_format;
spyformat = spyformat.replace("{output}", UCUtil.stripColor(sendMessage(sender, receiver, srcText, ch, true).toPlain()));
receiver.sendMessage(UCUtil.toText(spyformat));
}
}
}
if (ch.getDistance() == 0 && noWorldReceived <= 0) {
if (ch.getReceiversMsg()) {
UChat.get().getLang().sendMessage(sender, "channel.noplayer.world");
}
}
if ((receivers.size() - vanish) <= 0) {
if (ch.getReceiversMsg()) {
UChat.get().getLang().sendMessage(sender, "channel.noplayer.near");
}
}
} else {
if (UChat.get().msgTogglePlayers.contains(tellReceiver.getName()) && !sender.hasPermission("uchat.msgtoggle.exempt")) {
UChat.get().getLang().sendMessage(sender, "cmd.msgtoggle.msgdisabled");
return null;
}
channel = new UCChannel("tell");
// send spy
if (!sender.hasPermission("uchat.chat-spy.bypass")) {
for (Player receiver : Sponge.getServer().getOnlinePlayers()) {
if (!receiver.equals(tellReceiver) && !receiver.equals(sender) && UChat.get().isSpy.contains(receiver.getName()) && UChat.get().getPerms().hasSpyPerm(receiver, "private")) {
String spyformat = UChat.get().getConfig().root().general.spy_format;
if (isIgnoringPlayers(tellReceiver.getName(), sender.getName())) {
spyformat = UChat.get().getLang().get("chat.ignored") + spyformat;
}
spyformat = spyformat.replace("{output}", UCUtil.stripColor(sendMessage(sender, tellReceiver, srcText, channel, true).toPlain()));
receiver.sendMessage(UCUtil.toText(spyformat));
}
}
}
Text to = sendMessage(sender, tellReceiver, srcText, channel, false);
msgPlayers.put(tellReceiver, to);
msgPlayers.put(sender, to);
if (isIgnoringPlayers(tellReceiver.getName(), sender.getName())) {
to = Text.of(UCUtil.toText(UChat.get().getLang().get("chat.ignored")), to);
}
msgPlayers.put(Sponge.getServer().getConsole(), to);
}
if (!msgPlayers.keySet().contains(Sponge.getServer().getConsole())) {
msgPlayers.put(Sponge.getServer().getConsole(), msgPlayers.values().stream().findAny().get());
}
PostFormatChatMessageEvent postEvent = new PostFormatChatMessageEvent(sender, msgPlayers, channel);
Sponge.getEventManager().post(postEvent);
if (postEvent.isCancelled()) {
return null;
}
msgPlayers.forEach((send, text) -> {
UChat.get().getLogger().timings(timingType.END, "UCMessages#send()|before send");
send.sendMessage(text);
UChat.get().getLogger().timings(timingType.END, "UCMessages#send()|after send");
});
// send to jedis
if (channel != null && !channel.isTell() && UChat.get().getJedis() != null) {
UChat.get().getJedis().sendMessage(channel.getName().toLowerCase(), msgPlayers.get(sender));
}
// send to jda
if (channel != null && UChat.get().getUCJDA() != null) {
if (channel.isTell()) {
UChat.get().getUCJDA().sendTellToDiscord(msgPlayers.get(sender).toPlain());
} else {
UChat.get().getUCJDA().sendToDiscord(sender, evmsg, channel);
}
}
return msgCh;
}
use of br.net.fabiozumbi12.UltimateChat.Bukkit.UCChannel in project UltimateChat by FabioZumbi12.
the class UCConfig method loadChannels.
private void loadChannels() throws IOException {
File chfolder = new File(UChat.get().configDir(), "channels");
if (!chfolder.exists()) {
chfolder.mkdir();
UChat.get().getLogger().info("Created folder: " + chfolder.getPath());
}
if (UChat.get().getChannels() == null) {
UChat.get().setChannels(new HashMap<>());
}
File[] listOfFiles = chfolder.listFiles();
CommentedConfigurationNode channel;
ConfigurationLoader<CommentedConfigurationNode> channelManager;
if (listOfFiles.length == 0) {
// create default channels
File g = new File(chfolder, "global.conf");
channelManager = HoconConfigurationLoader.builder().setFile(g).build();
channel = channelManager.load();
channel.getNode("name").setValue("Global");
channel.getNode("alias").setValue("g");
channel.getNode("color").setValue("&2");
channel.getNode("jedis").setValue(true);
channelManager.save(channel);
File l = new File(chfolder, "local.conf");
channelManager = HoconConfigurationLoader.builder().setFile(l).build();
channel = channelManager.load();
channel.getNode("name").setValue("Local");
channel.getNode("alias").setValue("l");
channel.getNode("across-worlds").setValue(false);
channel.getNode("distance").setValue(40);
channel.getNode("color").setValue("&e");
channelManager.save(channel);
File ad = new File(chfolder, "admin.conf");
channelManager = HoconConfigurationLoader.builder().setFile(ad).build();
channel = channelManager.load();
channel.getNode("name").setValue("Admin");
channel.getNode("alias").setValue("ad");
channel.getNode("color").setValue("&b");
channel.getNode("jedis").setValue(true);
channelManager.save(channel);
listOfFiles = chfolder.listFiles();
}
for (File file : listOfFiles) {
if (file.getName().endsWith(".conf")) {
channelManager = HoconConfigurationLoader.builder().setFile(file).build();
channel = channelManager.load();
Map<String, Object> chProps = new HashMap<>();
channel.getChildrenMap().forEach((key, value) -> {
if (value.hasMapChildren()) {
String rkey = key.toString();
for (Entry<Object, ? extends CommentedConfigurationNode> vl : value.getChildrenMap().entrySet()) {
chProps.put(rkey + "." + vl.getKey(), vl.getValue().getValue());
}
} else {
chProps.put(key.toString(), value.getValue());
}
});
UCChannel ch = new UCChannel(chProps);
addChannel(ch);
}
}
}
Aggregations