Пример #1
0
  @Override
  public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!testPermission(sender)) return true;
    if (args.length == 0) {
      sender.sendMessage("Usage: " + usageMessage);
      return false;
    }

    String modeArg = args[0];
    int value = -1;

    try {
      value = Integer.parseInt(modeArg);
    } catch (NumberFormatException ex) {
    }

    GameMode mode = GameMode.getByValue(value);

    if (mode == null) {
      if (modeArg.equalsIgnoreCase("creative") || modeArg.equalsIgnoreCase("c")) {
        mode = GameMode.CREATIVE;
      } else if (modeArg.equalsIgnoreCase("adventure") || modeArg.equalsIgnoreCase("a")) {
        mode = GameMode.ADVENTURE;
      } else {
        mode = GameMode.SURVIVAL;
      }
    }

    Bukkit.getServer().setDefaultGameMode(mode);
    Command.broadcastCommandMessage(
        sender, "Default game mode set to " + mode.toString().toLowerCase());

    return true;
  }
Пример #2
0
 @SuppressWarnings("deprecation")
 public void setGameMode(Player player, String param) {
   param = param.toLowerCase();
   for (GameMode gm : GameMode.values()) {
     if (gm.toString().toLowerCase().startsWith(param)
         || param.equalsIgnoreCase(gm.getValue() + "")) {
       setGameMode(player, gm);
       return;
     }
   }
   sendMessage("No such gamemode: &c" + param);
 }
 @Override
 public boolean parseValue(String value) {
   try {
     return this.setValue(GameMode.getByValue(Integer.parseInt(value)));
   } catch (NumberFormatException nfe) {
     try {
       return this.setValue(GameMode.valueOf(value.toUpperCase()));
     } catch (Exception e) {
       return false;
     }
   }
 }
Пример #4
0
  /** Load the server configuration. */
  private void loadConfig() {
    config.load();

    // modifiable values
    spawnRadius = config.getInt(ServerConfig.Key.SPAWN_RADIUS);
    whitelistEnabled = config.getBoolean(ServerConfig.Key.WHITELIST);
    idleTimeout = config.getInt(ServerConfig.Key.PLAYER_IDLE_TIMEOUT);
    craftingManager.initialize();

    // special handling
    warnState = Warning.WarningState.value(config.getString(ServerConfig.Key.WARNING_STATE));
    try {
      defaultGameMode = GameMode.valueOf(config.getString(ServerConfig.Key.GAMEMODE));
    } catch (IllegalArgumentException | NullPointerException e) {
      defaultGameMode = GameMode.SURVIVAL;
    }

    // server icon
    defaultIcon = new GlowServerIcon();
    try {
      File file = config.getFile("server-icon.png");
      if (file.isFile()) {
        defaultIcon = new GlowServerIcon(file);
      }
    } catch (Exception e) {
      logger.log(Level.WARNING, "Failed to load server-icon.png", e);
    }
  }
Пример #5
0
 @Override
 public GameMode unmarshal(Object o) {
   GameMode gm = null;
   if (o != null) {
     gm = GameMode.valueOf((String) o);
   }
   return gm;
 }
Пример #6
0
 public void setGameMode(Player player, GameMode gm) {
   player.setGameMode(gm);
   sendMessage(
       "Set &6"
           + (player == sender ? "your" : player.getName() + "'s")
           + color
           + " gamemode to &c"
           + gm.toString().toLowerCase());
 }
 private GameMode verifyGameMode(String string) {
   GameMode gm = null;
   try {
     gm = GameMode.valueOf(string);
   } catch (Exception e) {
     /* ignore */
   }
   if (gm == null) {
     try {
       gm = GameMode.getByValue(Integer.valueOf(string));
     } catch (Exception e) {
       /* do nothing */
     }
     if (gm == null) {
       throw new IllegalArgumentException("&cGamemode " + string + " not found");
     }
   }
   return gm;
 }
Пример #8
0
 public void setDefaultGameMode(GameMode mode) {
   GameMode oldMode = defaultGameMode;
   defaultGameMode = mode;
   for (Player player : getOnlinePlayers()) {
     if (player.getGameMode() == oldMode) {
       player.setGameMode(mode);
     }
   }
   config.set("server.def-game-mode", mode.name());
 }
Пример #9
0
 public GameMode setDefaultGameMode(String mode) {
   GameMode gameMode;
   try {
     gameMode = GameMode.valueOf(mode);
   } catch (Throwable t) {
     logger.severe("Unknown game mode specified. Defaulting to survival");
     gameMode = GameMode.SURVIVAL;
   }
   setDefaultGameMode(gameMode);
   return getDefaultGameMode();
 }
Пример #10
0
  @Override
  public void setGameMode(GameMode mode) {
    if (getHandle().playerNetServerHandler == null) return;
    if (mode == null) {
      throw new IllegalArgumentException("Mode cannot be null");
    }

    if (mode != getGameMode()) {
      PlayerGameModeChangeEvent event = new PlayerGameModeChangeEvent(this, mode);
      server.getPluginManager().callEvent(event);
      if (event.isCancelled()) {
        return;
      }

      getHandle().theItemInWorldManager.setGameType(EnumGameType.getByID(mode.getValue()));
      getHandle()
          .playerNetServerHandler
          .sendPacketToPlayer(new Packet70GameEvent(3, mode.getValue()));
    }
  }
Пример #11
0
 public Object parseValue(String value) throws Exception {
   /// Handle values for this option
   switch (this) {
     case HEALTHP:
     case HEALTH:
     case POOLMONEY:
     case WITHINDISTANCE:
     case MONEY:
       return Double.valueOf(value);
     case LEVELRANGE:
       return MinMax.valueOf(value);
     case DISGUISEALLAS:
       return value;
     case MAGIC:
     case MAGICP:
     case HUNGER:
     case EXPERIENCE:
     case INVULNERABLE:
       return Integer.valueOf(value);
     case FLIGHTSPEED:
       return Float.valueOf(value);
     case ENCHANTS:
       return EffectUtil.parseArg(value, 0, 120);
     case DOCOMMANDS:
       return value;
     case GIVECLASS:
       return ArenaClassController.getClass(value);
     case GAMEMODE:
       GameMode gm;
       try {
         gm = GameMode.getByValue(Integer.valueOf(value));
       } catch (Throwable e) {
         gm = GameMode.valueOf(value.toUpperCase());
       }
       return gm; // multiply by number of ticks per second
     default:
       break;
   }
   return null;
 }
