Update VentureChat to have distanceIsCube option to allow local chat to limit chat in the Y dimension.

This commit is contained in:
Joseph Warner 2020-06-22 02:28:03 -05:00
parent fc0b1ddcd1
commit 7a416257ad
7 changed files with 77 additions and 15 deletions

View File

@ -306,6 +306,7 @@ channels:
autojoin: true autojoin: true
default: true default: true
distance: 0 distance: 0
distanceIsCube: false
cooldown: 0 cooldown: 0
bungeecord: false bungeecord: false
alias: g alias: g
@ -319,6 +320,7 @@ channels:
autojoin: true autojoin: true
default: false default: false
distance: 0 distance: 0
distanceIsCube: false
cooldown: 0 cooldown: 0
bungeecord: false bungeecord: false
alias: st alias: st
@ -332,6 +334,7 @@ channels:
autojoin: true autojoin: true
default: false default: false
distance: 0 distance: 0
distanceIsCube: false
cooldown: 0 cooldown: 0
bungeecord: false bungeecord: false
alias: a alias: a
@ -345,6 +348,7 @@ channels:
autojoin: true autojoin: true
default: false default: false
distance: 0 distance: 0
distanceIsCube: false
cooldown: 0 cooldown: 0
bungeecord: false bungeecord: false
alias: d alias: d
@ -358,6 +362,7 @@ channels:
autojoin: true autojoin: true
default: false default: false
distance: 0 distance: 0
distanceIsCube: false
cooldown: 0 cooldown: 0
bungeecord: false bungeecord: false
alias: h alias: h
@ -371,6 +376,7 @@ channels:
autojoin: true autojoin: true
default: false default: false
distance: 0 distance: 0
distanceIsCube: false
cooldown: 0 cooldown: 0
bungeecord: false bungeecord: false
alias: t alias: t
@ -384,6 +390,7 @@ channels:
autojoin: true autojoin: true
default: false default: false
distance: 230 distance: 230
distanceIsCube: false
cooldown: 0 cooldown: 0
bungeecord: false bungeecord: false
alias: l alias: l
@ -397,6 +404,7 @@ channels:
autojoin: true autojoin: true
default: false default: false
distance: 0 distance: 0
distanceIsCube: false
cooldown: 60 cooldown: 60
bungeecord: true bungeecord: true
alias: n alias: n

View File

@ -304,6 +304,7 @@ channels:
autojoin: true autojoin: true
default: true default: true
distance: 0 distance: 0
distanceIsCube: false
cooldown: 0 cooldown: 0
bungeecord: false bungeecord: false
alias: g alias: g
@ -317,6 +318,7 @@ channels:
autojoin: true autojoin: true
default: false default: false
distance: 0 distance: 0
distanceIsCube: false
cooldown: 0 cooldown: 0
bungeecord: false bungeecord: false
alias: st alias: st
@ -330,6 +332,7 @@ channels:
autojoin: true autojoin: true
default: false default: false
distance: 0 distance: 0
distanceIsCube: false
cooldown: 0 cooldown: 0
bungeecord: false bungeecord: false
alias: a alias: a
@ -343,6 +346,7 @@ channels:
autojoin: true autojoin: true
default: false default: false
distance: 0 distance: 0
distanceIsCube: false
cooldown: 0 cooldown: 0
bungeecord: false bungeecord: false
alias: d alias: d
@ -356,6 +360,7 @@ channels:
autojoin: true autojoin: true
default: false default: false
distance: 0 distance: 0
distanceIsCube: false
cooldown: 0 cooldown: 0
bungeecord: false bungeecord: false
alias: h alias: h
@ -369,6 +374,7 @@ channels:
autojoin: true autojoin: true
default: false default: false
distance: 0 distance: 0
distanceIsCube: false
cooldown: 0 cooldown: 0
bungeecord: false bungeecord: false
alias: t alias: t
@ -382,6 +388,7 @@ channels:
autojoin: true autojoin: true
default: false default: false
distance: 230 distance: 230
distanceIsCube: false
cooldown: 0 cooldown: 0
bungeecord: false bungeecord: false
alias: l alias: l
@ -395,6 +402,7 @@ channels:
autojoin: true autojoin: true
default: false default: false
distance: 0 distance: 0
distanceIsCube: false
cooldown: 60 cooldown: 60
bungeecord: true bungeecord: true
alias: n alias: n

