コード例 #1
0
  public static void cycleCreativeInv(EntityPlayerMP player, int steps) {
    InventoryPlayer inventory = player.inventory;

    // top down [row][col]
    ItemStack[][] slots = new ItemStack[10][9];
    PlayerSave playerSave = NEIServerConfig.forPlayer(player.getName());

    // get
    System.arraycopy(inventory.mainInventory, 0, slots[9], 0, 9);

    for (int row = 0; row < 3; row++) {
      System.arraycopy(inventory.mainInventory, (row + 1) * 9, slots[row + 6], 0, 9);
    }

    for (int row = 0; row < 6; row++) {
      System.arraycopy(playerSave.creativeInv, row * 9, slots[row], 0, 9);
    }

    ItemStack[][] newslots = new ItemStack[10][];

    // put back
    for (int row = 0; row < 10; row++) {
      newslots[(row + steps + 10) % 10] = slots[row];
    }

    System.arraycopy(newslots[9], 0, inventory.mainInventory, 0, 9);

    for (int row = 0; row < 3; row++) {
      System.arraycopy(newslots[row + 6], 0, inventory.mainInventory, (row + 1) * 9, 9);
    }

    for (int row = 0; row < 6; row++) {
      System.arraycopy(newslots[row], 0, playerSave.creativeInv, row * 9, 9);
    }

    playerSave.setDirty();
  }
コード例 #2
0
 public static void toggleMagnetMode(EntityPlayerMP player) {
   PlayerSave playerSave = NEIServerConfig.forPlayer(player.getName());
   playerSave.enableAction("magnet", !playerSave.isActionEnabled("magnet"));
 }
コード例 #3
0
ファイル: ShutDownHook.java プロジェクト: Onurrr/377_Remake
 @Override
 public void run() {
   PlayerSave.saveAllPlayers();
   System.out.println("Saved all players.");
 }