Пример #12
0
 public static void fullReset(final Arena arena, final Player player) {
   playersetHealth(player, arena.getArenaConfig().getInt(CFG.PLAYER_HEALTH));
   player.setFireTicks(0);
   player.setFallDistance(0);
   player.setVelocity(new Vector());
   player.setFoodLevel(arena.getArenaConfig().getInt(CFG.PLAYER_FOODLEVEL));
   player.setSaturation(arena.getArenaConfig().getInt(CFG.PLAYER_SATURATION));
   player.setExhaustion((float) arena.getArenaConfig().getDouble(CFG.PLAYER_EXHAUSTION));
   player.setLevel(0);
   player.setExp(0);
   player.setGameMode(GameMode.getByValue(arena.getArenaConfig().getInt(CFG.GENERAL_GAMEMODE)));
   PlayerState.removeEffects(player);
 }
 public GameModeConfigProperty(
     ConfigurationSection section,
     String name,
     GameMode defaultValue,
     String configNode,
     String help) {
   this.name = name;
   this.configNode = configNode;
   this.section = section;
   this.help = help;
   this.value = defaultValue;
   this.parseValue(this.section.getString(this.configNode, defaultValue.toString()));
 }
Пример #14
0
  @Override
  public void setGameMode(GameMode mode) {
    if (getHandle().field_71135_a == null) return;

    if (mode == null) {
      throw new IllegalArgumentException("Mode cannot be null");
    }

    if (mode != getGameMode()) {
      PlayerGameModeChangeEvent event = new PlayerGameModeChangeEvent(this, mode);
      server.getPluginManager().callEvent(event);
      if (event.isCancelled()) {
        return;
      }

      getHandle()
          .field_71134_c
          .func_73076_a(net.minecraft.world.EnumGameType.func_77146_a(mode.getValue()));
      getHandle()
          .field_71135_a
          .func_72567_b(new net.minecraft.network.packet.Packet70GameEvent(3, mode.getValue()));
    }
  }
  @Override
  public void executeTyped(Listener listener, PlayerChangedWorldEvent event) throws EventException {

    boolean saveRequired = false;
    String fromName = event.getFrom().getName();
    String toName = event.getPlayer().getWorld().getName();

    logger.finer("Player change from " + fromName + " to " + toName);

    try {

      // Save old game mode if required
      String fromWorldMode = plugin.getConfig().getString("worlds." + fromName + ".mode");
      if (fromWorldMode != null) {
        ModeOptions fromMode = ModeOptions.valueOf(fromWorldMode);
        if (fromMode == ModeOptions.REMEMBER) {
          GameMode fromGameMode =
              GameMode.valueOf(plugin.getConfig().getString("worlds." + fromName + ".gamemode"));
          String rememberWorldString =
              plugin
                  .getConfig()
                  .getString(
                      "players." + event.getPlayer().getUniqueId().toString() + "." + fromName);
          { // transition code
            String rememberWorldStringOld =
                plugin
                    .getConfig()
                    .getString("players." + event.getPlayer().getName() + "." + fromName);
            if (rememberWorldStringOld != null) {
              rememberWorldString = rememberWorldStringOld;
              plugin
                  .getConfig()
                  .set(
                      "players." + event.getPlayer().getUniqueId().toString() + "." + fromName,
                      rememberWorldString);
              plugin
                  .getConfig()
                  .set("players." + event.getPlayer().getName() + "." + fromName, null);
              saveRequired = true;
            }
          }
          if (event.getPlayer().getGameMode() != fromGameMode) {
            if (rememberWorldString == null
                || GameMode.valueOf(rememberWorldString) != event.getPlayer().getGameMode()) {
              logger.info("The player has a gamemode different to default. Saving");
              plugin
                  .getConfig()
                  .set(
                      "players." + event.getPlayer().getUniqueId().toString() + "." + fromName,
                      event.getPlayer().getGameMode().toString());
              saveRequired = true;
            }
          }
          if (rememberWorldString != null && event.getPlayer().getGameMode() == fromGameMode) {
            logger.info("The player used to have a unique gamemode but now it is the default");
            plugin.getConfig().set("players." + event.getPlayer().getName(), null);
            saveRequired = true;
          }
        }
      }

      // Change to new gamemode
      String newWorldMode = plugin.getConfig().getString("worlds." + toName + ".mode");
      if (newWorldMode != null) {
        ModeOptions toMode = ModeOptions.valueOf(newWorldMode);
        GameMode toGameMode =
            GameMode.valueOf(plugin.getConfig().getString("worlds." + toName + ".gamemode"));

        if (toMode == ModeOptions.REMEMBER) {
          String rememberWorldString =
              plugin
                  .getConfig()
                  .getString(
                      "players." + event.getPlayer().getUniqueId().toString() + "." + toName);
          { // transition code
            String rememberWorldStringOld =
                plugin
                    .getConfig()
                    .getString("players." + event.getPlayer().getName() + "." + toName);
            if (rememberWorldStringOld != null) {
              rememberWorldString = rememberWorldStringOld;
              plugin
                  .getConfig()
                  .set(
                      "players." + event.getPlayer().getUniqueId().toString() + "." + toName,
                      rememberWorldString);
              plugin.getConfig().set("players." + event.getPlayer().getName() + "." + toName, null);
              saveRequired = true;
            }
          }
          if (rememberWorldString != null) {
            toGameMode = GameMode.valueOf(rememberWorldString);
          }
        }
        if (event.getPlayer().getGameMode() != toGameMode) {
          logger.finer("Changing game mode to " + toGameMode);
          event.getPlayer().setGameMode(toGameMode);
        }
      } else {
        logger.fine("There is no setting for " + toName);
      }
    } finally {
      if (saveRequired) {
        plugin.saveConfig();
      }
    }
  }
