@EventHandler(priority = EventPriority.MONITOR)
  public void stackPlayer(PlayerInteractEntityEvent event) {
    // Do nothing if clicked entity is not a player.
    if (!(event.getRightClicked() instanceof Player)) return;

    // Do nothing if player does not have permission.
    Player player = event.getPlayer();
    if (!Perm.PLAYERSTACKER.has(player)) return;

    // Do nothing if clicking player is not stacking.
    User user = plugin.getUser(player.getUniqueId());
    if (user != null && !user.isStacking()) return;

    // Do nothing if clicked player is not stacking.
    Player clicked = (Player) event.getRightClicked();
    user = plugin.getUser(clicked.getUniqueId());
    if (user != null && !user.isStacking()) return;

    // Do nothing if player or clicked player are inside a vehicle.
    if (clicked.isInsideVehicle() || player.isInsideVehicle()) return;

    // Stack the player.
    Entity topPassenger = getTopPassenger(player);
    topPassenger.setPassenger(clicked);
  }
 public Entity addRider(Entity vehicle, ISpawnableEntity riderData) {
   Location vehicleLoc = vehicle.getLocation();
   Entity rider = spawnMobAt(riderData, vehicleLoc);
   vehicle.setPassenger(rider);
   spawner.addSecondaryMob(rider.getUniqueId(), vehicle.getUniqueId());
   return rider;
 }
Example #3
0
 @Override
 @Permission({
   "crazyspawner.mountme.self",
   "crazyspawner.mountme.others",
   "crazyspawner.mountme.*",
   "crazyspawner.mountme.<ENTITYTYPE>.*",
   "crazyspawner.mountme.<CUSTOMENTITYNAME>"
 })
 @Localized({
   "CRAZYSPAWNER.COMMAND.MOUNTME.SELF $EntityType$",
   "CRAZYSPAWNER.COMMAND.MOUNTME.OTHER $EntityType$ $MountedPlayer$",
   "CRAZYSPAWNER.COMMAND.MOUNTME.MOUNTED $EntityType$ $Sender$"
 })
 public void command(final CommandSender sender, final String[] args) throws CrazyException {
   final Map<String, TabbedParamitrisable> params = new TreeMap<String, TabbedParamitrisable>();
   final NamedEntitySpawnerParamitrisable spawnerParam =
       new NamedEntitySpawnerParamitrisable((NamedEntitySpawner) null);
   params.put("c", spawnerParam);
   params.put("creature", spawnerParam);
   params.put("e", spawnerParam);
   params.put("entity", spawnerParam);
   final PlayerParamitrisable playerParam = new PlayerParamitrisable(sender);
   params.put("p", playerParam);
   params.put("plr", playerParam);
   params.put("player", playerParam);
   ChatHelperExtended.readParameters(args, params, spawnerParam, playerParam);
   final NamedEntitySpawner spawner = spawnerParam.getValue();
   if (spawner == null)
     throw new CrazyCommandUsageException("<entity:NamedEntityType> [player:Player]");
   final Player player = playerParam.getValue();
   if (player == null)
     throw new CrazyCommandUsageException("<entity:NamedEntityType> <player:Player>");
   if (!PermissionModule.hasPermission(
       sender, "crazyspawner.mountme." + (player == sender ? "self" : "others")))
     throw new CrazyCommandPermissionException();
   if (!(PermissionModule.hasPermission(sender, "crazyspawner.mountme.*")
       || PermissionModule.hasPermission(
           sender, "crazyspawner.mountme." + spawner.getType().name() + ".*")
       || PermissionModule.hasPermission(sender, "crazyspawner.mountme." + spawner.getName())))
     throw new CrazyCommandPermissionException();
   Entity entity = spawner.spawn(player.getLocation());
   while (entity.getPassenger() != null) entity = entity.getPassenger();
   entity.setPassenger(player);
   if (player == sender)
     plugin.sendLocaleMessage(
         "COMMAND.MOUNTME.SELF", sender, spawnerParam.getValue().getType().name());
   else {
     plugin.sendLocaleMessage(
         "COMMAND.MOUNTME.OTHER",
         sender,
         spawnerParam.getValue().getType().name(),
         player.getName());
     plugin.sendLocaleMessage(
         "COMMAND.MOUNTME.MOUNTED",
         sender,
         spawnerParam.getValue().getType().name(),
         sender.getName());
   }
 }
 public void play(LivingEntity entity) {
   if (entity.isInsideVehicle()) {
     Entity carrier = entity.getVehicle();
     // if(carrier instanceof Arrow) {
     // entity.leaveVehicle();
     carrier.remove();
     // }
   } else {
     Location loc = entity.getLocation();
     // loc.setY(loc.getY() - 0.5);
     // Arrow arrow = entity.getLocation().getWorld().spawnArrow(loc, new Vector(0, -1, 0), 0, 0);
     // arrow.setPassenger(entity);
     // entity.teleport(loc);
     Entity e = loc.getWorld().spawn(loc, ArmorStand.class);
     e.setPassenger(entity);
   }
 }
