コード例 #1
0
  @Override
  public boolean run(
      CommandSender sender,
      Player sender_p,
      Command cmd,
      String commandLabel,
      String[] args,
      boolean senderIsConsole) {
    if (args.length == 0) {
      playerMsg("Available toggles: ");
      playerMsg("- waterplace");
      playerMsg("- fireplace");
      playerMsg("- lavaplace");
      playerMsg("- fluidspread");
      playerMsg("- lavadmg");
      playerMsg("- firespread");
      playerMsg("- prelog");
      playerMsg("- lockdown");
      playerMsg("- petprotect");
      playerMsg("- droptoggle");
      playerMsg("- nonuke");
      playerMsg("- explosives");
      playerMsg("- chaos", ChatColor.DARK_RED);
      return false;
    }

    if (args[0].equals("waterplace")) {
      toggle("Water placement is", TFM_ConfigEntry.ALLOW_WATER_PLACE);
      return true;
    }

    if (args[0].equals("fireplace")) {
      toggle("Fire placement is", TFM_ConfigEntry.ALLOW_FIRE_PLACE);
      return true;
    }

    if (args[0].equals("lavaplace")) {
      toggle("Lava placement is", TFM_ConfigEntry.ALLOW_LAVA_PLACE);
      return true;
    }

    if (args[0].equals("fluidspread")) {
      toggle("Fluid spread is", TFM_ConfigEntry.ALLOW_FLUID_SPREAD);
      return true;
    }

    if (args[0].equals("lavadmg")) {
      toggle("Lava damage is", TFM_ConfigEntry.ALLOW_LAVA_DAMAGE);
      return true;
    }

    if (args[0].equals("firespread")) {
      toggle("Fire spread is", TFM_ConfigEntry.ALLOW_FIRE_SPREAD);
      TFM_GameRuleHandler.setGameRule(
          TFM_GameRule.DO_FIRE_TICK, TFM_ConfigEntry.ALLOW_FIRE_SPREAD.getBoolean());
      return true;
    }

    if (args[0].equals("prelog")) {
      toggle("Command prelogging is", TFM_ConfigEntry.ENABLE_PREPROCESS_LOG);
      return true;
    }

    if (args[0].equals("lockdown")) {
      TFM_Util.adminAction(
          sender.getName(),
          (TotalFreedomMod.lockdownEnabled ? "De-a" : "A") + "ctivating server lockdown",
          true);
      TotalFreedomMod.lockdownEnabled = !TotalFreedomMod.lockdownEnabled;
      return true;
    }

    if (args[0].equals("petprotect")) {
      toggle("Tamed pet protection is", TFM_ConfigEntry.ENABLE_PET_PROTECT);
      return true;
    }

    if (args[0].equals("droptoggle")) {
      toggle("Automatic entity wiping is", TFM_ConfigEntry.AUTO_ENTITY_WIPE);
      return true;
    }

    if (args[0].equals("adminworld")) {
      if (!TFM_Util.isHighRank(sender)) {
        TFM_Util.playerMsg(sender, TFM_Command.MSG_NO_PERMS, ChatColor.RED);
        return true;
      }
      toggle("Adminworld is", TFM_ConfigEntry.ENABLE_ADMINWORLD);
      return true;
    }

    if (args[0].equals("chaos")) {
      if (!TFM_Util.isHighRank(sender)) {
        TFM_Util.playerMsg(sender, TFM_Command.MSG_NO_PERMS, ChatColor.RED);
        return true;
      }
      TFM_Util.adminAction(sender.getName(), "Toggling Chaos Mode!", false);
      TFM_Util.bcastMsg(
          !TFM_ConfigEntry.ENABLE_CHAOS.getBoolean()
              ? "EEEK, HIDE THE F*****G CHILDREN!!!!!"
              : "Everyone is safe... FOR NOW...",
          ChatColor.RED);
      toggle("Chaos mode is", TFM_ConfigEntry.ENABLE_CHAOS);
      return true;
    }

    if (args[0].equals("nonuke")) {
      if (args.length >= 2) {
        try {
          TFM_ConfigEntry.NUKE_MONITOR_RANGE.setDouble(
              Math.max(1.0, Math.min(500.0, Double.parseDouble(args[1]))));
        } catch (NumberFormatException nfex) {
        }
      }

      if (args.length >= 3) {
        try {
          TFM_ConfigEntry.NUKE_MONITOR_COUNT_BREAK.setInteger(
              Math.max(1, Math.min(500, Integer.parseInt(args[2]))));
        } catch (NumberFormatException nfex) {
        }
      }

      toggle("Nuke monitor is", TFM_ConfigEntry.NUKE_MONITOR_ENABLED);

      if (TFM_ConfigEntry.NUKE_MONITOR_ENABLED.getBoolean()) {
        playerMsg(
            "Anti-freecam range is set to "
                + TFM_ConfigEntry.NUKE_MONITOR_RANGE.getDouble()
                + " blocks.");
        playerMsg(
            "Block throttle rate is set to "
                + TFM_ConfigEntry.NUKE_MONITOR_COUNT_BREAK.getInteger()
                + " blocks destroyed per 5 seconds.");
      }

      return true;
    }
    if (args[0].equals("explosives")) {
      if (args.length == 2) {
        try {
          TFM_ConfigEntry.EXPLOSIVE_RADIUS.setDouble(
              Math.max(1.0, Math.min(30.0, Double.parseDouble(args[1]))));
        } catch (NumberFormatException ex) {
          playerMsg(ex.getMessage());
          return true;
        }
      }

      toggle("Explosions are", TFM_ConfigEntry.ALLOW_EXPLOSIONS);

      if (TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) {
        playerMsg("Radius set to " + TFM_ConfigEntry.EXPLOSIVE_RADIUS.getDouble());
      }
      return true;
    }

    return false;
  }
