mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-02 06:28:54 +00:00
Human pass over managers
This commit is contained in:
4 files changed
+40
-28
No files matched your search
@@ -13,14 +13,18 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class AdventureManager {
|
||||
|
||||
private final @NonNull CarbonChat carbonChat;
|
||||
private final @NonNull BukkitAudiences audiences;
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
@NonNull
|
||||
private final BukkitAudiences audiences;
|
||||
|
||||
public AdventureManager(@NonNull CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
this.audiences = BukkitAudiences.create(carbonChat);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Component processMessageWithPapi(@NonNull Player player, @Nullable String input, @NonNull String @NonNull ... placeholders) {
|
||||
if (input == null || input.trim().isEmpty()) {
|
||||
return TextComponent.empty();
|
||||
@@ -29,6 +33,7 @@ public class AdventureManager {
|
||||
return processMessage(PlaceholderAPI.setPlaceholders(player, input), placeholders);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Component processMessage(@Nullable String input, @NonNull String @NonNull ... placeholders) {
|
||||
if (input == null || input.trim().isEmpty()) {
|
||||
return TextComponent.empty();
|
||||
@@ -36,7 +41,7 @@ public class AdventureManager {
|
||||
|
||||
switch (carbonChat.getLanguage().getString("formatting.type", "minimessage").toLowerCase()) {
|
||||
case "minedown":
|
||||
return processMineDown(input, placeholders);
|
||||
return MineDown.parse(input, placeholders);
|
||||
case "mojang":
|
||||
case "mojangson":
|
||||
case "json":
|
||||
@@ -50,7 +55,7 @@ public class AdventureManager {
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private Component processMojang(String input, String @NonNull ... placeholders) {
|
||||
private Component processMojang(@NonNull String input, @NonNull String @NonNull ... placeholders) {
|
||||
for (int i = 0; i < placeholders.length; i += 2) {
|
||||
String placeholder = placeholders[i];
|
||||
String replacement = placeholders[i + 1];
|
||||
@@ -61,11 +66,8 @@ public class AdventureManager {
|
||||
return getAudiences().gsonSerializer().deserialize(input);
|
||||
}
|
||||
|
||||
private Component processMineDown(String input, String... placeholders) {
|
||||
return MineDown.parse(input, placeholders);
|
||||
}
|
||||
|
||||
public @NonNull BukkitAudiences getAudiences() {
|
||||
@NonNull
|
||||
public BukkitAudiences getAudiences() {
|
||||
return audiences;
|
||||
}
|
||||
}
|
||||
@@ -3,11 +3,12 @@ package net.draycia.carbon.managers;
|
||||
import net.draycia.carbon.CarbonChat;
|
||||
import net.draycia.carbon.channels.ChannelRegistry;
|
||||
import net.draycia.carbon.channels.ChatChannel;
|
||||
import net.draycia.carbon.channels.impls.*;
|
||||
import net.draycia.carbon.channels.impls.CarbonChatChannel;
|
||||
import net.draycia.carbon.events.ChannelRegisterEvent;
|
||||
import net.draycia.carbon.util.Registry;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
@@ -15,9 +16,15 @@ import java.util.Collections;
|
||||
|
||||
public class ChannelManager {
|
||||
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
private final @NonNull ChannelRegistry registry;
|
||||
private @Nullable String defaultChannelKey = null;
|
||||
|
||||
@NonNull
|
||||
private final ChannelRegistry registry;
|
||||
|
||||
@Nullable
|
||||
@MonotonicNonNull
|
||||
private String defaultChannelKey = null;
|
||||
|
||||
public ChannelManager(CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
@@ -41,18 +48,18 @@ public class ChannelManager {
|
||||
}
|
||||
|
||||
public boolean registerChannel(@NonNull ChatChannel channel) {
|
||||
boolean success = getRegistry().register(channel.getKey(), channel);
|
||||
boolean success = getRegistry().register(channel.getKey(), channel);
|
||||
|
||||
if (success) {
|
||||
if (channel.isDefault() && defaultChannelKey == null) {
|
||||
carbonChat.getLogger().info("Default channel registered: " + channel.getName());
|
||||
defaultChannelKey = channel.getKey();
|
||||
}
|
||||
if (success) {
|
||||
if (channel.isDefault() && defaultChannelKey == null) {
|
||||
carbonChat.getLogger().info("Default channel registered: " + channel.getName());
|
||||
defaultChannelKey = channel.getKey();
|
||||
}
|
||||
|
||||
Bukkit.getPluginManager().callEvent(new ChannelRegisterEvent(Collections.singletonList(channel), getRegistry()));
|
||||
}
|
||||
Bukkit.getPluginManager().callEvent(new ChannelRegisterEvent(Collections.singletonList(channel), getRegistry()));
|
||||
}
|
||||
|
||||
return success;
|
||||
return success;
|
||||
}
|
||||
|
||||
public @NonNull Registry<ChatChannel> getRegistry() {
|
||||
|
||||
@@ -8,14 +8,15 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class CommandManager {
|
||||
|
||||
private final @NonNull CarbonChat carbonChat;
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public CommandManager(@NonNull CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
reloadCommands(carbonChat);
|
||||
reloadCommands();
|
||||
}
|
||||
|
||||
private void reloadCommands(@NonNull CarbonChat carbonChat) {
|
||||
private void reloadCommands() {
|
||||
new ChannelCommand(carbonChat, getCommandSettings("channel"));
|
||||
new ChannelListCommand(carbonChat, getCommandSettings("channellist"));
|
||||
new ChatReloadCommand(carbonChat, getCommandSettings("chatreload"));
|
||||
@@ -33,7 +34,8 @@ public class CommandManager {
|
||||
new ToggleCommand(carbonChat, getCommandSettings("toggle"));
|
||||
}
|
||||
|
||||
private @NonNull CommandSettings getCommandSettings(@NonNull String command) {
|
||||
@NonNull
|
||||
private CommandSettings getCommandSettings(@NonNull String command) {
|
||||
ConfigurationSection section = carbonChat.getCommandsConfig().getConfigurationSection(command);
|
||||
|
||||
return new CommandSettings(section.getBoolean("enabled"), section.getString("name"),
|
||||
|
||||
@@ -12,9 +12,10 @@ import java.util.function.Function;
|
||||
|
||||
public class ContextManager {
|
||||
|
||||
private final Map<String, Function<MessageContext, Boolean>> handlers = new HashMap<>();
|
||||
@NonNull
|
||||
private final Map<@NonNull String, @NonNull Function<@NonNull MessageContext, @NonNull Boolean>> handlers = new HashMap<>();
|
||||
|
||||
public boolean register(String key, Function<MessageContext, Boolean> handler) {
|
||||
public boolean register(@NonNull String key, @NonNull Function<@NonNull MessageContext, @NonNull Boolean> handler) {
|
||||
if (this.handlers.containsKey(key)) {
|
||||
return false;
|
||||
}
|
||||
@@ -23,7 +24,7 @@ public class ContextManager {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean testContext(ChatUser user, ChatUser target, @NonNull ChatChannel channel) {
|
||||
public boolean testContext(@NonNull ChatUser user, @NonNull ChatUser target, @NonNull ChatChannel channel) {
|
||||
for (Map.Entry<String, Function<MessageContext, Boolean>> handler : handlers.entrySet()) {
|
||||
String key = handler.getKey();
|
||||
|
||||
|
||||
Reference in new issue
Block a user