public void actionPerformed(ActionEvent e) {
    /*
     * L'unico pulsante del pannello FinalPanel deve
     * ricondurre alla schermata del menĂ¹ principale
     */

    gameMode.resetAll();

    GameWin gameWin = gameMode.getGameWin();
    gameWin.setResizable(false);
    int height = gameWin.getBackgroundImage().getHeight(null);
    int width = gameWin.getBackgroundImage().getWidth(null);
    gameWin.setSize(width, height);
    Container c = gameWin.getContentPane();

    /*
     *  rimuovo gli eventuali altri pannelli presenti sulla finestra
     * e aggiungo quelli nuovi
     */
    c.removeAll();
    c.add(gameMode.getStartPanel(), BorderLayout.CENTER);
    gameWin.repaint();
    gameWin.validate();
    gameMode.getInitGame().getPreviewMap().setMappa(InitGame.DEFMAP);
  }
Example #2
0
 public static GameMode getModeFromString(String state) {
   GameMode[] values = GameMode.values();
   for (GameMode s : values) {
     if (s.getName().equals(state)) {
       return s;
     }
   }
   return null;
 }
Example #3
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);
    }
  }
  /**
   * Gets a list of card indices a hint is to be displayed on
   *
   * @return Card indices
   */
  public List<Integer> getHintIndices() {

    GameMode gameMode = getGameMode();
    int totalCards = getCards().size();

    List<Integer> results = new ArrayList<Integer>();

    if (gameMode.hintsEnabled()) {
      for (int i = 0; i < totalCards; i++) {
        if (gameMode.displayHintForCard(getCards().get(i))) {
          results.add(i);
        }
      }
    }
    return results;
  }
Example #5
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
  protected void setupPlayerSpawnArea() {
    super.setupPlayerSpawnArea();

    Random random = TurnSynchronizer.synchedRandom;
    for (int i = 0; i < 15; i++) {
      double x = (random.nextInt(newLevel.width - 16) + 8) * Tile.WIDTH + Tile.WIDTH / 2;
      double y = (random.nextInt(newLevel.height - 16) + 8) * Tile.HEIGHT + Tile.HEIGHT / 2 - 4;
      final Tile tile = newLevel.getTile((int) (x / Tile.WIDTH), (int) (y / Tile.HEIGHT));
      if (tile instanceof FloorTile) {
        newLevel.addEntity(new SpawnerForBat(x, y));
      }
    }
  }
Example #7
0
 @Override
 public GameMode getGameMode() {
   return GameMode.getByValue(getHandle().field_71134_c.func_73081_b().func_77148_a());
 }