View File

@ -43,6 +43,8 @@ public class VentureChatPlaceholders extends PlaceholderHook {
return mcp.getCurrentChannel().getCooldown() + ""; return mcp.getCurrentChannel().getCooldown() + "";
case "channel_distance": case "channel_distance":
return mcp.getCurrentChannel().getDistance() + ""; return mcp.getCurrentChannel().getDistance() + "";
case "channel_distance_is_cube":
return mcp.getCurrentChannel().getDistanceIsCube() ? PlaceholderAPIPlugin.booleanTrue() : PlaceholderAPIPlugin.booleanFalse();
} }
} }
return null; return null;

View File

@ -20,6 +20,7 @@ public class ChatChannel {
private Boolean autojoin; private Boolean autojoin;
private String alias; private String alias;
private Double distance; private Double distance;
private Boolean distanceIsCube;
private Boolean filter; private Boolean filter;
private Boolean bungee; private Boolean bungee;
private String format; private String format;
@ -41,6 +42,7 @@ public class ChatChannel {
Boolean _defaultchannel = false; Boolean _defaultchannel = false;
String _alias = ""; String _alias = "";
Double _distance = (double) 0; Double _distance = (double) 0;
Boolean _distanceIsCube = false;
Boolean _autojoin = false; Boolean _autojoin = false;
Boolean _bungee = false; Boolean _bungee = false;
String _format = ""; String _format = "";
@ -69,9 +71,10 @@ public class ChatChannel {
_defaultchannel = (Boolean) cs.getBoolean(key + ".default", false); _defaultchannel = (Boolean) cs.getBoolean(key + ".default", false);
_alias = (String) cs.getString(key + ".alias", "None"); _alias = (String) cs.getString(key + ".alias", "None");
_distance = (Double) cs.getDouble(key + ".distance", (double) 0); _distance = (Double) cs.getDouble(key + ".distance", (double) 0);
_distanceIsCube = (Boolean) cs.getBoolean(key + ".distanceIsCube", false);
_cooldown = (int) cs.getInt(key + ".cooldown", 0); _cooldown = (int) cs.getInt(key + ".cooldown", 0);
_autojoin = (Boolean) cs.getBoolean(key + ".autojoin", false); _autojoin = (Boolean) cs.getBoolean(key + ".autojoin", false);
ChatChannel c = new ChatChannel(_name, _color, _chatcolor, _permission, _mutable, _filter, _defaultchannel, _alias, _distance, _autojoin, _bungee, _cooldown, _format); ChatChannel c = new ChatChannel(_name, _color, _chatcolor, _permission, _mutable, _filter, _defaultchannel, _alias, _distance, _distanceIsCube, _autojoin, _bungee, _cooldown, _format);
channels[x++] = c; channels[x++] = c;
if(_defaultchannel) { if(_defaultchannel) {
defaultChatChannel = c; defaultChatChannel = c;
@ -115,7 +118,7 @@ public class ChatChannel {
return joinlist; return joinlist;
} }
public ChatChannel(String _Name, String _color, String _chatcolor, String _Permission, Boolean _mutable, Boolean _filter, Boolean _defaultchannel, String _alias, Double _distance, Boolean _autojoin, Boolean _bungee, int _cooldown, String _format) { public ChatChannel(String _Name, String _color, String _chatcolor, String _Permission, Boolean _mutable, Boolean _filter, Boolean _defaultchannel, String _alias, Double _distance, Boolean _distanceIsCube, Boolean _autojoin, Boolean _bungee, int _cooldown, String _format) {
name = _Name; name = _Name;
permission = "venturechat." + _Permission; permission = "venturechat." + _Permission;
mutable = _mutable; mutable = _mutable;
@ -124,6 +127,7 @@ public class ChatChannel {
setDefaultChannel(_defaultchannel); setDefaultChannel(_defaultchannel);
setAlias(_alias); setAlias(_alias);
setDistance(_distance); setDistance(_distance);
setDistanceIsCube(_distanceIsCube);
setFilter(_filter); setFilter(_filter);
setAutojoin(_autojoin); setAutojoin(_autojoin);
setBungee(_bungee); setBungee(_bungee);
@ -215,6 +219,10 @@ public class ChatChannel {
this.distance = distance; this.distance = distance;
} }
public void setDistanceIsCube(Boolean distanceIsCube) { this.distanceIsCube = distanceIsCube; }
public Boolean getDistanceIsCube() { return distanceIsCube; }
public Boolean hasDistance() { public Boolean hasDistance() {
return distance > 0; return distance > 0;
} }

View File

@ -72,7 +72,7 @@ public class Chwho extends MineverseCommand {
} }
} }
if(channel.hasDistance() && sender instanceof Player) { if(channel.hasDistance() && sender instanceof Player) {
if(!this.isPlayerWithinDistance((Player) sender, p.getPlayer(), channel.getDistance())) { if(!this.isPlayerWithinDistance((Player) sender, p.getPlayer(), channel.getDistance(), channel.getDistanceIsCube())) {
continue; continue;
} }
} }
@ -203,8 +203,9 @@ public class Chwho extends MineverseCommand {
} }
} }
private boolean isPlayerWithinDistance(Player p1, Player p2, double Distance) { private boolean isPlayerWithinDistance(Player p1, Player p2, double Distance, boolean DistanceIsCube) {
Double chDistance = Distance; Double chDistance = Distance;
boolean chDistanceIsCube = DistanceIsCube;
Location locreceip; Location locreceip;
Location locsender = p1.getLocation(); Location locsender = p1.getLocation();
Location diff; Location diff;
@ -212,7 +213,7 @@ public class Chwho extends MineverseCommand {
locreceip = p2.getLocation(); locreceip = p2.getLocation();
if(locreceip.getWorld() == p1.getWorld()) { if(locreceip.getWorld() == p1.getWorld()) {
diff = locreceip.subtract(locsender); diff = locreceip.subtract(locsender);
if(Math.abs(diff.getX()) > chDistance || Math.abs(diff.getZ()) > chDistance) { if(Math.abs(diff.getX()) > chDistance || Math.abs(diff.getZ()) > chDistance || (chDistanceIsCube && Math.abs(diff.getY()) > chDistance)) {
return false; return false;
} }
} }

View File

@ -1049,6 +1049,38 @@ public class Config extends MineverseCommand {
break; break;
} }
} }
case "distanceIsCube": {
try {
switch(args[3]) {
case "true": {
plugin.getConfig().getConfigurationSection("channels." + args[1]).set("distanceIsCube", true);
sender.sendMessage(ChatColor.GREEN + "distanceIsCube: has been set to true");
plugin.saveConfig();
plugin.reloadConfig();
Bukkit.getPluginManager().disablePlugin(plugin);
Bukkit.getPluginManager().enablePlugin(plugin);
break;
}
case "false": {
plugin.getConfig().getConfigurationSection("channels." + args[1]).set("distanceIsCube", false);
sender.sendMessage(ChatColor.GREEN + "distanceIsCube: has been set to false");
plugin.saveConfig();
plugin.reloadConfig();
Bukkit.getPluginManager().disablePlugin(plugin);
Bukkit.getPluginManager().enablePlugin(plugin);
break;
}
default: {
sender.sendMessage(ChatColor.RED + "Invalid arguments, /config channels [channel] distanceIsCube [true/false]");
break;
}
}
}
catch(Exception e) {
sender.sendMessage(ChatColor.GREEN + "distanceIsCube: " + plugin.getConfig().getConfigurationSection("channels." + args[1]).getBoolean("distanceIsCube"));
}
break;
}
case "cooldown": { case "cooldown": {
try { try {
if(Integer.parseInt(args[3]) >= 0) { if(Integer.parseInt(args[3]) >= 0) {
@ -1125,13 +1157,13 @@ public class Config extends MineverseCommand {
} }
} }
default: { default: {
sender.sendMessage(ChatColor.RED + "Invalid arguments, /config channels " + args[1] + " [color, chatcolor, mutable, alias, default, autojoin, distance, cooldown, bungeecord, format]"); sender.sendMessage(ChatColor.RED + "Invalid arguments, /config channels " + args[1] + " [color, chatcolor, mutable, alias, default, autojoin, distance, distanceIsCube, cooldown, bungeecord, format]");
break; break;
} }
} }
} }
catch(Exception e) { catch(Exception e) {
sender.sendMessage(ChatColor.RED + "Invalid arguments, /config channels " + args[1] + " [color, chatcolor, mutable, alias, default, autojoin, distance, cooldown, bungeecord, format]"); sender.sendMessage(ChatColor.RED + "Invalid arguments, /config channels " + args[1] + " [color, chatcolor, mutable, alias, default, autojoin, distance, distanceIsCube, cooldown, bungeecord, format]");
} }
break; break;
} }
@ -1150,6 +1182,7 @@ public class Config extends MineverseCommand {
plugin.getConfig().getConfigurationSection("channels." + args[2]).set("default", false); plugin.getConfig().getConfigurationSection("channels." + args[2]).set("default", false);
plugin.getConfig().getConfigurationSection("channels." + args[2]).set("autojoin", true); plugin.getConfig().getConfigurationSection("channels." + args[2]).set("autojoin", true);
plugin.getConfig().getConfigurationSection("channels." + args[2]).set("distance", 0.0); plugin.getConfig().getConfigurationSection("channels." + args[2]).set("distance", 0.0);
plugin.getConfig().getConfigurationSection("channels." + args[2]).set("distanceIsCube", false);
plugin.getConfig().getConfigurationSection("channels." + args[2]).set("cooldown", 0); plugin.getConfig().getConfigurationSection("channels." + args[2]).set("cooldown", 0);
plugin.getConfig().getConfigurationSection("channels." + args[2]).set("bungeecord", false); plugin.getConfig().getConfigurationSection("channels." + args[2]).set("bungeecord", false);
plugin.getConfig().getConfigurationSection("channels." + args[2]).set("servername", false); plugin.getConfig().getConfigurationSection("channels." + args[2]).set("servername", false);
@ -1218,7 +1251,7 @@ public class Config extends MineverseCommand {
sender.sendMessage(ChatColor.GREEN + "/config broadcastafk [true/false]"); sender.sendMessage(ChatColor.GREEN + "/config broadcastafk [true/false]");
sender.sendMessage(ChatColor.GREEN + "/config formatcleaner [true/false]"); sender.sendMessage(ChatColor.GREEN + "/config formatcleaner [true/false]");
sender.sendMessage(ChatColor.GREEN + "/config broadcast [color, permissions, displaytag]"); sender.sendMessage(ChatColor.GREEN + "/config broadcast [color, permissions, displaytag]");
sender.sendMessage(ChatColor.GREEN + "/config channels [channel] [chatcolor, mutable, permissions, alias, default, autojoin, distance, cooldown, bungeecord, format, create , delete]"); sender.sendMessage(ChatColor.GREEN + "/config channels [channel] [chatcolor, mutable, permissions, alias, default, autojoin, distance, distanceIsCube, cooldown, bungeecord, format, create , delete]");
sender.sendMessage(ChatColor.GREEN + "/config help"); sender.sendMessage(ChatColor.GREEN + "/config help");
break; break;
} }

