use of br.net.fabiozumbi12.UltimateChat.Bukkit.UCChannel in project UltimateChat by FabioZumbi12.
the class uChatAPI method registerNewChannel.
@Deprecated
public boolean registerNewChannel(String chName, String chAlias, boolean crossWorlds, int distance, String color, String tagBuilder, boolean needFocus, boolean receiverMsg, double cost, String ddmode, String ddmcformat, String mcddformat, String ddhover, boolean ddallowcmds, boolean bungee) throws IOException {
if (UChat.get().getChannel(chName) != null) {
return false;
}
if (tagBuilder == null || tagBuilder.equals("")) {
tagBuilder = UChat.get().getConfig().root().general.default_tag_builder;
}
UCChannel ch = new UCChannel(chName, chAlias, crossWorlds, distance, color, tagBuilder, needFocus, receiverMsg, cost, bungee, false, false, "player", "", new ArrayList<>(), "", ddmode, ddmcformat, mcddformat, ddhover, ddallowcmds, true);
UChat.get().getConfig().addChannel(ch);
UChat.get().reload();
return true;
}
use of br.net.fabiozumbi12.UltimateChat.Bukkit.UCChannel in project UltimateChat by FabioZumbi12.
the class uChatAPI method registerNewChannel.
@Deprecated
public boolean registerNewChannel(String chName, String chAlias, boolean crossWorlds, int distance, String color, String tagBuilder, boolean needFocus, boolean receiverMsg, double cost, String ddmode, String ddmcformat, String mcddformat, String ddhover, boolean ddallowcmds, boolean bungee) throws IOException {
if (UChat.get().getChannel(chName) != null) {
return false;
}
if (tagBuilder == null || tagBuilder.equals("")) {
tagBuilder = UChat.get().getUCConfig().getString("general.default-tag-builder");
}
UCChannel ch = new UCChannel(chName, chAlias, crossWorlds, distance, color, tagBuilder, needFocus, receiverMsg, cost, bungee, false, false, "player", "", new ArrayList<>(), "", ddmode, ddmcformat, mcddformat, ddhover, ddallowcmds, true);
UChat.get().getUCConfig().addChannel(ch);
UChat.get().reload();
return true;
}
use of br.net.fabiozumbi12.UltimateChat.Bukkit.UCChannel in project UltimateChat by FabioZumbi12.
the class ChatChannel method onMessage.
@Override
public void onMessage(String channel, String message) {
if (!UChat.get().getUCConfig().getBoolean("debug.messages") && message.split("\\$")[0].equals(this.thisId))
return;
if (Arrays.asList(channels).contains(channel)) {
Bukkit.getScheduler().runTaskAsynchronously(UChat.get(), () -> {
if (channel.equals("tellresponse")) {
String[] tellresp = message.split("@");
if (tellresp[0].equals(thisId))
return;
if (UChat.get().getJedis().tellPlayers.containsKey(tellresp[1])) {
Player sender = Bukkit.getPlayer(UChat.get().getJedis().tellPlayers.get(tellresp[1]));
if (sender != null && sender.isOnline()) {
if (tellresp[2].equals("false")) {
UChat.get().getLang().sendMessage(sender, UChat.get().getLang().get("listener.invalidplayer"));
} else {
UCUtil.performCommand(sender, Bukkit.getConsoleSender(), "tellraw " + sender.getName() + " " + tellresp[3]);
}
}
}
return;
}
if (channel.equals("tellsend")) {
String[] msgc = message.split("\\$");
String id = msgc[0];
String tellrec = msgc[1];
String messagef = msgc[2];
Player play = Bukkit.getPlayer(tellrec);
if (play == null) {
UChat.get().getJedis().getPool().getResource().publish("tellresponse", thisId + "@" + tellrec + "@false");
return;
} else {
UChat.get().getJedis().getPool().getResource().publish("tellresponse", thisId + "@" + tellrec + "@true@" + messagef.replace("@", ""));
}
UChat.get().getJedis().tellPlayers.remove(tellrec);
Bukkit.getConsoleSender().sendMessage(UCUtil.colorize("&7Private message from server " + id + " to player " + tellrec));
// send
UCUtil.performCommand(play, Bukkit.getConsoleSender(), "tellraw " + play.getName() + " " + messagef);
return;
}
if (!channel.equals("generic")) {
String[] msgc = message.split("\\$");
String id = msgc[0];
String messagef = msgc[1];
UCChannel ch = UChat.get().getChannel(channel);
if (ch == null || !ch.useJedis())
return;
if (ch.getDistance() == 0) {
if (ch.neeFocus()) {
for (String receiver : ch.getMembers()) {
if (Bukkit.getPlayer(receiver) != null) {
UCUtil.performCommand(Bukkit.getPlayer(receiver), Bukkit.getConsoleSender(), "tellraw " + receiver + " " + messagef);
}
}
} else {
for (Player receiver : Bukkit.getServer().getOnlinePlayers()) {
if (UCPerms.channelReadPerm(receiver, ch)) {
UCUtil.performCommand(receiver, Bukkit.getConsoleSender(), "tellraw " + receiver.getName() + " " + messagef);
}
}
}
}
Bukkit.getConsoleSender().sendMessage(UCUtil.colorize("&7Redis message to channel " + ch.getName() + " from: " + id));
} else {
String[] msgc = message.split("\\$");
String id = msgc[0];
String messagef = msgc[1];
for (Player receiver : Bukkit.getServer().getOnlinePlayers()) {
UCUtil.performCommand(receiver, Bukkit.getConsoleSender(), "tellraw " + receiver.getName() + " " + messagef);
}
Bukkit.getConsoleSender().sendMessage(UCUtil.colorize("&7Raw Message from: " + id));
}
});
}
}
use of br.net.fabiozumbi12.UltimateChat.Bukkit.UCChannel in project UltimateChat by FabioZumbi12.
the class ChatChannel method onMessage.
@Override
public void onMessage(String channel, final String message) {
if (!UChat.get().getConfig().root().debug.messages && message.split("\\$")[0].equals(this.thisId))
return;
if (Arrays.asList(channels).contains(channel)) {
Sponge.getScheduler().createAsyncExecutor(UChat.get()).execute(() -> {
if (channel.equals("tellresponse")) {
String[] tellresp = message.split("@");
if (tellresp[0].equals(thisId))
return;
if (UChat.get().getJedis().tellPlayers.containsKey(tellresp[1])) {
Optional<Player> sender = Sponge.getServer().getPlayer(UChat.get().getJedis().tellPlayers.get(tellresp[1]));
if (sender.isPresent() && sender.get().isOnline()) {
if (tellresp[2].equals("false")) {
UChat.get().getLang().sendMessage(sender.get(), UChat.get().getLang().get("listener.invalidplayer"));
} else {
Sponge.getScheduler().createSyncExecutor(UChat.get()).execute(() -> Sponge.getCommandManager().process(Sponge.getServer().getConsole(), "tellraw " + sender.get().getName() + " " + tellresp[3]));
}
}
}
return;
}
if (channel.equals("tellsend")) {
String[] msgc = message.split("\\$");
String id = msgc[0];
String tellrec = msgc[1];
String messagef = msgc[2];
Optional<Player> play = Sponge.getServer().getPlayer(tellrec);
if (!play.isPresent()) {
UChat.get().getJedis().getPool().getResource().publish("tellresponse", thisId + "@" + tellrec + "@false");
return;
} else {
UChat.get().getJedis().getPool().getResource().publish("tellresponse", thisId + "@" + tellrec + "@true@" + messagef.replace("@", ""));
}
UChat.get().getJedis().tellPlayers.remove(tellrec);
Sponge.getServer().getConsole().sendMessage(UCUtil.toText("&7Private message from server " + id + " to player " + tellrec));
// send
Sponge.getScheduler().createSyncExecutor(UChat.get()).execute(() -> Sponge.getCommandManager().process(Sponge.getServer().getConsole(), "tellraw " + play.get().getName() + " " + messagef));
return;
}
if (!channel.equals("generic")) {
String[] msgc = message.split("\\$");
String id = msgc[0];
String messagef = msgc[1];
UCChannel ch = UChat.get().getChannel(channel);
if (ch == null || !ch.useJedis())
return;
if (ch.getDistance() == 0) {
if (ch.neeFocus()) {
for (String receiver : ch.getMembers()) {
Sponge.getScheduler().createSyncExecutor(UChat.get()).execute(() -> Sponge.getCommandManager().process(Sponge.getServer().getConsole(), "tellraw " + receiver + " " + messagef));
}
} else {
for (Player receiver : Sponge.getServer().getOnlinePlayers()) {
if (UChat.get().getPerms().channelReadPerm(receiver, ch)) {
Sponge.getScheduler().createSyncExecutor(UChat.get()).execute(() -> Sponge.getCommandManager().process(Sponge.getServer().getConsole(), "tellraw " + receiver.getName() + " " + messagef));
}
}
}
Sponge.getServer().getConsole().sendMessage(UCUtil.toText("&7Message to channel " + ch.getName() + " from: " + id));
}
} else {
String[] msgc = message.split("\\$");
String id = msgc[0];
String messagef = msgc[1];
for (Player receiver : Sponge.getServer().getOnlinePlayers()) {
Sponge.getScheduler().createSyncExecutor(UChat.get()).execute(() -> Sponge.getCommandManager().process(Sponge.getServer().getConsole(), "tellraw " + receiver.getName() + " " + messagef));
}
Sponge.getServer().getConsole().sendMessage(UCUtil.toText("&7Raw Message from: " + id));
}
});
}
}
use of br.net.fabiozumbi12.UltimateChat.Bukkit.UCChannel in project UltimateChat by FabioZumbi12.
the class UCCommands method registerChAliases.
private void registerChAliases() {
// register ch cmds aliases
for (String cmd : UChat.get().getConfig().getChCmd()) {
unregisterCmd(cmd);
manager.register(UChat.get().instance(), CommandSpec.builder().arguments(new ChannelCommandElement(Text.of("channel"))).description(Text.of("Join in a channel if you have permission.")).executor((src, args) -> {
{
if (src instanceof Player) {
Player p = (Player) src;
if (!args.<UCChannel>getOne("channel").isPresent()) {
throw new CommandException(getHelpChannel(src).build());
}
UCChannel ch = args.<UCChannel>getOne("channel").get();
if (!UChat.get().getPerms().channelReadPerm(p, ch) && !UChat.get().getPerms().channelWritePerm(p, ch)) {
throw new CommandException(UCUtil.toText(UChat.get().getLang().get("channel.nopermission").replace("{channel}", ch.getName())));
}
if (!ch.availableInWorld(p.getWorld())) {
UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("channel.notavailable").replace("{channel}", ch.getName()));
return CommandResult.success();
}
if (ch.isMember(p)) {
UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("channel.alreadyon").replace("{channel}", ch.getName()));
return CommandResult.success();
}
if (!ch.getPassword().isEmpty()) {
UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("channel.password").replace("{channel}", ch.getAlias()));
return CommandResult.success();
}
// fire event
PlayerChangeChannelEvent event = new PlayerChangeChannelEvent(p, UChat.get().getPlayerChannel(src), ch);
Sponge.getEventManager().post(event);
if (event.isCancelled()) {
return CommandResult.success();
}
ch.addMember(p);
UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("channel.entered").replace("{channel}", ch.getName()));
}
return CommandResult.success();
}
}).build(), cmd);
}
}
Aggregations