Trying to become an architect

This commit is contained in:
samolego 2021-01-14 20:12:51 +01:00
parent 1092166973
commit 783851c753
42 changed files with 146 additions and 416 deletions

View File

@ -1,124 +0,0 @@
plugins {
id 'fabric-loom' version '0.5-SNAPSHOT'
id 'maven-publish'
}
repositories {
// Carpet mod
maven {
url 'https://jitpack.io'
}
maven {
url 'https://masa.dy.fi/maven'
}
}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
archivesBaseName = project.archives_base_name
version = "${project.mod_version}-${project.minecraft_version}"
group = project.maven_group
minecraft {
}
dependencies {
//to change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
// Password hashing
// Argon2
implementation "de.mkammerer:argon2-jvm:${argon2_version}"
include "de.mkammerer:argon2-jvm:${argon2_version}"
// BCrypt
implementation "at.favre.lib:bcrypt:${bcrypt_version}"
implementation "at.favre.lib:bytes:${bytes_version}"
include "at.favre.lib:bcrypt:${bcrypt_version}"
include "at.favre.lib:bytes:${bytes_version}"
// Storage
// LevelDB database
implementation group: 'org.iq80.leveldb', name: 'leveldb', version: '0.12'
implementation group: 'org.iq80.leveldb', name: 'leveldb-api', version: '0.12'
include group: 'org.iq80.leveldb', name: 'leveldb', version: '0.12'
include group: 'org.iq80.leveldb', name: 'leveldb-api', version: '0.12'
// MongoDB driver
implementation 'org.mongodb:mongodb-driver-sync:4.1.0'
include 'org.mongodb:mongodb-driver-sync:4.1.0'
// JNA lib
include 'net.java.dev.jna:jna:5.5.0'
// carpetMod
// from masa's maven
//modImplementation "carpet:fabric-carpet:${project.minecraft_version}-${project.carpet_core_version}"
//modImplementation "carpet:fabric-carpet:1.16-${project.carpet_core_version}"
// jitpack for quicker updating
modImplementation "com.github.gnembon:fabric-carpet:${project.carpet_branch}-SNAPSHOT"
}
processResources {
inputs.property "version", project.version
from(sourceSets.main.resources.srcDirs) {
include "fabric.mod.json"
expand "version": project.version
}
from(sourceSets.main.resources.srcDirs) {
exclude "fabric.mod.json"
}
}
// ensure that the encoding is set to UTF-8, no matter what the system default is
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this task, sources will not be generated.
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = "sources"
from sourceSets.main.allSource
}
jar {
from "LICENSE"
}
// configure the maven publication
publishing {
publications {
mavenJava(MavenPublication) {
// add all the jars that should be included when publishing to maven
artifact(remapJar) {
builtBy remapJar
}
artifact(sourcesJar) {
builtBy remapSourcesJar
}
}
}
// select the repositories you want to publish to
repositories {
// uncomment to publish to the local maven
// mavenLocal()
mavenCentral()
}
}

View File

