mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-03 14:38:51 +00:00
Fix various issues
This commit is contained in:
1 parent
22a068ff09
commit
6b36c330ee
7 files changed
+46
-31
No files matched your search
@@ -53,6 +53,8 @@ public abstract class ChatChannel implements ForwardingAudience {
|
|||||||
|
|
||||||
public abstract String getSwitchOtherMessage();
|
public abstract String getSwitchOtherMessage();
|
||||||
|
|
||||||
|
public abstract String getSwitchFailureMessage();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The message to be send to the player when toggling this channel off.
|
* @return The message to be send to the player when toggling this channel off.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -333,6 +333,11 @@ public class CarbonChatChannel extends ChatChannel {
|
|||||||
return getString("switch-other-message");
|
return getString("switch-other-message");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSwitchFailureMessage() {
|
||||||
|
return getString("switch-failure-message");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getToggleOffMessage() {
|
public String getToggleOffMessage() {
|
||||||
return getString("toggle-off-message");
|
return getString("toggle-off-message");
|
||||||
|
|||||||
@@ -18,6 +18,10 @@ public class PingHandler implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void onPing(ChatComponentEvent event) {
|
public void onPing(ChatComponentEvent event) {
|
||||||
|
if (event.getTarget() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (event.getSender().getUUID().equals(event.getTarget().getUUID())) {
|
if (event.getSender().getUUID().equals(event.getTarget().getUUID())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,7 +104,8 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setSelectedChannel(ChatChannel chatChannel, boolean fromRemote) {
|
public void setSelectedChannel(ChatChannel chatChannel, boolean fromRemote) {
|
||||||
String failureMessage = carbonChat.getConfig().getString("language.channel-switch-failure");
|
String failureMessage = chatChannel.getSwitchFailureMessage();
|
||||||
|
|
||||||
ChannelSwitchEvent event = new ChannelSwitchEvent(chatChannel, this, failureMessage);
|
ChannelSwitchEvent event = new ChannelSwitchEvent(chatChannel, this, failureMessage);
|
||||||
|
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ default:
|
|||||||
# switch-message, toggle-off-message and toggle-on-message support PlaceholderAPI
|
# switch-message, toggle-off-message and toggle-on-message support PlaceholderAPI
|
||||||
switch-message: '<gray>You are now in <color><channel> <gray>chat!'
|
switch-message: '<gray>You are now in <color><channel> <gray>chat!'
|
||||||
switch-other-message: '<gray><player> </rainbow><gray>is now in <color><channel> <gray>chat!'
|
switch-other-message: '<gray><player> </rainbow><gray>is now in <color><channel> <gray>chat!'
|
||||||
|
switch-failure-message: '<red>You cannot use channel <channel>!'
|
||||||
toggle-on-message: '<gray>You can now see <color><channel> <gray>chat!'
|
toggle-on-message: '<gray>You can now see <color><channel> <gray>chat!'
|
||||||
toggle-off-message: '<gray>You can no longer see <color><channel> <gray>chat!'
|
toggle-off-message: '<gray>You can no longer see <color><channel> <gray>chat!'
|
||||||
toggle-other-on: '<gray><player> </rainbow><gray>can now see <color><channel> <gray>chat!'
|
toggle-other-on: '<gray><player> </rainbow><gray>can now see <color><channel> <gray>chat!'
|
||||||
@@ -85,7 +86,6 @@ language:
|
|||||||
spy-whispers: '<yellow>Spy [<gray><sender></rainbow> <gold>-> <gray><target></rainbow><yellow>] <message>'
|
spy-whispers: '<yellow>Spy [<gray><sender></rainbow> <gold>-> <gray><target></rainbow><yellow>] <message>'
|
||||||
no-reply-target: '<red>You have no one to reply to!'
|
no-reply-target: '<red>You have no one to reply to!'
|
||||||
empty-channel: 'NONE' #<channel>, set to "NONE" to disable
|
empty-channel: 'NONE' #<channel>, set to "NONE" to disable
|
||||||
channel-switch-failure: '<red>You cannot use channel <channel>!'
|
|
||||||
other-nickname-set: '<green><user></rainbow>''s nickname was set to <nickname><green>!'
|
other-nickname-set: '<green><user></rainbow>''s nickname was set to <nickname><green>!'
|
||||||
other-nickname-reset: '<green><user></rainbow>''s nickname was reset!'
|
other-nickname-reset: '<green><user></rainbow>''s nickname was reset!'
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ public final class CarbonChatMCMMO extends JavaPlugin implements Listener {
|
|||||||
if ((party instanceof Boolean) && ((Boolean) party)) {
|
if ((party instanceof Boolean) && ((Boolean) party)) {
|
||||||
if (!isInParty(event.getUser())) {
|
if (!isInParty(event.getUser())) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
event.setFailureMessage(getConfig().getString("cancellation-message"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+32
-28
@@ -29,29 +29,7 @@ public final class CarbonChatWorldGuard extends JavaPlugin implements Listener {
|
|||||||
CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||||
|
|
||||||
carbonChat.getContextManager().register(KEY, (context) -> {
|
carbonChat.getContextManager().register(KEY, (context) -> {
|
||||||
if ((context.getValue() instanceof Boolean) && ((Boolean) context.getValue())) {
|
return this.testContext(context.getSender(), context.getTarget(), context.getValue());
|
||||||
return isInSameRegion(context.getSender(), context.getTarget());
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean user1InRegion = false;
|
|
||||||
boolean user2InRegion = false;
|
|
||||||
|
|
||||||
if (context.getValue() instanceof String) {
|
|
||||||
user1InRegion = isInRegion((String)context.getValue(), context.getSender());
|
|
||||||
user2InRegion = isInRegion((String)context.getValue(), context.getTarget());
|
|
||||||
} else if (context.getValue() instanceof List) {
|
|
||||||
for (String item : (List<String>) context.getValue()) {
|
|
||||||
if (!user1InRegion) {
|
|
||||||
user1InRegion = isInRegion(item, context.getSender());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!user2InRegion) {
|
|
||||||
user2InRegion = isInRegion(item, context.getTarget());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return user1InRegion && user2InRegion;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Bukkit.getPluginManager().registerEvents(this, this);
|
Bukkit.getPluginManager().registerEvents(this, this);
|
||||||
@@ -59,21 +37,21 @@ public final class CarbonChatWorldGuard extends JavaPlugin implements Listener {
|
|||||||
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
@EventHandler(ignoreCancelled = true)
|
||||||
public void onChannelSwitch(ChannelSwitchEvent event) {
|
public void onChannelSwitch(ChannelSwitchEvent event) {
|
||||||
|
// TODO: cancellation message
|
||||||
Object value = event.getChannel().getContext(KEY);
|
Object value = event.getChannel().getContext(KEY);
|
||||||
|
|
||||||
if (!isInRegionOrRegions(value, event.getUser())) {
|
if ((value instanceof String || value instanceof List) && !isInRegionOrRegions(value, event.getUser())) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
// TODO: placeholders (regions, etc)
|
|
||||||
event.setFailureMessage(getConfig().getString("cancellation-message"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
@EventHandler(ignoreCancelled = true)
|
||||||
public void onChannelMessage(PreChatFormatEvent event) {
|
public void onChannelMessage(PreChatFormatEvent event) {
|
||||||
|
// TODO: cancellation message
|
||||||
Object value = event.getChannel().getContext(KEY);
|
Object value = event.getChannel().getContext(KEY);
|
||||||
|
|
||||||
if (!isInRegionOrRegions(value, event.getUser())) {
|
if ((value instanceof String || value instanceof List) && !isInRegionOrRegions(value, event.getUser())) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,6 +71,32 @@ public final class CarbonChatWorldGuard extends JavaPlugin implements Listener {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean testContext(ChatUser sender, ChatUser target, Object value) {
|
||||||
|
boolean user1InRegion = false;
|
||||||
|
boolean user2InRegion = false;
|
||||||
|
|
||||||
|
if ((value instanceof Boolean) && ((Boolean) value)) {
|
||||||
|
return isInSameRegion(sender, target);
|
||||||
|
} else if (value instanceof String) {
|
||||||
|
user1InRegion = isInRegion((String)value, sender);
|
||||||
|
user2InRegion = isInRegion((String)value, target);
|
||||||
|
} else if (value instanceof List) {
|
||||||
|
for (String item : (List<String>)value) {
|
||||||
|
if (!user1InRegion) {
|
||||||
|
user1InRegion = isInRegion(item, sender);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!user2InRegion) {
|
||||||
|
user2InRegion = isInRegion(item, target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return user1InRegion && user2InRegion;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isInSameRegion(ChatUser user1, ChatUser user2) {
|
public boolean isInSameRegion(ChatUser user1, ChatUser user2) {
|
||||||
if (!user1.isOnline() || !user2.isOnline()) {
|
if (!user1.isOnline() || !user2.isOnline()) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in new issue
Block a user