Skip to content

Commit

Permalink
fix: wrong folder + luckperms for forge/fabric + use forgivingexception
Browse files Browse the repository at this point in the history
Close #23
  • Loading branch information
Yann151924 committed Sep 19, 2023
1 parent f8f68cc commit 80b530b
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ public abstract class AbstractAurionChat implements AurionChatPlugin {
private Map<UUID, AurionChatPlayer> aurionChatPlayers;

private ChatService chatService;

public static LuckPermsUtils luckPermsUtils = null;


private final PluginLogger logger = getlogger();

public final void enable(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.DeliverCallback;
import com.rabbitmq.client.impl.ForgivingExceptionHandler;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;

Expand All @@ -31,21 +32,22 @@ public class ChatService {
public ChatService(AbstractAurionChat plugin) throws IOException {
this.plugin = plugin;
this.config = this.plugin.getConfigurationAdapter();
this.createConnection(getUri());
this.createConnection();
}

public String getUri() {
return config.getString("rabbitmq.uri", "amqp://guest:guest@localhost:5672/");
}

private void createConnection(String uri) throws IOException {
private void createConnection() throws IOException {
ConnectionFactory factory = new ConnectionFactory();
try{
factory.setUri(getUri());
factory.setAutomaticRecoveryEnabled(true);
factory.setTopologyRecoveryEnabled(true);
factory.setNetworkRecoveryInterval(10000);
factory.setRequestedHeartbeat(10);
factory.setExceptionHandler(new ForgivingExceptionHandler());

connection = factory.newConnection();
channel = connection.createChannel();
Expand All @@ -63,14 +65,15 @@ private void createConnection(String uri) throws IOException {

public void reCreateConnection() throws IOException {
this.close();
this.createConnection(getUri());
this.createConnection();
}

private void join() throws IOException{
channel.exchangeDeclare(EXCHANGE_NAME, "fanout");

String queue = channel.queueDeclare().getQueue();
channel.queueBind(queue, EXCHANGE_NAME, "");

channel.basicConsume(queue, true, consumer(), consumerTag -> {});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public PlayerFactory(boolean withLuckPerms){
protected abstract UUID getUUID(T player);
protected abstract String getName(T player);
protected abstract void sendMessage(T player, Component message);
protected abstract boolean hasPermission(T player, String permission);

public String getPreffix(T player){
return luckPermsUtils != null ? luckPermsUtils.getPlayerPreffix(getUUID(player)).orElse("") : "";
Expand All @@ -30,6 +29,10 @@ public String getSuffix(T player){
return luckPermsUtils != null ? luckPermsUtils.getPlayerSuffix(getUUID(player)).orElse("") : "";
};

protected boolean hasPermission(T player, String permission) {
return luckPermsUtils.hasPermission(getUUID(player), permission);
}

public final Player wrap(T player){
Objects.requireNonNull(player, "player");
return new AbstractPlayer<>(this, player);
Expand Down
8 changes: 4 additions & 4 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ repositories {
apply plugin: 'fabric-loom'

dependencies {
minecraft "com.mojang:minecraft:1.20.1"
mappings "net.fabricmc:yarn:1.20.1+build.2:v2"
modImplementation "net.fabricmc:fabric-loader:0.14.21"
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

Set<String> apiModules = [
'fabric-api-base',
Expand All @@ -24,7 +24,7 @@ dependencies {
]

apiModules.forEach {
modImplementation(fabricApi.module(it, '0.83.1+1.20.1'))
modImplementation(fabricApi.module(it, project.fabric_version))
}
shadow project(':common')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public PlayerFactory getPlayerFactory() {

@Override
protected Path getConfigDirectory() {
return FabricLoader.getInstance().getGameDir().resolve("mods").resolve(AbstractAurionChat.ID);
return FabricLoader.getInstance().getGameDir().resolve("config").resolve(AbstractAurionChat.ID);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,4 @@ protected String getName(ServerPlayerEntity player) {
protected void sendMessage(ServerPlayerEntity player, Component message) {
player.sendMessage(toNativeText(message));
}

@Override
protected boolean hasPermission(ServerPlayerEntity player, String permission) {
return AurionChat.luckPermsUtils.hasPermission(player.getUuid(), permission);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,4 @@ protected String getName(ServerPlayer player) {
protected void sendMessage(ServerPlayer player, Component message) {
player.sendMessage(toNativeText(message), Util.NIL_UUID);
}

@Override
protected boolean hasPermission(ServerPlayer player, String permission) {
return AurionChat.luckPermsUtils.hasPermission(player.getUUID(), permission);
}
}

0 comments on commit 80b530b

Please sign in to comment.