@ -4,7 +4,6 @@ import com.mojang.authlib.GameProfile;
import net.minecraft.block.Blocks;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.network.packet.c2s.play.ChatMessageC2SPacket;
import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket;
import net.minecraft.server.PlayerManager;
import net.minecraft.server.network.ServerPlayerEntity;
@ -15,7 +14,6 @@ import net.minecraft.util.math.BlockPos;
import org.samo_lego.simpleauth.storage.PlayerCache;
import org.samo_lego.simpleauth.utils.PlayerAuth;
import java.net.SocketAddress;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -28,9 +26,15 @@ import static org.samo_lego.simpleauth.SimpleAuth.playerCacheMap;
*/
public class AuthEventHandler {
// Player pre-join
// Returns text as a reason for disconnect or null to pass
public static LiteralText checkCanPlayerJoinServer(SocketAddress socketAddress, GameProfile profile, PlayerManager manager) {
/**
* Player pre-join.
* Returns text as a reason for disconnect or null to pass
*
* @param profile GameProfile of the player
* @param manager PlayerManager
* @return TExt if player should be disconnected
*/
public static LiteralText checkCanPlayerJoinServer(GameProfile profile, PlayerManager manager) {
// Getting the player
String incomingPlayerUsername = profile.getName();
PlayerEntity onlinePlayer = manager.getPlayer(incomingPlayerUsername);

View File

@ -3,7 +3,7 @@ package org.samo_lego.simpleauth.mixin;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.ActionResult;
import org.samo_lego.simpleauth.event.item.DropItemCallback;
import org.samo_lego.simpleauth.event.AuthEventHandler;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
@ -17,7 +17,7 @@ public class MixinPlayerEntity {
@Inject(method = "dropSelectedItem(Z)Z", at = @At("HEAD"), cancellable = true)
private void dropSelectedItem(boolean dropEntireStack, CallbackInfoReturnable<Boolean> cir) {
ServerPlayerEntity player = (ServerPlayerEntity) (Object) this;
ActionResult result = DropItemCallback.EVENT.invoker().onDropItem(player);
ActionResult result = AuthEventHandler.onDropItem(player);
if (result == ActionResult.FAIL) {
cir.setReturnValue(false);

View File

@ -9,6 +9,7 @@ import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.stat.ServerStatHandler;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import org.samo_lego.simpleauth.event.AuthEventHandler;
import org.samo_lego.simpleauth.event.entity.player.PlayerJoinServerCallback;
import org.samo_lego.simpleauth.event.entity.player.PlayerLeaveServerCallback;
import org.samo_lego.simpleauth.event.entity.player.PrePlayerJoinCallback;
@ -36,12 +37,12 @@ public abstract class MixinPlayerManager {
@Inject(method = "onPlayerConnect(Lnet/minecraft/network/ClientConnection;Lnet/minecraft/server/network/ServerPlayerEntity;)V", at = @At("RETURN"))
private void onPlayerConnect(ClientConnection clientConnection, ServerPlayerEntity serverPlayerEntity, CallbackInfo ci) {
PlayerJoinServerCallback.EVENT.invoker().onPlayerJoin(serverPlayerEntity);
AuthEventHandler.onPlayerJoin(serverPlayerEntity);
}
@Inject(method = "remove(Lnet/minecraft/server/network/ServerPlayerEntity;)V", at = @At("HEAD"))
private void onPlayerLeave(ServerPlayerEntity serverPlayerEntity, CallbackInfo ci) {
PlayerLeaveServerCallback.EVENT.invoker().onPlayerLeave(serverPlayerEntity);
AuthEventHandler.onPlayerLeave(serverPlayerEntity);
}
@Inject(method = "checkCanJoin(Ljava/net/SocketAddress;Lcom/mojang/authlib/GameProfile;)Lnet/minecraft/text/Text;", at = @At("HEAD"), cancellable = true)
@ -49,7 +50,7 @@ public abstract class MixinPlayerManager {
// Getting the player that is trying to join the server
PlayerManager manager = (PlayerManager) (Object) this;
LiteralText returnText = PrePlayerJoinCallback.EVENT.invoker().checkCanPlayerJoinServer(socketAddress, profile, manager);
LiteralText returnText = AuthEventHandler.checkCanPlayerJoinServer(profile, manager);
if(returnText != null) {
// Canceling player joining with the returnText message

View File

@ -7,6 +7,7 @@ import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.ActionResult;
import org.samo_lego.simpleauth.event.AuthEventHandler;
import org.samo_lego.simpleauth.event.entity.player.ChatCallback;
import org.samo_lego.simpleauth.event.entity.player.PlayerMoveCallback;
import org.samo_lego.simpleauth.event.item.TakeItemCallback;
@ -33,7 +34,7 @@ public abstract class MixinServerPlayNetworkHandler {
cancellable = true
)
private void onPlayerChat(String message, CallbackInfo ci) {
ActionResult result = ChatCallback.EVENT.invoker().onPlayerChat(this.player, message);
ActionResult result = AuthEventHandler.onPlayerChat(this.player, message);
if (result == ActionResult.FAIL) {
ci.cancel();
}
@ -50,7 +51,7 @@ public abstract class MixinServerPlayNetworkHandler {
)
private void onPlayerAction(PlayerActionC2SPacket packet, CallbackInfo ci) {
if(packet.getAction() == SWAP_ITEM_WITH_OFFHAND) {
ActionResult result = TakeItemCallback.EVENT.invoker().onTakeItem(this.player);
ActionResult result = AuthEventHandler.onTakeItem(this.player);
if (result == ActionResult.FAIL) {
ci.cancel();
}
@ -67,7 +68,7 @@ public abstract class MixinServerPlayNetworkHandler {
cancellable = true
)
private void onPlayerMove(PlayerMoveC2SPacket playerMoveC2SPacket, CallbackInfo ci) {
ActionResult result = PlayerMoveCallback.EVENT.invoker().onPlayerMove(player);
ActionResult result = AuthEventHandler.onPlayerMove(player);
if (result == ActionResult.FAIL) {
// A bit ugly, I know. (we need to update player position)
player.networkHandler.requestTeleport(player.getX(), player.getY(), player.getZ(), player.yaw, player.pitch);
@ -85,7 +86,7 @@ public abstract class MixinServerPlayNetworkHandler {
cancellable = true
)
public void onCreativeInventoryAction(CreativeInventoryActionC2SPacket packet, CallbackInfo ci) {
ActionResult result = TakeItemCallback.EVENT.invoker().onTakeItem(this.player);
ActionResult result = AuthEventHandler.onTakeItem(this.player);
if (result == ActionResult.FAIL) {
// Canceling the item taking

View File

@ -5,6 +5,7 @@ import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket;
import net.minecraft.screen.slot.Slot;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.ActionResult;
import org.samo_lego.simpleauth.event.AuthEventHandler;
import org.samo_lego.simpleauth.event.item.TakeItemCallback;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
@ -17,7 +18,7 @@ public abstract class MixinSlot {
@Inject(method = "canTakeItems(Lnet/minecraft/entity/player/PlayerEntity;)Z", at = @At(value = "HEAD"), cancellable = true)
private void canTakeItems(PlayerEntity playerEntity, CallbackInfoReturnable<Boolean> cir) {
ServerPlayerEntity player = (ServerPlayerEntity) playerEntity;
ActionResult result = TakeItemCallback.EVENT.invoker().onTakeItem(player);
ActionResult result = AuthEventHandler.onTakeItem(player);
if (result == ActionResult.FAIL) {
// Canceling the item taking

68
fabric/build.gradle Normal file
View File

@ -0,0 +1,68 @@
plugins {
id "com.github.johnrengelman.shadow" version "5.0.0"
}
repositories {
// Carpet mod
maven {
url 'https://jitpack.io'
}
maven {
url 'https://masa.dy.fi/maven'
}
}
configurations {
shadow
}
architectury {
platformSetupLoomIde()
}
dependencies {
minecraft "com.mojang:minecraft:${rootProject.minecraft_version}"
mappings("net.fabricmc:yarn:${rootProject.yarn_mappings}:v2")
modImplementation "net.fabricmc:fabric-loader:${rootProject.loader_version}"
// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_version}"
compileOnly(project(path: ":common")) {
transitive = false
exclude(module: "fabric-api")
}
runtimeOnly(project(path: ":common", configuration: "transformedRuntime")) {
transitive = false
exclude(module: "fabric-api")
}
shadow(project(path: ":common", configuration: "transformed")) {
transitive = false
exclude(module: "fabric-api")
}
// carpetMod
// from masa's maven
//modImplementation "carpet:fabric-carpet:${project.minecraft_version}-${project.carpet_core_version}"
//modImplementation "carpet:fabric-carpet:1.16-${project.carpet_core_version}"
// jitpack for quicker updating
modImplementation "com.github.gnembon:fabric-carpet:${project.carpet_branch}-SNAPSHOT"
}
processResources {
filesMatching("fabric.mod.json") {
expand "version": project.version
}
inputs.property "version", project.version
}
shadowJar {
configurations = [project.configurations.shadow]
classifier "shadow"
}
remapJar {
dependsOn(shadowJar)
input.set(shadowJar.archivePath)
archiveClassifier = "fabric"
}

View File

@ -0,0 +1,39 @@
package org.samo_lego.simpleauth;
import net.fabricmc.api.DedicatedServerModInitializer;
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.event.player.*;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.server.MinecraftServer;
public class SimpleAuthFabric implements DedicatedServerModInitializer {
@Override
public void onInitializeServer() {
SimpleAuth.init(FabricLoader.getInstance().getGameDir());
// Registering the commands
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> {
RegisterCommand.registerCommand(dispatcher);
LoginCommand.registerCommand(dispatcher);
LogoutCommand.registerCommand(dispatcher);
AuthCommand.registerCommand(dispatcher);
AccountCommand.registerCommand(dispatcher);
});
// From Fabric API
PlayerBlockBreakEvents.BEFORE.register((world, player, blockPos, blockState, blockEntity) -> AuthEventHandler.onBreakBlock(player));
UseBlockCallback.EVENT.register((player, world, hand, blockHitResult) -> AuthEventHandler.onUseBlock(player));
UseItemCallback.EVENT.register((player, world, hand) -> AuthEventHandler.onUseItem(player));
AttackEntityCallback.EVENT.register((player, world, hand, entity, entityHitResult) -> AuthEventHandler.onAttackEntity(player));
UseEntityCallback.EVENT.register((player, world, hand, entity, entityHitResult) -> AuthEventHandler.onUseEntity(player));
ServerLifecycleEvents.START_DATA_PACK_RELOAD.register((server, serverResourceManager) -> AuthEventHandler.reloadConfig(null));
ServerLifecycleEvents.SERVER_STOPPED.register(this::onStopServer);
}
private void onStopServer(MinecraftServer server) {
SimpleAuth.stop();
}
}

1
forge/gradle.properties Normal file
View File

@ -0,0 +1 @@
loom.forge = true

View File

@ -9,16 +9,23 @@ loader_version=0.10.8
#Fabric api
fabric_version=0.28.0+1.16
# Forge
forge_version = 35.1.0
# Mod Properties
mod_version = 1.7.4
maven_group = org.samo_lego
archives_base_name = simpleauth
# Hashing
# Hashing libs
argon2_version = 2.7
bcrypt_version = 0.9.0
bytes_version = 1.3.0
# Architectury
architectury_version=1.3.78
# Carpet for debugging
carpet_core_version = 1.4.16+v201105
carpet_branch = master

View File

@ -5,6 +5,14 @@ pluginManagement {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
maven { url "https://dl.bintray.com/shedaniel/cloth" }
maven { url "https://files.minecraftforge.net/maven/" }
gradlePluginPortal()
}
}
include("common")
include("fabric")
include("forge")
rootProject.name = "simpleauth"

View File

@ -1,136 +0,0 @@
package org.samo_lego.simpleauth;
import net.fabricmc.api.DedicatedServerModInitializer;
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.event.player.*;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.server.MinecraftServer;
import org.samo_lego.simpleauth.commands.*;
import org.samo_lego.simpleauth.event.AuthEventHandler;
import org.samo_lego.simpleauth.event.entity.player.*;
import org.samo_lego.simpleauth.event.item.DropItemCallback;
import org.samo_lego.simpleauth.event.item.TakeItemCallback;
import org.samo_lego.simpleauth.storage.AuthConfig;
import org.samo_lego.simpleauth.storage.DBHelper;
import org.samo_lego.simpleauth.storage.PlayerCache;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Properties;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import static org.samo_lego.simpleauth.commands.AuthCommand.reloadConfig;
import static org.samo_lego.simpleauth.event.AuthEventHandler.*;
import static org.samo_lego.simpleauth.utils.SimpleLogger.logError;
import static org.samo_lego.simpleauth.utils.SimpleLogger.logInfo;
public class SimpleAuth implements DedicatedServerModInitializer {
public static DBHelper DB = new DBHelper();
public static final ExecutorService THREADPOOL = Executors.newCachedThreadPool();
/**
* HashMap of players that have joined the server.
* It's cleared on server stop in order to save some interactions with database during runtime.
* Stores their data as {@link org.samo_lego.simpleauth.storage.PlayerCache PlayerCache} object.
*/
public static final HashMap<String, PlayerCache> playerCacheMap = new HashMap<>();
/**
* HashSet of player names that have Mojang accounts.
* If player is saved in here, they will be treated as online-mode ones.
*/
public static final HashSet<String> mojangAccountNamesCache = new HashSet<>();
// Getting game directory
public static final Path gameDirectory = FabricLoader.getInstance().getGameDir();
// Server properties
public static final Properties serverProp = new Properties();
/**
* Config of the SimpleAuth mod.
*/
public static AuthConfig config;
@Override
public void onInitializeServer() {
// Info I guess :D
logInfo("SimpleAuth mod by samo_lego.");
// The support on discord was great! I really appreciate your help.
logInfo("This mod wouldn't exist without the awesome Fabric Community. TYSM guys!");
try {
serverProp.load(new FileReader(gameDirectory + "/server.properties"));
} catch (IOException e) {
logError("Error while reading server properties: " + e.getMessage());
}
// Creating data directory (database and config files are stored there)
File file = new File(gameDirectory + "/mods/SimpleAuth/leveldbStore");
if (!file.exists() && !file.mkdirs())
throw new RuntimeException("[SimpleAuth] Error creating directory!");
// Loading config
config = AuthConfig.load(new File(gameDirectory + "/mods/SimpleAuth/config.json"));
// Connecting to db
DB.openConnection();
// Registering the commands
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> {
RegisterCommand.registerCommand(dispatcher);
LoginCommand.registerCommand(dispatcher);
LogoutCommand.registerCommand(dispatcher);
AuthCommand.registerCommand(dispatcher);
AccountCommand.registerCommand(dispatcher);
});
// Registering the events
PrePlayerJoinCallback.EVENT.register(AuthEventHandler::checkCanPlayerJoinServer);
PlayerJoinServerCallback.EVENT.register(AuthEventHandler::onPlayerJoin);
PlayerLeaveServerCallback.EVENT.register(AuthEventHandler::onPlayerLeave);
DropItemCallback.EVENT.register(AuthEventHandler::onDropItem);
TakeItemCallback.EVENT.register(AuthEventHandler::onTakeItem);
ChatCallback.EVENT.register(AuthEventHandler::onPlayerChat);
PlayerMoveCallback.EVENT.register(AuthEventHandler::onPlayerMove);
// From Fabric API
PlayerBlockBreakEvents.BEFORE.register((world, player, blockPos, blockState, blockEntity) -> onBreakBlock(player));
UseBlockCallback.EVENT.register((player, world, hand, blockHitResult) -> onUseBlock(player));
UseItemCallback.EVENT.register((player, world, hand) -> onUseItem(player));
AttackEntityCallback.EVENT.register((player, world, hand, entity, entityHitResult) -> onAttackEntity(player));
UseEntityCallback.EVENT.register((player, world, hand, entity, entityHitResult) -> onUseEntity(player));
ServerLifecycleEvents.START_DATA_PACK_RELOAD.register((server, serverResourceManager) -> reloadConfig(null));
ServerLifecycleEvents.SERVER_STOPPED.register(this::onStopServer);
}
/**
* Called on server stop.
*/
private void onStopServer(MinecraftServer server) {
logInfo("Shutting down SimpleAuth.");
DB.saveAll(playerCacheMap);
// Closing threads
try {
THREADPOOL.shutdownNow();
if (!THREADPOOL.awaitTermination(500, TimeUnit.MILLISECONDS)) {
Thread.currentThread().interrupt();
}
} catch (InterruptedException e) {
logError(e.getMessage());
THREADPOOL.shutdownNow();
}
// Closing DB connection
DB.close();
}
}

View File

@ -1,22 +0,0 @@
package org.samo_lego.simpleauth.event.entity.player;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.network.packet.c2s.play.ChatMessageC2SPacket;
import net.minecraft.util.ActionResult;
public interface ChatCallback {
Event<ChatCallback> EVENT = EventFactory.createArrayBacked(ChatCallback.class, listeners -> (player, message) -> {
for (ChatCallback event : listeners) {
ActionResult result = event.onPlayerChat(player, message);
if (result != ActionResult.PASS) {
return result;
}
}
return ActionResult.PASS;
});
ActionResult onPlayerChat(PlayerEntity player, String message);
}

View File

@ -1,14 +0,0 @@
package org.samo_lego.simpleauth.event.entity.player;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.server.network.ServerPlayerEntity;
public interface PlayerJoinServerCallback {
Event<PlayerJoinServerCallback> EVENT = EventFactory.createArrayBacked(PlayerJoinServerCallback.class, listeners -> (player) -> {
for (PlayerJoinServerCallback callback : listeners) {
callback.onPlayerJoin(player);
}
});
void onPlayerJoin(ServerPlayerEntity player);
}

View File

@ -1,15 +0,0 @@
package org.samo_lego.simpleauth.event.entity.player;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.server.network.ServerPlayerEntity;
public interface PlayerLeaveServerCallback {
Event<PlayerLeaveServerCallback> EVENT = EventFactory.createArrayBacked(PlayerLeaveServerCallback.class, listeners -> (player) -> {
for (PlayerLeaveServerCallback callback : listeners) {
callback.onPlayerLeave(player);
}
});
void onPlayerLeave(ServerPlayerEntity player);
}

View File

@ -1,21 +0,0 @@
package org.samo_lego.simpleauth.event.entity.player;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.ActionResult;
public interface PlayerMoveCallback {
Event<PlayerMoveCallback> EVENT = EventFactory.createArrayBacked(PlayerMoveCallback.class, listeners -> (player) -> {
for (PlayerMoveCallback event : listeners) {
ActionResult result = event.onPlayerMove(player);
if (result != ActionResult.PASS) {
return result;
}
}
return ActionResult.PASS;
});
ActionResult onPlayerMove(PlayerEntity player);
}

View File

@ -1,28 +0,0 @@
package org.samo_lego.simpleauth.event.entity.player;
import com.mojang.authlib.GameProfile;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.server.PlayerManager;
import net.minecraft.text.LiteralText;
import java.net.SocketAddress;
public interface PrePlayerJoinCallback {
Event<PrePlayerJoinCallback> EVENT = EventFactory.createArrayBacked(
PrePlayerJoinCallback.class, listeners -> (
socketAddress, profile, manager
) -> {
for (PrePlayerJoinCallback event : listeners) {
LiteralText returnText = event.checkCanPlayerJoinServer(socketAddress, profile, manager);
if (returnText != null) {
return returnText;
}
}
return null;
});
LiteralText checkCanPlayerJoinServer(SocketAddress socketAddress, GameProfile profile, PlayerManager manager);
}

View File

@ -1,20 +0,0 @@
package org.samo_lego.simpleauth.event.item;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.ActionResult;
public interface DropItemCallback {
Event<DropItemCallback> EVENT = EventFactory.createArrayBacked(DropItemCallback.class, listeners -> (player) -> {
for (DropItemCallback event : listeners) {
ActionResult result = event.onDropItem(player);
if (result != ActionResult.PASS) {
return result;
}
}
return ActionResult.PASS;
});
ActionResult onDropItem(PlayerEntity player);
}

View File

@ -1,20 +0,0 @@
package org.samo_lego.simpleauth.event.item;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.ActionResult;
public interface TakeItemCallback {
Event<TakeItemCallback> EVENT = EventFactory.createArrayBacked(TakeItemCallback.class, listeners -> (player) -> {
for (TakeItemCallback event : listeners) {
ActionResult result = event.onTakeItem(player);
if (result != ActionResult.PASS) {
return result;
}
}
return ActionResult.PASS;
});
ActionResult onTakeItem(PlayerEntity player);
}