Пример #16
0
 @Override
 public GameMode getGameMode() {
   return GameMode.getByValue(getHandle().theItemInWorldManager.getGameType().getID());
 }
 @Override
 public String toString() {
   return value.toString();
 }
Пример #18
0
 public void setPlayerGameMode(String playerName, int gameMode) throws Exception {
   Player p = getPlayerExact(playerName);
   p.setGameMode(GameMode.getByValue(gameMode));
   p.saveData();
 }
Пример #19
0
  /** Initializes the channel and pipeline factories. */
  private void init() {
    Bukkit.setServer(this);

    monitor = new DeadlockMonitor();
    monitor.start();

    ChannelFactory factory = new NioServerSocketChannelFactory(executor, executor);
    bootstrap.setFactory(factory);

    ChannelPipelineFactory pipelineFactory = new MinecraftPipelineFactory(this);
    bootstrap.setPipelineFactory(pipelineFactory);

    // TODO: This needs a cleanup badly
    InputStream stream = getClass().getClassLoader().getResourceAsStream("defaults/glowstone.yml");
    if (stream == null) {
      logger.severe("Error creating default config: Config not found in classpath");
      return;
    }
    try {
      config.setDefaults(YamlConfiguration.loadConfiguration(stream));
    } finally {
      try {
        stream.close();
      } catch (IOException e) {
      }
    }
    config.set("server.view-distance", GlowChunk.VISIBLE_RADIUS);

    // If the configuration is empty, attempt to migrate non-Glowstone configs
    if (config.getKeys(false).size() <= 1) {
      System.out.println("Generating default configuration config/glowstone.yml...");

      // bukkit.yml
      File bukkitYml = new File("bukkit.yml");
      if (bukkitYml.exists()) {
        YamlConfiguration bukkit = YamlConfiguration.loadConfiguration(bukkitYml);
        String moved = "", separator = "";

        if (bukkit.get("database") != null) {
          config.createSection(
              "database", bukkit.getConfigurationSection("database").getValues(true));
          moved += separator + "database settings";
          separator = ", ";
        }

        if (bukkit.get("settings.spawn-radius") != null) {
          config.set("server.spawn-radius", bukkit.getInt("settings.spawn-radius", 16));
          moved += separator + "spawn radius";
          separator = ", ";
        }

        if (bukkit.getString("settings.update-folder") != null) {
          config.set("server.folders.update", bukkit.getString("settings.update-folder"));
          moved += separator + "update folder";
          separator = ", ";
        }

        if (bukkit.getString("settings.world-container") != null) {
          config.set(
              "server.folders.world-container", bukkit.getString("settings.world-container"));
          moved += separator + "world container";
          separator = "m ";
        }

        if (bukkit.get("worlds") != null) {
          config.createSection("worlds", bukkit.getConfigurationSection("worlds").getValues(true));
          moved += separator + "world generators";
          separator = ", ";
        }

        // TODO: move aliases when those are implemented

        if (moved.length() > 0) {
          System.out.println("Copied " + moved + " from bukkit.yml");
        }
      }

      // server.properties
      File serverProps = new File("server.properties");
      if (serverProps.exists()) {
        try {
          Properties properties = new Properties();
          properties.load(new FileInputStream(serverProps));
          String moved = "", separator = "";

          if (properties.containsKey("level-name")) {
            String world = properties.getProperty("level-name", "world");
            config.set("server.world-name", world);
            moved += separator + "world name";
            separator = ", ";
          }

          if (properties.containsKey("online-mode")) {
            String value = properties.getProperty("online-mode", "true");
            boolean bool =
                value.equalsIgnoreCase("on")
                    || value.equalsIgnoreCase("yes")
                    || value.equalsIgnoreCase("true");
            config.set("server.online-mode", bool);
            moved += separator + "online mode";
            separator = ", ";
          }

          if (properties.containsKey("server-port")) {
            String value = properties.getProperty("server-port", "25565");
            try {
              int port = Integer.parseInt(value);
              config.set("server.port", port);
              moved += separator + "port";
              separator = ", ";
            } catch (NumberFormatException ex) {
            }
          }

          if (properties.containsKey("max-players")) {
            String value = properties.getProperty("max-players", "20");
            try {
              int players = Integer.parseInt(value);
              config.set("server.max-players", players);
              moved += separator + "max players";
              separator = ", ";
            } catch (NumberFormatException e) {
            }
          }

          if (properties.containsKey("motd")) {
            String motd = properties.getProperty("motd", "Glowstone server");
            config.set("server.motd", motd);
            moved += separator + "MOTD";
            separator = ", ";
          }

          if (properties.containsKey("gamemode")) {
            String value = properties.getProperty("gamemode", "0");
            try {
              int mode = Integer.parseInt(value);
              GameMode gMode = GameMode.getByValue(mode);
              if (gMode == null) gMode = GameMode.SURVIVAL;
              config.set("server.def-game-mode", gMode.name());
              moved += separator + "default game mode";
              separator = ", ";
            } catch (NumberFormatException ex) {
            }
          }

          // TODO: move nether, view distance, monsters, etc when implemented

          if (moved.length() > 0) {
            System.out.println("Copied " + moved + " from server.properties");
          }
        } catch (IOException ex) {
        }
      }
    }
    config.options().copyDefaults(true);
    config.save();
  }
Пример #20
0
 @Override
 public Object marshal(GameMode o) {
   return o == null ? null : o.name();
 }
