mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-01-23 16:51:28 +01:00
Added "/mv gamerule" and "/mv gamerules" for setting and listing game rules per world. Fixes #987.
This commit is contained in:
parent
ebc2a516bb
commit
841f6f05df
@ -31,6 +31,8 @@ import com.onarandombox.MultiverseCore.commands.CreateCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.DebugCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.DeleteCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.EnvironmentCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.GameruleCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.GamerulesCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.GeneratorCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.HelpCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.ImportCommand;
|
||||
@ -823,6 +825,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
this.commandHandler.registerCommand(new GeneratorCommand(this));
|
||||
this.commandHandler.registerCommand(new CheckCommand(this));
|
||||
this.commandHandler.registerCommand(new ScriptCommand(this));
|
||||
this.commandHandler.registerCommand(new GameruleCommand(this));
|
||||
this.commandHandler.registerCommand(new GamerulesCommand(this));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,75 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Allows management of Anchor Destinations.
|
||||
*/
|
||||
public class GameruleCommand extends MultiverseCommand {
|
||||
|
||||
public GameruleCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Set a Minecraft Game Rule for a World.");
|
||||
this.setCommandUsage("/mv gamerule " + ChatColor.GREEN + "{RULE} {VALUE}" + ChatColor.GOLD + " [WORLD]");
|
||||
this.setArgRange(2, 3);
|
||||
this.addKey("mv gamerule");
|
||||
this.addKey("mv rule");
|
||||
this.addKey("mvgamerule");
|
||||
this.addKey("mvrule");
|
||||
this.addCommandExample("/mv gamerule " + ChatColor.GREEN + "doMobLoot false");
|
||||
this.addCommandExample("/mvrule " + ChatColor.GREEN + "keepInventory true " + ChatColor.RED + "world_nether");
|
||||
this.setPermission("multiverse.core.gamerule.set", "Allows a player to set a gamerule.", PermissionDefault.OP);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
// We NEED a world from the command line
|
||||
final Player p;
|
||||
if (sender instanceof Player) {
|
||||
p = (Player) sender;
|
||||
} else {
|
||||
p = null;
|
||||
}
|
||||
|
||||
if (args.size() == 2 && p == null) {
|
||||
sender.sendMessage("From the command line, WORLD is required.");
|
||||
sender.sendMessage(this.getCommandDesc());
|
||||
sender.sendMessage(this.getCommandUsage());
|
||||
sender.sendMessage("Nothing changed.");
|
||||
return;
|
||||
}
|
||||
|
||||
final String gameRule = args.get(0);
|
||||
final String value = args.get(1);
|
||||
final World world;
|
||||
if (args.size() == 2) {
|
||||
world = p.getWorld();
|
||||
} else {
|
||||
world = Bukkit.getWorld(args.get(2));
|
||||
}
|
||||
|
||||
if (world.setGameRuleValue(gameRule, value)) {
|
||||
sender.sendMessage(ChatColor.GREEN + "Success!" + ChatColor.WHITE + " Gamerule " + ChatColor.AQUA + gameRule
|
||||
+ ChatColor.WHITE + " was set to " + ChatColor.GREEN + value);
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "Failure!" + ChatColor.WHITE + " Gamerule " + ChatColor.AQUA + gameRule
|
||||
+ ChatColor.WHITE + " cannot be set to " + ChatColor.RED + value);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Allows management of Anchor Destinations.
|
||||
*/
|
||||
public class GamerulesCommand extends MultiverseCommand {
|
||||
|
||||
public GamerulesCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("List the Minecraft Game Rules for a World.");
|
||||
this.setCommandUsage("/mv gamerules" + ChatColor.GOLD + " [WORLD]");
|
||||
this.setArgRange(0, 1);
|
||||
this.addKey("mv gamerules");
|
||||
this.addKey("mv rules");
|
||||
this.addKey("mvgamerules");
|
||||
this.addKey("mvrules");
|
||||
this.addCommandExample("/mv gamerules");
|
||||
this.addCommandExample("/mvrules " + ChatColor.RED + "world_nether");
|
||||
this.setPermission("multiverse.core.gamerule.list", "Allows a player to list gamerules.", PermissionDefault.OP);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
// We NEED a world from the command line
|
||||
final Player p;
|
||||
if (sender instanceof Player) {
|
||||
p = (Player) sender;
|
||||
} else {
|
||||
p = null;
|
||||
}
|
||||
|
||||
if (args.size() == 0 && p == null) {
|
||||
sender.sendMessage("From the command line, WORLD is required.");
|
||||
sender.sendMessage(this.getCommandDesc());
|
||||
sender.sendMessage(this.getCommandUsage());
|
||||
sender.sendMessage("Nothing changed.");
|
||||
return;
|
||||
}
|
||||
|
||||
final World world;
|
||||
if (args.size() == 0) {
|
||||
world = p.getWorld();
|
||||
} else {
|
||||
world = Bukkit.getWorld(args.get(0));
|
||||
}
|
||||
|
||||
final StringBuilder gameRules = new StringBuilder();
|
||||
for (final String gameRule : world.getGameRules()) {
|
||||
if (gameRules.length() != 0) {
|
||||
gameRules.append(ChatColor.WHITE).append(", ");
|
||||
}
|
||||
gameRules.append(ChatColor.AQUA).append(gameRule).append(ChatColor.WHITE).append(": ");
|
||||
gameRules.append(ChatColor.GREEN).append(world.getGameRuleValue(gameRule));
|
||||
}
|
||||
sender.sendMessage("=== Gamerules for " + ChatColor.AQUA + world.getName() + ChatColor.WHITE + " ===");
|
||||
sender.sendMessage(gameRules.toString());
|
||||
}
|
||||
}
|
@ -215,3 +215,20 @@ commands:
|
||||
description: Reduces startup messages
|
||||
usage: |
|
||||
/<command> [true|false]
|
||||
|
||||
mvgamerule:
|
||||
description: Sets a gamerule.
|
||||
usage: |
|
||||
/<command> {RULE} {VALUE} [WORLD]
|
||||
mvrule:
|
||||
description: Sets a gamerule.
|
||||
usage: |
|
||||
/<command> {RULE} {VALUE} [WORLD]
|
||||
mvgamerules:
|
||||
description: Lists the gamerules.
|
||||
usage: |
|
||||
/<command> [WORLD]
|
||||
mvrules:
|
||||
description: Lists the gamerules.
|
||||
usage: |
|
||||
/<command> [WORLD]
|
Loading…
Reference in New Issue
Block a user