mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 14:38:48 +00:00
Fix cross world radius, log exceptions in event subscribers
This commit is contained in:
1 parent
b5c7b16f8d
commit
4a71b5926e
5 files changed
+23
-10
No files matched your search
@@ -25,6 +25,7 @@ import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.util.KeyedRenderer;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
@@ -128,7 +129,7 @@ public class CarbonChatEvent implements ResultedCarbonEvent<CarbonChatEvent.Resu
|
||||
* @return the chat channel
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public @Nullable ChatChannel chatChannel() {
|
||||
public @MonotonicNonNull ChatChannel chatChannel() {
|
||||
return this.chatChannel;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ public class ItemLinkHandler {
|
||||
public ItemLinkHandler(
|
||||
final CarbonChat carbonChat
|
||||
) {
|
||||
carbonChat.eventHandler().subscribe(CarbonChatEvent.class, 1, true, event -> {
|
||||
carbonChat.eventHandler().subscribe(CarbonChatEvent.class, 1, false, event -> {
|
||||
if (!event.sender().hasPermission("carbon.itemlink")) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,10 @@ public class RadiusListener {
|
||||
final CarbonChat carbonChat
|
||||
) {
|
||||
carbonChat.eventHandler().subscribe(CarbonChatEvent.class, 0, false, event -> {
|
||||
if (event.chatChannel() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final double radius = event.chatChannel().radius();
|
||||
|
||||
if (radius < 0) {
|
||||
@@ -59,9 +63,11 @@ public class RadiusListener {
|
||||
}
|
||||
|
||||
if (audience instanceof CarbonPlayer carbonPlayer) {
|
||||
final double distance = carbonPlayer.distanceSquaredFrom(event.sender());
|
||||
if (event.sender().sameWorldAs(carbonPlayer)) {
|
||||
final double distance = carbonPlayer.distanceSquaredFrom(event.sender());
|
||||
|
||||
return distance > (radius * radius);
|
||||
return distance > (radius * radius);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -33,7 +33,7 @@ tasks {
|
||||
relocateDependency("io.leangen.geantyref")
|
||||
}
|
||||
runServer {
|
||||
minecraftVersion("1.19")
|
||||
minecraftVersion("1.18.2")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ bukkit {
|
||||
name = rootProject.name
|
||||
version = project.version as String
|
||||
main = "net.draycia.carbon.paper.CarbonChatPaper"
|
||||
apiVersion = "1.19"
|
||||
apiVersion = "1.18"
|
||||
author = "Draycia"
|
||||
depend = listOf("LuckPerms")
|
||||
softDepend = listOf("PlaceholderAPI", "EssentialsDiscord", "DiscordSRV")
|
||||
|
||||
@@ -22,6 +22,7 @@ package net.draycia.carbon.paper.listeners;
|
||||
import com.google.inject.Inject;
|
||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.channels.ChannelRegistry;
|
||||
@@ -37,6 +38,7 @@ import net.kyori.adventure.identity.Identity;
|
||||
import net.kyori.adventure.text.TextReplacementConfig;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import net.kyori.event.EventSubscriber;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@@ -113,6 +115,10 @@ public final class PaperChatListener implements Listener {
|
||||
final var result = this.carbonChat.eventHandler().emit(chatEvent);
|
||||
|
||||
if (!result.wasSuccessful()) {
|
||||
for (final Map.Entry<EventSubscriber<?>, Throwable> entry : result.exceptions().entrySet()) {
|
||||
this.carbonChat.logger().error(entry.getValue());
|
||||
}
|
||||
|
||||
final var message = chatEvent.result().reason();
|
||||
|
||||
if (!message.equals(empty())) {
|
||||
@@ -126,7 +132,7 @@ public final class PaperChatListener implements Listener {
|
||||
event.viewers().clear();
|
||||
event.setCancelled(true);
|
||||
} catch (final UnsupportedOperationException exception) {
|
||||
exception.printStackTrace();
|
||||
this.carbonChat.logger().error(exception);
|
||||
}
|
||||
|
||||
if (sender.hasPermission("carbon.hideidentity")) {
|
||||
@@ -153,7 +159,7 @@ public final class PaperChatListener implements Listener {
|
||||
try {
|
||||
event.viewers().addAll(chatEvent.recipients());
|
||||
} catch (final UnsupportedOperationException exception) {
|
||||
exception.printStackTrace();
|
||||
this.carbonChat.logger().error(exception);
|
||||
}
|
||||
|
||||
event.renderer((source, sourceDisplayName, message, viewer) -> {
|
||||
@@ -167,8 +173,8 @@ public final class PaperChatListener implements Listener {
|
||||
} else {
|
||||
renderedMessage = renderer.render(sender, viewer, renderedMessage.component(), message);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
} catch (final Exception exception) {
|
||||
this.carbonChat.logger().error(exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user