Skip to content

Commit

Permalink
Remove Redis from Project
Browse files Browse the repository at this point in the history
  • Loading branch information
DaNussi committed Mar 22, 2024
1 parent 5d5d93d commit 804a71f
Show file tree
Hide file tree
Showing 20 changed files with 23 additions and 1,198 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ dependencies {

// REDIS DB
// minecraftLibrary jarJar('redis.clients:jedis:3.6.0')
minecraftLibrary jarJar(group: 'redis.clients', name: 'jedis', version: '[3.6.0,)')
// minecraftLibrary jarJar(group: 'redis.clients', name: 'jedis', version: '[3.6.0,)')
// minecraftLibrary jarJar('org.apache.commons:commons-pool2:2.11.1')
minecraftLibrary jarJar(group: 'org.apache.commons', name: 'commons-pool2', version: '[2.11.1,)')
// minecraftLibrary jarJar(group: 'org.apache.commons', name: 'commons-pool2', version: '[2.11.1,)')

// For more info...
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,11 @@

import com.mojang.logging.LogUtils;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.server.ServerStartingEvent;
import net.minecraftforge.event.server.ServerStoppingEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.nussi.dedicated_applied_energistics.modules.InfluxLogger;
import net.nussi.dedicated_applied_energistics.modules.VirtualInventory;
import net.nussi.dedicated_applied_energistics.providers.InterDimensionalInterfaceStorage;
import org.slf4j.Logger;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@Mod.EventBusSubscriber(modid = DedicatedAppliedEnegistics.MODID)
public class DedicatedAppliedEnergisticsController {
Expand All @@ -44,134 +33,14 @@ public class DedicatedAppliedEnergisticsController {
}


public static boolean IsRunning = false;

public static String Start() {
if(IsRunning) return "DAE2 already started!";


controllables.forEach(controllable -> {
try {
controllable.externalStart();
} catch (Exception e) {
LOGGER.error(e.getMessage());
e.printStackTrace();
}
});
if(CONFIG_VALUE_BEHAVIOUR_VIRTUAL_INVENTORY.get()) VirtualInventory.Init();
if(CONFIG_VALUE_BEHAVIOUR_INFLUXDB_LOGGER.get()) InfluxLogger.Init();

IsRunning = true;
return "OK";
}

public static String Stop() {
IsRunning = false;

controllables.forEach(controllable -> {
try {
controllable.externalStop();
} catch (Exception e) {
LOGGER.error(e.getMessage());
e.printStackTrace();
}
});
VirtualInventory.Reset();
InfluxLogger.Reset();
if(jedisPool != null) jedisPool.close();

return "OK";
}

public static String Reset() {
String status = Stop();

CONFIG_VALUE_REDIS_URI.set(CONFIG_VALUE_REDIS_URI.getDefault());

CONFIG_VALUE_BEHAVIOUR_AUTOSTART.set(CONFIG_VALUE_BEHAVIOUR_AUTOSTART.getDefault());
CONFIG_VALUE_BEHAVIOUR_VIRTUAL_INVENTORY.set(CONFIG_VALUE_BEHAVIOUR_VIRTUAL_INVENTORY.getDefault());

return status;
}

public static JedisPool jedisPool;
public static Jedis getJedis() {
if(jedisPool == null) {
jedisPool = new JedisPool(new JedisPoolConfig(), CONFIG_VALUE_REDIS_URI.get());
}
return jedisPool.getResource();

// Jedis jedis = new Jedis(CONFIG_VALUE_REDIS_URI.get());
// return jedis;
}


@SubscribeEvent
public static void onServerStopping(ServerStoppingEvent event) throws Exception {
Stop();
// Stop();
}

@SubscribeEvent
public static void onServerStarting(ServerStartingEvent event) throws Exception {
if(CONFIG_VALUE_BEHAVIOUR_AUTOSTART.get()) Start();
}

public static List<Controllable> controllables = new ArrayList<>();
public static void addControllable(Controllable controllable) {
controllables.add(controllable);
}

public static abstract class Controllable {
private final List<Jedis> jedisInstances = new ArrayList<>();
private boolean running = false;
private Thread internalThread;

public Controllable() {
DedicatedAppliedEnergisticsController.addControllable(this);
if(DedicatedAppliedEnergisticsController.IsRunning && !this.isRunning()) this.externalStart();
}

protected abstract void onStart();
protected abstract void onStop();

public Jedis getJedis() {
Jedis jedis = DedicatedAppliedEnergisticsController.getJedis();
jedisInstances.add(jedis);
return jedis;
}

protected boolean isRunning() {
return running;
}

public void externalStart() {
if(isRunning()) {
LOGGER.warn("Controllable already running!");
return;
}
this.internalThread = new Thread(this::onStart);
this.internalThread.start();
this.running = true;
}

public void externalStop() {
if(!isRunning()) {
LOGGER.warn("Controllable already stopped!");
return;
}
this.running = false;

if(this.internalThread != null) {
this.internalThread.interrupt();
this.internalThread = null;
}

this.onStop();

jedisInstances.forEach(Jedis::disconnect);
jedisInstances.forEach(Jedis::close);
jedisInstances.clear();
}
// if(CONFIG_VALUE_BEHAVIOUR_AUTOSTART.get()) Start();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public InterDimensionalInterfaceBlockEntity(BlockPos pos, BlockState state) {
this.getMainNode().addService(ICraftingProvider.class, this);
this.crafting = new InterDimensionalInterfaceCrafting(this);

this.storage.onStart();
this.crafting.onStart();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.nussi.dedicated_applied_energistics.commands;

import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.logging.LogUtils;
import net.minecraft.commands.CommandSourceStack;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package net.nussi.dedicated_applied_energistics.commands;

import com.mojang.brigadier.builder.ArgumentBuilder;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;

public interface Command {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
package net.nussi.dedicated_applied_energistics.commands;


import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.logging.LogUtils;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component;
import net.minecraftforge.common.ForgeConfigSpec;
import net.nussi.dedicated_applied_energistics.DedicatedAppliedEnergisticsController;
import net.nussi.dedicated_applied_energistics.modules.InfluxLogger;
import net.nussi.dedicated_applied_energistics.modules.VirtualInventory;
import org.slf4j.Logger;
import redis.clients.jedis.util.JedisURIHelper;

import java.net.URI;
import java.net.URISyntaxException;

public class ConfigCommand implements Command {
private static final Logger LOGGER = LogUtils.getLogger();
Expand All @@ -35,23 +25,11 @@ public LiteralArgumentBuilder<CommandSourceStack> ConfigureCommand(LiteralArgume
}

private static int config(CommandSourceStack commandSourceStack, String uri) {
try {
if(!JedisURIHelper.isValid(new URI(uri))) {
commandSourceStack.sendSystemMessage(Component.literal("Invalid redis uri!"));
return 1;
}
} catch (URISyntaxException e) {
commandSourceStack.sendSystemMessage(Component.literal("Invalid redis uri!"));
return 1;
}

DedicatedAppliedEnergisticsController.CONFIG_VALUE_REDIS_URI.set(uri);
commandSourceStack.sendSystemMessage(Component.literal("Set redis uri to: " + uri));
return 1;
}

private static int reset(CommandSourceStack commandSourceStack) {
DedicatedAppliedEnergisticsController.Reset();
commandSourceStack.sendSystemMessage(Component.literal("Reset config and stopped!"));
return 1;
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.nussi.dedicated_applied_energistics.commands;

import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.logging.LogUtils;
import net.minecraft.commands.CommandSourceStack;
Expand All @@ -22,10 +21,7 @@ public LiteralArgumentBuilder<CommandSourceStack> ConfigureCommand(LiteralArgume

private static int status(CommandSourceStack commandSourceStack) {
commandSourceStack.sendSystemMessage(Component.literal(
"IsRunning: " + DedicatedAppliedEnergisticsController.IsRunning + "\n" +
"Redis URI: " + DedicatedAppliedEnergisticsController.CONFIG_VALUE_REDIS_URI.get() + "\n" +
"Autostart: " + DedicatedAppliedEnergisticsController.CONFIG_VALUE_BEHAVIOUR_AUTOSTART.get() + "\n" +
"VirtualInventory: " + DedicatedAppliedEnergisticsController.CONFIG_VALUE_BEHAVIOUR_VIRTUAL_INVENTORY.get() + ""
"Autostart: " + DedicatedAppliedEnergisticsController.CONFIG_VALUE_BEHAVIOUR_AUTOSTART.get() + ""
));
return 1;
}
Expand Down

This file was deleted.

Loading

0 comments on commit 804a71f

Please sign in to comment.