コード例 #2
0
  @Override
  public boolean run(
      CommandSender sender,
      Player sender_p,
      Command cmd,
      String commandLabel,
      String[] args,
      boolean senderIsConsole) {
    if (!TFM_ConfigEntry.ENABLE_ADMINWORLD.getBoolean() && !TFM_Util.isHighRank(sender)) {
      TFM_Util.playerMsg(sender, "Admin World is currently disabled!", ChatColor.RED);
      return true;
    }

    CommandMode commandMode = null;

    if (args.length == 0) {
      commandMode = CommandMode.TELEPORT;
    } else if (args.length >= 2) {
      if ("guest".equalsIgnoreCase(args[0])) {
        commandMode = CommandMode.GUEST;
      } else if ("time".equalsIgnoreCase(args[0])) {
        commandMode = CommandMode.TIME;
      } else if ("weather".equalsIgnoreCase(args[0])) {
        commandMode = CommandMode.WEATHER;
      }
    }

    if (commandMode == null) {
      return false;
    }

    try {
      switch (commandMode) {
        case TELEPORT:
          {
            if (!(sender instanceof Player) || sender_p == null) {
              return true;
            }

            World adminWorld = null;
            try {
              adminWorld = TFM_AdminWorld.getInstance().getWorld();
            } catch (Exception ex) {
            }

            if (adminWorld == null || sender_p.getWorld() == adminWorld) {
              playerMsg("Going to the main world.");
              sender_p.teleport(server.getWorlds().get(0).getSpawnLocation());
            } else {
              if (TFM_AdminWorld.getInstance().canAccessWorld(sender_p)) {
                playerMsg("Going to the AdminWorld.");
                TFM_AdminWorld.getInstance().sendToWorld(sender_p);
              } else {
                playerMsg("You don't have permission to access the AdminWorld.");
              }
            }

            break;
          }
        case GUEST:
          {
            if (args.length == 2) {
              if ("list".equalsIgnoreCase(args[1])) {
                playerMsg(
                    "AdminWorld guest list: " + TFM_AdminWorld.getInstance().guestListToString());
              } else if ("purge".equalsIgnoreCase(args[1])) {
                assertCommandPerms(sender, sender_p);
                TFM_AdminWorld.getInstance().purgeGuestList();
                TFM_Util.adminAction(sender.getName(), "AdminWorld guest list purged.", false);
              } else {
                return false;
              }
            } else if (args.length == 3) {
              assertCommandPerms(sender, sender_p);

              if ("add".equalsIgnoreCase(args[1])) {
                final Player player = getPlayer(args[2]);

                if (player == null) {
                  sender.sendMessage(TotalFreedomMod.PLAYER_NOT_FOUND);
                  return true;
                }

                if (TFM_AdminWorld.getInstance().addGuest(player, sender_p)) {
                  TFM_Util.adminAction(
                      sender.getName(), "AdminWorld guest added: " + player.getName(), false);
                } else {
                  playerMsg("Could not add player to guest list.");
                }
              } else if ("remove".equals(args[1])) {
                final Player player = TFM_AdminWorld.getInstance().removeGuest(args[2]);
                if (player != null) {
                  TFM_Util.adminAction(
                      sender.getName(), "AdminWorld guest removed: " + player.getName(), false);
                } else {
                  playerMsg("Can't find guest entry for: " + args[2]);
                }
              } else {
                return false;
              }
            }

            break;
          }
        case TIME:
          {
            assertCommandPerms(sender, sender_p);

            if (args.length == 2) {
              TFM_AdminWorld.TimeOfDay timeOfDay = TFM_AdminWorld.TimeOfDay.getByAlias(args[1]);
              if (timeOfDay != null) {
                TFM_AdminWorld.getInstance().setTimeOfDay(timeOfDay);
                playerMsg("AdminWorld time set to: " + timeOfDay.name());
              } else {
                playerMsg("Invalid time of day. Can be: sunrise, noon, sunset, midnight");
              }
            } else {
              return false;
            }

            break;
          }
        case WEATHER:
          {
            assertCommandPerms(sender, sender_p);

            if (args.length == 2) {
              TFM_AdminWorld.WeatherMode weatherMode =
                  TFM_AdminWorld.WeatherMode.getByAlias(args[1]);
              if (weatherMode != null) {
                TFM_AdminWorld.getInstance().setWeatherMode(weatherMode);
                playerMsg("AdminWorld weather set to: " + weatherMode.name());
              } else {
                playerMsg("Invalid weather mode. Can be: off, rain, storm");
              }
            } else {
              return false;
            }

            break;
          }
        default:
          {
            return false;
          }
      }
    } catch (PermissionDeniedException ex) {
      sender.sendMessage(ex.getMessage());
    }

    return true;
  }