Example #8
0
 public void setPlayerGameMode(String playerName, int gameMode) throws Exception {
   Player p = getPlayerExact(playerName);
   p.setGameMode(GameMode.getByValue(gameMode));
   p.saveData();
 }
  /** Creates or loads the config file. */
  public void loadPluginConfig() {
    this.settings = new Settings();
    ItemStack[] itemsChest = {
      new ItemStack(Material.ICE, 2),
      new ItemStack(Material.SAPLING, 5),
      new ItemStack(Material.MELON, 3),
      new ItemStack(Material.CACTUS, 1),
      new ItemStack(Material.LAVA_BUCKET, 1),
      new ItemStack(Material.PUMPKIN, 1)
    };

    if (!this.filePlugin.exists()) {
      settings.setIslandDistance(50);
      settings.setItemsChest(itemsChest);
      settings.setIsOnline(true);
      settings.setAllowContent(false);
      settings.setLanguage("english");
      settings.setGameMode(GameMode.BUILD);
      settings.setIslandsPerPlayer(1);
      settings.setLivesPerIsland(1);
      settings.setRespawnWithInventory(true);
      settings.setWithProtectedArea(true);
      settings.setAllowEnderPearl(false);
      settings.setWorldName(this.getDescription().getName());
      settings.setRemoveCreaturesByTeleport(true);
      settings.setIslandSchematic("");
      settings.setIslandYPosition(64);
      settings.setTowerSchematic("");
      settings.setTowerYPosition(80);

      for (EnumPluginConfig c : EnumPluginConfig.values()) {
        this.setStringbyPath(this.configPlugin, this.filePlugin, c.getPath(), c.getValue());
      }
    } else {
      try {
        this.configPlugin.load(this.filePlugin);
      } catch (Exception e) {
        e.printStackTrace();
      }

      try {
        settings.setIslandDistance(
            Integer.parseInt(
                this.getStringbyPath(
                    this.configPlugin,
                    this.filePlugin,
                    EnumPluginConfig.OPTIONS_ISLANDDISTANCE.getPath(),
                    50,
                    true)));
      } catch (Exception e) {
        settings.setIslandDistance(50);
      }

      String[] dataItems =
          this.getStringbyPath(
                  this.configPlugin,
                  this.filePlugin,
                  EnumPluginConfig.OPTIONS_CHESTITEMS.getPath(),
                  "79:2 6:5 360:3 81:1 327:1 86:1",
                  true)
              .split(" ");
      ArrayList<ItemStack> alitemsChest = new ArrayList<ItemStack>();

      for (String s : dataItems) {
        if (s.trim() != "") {
          String[] dataValues = s.split(":");
          try {
            int id = Integer.parseInt(dataValues[0]);
            int amount = Integer.parseInt(dataValues[1]);

            Material m = Material.matchMaterial("" + dataValues[0]);
            if (m != null) {
              if (dataValues.length == 2) {
                alitemsChest.add(new ItemStack(id, amount));
              } else if (dataValues.length == 3) {
                alitemsChest.add(
                    new ItemStack(id, amount, (short) 0, Byte.parseByte(dataValues[2])));
              }
            }

          } catch (Exception ex) {
          }
        }
      }

      itemsChest = new ItemStack[alitemsChest.size()];
      for (int i = 0; i < itemsChest.length; i++) {
        itemsChest[i] = alitemsChest.get(i);
      }

      try {
        settings.setLivesPerIsland(
            Integer.parseInt(
                this.getStringbyPath(
                    this.configPlugin,
                    this.filePlugin,
                    EnumPluginConfig.OPTIONS_PVP_LIVESPERISLAND.getPath(),
                    1,
                    true)));
      } catch (Exception e) {
        settings.setLivesPerIsland(1);
      }

      try {
        settings.setIslandsPerPlayer(
            Integer.parseInt(
                this.getStringbyPath(
                    this.configPlugin,
                    this.filePlugin,
                    EnumPluginConfig.OPTIONS_PVP_ISLANDSPERPLAYER.getPath(),
                    1,
                    true)));
      } catch (Exception e) {
        settings.setIslandsPerPlayer(1);
      }

      try {
        settings.setTowerYPosition(
            Integer.parseInt(
                this.getStringbyPath(
                    this.configPlugin,
                    this.filePlugin,
                    EnumPluginConfig.OPTIONS_SCHEMATIC_TOWER_YHEIGHT.getPath(),
                    80,
                    true)));
      } catch (Exception e) {
        settings.setTowerYPosition(80);
      }

      try {
        settings.setIslandYPosition(
            Integer.parseInt(
                this.getStringbyPath(
                    this.configPlugin,
                    this.filePlugin,
                    EnumPluginConfig.OPTIONS_SCHEMATIC_ISLAND_Y_POSITION.getPath(),
                    64,
                    true)));
        if (settings.getIslandYPosition() < 0) {
          settings.setIslandYPosition(64);
        }
      } catch (Exception e) {
        settings.setIslandYPosition(64);
      }

      settings.setItemsChest(itemsChest);
      settings.setIsOnline(
          Boolean.parseBoolean(
              this.getStringbyPath(
                  this.configPlugin,
                  this.filePlugin,
                  EnumPluginConfig.OPTIONS_SKYBLOCKONLINE.getPath(),
                  true,
                  true)));
      settings.setLanguage(
          this.getStringbyPath(
              this.configPlugin,
              this.filePlugin,
              EnumPluginConfig.OPTIONS_LANGUAGE.getPath(),
              "english",
              true));
      settings.setAllowContent(
          Boolean.parseBoolean(
              this.getStringbyPath(
                  this.configPlugin,
                  this.filePlugin,
                  EnumPluginConfig.OPTIONS_ALLOWCONTENT.getPath(),
                  false,
                  true)));
      settings.setGameMode(
          GameMode.valueOf(
              this.getStringbyPath(
                      this.configPlugin,
                      this.filePlugin,
                      EnumPluginConfig.OPTIONS_GAMEMODE.getPath(),
                      "build",
                      true)
                  .toUpperCase()));
      settings.setRespawnWithInventory(
          Boolean.parseBoolean(
              this.getStringbyPath(
                  this.configPlugin,
                  this.filePlugin,
                  EnumPluginConfig.OPTIONS_BUILD_RESPAWNWITHINVENTORY.getPath(),
                  true,
                  true)));
      settings.setWithProtectedArea(
          Boolean.parseBoolean(
              this.getStringbyPath(
                  this.configPlugin,
                  this.filePlugin,
                  EnumPluginConfig.OPTIONS_BUILD_WITHPROTECTEDAREA.getPath(),
                  true,
                  true)));
      settings.setAllowEnderPearl(
          Boolean.parseBoolean(
              this.getStringbyPath(
                  this.configPlugin,
                  this.filePlugin,
                  EnumPluginConfig.OPTIONS_BUILD_ALLOWENDERPEARL.getPath(),
                  false,
                  true)));
      settings.setWithProtectedBorder(
          Boolean.parseBoolean(
              this.getStringbyPath(
                  this.configPlugin,
                  this.filePlugin,
                  EnumPluginConfig.OPTIONS_BUILD_WITHPROTECTEDBORDER.getPath(),
                  true,
                  true)));
      settings.setWorldName(
          this.getStringbyPath(
              this.configPlugin,
              this.filePlugin,
              EnumPluginConfig.OPTIONS_WORLDNAME.getPath(),
              this.getDescription().getName(),
              true));
      settings.setIsLocked(
          Boolean.parseBoolean(
              this.getStringbyPath(
                  this.configPlugin,
                  this.filePlugin,
                  EnumPluginConfig.OPTIONS_CLOSED.getPath(),
                  false,
                  true)));
      settings.setRemoveCreaturesByTeleport(
          Boolean.parseBoolean(
              this.getStringbyPath(
                  this.configPlugin,
                  this.filePlugin,
                  EnumPluginConfig.OPTIONS_REMOVECREATURESBYTELEPORT.getPath(),
                  true,
                  true)));
      settings.setIslandSchematic(
          this.getStringbyPath(
              this.configPlugin,
              this.filePlugin,
              EnumPluginConfig.OPTIONS_SCHEMATIC_ISLAND_FILENAME.getPath(),
              "",
              true));
      settings.setTowerSchematic(
          this.getStringbyPath(
              this.configPlugin,
              this.filePlugin,
              EnumPluginConfig.OPTIONS_SCHEMATIC_TOWER_FILENAME.getPath(),
              "",
              true));
    }
  }