Пример #21
0
  public void unload() {
    final Player player = Bukkit.getPlayerExact(name);

    if (player == null) {
      final ArenaPlayer aPlayer = ArenaPlayer.parsePlayer(name);
      PVPArena.instance.getAgm().disconnect(aPlayer.getArena(), aPlayer);
      return;
    }
    debug.i("restoring PlayerState of " + name, player);

    player.setFireTicks(fireticks);
    player.setFoodLevel(foodlevel);
    player.setGameMode(GameMode.getByValue(gamemode));

    final ArenaPlayer aPlayer = ArenaPlayer.parsePlayer(player.getName());
    player.setFoodLevel(foodlevel);
    if (player.getMaxHealth() != maxhealth) {
      final double newHealth = player.getMaxHealth() * health / maxhealth;
      if (newHealth > player.getMaxHealth()) {
        player.setHealth(player.getMaxHealth());
      } else {
        player.setHealth(newHealth);
      }

    } else {
      player.setHealth(health);
    }
    player.setSaturation(saturation);
    player.setGameMode(GameMode.getByValue(gamemode));
    player.setLevel(explevel);
    player.setExp(experience);
    player.setExhaustion(exhaustion);
    player.setFallDistance(0);
    player.setVelocity(new Vector());
    if (aPlayer.getArena() != null
        && aPlayer.getArena().getArenaConfig().getBoolean(CFG.CHAT_COLORNICK)) {
      player.setDisplayName(displayname);
    }

    if (aPlayer.getArena() != null) {

      ArenaModuleManager.unload(aPlayer.getArena(), player);
      PVPArena.instance.getAgm().unload(aPlayer.getArena(), player);
    }

    removeEffects(player);
    player.addPotionEffects(potionEffects);

    aPlayer.setTelePass(false);
    player.setFireTicks(fireticks);

    if (aPlayer.getArena() != null) {
      player.setNoDamageTicks(
          aPlayer.getArena().getArenaConfig().getInt(CFG.TIME_TELEPORTPROTECT) * 20);
    }
    player.resetPlayerTime();
    if (flying && !player.getAllowFlight()) {
      player.setAllowFlight(true);
    }
    player.setFlying(flying);
  }