View File

@ -43,7 +43,7 @@ public class ChatListener implements Listener {
} }
// this event isn't always asynchronous even though the event's name starts with "Async" // this event isn't always asynchronous even though the event's name starts with "Async"
// blame md_5 for that one (_) // blame md_5 for that one (<EFBFBD>_<EFBFBD>)
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onAsyncPlayerChatEvent(AsyncPlayerChatEvent event) { public void onAsyncPlayerChatEvent(AsyncPlayerChatEvent event) {
event.setCancelled(true); event.setCancelled(true);
@ -90,16 +90,16 @@ public class ChatListener implements Listener {
mcp.setConversation(null); mcp.setConversation(null);
} }
else { else {
if(tp.getIgnores().contains(mcp.getUUID())) { if(tp.getIgnores().contains(mcp.getUUID())) {
mcp.getPlayer().sendMessage(LocalizedMessage.IGNORING_MESSAGE.toString() mcp.getPlayer().sendMessage(LocalizedMessage.IGNORING_MESSAGE.toString()
.replace("{player}", tp.getName())); .replace("{player}", tp.getName()));
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if(!tp.getMessageToggle()) { if(!tp.getMessageToggle()) {
mcp.getPlayer().sendMessage(LocalizedMessage.BLOCKING_MESSAGE.toString() mcp.getPlayer().sendMessage(LocalizedMessage.BLOCKING_MESSAGE.toString()
.replace("{player}", tp.getName())); .replace("{player}", tp.getName()));
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
String filtered = chat; String filtered = chat;
@ -234,6 +234,7 @@ public class ChatListener implements Listener {
return; return;
} }
Double chDistance = (double) 0; Double chDistance = (double) 0;
boolean chDistanceIsCube = false;
int chCooldown = 0; int chCooldown = 0;
String curColor = ""; String curColor = "";
if(eventChannel.hasPermission() && !mcp.getPlayer().hasPermission(eventChannel.getPermission())) { if(eventChannel.hasPermission() && !mcp.getPlayer().hasPermission(eventChannel.getPermission())) {
@ -321,6 +322,7 @@ public class ChatListener implements Listener {
if(eventChannel.hasDistance()) { if(eventChannel.hasDistance()) {
chDistance = eventChannel.getDistance(); chDistance = eventChannel.getDistance();
chDistanceIsCube = eventChannel.getDistanceIsCube();
} }
format = PlaceholderAPI.setBracketPlaceholders(mcp.getPlayer(), Format.FormatStringAll(plugin.getConfig().getConfigurationSection("channels." + eventChannel.getName()).getString("format"))); format = PlaceholderAPI.setBracketPlaceholders(mcp.getPlayer(), Format.FormatStringAll(plugin.getConfig().getConfigurationSection("channels." + eventChannel.getName()).getString("format")));
@ -422,7 +424,7 @@ public class ChatListener implements Listener {
locreceip = p.getPlayer().getLocation(); locreceip = p.getPlayer().getLocation();
if(locreceip.getWorld() == mcp.getPlayer().getWorld()) { if(locreceip.getWorld() == mcp.getPlayer().getWorld()) {
diff = locreceip.subtract(locsender); diff = locreceip.subtract(locsender);
if(Math.abs(diff.getX()) > chDistance || Math.abs(diff.getZ()) > chDistance) { if(Math.abs(diff.getX()) > chDistance || Math.abs(diff.getZ()) > chDistance || (chDistanceIsCube && Math.abs(diff.getY()) > chDistance)) {
recipients.remove(p.getPlayer()); recipients.remove(p.getPlayer());
recipientCount--; recipientCount--;
continue; continue;
@ -464,7 +466,7 @@ public class ChatListener implements Listener {
String globalJSON = Format.convertToJson(mcp, format, chat); String globalJSON = Format.convertToJson(mcp, format, chat);
String consoleChat = format + chat; String consoleChat = format + chat;
String message = consoleChat.replaceAll("(§([a-z0-9]))", ""); String message = consoleChat.replaceAll("(<EFBFBD>([a-z0-9]))", "");
int hash = message.hashCode(); int hash = message.hashCode();
//Create VentureChatEvent //Create VentureChatEvent