Package simpleserver

Examples of simpleserver.Coordinate


    super("warpto [player] x y z", "Teleport (a player) to the given coordinates");
  }

  public void execute(Player player, String message) {
    String args[] = extractArguments(message);
    Coordinate c;

    if (args.length < 3) {
      player.addTMessage(Color.GRAY, "Usage: warpto [player] x y z");
      return;
    }

    Player target = player;
    if (args.length > 3) {
      String trg = args[0];
      target = player.getServer().findPlayer(trg);
      if (target == null) {
        player.addTMessage(Color.RED, "Player not online (%s)", trg);
        return;
      }
    }

    int x = 0;
    int y = 0;
    int z = 0;
    try {
      x = Integer.valueOf(args[args.length - 3]);
      y = Integer.valueOf(args[args.length - 2]);
      z = Integer.valueOf(args[args.length - 1]);
    } catch (Exception e) {
      player.addTMessage(Color.RED, "Invalid coordinate!");
      return;
    }

    c = new Coordinate(x, y, z);
    target.teleportSelf(c);
    player.getServer().adminLog("Admin " + player.getName() + " teleported:\t "
        + target.getName() + "\tto\t" + c.toString());
  }
View Full Code Here


  }

  private void loadChests(NBTList<NBTCompound> node) {
    for (int i = 0; i < node.size(); i++) {
      NBTCompound tag = node.get(i);
      Coordinate coord;
      try {
        coord = new Coordinate(tag.getCompound("coordinate"));
      } catch (Exception e) {
        System.out.println("Skipping corrupt chest");
        continue;
      }
      Chest chest;
View Full Code Here

      player.addTMessage(Color.RED, "This event name is already taken!");
      return;
    }

    Event e = new Event(args[0],
                        new Coordinate((int) player.x(), (int) player.y(), (int) player.z(), player.getDimension()));
    player.getServer().config.events.add(e);
    player.getServer().saveConfig();

    player.addTMessage(Color.GRAY, "Event created!");
  }
