forked from iguanaman/HungerOverhaul
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a command to reload the jsons so the end user does not have to re…
…load the client/server every time. Closes #141
- Loading branch information
alexbegt
committed
May 6, 2017
1 parent
a9e6154
commit 7b70164
Showing
6 changed files
with
180 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/iguanaman/hungeroverhaul/module/commands/Commands.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
src/main/java/iguanaman/hungeroverhaul/module/commands/HOCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/iguanaman/hungeroverhaul/module/commands/sub/ISubCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/iguanaman/hungeroverhaul/module/commands/sub/ReloadJson.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters