mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-03 06:28:54 +00:00
Single module setup
This commit is contained in:
1 parent
ad9a794156
commit
66217f6534
70 files changed
+92
-138
No files matched your search
@@ -0,0 +1,85 @@
|
||||
package net.draycia.carbon.util;
|
||||
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import net.draycia.carbon.CarbonChat;
|
||||
import net.draycia.carbon.channels.ChatChannel;
|
||||
import net.draycia.carbon.storage.ChatUser;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class CarbonPlaceholders extends PlaceholderExpansion {
|
||||
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public CarbonPlaceholders(CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return "carbonchat";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return "Draycia (Vicarious#0001)";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return "1.0.0";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean persist() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public String onPlaceholderRequest(final Player player, 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 channel.canPlayerUse(user) ? "true" : "false";
|
||||
} 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 channel.canPlayerSee(user, true) ? "true" : "false";
|
||||
} 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 user.getChannelSettings(channel).isIgnored() ? "true" : "false";
|
||||
} else if (key.startsWith("selected_channel")) {
|
||||
ChatChannel channel = carbonChat.getUserService().wrap(player).getSelectedChannel();
|
||||
|
||||
return channel == null ? carbonChat.getChannelManager().getDefaultChannel().getName() : channel.getName();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
Simple channel based chat plugin for Spigot
|
||||
Copyright (C) 2020 Alexander Söderberg
|
||||
Copyright (C) 2020 Josua Parks (Draycia)
|
||||
|
||||
Modifications made to work with Kyori/Adventure
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.draycia.carbon.util;
|
||||
|
||||
import net.kyori.adventure.platform.bukkit.MinecraftComponentSerializer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public final class ItemStackUtils {
|
||||
|
||||
private final Method asNMSCopyMethod;
|
||||
private final Method cMethod;
|
||||
|
||||
public ItemStackUtils() throws NoSuchMethodException, ClassNotFoundException {
|
||||
final String version = Bukkit.getServer().getClass().getPackage().getName()
|
||||
.substring("org.bukkit.craftbukkit.".length());
|
||||
|
||||
Class<?> craftItemStackClass = Class.forName("org.bukkit.craftbukkit." + version + ".inventory.CraftItemStack");
|
||||
this.asNMSCopyMethod = craftItemStackClass.getMethod("asNMSCopy", ItemStack.class);
|
||||
Class<?> itemStackClass = Class.forName("net.minecraft.server." + version + ".ItemStack");
|
||||
this.cMethod = itemStackClass.getMethod("C");
|
||||
}
|
||||
|
||||
public Component createComponent(final Player player) {
|
||||
final ItemStack itemStack = player.getInventory().getItemInMainHand();
|
||||
|
||||
if (itemStack == null || itemStack.getType() == Material.AIR) {
|
||||
return TextComponent.empty();
|
||||
}
|
||||
|
||||
try {
|
||||
final Object cbItemStack = this.asNMSCopyMethod.invoke(null, itemStack);
|
||||
final Object mojangComponent = this.cMethod.invoke(cbItemStack);
|
||||
|
||||
return MinecraftComponentSerializer.INSTANCE.deserialize(mojangComponent);
|
||||
} catch (final IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
return TextComponent.empty();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package net.draycia.carbon.util;
|
||||
|
||||
import io.lettuce.core.pubsub.RedisPubSubListener;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RedisListener extends RedisPubSubListener<String, String> {
|
||||
|
||||
void message(String channel, String message);
|
||||
|
||||
@Override
|
||||
default void message(String pattern, String channel, String message) { }
|
||||
|
||||
@Override
|
||||
default void subscribed(String channel, long count) { }
|
||||
|
||||
@Override
|
||||
default void psubscribed(String pattern, long count) { }
|
||||
|
||||
@Override
|
||||
default void unsubscribed(String channel, long count) { }
|
||||
|
||||
@Override
|
||||
default void punsubscribed(String pattern, long count) { }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package net.draycia.carbon.util;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface Registry<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(@NotNull String key, @NotNull T value);
|
||||
|
||||
/**
|
||||
* Gets the list of registered values
|
||||
* @return The list of registered values
|
||||
*/
|
||||
@NotNull
|
||||
Collection<T> values();
|
||||
|
||||
/**
|
||||
* Obtains an entry associated with the specified key
|
||||
* @param key The key for the entry
|
||||
* @return The entry associated with the key
|
||||
*/
|
||||
@Nullable
|
||||
T get(String key);
|
||||
|
||||
/**
|
||||
* Clears all registered entries from the registry
|
||||
*/
|
||||
void clearAll();
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user