Example #5
0
  /**
   * Teleport a player to a location.
   *
   * @param player The player.
   * @param to The location to teleport to.
   * @param keepVehicle Whether or not to keep the vehicle.
   */
  public static void teleport(Player player, Location to, boolean keepVehicle) {
    if (to == null || player == null) return;

    if (player.isInsideVehicle()) {
      // Eject the vehicle...
      Entity vehicle = player.getVehicle();
      vehicle.eject();
      // Teleport the player...
      player.teleport(to);
      // Remove the vehicle if it's not persisting.
      if (!keepVehicle) vehicle.remove();
      else {
        // Otherwise teleport the vehicle and remount.
        vehicle.teleport(to);
        vehicle.setPassenger(player);
      }
      return;
    }

    player.teleport(to);
  }
  @Override
  public void run(Server server, User user, String commandLabel, String[] args) throws Exception {
    if (args.length < 1) {
      throw new NotEnoughArgumentsException();
      // TODO: user.sendMessage("ยง7Mobs: Zombie PigZombie Skeleton Slime Chicken Pig Monster Spider
      // Creeper Ghast Squid Giant Cow Sheep Wolf");
    }

    String[] mountparts = args[0].split(",");
    String[] parts = mountparts[0].split(":");
    String mobType = parts[0];
    mobType = mobType.equalsIgnoreCase("PigZombie") ? "PigZombie" : Util.capitalCase(mobType);
    String mobData = null;
    if (parts.length == 2) {
      mobData = parts[1];
    }
    String mountType = null;
    String mountData = null;
    if (mountparts.length > 1) {
      parts = mountparts[1].split(":");
      mountType = parts[0];
      mountType =
          mountType.equalsIgnoreCase("PigZombie") ? "PigZombie" : Util.capitalCase(mountType);
      if (parts.length == 2) {
        mountData = parts[1];
      }
    }

    if (ess.getSettings().getProtectPreventSpawn(mobType.toLowerCase())
        || (mountType != null
            && ess.getSettings().getProtectPreventSpawn(mountType.toLowerCase()))) {
      throw new Exception(Util.i18n("unableToSpawnMob"));
    }

    Entity spawnedMob = null;
    Mob mob = null;
    Entity spawnedMount = null;
    Mob mobMount = null;

    mob = Mob.fromName(mobType);
    if (mob == null) {
      throw new Exception(Util.i18n("invalidMob"));
    }
    int[] ignore = {8, 9};
    Block block = (new TargetBlock(user, 300, 0.2, ignore)).getTargetBlock();
    if (block == null) {
      user.sendMessage(Util.i18n("unableToSpawnMob"));
      return;
    }
    Location loc = block.getLocation();
    Location sloc = Util.getSafeDestination(loc);
    try {
      spawnedMob = mob.spawn(user, server, sloc);
    } catch (MobException e) {
      user.sendMessage(Util.i18n("unableToSpawnMob"));
      return;
    }

    if (mountType != null) {
      mobMount = Mob.fromName(mountType);
      if (mobMount == null) {
        user.sendMessage(Util.i18n("invalidMob"));
        return;
      }
      try {
        spawnedMount = mobMount.spawn(user, server, loc);
      } catch (MobException e) {
        user.sendMessage(Util.i18n("unableToSpawnMob"));
        return;
      }
      spawnedMob.setPassenger(spawnedMount);
    }
    if (mobData != null) {
      changeMobData(mob.name, spawnedMob, mobData, user);
    }
    if (spawnedMount != null && mountData != null) {
      changeMobData(mobMount.name, spawnedMount, mountData, user);
    }
    if (args.length == 2) {
      int mobCount = Integer.parseInt(args[1]);
      int serverLimit = ess.getSettings().getSpawnMobLimit();
      if (mobCount > serverLimit) {
        mobCount = serverLimit;
        user.sendMessage(Util.i18n("mobSpawnLimit"));
      }

      try {
        for (int i = 1; i < mobCount; i++) {
          spawnedMob = mob.spawn(user, server, loc);
          if (mobMount != null) {
            try {
              spawnedMount = mobMount.spawn(user, server, loc);
            } catch (MobException e) {
              user.sendMessage(Util.i18n("unableToSpawnMob"));
              return;
            }
            spawnedMob.setPassenger(spawnedMount);
          }
          if (mobData != null) {
            changeMobData(mob.name, spawnedMob, mobData, user);
          }
          if (spawnedMount != null && mountData != null) {
            changeMobData(mobMount.name, spawnedMount, mountData, user);
          }
        }
        user.sendMessage(
            args[1] + " " + mob.name.toLowerCase() + mob.suffix + " " + Util.i18n("spawned"));
      } catch (MobException e1) {
        throw new Exception(Util.i18n("unableToSpawnMob"), e1);
      } catch (NumberFormatException e2) {
        throw new Exception(Util.i18n("numberRequired"), e2);
      } catch (NullPointerException np) {
        throw new Exception(Util.i18n("soloMob"), np);
      }
    } else {
      user.sendMessage(mob.name + " " + Util.i18n("spawned"));
    }
  }
  @Override
  public void trigger(ChipState chip) {

    if (!location.getChunk().isLoaded()) return;

    if (!chip.getInput(0)) return;
    Block left = SignUtil.getLeftBlock(BukkitUtil.toSign(getSign()).getBlock());
    ChangedSign effectSign = null;
    if (left.getTypeId() == BlockID.WALL_SIGN) {
      effectSign = BukkitUtil.toChangedSign(left);
    }

    Block right = SignUtil.getRightBlock(BukkitUtil.toSign(getSign()).getBlock());
    ChangedSign armourSign = null;
    if (right.getTypeId() == BlockID.WALL_SIGN) {
      armourSign = BukkitUtil.toChangedSign(right);
    }

    for (int i = 0; i < amount; i++) {
      Entity ent = BukkitUtil.toSign(getSign()).getWorld().spawn(location, type.getEntityClass());

      if (armourSign != null) { // Apply armor
        if (ent instanceof LivingEntity) {

          for (int s = 0; s < 4; s++) {
            String bit = armourSign.getLine(s);

            ItemStack slot = ItemUtil.makeItemValid(ItemUtil.getItem(bit));

            if (s == 0) ((LivingEntity) ent).getEquipment().setHelmet(slot);
            if (s == 1) ((LivingEntity) ent).getEquipment().setChestplate(slot);
            if (s == 2) ((LivingEntity) ent).getEquipment().setLeggings(slot);
            if (s == 3) ((LivingEntity) ent).getEquipment().setBoots(slot);
          }
        }
      }

      Boolean upwards = null;

      while (effectSign != null) { // Apply effects
        for (int s = 0; s < 4; s++) {
          String bit = effectSign.getLine(s);
          if (bit == null || bit.trim().isEmpty()) continue;

          String[] data = RegexUtil.COLON_PATTERN.split(bit);

          if (data[0].equalsIgnoreCase("e")) CreatureSpawner.setEntityData(ent, bit.substring(2));
          else if (data[0].equalsIgnoreCase("r")) {
            EntityType rider = EntityType.fromName(data[1].trim());
            Entity rid = BukkitUtil.toSign(getSign()).getWorld().spawnEntity(location, rider);
            ent.setPassenger(rid);
          } else if (data[0].equalsIgnoreCase("p") && ent instanceof LivingEntity) {
            for (int a = 1; a < data.length; a++) {
              try {
                String[] potionBits = RegexUtil.SEMICOLON_PATTERN.split(data[a]);
                PotionEffect effect =
                    new PotionEffect(
                        PotionEffectType.getById(Integer.parseInt(potionBits[0])),
                        Integer.parseInt(potionBits[1]),
                        Integer.parseInt(potionBits[2]));
                ((LivingEntity) ent).addPotionEffect(effect, true);
              } catch (Exception e) {
              }
            }
          } else if (data[0].equalsIgnoreCase("v")) {
            try {
              double x, y, z;
              String[] coords = RegexUtil.COMMA_PATTERN.split(data[1]);
              x = Double.parseDouble(coords[0]);
              y = Double.parseDouble(coords[1]);
              z = Double.parseDouble(coords[2]);
              ent.setVelocity(new org.bukkit.util.Vector(x, y, z));
            } catch (Exception ignored) {
            }
          } else if (data[0].equalsIgnoreCase("s")) {
            if (!(ent instanceof LivingEntity)) continue;

            ItemStack slot = ItemUtil.makeItemValid(ItemUtil.getItem(bit.replace("s:", "")));
            ((LivingEntity) ent).getEquipment().setItemInHand(slot);
          }
        }
        if (upwards == null) {
          if (BukkitUtil.toSign(effectSign).getBlock().getRelative(0, 1, 0).getTypeId()
              == BlockID.WALL_SIGN) {
            effectSign =
                BukkitUtil.toChangedSign(
                    BukkitUtil.toSign(effectSign).getBlock().getRelative(0, 1, 0));
            upwards = true;
          } else if (BukkitUtil.toSign(effectSign).getBlock().getRelative(0, -1, 0).getTypeId()
              == BlockID.WALL_SIGN) {
            effectSign =
                BukkitUtil.toChangedSign(
                    BukkitUtil.toSign(effectSign).getBlock().getRelative(0, -1, 0));
            upwards = false;
          } else break;
        } else {
          if (BukkitUtil.toSign(effectSign)
                  .getBlock()
                  .getRelative(0, upwards ? 1 : -1, 0)
                  .getTypeId()
              == BlockID.WALL_SIGN)
            effectSign =
                BukkitUtil.toChangedSign(
                    BukkitUtil.toSign(effectSign).getBlock().getRelative(0, upwards ? 1 : -1, 0));
          else break;
        }
      }
    }
  }
 public boolean setPassenger(MCEntity passenger) {
   return e.setPassenger((Entity) passenger.getHandle());
 }