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