diff --git a/src/main/java/org/ultramine/commands/basic/VanillaCommands.java b/src/main/java/org/ultramine/commands/basic/VanillaCommands.java index a202d38..33050c5 100644 --- a/src/main/java/org/ultramine/commands/basic/VanillaCommands.java +++ b/src/main/java/org/ultramine/commands/basic/VanillaCommands.java @@ -13,9 +13,11 @@ import net.minecraft.util.StatCollector; import static net.minecraft.util.EnumChatFormatting.*; import net.minecraft.world.EnumDifficulty; +import net.minecraft.world.GameRules; import net.minecraft.world.WorldServer; import net.minecraft.world.storage.WorldInfo; +import org.apache.commons.lang3.StringUtils; import org.ultramine.commands.Command; import org.ultramine.commands.CommandContext; import org.ultramine.commands.IExtendedCommand; @@ -240,4 +242,46 @@ ctx.sendMessage("commands.time.added", time); } } + + @Command( + name = "gamerule", + group = "vanilla", + permissions = {"command.vanilla.difficulty"}, + syntax = { + "", + "", + " ", + " ", + " " + } + ) + public static void gamerule(CommandContext ctx) + { + GameRules rules = (ctx.contains("world") ? ctx.get("world").asWorld() : ctx.getSenderAsPlayer().getServerForPlayer()).getGameRules(); + if(ctx.contains("value")) + { + String key = ctx.get("key").asString(); + if(rules.hasRule(key)) + { + rules.setOrCreateGameRule(key, ctx.get("value").asString()); + ctx.sendMessage("commands.gamerule.success"); + } + else + { + ctx.sendMessage("commands.gamerule.norule", key); + } + } + else if(ctx.contains("key")) + { + String key = ctx.get("key").asString(); + if(rules.hasRule(key)) + ctx.sendMessage("%s = %s", key, rules.getGameRuleStringValue(key)); + else + ctx.sendMessage("commands.gamerule.norule", key); + } + else + { + ctx.sendMessage(StringUtils.join(rules.getRules(), ", ")); + } + } }