mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-02 14:38:49 +00:00
Add checkerframework compilation checking (#109)
* Reorder nullability annotations again * Add checker validation to API module * Add checker validation to Common module * Begin checker validation for Bukkit module * It compiles!
This commit is contained in:
1 parent
3314a51df8
commit
d9ab711adc
83 files changed
+1127
-717
No files matched your search
@@ -84,6 +84,7 @@ import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@SuppressWarnings("initialization.fields.uninitialized")
|
||||
public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
|
||||
private static final int BSTATS_PLUGIN_ID = 8720;
|
||||
@@ -215,6 +216,7 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
new WhisperPingHandler();
|
||||
}
|
||||
|
||||
@SuppressWarnings("return.type.incompatible")
|
||||
private void setupCommands() {
|
||||
try {
|
||||
this.commandManager = new PaperCommandManager<>(this,
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class DistanceContext {
|
||||
|
||||
private @NonNull static final String KEY = "distance";
|
||||
private final static @NonNull String KEY = "distance";
|
||||
|
||||
public DistanceContext() {
|
||||
CarbonEvents.register(ReceiverContextEvent.class, PostOrders.NORMAL, false, event -> {
|
||||
|
||||
+13
-4
@@ -9,16 +9,25 @@ import net.kyori.adventure.identity.Identity;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class EconomyContext {
|
||||
private @NonNull final CarbonChatBukkit carbonChat;
|
||||
private final @NonNull CarbonChatBukkit carbonChat;
|
||||
|
||||
private @NonNull final Economy economy;
|
||||
private final @NonNull Economy economy;
|
||||
|
||||
public EconomyContext(@NonNull final CarbonChatBukkit carbonChat) {
|
||||
public EconomyContext(final @NonNull CarbonChatBukkit carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
this.economy = this.carbonChat.getServer().getServicesManager().getRegistration(Economy.class).getProvider();
|
||||
|
||||
final RegisteredServiceProvider<Economy> provider =
|
||||
this.carbonChat.getServer().getServicesManager().getRegistration(Economy.class);
|
||||
|
||||
if (provider == null) {
|
||||
throw new IllegalArgumentException("Economy provider not found!");
|
||||
}
|
||||
|
||||
this.economy = provider.getProvider();
|
||||
|
||||
CarbonEvents.register(PreChatFormatEvent.class, event -> {
|
||||
if (!(event.channel() instanceof TextChannel)) {
|
||||
|
||||
+3
-3
@@ -12,9 +12,9 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class PAPIContext {
|
||||
|
||||
private @NonNull static final String KEY = "placeholder";
|
||||
private @NonNull static final String SENDER = "-sender";
|
||||
private @NonNull static final String RECEIVER = "-receiver";
|
||||
private final static @NonNull String KEY = "placeholder";
|
||||
private final static @NonNull String SENDER = "-sender";
|
||||
private final static @NonNull String RECEIVER = "-receiver";
|
||||
|
||||
public PAPIContext() {
|
||||
CarbonEvents.register(ReceiverContextEvent.class, PostOrders.NORMAL, false, event -> {
|
||||
|
||||
+9
-10
@@ -22,11 +22,11 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class TownyContext implements Listener {
|
||||
|
||||
private @NonNull static final String KEY = "towny-town";
|
||||
private final static @NonNull String KEY = "towny-town";
|
||||
|
||||
private @NonNull final CarbonChat carbonChat;
|
||||
private final @NonNull CarbonChat carbonChat;
|
||||
|
||||
public TownyContext(@NonNull final CarbonChat carbonChat) {
|
||||
public TownyContext(final @NonNull CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
CarbonEvents.register(ReceiverContextEvent.class, event -> {
|
||||
@@ -69,8 +69,7 @@ public final class TownyContext implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onResidentRemove(final TownRemoveResidentEvent event) {
|
||||
final String name = event.getResident().getName();
|
||||
final PlayerUser user = this.carbonChat.userService().wrap(Bukkit.getPlayer(name).getUniqueId());
|
||||
final PlayerUser user = this.carbonChat.userService().wrap(event.getResident().getUUID());
|
||||
final ChatChannel channel = user.selectedChannel();
|
||||
|
||||
if (!(channel instanceof TextChannel)) {
|
||||
@@ -102,9 +101,9 @@ public final class TownyContext implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isInTown(@NonNull final PlayerUser user) {
|
||||
public boolean isInTown(final @NonNull PlayerUser user) {
|
||||
try {
|
||||
return TownyAPI.getInstance().getDataSource().getResident(Bukkit.getPlayer(user.uuid()).getName()).hasTown();
|
||||
return TownyAPI.getInstance().getDataSource().getResident(user.name()).hasTown();
|
||||
} catch (final NotRegisteredException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
@@ -112,16 +111,16 @@ public final class TownyContext implements Listener {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isInSameTown(@NonNull final PlayerUser user1, @NonNull final PlayerUser user2) {
|
||||
public boolean isInSameTown(final @NonNull PlayerUser user1, final @NonNull PlayerUser user2) {
|
||||
if (Bukkit.getPlayer(user1.uuid()) == null || Bukkit.getPlayer(user2.uuid()) == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
final Resident resident = TownyAPI.getInstance().getDataSource().getResident(Bukkit.getPlayer(user1.uuid()).getName());
|
||||
final Resident resident = TownyAPI.getInstance().getDataSource().getResident(user1.name());
|
||||
|
||||
if (resident.hasTown()) {
|
||||
return resident.getTown().hasResident(Bukkit.getPlayer(user2.uuid()).getName());
|
||||
return resident.getTown().hasResident(user2.name());
|
||||
}
|
||||
} catch (final NotRegisteredException exception) {
|
||||
exception.printStackTrace();
|
||||
|
||||
+25
-8
@@ -5,6 +5,7 @@ import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import com.sk89q.worldguard.protection.regions.RegionContainer;
|
||||
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
||||
@@ -18,7 +19,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class WorldGuardContext {
|
||||
|
||||
private @NonNull static final String KEY = "worldguard-region";
|
||||
private final static @NonNull String KEY = "worldguard-region";
|
||||
|
||||
public WorldGuardContext() {
|
||||
CarbonEvents.register(ReceiverContextEvent.class, event -> {
|
||||
@@ -29,7 +30,13 @@ public final class WorldGuardContext {
|
||||
return;
|
||||
}
|
||||
|
||||
event.cancelled(this.testContext(senderPlayer, recipientPlayer, event.context(KEY)));
|
||||
final Context context = event.context(KEY);
|
||||
|
||||
if (context == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.cancelled(this.testContext(senderPlayer, recipientPlayer, context));
|
||||
});
|
||||
|
||||
CarbonEvents.register(MessageContextEvent.class, event -> {
|
||||
@@ -46,7 +53,7 @@ public final class WorldGuardContext {
|
||||
});
|
||||
}
|
||||
|
||||
private boolean isInRegionOrRegions(@NonNull final Context context, @NonNull final Player player) {
|
||||
private boolean isInRegionOrRegions(final @NonNull Context context, final @NonNull Player player) {
|
||||
if (context.isString()) {
|
||||
return this.isInRegion(context.asString(), player);
|
||||
}
|
||||
@@ -62,7 +69,7 @@ public final class WorldGuardContext {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean testContext(@NonNull final Player sender, @NonNull final Player target, @NonNull final Context context) {
|
||||
public boolean testContext(final @NonNull Player sender, final @NonNull Player target, final @NonNull Context context) {
|
||||
boolean user1InRegion = false;
|
||||
boolean user2InRegion = false;
|
||||
|
||||
@@ -88,7 +95,7 @@ public final class WorldGuardContext {
|
||||
return user1InRegion && user2InRegion;
|
||||
}
|
||||
|
||||
public boolean isInSameRegion(@NonNull final Player user1, @NonNull final Player user2) {
|
||||
public boolean isInSameRegion(final @NonNull Player user1, final @NonNull Player user2) {
|
||||
final Location user1Location = BukkitAdapter.adapt(user1.getLocation());
|
||||
final Location user2Location = BukkitAdapter.adapt(user2.getLocation());
|
||||
|
||||
@@ -107,15 +114,25 @@ public final class WorldGuardContext {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isInRegion(@NonNull final String region, @NonNull final Player player) {
|
||||
public boolean isInRegion(final @NonNull String region, final @NonNull Player player) {
|
||||
final RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||
final World world = BukkitAdapter.adapt(player.getWorld());
|
||||
final ProtectedRegion protection = container.get(world).getRegion(region);
|
||||
final RegionManager regionManager = container.get(world);
|
||||
|
||||
if (regionManager == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final ProtectedRegion protection = regionManager.getRegion(region);
|
||||
|
||||
if (protection == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.isInRegion(protection, player);
|
||||
}
|
||||
|
||||
public boolean isInRegion(@NonNull final ProtectedRegion region, @NonNull final Player player) {
|
||||
public boolean isInRegion(final @NonNull ProtectedRegion region, final @NonNull Player player) {
|
||||
final org.bukkit.Location location = player.getLocation();
|
||||
|
||||
return region.contains(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
|
||||
+18
-9
@@ -21,11 +21,11 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class mcMMOContext implements Listener {
|
||||
|
||||
private @NonNull final CarbonChat carbonChat;
|
||||
private final @NonNull CarbonChat carbonChat;
|
||||
|
||||
private @NonNull static final String KEY = "mcmmo-party";
|
||||
private final static @NonNull String KEY = "mcmmo-party";
|
||||
|
||||
public mcMMOContext(@NonNull final CarbonChat carbonChat) {
|
||||
public mcMMOContext(final @NonNull CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
CarbonEvents.register(ReceiverContextEvent.class, PostOrders.NORMAL, false, event -> {
|
||||
@@ -97,16 +97,25 @@ public final class mcMMOContext implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isInParty(@NonNull final PlayerUser user) {
|
||||
return PartyAPI.inParty(Bukkit.getPlayer(user.uuid()));
|
||||
}
|
||||
public boolean isInParty(final @NonNull PlayerUser user) {
|
||||
final Player player = Bukkit.getPlayer(user.uuid());
|
||||
|
||||
public boolean isInSameParty(@NonNull final PlayerUser user1, @NonNull final PlayerUser user2) {
|
||||
if (Bukkit.getPlayer(user1.uuid()) == null || Bukkit.getPlayer(user2.uuid()) == null) {
|
||||
if (player == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return PartyAPI.inSameParty(Bukkit.getPlayer(user1.uuid()), Bukkit.getPlayer(user2.uuid()));
|
||||
return PartyAPI.inParty(player);
|
||||
}
|
||||
|
||||
public boolean isInSameParty(final @NonNull PlayerUser user1, final @NonNull PlayerUser user2) {
|
||||
final Player player1 = Bukkit.getPlayer(user1.uuid());
|
||||
final Player player2 = Bukkit.getPlayer(user2.uuid());
|
||||
|
||||
if (player1 == null || player2 == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return PartyAPI.inSameParty(player1, player2);
|
||||
}
|
||||
|
||||
}
|
||||
+7
-10
@@ -23,23 +23,19 @@ import java.util.Map;
|
||||
|
||||
public class BukkitChatListener implements Listener {
|
||||
|
||||
private @NonNull final CarbonChatBukkit carbonChat;
|
||||
private final @NonNull CarbonChatBukkit carbonChat;
|
||||
|
||||
public BukkitChatListener(@NonNull final CarbonChatBukkit carbonChat) {
|
||||
public BukkitChatListener(final @NonNull CarbonChatBukkit carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
}
|
||||
|
||||
// Chat messages
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerchat(@NonNull final AsyncPlayerChatEvent event) {
|
||||
public void onPlayerChat(final @NonNull AsyncPlayerChatEvent event) {
|
||||
final PlayerUser user = this.carbonChat.userService().wrap(event.getPlayer().getUniqueId());
|
||||
ChatChannel channel = user.selectedChannel();
|
||||
|
||||
if (channel == null) {
|
||||
if (this.carbonChat.channelRegistry().defaultValue() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
channel = this.carbonChat.channelRegistry().defaultValue();
|
||||
}
|
||||
|
||||
@@ -53,14 +49,15 @@ public class BukkitChatListener implements Listener {
|
||||
}
|
||||
|
||||
final TextChannel textChannel = (TextChannel) entry;
|
||||
final String prefix = textChannel.messagePrefix();
|
||||
|
||||
if (textChannel.messagePrefix() == null || textChannel.messagePrefix().isEmpty()) {
|
||||
if (prefix == null || prefix.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (event.getMessage().startsWith(textChannel.messagePrefix())) {
|
||||
if (event.getMessage().startsWith(prefix)) {
|
||||
if (entry.canPlayerUse(user)) {
|
||||
event.setMessage(event.getMessage().substring(textChannel.messagePrefix().length()));
|
||||
event.setMessage(event.getMessage().substring(prefix.length()));
|
||||
channel = entry;
|
||||
break;
|
||||
}
|
||||
|
||||
+5
-2
@@ -3,6 +3,7 @@ package net.draycia.carbon.bukkit.listeners.events;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import net.draycia.carbon.api.events.misc.CarbonEvents;
|
||||
import net.draycia.carbon.api.events.ChatFormatEvent;
|
||||
import net.draycia.carbon.api.users.PlayerUser;
|
||||
import net.kyori.event.PostOrders;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -11,12 +12,14 @@ public class RelationalPlaceholderHandler {
|
||||
|
||||
public RelationalPlaceholderHandler() {
|
||||
CarbonEvents.register(ChatFormatEvent.class, PostOrders.FIRST, false, event -> {
|
||||
if (event.target() == null) {
|
||||
final PlayerUser targetUser = event.target();
|
||||
|
||||
if (targetUser == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Player sender = Bukkit.getPlayer(event.sender().uuid());
|
||||
final Player target = Bukkit.getPlayer(event.target().uuid());
|
||||
final Player target = Bukkit.getPlayer(targetUser.uuid());
|
||||
|
||||
if (sender == null || target == null) {
|
||||
return;
|
||||
|
||||
+12
-11
@@ -18,17 +18,18 @@ import java.util.function.Consumer;
|
||||
|
||||
public class BungeeMessageService implements MessageService {
|
||||
|
||||
private @NonNull final CarbonChatBukkit carbonChat;
|
||||
private final @NonNull CarbonChatBukkit carbonChat;
|
||||
|
||||
private @NonNull final BungeeChannelApi api;
|
||||
private final @NonNull BungeeChannelApi api;
|
||||
|
||||
private @NonNull final Map<@NonNull String, @NonNull BiConsumer<@NonNull PlayerUser, @NonNull ByteArrayDataInput>> userLoadedListeners = new HashMap<>();
|
||||
private final @NonNull Map<@NonNull String, @NonNull BiConsumer<@NonNull PlayerUser, @NonNull ByteArrayDataInput>> userLoadedListeners = new HashMap<>();
|
||||
|
||||
private @NonNull final Map<@NonNull String, @NonNull BiConsumer<@NonNull UUID, @NonNull ByteArrayDataInput>> userNotLoadedListeners = new HashMap<>();
|
||||
private final @NonNull Map<@NonNull String, @NonNull BiConsumer<@NonNull UUID, @NonNull ByteArrayDataInput>> userNotLoadedListeners = new HashMap<>();
|
||||
|
||||
private @NonNull final UUID serverUUID = UUID.randomUUID();
|
||||
private final @NonNull UUID serverUUID = UUID.randomUUID();
|
||||
|
||||
public BungeeMessageService(@NonNull final CarbonChatBukkit carbonChat) {
|
||||
@SuppressWarnings("method.invocation.invalid")
|
||||
public BungeeMessageService(final @NonNull CarbonChatBukkit carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
this.carbonChat.getServer().getMessenger().registerOutgoingPluginChannel(carbonChat, "BungeeCord");
|
||||
@@ -60,7 +61,7 @@ public class BungeeMessageService implements MessageService {
|
||||
});
|
||||
}
|
||||
|
||||
private void receiveMessage(@NonNull final UUID uuid, @NonNull final String key, @NonNull final ByteArrayDataInput value) {
|
||||
private void receiveMessage(final @NonNull UUID uuid, final @NonNull String key, final @NonNull ByteArrayDataInput value) {
|
||||
final PlayerUser user = this.carbonChat.userService().wrapIfLoaded(uuid);
|
||||
|
||||
if (user != null) {
|
||||
@@ -79,23 +80,23 @@ public class BungeeMessageService implements MessageService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerUserMessageListener(@NonNull final String key, @NonNull final BiConsumer<@NonNull PlayerUser, @NonNull ByteArrayDataInput> listener) {
|
||||
public void registerUserMessageListener(final @NonNull String key, final @NonNull BiConsumer<@NonNull PlayerUser, @NonNull ByteArrayDataInput> listener) {
|
||||
this.userLoadedListeners.put(key, listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerUUIDMessageListener(@NonNull final String key, @NonNull final BiConsumer<@NonNull UUID, @NonNull ByteArrayDataInput> listener) {
|
||||
public void registerUUIDMessageListener(final @NonNull String key, final @NonNull BiConsumer<@NonNull UUID, @NonNull ByteArrayDataInput> listener) {
|
||||
this.userNotLoadedListeners.put(key, listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterMessageListener(@NonNull final String key) {
|
||||
public void unregisterMessageListener(final @NonNull String key) {
|
||||
this.userLoadedListeners.remove(key);
|
||||
this.userNotLoadedListeners.remove(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(@NonNull final String key, @NonNull final UUID uuid, @NonNull final Consumer<ByteArrayDataOutput> consumer) {
|
||||
public void sendMessage(final @NonNull String key, final @NonNull UUID uuid, final @NonNull Consumer<ByteArrayDataOutput> consumer) {
|
||||
final ByteArrayDataOutput msg = ByteStreams.newDataOutput();
|
||||
|
||||
msg.writeLong(this.serverUUID.getMostSignificantBits());
|
||||
|
||||
+7
-3
@@ -12,11 +12,15 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class BukkitConsoleUser implements ConsoleUser, ForwardingAudience.Single {
|
||||
|
||||
private @NonNull final Audience audience;
|
||||
private final @NonNull Audience audience;
|
||||
|
||||
public BukkitConsoleUser(@NonNull final ConsoleCommandSender sender) {
|
||||
public BukkitConsoleUser(final @NonNull ConsoleCommandSender sender) {
|
||||
final Plugin plugin = Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||
|
||||
if (plugin == null) {
|
||||
throw new IllegalArgumentException("CarbonChat plugin cannot be found!");
|
||||
}
|
||||
|
||||
this.audience = BukkitAudiences.create(plugin).sender(sender);
|
||||
}
|
||||
|
||||
@@ -35,7 +39,7 @@ public class BukkitConsoleUser implements ConsoleUser, ForwardingAudience.Single
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(@NonNull final String permission) {
|
||||
public boolean hasPermission(final @NonNull String permission) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
+90
-59
@@ -24,24 +24,23 @@ import net.luckperms.api.query.QueryOptions;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
public class BukkitPlayerUser implements PlayerUser, ForwardingAudience.Single {
|
||||
|
||||
private @NonNull final transient CarbonChatBukkit carbonChat;
|
||||
private @NonNull final Map<@NonNull String, @NonNull SimpleUserChannelSettings> channelSettings = new HashMap<>();
|
||||
private @NonNull final List<@NonNull UUID> ignoredUsers = new ArrayList<>();
|
||||
private @MonotonicNonNull UUID uuid;
|
||||
private final @NonNull transient CarbonChatBukkit carbonChat;
|
||||
private final @NonNull Map<@NonNull String, @NonNull SimpleUserChannelSettings> channelSettings = new HashMap<>();
|
||||
private final @NonNull List<@NonNull UUID> ignoredUsers = new ArrayList<>();
|
||||
private @NonNull UUID uuid;
|
||||
private boolean muted = false;
|
||||
private boolean shadowMuted = false;
|
||||
private boolean spyingWhispers = false;
|
||||
@@ -51,11 +50,19 @@ public class BukkitPlayerUser implements PlayerUser, ForwardingAudience.Single {
|
||||
private @Nullable String selectedChannelKey = null;
|
||||
private transient @Nullable ChatChannel selectedChannel = null;
|
||||
|
||||
@SuppressWarnings("initialization.fields.uninitialized")
|
||||
public BukkitPlayerUser() {
|
||||
this.carbonChat = (CarbonChatBukkit) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||
final CarbonChatBukkit carbonChatBukkit =
|
||||
(CarbonChatBukkit) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||
|
||||
if (carbonChatBukkit == null) {
|
||||
throw new IllegalArgumentException("CarbonChat plugin not present.");
|
||||
}
|
||||
|
||||
this.carbonChat = carbonChatBukkit;
|
||||
}
|
||||
|
||||
public BukkitPlayerUser(@NonNull final UUID uuid) {
|
||||
public BukkitPlayerUser(final @NonNull UUID uuid) {
|
||||
this();
|
||||
this.uuid = uuid;
|
||||
}
|
||||
@@ -71,7 +78,7 @@ public class BukkitPlayerUser implements PlayerUser, ForwardingAudience.Single {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull String parsePlaceholders(@NonNull final String input) {
|
||||
public @NonNull String parsePlaceholders(final @NonNull String input) {
|
||||
final Player player = Bukkit.getPlayer(this.uuid());
|
||||
|
||||
if (player == null) {
|
||||
@@ -92,14 +99,23 @@ public class BukkitPlayerUser implements PlayerUser, ForwardingAudience.Single {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String nickname() {
|
||||
return this.nickname;
|
||||
public @NonNull String nickname() {
|
||||
if (this.nickname != null) {
|
||||
return this.nickname();
|
||||
}
|
||||
|
||||
return this.displayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(@NonNull final String permission) {
|
||||
return LuckPermsProvider.get().getUserManager().getUser(this.uuid())
|
||||
.getCachedData().getPermissionData().checkPermission(permission).asBoolean();
|
||||
public boolean hasPermission(final @NonNull String permission) {
|
||||
final User user = LuckPermsProvider.get().getUserManager().getUser(this.uuid());
|
||||
|
||||
if (user == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return user.getCachedData().getPermissionData().checkPermission(permission).asBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -116,7 +132,9 @@ public class BukkitPlayerUser implements PlayerUser, ForwardingAudience.Single {
|
||||
|
||||
final Player onlinePlayer = player.getPlayer();
|
||||
|
||||
onlinePlayer.setDisplayName(newNickname);
|
||||
if (onlinePlayer != null) {
|
||||
onlinePlayer.setDisplayName(newNickname);
|
||||
}
|
||||
|
||||
// if (this.carbonChat.getConfig().getBoolean("nicknames-set-tab-name")) {
|
||||
// onlinePlayer.setPlayerListName(newNickname);
|
||||
@@ -124,19 +142,21 @@ public class BukkitPlayerUser implements PlayerUser, ForwardingAudience.Single {
|
||||
}
|
||||
|
||||
if (!fromRemote) {
|
||||
if (this.nickname == null) {
|
||||
final String nick = this.nickname;
|
||||
|
||||
if (nick == null) {
|
||||
this.carbonChat.messageManager().sendMessage("nickname-reset", this.uuid(), byteArray -> {
|
||||
});
|
||||
} else {
|
||||
this.carbonChat.messageManager().sendMessage("nickname", this.uuid(), byteArray -> {
|
||||
byteArray.writeUTF(this.nickname);
|
||||
byteArray.writeUTF(nick);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String displayName() {
|
||||
public @NonNull String displayName() {
|
||||
final Player player = Bukkit.getPlayer(this.uuid());
|
||||
|
||||
if (player != null) {
|
||||
@@ -146,7 +166,7 @@ public class BukkitPlayerUser implements PlayerUser, ForwardingAudience.Single {
|
||||
return this.name();
|
||||
}
|
||||
|
||||
public void displayName(@Nullable final String displayName) {
|
||||
public void displayName(final @Nullable String displayName) {
|
||||
final Player player = Bukkit.getPlayer(this.uuid());
|
||||
|
||||
if (player != null) {
|
||||
@@ -155,10 +175,18 @@ public class BukkitPlayerUser implements PlayerUser, ForwardingAudience.Single {
|
||||
}
|
||||
|
||||
public @NonNull String name() {
|
||||
return Objects.requireNonNull(Bukkit.getOfflinePlayer(this.uuid()).getName());
|
||||
final OfflinePlayer player = Bukkit.getOfflinePlayer(this.uuid());
|
||||
final String name = player.getName();
|
||||
|
||||
if (name != null) {
|
||||
return name;
|
||||
}
|
||||
|
||||
return this.uuid.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("argument.type.incompatible")
|
||||
public @Nullable ChatChannel selectedChannel() {
|
||||
if (this.selectedChannel != null) {
|
||||
return this.selectedChannel;
|
||||
@@ -179,7 +207,7 @@ public class BukkitPlayerUser implements PlayerUser, ForwardingAudience.Single {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectedChannel(@NonNull final ChatChannel chatChannel, final boolean fromRemote) {
|
||||
public void selectedChannel(final @NonNull ChatChannel chatChannel, final boolean fromRemote) {
|
||||
final String failureMessage = chatChannel.switchFailureMessage();
|
||||
|
||||
final ChannelSwitchEvent event = new ChannelSwitchEvent(chatChannel, this, failureMessage);
|
||||
@@ -217,12 +245,12 @@ public class BukkitPlayerUser implements PlayerUser, ForwardingAudience.Single {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean ignoringUser(@NonNull final UUID uuid) {
|
||||
public boolean ignoringUser(final @NonNull UUID uuid) {
|
||||
return this.ignoredUsers.contains(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ignoringUser(@NonNull final UUID uuid, final boolean ignoring, final boolean fromRemote) {
|
||||
public void ignoringUser(final @NonNull UUID uuid, final boolean ignoring, final boolean fromRemote) {
|
||||
if (ignoring) {
|
||||
this.ignoredUsers.add(uuid);
|
||||
} else {
|
||||
@@ -246,12 +274,18 @@ public class BukkitPlayerUser implements PlayerUser, ForwardingAudience.Single {
|
||||
private transient final LuckPerms luckPerms = LuckPermsProvider.get();
|
||||
|
||||
@Override
|
||||
public boolean hasGroup(@NonNull final String groupName) {
|
||||
return this.hasGroup(this.luckPerms.getGroupManager().getGroup(groupName));
|
||||
public boolean hasGroup(final @NonNull String groupName) {
|
||||
final Group group = this.luckPerms.getGroupManager().getGroup(groupName);
|
||||
|
||||
if (group == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.hasGroup(group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasGroup(@NonNull final Group group) {
|
||||
public boolean hasGroup(final @NonNull Group group) {
|
||||
return this.groups().contains(group);
|
||||
}
|
||||
|
||||
@@ -259,13 +293,21 @@ public class BukkitPlayerUser implements PlayerUser, ForwardingAudience.Single {
|
||||
public @NonNull Collection<@NonNull Group> groups() {
|
||||
final User user = this.luckPerms.getUserManager().getUser(this.uuid());
|
||||
|
||||
return user.getInheritedGroups(QueryOptions.nonContextual());
|
||||
if (user != null) {
|
||||
return user.getInheritedGroups(QueryOptions.nonContextual());
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Group primaryGroup() {
|
||||
final User user = this.luckPerms.getUserManager().getUser(this.uuid());
|
||||
|
||||
if (user == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.luckPerms.getGroupManager().getGroup(user.getPrimaryGroup());
|
||||
}
|
||||
|
||||
@@ -318,19 +360,24 @@ public class BukkitPlayerUser implements PlayerUser, ForwardingAudience.Single {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replyTarget(@Nullable final UUID target, final boolean fromRemote) {
|
||||
public void replyTarget(final @Nullable UUID target, final boolean fromRemote) {
|
||||
this.replyTarget = target;
|
||||
|
||||
if (!fromRemote) {
|
||||
this.carbonChat.messageManager().sendMessage("reply-target", this.uuid(), byteArray -> {
|
||||
byteArray.writeLong(target.getMostSignificantBits());
|
||||
byteArray.writeLong(target.getLeastSignificantBits());
|
||||
});
|
||||
if (target != null) {
|
||||
this.carbonChat.messageManager().sendMessage("reply-target", this.uuid(), byteArray -> {
|
||||
byteArray.writeLong(target.getMostSignificantBits());
|
||||
byteArray.writeLong(target.getLeastSignificantBits());
|
||||
});
|
||||
} else {
|
||||
this.carbonChat.messageManager().sendMessage("reply-target-reset", this.uuid(), byteArray -> {
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull UserChannelSettings channelSettings(@NonNull final ChatChannel channel) {
|
||||
public @NonNull UserChannelSettings channelSettings(final @NonNull ChatChannel channel) {
|
||||
return this.channelSettings.computeIfAbsent(channel.key(), name -> {
|
||||
return new SimpleUserChannelSettings(this.uuid, channel.key());
|
||||
});
|
||||
@@ -357,7 +404,7 @@ public class BukkitPlayerUser implements PlayerUser, ForwardingAudience.Single {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(@NonNull final PlayerUser sender, @NonNull final String message) {
|
||||
public void sendMessage(final @NonNull PlayerUser sender, final @NonNull String message) {
|
||||
if (this.ignoringUser(sender) || sender.ignoringUser(this)) {
|
||||
return;
|
||||
}
|
||||
@@ -366,28 +413,16 @@ public class BukkitPlayerUser implements PlayerUser, ForwardingAudience.Single {
|
||||
final String fromPlayerFormat = this.carbonChat.carbonSettings().whisperOptions().receiverFormat();
|
||||
|
||||
final OfflinePlayer offlineSender = Bukkit.getOfflinePlayer(sender.uuid());
|
||||
String senderName = offlineSender.getName();
|
||||
final String senderOfflineName = senderName;
|
||||
|
||||
if (offlineSender.isOnline()) {
|
||||
senderName = offlineSender.getPlayer().getDisplayName();
|
||||
}
|
||||
final String senderName = sender.nickname();
|
||||
|
||||
final OfflinePlayer offlineTarget = Bukkit.getOfflinePlayer(this.uuid());
|
||||
String targetName = offlineTarget.getName();
|
||||
final String targetOfflineName = targetName;
|
||||
|
||||
if (offlineTarget.isOnline()) {
|
||||
targetName = offlineTarget.getPlayer().getDisplayName();
|
||||
}
|
||||
final String targetName = this.nickname();
|
||||
|
||||
final Component toPlayerComponent = this.carbonChat.messageProcessor().processMessage(toPlayerFormat,
|
||||
"message", message, "targetname", targetOfflineName, "sendername", senderOfflineName,
|
||||
"target", targetName, "sender", senderName);
|
||||
"message", message, "target", targetName, "sender", senderName);
|
||||
|
||||
final Component fromPlayerComponent = this.carbonChat.messageProcessor().processMessage(fromPlayerFormat,
|
||||
"message", message, "targetname", targetOfflineName, "sendername", senderOfflineName,
|
||||
"target", targetName, "sender", senderName);
|
||||
"message", message, "target", targetName, "sender", senderName);
|
||||
|
||||
final PrivateMessageEvent event = new PrivateMessageEvent(sender, this, toPlayerComponent, fromPlayerComponent, message);
|
||||
|
||||
@@ -418,9 +453,7 @@ public class BukkitPlayerUser implements PlayerUser, ForwardingAudience.Single {
|
||||
final String playerOfflineFormat = this.carbonChat.translations().otherPlayerOffline();
|
||||
|
||||
final Component playerOfflineComponent = this.carbonChat.messageProcessor().processMessage(playerOfflineFormat,
|
||||
"message", message,
|
||||
"targetname", targetOfflineName, "sendername", senderOfflineName,
|
||||
"target", targetNameFinal, "sender", senderNameFinal);
|
||||
"message", message, "target", targetNameFinal, "sender", senderNameFinal);
|
||||
|
||||
sender.sendMessage(Identity.nil(), playerOfflineComponent);
|
||||
|
||||
@@ -429,14 +462,13 @@ public class BukkitPlayerUser implements PlayerUser, ForwardingAudience.Single {
|
||||
|
||||
BungeeChannelApi.of(this.carbonChat).getPlayerList("ALL").thenAccept(list -> {
|
||||
final OfflinePlayer player = Bukkit.getOfflinePlayer(this.uuid());
|
||||
final String name = player.getName();
|
||||
|
||||
if (!list.contains(player.getName())) {
|
||||
if (name == null || !list.contains(name)) {
|
||||
final String playerOfflineFormat = this.carbonChat.translations().otherPlayerOffline();
|
||||
|
||||
final Component playerOfflineComponent = this.carbonChat.messageProcessor().processMessage(playerOfflineFormat,
|
||||
"message", message,
|
||||
"targetname", targetOfflineName, "sendername", senderOfflineName,
|
||||
"target", targetNameFinal, "sender", senderNameFinal);
|
||||
"message", message, "target", targetNameFinal, "sender", senderNameFinal);
|
||||
|
||||
sender.sendMessage(Identity.nil(), playerOfflineComponent);
|
||||
|
||||
@@ -466,8 +498,7 @@ public class BukkitPlayerUser implements PlayerUser, ForwardingAudience.Single {
|
||||
|
||||
user.sendMessage(sender.identity(), this.carbonChat.messageProcessor()
|
||||
.processMessage(this.carbonChat.translations().spyWhispers(), "message", message,
|
||||
"targetname", targetOfflineName, "sendername", senderOfflineName, "target", targetName,
|
||||
"sender", senderName));
|
||||
"target", targetName, "sender", senderName));
|
||||
}
|
||||
}
|
||||
}
|
||||
+17
-12
@@ -5,7 +5,6 @@ import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.users.CarbonUser;
|
||||
import net.draycia.carbon.api.users.UserChannelSettings;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
@@ -13,16 +12,15 @@ import java.util.UUID;
|
||||
|
||||
public class SimpleUserChannelSettings implements UserChannelSettings {
|
||||
|
||||
private @NonNull final transient CarbonChat carbonChat = CarbonChatProvider.carbonChat();
|
||||
private final transient @NonNull CarbonChat carbonChat = CarbonChatProvider.carbonChat();
|
||||
private boolean spying;
|
||||
private boolean ignored;
|
||||
private @NonNull String color;
|
||||
@MonotonicNonNull // @NonNull but not initialised in all constructors.
|
||||
private UUID uuid;
|
||||
@MonotonicNonNull // @NonNull but not initialised in all constructors.
|
||||
private String channel;
|
||||
private @Nullable String color;
|
||||
private @NonNull UUID uuid;
|
||||
private @NonNull String channel;
|
||||
|
||||
public SimpleUserChannelSettings(@NonNull final UUID uuid, @NonNull final String channel) {
|
||||
@SuppressWarnings("initialization.fields.uninitialized")
|
||||
public SimpleUserChannelSettings(final @NonNull UUID uuid, final @NonNull String channel) {
|
||||
this.uuid = uuid;
|
||||
this.channel = channel;
|
||||
}
|
||||
@@ -75,7 +73,7 @@ public class SimpleUserChannelSettings implements UserChannelSettings {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void color(@Nullable final TextColor color, final boolean fromRemote) {
|
||||
public void color(final @Nullable TextColor color, final boolean fromRemote) {
|
||||
if (color == null) {
|
||||
this.color = null;
|
||||
} else {
|
||||
@@ -83,9 +81,16 @@ public class SimpleUserChannelSettings implements UserChannelSettings {
|
||||
}
|
||||
|
||||
if (!fromRemote) {
|
||||
this.carbonChat.messageService().sendMessage("channel-color", this.uuid, byteArray -> {
|
||||
byteArray.writeUTF(color.asHexString());
|
||||
});
|
||||
final String newColor = this.color;
|
||||
|
||||
if (newColor == null || newColor.isEmpty()) {
|
||||
this.carbonChat.messageService().sendMessage("channel-color-reset", this.uuid, byteArray -> {
|
||||
});
|
||||
} else {
|
||||
this.carbonChat.messageService().sendMessage("channel-color", this.uuid, byteArray -> {
|
||||
byteArray.writeUTF(newColor);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-5
@@ -6,13 +6,12 @@ import net.draycia.carbon.bukkit.CarbonChatBukkit;
|
||||
import net.draycia.carbon.api.users.PlayerUser;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class CarbonPlaceholders extends PlaceholderExpansion {
|
||||
|
||||
private @NonNull final CarbonChatBukkit carbonChat;
|
||||
private final @NonNull CarbonChatBukkit carbonChat;
|
||||
|
||||
public CarbonPlaceholders(@NonNull final CarbonChatBukkit carbonChat) {
|
||||
public CarbonPlaceholders(final @NonNull CarbonChatBukkit carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
}
|
||||
|
||||
@@ -37,7 +36,7 @@ public class CarbonPlaceholders extends PlaceholderExpansion {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String onPlaceholderRequest(@NonNull final Player player, @NonNull final String identifier) {
|
||||
public @NonNull String onPlaceholderRequest(final @NonNull Player player, final @NonNull String identifier) {
|
||||
final String key = identifier.toLowerCase();
|
||||
|
||||
if (key.startsWith("can_use_")) {
|
||||
@@ -82,7 +81,7 @@ public class CarbonPlaceholders extends PlaceholderExpansion {
|
||||
return channel == null ? this.carbonChat.channelRegistry().defaultValue().name() : channel.name();
|
||||
}
|
||||
|
||||
return null;
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -39,7 +39,7 @@ import java.util.List;
|
||||
|
||||
public final class CarbonUtils {
|
||||
|
||||
private static @NonNull final String @NonNull [] colors;
|
||||
private static final @NonNull String @NonNull [] colors;
|
||||
|
||||
private CarbonUtils() {
|
||||
|
||||
@@ -55,7 +55,7 @@ public final class CarbonUtils {
|
||||
colors = colorList.toArray(new String[0]);
|
||||
}
|
||||
|
||||
public @NonNull static Component createComponent(@NonNull final Player player) {
|
||||
public static @NonNull Component createComponent(final @NonNull Player player) {
|
||||
if (!FunctionalityConstants.HAS_HOVER_EVENT_METHOD) {
|
||||
return net.kyori.adventure.text.Component.empty();
|
||||
}
|
||||
|
||||
+2
-2
@@ -6,7 +6,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored") // This is a common pattern in this class.
|
||||
@SuppressWarnings({"ResultOfMethodCallIgnored", "argument.type.incompatible"})
|
||||
public final class FunctionalityConstants {
|
||||
|
||||
public static final boolean HAS_HOVER_EVENT_METHOD = noThrow(() -> ItemFactory.class.getMethod("hoverContentOf", ItemStack.class));
|
||||
@@ -29,7 +29,7 @@ public final class FunctionalityConstants {
|
||||
|
||||
}
|
||||
|
||||
private static boolean noThrow(@NonNull final ThrowingRunnable runnable) {
|
||||
private static boolean noThrow(final @NonNull ThrowingRunnable runnable) {
|
||||
try {
|
||||
runnable.run();
|
||||
return true;
|
||||
|
||||
@@ -38,7 +38,7 @@ import java.util.zip.GZIPOutputStream;
|
||||
* <p>
|
||||
* Check out https://bStats.org/ to learn more about bStats!
|
||||
*/
|
||||
@SuppressWarnings({"WeakerAccess", "unused"})
|
||||
@SuppressWarnings("ALL")
|
||||
public class Metrics {
|
||||
|
||||
static {
|
||||
|
||||
Reference in new issue
Block a user