Search in sources :

Example 96 with EntityType

use of org.bukkit.entity.EntityType in project Citizens2 by CitizensDev.

the class NPCCommands method create.

@Command(aliases = { "npc" }, usage = "create [name] ((-b,u) --at (x:y:z:world) --type (type) --trait ('trait1, trait2...') --b (behaviours))", desc = "Create a new NPC", flags = "bu", modifiers = { "create" }, min = 2, permission = "citizens.npc.create")
@Requirements
public void create(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    String name = Colorizer.parseColors(args.getJoinedStrings(1).trim());
    EntityType type = EntityType.PLAYER;
    if (args.hasValueFlag("type")) {
        String inputType = args.getFlag("type");
        type = Util.matchEntityType(inputType);
        if (type == null) {
            throw new CommandException(Messaging.tr(Messages.NPC_CREATE_INVALID_MOBTYPE, inputType));
        } else if (!EntityControllers.controllerExistsForType(type)) {
            throw new CommandException(Messaging.tr(Messages.NPC_CREATE_MISSING_MOBTYPE, inputType));
        }
    }
    int nameLength = type == EntityType.PLAYER ? 46 : 64;
    if (name.length() > nameLength) {
        Messaging.sendErrorTr(sender, Messages.NPC_NAME_TOO_LONG);
        name = name.substring(0, nameLength);
    }
    if (name.length() == 0)
        throw new CommandException();
    if (!sender.hasPermission("citizens.npc.create.*") && !sender.hasPermission("citizens.npc.createall") && !sender.hasPermission("citizens.npc.create." + type.name().toLowerCase().replace("_", "")))
        throw new NoPermissionsException();
    npc = npcRegistry.createNPC(type, name);
    String msg = "You created [[" + npc.getName() + "]]";
    int age = 0;
    if (args.hasFlag('b')) {
        if (!Ageable.class.isAssignableFrom(type.getEntityClass()))
            Messaging.sendErrorTr(sender, Messages.MOBTYPE_CANNOT_BE_AGED, type.name().toLowerCase().replace("_", "-"));
        else {
            age = -24000;
            msg += " as a baby";
        }
    }
    // Initialize necessary traits
    if (!Setting.SERVER_OWNS_NPCS.asBoolean()) {
        npc.getTrait(Owner.class).setOwner(sender);
    }
    npc.getTrait(MobType.class).setType(type);
    Location spawnLoc = null;
    if (sender instanceof Player) {
        spawnLoc = args.getSenderLocation();
    } else if (sender instanceof BlockCommandSender) {
        spawnLoc = args.getSenderLocation();
    }
    CommandSenderCreateNPCEvent event = sender instanceof Player ? new PlayerCreateNPCEvent((Player) sender, npc) : new CommandSenderCreateNPCEvent(sender, npc);
    Bukkit.getPluginManager().callEvent(event);
    if (event.isCancelled()) {
        npc.destroy();
        String reason = "Couldn't create NPC.";
        if (!event.getCancelReason().isEmpty())
            reason += " Reason: " + event.getCancelReason();
        throw new CommandException(reason);
    }
    if (args.hasValueFlag("at")) {
        spawnLoc = CommandContext.parseLocation(args.getSenderLocation(), args.getFlag("at"));
    }
    if (spawnLoc == null) {
        npc.destroy();
        throw new CommandException(Messages.INVALID_SPAWN_LOCATION);
    }
    if (!args.hasFlag('u')) {
        npc.spawn(spawnLoc);
    }
    if (args.hasValueFlag("trait")) {
        Iterable<String> parts = Splitter.on(',').trimResults().split(args.getFlag("trait"));
        StringBuilder builder = new StringBuilder();
        for (String tr : parts) {
            Trait trait = CitizensAPI.getTraitFactory().getTrait(tr);
            if (trait == null)
                continue;
            npc.addTrait(trait);
            builder.append(StringHelper.wrap(tr) + ", ");
        }
        if (builder.length() > 0)
            builder.delete(builder.length() - 2, builder.length());
        msg += " with traits " + builder.toString();
    }
    if (args.hasValueFlag("template")) {
        Iterable<String> parts = Splitter.on(',').trimResults().split(args.getFlag("template"));
        StringBuilder builder = new StringBuilder();
        for (String part : parts) {
            Template template = Template.byName(part);
            if (template == null)
                continue;
            template.apply(npc);
            builder.append(StringHelper.wrap(part) + ", ");
        }
        if (builder.length() > 0)
            builder.delete(builder.length() - 2, builder.length());
        msg += " with templates " + builder.toString();
    }
    // Set age after entity spawns
    if (npc.getEntity() instanceof Ageable) {
        npc.getTrait(Age.class).setAge(age);
    }
    selector.select(sender, npc);
    Messaging.send(sender, msg + '.');
}
Also used : PlayerCreateNPCEvent(net.citizensnpcs.api.event.PlayerCreateNPCEvent) Owner(net.citizensnpcs.api.trait.trait.Owner) Player(org.bukkit.entity.Player) ServerCommandException(net.citizensnpcs.api.command.exception.ServerCommandException) CommandException(net.citizensnpcs.api.command.exception.CommandException) Ageable(org.bukkit.entity.Ageable) MobType(net.citizensnpcs.api.trait.trait.MobType) CommandSenderCreateNPCEvent(net.citizensnpcs.api.event.CommandSenderCreateNPCEvent) Template(net.citizensnpcs.npc.Template) EntityType(org.bukkit.entity.EntityType) NoPermissionsException(net.citizensnpcs.api.command.exception.NoPermissionsException) Trait(net.citizensnpcs.api.trait.Trait) WitherTrait(net.citizensnpcs.trait.WitherTrait) SheepTrait(net.citizensnpcs.trait.SheepTrait) ScriptTrait(net.citizensnpcs.trait.ScriptTrait) ArmorStandTrait(net.citizensnpcs.trait.ArmorStandTrait) Age(net.citizensnpcs.trait.Age) Location(org.bukkit.Location) CurrentLocation(net.citizensnpcs.trait.CurrentLocation) BlockCommandSender(org.bukkit.command.BlockCommandSender) Command(net.citizensnpcs.api.command.Command) Requirements(net.citizensnpcs.api.command.Requirements)

Example 97 with EntityType

use of org.bukkit.entity.EntityType in project NoCheatPlus by NoCheatPlus.

the class VehicleChecks method onVehicleUpdate.

/**
 * This should always fire, prefer over VehicleMoveEvent, if possible.
 *
 * @param event
 */
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onVehicleUpdate(final VehicleUpdateEvent event) {
    // TODO: VehicleUpdateEvent. How to track teleporting of the vehicle?
    // TODO: Track just left vehicle/entity positions otherwise (on tick + vehicle update)?
    // TODO: No problem: (?) update 'authorized state' if no player passenger.
    final Vehicle vehicle = event.getVehicle();
    final EntityType vehicleType = vehicle.getType();
    if (!normalVehicles.contains(vehicleType)) {
        // A little extra sweep to check for debug flags.
        normalVehicles.add(vehicleType);
        if (worldDataManager.getWorldData(vehicle.getWorld()).isDebugActive(checkType)) {
            debug(null, "VehicleUpdateEvent fired for: " + vehicleType);
        }
    }
    // TODO: Detect if a VehicleMove event will fire (not strictly possible without nms, depends on visibility of fields, possibly estimate instead?).
    if (vehicle.getVehicle() != null) {
        // Do ignore events for vehicles inside of other vehicles.
        return;
    }
    final Player player = passengerUtil.getFirstPlayerPassenger(vehicle);
    if (player == null || player.isDead()) {
        return;
    }
    if (vehicle.isDead() || !vehicle.isValid()) {
        // TODO: Actually force dismount?
        onPlayerVehicleLeave(player, vehicle);
        return;
    }
    final IPlayerData pData = DataManager.getPlayerData(player);
    final MovingData data = pData.getGenericInstance(MovingData.class);
    // final MovingConfig cc = MovingConfig.getConfig(player);
    final boolean debug = pData.isDebugActive(checkType);
    if (debug) {
        final Location loc = vehicle.getLocation(useLoc1);
        debug(player, "VehicleUpdateEvent: " + vehicleType + " " + loc);
        useLoc1.setWorld(null);
    }
    onVehicleUpdate(vehicle, vehicleType, player, false, data, pData, debug);
}
Also used : Vehicle(org.bukkit.entity.Vehicle) EntityType(org.bukkit.entity.EntityType) Player(org.bukkit.entity.Player) MovingData(fr.neatmonster.nocheatplus.checks.moving.MovingData) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) Location(org.bukkit.Location) RichBoundsLocation(fr.neatmonster.nocheatplus.utilities.location.RichBoundsLocation) EventHandler(org.bukkit.event.EventHandler)

Example 98 with EntityType

use of org.bukkit.entity.EntityType in project NoCheatPlus by NoCheatPlus.

the class BlockCacheCB2512 method standsOnEntity.

@Override
public boolean standsOnEntity(final Entity entity, final double minX, final double minY, final double minZ, final double maxX, final double maxY, final double maxZ) {
    try {
        // TODO: Probably check other ids too before doing this ?
        final net.minecraft.server.v1_4_5.Entity mcEntity = ((CraftEntity) entity).getHandle();
        final AxisAlignedBB box = useBox.b(minX, minY, minZ, maxX, maxY, maxZ);
        @SuppressWarnings("rawtypes") final List list = world.getEntities(mcEntity, box);
        @SuppressWarnings("rawtypes") Iterator iterator = list.iterator();
        while (iterator.hasNext()) {
            final net.minecraft.server.v1_4_5.Entity other = (net.minecraft.server.v1_4_5.Entity) iterator.next();
            final EntityType type = other.getBukkitEntity().getType();
            if (type != EntityType.BOAT && type != EntityType.MINECART)
                continue;
            final AxisAlignedBB otherBox = other.boundingBox;
            if (box.a > otherBox.d || box.d < otherBox.a || box.b > otherBox.e || box.e < otherBox.b || box.c > otherBox.f || box.f < otherBox.c)
                continue;
            else {
                return true;
            }
        }
    } catch (Throwable t) {
    // Ignore exceptions (Context: DisguiseCraft).
    }
    return false;
}
Also used : AxisAlignedBB(net.minecraft.server.v1_4_5.AxisAlignedBB) CraftEntity(org.bukkit.craftbukkit.v1_4_5.entity.CraftEntity) Entity(org.bukkit.entity.Entity) TileEntity(net.minecraft.server.v1_4_5.TileEntity) CraftEntity(org.bukkit.craftbukkit.v1_4_5.entity.CraftEntity) EntityType(org.bukkit.entity.EntityType) Iterator(java.util.Iterator) List(java.util.List)

Example 99 with EntityType

use of org.bukkit.entity.EntityType in project NoCheatPlus by NoCheatPlus.

the class BlockCacheCB2545 method standsOnEntity.

@Override
public boolean standsOnEntity(final Entity entity, final double minX, final double minY, final double minZ, final double maxX, final double maxY, final double maxZ) {
    try {
        // TODO: Probably check other ids too before doing this ?
        final net.minecraft.server.v1_4_6.Entity mcEntity = ((CraftEntity) entity).getHandle();
        final AxisAlignedBB box = useBox.b(minX, minY, minZ, maxX, maxY, maxZ);
        @SuppressWarnings("rawtypes") final List list = world.getEntities(mcEntity, box);
        @SuppressWarnings("rawtypes") Iterator iterator = list.iterator();
        while (iterator.hasNext()) {
            final net.minecraft.server.v1_4_6.Entity other = (net.minecraft.server.v1_4_6.Entity) iterator.next();
            final EntityType type = other.getBukkitEntity().getType();
            if (type != EntityType.BOAT && type != EntityType.MINECART)
                continue;
            final AxisAlignedBB otherBox = other.boundingBox;
            if (box.a > otherBox.d || box.d < otherBox.a || box.b > otherBox.e || box.e < otherBox.b || box.c > otherBox.f || box.f < otherBox.c)
                continue;
            else {
                return true;
            }
        }
    } catch (Throwable t) {
    // Ignore exceptions (Context: DisguiseCraft).
    }
    return false;
}
Also used : AxisAlignedBB(net.minecraft.server.v1_4_6.AxisAlignedBB) CraftEntity(org.bukkit.craftbukkit.v1_4_6.entity.CraftEntity) Entity(org.bukkit.entity.Entity) TileEntity(net.minecraft.server.v1_4_6.TileEntity) CraftEntity(org.bukkit.craftbukkit.v1_4_6.entity.CraftEntity) EntityType(org.bukkit.entity.EntityType) Iterator(java.util.Iterator) List(java.util.List)

