Skip to content

Commit

Permalink
Add a command to reload the jsons so the end user does not have to re…
Browse files Browse the repository at this point in the history
…load the client/server every time. Closes #141
  • Loading branch information
alexbegt committed May 6, 2017
1 parent a9e6154 commit 7b70164
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/main/java/iguanaman/hungeroverhaul/HungerOverhaul.java
@@ -1,12 +1,15 @@
package iguanaman.hungeroverhaul;

import java.io.File;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import iguanaman.hungeroverhaul.common.config.Config;
import iguanaman.hungeroverhaul.library.Util;
import iguanaman.hungeroverhaul.module.biomesoplenty.BiomesOPlentyModule;
import iguanaman.hungeroverhaul.module.bonemeal.BonemealModule;
import iguanaman.hungeroverhaul.module.commands.HOCommand;
import iguanaman.hungeroverhaul.module.event.HungerOverhaulEventHook;
import iguanaman.hungeroverhaul.module.event.IMCHandler;
import iguanaman.hungeroverhaul.module.food.FoodEventHandler;
Expand Down Expand Up @@ -35,6 +38,7 @@
import net.minecraftforge.fml.common.event.FMLInterModComms.IMCEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;

@Mod(modid = HungerOverhaul.modID, name = HungerOverhaul.modName, version = HungerOverhaul.modVersion, dependencies = "required-after:Forge@[12.18.0.1993,);required-after:AppleCore;after:tconstruct;after:harvestcraft;after:natura@[${natura_version},);after:ic2;after:*", acceptedMinecraftVersions = "[1.10.2, 1.11)")
public class HungerOverhaul
Expand All @@ -53,12 +57,16 @@ public class HungerOverhaul

public static Potion potionWellFed;

public static File configPath;

@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
Config.load(event);

JsonModule.preinit(event.getModConfigurationDirectory());
configPath = event.getModConfigurationDirectory();

JsonModule.preinit(configPath);

potionWellFed = new PotionWellFed();
}
Expand Down Expand Up @@ -119,6 +127,12 @@ public void postInit(FMLPostInitializationEvent event)
MinecraftForge.EVENT_BUS.register(new LootModule());
}

@EventHandler
private void serverStarting(final FMLServerStartingEvent evt)
{
evt.registerServerCommand(new HOCommand(evt.getServer()));
}

@EventHandler
public void handleIMCMessages(IMCEvent event)
{
Expand Down
@@ -0,0 +1,25 @@
package iguanaman.hungeroverhaul.module.commands;

import iguanaman.hungeroverhaul.module.commands.sub.ISubCommand;
import iguanaman.hungeroverhaul.module.commands.sub.ReloadJson;

public enum Commands
{
ReloadJson(4, new ReloadJson());

public final int level;

public final ISubCommand command;

Commands(final int level, final ISubCommand w)
{
this.level = level;
this.command = w;
}

@Override
public String toString()
{
return this.name();
}
}
@@ -0,0 +1,94 @@
package iguanaman.hungeroverhaul.module.commands;

import com.google.common.base.Joiner;

import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.command.WrongUsageException;
import net.minecraft.server.MinecraftServer;

public final class HOCommand extends CommandBase
{
private final MinecraftServer server;

public HOCommand(final MinecraftServer server)
{
this.server = server;
}

@Override
public int getRequiredPermissionLevel()
{
return 0;
}

@Override
public String getCommandName()
{
return "hungeroverhaul";
}

@Override
public String getCommandUsage(final ICommandSender icommandsender)
{
return "commands.hungeroverhaul.usage";
}

@Override
public void execute(final MinecraftServer server, final ICommandSender sender, final String[] args) throws CommandException
{
if (args.length == 0)
{
throw new WrongUsageException("commands.hungeroverhaul.usage");
}
else if ("help".equals(args[0]))
{
try
{
if (args.length > 1)
{
final Commands c = Commands.valueOf(args[1]);

throw new WrongUsageException(c.command.getHelp(this.server));
}
}
catch (final WrongUsageException wrong)
{
throw wrong;
}
catch (final Throwable er)
{
throw new WrongUsageException("commands.hungeroverhaul.usage");
}
}
else if ("list".equals(args[0]))
{
throw new WrongUsageException(Joiner.on(", ").join(Commands.values()));
}
else
{
try
{
final Commands c = Commands.valueOf(args[0]);

if (sender.canCommandSenderUseCommand(c.level, this.getCommandName()))
{
c.command.call(this.server, args, sender);
}
else
{
throw new WrongUsageException("commands.hungeroverhaul.permissions");
}
}
catch (final WrongUsageException wrong)
{
throw wrong;
}
catch (final Throwable er)
{
throw new WrongUsageException("commands.hungeroverhaul.usage");
}
}
}
}
@@ -0,0 +1,11 @@
package iguanaman.hungeroverhaul.module.commands.sub;

import net.minecraft.command.ICommandSender;
import net.minecraft.server.MinecraftServer;

public interface ISubCommand
{
String getHelp(MinecraftServer srv);

void call(MinecraftServer srv, String[] args, ICommandSender sender);
}
@@ -0,0 +1,26 @@
package iguanaman.hungeroverhaul.module.commands.sub;

import iguanaman.hungeroverhaul.HungerOverhaul;
import iguanaman.hungeroverhaul.module.json.JsonModule;
import net.minecraft.command.ICommandSender;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.text.TextComponentTranslation;

public class ReloadJson implements ISubCommand
{
@Override
public String getHelp(MinecraftServer srv)
{
return "commands.hungeroverhaul.ReloadJson";
}

@Override
public void call(MinecraftServer srv, String[] args, ICommandSender sender)
{
JsonModule.preinit(HungerOverhaul.configPath);

JsonModule.init();

sender.addChatMessage(new TextComponentTranslation("commands.hungeroverhaul.JsonReloaded"));
}
}
10 changes: 9 additions & 1 deletion src/main/resources/assets/hungeroverhaul/lang/en_US.lang
Expand Up @@ -30,4 +30,12 @@ ui.health.injured=Injured
ui.health.hurt=Hurt
ui.hunger.starving=Starving
ui.hunger.hungry=Hungry
ui.hunger.peckish=Peckish
ui.hunger.peckish=Peckish

#######################
# Command Strings #
#######################
commands.hungeroverhaul.usage=Commands provided by Hunger Overhaul - use /hungeroverhaul list for a list, and /hungeroverhaul help _____ for help with a command.
commands.hungeroverhaul.permissions=You do not have adequate permissions to run this command.
commands.hungeroverhaul.ReloadJson=Reloads the json's to test modifications to food without having to restart your client ( OP )
commands.hungeroverhaul.JsonReloaded=Json module has been reloaded!

0 comments on commit 7b70164

Please sign in to comment.