mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-03 06:28:54 +00:00
Fix spacing
This commit is contained in:
1 parent
a8788c7d3d
commit
a47ff4e7b2
74 files changed
+5000
-4927
No files matched your search
@@ -10,84 +10,84 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class CarbonPlaceholders extends PlaceholderExpansion {
|
||||
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public CarbonPlaceholders(@NonNull CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
public CarbonPlaceholders(@NonNull CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public String getIdentifier() {
|
||||
return "carbonchat";
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public String getAuthor() {
|
||||
return "Draycia (Vicarious#0001)";
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public String getVersion() {
|
||||
return "1.0.0";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean persist() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String onPlaceholderRequest(@NonNull final Player player, @NonNull final String identifier) {
|
||||
String key = identifier.toLowerCase();
|
||||
|
||||
if (key.startsWith("can_use_")) {
|
||||
String value = key.replace("can_use_", "");
|
||||
|
||||
ChatChannel channel = carbonChat.getChannelManager().getRegistry().get(value);
|
||||
|
||||
if (channel == null) {
|
||||
return "false";
|
||||
}
|
||||
|
||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||
|
||||
return String.valueOf(channel.canPlayerUse(user));
|
||||
} else if (key.startsWith("can_see_")) {
|
||||
String value = key.replace("can_see_", "");
|
||||
|
||||
ChatChannel channel = carbonChat.getChannelManager().getRegistry().get(value);
|
||||
|
||||
if (channel == null) {
|
||||
return "false";
|
||||
}
|
||||
|
||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||
|
||||
return String.valueOf(channel.canPlayerSee(user, true));
|
||||
} else if (key.startsWith("ignoring_channel_")) {
|
||||
String value = key.replace("ignoring_channel_", "");
|
||||
|
||||
ChatChannel channel = carbonChat.getChannelManager().getRegistry().get(value);
|
||||
|
||||
if (channel == null) {
|
||||
return "false";
|
||||
}
|
||||
|
||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||
|
||||
return String.valueOf(user.getChannelSettings(channel).isIgnored());
|
||||
} else if (key.startsWith("selected_channel")) {
|
||||
ChatChannel channel = carbonChat.getUserService().wrap(player).getSelectedChannel();
|
||||
|
||||
return channel == null ? carbonChat.getChannelManager().getDefaultChannel().getName() : channel.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public String getIdentifier() {
|
||||
return "carbonchat";
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public String getAuthor() {
|
||||
return "Draycia (Vicarious#0001)";
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public String getVersion() {
|
||||
return "1.0.0";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean persist() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String onPlaceholderRequest(@NonNull final Player player, @NonNull final String identifier) {
|
||||
String key = identifier.toLowerCase();
|
||||
|
||||
if (key.startsWith("can_use_")) {
|
||||
String value = key.replace("can_use_", "");
|
||||
|
||||
ChatChannel channel = carbonChat.getChannelManager().getRegistry().get(value);
|
||||
|
||||
if (channel == null) {
|
||||
return "false";
|
||||
}
|
||||
|
||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||
|
||||
return String.valueOf(channel.canPlayerUse(user));
|
||||
} else if (key.startsWith("can_see_")) {
|
||||
String value = key.replace("can_see_", "");
|
||||
|
||||
ChatChannel channel = carbonChat.getChannelManager().getRegistry().get(value);
|
||||
|
||||
if (channel == null) {
|
||||
return "false";
|
||||
}
|
||||
|
||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||
|
||||
return String.valueOf(channel.canPlayerSee(user, true));
|
||||
} else if (key.startsWith("ignoring_channel_")) {
|
||||
String value = key.replace("ignoring_channel_", "");
|
||||
|
||||
ChatChannel channel = carbonChat.getChannelManager().getRegistry().get(value);
|
||||
|
||||
if (channel == null) {
|
||||
return "false";
|
||||
}
|
||||
|
||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||
|
||||
return String.valueOf(user.getChannelSettings(channel).isIgnored());
|
||||
} else if (key.startsWith("selected_channel")) {
|
||||
ChatChannel channel = carbonChat.getUserService().wrap(player).getSelectedChannel();
|
||||
|
||||
return channel == null ? carbonChat.getChannelManager().getDefaultChannel().getName() : channel.getName();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -49,93 +49,93 @@ import java.util.List;
|
||||
|
||||
public final class CarbonUtils {
|
||||
|
||||
private static final @NonNull String @NonNull [] colors;
|
||||
private static final @NonNull String @NonNull [] colors;
|
||||
|
||||
static {
|
||||
List<String> colorList = new ArrayList<>();
|
||||
static {
|
||||
List<String> colorList = new ArrayList<>();
|
||||
|
||||
for (NamedTextColor color : NamedTextColor.values()) {
|
||||
colorList.add(color.toString());
|
||||
}
|
||||
|
||||
colors = colorList.toArray(new String[0]);
|
||||
for (NamedTextColor color : NamedTextColor.values()) {
|
||||
colorList.add(color.toString());
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static Component createComponent(@NonNull final Player player) {
|
||||
if (!FunctionalityConstants.HAS_HOVER_EVENT_METHOD) {
|
||||
return net.kyori.adventure.text.TextComponent.empty();
|
||||
}
|
||||
colors = colorList.toArray(new String[0]);
|
||||
}
|
||||
|
||||
final ItemStack itemStack = player.getInventory().getItemInMainHand();
|
||||
|
||||
if (itemStack.getType().isAir()) {
|
||||
return net.kyori.adventure.text.TextComponent.empty();
|
||||
}
|
||||
|
||||
Content content = Bukkit.getItemFactory().hoverContentOf(itemStack);
|
||||
HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_ITEM, content);
|
||||
|
||||
ComponentBuilder component = new ComponentBuilder();
|
||||
component.event(event); // Let this be inherited by all coming components.
|
||||
component.color(ChatColor.WHITE).append("[");
|
||||
|
||||
if (itemStack.getItemMeta().hasDisplayName()) {
|
||||
component.append(TextComponent.fromLegacyText(itemStack.getItemMeta().getDisplayName()));
|
||||
} else {
|
||||
String name = itemStack.getItemMeta().hasDisplayName()
|
||||
? itemStack.getItemMeta().getDisplayName()
|
||||
: "item.minecraft." + itemStack.getType().name().toLowerCase(); // As of 1.13, Material is 1:1 with MC's names
|
||||
component.append(new TranslatableComponent(name));
|
||||
}
|
||||
|
||||
component.color(ChatColor.WHITE).append("]");
|
||||
|
||||
return BungeeCordComponentSerializer.get().deserialize(component.create());
|
||||
@NonNull
|
||||
public static Component createComponent(@NonNull final Player player) {
|
||||
if (!FunctionalityConstants.HAS_HOVER_EVENT_METHOD) {
|
||||
return net.kyori.adventure.text.TextComponent.empty();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static TextColor parseColor(@Nullable String input) {
|
||||
return parseColor(null, input);
|
||||
final ItemStack itemStack = player.getInventory().getItemInMainHand();
|
||||
|
||||
if (itemStack.getType().isAir()) {
|
||||
return net.kyori.adventure.text.TextComponent.empty();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static TextColor parseColor(@Nullable ChatUser user, @Nullable String input) {
|
||||
if (input == null) {
|
||||
input = "white";
|
||||
}
|
||||
Content content = Bukkit.getItemFactory().hoverContentOf(itemStack);
|
||||
HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_ITEM, content);
|
||||
|
||||
if (user != null && user.isOnline()) {
|
||||
input = PlaceholderAPI.setPlaceholders(user.asPlayer(), input);
|
||||
}
|
||||
ComponentBuilder component = new ComponentBuilder();
|
||||
component.event(event); // Let this be inherited by all coming components.
|
||||
component.color(ChatColor.WHITE).append("[");
|
||||
|
||||
for (NamedTextColor namedColor : NamedTextColor.values()) {
|
||||
if (namedColor.toString().equalsIgnoreCase(input)) {
|
||||
return namedColor;
|
||||
}
|
||||
}
|
||||
|
||||
if (input.contains("&") || input.contains("§")) {
|
||||
input = input.replace("&", "§");
|
||||
|
||||
return LegacyComponentSerializer.legacySection().deserialize(input).color();
|
||||
}
|
||||
|
||||
return TextColor.fromCSSHexString(input);
|
||||
if (itemStack.getItemMeta().hasDisplayName()) {
|
||||
component.append(TextComponent.fromLegacyText(itemStack.getItemMeta().getDisplayName()));
|
||||
} else {
|
||||
String name = itemStack.getItemMeta().hasDisplayName()
|
||||
? itemStack.getItemMeta().getDisplayName()
|
||||
: "item.minecraft." + itemStack.getType().name().toLowerCase(); // As of 1.13, Material is 1:1 with MC's names
|
||||
component.append(new TranslatableComponent(name));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static Argument onlineChatUserArgument() {
|
||||
return new CustomArgument<>((input) -> {
|
||||
CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||
component.color(ChatColor.WHITE).append("]");
|
||||
|
||||
Player player = Bukkit.getPlayer(input);
|
||||
return BungeeCordComponentSerializer.get().deserialize(component.create());
|
||||
}
|
||||
|
||||
if (player == null) {
|
||||
throw new CustomArgument.CustomArgumentException("Invalid player for input (" + input + ")");
|
||||
}
|
||||
@Nullable
|
||||
public static TextColor parseColor(@Nullable String input) {
|
||||
return parseColor(null, input);
|
||||
}
|
||||
|
||||
return carbonChat.getUserService().wrap(player);
|
||||
@Nullable
|
||||
public static TextColor parseColor(@Nullable ChatUser user, @Nullable String input) {
|
||||
if (input == null) {
|
||||
input = "white";
|
||||
}
|
||||
|
||||
if (user != null && user.isOnline()) {
|
||||
input = PlaceholderAPI.setPlaceholders(user.asPlayer(), input);
|
||||
}
|
||||
|
||||
for (NamedTextColor namedColor : NamedTextColor.values()) {
|
||||
if (namedColor.toString().equalsIgnoreCase(input)) {
|
||||
return namedColor;
|
||||
}
|
||||
}
|
||||
|
||||
if (input.contains("&") || input.contains("§")) {
|
||||
input = input.replace("&", "§");
|
||||
|
||||
return LegacyComponentSerializer.legacySection().deserialize(input).color();
|
||||
}
|
||||
|
||||
return TextColor.fromCSSHexString(input);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static Argument onlineChatUserArgument() {
|
||||
return new CustomArgument<>((input) -> {
|
||||
CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||
|
||||
Player player = Bukkit.getPlayer(input);
|
||||
|
||||
if (player == null) {
|
||||
throw new CustomArgument.CustomArgumentException("Invalid player for input (" + input + ")");
|
||||
}
|
||||
|
||||
return carbonChat.getUserService().wrap(player);
|
||||
// }).overrideSuggestions((sender, args) -> {
|
||||
// ArrayList<String> players = new ArrayList<>();
|
||||
//
|
||||
@@ -144,15 +144,15 @@ public final class CarbonUtils {
|
||||
// }
|
||||
//
|
||||
// return players.toArray(new String[0]);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static Argument chatUserArgument() {
|
||||
return new CustomArgument<>((input) -> {
|
||||
CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||
@NonNull
|
||||
public static Argument chatUserArgument() {
|
||||
return new CustomArgument<>((input) -> {
|
||||
CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||
|
||||
return carbonChat.getUserService().wrap(input);
|
||||
return carbonChat.getUserService().wrap(input);
|
||||
// }).overrideSuggestions((sender, args) -> {
|
||||
// ArrayList<String> players = new ArrayList<>();
|
||||
//
|
||||
@@ -161,34 +161,34 @@ public final class CarbonUtils {
|
||||
// }
|
||||
//
|
||||
// return players.toArray(new String[0]);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static Argument textColorArgument() {
|
||||
return new CustomArgument<>((input) -> {
|
||||
TextColor color = parseColor(input);
|
||||
@NonNull
|
||||
public static Argument textColorArgument() {
|
||||
return new CustomArgument<>((input) -> {
|
||||
TextColor color = parseColor(input);
|
||||
|
||||
if (color == null) {
|
||||
throw new CustomArgument.CustomArgumentException("Invalid color for input (" + input + ")");
|
||||
}
|
||||
if (color == null) {
|
||||
throw new CustomArgument.CustomArgumentException("Invalid color for input (" + input + ")");
|
||||
}
|
||||
|
||||
return color;
|
||||
}).overrideSuggestions(colors);
|
||||
}
|
||||
return color;
|
||||
}).overrideSuggestions(colors);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static Argument channelArgument() {
|
||||
return new CustomArgument<>((input) -> {
|
||||
CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||
@NonNull
|
||||
public static Argument channelArgument() {
|
||||
return new CustomArgument<>((input) -> {
|
||||
CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||
|
||||
ChatChannel channel = carbonChat.getChannelManager().getRegistry().get(input);
|
||||
ChatChannel channel = carbonChat.getChannelManager().getRegistry().get(input);
|
||||
|
||||
if (channel == null) {
|
||||
throw new CustomArgument.CustomArgumentException("Invalid channel for input (" + input + ")");
|
||||
}
|
||||
if (channel == null) {
|
||||
throw new CustomArgument.CustomArgumentException("Invalid channel for input (" + input + ")");
|
||||
}
|
||||
|
||||
return channel;
|
||||
return channel;
|
||||
// }).overrideSuggestions((sender, args) -> {
|
||||
// CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||
//
|
||||
@@ -199,12 +199,12 @@ public final class CarbonUtils {
|
||||
// }
|
||||
//
|
||||
// return channels.toArray(new String[0]);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static Argument usableChannelArgument() {
|
||||
throw new NotImplementedException("Not implemented yet.");
|
||||
}
|
||||
@NonNull
|
||||
public static Argument usableChannelArgument() {
|
||||
throw new NotImplementedException("Not implemented yet.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -6,12 +6,12 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class CommandUtils {
|
||||
|
||||
public static void handleDuplicateCommands(@NonNull CommandSettings settings) {
|
||||
CommandAPI.unregister(settings.getName());
|
||||
public static void handleDuplicateCommands(@NonNull CommandSettings settings) {
|
||||
CommandAPI.unregister(settings.getName());
|
||||
|
||||
for (String command : settings.getAliases()) {
|
||||
CommandAPI.unregister(command);
|
||||
}
|
||||
for (String command : settings.getAliases()) {
|
||||
CommandAPI.unregister(command);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,19 +7,19 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored") // This is a common pattern in this class.
|
||||
public final class FunctionalityConstants {
|
||||
|
||||
public static final boolean HAS_HOVER_EVENT_METHOD = noThrow(() -> ItemFactory.class.getMethod("hoverContentOf", ItemStack.class));
|
||||
public static final boolean HAS_HOVER_EVENT_METHOD = noThrow(() -> ItemFactory.class.getMethod("hoverContentOf", ItemStack.class));
|
||||
|
||||
private static boolean noThrow(@NonNull ThrowingRunnable runnable) {
|
||||
try {
|
||||
runnable.run();
|
||||
return true;
|
||||
} catch (Exception ex) {
|
||||
return false;
|
||||
}
|
||||
private static boolean noThrow(@NonNull ThrowingRunnable runnable) {
|
||||
try {
|
||||
runnable.run();
|
||||
return true;
|
||||
} catch (Exception ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
private interface ThrowingRunnable {
|
||||
void run() throws Exception;
|
||||
}
|
||||
@FunctionalInterface
|
||||
private interface ThrowingRunnable {
|
||||
void run() throws Exception;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -6,22 +6,27 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
@FunctionalInterface
|
||||
public interface RedisListener extends RedisPubSubListener<String, String> {
|
||||
|
||||
@Override
|
||||
void message(@NonNull String channel, @NonNull String message);
|
||||
@Override
|
||||
void message(@NonNull String channel, @NonNull String message);
|
||||
|
||||
@Override
|
||||
default void message(@NonNull String pattern, @NonNull String channel, @NonNull String message) { }
|
||||
@Override
|
||||
default void message(@NonNull String pattern, @NonNull String channel, @NonNull String message) {
|
||||
}
|
||||
|
||||
@Override
|
||||
default void subscribed(@NonNull String channel, long count) { }
|
||||
@Override
|
||||
default void subscribed(@NonNull String channel, long count) {
|
||||
}
|
||||
|
||||
@Override
|
||||
default void psubscribed(@NonNull String pattern, long count) { }
|
||||
@Override
|
||||
default void psubscribed(@NonNull String pattern, long count) {
|
||||
}
|
||||
|
||||
@Override
|
||||
default void unsubscribed(@NonNull String channel, long count) { }
|
||||
@Override
|
||||
default void unsubscribed(@NonNull String channel, long count) {
|
||||
}
|
||||
|
||||
@Override
|
||||
default void punsubscribed(@NonNull String pattern, long count) { }
|
||||
@Override
|
||||
default void punsubscribed(@NonNull String pattern, long count) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,35 +7,35 @@ import java.util.Collection;
|
||||
|
||||
public interface Registry<@NonNull T> {
|
||||
|
||||
/**
|
||||
* Adds the specified key and value to the registry
|
||||
*
|
||||
* @param key The entry's key
|
||||
* @param value The value to insert
|
||||
* @return If successfully registered
|
||||
*/
|
||||
boolean register(@NonNull String key, @NonNull T value);
|
||||
/**
|
||||
* Adds the specified key and value to the registry
|
||||
*
|
||||
* @param key The entry's key
|
||||
* @param value The value to insert
|
||||
* @return If successfully registered
|
||||
*/
|
||||
boolean register(@NonNull String key, @NonNull T value);
|
||||
|
||||
/**
|
||||
* Gets the list of registered values
|
||||
*
|
||||
* @return The list of registered values
|
||||
*/
|
||||
@NonNull
|
||||
Collection<@NonNull T> values();
|
||||
/**
|
||||
* Gets the list of registered values
|
||||
*
|
||||
* @return The list of registered values
|
||||
*/
|
||||
@NonNull
|
||||
Collection<@NonNull T> values();
|
||||
|
||||
/**
|
||||
* Obtains an entry associated with the specified key
|
||||
*
|
||||
* @param key The key for the entry
|
||||
* @return The entry associated with the key or {@code null} if unassociated
|
||||
*/
|
||||
@Nullable
|
||||
T get(@NonNull String key);
|
||||
/**
|
||||
* Obtains an entry associated with the specified key
|
||||
*
|
||||
* @param key The key for the entry
|
||||
* @return The entry associated with the key or {@code null} if unassociated
|
||||
*/
|
||||
@Nullable
|
||||
T get(@NonNull String key);
|
||||
|
||||
/**
|
||||
* Clears all registered entries from the registry
|
||||
*/
|
||||
void clearAll();
|
||||
/**
|
||||
* Clears all registered entries from the registry
|
||||
*/
|
||||
void clearAll();
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user