mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-06 02:39:48 +01:00
Update GameMode command and increase Java support. (#2279)
* update gamerule command * fix NPE in gamerules command and remove deprecated method * catch buscript initialization errors * update gamerule command to be more descriptive * undo GameruleCommand style changes * update legacy version reporting to include all config options * use LF line ending for files being pasted to the web * avoid duplicate code
This commit is contained in:
parent
2fd8e3edc3
commit
51e035eb3e
@ -350,9 +350,14 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
|||||||
* Initializes the buscript javascript library.
|
* Initializes the buscript javascript library.
|
||||||
*/
|
*/
|
||||||
private void initializeBuscript() {
|
private void initializeBuscript() {
|
||||||
|
try {
|
||||||
buscript = new Buscript(this);
|
buscript = new Buscript(this);
|
||||||
// Add global variable "multiverse" to javascript environment
|
// Add global variable "multiverse" to javascript environment
|
||||||
buscript.setScriptVariable("multiverse", this);
|
buscript.setScriptVariable("multiverse", this);
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
buscript = null;
|
||||||
|
Logging.warning("Buscript failed to load! The script command will be disabled!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeDestinationFactory() {
|
private void initializeDestinationFactory() {
|
||||||
|
@ -10,6 +10,7 @@ package com.onarandombox.MultiverseCore.commands;
|
|||||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.GameRule;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -55,7 +56,7 @@ public class GameruleCommand extends MultiverseCommand {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String gameRule = args.get(0);
|
final GameRule gameRule = GameRule.getByName(args.get(0));
|
||||||
final String value = args.get(1);
|
final String value = args.get(1);
|
||||||
final World world;
|
final World world;
|
||||||
if (args.size() == 2) {
|
if (args.size() == 2) {
|
||||||
@ -69,12 +70,47 @@ public class GameruleCommand extends MultiverseCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (world.setGameRuleValue(gameRule, value)) {
|
if (gameRule == null) {
|
||||||
sender.sendMessage(ChatColor.GREEN + "Success!" + ChatColor.WHITE + " Gamerule " + ChatColor.AQUA + gameRule
|
sender.sendMessage(ChatColor.RED + "Failure! " + ChatColor.AQUA + args.get(0) + ChatColor.WHITE
|
||||||
+ ChatColor.WHITE + " was set to " + ChatColor.GREEN + value);
|
+ " is not a valid gamerule.");
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(ChatColor.RED + "Failure!" + ChatColor.WHITE + " Gamerule " + ChatColor.AQUA + gameRule
|
if (gameRule.getType() == Boolean.class) {
|
||||||
+ ChatColor.WHITE + " cannot be set to " + ChatColor.RED + value);
|
boolean booleanValue;
|
||||||
|
if (value.equalsIgnoreCase("true")) {
|
||||||
|
booleanValue = true;
|
||||||
|
} else if (value.equalsIgnoreCase("false")) {
|
||||||
|
booleanValue = false;
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(getErrorMessage(gameRule.getName(), value) + "it can only be set to true or false.");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!world.setGameRule(gameRule, booleanValue)) {
|
||||||
|
sender.sendMessage(getErrorMessage(gameRule.getName(), value) + "something went wrong.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else if (gameRule.getType() == Integer.class) {
|
||||||
|
try {
|
||||||
|
if (!world.setGameRule(gameRule, Integer.parseInt(value))) {
|
||||||
|
throw new NumberFormatException();
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
sender.sendMessage(getErrorMessage(gameRule.getName(), value) + "it can only be set to a positive integer.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(ChatColor.RED + "Failure!" + ChatColor.WHITE + " Gamerule " + ChatColor.AQUA + gameRule.getName()
|
||||||
|
+ ChatColor.WHITE + " isn't supported yet, please let us know about it.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sender.sendMessage(ChatColor.GREEN + "Success!" + ChatColor.WHITE + " Gamerule " + ChatColor.AQUA + gameRule.getName()
|
||||||
|
+ ChatColor.WHITE + " was set to " + ChatColor.GREEN + value + ChatColor.WHITE + ".");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getErrorMessage(String gameRule, String value) {
|
||||||
|
return ChatColor.RED + "Failure!" + ChatColor.WHITE + " Gamerule " + ChatColor.AQUA + gameRule
|
||||||
|
+ ChatColor.WHITE + " could not be set to " + ChatColor.RED + value + ChatColor.WHITE + ", ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ package com.onarandombox.MultiverseCore.commands;
|
|||||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.GameRule;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -60,6 +61,11 @@ public class GamerulesCommand extends MultiverseCommand {
|
|||||||
world = p.getWorld();
|
world = p.getWorld();
|
||||||
} else {
|
} else {
|
||||||
world = Bukkit.getWorld(args.get(0));
|
world = Bukkit.getWorld(args.get(0));
|
||||||
|
if (world == null) {
|
||||||
|
sender.sendMessage(ChatColor.RED + "Failure!" + ChatColor.WHITE + " World " + ChatColor.AQUA + args.get(0)
|
||||||
|
+ ChatColor.WHITE + " does not exist.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final StringBuilder gameRules = new StringBuilder();
|
final StringBuilder gameRules = new StringBuilder();
|
||||||
@ -68,7 +74,7 @@ public class GamerulesCommand extends MultiverseCommand {
|
|||||||
gameRules.append(ChatColor.WHITE).append(", ");
|
gameRules.append(ChatColor.WHITE).append(", ");
|
||||||
}
|
}
|
||||||
gameRules.append(ChatColor.AQUA).append(gameRule).append(ChatColor.WHITE).append(": ");
|
gameRules.append(ChatColor.AQUA).append(gameRule).append(ChatColor.WHITE).append(": ");
|
||||||
gameRules.append(ChatColor.GREEN).append(world.getGameRuleValue(gameRule));
|
gameRules.append(ChatColor.GREEN).append(world.getGameRuleValue(GameRule.getByName(gameRule)));
|
||||||
}
|
}
|
||||||
sender.sendMessage("=== Gamerules for " + ChatColor.AQUA + world.getName() + ChatColor.WHITE + " ===");
|
sender.sendMessage("=== Gamerules for " + ChatColor.AQUA + world.getName() + ChatColor.WHITE + " ===");
|
||||||
sender.sendMessage(gameRules.toString());
|
sender.sendMessage(gameRules.toString());
|
||||||
|
@ -35,6 +35,10 @@ public class ScriptCommand extends MultiverseCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void runCommand(CommandSender sender, List<String> args) {
|
public void runCommand(CommandSender sender, List<String> args) {
|
||||||
|
if (plugin.getScriptAPI() == null) {
|
||||||
|
sender.sendMessage("Buscript failed to load while the server was starting. Scripts cannot be run.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
File file = new File(plugin.getScriptAPI().getScriptFolder(), args.get(0));
|
File file = new File(plugin.getScriptAPI().getScriptFolder(), args.get(0));
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
sender.sendMessage("That script file does not exist in the Multiverse-Core scripts directory!");
|
sender.sendMessage("That script file does not exist in the Multiverse-Core scripts directory!");
|
||||||
|
@ -61,16 +61,22 @@ public class VersionCommand extends MultiverseCommand {
|
|||||||
"[Multiverse-Core] Economy being used: " + plugin.getEconomist().getEconomyName() + System.lineSeparator() +
|
"[Multiverse-Core] Economy being used: " + plugin.getEconomist().getEconomyName() + System.lineSeparator() +
|
||||||
"[Multiverse-Core] Permissions Plugin: " + this.plugin.getMVPerms().getType() + System.lineSeparator() +
|
"[Multiverse-Core] Permissions Plugin: " + this.plugin.getMVPerms().getType() + System.lineSeparator() +
|
||||||
"[Multiverse-Core] Dumping Config Values: (version " + this.plugin.getMVConfig().getVersion() + ")" + System.lineSeparator() +
|
"[Multiverse-Core] Dumping Config Values: (version " + this.plugin.getMVConfig().getVersion() + ")" + System.lineSeparator() +
|
||||||
"[Multiverse-Core] messagecooldown: " + plugin.getMessaging().getCooldown() + System.lineSeparator() +
|
|
||||||
"[Multiverse-Core] teleportcooldown: " + plugin.getMVConfig().getTeleportCooldown() + System.lineSeparator() +
|
|
||||||
"[Multiverse-Core] worldnameprefix: " + plugin.getMVConfig().getPrefixChat() + System.lineSeparator() +
|
|
||||||
"[Multiverse-Core] worldnameprefixFormat: " + plugin.getMVConfig().getPrefixChatFormat() + System.lineSeparator() +
|
|
||||||
"[Multiverse-Core] enforceaccess: " + plugin.getMVConfig().getEnforceAccess() + System.lineSeparator() +
|
"[Multiverse-Core] enforceaccess: " + plugin.getMVConfig().getEnforceAccess() + System.lineSeparator() +
|
||||||
"[Multiverse-Core] displaypermerrors: " + plugin.getMVConfig().getDisplayPermErrors() + System.lineSeparator() +
|
"[Multiverse-Core] prefixchat: " + plugin.getMVConfig().getPrefixChat() + System.lineSeparator() +
|
||||||
|
"[Multiverse-Core] prefixchatformat: " + plugin.getMVConfig().getPrefixChatFormat() + System.lineSeparator() +
|
||||||
|
"[Multiverse-Core] useasyncchat: " + plugin.getMVConfig().getUseAsyncChat() + System.lineSeparator() +
|
||||||
"[Multiverse-Core] teleportintercept: " + plugin.getMVConfig().getTeleportIntercept() + System.lineSeparator() +
|
"[Multiverse-Core] teleportintercept: " + plugin.getMVConfig().getTeleportIntercept() + System.lineSeparator() +
|
||||||
"[Multiverse-Core] firstspawnoverride: " + plugin.getMVConfig().getFirstSpawnOverride() + System.lineSeparator() +
|
"[Multiverse-Core] firstspawnoverride: " + plugin.getMVConfig().getFirstSpawnOverride() + System.lineSeparator() +
|
||||||
|
"[Multiverse-Core] displaypermerrors: " + plugin.getMVConfig().getDisplayPermErrors() + System.lineSeparator() +
|
||||||
|
"[Multiverse-Core] globaldebug: " + plugin.getMVConfig().getGlobalDebug() + System.lineSeparator() +
|
||||||
|
"[Multiverse-Core] silentstart: " + plugin.getMVConfig().getSilentStart() + System.lineSeparator() +
|
||||||
|
"[Multiverse-Core] messagecooldown: " + plugin.getMessaging().getCooldown() + System.lineSeparator() +
|
||||||
|
"[Multiverse-Core] version: " + plugin.getMVConfig().getVersion() + System.lineSeparator() +
|
||||||
"[Multiverse-Core] firstspawnworld: " + plugin.getMVConfig().getFirstSpawnWorld() + System.lineSeparator() +
|
"[Multiverse-Core] firstspawnworld: " + plugin.getMVConfig().getFirstSpawnWorld() + System.lineSeparator() +
|
||||||
"[Multiverse-Core] debug: " + plugin.getMVConfig().getGlobalDebug() + System.lineSeparator() +
|
"[Multiverse-Core] teleportcooldown: " + plugin.getMVConfig().getTeleportCooldown() + System.lineSeparator() +
|
||||||
|
"[Multiverse-Core] defaultportalsearch: " + plugin.getMVConfig().isUsingDefaultPortalSearch() + System.lineSeparator() +
|
||||||
|
"[Multiverse-Core] portalsearchradius: " + plugin.getMVConfig().getPortalSearchRadius() + System.lineSeparator() +
|
||||||
|
"[Multiverse-Core] autopurge: " + plugin.getMVConfig().isAutoPurgeEnabled() + System.lineSeparator() +
|
||||||
"[Multiverse-Core] Special Code: FRN002" + System.lineSeparator();
|
"[Multiverse-Core] Special Code: FRN002" + System.lineSeparator();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,7 +116,7 @@ public class VersionCommand extends MultiverseCommand {
|
|||||||
String line;
|
String line;
|
||||||
result = new StringBuilder();
|
result = new StringBuilder();
|
||||||
while ((line = bufferedReader.readLine()) != null) {
|
while ((line = bufferedReader.readLine()) != null) {
|
||||||
result.append(line).append(System.lineSeparator());
|
result.append(line).append("\n");
|
||||||
}
|
}
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
Logging.severe("Unable to find %s. Here's the traceback: %s", filename, e.getMessage());
|
Logging.severe("Unable to find %s. Here's the traceback: %s", filename, e.getMessage());
|
||||||
|
Loading…
Reference in New Issue
Block a user