Permalink
Browse files

Fixed error when using variable commands without it being enabled.

  • Loading branch information...
me4502 committed Nov 15, 2016
1 parent db2e2a7 commit ec421f4d3dddd9e6576bfa2b55f593b79e220b89
Showing with 55 additions and 0 deletions.
  1. +55 −0 src/main/java/com/sk89q/craftbook/mechanics/variables/VariableCommands.java
@@ -29,6 +29,11 @@ public VariableCommands(CraftBookPlugin plugin) {
@Command(aliases = "set", desc = "Sets a variable.", max=2, min=2, flags="n:", usage = "<Variable> <Value> -n <Namespace>")
public void set(CommandContext context, CommandSender sender) throws CommandException {
+ if (VariableManager.instance == null) {
+ sender.sendMessage(ChatColor.RED + "Variables are not enabled!");
+ return;
+ }
+
String key = "global";
if(!VariableManager.instance.defaultToGlobal && sender instanceof Player)
@@ -56,6 +61,11 @@ public void set(CommandContext context, CommandSender sender) throws CommandExce
@Command(aliases = "define", desc = "Defines a variable.", max=2, min=2, flags="n:", usage = "<Variable> <Value> -n <Namespace>")
public void define(CommandContext context, CommandSender sender) throws CommandException {
+ if (VariableManager.instance == null) {
+ sender.sendMessage(ChatColor.RED + "Variables are not enabled!");
+ return;
+ }
+
String key = "global";
if(!VariableManager.instance.defaultToGlobal && sender instanceof Player)
@@ -82,6 +92,11 @@ public void define(CommandContext context, CommandSender sender) throws CommandE
@Command(aliases = "get", desc = "Checks a variable.", max=1, min=1, flags="n:", usage = "<Variable> -n <Namespace>")
public void get(CommandContext context, CommandSender sender) throws CommandException {
+ if (VariableManager.instance == null) {
+ sender.sendMessage(ChatColor.RED + "Variables are not enabled!");
+ return;
+ }
+
String key = "global";
if(!VariableManager.instance.defaultToGlobal && sender instanceof Player)
@@ -104,6 +119,11 @@ public void get(CommandContext context, CommandSender sender) throws CommandExce
@Command(aliases = {"erase","remove","delete","rm"}, desc = "Erase a variable.", max=1, min=1, flags="n:", usage = "<Variable> -n <Namespace>")
public void erase(CommandContext context, CommandSender sender) throws CommandException {
+ if (VariableManager.instance == null) {
+ sender.sendMessage(ChatColor.RED + "Variables are not enabled!");
+ return;
+ }
+
String key = "global";
if(!VariableManager.instance.defaultToGlobal && sender instanceof Player)
@@ -141,6 +161,11 @@ private static void resetICCache(String variable, String namespace) {
@Command(aliases = "append", desc = "Append to a variable.", max=2, min=2, flags="n:", usage = "<Variable> <Appended Value> -n <Namespace>")
public void append(CommandContext context, CommandSender sender) throws CommandException {
+ if (VariableManager.instance == null) {
+ sender.sendMessage(ChatColor.RED + "Variables are not enabled!");
+ return;
+ }
+
String key = "global";
if(!VariableManager.instance.defaultToGlobal && sender instanceof Player)
@@ -168,6 +193,11 @@ public void append(CommandContext context, CommandSender sender) throws CommandE
@Command(aliases = "prepend", desc = "Prepend to a variable.", max=2, min=2, flags="n:", usage = "<Variable> <Prepended Value> -n <Namespace>")
public void prepend(CommandContext context, CommandSender sender) throws CommandException {
+ if (VariableManager.instance == null) {
+ sender.sendMessage(ChatColor.RED + "Variables are not enabled!");
+ return;
+ }
+
String key = "global";
if(!VariableManager.instance.defaultToGlobal && sender instanceof Player)
@@ -195,6 +225,11 @@ public void prepend(CommandContext context, CommandSender sender) throws Command
@Command(aliases = "toggle", desc = "Toggle a boolean.", max=1, min=1, flags="n:", usage = "<Variable> -n <Namespace>")
public void toggle(CommandContext context, CommandSender sender) throws CommandException {
+ if (VariableManager.instance == null) {
+ sender.sendMessage(ChatColor.RED + "Variables are not enabled!");
+ return;
+ }
+
String key = "global";
if(!VariableManager.instance.defaultToGlobal && sender instanceof Player)
@@ -229,6 +264,11 @@ else if(var.equalsIgnoreCase("yes") || var.equalsIgnoreCase("no"))
@Command(aliases = "add", desc = "Add to a numeric variable.", max=2, min=2, flags="n:", usage = "<Variable> <Added Value> -n <Namespace>")
public void add(CommandContext context, CommandSender sender) throws CommandException {
+ if (VariableManager.instance == null) {
+ sender.sendMessage(ChatColor.RED + "Variables are not enabled!");
+ return;
+ }
+
String key = "global";
if(!VariableManager.instance.defaultToGlobal && sender instanceof Player)
@@ -268,6 +308,11 @@ public void add(CommandContext context, CommandSender sender) throws CommandExce
@Command(aliases = "subtract", desc = "Subtract from a numeric variable.", max=2, min=2, flags="n:", usage = "<Variable> <Subtracting Value> -n <Namespace>")
public void subtract(CommandContext context, CommandSender sender) throws CommandException {
+ if (VariableManager.instance == null) {
+ sender.sendMessage(ChatColor.RED + "Variables are not enabled!");
+ return;
+ }
+
String key = "global";
if(!VariableManager.instance.defaultToGlobal && sender instanceof Player)
@@ -307,6 +352,11 @@ public void subtract(CommandContext context, CommandSender sender) throws Comman
@Command(aliases = {"multiply","multiple"}, desc = "Multiply a numeric variable.", max=2, min=2, flags="n:", usage = "<Variable> <Multiplying Value> -n <Namespace>")
public void multiple(CommandContext context, CommandSender sender) throws CommandException {
+ if (VariableManager.instance == null) {
+ sender.sendMessage(ChatColor.RED + "Variables are not enabled!");
+ return;
+ }
+
String key = "global";
if(!VariableManager.instance.defaultToGlobal && sender instanceof Player)
@@ -346,6 +396,11 @@ public void multiple(CommandContext context, CommandSender sender) throws Comman
@Command(aliases = "divide", desc = "Divide a numeric variable.", max=2, min=2, flags="n:", usage = "<Variable> <Dividing Value> -n <Namespace>")
public void divide(CommandContext context, CommandSender sender) throws CommandException {
+ if (VariableManager.instance == null) {
+ sender.sendMessage(ChatColor.RED + "Variables are not enabled!");
+ return;
+ }
+
String key = "global";
if(!VariableManager.instance.defaultToGlobal && sender instanceof Player)

0 comments on commit ec421f4

Please sign in to comment.