Package org.getspout.spoutapi.player

Examples of org.getspout.spoutapi.player.SpoutPlayer


    return spoutPlayers;
  }

  @Override
  public void setVersionString(int playerId, String versionString) {
    SpoutPlayer sp = getPlayer(playerId);
    if (sp instanceof SpoutCraftPlayer) {
      SpoutCraftPlayer scp = (SpoutCraftPlayer)sp;
      scp.setVersionString(versionString);
      System.out.println("[SpoutPlugin] " + scp.getName() + " is running " + scp.getVersionString());
      int build;
View Full Code Here


  }

  @EventHandler
  public void onPluginDisable(PluginDisableEvent event) {
    for (Player i : Bukkit.getServer().getOnlinePlayers()) {
      SpoutPlayer p = SpoutManager.getPlayer(i);
      p.getMainScreen().removeWidgets(event.getPlugin());
    }
  }
View Full Code Here

  }

  @Override
  public void run(int playerId) {
    if (!cached) {
      SpoutPlayer player = SpoutManager.getPlayerFromId(playerId);
      if (player != null) {
        File file = new File(this.file);
        if (file.exists()) {
          player.sendPacket(new PacketCacheFile(plugin, file));
        }
      }
    }
  }
View Full Code Here

  public int getNumBytes() {
    return 34;
  }

  public void run(int playerId) {
    SpoutPlayer p = SpoutManager.getPlayerFromId(playerId);
    InGameHUD mainScreen = p.getMainScreen();
    PopupScreen popup = mainScreen.getActivePopup();
    Screen current = p.getCurrentScreen();

    Screen in = null;
    if (mainScreen != null && screen.equals(mainScreen.getId())) {
      in = mainScreen;
    }
    if (popup != null && screen.equals(popup.getId())) {
      in = popup;
    }
    if (current != null && screen.equals(current.getId())) {
      in = current;
    }
    if (in == null) {
      return;
    }
    if (!in.containsWidget(slot)) {
      return;
    }

    // Slot handling code goes here.
    Slot slot = (Slot) in.getWidget(this.slot);
    try {
      ItemStack stackOnCursor = p.getItemOnCursor();
      if (stackOnCursor == null) {
        stackOnCursor = new ItemStack(0);
      }
      ItemStack stackInSlot = slot.getItem();
      if ((stackOnCursor == null || stackOnCursor.getTypeId() == 0) && stackInSlot.getTypeId() == 0) {
        return; // Nothing to do
      }
      if (stackOnCursor.getTypeId() == 0 && stackInSlot.getTypeId() != 0 && button == 1) { // Split item
        int amountSlot = stackInSlot.getAmount() / 2;
        int amountCursor = stackInSlot.getAmount() - amountSlot;
        if (stackInSlot.getAmount() == 1) {
          amountSlot = 0;
          amountCursor = 1;
        }
        stackOnCursor = stackInSlot.clone();
        stackOnCursor.setAmount(amountCursor);
        stackInSlot.setAmount(amountSlot);
        if (amountSlot == 0) {
          stackInSlot = new ItemStack(0);
        }
        SlotEvent s = new SlotTakeEvent(p, slot, stackInSlot, !slot.onItemTake(stackOnCursor));
        Bukkit.getPluginManager().callEvent(s);
        if (!s.isCancelled()) {
          slot.setItem(stackInSlot);
        } else {
          slot.setDirty(true); // We need to tell the client that the operation was denied.
          return;
        }
      } else if (stackOnCursor != null && (stackInSlot.getTypeId() == 0 || (stackInSlot.getTypeId() == stackOnCursor.getTypeId() && stackInSlot.getDurability() == stackOnCursor.getDurability()))) { // Put item
        ItemStack toPut = stackOnCursor.clone();
        int putAmount = toPut.getAmount();
        if (button == 1) {
          putAmount = 1;
        }
        int amount = stackInSlot.getTypeId() == 0 ? 0 : stackInSlot.getAmount();
        amount += putAmount;
        int maxStackSize = toPut.getMaxStackSize();
        if (maxStackSize == -1) {
          maxStackSize = 64;
        }
        if (amount > maxStackSize) {
          putAmount -= amount - maxStackSize;
          amount = maxStackSize;
        }
        if (putAmount <= 0) {
          return;
        }
        toPut.setAmount(putAmount);
        SlotEvent s = new SlotPutEvent(p, slot, stackInSlot, !slot.onItemPut(toPut));
        Bukkit.getPluginManager().callEvent(s);
        if (!s.isCancelled()) {
          stackOnCursor.setAmount(stackOnCursor.getAmount() - putAmount);
          if (stackOnCursor.getAmount() == 0) {
            stackOnCursor = new ItemStack(0);
          }
          ItemStack put = toPut.clone();
          put.setAmount(amount);
          slot.setItem(put);
        } else {
          slot.setDirty(true); // We need to tell the client that the operation was denied.
        }
      } else if (stackOnCursor == null || stackOnCursor.getTypeId() == 0) { //Take item or shift click
        if (holdingShift) {
          slot.onItemShiftClicked();
          SlotEvent s = new SlotShiftClickEvent(p, slot);
          Bukkit.getPluginManager().callEvent(s);
        } else { // Take item
          SlotEvent s = new SlotTakeEvent(p, slot, stackInSlot, !slot.onItemTake(stackInSlot));
          Bukkit.getPluginManager().callEvent(s);
          if (!s.isCancelled()) {
            stackOnCursor = stackInSlot;
            slot.setItem(new ItemStack(0));
          } else {
            slot.setDirty(true); // We need to tell the client that the operation was denied.
          }
        }
      } else if (stackOnCursor.getTypeId() != stackInSlot.getTypeId() || stackOnCursor.getDurability() != stackInSlot.getDurability()) { // Exchange slot stack and cursor stack
        SlotEvent s = new SlotExchangeEvent(p, slot, stackInSlot, stackOnCursor.clone(), !slot.onItemExchange(stackInSlot, stackOnCursor.clone()));
        Bukkit.getPluginManager().callEvent(s);
        if (!s.isCancelled()) {
          slot.setItem(stackOnCursor.clone());
          stackOnCursor = stackInSlot;
        } else {
          slot.setDirty(true); // We need to tell the client that the operation was denied.
        }
      }

      if (stackOnCursor == null || stackOnCursor.getTypeId() == 0) {
        p.setItemOnCursor(null);
      } else {
        p.setItemOnCursor(stackOnCursor);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
View Full Code Here

    }
  }

  @Override
  public void run(int playerId) {
    SpoutPlayer player = SpoutManager.getPlayerFromId(playerId);
    if (player != null) {
      CraftWorld cw = ((CraftWorld)player.getWorld());
      if (cw.getHandle().chunkProviderServer.unloadQueue.contains(chunkX, chunkZ)) {
        return;
      }
      if (!cw.getHandle().chunkProviderServer.isChunkLoaded(chunkX, chunkZ)) {
        return;
      }
      Chunk c = player.getWorld().getChunkAt(chunkX, chunkZ);
      if (c instanceof SpoutChunk) {
        SpoutChunk chunk = (SpoutChunk)c;
        player.sendPacket(new PacketCustomBlockChunkOverride(chunk.getCustomBlockIds(), chunk.getCustomBlockData(), chunkX, chunkZ));
      }
    }
  }
View Full Code Here

    output.writeString(data);
  }

  @Override
  public void run(int playerId) {
    SpoutPlayer player = SpoutManager.getPlayerFromId(playerId);
    if (player != null) {
      Screen screen = null;
      if (player.getMainScreen().getId().equals(this.screen)) {
        screen = player.getMainScreen();
      }
      if (player.getMainScreen().getActivePopup() != null && player.getMainScreen().getActivePopup().getId().equals(this.screen)) {
        screen = player.getMainScreen().getActivePopup();
      }
      if (player.getCurrentScreen() != null && player.getCurrentScreen().getId().equals(this.screen)) {
        screen = player.getCurrentScreen();
      }
      if (screen != null) {
        Widget control = screen.getWidget(widget);
        if (control != null) {
          if (control instanceof Button) {
View Full Code Here

    output.write(screen);
  }

  @Override
  public void run(int playerId) {
    SpoutPlayer player = SpoutManager.getPlayerFromId(playerId);
    ScreenEvent event;
    switch (ScreenAction.getScreenActionFromId(action)) {
      case Close:
        event = new ScreenCloseEvent(player, player.getMainScreen().getActivePopup(), ScreenType.getType(this.screen));
        Bukkit.getServer().getPluginManager().callEvent(event);
        if (event.isCancelled()) {
          handleScreenCloseCancelled(player, (ScreenCloseEvent) event, true);
        } else if (ScreenType.getType(this.screen) == ScreenType.CUSTOM_SCREEN) {
          handleScreenClose(player, (ScreenCloseEvent) event, true);
        }
        if (!event.isCancelled()) {
          player.openScreen(ScreenType.GAME_SCREEN, false);
        }
        break;
      case Open:
        event = new ScreenOpenEvent(player, player.getMainScreen().getActivePopup(), ScreenType.getType(this.screen));
        Bukkit.getServer().getPluginManager().callEvent(event);
        if (event.isCancelled()) {
          PopupScreen screen = player.getMainScreen().getActivePopup();
          if (screen != null) {
            screen.setDirty(true);
            player.sendImmediatePacket(new PacketWidget(screen, screen.getId()));
          }
        } else {
          player.openScreen(ScreenType.getType(this.screen), false);
        }
        break;
    }
  }
View Full Code Here

    return this;
  }

  @Override
  public Screen removeWidget(Widget widget) {
    SpoutPlayer player = SpoutManager.getPlayerFromId(playerId);
    if (player != null) {
      if (widgets.containsKey(widget)) {
        widgets.remove(widget);
        if (!widget.getType().isServerOnly()) {
          SpoutManager.getPlayerFromId(playerId).sendImmediatePacket(new PacketWidgetRemove(widget, getId()));
View Full Code Here

    return false;
  }

  @Override
  public void onTick() {
    SpoutPlayer player = SpoutManager.getPlayerFromId(playerId);
    if (player != null) {
      // Create a copy because onTick may remove the widget
      Set<Widget> widgetCopy = new HashSet<Widget>(widgets.keySet());
      for (Widget widget : widgetCopy) {
        try {
          widget.onTick();
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
      for (Widget widget : widgets.keySet()) {
        try {
          widget.onAnimate();
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
      for (Widget widget : widgets.keySet()) {
        if (widget.isDirty()) {
          if (!widget.hasSize()/* || !widget.hasPosition()*/) {
            String type = "Unknown";
            try {
              type = widget.getType().getWidgetClass().getSimpleName();
            } catch (Exception e) {
            }
            Logger.getLogger("Minecraft").log(Level.WARNING,
                type
                    + " belonging to " + widget.getPlugin().getDescription().getName()
                    + " does not have a default "
                    + (!widget.hasSize() ? "size" : "") + (!widget.hasSize() && !widget.hasPosition() ? " or " : "") + (!widget.hasPosition() ? "position" : "")
                    + "!");
            widget.setX(widget.getX());
            widget.setHeight(widget.getHeight());
          }
          if (!widget.getType().isServerOnly()) {
            player.sendImmediatePacket(new PacketWidget(widget, getId()));
          }
          widget.setDirty(false);
        }
      }
    }
View Full Code Here

    output.writeBoolean(focus);
  }

  @Override
  public void run(int playerId) {
    SpoutPlayer player = SpoutManager.getPlayerFromId(playerId);
    if (player != null) {
      PopupScreen popup = player.getMainScreen().getActivePopup();
      if (popup != null) {
        Widget w = popup.getWidget(widgetId);
        if (w != null && w instanceof Control) {
          ((Control) w).setFocus(focus);
        }
View Full Code Here

TOP

Related Classes of org.getspout.spoutapi.player.SpoutPlayer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.