Search in sources :

Example 21 with EntityType

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

the class Controllable method loadController.

private void loadController() {
    EntityType type = npc.getEntity().getType();
    if (explicitType != null) {
        type = explicitType;
    }
    if (!(npc.getEntity() instanceof LivingEntity) && (explicitType == null || explicitType == EntityType.UNKNOWN || npc.getEntity().getType() == explicitType)) {
        controller = new LookAirController();
        return;
    }
    Class<? extends MovementController> clazz = controllerTypes.get(type);
    if (clazz == null) {
        controller = new GroundController();
        return;
    }
    Constructor<? extends MovementController> innerConstructor = null;
    try {
        innerConstructor = clazz.getConstructor(Controllable.class);
        innerConstructor.setAccessible(true);
    } catch (Exception e) {
        e.printStackTrace();
    }
    try {
        if (innerConstructor == null) {
            controller = clazz.newInstance();
        } else {
            controller = innerConstructor.newInstance(this);
        }
    } catch (Exception e) {
        e.printStackTrace();
        controller = new GroundController();
    }
}
Also used : EntityType(org.bukkit.entity.EntityType) LivingEntity(org.bukkit.entity.LivingEntity) NPCLoadException(net.citizensnpcs.api.exception.NPCLoadException)

Example 22 with EntityType

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

the class NPCCommands method type.

@Command(aliases = { "npc" }, usage = "type [type]", desc = "Sets an NPC's entity type", modifiers = { "type" }, min = 2, max = 2, permission = "citizens.npc.type")
public void type(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    EntityType type = Util.matchEntityType(args.getString(1));
    if (type == null)
        throw new CommandException(Messages.INVALID_ENTITY_TYPE, args.getString(1));
    npc.setBukkitEntityType(type);
    Messaging.sendTr(sender, Messages.ENTITY_TYPE_SET, npc.getName(), args.getString(1));
}
Also used : EntityType(org.bukkit.entity.EntityType) ServerCommandException(net.citizensnpcs.api.command.exception.ServerCommandException) CommandException(net.citizensnpcs.api.command.exception.CommandException) Command(net.citizensnpcs.api.command.Command)

Example 23 with EntityType

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

the class NPCCommands method list.

@Command(aliases = { "npc" }, usage = "list (page) ((-a) --owner (owner) --type (type) --char (char) --registry (name))", desc = "List NPCs", flags = "a", modifiers = { "list" }, min = 1, max = 2, permission = "citizens.npc.list")
@Requirements
public void list(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    NPCRegistry source = args.hasValueFlag("registry") ? CitizensAPI.getNamedNPCRegistry(args.getFlag("registry")) : npcRegistry;
    if (source == null)
        throw new CommandException();
    List<NPC> npcs = new ArrayList<NPC>();
    if (args.hasFlag('a')) {
        for (NPC add : source.sorted()) {
            npcs.add(add);
        }
    } else if (args.getValueFlags().size() == 0 && sender instanceof Player) {
        for (NPC add : source.sorted()) {
            if (!npcs.contains(add) && add.getTrait(Owner.class).isOwnedBy(sender)) {
                npcs.add(add);
            }
        }
    } else {
        if (args.hasValueFlag("owner")) {
            String name = args.getFlag("owner");
            for (NPC add : source.sorted()) {
                if (!npcs.contains(add) && add.getTrait(Owner.class).isOwnedBy(name)) {
                    npcs.add(add);
                }
            }
        }
        if (args.hasValueFlag("type")) {
            EntityType type = Util.matchEntityType(args.getFlag("type"));
            if (type == null)
                throw new CommandException(Messages.COMMAND_INVALID_MOBTYPE, type);
            for (NPC add : source) {
                if (!npcs.contains(add) && add.getTrait(MobType.class).getType() == type)
                    npcs.add(add);
            }
        }
    }
    Paginator paginator = new Paginator().header("NPCs");
    paginator.addLine("<e>Key: <a>ID  <b>Name");
    for (int i = 0; i < npcs.size(); i += 2) {
        String line = "<a>" + npcs.get(i).getId() + "<b>  " + npcs.get(i).getName();
        if (npcs.size() >= i + 2)
            line += "      " + "<a>" + npcs.get(i + 1).getId() + "<b>  " + npcs.get(i + 1).getName();
        paginator.addLine(line);
    }
    int page = args.getInteger(1, 1);
    if (!paginator.sendPage(sender, page))
        throw new CommandException(Messages.COMMAND_PAGE_MISSING);
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) EntityType(org.bukkit.entity.EntityType) Player(org.bukkit.entity.Player) Owner(net.citizensnpcs.api.trait.trait.Owner) ArrayList(java.util.ArrayList) ServerCommandException(net.citizensnpcs.api.command.exception.ServerCommandException) CommandException(net.citizensnpcs.api.command.exception.CommandException) Paginator(net.citizensnpcs.api.util.Paginator) NPCRegistry(net.citizensnpcs.api.npc.NPCRegistry) Command(net.citizensnpcs.api.command.Command) Requirements(net.citizensnpcs.api.command.Requirements)