Пример #22
0
  /**
   * Instantiates a new moving configuration.
   *
   * @param config the data
   */
  public MovingConfig(final ConfigFile config) {
    super(config, ConfPaths.MOVING);

    ignoreCreative = config.getBoolean(ConfPaths.MOVING_CREATIVEFLY_IGNORECREATIVE);
    ignoreAllowFlight = config.getBoolean(ConfPaths.MOVING_CREATIVEFLY_IGNOREALLOWFLIGHT);

    creativeFlyCheck = config.getBoolean(ConfPaths.MOVING_CREATIVEFLY_CHECK);
    final ModelFlying defaultModel =
        new ModelFlying(
            config, ConfPaths.MOVING_CREATIVEFLY_MODEL + "creative.", new ModelFlying());
    for (final GameMode gameMode : GameMode.values()) {
      flyingModels.put(
          gameMode,
          new ModelFlying(
              config,
              ConfPaths.MOVING_CREATIVEFLY_MODEL + (gameMode.name().toLowerCase()) + ".",
              defaultModel));
    }
    creativeFlyActions =
        config.getOptimizedActionList(
            ConfPaths.MOVING_CREATIVEFLY_ACTIONS, Permissions.MOVING_CREATIVEFLY);

    morePacketsCheck = config.getBoolean(ConfPaths.MOVING_MOREPACKETS_CHECK);
    morePacketsEPSIdeal = config.getInt(ConfPaths.MOVING_MOREPACKETS_EPSIDEAL);
    morePacketsEPSMax =
        Math.max(morePacketsEPSIdeal, config.getInt(ConfPaths.MOVING_MOREPACKETS_EPSMAX));
    morePacketsEPSBuckets =
        2 * Math.max(1, Math.min(60, config.getInt(ConfPaths.MOVING_MOREPACKETS_SECONDS)));
    morePacketsBurstPackets = config.getInt(ConfPaths.MOVING_MOREPACKETS_BURST_EPM);
    morePacketsBurstDirect = config.getInt(ConfPaths.MOVING_MOREPACKETS_BURST_DIRECT);
    morePacketsBurstEPM = config.getInt(ConfPaths.MOVING_MOREPACKETS_BURST_EPM);
    morePacketsActions =
        config.getOptimizedActionList(
            ConfPaths.MOVING_MOREPACKETS_ACTIONS, Permissions.MOVING_MOREPACKETS);

    morePacketsVehicleCheck = config.getBoolean(ConfPaths.MOVING_MOREPACKETSVEHICLE_CHECK);
    morePacketsVehicleActions =
        config.getOptimizedActionList(
            ConfPaths.MOVING_MOREPACKETSVEHICLE_ACTIONS, Permissions.MOVING_MOREPACKETS);

    noFallCheck = config.getBoolean(ConfPaths.MOVING_NOFALL_CHECK);
    noFallDealDamage = config.getBoolean(ConfPaths.MOVING_NOFALL_DEALDAMAGE);
    noFallViolationReset = config.getBoolean(ConfPaths.MOVING_NOFALL_RESETONVL);
    noFallTpReset = config.getBoolean(ConfPaths.MOVING_NOFALL_RESETONTP);
    noFallVehicleReset = config.getBoolean(ConfPaths.MOVING_NOFALL_RESETONVEHICLE);
    noFallAntiCriticals = config.getBoolean(ConfPaths.MOVING_NOFALL_ANTICRITICALS);
    noFallActions =
        config.getOptimizedActionList(ConfPaths.MOVING_NOFALL_ACTIONS, Permissions.MOVING_NOFALL);

    passableCheck = config.getBoolean(ConfPaths.MOVING_PASSABLE_CHECK);
    passableRayTracingCheck = config.getBoolean(ConfPaths.MOVING_PASSABLE_RAYTRACING_CHECK);
    passableRayTracingBlockChangeOnly =
        config.getBoolean(ConfPaths.MOVING_PASSABLE_RAYTRACING_BLOCKCHANGEONLY);
    passableActions =
        config.getOptimizedActionList(
            ConfPaths.MOVING_PASSABLE_ACTIONS, Permissions.MOVING_PASSABLE);
    passableUntrackedTeleportCheck =
        config.getBoolean(ConfPaths.MOVING_PASSABLE_UNTRACKED_TELEPORT_ACTIVE);
    passableUntrackedCommandCheck =
        config.getBoolean(ConfPaths.MOVING_PASSABLE_UNTRACKED_CMD_ACTIVE);
    passableUntrackedCommandTryTeleport =
        config.getBoolean(ConfPaths.MOVING_PASSABLE_UNTRACKED_CMD_TRYTELEPORT);
    CommandUtil.feedCommands(
        passableUntrackedCommandPrefixes,
        config,
        ConfPaths.MOVING_PASSABLE_UNTRACKED_CMD_PREFIXES,
        true);

    survivalFlyCheck = config.getBoolean(ConfPaths.MOVING_SURVIVALFLY_CHECK);
    // Default values are specified here because this settings aren't showed by default into the
    // configuration file.
    survivalFlyBlockingSpeed = config.getInt(ConfPaths.MOVING_SURVIVALFLY_BLOCKINGSPEED, 100);
    survivalFlySneakingSpeed = config.getInt(ConfPaths.MOVING_SURVIVALFLY_SNEAKINGSPEED, 100);
    survivalFlySpeedingSpeed = config.getInt(ConfPaths.MOVING_SURVIVALFLY_SPEEDINGSPEED, 200);
    survivalFlySprintingSpeed = config.getInt(ConfPaths.MOVING_SURVIVALFLY_SPRINTINGSPEED, 100);
    survivalFlySwimmingSpeed = config.getInt(ConfPaths.MOVING_SURVIVALFLY_SWIMMINGSPEED, 100);
    survivalFlyWalkingSpeed = config.getInt(ConfPaths.MOVING_SURVIVALFLY_WALKINGSPEED, 100);
    survivalFlyCobwebHack = config.getBoolean(ConfPaths.MOVING_SURVIVALFLY_COBWEBHACK, true);
    sfGroundHop =
        config.getBoolean(
            ConfPaths.MOVING_SURVIVALFLY_GROUNDHOP,
            ServerVersion.compareMinecraftVersion("1.7") == -1);
    survivalFlyAccountingH = config.getBoolean(ConfPaths.MOVING_SURVIVALFLY_EXTENDED_HACC, false);
    survivalFlyAccountingV = config.getBoolean(ConfPaths.MOVING_SURVIVALFLY_EXTENDED_VACC);
    sfSetBackPolicyFallDamage =
        config.getBoolean(ConfPaths.MOVING_SURVIVALFLY_SETBACKPOLICY_FALLDAMAGE);
    sfSetBackPolicyVoid = config.getBoolean(ConfPaths.MOVING_SURVIVALFLY_SETBACKPOLICY_VOIDTOVOID);
    final double sfStepHeight =
        config.getDouble(ConfPaths.MOVING_SURVIVALFLY_STEPHEIGHT, Double.MAX_VALUE);
    if (sfStepHeight == Double.MAX_VALUE) {
      final String ref;
      if (Bukkit.getVersion().toLowerCase().indexOf("spigot") != -1) {
        // Assume 1.8 clients being supported.
        ref = "1.7.10";
      } else {
        ref = "1.8";
      }
      this.sfStepHeight = ServerVersion.select(ref, 0.5, 0.6, 0.6, 0.5).doubleValue();
    } else {
      this.sfStepHeight = sfStepHeight;
    }
    survivalFlyVLFreeze = config.getLong(ConfPaths.MOVING_SURVIVALFLY_VLFREEZE, 2000L);
    survivalFlyActions =
        config.getOptimizedActionList(
            ConfPaths.MOVING_SURVIVALFLY_ACTIONS, Permissions.MOVING_SURVIVALFLY);

    sfHoverCheck = config.getBoolean(ConfPaths.MOVING_SURVIVALFLY_HOVER_CHECK);
    sfHoverTicks = config.getInt(ConfPaths.MOVING_SURVIVALFLY_HOVER_TICKS);
    sfHoverLoginTicks = Math.max(0, config.getInt(ConfPaths.MOVING_SURVIVALFLY_HOVER_LOGINTICKS));
    sfHoverFallDamage = config.getBoolean(ConfPaths.MOVING_SURVIVALFLY_HOVER_FALLDAMAGE);
    sfHoverViolation = config.getDouble(ConfPaths.MOVING_SURVIVALFLY_HOVER_SFVIOLATION);

    velocityActivationCounter = config.getInt(ConfPaths.MOVING_VELOCITY_ACTIVATIONCOUNTER);
    velocityActivationTicks = config.getInt(ConfPaths.MOVING_VELOCITY_ACTIVATIONTICKS);
    velocityStrictInvalidation = config.getBoolean(ConfPaths.MOVING_VELOCITY_STRICTINVALIDATION);
    yOnGround =
        config.getDouble(
            ConfPaths.MOVING_YONGROUND,
            Y_ON_GROUND_MIN,
            Y_ON_GROUND_MAX,
            Y_ON_GROUND_DEFAULT); // sqrt(1/256), see: NetServerHandler.
    noFallyOnGround =
        config.getDouble(
            ConfPaths.MOVING_NOFALL_YONGROUND, Y_ON_GROUND_MIN, Y_ON_GROUND_MAX, yOnGround);

    // TODO: Ignore the stance, once it is known that the server catches such.
    ignoreStance =
        config.getAlmostBoolean(ConfPaths.MOVING_IGNORESTANCE, AlmostBoolean.NO).decide();
    tempKickIllegal = config.getBoolean(ConfPaths.MOVING_TEMPKICKILLEGAL);
    loadChunksOnJoin = config.getBoolean(ConfPaths.MOVING_LOADCHUNKS_JOIN);
    sprintingGrace =
        Math.max(
            0L,
            (long)
                (config.getDouble(ConfPaths.MOVING_SPRINTINGGRACE) * 1000.0)); // Config: seconds.
    assumeSprint = config.getBoolean(ConfPaths.MOVING_ASSUMESPRINT);
    speedGrace =
        Math.max(
            0,
            (int)
                Math.round(
                    config.getDouble(ConfPaths.MOVING_SPEEDGRACE) * 20.0)); // Config: seconds
    AlmostBoolean ref =
        config.getAlmostBoolean(ConfPaths.MOVING_ENFORCELOCATION, AlmostBoolean.MAYBE);
    if (ref == AlmostBoolean.MAYBE) {
      enforceLocation = Bugs.shouldEnforceLocation();
    } else {
      enforceLocation = ref.decide();
    }

    ref = config.getAlmostBoolean(ConfPaths.MOVING_VEHICLES_ENFORCELOCATION, AlmostBoolean.MAYBE);
    vehicleEnforceLocation = ref.decideOptimistically(); // Currently rather enabled.
    vehiclePreventDestroyOwn = config.getBoolean(ConfPaths.MOVING_VEHICLES_PREVENTDESTROYOWN);

    traceSize = config.getInt(ConfPaths.MOVING_TRACE_SIZE);
    traceMergeDist = config.getDouble(ConfPaths.MOVING_TRACE_MERGEDIST);
  }
