Skip to content

Commit

Permalink
feat: create editorconfig and switch code from crlf to lf
Browse files Browse the repository at this point in the history
  • Loading branch information
SerenModz21 committed Jun 23, 2024
1 parent 166303d commit 77e94ef
Show file tree
Hide file tree
Showing 17 changed files with 1,118 additions and 1,107 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = false

[.github/workflows/*.yml]
indent_size = 2
25 changes: 12 additions & 13 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
pluginManagement {
repositories {
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
mavenCentral()
gradlePluginPortal()
}
}

rootProject.name = 'discord-bridge'

pluginManagement {
repositories {
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
mavenCentral()
gradlePluginPortal()
}
}

rootProject.name = 'discord-bridge'
132 changes: 66 additions & 66 deletions src/main/java/net/kings_world/discord_bridge/DiscordBridgeEvents.java
Original file line number Diff line number Diff line change
@@ -1,66 +1,66 @@
package net.kings_world.discord_bridge;

import dev.kord.core.entity.Message;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.advancement.AdvancementDisplay;
import net.minecraft.entity.LivingEntity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;

public final class DiscordBridgeEvents {
public static final Event<PlayerJoin> PLAYER_JOIN = EventFactory.createArrayBacked(PlayerJoin.class, callbacks -> player -> {
for (PlayerJoin callback : callbacks) {
callback.onPlayerJoin(player);
}
});

public static final Event<PlayerLeave> PLAYER_LEAVE = EventFactory.createArrayBacked(PlayerLeave.class, callbacks -> (player, reason) -> {
for (PlayerLeave callback : callbacks) {
callback.onPlayerLeave(player, reason);
}
});

public static final Event<PlayerDeath> PLAYER_DEATH = EventFactory.createArrayBacked(PlayerDeath.class, callbacks -> (entity, reason) -> {
for (PlayerDeath callback : callbacks) {
callback.onPlayerDeath(entity, reason);
}
});

public static final Event<PlayerAdvancement> PLAYER_ADVANCEMENT = EventFactory.createArrayBacked(PlayerAdvancement.class, callbacks -> (player, advancement) -> {
for (PlayerAdvancement callback : callbacks) {
callback.onPlayerAdvancement(player, advancement);
}
});

public static final Event<DiscordMessage> DISCORD_MESSAGE = EventFactory.createArrayBacked(DiscordMessage.class, callbacks -> message -> {
for (DiscordMessage callback : callbacks) {
callback.onDiscordMessage(message);
}
});

@FunctionalInterface
public interface PlayerJoin {
void onPlayerJoin(ServerPlayerEntity player);
}

@FunctionalInterface
public interface PlayerLeave {
void onPlayerLeave(ServerPlayerEntity player, Text reason);
}

@FunctionalInterface
public interface PlayerDeath {
void onPlayerDeath(LivingEntity entity, Text reason);
}

@FunctionalInterface
public interface PlayerAdvancement {
void onPlayerAdvancement(ServerPlayerEntity player, AdvancementDisplay advancement);
}

@FunctionalInterface
public interface DiscordMessage {
void onDiscordMessage(Message message);
}
}
package net.kings_world.discord_bridge;

import dev.kord.core.entity.Message;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.advancement.AdvancementDisplay;
import net.minecraft.entity.LivingEntity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;

public final class DiscordBridgeEvents {
public static final Event<PlayerJoin> PLAYER_JOIN = EventFactory.createArrayBacked(PlayerJoin.class, callbacks -> player -> {
for (PlayerJoin callback : callbacks) {
callback.onPlayerJoin(player);
}
});

public static final Event<PlayerLeave> PLAYER_LEAVE = EventFactory.createArrayBacked(PlayerLeave.class, callbacks -> (player, reason) -> {
for (PlayerLeave callback : callbacks) {
callback.onPlayerLeave(player, reason);
}
});

public static final Event<PlayerDeath> PLAYER_DEATH = EventFactory.createArrayBacked(PlayerDeath.class, callbacks -> (entity, reason) -> {
for (PlayerDeath callback : callbacks) {
callback.onPlayerDeath(entity, reason);
}
});

public static final Event<PlayerAdvancement> PLAYER_ADVANCEMENT = EventFactory.createArrayBacked(PlayerAdvancement.class, callbacks -> (player, advancement) -> {
for (PlayerAdvancement callback : callbacks) {
callback.onPlayerAdvancement(player, advancement);
}
});

public static final Event<DiscordMessage> DISCORD_MESSAGE = EventFactory.createArrayBacked(DiscordMessage.class, callbacks -> message -> {
for (DiscordMessage callback : callbacks) {
callback.onDiscordMessage(message);
}
});

@FunctionalInterface
public interface PlayerJoin {
void onPlayerJoin(ServerPlayerEntity player);
}

@FunctionalInterface
public interface PlayerLeave {
void onPlayerLeave(ServerPlayerEntity player, Text reason);
}

@FunctionalInterface
public interface PlayerDeath {
void onPlayerDeath(LivingEntity entity, Text reason);
}

@FunctionalInterface
public interface PlayerAdvancement {
void onPlayerAdvancement(ServerPlayerEntity player, AdvancementDisplay advancement);
}

@FunctionalInterface
public interface DiscordMessage {
void onDiscordMessage(Message message);
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
package net.kings_world.discord_bridge.mixins;

import net.kings_world.discord_bridge.DiscordBridgeEvents;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageTracker;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(DamageTracker.class)
public class DamageTrackerMixin {
@Shadow
@Final
private LivingEntity entity;

@Inject(at = @At(value = "RETURN"), method = "getDeathMessage")
private void onGetDeathMessage(CallbackInfoReturnable<Text> cir) {
DiscordBridgeEvents.PLAYER_DEATH.invoker().onPlayerDeath(entity, cir.getReturnValue());
}
package net.kings_world.discord_bridge.mixins;

import net.kings_world.discord_bridge.DiscordBridgeEvents;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageTracker;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(DamageTracker.class)
public class DamageTrackerMixin {
@Shadow
@Final
private LivingEntity entity;

@Inject(at = @At(value = "RETURN"), method = "getDeathMessage")
private void onGetDeathMessage(CallbackInfoReturnable<Text> cir) {
DiscordBridgeEvents.PLAYER_DEATH.invoker().onPlayerDeath(entity, cir.getReturnValue());
}
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
package net.kings_world.discord_bridge.mixins;

import net.kings_world.discord_bridge.DiscordBridge;
import net.kings_world.discord_bridge.DiscordBridgeEvents;
import net.minecraft.advancement.Advancement;
import net.minecraft.advancement.AdvancementDisplay;
import net.minecraft.advancement.PlayerAdvancementTracker;
import net.minecraft.server.network.ServerPlayerEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(PlayerAdvancementTracker.class)
public abstract class PlayerAdvancementTrackerMixin {
@Shadow
private ServerPlayerEntity owner;

@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/text/Text;Z)V"), method = "grantCriterion")
private void onAdvancementBroadcast(Advancement advancement, String criterionName, CallbackInfoReturnable<Boolean> cir) {
AdvancementDisplay display = advancement.getDisplay();
if (display == null) {
DiscordBridge.INSTANCE.getLogger().warn("Advancement " + advancement.getId().toString() + " has no display!");
return;
}
DiscordBridge.INSTANCE.getLogger().info(owner.getName().getString() + " unlocked " + display.getTitle().getString());
DiscordBridgeEvents.PLAYER_ADVANCEMENT.invoker().onPlayerAdvancement(owner, display);
}
package net.kings_world.discord_bridge.mixins;

import net.kings_world.discord_bridge.DiscordBridge;
import net.kings_world.discord_bridge.DiscordBridgeEvents;
import net.minecraft.advancement.Advancement;
import net.minecraft.advancement.AdvancementDisplay;
import net.minecraft.advancement.PlayerAdvancementTracker;
import net.minecraft.server.network.ServerPlayerEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(PlayerAdvancementTracker.class)
public abstract class PlayerAdvancementTrackerMixin {
@Shadow
private ServerPlayerEntity owner;

@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/text/Text;Z)V"), method = "grantCriterion")
private void onAdvancementBroadcast(Advancement advancement, String criterionName, CallbackInfoReturnable<Boolean> cir) {
AdvancementDisplay display = advancement.getDisplay();
if (display == null) {
DiscordBridge.INSTANCE.getLogger().warn("Advancement " + advancement.getId().toString() + " has no display!");
return;
}
DiscordBridge.INSTANCE.getLogger().info(owner.getName().getString() + " unlocked " + display.getTitle().getString());
DiscordBridgeEvents.PLAYER_ADVANCEMENT.invoker().onPlayerAdvancement(owner, display);
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package net.kings_world.discord_bridge.mixins;

import net.kings_world.discord_bridge.DiscordBridgeEvents;
import net.minecraft.network.ClientConnection;
import net.minecraft.server.PlayerManager;
import net.minecraft.server.network.ServerPlayerEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(PlayerManager.class)
public class PlayerManagerMixin {
@Inject(at = @At("TAIL"), method = "onPlayerConnect")
private void onPlayerJoin(ClientConnection connection, ServerPlayerEntity player, CallbackInfo info) {
DiscordBridgeEvents.PLAYER_JOIN.invoker().onPlayerJoin(player);
}
}
package net.kings_world.discord_bridge.mixins;

import net.kings_world.discord_bridge.DiscordBridgeEvents;
import net.minecraft.network.ClientConnection;
import net.minecraft.server.PlayerManager;
import net.minecraft.server.network.ServerPlayerEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(PlayerManager.class)
public class PlayerManagerMixin {
@Inject(at = @At("TAIL"), method = "onPlayerConnect")
private void onPlayerJoin(ClientConnection connection, ServerPlayerEntity player, CallbackInfo info) {
DiscordBridgeEvents.PLAYER_JOIN.invoker().onPlayerJoin(player);
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package net.kings_world.discord_bridge.mixins;

import net.kings_world.discord_bridge.DiscordBridgeEvents;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(ServerPlayNetworkHandler.class)
public class ServerPlayNetworkHandlerMixin {
@Shadow
public ServerPlayerEntity player;

@Inject(at = @At("HEAD"), method = "onDisconnected")
private void onPlayerLeave(Text reason, CallbackInfo info) {
DiscordBridgeEvents.PLAYER_LEAVE.invoker().onPlayerLeave(player, reason);
}
package net.kings_world.discord_bridge.mixins;

import net.kings_world.discord_bridge.DiscordBridgeEvents;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(ServerPlayNetworkHandler.class)
public class ServerPlayNetworkHandlerMixin {
@Shadow
public ServerPlayerEntity player;

@Inject(at = @At("HEAD"), method = "onDisconnected")
private void onPlayerLeave(Text reason, CallbackInfo info) {
DiscordBridgeEvents.PLAYER_LEAVE.invoker().onPlayerLeave(player, reason);
}
}
Loading

0 comments on commit 77e94ef

Please sign in to comment.