Example 100 with EntityType

use of org.bukkit.entity.EntityType in project Minigames by AddstarMC.

the class SpawnEntityAction method displayMenu.

@Override
public boolean displayMenu(MinigamePlayer player, Menu previous) {
    Menu m = new Menu(3, "Spawn Entity", player);
    m.addItem(new MenuItemPage("Back", MenuUtility.getBackMaterial(), previous), m.getSize() - 9);
    List<String> options = new ArrayList<>();
    for (EntityType type : EntityType.values()) {
        if (type != EntityType.ITEM_FRAME && type != EntityType.LEASH_HITCH && type != EntityType.PLAYER && type != EntityType.LIGHTNING && type != EntityType.PAINTING && type != EntityType.UNKNOWN && type != EntityType.DROPPED_ITEM)
            options.add(MinigameUtils.capitalize(type.toString().replace("_", " ")));
    }
    m.addItem(new MenuItemList("Entity Type", Material.SKELETON_SKULL, new Callback<String>() {

        @Override
        public void setValue(String value) {
            type.setFlag(value.toUpperCase().replace(" ", "_"));
            settings.clear();
            addBaseSettings();
        }

        @Override
        public String getValue() {
            return MinigameUtils.capitalize(type.getFlag().replace("_", " "));
        }
    }, options));
    m.addItem(new MenuItemDecimal("X Velocity", Material.ARROW, new Callback<Double>() {

        @Override
        public void setValue(Double value) {
            settings.put("velocityx", value.toString());
        }

        @Override
        public Double getValue() {
            return Double.valueOf(settings.get("velocityx"));
        }
    }, 0.5, 1, null, null));
    m.addItem(new MenuItemDecimal("Y Velocity", Material.ARROW, new Callback<Double>() {

        @Override
        public void setValue(Double value) {
            settings.put("velocityy", value.toString());
        }

        @Override
        public Double getValue() {
            return Double.valueOf(settings.get("velocityy"));
        }
    }, 0.5, 1, null, null));
    m.addItem(new MenuItemDecimal("Z Velocity", Material.ARROW, new Callback<Double>() {

        @Override
        public void setValue(Double value) {
            settings.put("velocityz", value.toString());
        }

        @Override
        public Double getValue() {
            return Double.valueOf(settings.get("velocityz"));
        }
    }, 0.5, 1, null, null));
    m.addItem(new MenuItemNewLine());
    final Menu eSet = new Menu(3, "Settings", player);
    final MenuItemPage backButton = new MenuItemPage("Back", MenuUtility.getBackMaterial(), m);
    final MenuItemCustom cus = new MenuItemCustom("Entity Settings", Material.CHEST);
    final MinigamePlayer fply = player;
    cus.setClick(object -> {
        if (type.getFlag().equals("ZOMBIE")) {
            eSet.clearMenu();
            eSet.addItem(backButton, eSet.getSize() - 9);
            livingEntitySettings(eSet);
            eSet.displayMenu(fply);
            return null;
        }
        return cus.getItem();
    });
    m.addItem(cus);
    m.displayMenu(player);
    return true;
}
Also used : MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) ArrayList(java.util.ArrayList) EntityType(org.bukkit.entity.EntityType)

Aggregations

EntityType (org.bukkit.entity.EntityType)109 ArrayList (java.util.ArrayList)29 ItemStack (org.bukkit.inventory.ItemStack)28 Material (org.bukkit.Material)23 Player (org.bukkit.entity.Player)23 Entity (org.bukkit.entity.Entity)19 Location (org.bukkit.Location)17 IOException (java.io.IOException)16 File (java.io.File)13 LivingEntity (org.bukkit.entity.LivingEntity)13 EventHandler (org.bukkit.event.EventHandler)12 PotionType (org.bukkit.potion.PotionType)12 HashMap (java.util.HashMap)10 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)9 Block (org.bukkit.block.Block)8 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)8 World (org.bukkit.World)7 SpawnEgg (org.bukkit.material.SpawnEgg)7 UUID (java.util.UUID)5 Biome (org.bukkit.block.Biome)5