View Full Code Here

    // String.format("%02x", packetId));
    int x;
    byte y;
    int z;
    byte dimension;
    Coordinate coordinate;
    switch (packetId) {
      case 0x00: // Keep Alive
        write(packetId);
        write(in.readInt()); // random number that is returned from server
        break;
      case 0x01: // Login Request/Response
        write(packetId);
        if (!isServerTunnel) {
          write(in.readInt());
          write(readUTF16());
          copyNBytes(5);
          break;
        }
        player.setEntityId(write(in.readInt()));
        write(readUTF16());

        write(in.readByte());

        dimension = in.readByte();
        if (isServerTunnel) {
          player.setDimension(Dimension.get(dimension));
        }
        write(dimension);
        write(in.readByte());
        write(in.readByte());
        if (isServerTunnel) {
          in.readByte();
          write((byte) server.config.properties.getInt("maxPlayers"));
        } else {
          write(in.readByte());
        }

        break;
      case 0x02: // Handshake
        byte version = in.readByte();
        String name = readUTF16();
        boolean nameSet = false;

        if (name.contains(";")) {
          name = name.substring(0, name.indexOf(";"));
        }
        if (name.equals("Player") || !server.authenticator.isMinecraftUp) {
          AuthRequest req = server.authenticator.getAuthRequest(player.getIPAddress());
          if (req != null) {
            name = req.playerName;
            nameSet = server.authenticator.completeLogin(req, player);
          }
          if (req == null || !nameSet) {
            if (!name.equals("Player")) {
              player.addTMessage(Color.RED, "Login verification failed.");
              player.addTMessage(Color.RED, "You were logged in as guest.");
            }
            name = server.authenticator.getFreeGuestName();
            player.setGuest(true);
            nameSet = player.setName(name);
          }
        } else {
          nameSet = player.setName(name);
          if (nameSet) {
            player.updateRealName(name);
          }
        }

        if (player.isGuest() && !server.authenticator.allowGuestJoin()) {
          player.kick(t("Failed to login: User not authenticated"));
          nameSet = false;
        }

        tunneler.setName(streamType + "-" + player.getName());
        write(packetId);
        write(version);
        write(player.getName());
        write(readUTF16());
        write(in.readInt());

        break;
      case 0x03: // Chat Message
        String message = readUTF16();
        MessagePacket messagePacket = new Message().decodeMessage(message);

        if (messagePacket == null) {
          // we are raw text, handle as such

          if (isServerTunnel && server.config.properties.getBoolean("useMsgFormats")) {
            if (server.config.properties.getBoolean("forwardChat") && server.getMessager().wasForwarded(message)) {
              break;
            }

            Matcher colorMatcher = COLOR_PATTERN.matcher(message);
            String cleanMessage = colorMatcher.replaceAll("");

            Matcher messageMatcher = MESSAGE_PATTERN.matcher(cleanMessage);
            if (messageMatcher.find()) {

            } else if (cleanMessage.matches(CONSOLE_CHAT_PATTERN) && !server.config.properties.getBoolean("chatConsoleToOps")) {
              break;
            }

            if (server.config.properties.getBoolean("msgWrap")) {
              sendMessage(message);
            } else {
              if (message.length() > MAXIMUM_MESSAGE_SIZE) {
                //message = message.substring(0, MAXIMUM_MESSAGE_SIZE);
              }
              write(packetId);
              write(message);
            }
          } else if (!isServerTunnel) {

            if (player.isMuted() && !message.startsWith("/")
                    && !message.startsWith("!")) {
              player.addTMessage(Color.RED, "You are muted! You may not send messages to all players.");
              break;
            }

            if (message.charAt(0) == commandPrefix) {
              message = player.parseCommand(message, false);
              if (message == null) {
                break;
              }
              write(packetId);
              write(message);
              return;
            }

            player.sendMessage(message);
          }
        } else {
          // we have a json object
          if (messagePacket.isJoinedPacket()) {
            String username = messagePacket.getJoinedUsername();

            if (isServerTunnel) {
              if (server.bots.ninja(username)) {
                break;
              }
              if (message.contains("join")) {
                player.addTMessage(Color.YELLOW, "%s joined the game.", username);
              } else {
                player.addTMessage(Color.YELLOW, "%s left the game.", username);
              }
              break;
            }
          } else {
            write(packetId);
            write(message);
          }
        }

        break;

      case 0x04: // Time Update
        write(packetId);
        write(in.readLong());
        long time = in.readLong();
        server.setTime(time);
        write(time);
        break;
      case 0x05: // Player Inventory
        write(packetId);
        write(in.readInt());
        write(in.readShort());
        copyItem();
        break;
      case 0x06: // Spawn Position
        write(packetId);
        copyNBytes(12);
        if (server.options.getBoolean("enableEvents")) {
          server.eventhost.execute(server.eventhost.findEvent("onPlayerConnect"), player, true, null);
        }
        break;
      case 0x07: // Use Entity
        int user = in.readInt();
        int target = in.readInt();
        Player targetPlayer = server.playerList.findPlayer(target);
        if (targetPlayer != null) {
          if (targetPlayer.godModeEnabled()) {
            in.readBoolean();
            break;
          }
        }
        write(packetId);
        write(user);
        write(target);
        copyNBytes(1);
        break;
      case 0x08: // Update Health
        write(packetId);
        player.updateHealth(write(in.readFloat()));
        player.getHealth();
        write(in.readShort());
        write(in.readFloat());
        break;
      case 0x09: // Respawn
        write(packetId);
        if (!isServerTunnel) {
          break;
        }
        player.setDimension(Dimension.get(write(in.readInt())));
        write(in.readByte());
        write(in.readByte());
        write(in.readShort());
        write(readUTF16()); // Added in 1.1 (level type)
        if (server.options.getBoolean("enableEvents") && isServerTunnel) {
          server.eventhost.execute(server.eventhost.findEvent("onPlayerRespawn"), player, true, null);
        }
        break;
      case 0x0a: // Player
        write(packetId);
        copyNBytes(1);
        if (!inGame && !isServerTunnel) {
          player.sendMOTD();

          if (server.config.properties.getBoolean("showListOnConnect")) {
            // display player list if enabled in config
            player.execute(PlayerListCommand.class);
          }

          inGame = true;
        }
        break;
      case 0x0b: // Player Position
        write(packetId);
        copyPlayerLocation();
        copyNBytes(1);
        break;
      case 0x0c: // Player Look
        write(packetId);
        copyPlayerLook();
        copyNBytes(1);
        break;
      case 0x0d: // Player Position & Look
        write(packetId);
        copyPlayerLocation();
        copyPlayerLook();
        copyNBytes(1);
        break;
      case 0x0e: // Player Digging
        if (!isServerTunnel) {
          byte status = in.readByte();
          x = in.readInt();
          y = in.readByte();
          z = in.readInt();
          byte face = in.readByte();

          coordinate = new Coordinate(x, y, z, player);

          if (!player.getGroup().ignoreAreas) {
            BlockPermission perm = server.config.blockPermission(player, coordinate);

            if (!perm.use && status == 0) {
              player.addTMessage(Color.RED, "You can not use this block here!");
              break;
            }
            if (!perm.destroy && status == BLOCK_DESTROYED_STATUS) {
              player.addTMessage(Color.RED, "You can not destroy this block!");
              break;
            }
          }

          boolean locked = server.data.chests.isLocked(coordinate);

          if (!locked || player.ignoresChestLocks() || server.data.chests.canOpen(player, coordinate)) {
            if (locked && status == BLOCK_DESTROYED_STATUS) {
              server.data.chests.releaseLock(coordinate);
              server.data.save();
            }

            write(packetId);
            write(status);
            write(x);
            write(y);
            write(z);
            write(face);

            if (player.instantDestroyEnabled()) {
              packetFinished();
              write(packetId);
              write(BLOCK_DESTROYED_STATUS);
              write(x);
              write(y);
              write(z);
              write(face);
            }

            if (status == BLOCK_DESTROYED_STATUS) {
              player.destroyedBlock();
            }
          }
        } else {
          write(packetId);
          copyNBytes(11);
        }
        break;
      case 0x0f: // Player Block Placement
        x = in.readInt();
        y = in.readByte();
        z = in.readInt();
        coordinate = new Coordinate(x, y, z, player);
        final byte direction = in.readByte();
        final short dropItem = in.readShort();
        byte itemCount = 0;
        short uses = 0;
        byte[] data = null;
        if (dropItem != -1) {
          itemCount = in.readByte();
          uses = in.readShort();
          short dataLength = in.readShort();
          if (dataLength != -1) {
            data = new byte[dataLength];
            in.readFully(data);
          }
        }
        byte blockX = in.readByte();
        byte blockY = in.readByte();
        byte blockZ = in.readByte();

        boolean writePacket = true;
        boolean drop = false;

        BlockPermission perm = server.config.blockPermission(player, coordinate, dropItem);

        if (server.options.getBoolean("enableEvents")) {
          player.checkButtonEvents(new Coordinate(x + (x < 0 ? 1 : 0), y + 1, z + (z < 0 ? 1 : 0)));
        }

        if (isServerTunnel || server.data.chests.isChest(coordinate)) {
          // continue
        } else if (!player.getGroup().ignoreAreas && ((dropItem != -1 && !perm.place) || !perm.use)) {
          if (!perm.use) {
            player.addTMessage(Color.RED, "You can not use this block here!");
          } else {
            player.addTMessage(Color.RED, "You can not place this block here!");
          }

          writePacket = false;
          drop = true;
        } else if (dropItem == 54) {
          int xPosition = x;
          byte yPosition = y;
          int zPosition = z;
          switch (direction) {
            case 0:
              --yPosition;
              break;
            case 1:
              ++yPosition;
              break;
            case 2:
              --zPosition;
              break;
            case 3:
              ++zPosition;
              break;
            case 4:
              --xPosition;
              break;
            case 5:
              ++xPosition;
              break;
          }

          Coordinate targetBlock = new Coordinate(xPosition, yPosition, zPosition, player);

          Chest adjacentChest = server.data.chests.adjacentChest(targetBlock);

          if (adjacentChest != null && !adjacentChest.isOpen() && !adjacentChest.ownedBy(player)) {
            player.addTMessage(Color.RED, "The adjacent chest is locked!");
            writePacket = false;
            drop = true;
          } else {
            player.placingChest(targetBlock);
          }
        }

        if (writePacket) {
          write(packetId);
          write(x);
          write(y);
          write(z);
          write(direction);
          write(dropItem);

          if (dropItem != -1) {
            write(itemCount);
            write(uses);
            if (data != null) {
              write((short) data.length);
              out.write(data);
            } else {
              write((short) -1);
            }

            if (dropItem <= 94 && direction >= 0) {
              player.placedBlock();
            }
          }
          write(blockX);
          write(blockY);
          write(blockZ);

          player.openingChest(coordinate);

        } else if (drop) {
          // Drop the item in hand. This keeps the client state in-sync with the
          // server. This generally prevents empty-hand clicks by the client
          // from placing blocks the server thinks the client has in hand.
          write((byte) 0x0e);
          write((byte) 0x04);
          write(x);
          write(y);
          write(z);
          write(direction);
        }

        break;
      case 0x10: // Holding Change
        write(packetId);
        copyNBytes(2);
        break;
      case 0x11: // Use Bed
        write(packetId);
        copyNBytes(14);
        break;
      case 0x12: // Animation
        write(packetId);
        copyNBytes(5);
        break;
      case 0x13: // Entity Action
        write(packetId);
        write(in.readInt());
        write(in.readByte());
        write(in.readInt());
        break;
      case 0x14: // Named Entity Spawn
        int eid = in.readInt();
        name = readUTF16();
        if (!server.bots.ninja(name)) {
          write(packetId);
          write(eid);
          write(name);
          copyNBytes(16);
          copyUnknownBlob();
        } else {
          skipNBytes(16);
          skipUnknownBlob();
        }
        break;
      case 0x16: // Collect Item
        write(packetId);
        copyNBytes(8);
        break;
      case 0x17: // Add Object/Vehicle
        write(packetId);
        write(in.readInt());
        write(in.readByte());
        write(in.readInt());
        write(in.readInt());
        write(in.readInt());
        write(in.readByte());
        write(in.readByte());
        int flag = in.readInt();
        write(flag);
        if (flag > 0) {
          write(in.readShort());
          write(in.readShort());
          write(in.readShort());
        }
        break;
      case 0x18: // Mob Spawn
        write(packetId);
        write(in.readInt());
        write(in.readByte());
        write(in.readInt());
        write(in.readInt());
        write(in.readInt());
        write(in.readByte());
        write(in.readByte());
        write(in.readByte());
        write(in.readShort());
        write(in.readShort());
        write(in.readShort());

        copyUnknownBlob();
        break;
      case 0x19: // Entity: Painting
        write(packetId);
        write(in.readInt());
        write(readUTF16());
        write(in.readInt());
        write(in.readInt());
        write(in.readInt());
        write(in.readInt());
        break;
      case 0x1a: // Experience Orb
        write(packetId);
        write(in.readInt());
        write(in.readInt());
        write(in.readInt());
        write(in.readInt());
        write(in.readShort());
        break;
      case 0x1b: // Steer Vehicle
        write(packetId);
        write(in.readFloat());
        write(in.readFloat());
        write(in.readBoolean());
        write(in.readBoolean());
        break;
      case 0x1c: // Entity Velocity
        write(packetId);
        copyNBytes(10);
        break;
      case 0x1d: // Destroy Entity
        write(packetId);
        byte destoryCount = write(in.readByte());
        if (destoryCount > 0) {
          copyNBytes(destoryCount * 4);
        }
        break;
      case 0x1e: // Entity
        write(packetId);
        copyNBytes(4);
        break;
      case 0x1f: // Entity Relative Move
        write(packetId);
        copyNBytes(7);
        break;
      case 0x20: // Entity Look
        write(packetId);
        copyNBytes(6);
        break;
      case 0x21: // Entity Look and Relative Move
        write(packetId);
        copyNBytes(9);
        break;
      case 0x22: // Entity Teleport
        write(packetId);
        copyNBytes(18);
        break;
      case 0x23: // Entitiy Look
        write(packetId);
        write(in.readInt());
        write(in.readByte());
        break;
      case 0x26: // Entity Status
        write(packetId);
        copyNBytes(5);
        break;
      case 0x27: // Attach Entity
        write(packetId);
        write(in.readInt());
        write(in.readInt());
        write(in.readBoolean());
        break;
      case 0x28: // Entity Metadata
        write(packetId);
        write(in.readInt());

        copyUnknownBlob();
        break;
      case 0x29: // Entity Effect
        write(packetId);
        write(in.readInt());
        write(in.readByte());
        write(in.readByte());
        write(in.readShort());
        break;
      case 0x2a: // Remove Entity Effect
        write(packetId);
        write(in.readInt());
        write(in.readByte());
        break;
      case 0x2b: // Experience
        write(packetId);
        player.updateExperience(write(in.readFloat()), write(in.readShort()), write(in.readShort()));
        break;
      case 0x2c: // Entity Properties
        write(packetId);
        write(in.readInt());
        int properties_count = in.readInt();
        short list_length = 0;
        write(properties_count);

        // loop for every property key/value pair
        for (int i = 0; i < properties_count; i++) {
          write(readUTF16());
          write(in.readDouble());

          // grab list elements
          list_length = in.readShort();
          write(list_length);
          if (list_length > 0) {
            for (int k = 0; k < list_length; k++) {
              write(in.readLong());
              write(in.readLong());
              write(in.readDouble());
              write(in.readByte());
            }
          }
        }
        break;
      case 0x33: // Map Chunk
        write(packetId);
        write(in.readInt());
        write(in.readInt());
        write(in.readBoolean());
        write(in.readShort());
        write(in.readShort());
        copyNBytes(write(in.readInt()));
        break;
      case 0x34: // Multi Block Change
        write(packetId);
        write(in.readInt());
        write(in.readInt());
        write(in.readShort());
        copyNBytes(write(in.readInt()));
        break;
      case 0x35: // Block Change
        write(packetId);
        x = in.readInt();
        y = in.readByte();
        z = in.readInt();
        short blockType = in.readShort();
        byte metadata = in.readByte();
        coordinate = new Coordinate(x, y, z, player);

        if (blockType == 54 && player.placedChest(coordinate)) {
          lockChest(coordinate);
          player.placingChest(null);
        }
View Full Code Here

  void convert(Attributes attributes, Stack<PermissionContainer> stack) throws SAXException {
    PermissionContainer container = stack.peek();

    String[] parts = attributes.getValue("start").split(";");
    String[] coords = parts[0].split(",");
    Coordinate start;
    if (coords.length == 2) {
      start = new Coordinate(getInt(coords[0]), 0, getInt(coords[1]));
    } else if (coords.length >= 3) {
      start = new Coordinate(getInt(coords[0]), getInt(coords[1]), getInt(coords[2]));
    } else {
      throw new SAXException("Invalid coordinate: " + parts[0]);
    }

    Dimension dimension = (parts.length >= 2) ? Dimension.get(parts[1]) : Dimension.EARTH;

    parts = attributes.getValue("end").split(";");
    coords = parts[0].split(",");
    Coordinate end;
    if (coords.length == 2) {
      end = new Coordinate(getInt(coords[0]), 127, getInt(coords[1]));
    } else if (coords.length >= 3) {
      end = new Coordinate(getInt(coords[0]), getInt(coords[1]), getInt(coords[2]));
    } else {
      throw new SAXException("Invalid coordinate: " + parts[0]);
    }

    if (!((Config) stack.firstElement()).dimensions.contains(dimension)) {
View Full Code Here

      z = data.getInt("SpawnZ").get();
    } catch (Exception e) {
      x = z = 0;
      y = 62;
    }
    return new Coordinate(x, y, z, Dimension.EARTH);
  }
View Full Code Here

        name = tokens[6];
      } else {
        name = (tokens[0].equals("-")) ? "-" : t("Locked Chest");
      }

      Coordinate coordinate = new Coordinate(x, y, z, dimension);
      locations.put(coordinate, new Chest(tokens[0], coordinate, Boolean.parseBoolean(tokens[1]), name));
    }
  }
View Full Code Here

    } else {
      y = getInt(parts[1]);
      z = getInt(parts[2]);
    }

    return new Coordinate(x, y, z);
  }
View Full Code Here

    if (p == null) {
      notifyError("Source player not online!");
      return;
    }

    Coordinate c = null;

    String dest = tokens.get(1);

    // Try to find such a player
    Player q = server.findPlayer(dest);
View Full Code Here

      z = Integer.valueOf(tokens.remove(0));
    } catch (Exception e) {
      notifyError("Invalid NPC spawn coordinate!");
      return;
    }
    Coordinate c = new Coordinate(x, y, z);

    try {
      NpcBot s = new NpcBot(name, event.name, server, c);
      server.bots.connect(s);
      eventHost.npcs.put(name, s);
View Full Code Here

TOP

Related Classes of simpleserver.Coordinate

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.