Пример #23
0
	@Override
	public void setDefaultGameMode(GameMode mode) {
		theServer.setGameType(EnumGameType.getByID(mode.getValue()));

	}
Пример #24
0
	@Override
	public GameMode getDefaultGameMode() {

		return GameMode.getByValue(theServer.getGameType().getID());
	}
Пример #25
0
  @EventHandler
  public void onPlayerInteract(PlayerInteractEvent pie) {
    Player player = pie.getPlayer();
    Game g = Main.getInstance().getGameManager().getGameOfPlayer(player);

    if (g == null) {
      if (pie.getAction() != Action.RIGHT_CLICK_BLOCK
          && pie.getAction() != Action.RIGHT_CLICK_AIR) {
        return;
      }

      Block clicked = pie.getClickedBlock();

      if (clicked == null) {
        return;
      }

      if (!(clicked.getState() instanceof Sign)) {
        return;
      }

      Game game = Main.getInstance().getGameManager().getGameBySignLocation(clicked.getLocation());
      if (game == null) {
        return;
      }

      if (game.playerJoins(player)) {
        player.sendMessage(ChatWriter.pluginMessage(ChatColor.GREEN + Main._l("success.joined")));
      }
      return;
    }

    if (g.getState() == GameState.STOPPED) {
      return;
    }

    Material interactingMaterial = pie.getMaterial();
    Block clickedBlock = pie.getClickedBlock();

    if (g.getState() == GameState.RUNNING) {
      if (pie.getAction() == Action.PHYSICAL) {
        if (clickedBlock != null
            && (clickedBlock.getType() == Material.WHEAT
                || clickedBlock.getType() == Material.SOIL)) {
          pie.setCancelled(true);
          return;
        }
      }

      if (pie.getAction() != Action.RIGHT_CLICK_BLOCK
          && pie.getAction() != Action.RIGHT_CLICK_AIR) {
        return;
      }

      if (clickedBlock != null) {
        if (clickedBlock.getType() == Material.LEVER
            && !g.isSpectator(player)
            && pie.getAction() == Action.RIGHT_CLICK_BLOCK) {
          if (!g.getRegion().isPlacedUnbreakableBlock(clickedBlock)) {
            g.getRegion().addPlacedUnbreakableBlock(clickedBlock, clickedBlock.getState());
          }
          return;
        }
      }

      if (g.isSpectator(player)) {
        if (interactingMaterial == Material.SLIME_BALL) {
          g.playerLeave(player, false);
          return;
        }

        if (interactingMaterial == Material.COMPASS) {
          g.openSpectatorCompass(player);
          pie.setCancelled(true);
          return;
        }
      }

      // Spectators want to block
      if (clickedBlock != null) {
        try {
          GameMode.valueOf("SPECTATOR");
        } catch (Exception ex) {
          for (Player p : g.getFreePlayers()) {
            if (!g.getRegion().isInRegion(p.getLocation())) {
              continue;
            }

            if (pie.getClickedBlock().getLocation().distance(p.getLocation()) < 2) {
              Location oldLocation = p.getLocation();
              if (oldLocation.getY() >= pie.getClickedBlock().getLocation().getY()) {
                oldLocation.setY(oldLocation.getY() + 2);
              } else {
                oldLocation.setY(oldLocation.getY() - 2);
              }

              p.teleport(oldLocation);
            }
          }
        }
      }

      if (clickedBlock != null) {
        if (clickedBlock.getType() == Material.ENDER_CHEST && !g.isSpectator(player)) {
          pie.setCancelled(true);

          Block chest = pie.getClickedBlock();
          Team chestTeam = g.getTeamOfEnderChest(chest);
          Team playerTeam = g.getPlayerTeam(player);

          if (chestTeam == null) {
            return;
          }

          if (chestTeam.equals(playerTeam)) {
            player.openInventory(chestTeam.getInventory());
          } else {
            player.sendMessage(
                ChatWriter.pluginMessage(ChatColor.RED + Main._l("ingame.noturteamchest")));
          }

          return;
        }
      }

      return;
    } else if (g.getState() == GameState.WAITING) {
      if (interactingMaterial == null) {
        pie.setCancelled(true);
        return;
      }

      if (pie.getAction() == Action.PHYSICAL) {
        if (clickedBlock != null
            && (clickedBlock.getType() == Material.WHEAT
                || clickedBlock.getType() == Material.SOIL)) {
          pie.setCancelled(true);
          return;
        }
      }

      if (pie.getAction() != Action.RIGHT_CLICK_BLOCK
          && pie.getAction() != Action.RIGHT_CLICK_AIR) {
        return;
      }

      switch (interactingMaterial) {
        case BED:
          pie.setCancelled(true);
          if (!g.isAutobalanceEnabled()) {
            g.getPlayerStorage(player).openTeamSelection(g);
          }

          break;
        case DIAMOND:
          pie.setCancelled(true);
          if (player.isOp() || player.hasPermission("bw.setup")) {
            g.start(player);
          } else if (player.hasPermission("bw.vip.forcestart")) {
            GameLobbyCountdownRule rule = Main.getInstance().getLobbyCountdownRule();
            if (rule.isRuleMet(g)) {
              g.start(player);
            } else {
              if (rule == GameLobbyCountdownRule.PLAYERS_IN_GAME
                  || rule == GameLobbyCountdownRule.ENOUGH_TEAMS_AND_PLAYERS) {
                player.sendMessage(
                    ChatWriter.pluginMessage(
                        ChatColor.RED + Main._l("lobby.notenoughplayers-rule0")));
              } else {
                player.sendMessage(
                    ChatWriter.pluginMessage(
                        ChatColor.RED + Main._l("lobby.notenoughplayers-rule1")));
              }
            }
          }
          break;
        case SLIME_BALL:
          pie.setCancelled(true);
          g.playerLeave(player, false);
          break;
        case LEATHER_CHESTPLATE:
          pie.setCancelled(true);
          player.updateInventory();
          break;
        default:
          break;
      }
    }
  }