コード例 #4
0
  public void process() {
    synchronized (PlayerHandler.players) {
      long start = System.currentTimeMillis();
      updatePlayerNames();

      if (kickAllPlayers) {
        for (int i = 1; i < Config.MAX_PLAYERS; i++) {
          if (players[i] != null) {
            players[i].disconnected = true;
          }
        }
      }

      for (int i = 0; i < Config.MAX_PLAYERS; i++) {
        if (players[i] == null || !players[i].isActive) continue;
        try {

          if (players[i].disconnected
              && (System.currentTimeMillis() - players[i].logoutDelay > 10000
                  || players[i].properLogout
                  || kickAllPlayers)) {
            if (players[i].inTrade) {
              Client o = (Client) Server.playerHandler.players[players[i].tradeWith];
              if (o != null) {
                o.getTradeAndDuel().declineTrade();
              }
            }
            if (players[i].duelStatus == 5) {
              Client o = (Client) Server.playerHandler.players[players[i].duelingWith];
              if (o != null) {
                o.getTradeAndDuel().duelVictory();
              }
            } else if (players[i].duelStatus <= 4 && players[i].duelStatus >= 1) {
              Client o = (Client) Server.playerHandler.players[players[i].duelingWith];
              if (o != null) {
                o.getTradeAndDuel().declineDuel();
              }
            }
            Client o = (Client) Server.playerHandler.players[i];
            if (PlayerSave.saveGame(o)) {
              System.out.println("Game saved for player " + players[i].playerName);
            } else {
              System.out.println("Could not save for " + players[i].playerName);
            }
            removePlayer(players[i]);
            players[i] = null;
            continue;
          }

          players[i].preProcessing();
          while (players[i].processQueuedPackets()) ;
          players[i].processPackets = 0;
          players[i].process();
          players[i].postProcessing();
          players[i].getNextPlayerMovement();

        } catch (Exception e) {
          e.printStackTrace();
        }
      }

      for (int i = 0; i < Config.MAX_PLAYERS; i++) {
        if (players[i] == null || !players[i].isActive) continue;
        try {
          if (players[i].disconnected
              && (System.currentTimeMillis() - players[i].logoutDelay > 10000
                  || players[i].properLogout
                  || kickAllPlayers)) {
            if (players[i].inTrade) {
              Client o = (Client) Server.playerHandler.players[players[i].tradeWith];
              if (o != null) {
                o.getTradeAndDuel().declineTrade();
              }
            }
            if (players[i].duelStatus == 5) {
              Client o1 = (Client) Server.playerHandler.players[players[i].duelingWith];
              if (o1 != null) {
                o1.getTradeAndDuel().duelVictory();
              }
            } else if (players[i].duelStatus <= 4 && players[i].duelStatus >= 1) {
              Client o1 = (Client) Server.playerHandler.players[players[i].duelingWith];
              if (o1 != null) {
                o1.getTradeAndDuel().declineDuel();
              }
            }

            Client o1 = (Client) Server.playerHandler.players[i];
            if (PlayerSave.saveGame(o1)) {
              System.out.println("Game saved for player " + players[i].playerName);
            } else {
              System.out.println("Could not save for " + players[i].playerName);
            }
            removePlayer(players[i]);
            players[i] = null;
          } else {
            Client o = (Client) Server.playerHandler.players[i];
            // if(o.g) {
            if (!players[i].initialized) {
              players[i].initialize();
              players[i].initialized = true;
            } else {
              players[i].update();
            }
            // }
          }
        } catch (Exception e) {
          e.printStackTrace();
        }
      }

      if (updateRunning && !updateAnnounced) {
        updateAnnounced = true;
        Server.UpdateServer = true;
      }
      if (updateRunning
          && (System.currentTimeMillis() - updateStartTime > (updateSeconds * 1000))) {
        kickAllPlayers = true;
      }

      for (int i = 0; i < Config.MAX_PLAYERS; i++) {
        if (players[i] == null || !players[i].isActive) continue;
        try {
          players[i].clearUpdateFlags();
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
      Server.TIMES[2] = start - System.currentTimeMillis();
    }
  }
コード例 #5
0
 public static void unloadPlayer(EntityPlayer player) {
   System.out.println("Unloading Player: " + player.username);
   PlayerSave playerSave = playerSaves.remove(player.username);
   if (playerSave != null) playerSave.save();
 }
コード例 #6
0
ファイル: Server.java プロジェクト: Ventuz/vscape
  @Override
  public void run() {
    try {
      Thread.currentThread().setName("ServerEngine");
      System.setOut(new Misc.TimestampLogger(System.out));
      System.setErr(new Misc.TimestampLogger(System.err, "./data/err.log"));

      address = new InetSocketAddress(host, port);
      System.out.println("Starting " + Constants.SERVER_NAME + " on " + address + "...");

      // load shutdown hook
      Thread shutdownhook = new ShutDownHook();
      Runtime.getRuntime().addShutdownHook(shutdownhook);

      PacketManager.loadPackets();

      Cache.load();

      // load scripts
      Misc.loadScripts(new File("./data/ruby/"));

      GlobalVariables.patchNotes = Misc.loadPatchNotes();
      GlobalVariables.info = Misc.loadInfo();
      GlobalVariables.npcDump = Misc.getNpcDump();
      GlobalVariables.itemDump = Misc.getItemDump();

      // load all xstream related files.
      XStreamUtil.loadAllFiles();

      // item weights
      ItemDefinition.loadWeight();

      // interfaces
      RSInterface.load();

      // Load plugins
      PluginManager.loadPlugins();

      // Load regions
      ObjectDef.loadConfig();
      Region.load();
      Rangable.load();

      // Load objects
      ObjectLoader objectLoader = new ObjectLoader();
      objectLoader.load();

      GameObjectData.init();

      // load combat manager
      CombatManager.init();

      // Load minute timer
      startMinutesCounter();

      // global drops
      GlobalGroundItem.initialize();

      // load npc ls
      Npc.loadNpcDrops();

      // mage arena timers
      AlchemistPlayground.loadAlchemistPlayGround();
      EnchantingChamber.loadEnchantingChamber();
      CreatureGraveyard.loadCreatureGraveyard();

      // spawning world fishing spots
      FishingSpots.spawnFishingSpots();

      QuestHandler.init();

      NpcLoader.loadAutoSpawn("./data/npcs/spawn-config.cfg");

      HighscoresManager.load();

      // Start up and get a'rollin!
      startup();
      System.out.println("Online!");
      while (!Thread.interrupted()) {
        try {
          cycle();
          sleep();
        } catch (Exception ex) {
          PlayerSave.saveAllPlayers();
          ex.printStackTrace();
        }
      }
      scheduler.schedule(
          new Task() {
            @Override
            protected void execute() {
              if (Thread.interrupted()) {
                PlayerSave.saveAllPlayers();
                stop();
                return;
              }
              try {
                cycle();
              } catch (Exception ex) {
                PlayerSave.saveAllPlayers();
                ex.printStackTrace();
                stop();
              }
            }
          });
    } catch (Exception ex) {
      ex.printStackTrace();
    }
    PluginManager.close();
  }
コード例 #7
0
 @Override
 public void markDirty() {
   if (side.isServer()) {
     playerSave.setCreativeDirty();
   }
 }