Skip to content

Commit

Permalink
Raname packages
Browse files Browse the repository at this point in the history
  • Loading branch information
NikitaCartes committed Jul 15, 2021
1 parent 1b77730 commit 6e14895
Show file tree
Hide file tree
Showing 31 changed files with 247 additions and 260 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
## Simple Authentication Mod
## Easy Authentication Mod

Since samo_lego deprecated his mod, I consider updating it to the latest version.

For Minecraft 1.16 and below you can check [original repository](https://github.com/samolego/SimpleAuth).

See [wiki](https://github.com/samolego/SimpleAuth/wiki) for more information.
See [wiki](https://github.com/NikitaCartes/EasyAuth/wiki) for more information.

## License
Libraries that the project is using:
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ minecraft {
}

loom {
accessWidener("src/main/resources/simpleauth.accesswidener")
accessWidener("src/main/resources/easyauth.accesswidener")
}

// Declare dependencies
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package org.samo_lego.simpleauth;
package xyz.nikitacartes.easyauth;

import net.fabricmc.api.ModInitializer;
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.storage.AuthConfig;
import org.samo_lego.simpleauth.storage.DBHelper;
import org.samo_lego.simpleauth.storage.PlayerCache;
import xyz.nikitacartes.easyauth.commands.*;
import xyz.nikitacartes.easyauth.event.AuthEventHandler;
import xyz.nikitacartes.easyauth.storage.AuthConfig;
import xyz.nikitacartes.easyauth.storage.DBHelper;
import xyz.nikitacartes.easyauth.storage.PlayerCache;
import xyz.nikitacartes.easyauth.utils.EasyLogger;

import java.io.File;
import java.io.FileReader;
Expand All @@ -23,10 +24,7 @@
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

import static org.samo_lego.simpleauth.utils.SimpleLogger.logError;
import static org.samo_lego.simpleauth.utils.SimpleLogger.logInfo;

public class SimpleAuth implements ModInitializer {
public class EasyAuth implements ModInitializer {
public static final String MOD_ID = "easyauth";


Expand Down Expand Up @@ -61,14 +59,14 @@ public class SimpleAuth implements ModInitializer {

public static void init(Path gameDir) {
gameDirectory = gameDir;
logInfo("EasyAuth mod by samo_lego, NikitaCartes.");
EasyLogger.logInfo("EasyAuth mod by samo_lego, NikitaCartes.");
// 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());
EasyLogger.logError("Error while reading server properties: " + e.getMessage());
}

// Creating data directory (database and config files are stored there)
Expand All @@ -85,7 +83,7 @@ public static void init(Path gameDir) {
* Called on server stop.
*/
public static void stop() {
logInfo("Shutting down EasyAuth.");
EasyLogger.logInfo("Shutting down EasyAuth.");
DB.saveAll(playerCacheMap);

// Closing threads
Expand All @@ -95,7 +93,7 @@ public static void stop() {
Thread.currentThread().interrupt();
}
} catch (InterruptedException e) {
logError(e.getMessage());
EasyLogger.logError(e.getMessage());
THREADPOOL.shutdownNow();
}

Expand All @@ -105,7 +103,7 @@ public static void stop() {

@Override
public void onInitialize() {
SimpleAuth.init(FabricLoader.getInstance().getGameDir());
EasyAuth.init(FabricLoader.getInstance().getGameDir());

// Registering the commands
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> {
Expand All @@ -127,6 +125,6 @@ public void onInitialize() {
}

private void onStopServer(MinecraftServer server) {
SimpleAuth.stop();
EasyAuth.stop();
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package org.samo_lego.simpleauth.commands;
package xyz.nikitacartes.easyauth.commands;

import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.LiteralText;
import org.samo_lego.simpleauth.utils.AuthHelper;
import org.samo_lego.simpleauth.utils.PlayerAuth;
import xyz.nikitacartes.easyauth.utils.AuthHelper;
import xyz.nikitacartes.easyauth.utils.PlayerAuth;

import static com.mojang.brigadier.arguments.StringArgumentType.getString;
import static com.mojang.brigadier.arguments.StringArgumentType.word;
import static net.minecraft.server.command.CommandManager.argument;
import static net.minecraft.server.command.CommandManager.literal;
import static org.samo_lego.simpleauth.SimpleAuth.*;
import static xyz.nikitacartes.easyauth.EasyAuth.*;

public class AccountCommand {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.samo_lego.simpleauth.commands;
package xyz.nikitacartes.easyauth.commands;

import com.mojang.brigadier.CommandDispatcher;
import net.minecraft.command.argument.BlockPosArgumentType;
Expand All @@ -9,18 +9,18 @@
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.LiteralText;
import net.minecraft.util.Identifier;
import org.samo_lego.simpleauth.storage.AuthConfig;
import org.samo_lego.simpleauth.storage.PlayerCache;
import org.samo_lego.simpleauth.utils.AuthHelper;
import xyz.nikitacartes.easyauth.EasyAuth;
import xyz.nikitacartes.easyauth.storage.AuthConfig;
import xyz.nikitacartes.easyauth.storage.PlayerCache;
import xyz.nikitacartes.easyauth.utils.AuthHelper;
import xyz.nikitacartes.easyauth.utils.EasyLogger;

import java.io.File;

import static com.mojang.brigadier.arguments.StringArgumentType.getString;
import static com.mojang.brigadier.arguments.StringArgumentType.word;
import static net.minecraft.server.command.CommandManager.argument;
import static net.minecraft.server.command.CommandManager.literal;
import static org.samo_lego.simpleauth.SimpleAuth.*;
import static org.samo_lego.simpleauth.utils.SimpleLogger.logInfo;

public class AuthCommand {

Expand Down Expand Up @@ -110,12 +110,12 @@ public static void registerCommand(CommandDispatcher<ServerCommandSource> dispat
* @return 0
*/
public static int reloadConfig(Entity sender) {
config = AuthConfig.load(new File("./mods/EasyAuth/config.json"));
EasyAuth.config = AuthConfig.load(new File("./mods/EasyAuth/config.json"));

if(sender != null)
((PlayerEntity) sender).sendMessage(new LiteralText(config.lang.configurationReloaded), false);
((PlayerEntity) sender).sendMessage(new LiteralText(EasyAuth.config.lang.configurationReloaded), false);
else
logInfo(config.lang.configurationReloaded);
EasyLogger.logInfo(EasyAuth.config.lang.configurationReloaded);
return 1;
}

Expand All @@ -130,17 +130,17 @@ private static int setGlobalPassword(ServerCommandSource source, String password
// Getting the player who send the command
Entity sender = source.getEntity();
// Different thread to avoid lag spikes
THREADPOOL.submit(() -> {
EasyAuth.THREADPOOL.submit(() -> {
// Writing the global pass to config
config.main.globalPassword = AuthHelper.hashPassword(password.toCharArray());
config.main.enableGlobalPassword = true;
config.save(new File("./mods/EasyAuth/config.json"));
EasyAuth.config.main.globalPassword = AuthHelper.hashPassword(password.toCharArray());
EasyAuth.config.main.enableGlobalPassword = true;
EasyAuth.config.save(new File("./mods/EasyAuth/config.json"));
});

if(sender != null)
((PlayerEntity) sender).sendMessage(new LiteralText(config.lang.globalPasswordSet), false);
((PlayerEntity) sender).sendMessage(new LiteralText(EasyAuth.config.lang.globalPasswordSet), false);
else
logInfo(config.lang.globalPasswordSet);
EasyLogger.logInfo(EasyAuth.config.lang.globalPasswordSet);
return 1;
}

Expand All @@ -158,21 +158,21 @@ private static int setGlobalPassword(ServerCommandSource source, String password
*/
private static int setSpawn(ServerCommandSource source, Identifier world, double x, double y, double z, float yaw, float pitch) {
// Setting config values and saving
config.worldSpawn.dimension = String.valueOf(world);
config.worldSpawn.x = x;
config.worldSpawn.y = y;
config.worldSpawn.z = z;
config.worldSpawn.yaw = yaw;
config.worldSpawn.pitch = pitch;
config.main.spawnOnJoin = true;
config.save(new File("./mods/EasyAuth/config.json"));
EasyAuth.config.worldSpawn.dimension = String.valueOf(world);
EasyAuth.config.worldSpawn.x = x;
EasyAuth.config.worldSpawn.y = y;
EasyAuth.config.worldSpawn.z = z;
EasyAuth.config.worldSpawn.yaw = yaw;
EasyAuth.config.worldSpawn.pitch = pitch;
EasyAuth.config.main.spawnOnJoin = true;
EasyAuth.config.save(new File("./mods/EasyAuth/config.json"));

// Getting sender
Entity sender = source.getEntity();
if(sender != null)
((PlayerEntity) sender).sendMessage(new LiteralText(config.lang.worldSpawnSet), false);
((PlayerEntity) sender).sendMessage(new LiteralText(EasyAuth.config.lang.worldSpawnSet), false);
else
logInfo(config.lang.worldSpawnSet);
EasyLogger.logInfo(EasyAuth.config.lang.worldSpawnSet);
return 1;
}

Expand All @@ -185,15 +185,15 @@ private static int setSpawn(ServerCommandSource source, Identifier world, double
*/
private static int removeAccount(ServerCommandSource source, String uuid) {
Entity sender = source.getEntity();
THREADPOOL.submit(() -> {
DB.deleteUserData(uuid);
playerCacheMap.put(uuid, null);
EasyAuth.THREADPOOL.submit(() -> {
EasyAuth.DB.deleteUserData(uuid);
EasyAuth.playerCacheMap.put(uuid, null);
});

if(sender != null)
((PlayerEntity) sender).sendMessage(new LiteralText(config.lang.userdataDeleted), false);
((PlayerEntity) sender).sendMessage(new LiteralText(EasyAuth.config.lang.userdataDeleted), false);
else
logInfo(config.lang.userdataDeleted);
EasyLogger.logInfo(EasyAuth.config.lang.userdataDeleted);
return 1; // Success
}

Expand All @@ -209,22 +209,22 @@ private static int registerUser(ServerCommandSource source, String uuid, String
// Getting the player who send the command
Entity sender = source.getEntity();

THREADPOOL.submit(() -> {
EasyAuth.THREADPOOL.submit(() -> {
PlayerCache playerCache;
if(playerCacheMap.containsKey(uuid)) {
playerCache = playerCacheMap.get(uuid);
if(EasyAuth.playerCacheMap.containsKey(uuid)) {
playerCache = EasyAuth.playerCacheMap.get(uuid);
}
else {
playerCache = PlayerCache.fromJson(null, uuid);
}

playerCacheMap.put(uuid, playerCache);
playerCacheMap.get(uuid).password = AuthHelper.hashPassword(password.toCharArray());
EasyAuth.playerCacheMap.put(uuid, playerCache);
EasyAuth.playerCacheMap.get(uuid).password = AuthHelper.hashPassword(password.toCharArray());

if (sender != null)
((PlayerEntity) sender).sendMessage(new LiteralText(config.lang.userdataUpdated), false);
((PlayerEntity) sender).sendMessage(new LiteralText(EasyAuth.config.lang.userdataUpdated), false);
else
logInfo(config.lang.userdataUpdated);
EasyLogger.logInfo(EasyAuth.config.lang.userdataUpdated);
});
return 0;
}
Expand All @@ -241,29 +241,29 @@ private static int updatePassword(ServerCommandSource source, String uuid, Strin
// Getting the player who send the command
Entity sender = source.getEntity();

THREADPOOL.submit(() -> {
EasyAuth.THREADPOOL.submit(() -> {
PlayerCache playerCache;
if(playerCacheMap.containsKey(uuid)) {
playerCache = playerCacheMap.get(uuid);
if(EasyAuth.playerCacheMap.containsKey(uuid)) {
playerCache = EasyAuth.playerCacheMap.get(uuid);
}
else {
playerCache = PlayerCache.fromJson(null, uuid);
}

playerCacheMap.put(uuid, playerCache);
if(!playerCacheMap.get(uuid).password.isEmpty()) {
EasyAuth.playerCacheMap.put(uuid, playerCache);
if(!EasyAuth.playerCacheMap.get(uuid).password.isEmpty()) {
if (sender != null)
((PlayerEntity) sender).sendMessage(new LiteralText(config.lang.userNotRegistered), false);
((PlayerEntity) sender).sendMessage(new LiteralText(EasyAuth.config.lang.userNotRegistered), false);
else
logInfo(config.lang.userNotRegistered);
EasyLogger.logInfo(EasyAuth.config.lang.userNotRegistered);
return;
}
playerCacheMap.get(uuid).password = AuthHelper.hashPassword(password.toCharArray());
EasyAuth.playerCacheMap.get(uuid).password = AuthHelper.hashPassword(password.toCharArray());

if (sender != null)
((PlayerEntity) sender).sendMessage(new LiteralText(config.lang.userdataUpdated), false);
((PlayerEntity) sender).sendMessage(new LiteralText(EasyAuth.config.lang.userdataUpdated), false);
else
logInfo(config.lang.userdataUpdated);
EasyLogger.logInfo(EasyAuth.config.lang.userdataUpdated);
});
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package org.samo_lego.simpleauth.commands;
package xyz.nikitacartes.easyauth.commands;

import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.LiteralText;
import org.samo_lego.simpleauth.utils.AuthHelper;
import org.samo_lego.simpleauth.utils.PlayerAuth;
import xyz.nikitacartes.easyauth.utils.AuthHelper;
import xyz.nikitacartes.easyauth.utils.PlayerAuth;

import static com.mojang.brigadier.arguments.StringArgumentType.getString;
import static com.mojang.brigadier.arguments.StringArgumentType.word;
import static net.minecraft.server.command.CommandManager.argument;
import static net.minecraft.server.command.CommandManager.literal;
import static org.samo_lego.simpleauth.SimpleAuth.*;
import static xyz.nikitacartes.easyauth.EasyAuth.*;

public class LoginCommand {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package org.samo_lego.simpleauth.commands;
package xyz.nikitacartes.easyauth.commands;

import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.LiteralText;
import org.samo_lego.simpleauth.utils.PlayerAuth;
import xyz.nikitacartes.easyauth.utils.PlayerAuth;

import static net.minecraft.server.command.CommandManager.literal;
import static org.samo_lego.simpleauth.SimpleAuth.config;
import static org.samo_lego.simpleauth.SimpleAuth.mojangAccountNamesCache;
import static xyz.nikitacartes.easyauth.EasyAuth.config;
import static xyz.nikitacartes.easyauth.EasyAuth.mojangAccountNamesCache;

public class LogoutCommand {

Expand Down
Loading

0 comments on commit 6e14895

Please sign in to comment.