Пример #26
0
 @Override
 public GameMode getGameMode() {
   return GameMode.getByValue(getHandle().field_71134_c.func_73081_b().func_77148_a());
 }
Пример #27
0
    public String performLogin(Player player, String password) {
            
        String name = player.getName().toLowerCase();
        String ip = player.getAddress().getAddress().getHostAddress();
        
        if (PlayerCache.getInstance().isAuthenticated(name)) {
            return m._("logged_in");
           
        }

        if (!database.isAuthAvailable(player.getName().toLowerCase())) {
            return m._("user_unknown");
        }
        
        PlayerAuth pAuth = database.getAuth(name);
            // if Mysql is unavaible
            if(pAuth == null)
                return m._("user_unknown");
            
        String hash = pAuth.getHash();
        

        try {
            if(!passpartu) {
            if (PasswordSecurity.comparePasswordWithHash(password, hash)) {
                PlayerAuth auth = new PlayerAuth(name, hash, ip, new Date().getTime());
            
                database.updateSession(auth);
                PlayerCache.getInstance().addPlayer(auth);
                LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(name);
                if (limbo != null) {
                    if(Settings.protectInventoryBeforeLogInEnabled) {
                        player.getInventory().setContents(limbo.getInventory());
                        player.getInventory().setArmorContents(limbo.getArmour());
                    }
                    player.setGameMode(GameMode.getByValue(limbo.getGameMode()));
                    player.setOp(limbo.getOperator());
                    /*                  
                     * if (limbo.getOperator()) {
                         System.out.println("player is an operator after login success");
                    }*/
                    utils.addNormal(player, limbo.getGroup());
                    //System.out.println("il gruppo in logincommand "+limbo.getGroup());
                    //
                    // TODO: completly rewrite this part, too much if, else ...
                    // check quit location, check correct spawn, 
                    //
                    World world = player.getWorld();

                        
                    if (Settings.isTeleportToSpawnEnabled && !Settings.isForceSpawnLocOnJoinEnabled) {                  
                                 // This is initial work around for prevent ppl to quit on bukkit bug
                                 // take last quit location from database and subtract y from safe spawn             
                                 // if the error range is smaller then 1, player can come back in his quit location
                                 // otherwise he try to spawn in a unsafe location!
                                
                                 if(Settings.isSaveQuitLocationEnabled && database.getAuth(name).getQuitLocY() != 0) {
                                     Location quitLoc = new Location(player.getWorld(),(double)database.getAuth(name).getQuitLocX()+0.5,(double)database.getAuth(name).getQuitLocY()+1.5,(double)database.getAuth(name).getQuitLocZ()+0.5);
                                     //pre-load chunk before teleport player to quit location
                                     
                                     if(!world.getChunkAt(quitLoc).isLoaded()) {
                                         //System.out.println("Debug chunk insent loaded");
                                         world.getChunkAt(quitLoc).load();
                                     }
                                     player.teleport(quitLoc);
                                     //System.out.println("quit location from db:"+quitLoc);
                                 } else {
                                    //pre-load chunk before teleport player to quit location
                                    if(!world.getChunkAt(limbo.getLoc()).isLoaded())
                                            world.getChunkAt(limbo.getLoc()).load();                                      
                                 player.teleport(limbo.getLoc());
                                 //System.out.println("quit location from bukkit:"+limbo.getLoc());
                                 } 
                    } else {
                        if(Settings.isForceSpawnLocOnJoinEnabled) {
                            player.teleport(player.getWorld().getSpawnLocation());  
                        } else {
                        if ( Settings.isSaveQuitLocationEnabled && database.getAuth(name).getQuitLocY() != 0) {
                          Location quitLoc = new Location(player.getWorld(),(double)database.getAuth(name).getQuitLocX()+0.5,(double)database.getAuth(name).getQuitLocY()+1.5,(double)database.getAuth(name).getQuitLocZ()+0.5);
                          //pre-load chunk before teleport player to quit location
                              if(!world.getChunkAt(quitLoc).isLoaded()) {
                                  //System.out.println("Debug chunk insent loaded");
                                  world.getChunkAt(quitLoc).load(); 
                              }
                          player.teleport(quitLoc);  
                          //System.out.println("quit location from db:"+quitLoc);
                        } else {
                          //pre-load chunk before teleport player to quit location
                              if(!world.getChunkAt(limbo.getLoc()).isLoaded()) {
                                  //System.out.println("Debug chunk insent loaded");
                                  world.getChunkAt(limbo.getLoc()).load();      
                              }
                                player.teleport(limbo.getLoc());
                                //System.out.println("quit location from bukkit:"+limbo.getLoc()); 
                                }  
                        }
                    } 
                player.getServer().getScheduler().cancelTask(limbo.getTimeoutTaskId());
                LimboCache.getInstance().deleteLimboPlayer(name);
                if(playerCache.doesCacheExist(name)) {
                        playerCache.removeCache(name);
                    }   
                }
                
               /*
                *  Little Work Around under Registration Group Switching for admins that
                *  add Registration thru a web Scripts.
                */
                if ( Settings.isPermissionCheckEnabled && AuthMe.permission.playerInGroup(player, Settings.unRegisteredGroup) && !Settings.unRegisteredGroup.isEmpty() ) {
                    AuthMe.permission.playerRemoveGroup(player.getWorld(), player.getName(), Settings.unRegisteredGroup);
                    AuthMe.permission.playerAddGroup(player.getWorld(), player.getName(), Settings.getRegisteredGroup);
                }
                    
                    
                player.sendMessage(m._("login"));
                ConsoleLogger.info(player.getDisplayName() + " logged in!");
                player.saveData();
                
            } else {
                ConsoleLogger.info(player.getDisplayName() + " used the wrong password");
                if (Settings.isKickOnWrongPasswordEnabled) {
                    player.kickPlayer(m._("wrong_pwd"));
                } else {
                    return (m._("wrong_pwd"));
                }
            }
         } else {
            // need for bypass password check if passpartu command is enabled
                PlayerAuth auth = new PlayerAuth(name, hash, ip, new Date().getTime());
                database.updateSession(auth);
                PlayerCache.getInstance().addPlayer(auth);
                LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(name);
                if (limbo != null) {
                    if(Settings.protectInventoryBeforeLogInEnabled) {
                        player.getInventory().setContents(limbo.getInventory());
                        player.getInventory().setArmorContents(limbo.getArmour());
                    }
                    player.setGameMode(GameMode.getByValue(limbo.getGameMode()));
                    player.setOp(limbo.getOperator());
                    /*                  
                     * if (limbo.getOperator()) {
                         System.out.println("player is an operator after login success");
                    }*/
                    utils.addNormal(player, limbo.getGroup());
                   //System.out.println("il gruppo in logincommand "+limbo.getGroup());
                   //
                   // TODO: completly rewrite this part, too much if, else ...
                   // check quit location, check correct spawn, 
                   //
                    World world = player.getWorld();
                    if (Settings.isTeleportToSpawnEnabled && !Settings.isForceSpawnLocOnJoinEnabled) {                  
                                 // This is initial work around for prevent ppl to quit on bukkit bug
                                 // take last quit location from database and subtract y from safe spawn             
                                 // if the error range is smaller then 1, player can come back in his quit location
                                 // otherwise he try to spawn in a unsafe location!
                                
                                 if(Settings.isSaveQuitLocationEnabled && database.getAuth(name).getQuitLocY() != 0) {
                                     Location quitLoc = new Location(player.getWorld(),(double)database.getAuth(name).getQuitLocX()+0.5,(double)database.getAuth(name).getQuitLocY()+0.5,(double)database.getAuth(name).getQuitLocZ()+0.5);
                                     //pre-load chunk before teleport player to quit location
                                     
                                     if(!world.getChunkAt(quitLoc).isLoaded()) {
                                         //System.out.println("Debug chunk insent loaded");
                                         world.getChunkAt(quitLoc).load();
                                     }
                                     player.teleport(quitLoc);
                                     //System.out.println("quit location from db:"+quitLoc);
                                 } else {
                                    //pre-load chunk before teleport player to quit location
                                    if(!world.getChunkAt(limbo.getLoc()).isLoaded())
                                            world.getChunkAt(limbo.getLoc()).load();                                      
                                 player.teleport(limbo.getLoc());
                                 //System.out.println("quit location from bukkit:"+limbo.getLoc());
                                 } 
                    } else {
                        if(Settings.isForceSpawnLocOnJoinEnabled) {
                            player.teleport(player.getWorld().getSpawnLocation());  
                        } else {
                        if ( Settings.isSaveQuitLocationEnabled && database.getAuth(name).getQuitLocY() != 0) {
                          Location quitLoc = new Location(player.getWorld(),(double)database.getAuth(name).getQuitLocX()+0.5,(double)database.getAuth(name).getQuitLocY()+0.5,(double)database.getAuth(name).getQuitLocZ()+0.5);
                          //pre-load chunk before teleport player to quit location
                              if(!world.getChunkAt(quitLoc).isLoaded()) {
                                  //System.out.println("Debug chunk insent loaded");
                                  world.getChunkAt(quitLoc).load(); 
                              }
                          player.teleport(quitLoc);  
                          //System.out.println("quit location from db:"+quitLoc);
                        } else {
                          //pre-load chunk before teleport player to quit location
                              if(!world.getChunkAt(limbo.getLoc()).isLoaded()) {
                                  //System.out.println("Debug chunk insent loaded");
                                  world.getChunkAt(limbo.getLoc()).load();      
                              }
                                player.teleport(limbo.getLoc());
                                //System.out.println("quit location from bukkit:"+limbo.getLoc()); 
                                }  
                        }
                    } 
                player.getServer().getScheduler().cancelTask(limbo.getTimeoutTaskId());
                LimboCache.getInstance().deleteLimboPlayer(name);
                if(playerCache.doesCacheExist(name)) {
                        playerCache.removeCache(name);
                    }   
                }
                
               /*
                *  Little Work Around under Registration Group Switching for admins that
                *  add Registration thru a web Scripts.
                */
                if ( Settings.isPermissionCheckEnabled && AuthMe.permission.playerInGroup(player, Settings.unRegisteredGroup) && !Settings.unRegisteredGroup.isEmpty() ) {
                    AuthMe.permission.playerRemoveGroup(player.getWorld(), player.getName(), Settings.unRegisteredGroup);
                    AuthMe.permission.playerAddGroup(player.getWorld(), player.getName(), Settings.getRegisteredGroup);
                }
                    
                    
                player.sendMessage(m._("login"));
                ConsoleLogger.info(player.getDisplayName() + " logged in!");
                player.saveData(); 
                this.passpartu = false;
            }                
          
        } catch (NoSuchAlgorithmException ex) {
            ConsoleLogger.showError(ex.getMessage());
            return (m._("error"));
        }
        return "";
	}