Example 24 with EntityType

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

the class VehicleChecks method onVehicleMove.

/**
 * When a vehicle moves, its player will be checked for various suspicious behaviors.
 *
 * @param event
 *            the event
 */
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onVehicleMove(final VehicleMoveEvent event) {
    // Check data.
    final Vehicle vehicle = event.getVehicle();
    if (vehicle == null) {
        return;
    }
    // Mind that players could be riding horses inside of minecarts etc.
    if (vehicle.getVehicle() != null) {
        // Do ignore events for vehicles inside of other vehicles.
        return;
    }
    final Player player = passengerUtil.getFirstPlayerPassenger(vehicle);
    if (player == null) {
        return;
    }
    if (vehicle.isDead() || !vehicle.isValid()) {
        // TODO: Actually force dismount?
        onPlayerVehicleLeave(player, vehicle);
        return;
    }
    final EntityType vehicleType = vehicle.getType();
    final IPlayerData pData = DataManager.getPlayerData(player);
    final MovingData data = pData.getGenericInstance(MovingData.class);
    final Location from = event.getFrom();
    final Location to = event.getTo();
    if (pData.isDebugActive(checkType)) {
        outputDebugVehicleMoveEvent(player, from, to);
    }
    if (from == null) {
        // TODO: (In case update doesn't, could fake it here.)
        return;
    } else if (from.equals(to)) {
    // Not possible by obc code.
    } else {
        if (!from.getWorld().equals(to.getWorld())) {
            // TODO: Data adjustments will be necessary with the envelope check.
            return;
        }
    // TODO: Check consistency with assumed/tracked past position, both for from and to. Do something based on result.
    }
    if (normalVehicles.contains(vehicleType)) {
        // Assume handled.
        return;
    } else {
    // Should not be possible, unless plugins somehow force this.
    // TODO: Log warning once / what?
    // TODO: Ignore or continue?
    }
    // Process as move.
    final boolean debug = pData.isDebugActive(checkType);
    if (debug) {
        debug(player, "VehicleMoveEvent: legacy handling, potential issue.");
    }
    // TODO: Actually here consistency with past position tracking should be tested.
    // TODO: Abstraction creation before calling checkVehicleMove, compare/align with onVehicleUpdate.
    checkVehicleMove(vehicle, vehicleType, from, to, 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 25 with EntityType

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

the class VehicleChecks method onPlayerMoveVehicle.

/**
 * Called from player-move checking, if the player is inside of a vehicle.
 * @param player
 * @param from
 * @param to
 * @param data
 */
public Location onPlayerMoveVehicle(final Player player, final Location from, final Location to, final MovingData data, final IPlayerData pData) {
    // Workaround for pigs and other (1.5.x and before)!
    // Note that with 1.6 not even PlayerMove fires for horses and pigs.
    // (isInsideVehicle is the faster check without object creation, do re-check though, if it changes to only check for Vehicle instances.)
    final Entity vehicle = passengerUtil.getLastNonPlayerVehicle(player);
    if (pData.isDebugActive(checkType)) {
        debug(player, "onPlayerMoveVehicle: vehicle: " + vehicle);
    }
    data.wasInVehicle = true;
    data.sfHoverTicks = -1;
    data.removeAllVelocity();
    data.sfLowJump = false;
    // TODO: What with processingEvents.remove(player.getName());
    if (vehicle == null || vehicle.isDead() || !vehicle.isValid()) {
        // TODO: Note special case, if ever players can move with dead vehicles for a while.
        // TODO: Actually force dismount?
        onPlayerVehicleLeave(player, vehicle);
        return null;
    } else {
        // (Auto detection of missing events, might fire one time too many per plugin run.)
        final EntityType vehicleType = vehicle.getType();
        if (!normalVehicles.contains(vehicleType)) {
            // Treat like VehicleUpdateEvent.
            onVehicleUpdate(vehicle, vehicleType, player, true, data, pData, pData.isDebugActive(checkType));
            return null;
        } else {
            final Location vLoc = vehicle.getLocation();
            data.vehicleConsistency = MoveConsistency.getConsistency(from, to, vLoc);
            // TODO: Consider TeleportUtil.forceMount or similar.
            final MovingConfig cc = pData.getGenericInstance(MovingConfig.class);
            if (data.vehicleConsistency == MoveConsistency.INCONSISTENT) {
                if (cc.vehicleEnforceLocation) {
                    // TODO: Permission + bypass check(s) !
                    return vLoc;
                } else {
                    return null;
                }
            } else {
                // (Skip chunk loading here.)
                aux.resetPositionsAndMediumProperties(player, vLoc, data, cc);
                return null;
            }
        }
    }
}
Also used : EntityType(org.bukkit.entity.EntityType) Entity(org.bukkit.entity.Entity) MovingConfig(fr.neatmonster.nocheatplus.checks.moving.MovingConfig) Location(org.bukkit.Location) RichBoundsLocation(fr.neatmonster.nocheatplus.utilities.location.RichBoundsLocation)

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