Skip to content

Commit

Permalink
Fixed exceptions, initialization protection is not required in consol…
Browse files Browse the repository at this point in the history
…e commands
  • Loading branch information
OldSerpskiStalker committed Sep 24, 2024
1 parent e1dc6ef commit b4ae194
Show file tree
Hide file tree
Showing 15 changed files with 23 additions and 173 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.imesense.dynamicspawncontrol;

import jdk.nashorn.internal.runtime.StoredScript;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
Expand All @@ -24,6 +25,7 @@
import org.imesense.dynamicspawncontrol.technical.parsers.ParserGenericJsonScripts;
import org.imesense.dynamicspawncontrol.technical.parsers.ParserManager;
import org.imesense.dynamicspawncontrol.technical.proxy.IProxy;
import org.imesense.dynamicspawncontrol.technical.worldcache.Cache;
import org.imesense.dynamicspawncontrol.technical.worldcache.CacheStorage;

import java.io.File;
Expand Down Expand Up @@ -270,8 +272,7 @@ public synchronized void serverLoad(FMLServerStartingEvent event)
@EventHandler
public synchronized void serverStopped(FMLServerStoppedEvent event)
{
Cache.cleanCache();
Structures.STRUCTURES_CACHE.clean();

Log.closeExecutor();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,11 @@
*/
public final class cmdAdminDumpBlock extends CommandBase
{
/**
*
*/
private static boolean instanceExists = false;

/**
*
*/
public cmdAdminDumpBlock()
{
if (instanceExists)
{
Log.writeDataToLogFile(2, String.format("An instance of [%s] already exists!", this.getClass().getSimpleName()));
throw new RuntimeException();
}

instanceExists = true;

CodeGenericUtils.printInitClassToLog(cmdAdminDumpBlock.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,11 @@
*/
public final class cmdAdminDumpEntity extends CommandBase
{
/**
*
*/
private static boolean instanceExists = false;

/**
*
*/
public cmdAdminDumpEntity()
{
if (instanceExists)
{
Log.writeDataToLogFile(2, String.format("An instance of [%s] already exists!", this.getClass().getSimpleName()));
throw new RuntimeException();
}

instanceExists = true;

CodeGenericUtils.printInitClassToLog(cmdAdminDumpEntity.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,11 @@
*/
public final class cmdAdminDumpItem extends CommandBase
{
/**
*
*/
private static boolean instanceExists = false;

/**
*
*/
public cmdAdminDumpItem()
{
if (instanceExists)
{
Log.writeDataToLogFile(2, String.format("An instance of [%s] already exists!", this.getClass().getSimpleName()));
throw new RuntimeException();
}

instanceExists = true;

CodeGenericUtils.printInitClassToLog(cmdAdminDumpItem.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,11 @@
*/
public final class cmdAdminGameMode extends CommandBase
{
/**
*
*/
private static boolean instanceExists = false;

/**
*
*/
public cmdAdminGameMode()
{
if (instanceExists)
{
Log.writeDataToLogFile(2, String.format("An instance of [%s] already exists!", this.getClass().getSimpleName()));
throw new RuntimeException();
}

instanceExists = true;

CodeGenericUtils.printInitClassToLog(cmdAdminGameMode.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,11 @@
*/
public final class cmdAdminGetWorldMoonPhase extends CommandBase
{
/**
*
*/
private static boolean instanceExists = false;

/**
*
*/
public cmdAdminGetWorldMoonPhase()
{
if (instanceExists)
{
Log.writeDataToLogFile(2, String.format("An instance of [%s] already exists!", this.getClass().getSimpleName()));
throw new RuntimeException();
}

instanceExists = true;

CodeGenericUtils.printInitClassToLog(cmdAdminGetWorldMoonPhase.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,11 @@
*/
public final class cmdAdminLaunchFireball extends CommandBase
{
/**
*
*/
private static boolean instanceExists = false;

/**
*
*/
public cmdAdminLaunchFireball()
{
if (instanceExists)
{
Log.writeDataToLogFile(2, String.format("An instance of [%s] already exists!", this.getClass().getSimpleName()));
throw new RuntimeException();
}

instanceExists = true;

CodeGenericUtils.printInitClassToLog(cmdAdminLaunchFireball.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,11 @@
*/
public final class cmdAdminScanEntities extends CommandBase
{
/**
*
*/
private static boolean instanceExists = false;

/**
*
*/
public cmdAdminScanEntities()
{
if (instanceExists)
{
Log.writeDataToLogFile(2, String.format("An instance of [%s] already exists!", this.getClass().getSimpleName()));
throw new RuntimeException();
}

instanceExists = true;

CodeGenericUtils.printInitClassToLog(cmdAdminScanEntities.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,11 @@
*/
public final class cmdAdminSwitchVanish extends CommandBase
{
/**
*
*/
private static boolean instanceExists = false;

/**
*
*/
public cmdAdminSwitchVanish()
{
if (instanceExists)
{
Log.writeDataToLogFile(2, String.format("An instance of [%s] already exists!", this.getClass().getSimpleName()));
throw new RuntimeException();
}

instanceExists = true;

CodeGenericUtils.printInitClassToLog(cmdAdminSwitchVanish.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,11 @@
*/
public final class cmdServerJsonScriptsReload extends CommandBase
{
/**
*
*/
private static boolean instanceExists = false;

/**
*
*/
public cmdServerJsonScriptsReload()
{
if (instanceExists)
{
Log.writeDataToLogFile(2, String.format("An instance of [%s] already exists!", this.getClass().getSimpleName()));
throw new RuntimeException();
}

instanceExists = true;

CodeGenericUtils.printInitClassToLog(cmdServerJsonScriptsReload.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,11 @@
*/
public final class cmdServerMobsKiller extends CommandBase
{
/**
*
*/
private static boolean instanceExists = false;

/**
*
*/
public cmdServerMobsKiller()
{
if (instanceExists)
{
Log.writeDataToLogFile(2, String.format("An instance of [%s] already exists!", this.getClass().getSimpleName()));
throw new RuntimeException();
}

instanceExists = true;

CodeGenericUtils.printInitClassToLog(cmdServerMobsKiller.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,11 @@
*/
public final class cmdServerSingleScriptsReload extends CommandBase
{
/**
*
*/
private static boolean instanceExists = false;

/**
*
*/
public cmdServerSingleScriptsReload()
{
if (instanceExists)
{
Log.writeDataToLogFile(2, String.format("An instance of [%s] already exists!", this.getClass().getSimpleName()));
throw new RuntimeException();
}

instanceExists = true;

CodeGenericUtils.printInitClassToLog(cmdServerSingleScriptsReload.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ public final class Log
*/
private static File logFile;

/**
*
*/
public static final int LEVEL_INFO = 0;
public static final int LEVEL_WARN = 1;
public static final int LEVEL_ERROR = 2;

/**
*
*/
Expand Down Expand Up @@ -76,8 +69,6 @@ public static void createLogFile(final String path)
writer.write("\n*******************************************************************");

writer.close();

System.out.println("The file was successfully created: " + logFile.getAbsolutePath());
}
catch (IOException exception)
{
Expand Down Expand Up @@ -127,8 +118,6 @@ private static void cleanFile(File file, int maxLines)
}

writer.close();

System.out.println("The file was successfully updated.");
}
else
{
Expand Down Expand Up @@ -158,7 +147,7 @@ public static void writeDataToLogFile(final int levelInfo, String data)
{
if (logLevel[0] < 0 || logLevel[0] >= LEVEL_PREFIXES.length)
{
logLevel[0] = LEVEL_INFO;
logLevel[0] = 0;
}

FileWriter writer = new FileWriter(logFile, true);
Expand All @@ -167,24 +156,16 @@ public static void writeDataToLogFile(final int levelInfo, String data)
writer.close();

cleanFile(logFile, ConfigLogFile.LogMaxLines);
System.out.println("The data has been successfully written to the log file: " + logFile.getAbsolutePath());
}
catch (IOException exception)
{
System.err.println("Error writing data to a file: " + exception.getMessage());
}
});
} else
}
else
{
System.err.println("The log file has not been created. First, create a log file.");
}
}

/**
*
*/
public static void closeExecutor()
{
EXECUTOR.shutdown();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

/**
*
* OldSerpskiStalker:
* Console commands are loaded every time you enter the world.
* A constructor with protection is not required!
*/
public final class RegisterCommandsClasses
{
Expand Down
Loading

0 comments on commit b4ae194

Please sign in to comment.