Search in sources :

Example 41 with Player

use of cn.nukkit.Player in project Nukkit by Nukkit.

the class RakNetInterface method openSession.

@Override
public void openSession(String identifier, String address, int port, long clientID) {
    PlayerCreationEvent ev = new PlayerCreationEvent(this, Player.class, Player.class, null, address, port);
    this.server.getPluginManager().callEvent(ev);
    Class<? extends Player> clazz = ev.getPlayerClass();
    try {
        Constructor constructor = clazz.getConstructor(SourceInterface.class, Long.class, String.class, int.class);
        Player player = (Player) constructor.newInstance(this, ev.getClientId(), ev.getAddress(), ev.getPort());
        this.players.put(identifier, player);
        this.networkLatency.put(identifier, 0);
        this.identifiersACK.put(identifier, 0);
        this.identifiers.put(player.rawHashCode(), identifier);
        this.server.addPlayer(identifier, player);
    } catch (NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException e) {
        Server.getInstance().getLogger().logException(e);
    }
}
Also used : Player(cn.nukkit.Player) PlayerCreationEvent(cn.nukkit.event.player.PlayerCreationEvent) Constructor(java.lang.reflect.Constructor) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 42 with Player

use of cn.nukkit.Player in project Nukkit by Nukkit.

the class Effect method remove.

public void remove(Entity entity) {
    if (entity instanceof Player) {
        MobEffectPacket pk = new MobEffectPacket();
        pk.eid = entity.getId();
        pk.effectId = this.getId();
        pk.eventId = MobEffectPacket.EVENT_REMOVE;
        ((Player) entity).dataPacket(pk);
        if (this.id == Effect.SPEED || this.id == Effect.SLOWNESS) {
            ((Player) entity).setMovementSpeed(0.1f);
        }
    }
    if (this.id == Effect.INVISIBILITY) {
        entity.setDataFlag(Entity.DATA_FLAGS, Entity.DATA_FLAG_INVISIBLE, false);
        entity.setNameTagVisible(true);
    }
    if (this.id == Effect.ABSORPTION) {
        entity.setAbsorption(0);
    }
}
Also used : Player(cn.nukkit.Player) MobEffectPacket(cn.nukkit.network.protocol.MobEffectPacket)

Example 43 with Player

use of cn.nukkit.Player in project Nukkit by Nukkit.

the class Potion method applyPotion.

public void applyPotion(Entity entity, double health) {
    if (!(entity instanceof EntityLiving)) {
        return;
    }
    Effect applyEffect = getEffect(this.getId(), this.isSplash());
    if (applyEffect == null) {
        return;
    }
    if (entity instanceof Player) {
        if (!((Player) entity).isSurvival() && applyEffect.isBad()) {
            return;
        }
    }
    PotionApplyEvent event = new PotionApplyEvent(this, applyEffect, entity);
    entity.getServer().getPluginManager().callEvent(event);
    if (event.isCancelled()) {
        return;
    }
    applyEffect = event.getApplyEffect();
    switch(this.getId()) {
        case INSTANT_HEALTH:
        case INSTANT_HEALTH_II:
            entity.heal(new EntityRegainHealthEvent(entity, (float) (health * (double) (4 << (applyEffect.getAmplifier() + 1))), EntityRegainHealthEvent.CAUSE_EATING));
            break;
        case HARMING:
        case HARMING_II:
            entity.attack(new EntityDamageEvent(entity, DamageCause.MAGIC, (float) (health * (double) (6 << (applyEffect.getAmplifier() + 1)))));
            break;
        default:
            int duration = (int) ((isSplash() ? health : 1) * (double) applyEffect.getDuration() + 0.5);
            applyEffect.setDuration(duration);
            entity.addEffect(applyEffect);
    }
}
Also used : Player(cn.nukkit.Player) EntityLiving(cn.nukkit.entity.EntityLiving) EntityRegainHealthEvent(cn.nukkit.event.entity.EntityRegainHealthEvent) PotionApplyEvent(cn.nukkit.event.potion.PotionApplyEvent) EntityDamageEvent(cn.nukkit.event.entity.EntityDamageEvent)

Example 44 with Player

use of cn.nukkit.Player in project LuckPerms by lucko.

the class NukkitConnectionListener method onPlayerQuit.

// Wait until the last priority to unload, so plugins can still perform permission checks on this event
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerQuit(PlayerQuitEvent e) {
    final Player player = e.getPlayer();
    // Remove the custom permissible
    try {
        PermissibleInjector.unInject(player, true);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    // Handle auto op
    if (this.plugin.getConfiguration().get(ConfigKeys.AUTO_OP)) {
        player.setOp(false);
    }
    // Register with the housekeeper, so the User's instance will stick
    // around for a bit after they disconnect
    this.plugin.getUserManager().getHouseKeeper().registerUsage(player.getUniqueId());
    // force a clear of transient nodes
    this.plugin.getBootstrap().getScheduler().doAsync(() -> {
        User user = this.plugin.getUserManager().getIfLoaded(player.getUniqueId());
        if (user != null) {
            user.clearTransientNodes();
        }
    });
}
Also used : Player(cn.nukkit.Player) User(me.lucko.luckperms.common.model.User) EventHandler(cn.nukkit.event.EventHandler)

Example 45 with Player

use of cn.nukkit.Player in project LuckPerms by lucko.

the class NukkitPlatformListener method onWorldChange.

@EventHandler(priority = EventPriority.LOWEST)
public void onWorldChange(EntityLevelChangeEvent e) {
    if (e.getEntity() instanceof Player) {
        Player player = (Player) e.getEntity();
        this.plugin.getContextManager().invalidateCache(player);
        this.plugin.refreshAutoOp(this.plugin.getUserManager().getIfLoaded(player.getUniqueId()), player);
    }
}
Also used : Player(cn.nukkit.Player) EventHandler(cn.nukkit.event.EventHandler)

Aggregations

Player (cn.nukkit.Player)85 TranslationContainer (cn.nukkit.lang.TranslationContainer)24 Entity (cn.nukkit.entity.Entity)13 BlockEntity (cn.nukkit.blockentity.BlockEntity)10 Item (cn.nukkit.item.Item)10 Level (cn.nukkit.level.Level)7 IOException (java.io.IOException)6 CompoundTag (cn.nukkit.nbt.tag.CompoundTag)5 Block (cn.nukkit.block.Block)4 ItemBlock (cn.nukkit.item.ItemBlock)4 BlockAir (cn.nukkit.block.BlockAir)3 EventHandler (cn.nukkit.event.EventHandler)3 BaseFullChunk (cn.nukkit.level.format.generic.BaseFullChunk)3 InventoryContentPacket (cn.nukkit.network.protocol.InventoryContentPacket)3 InventorySlotPacket (cn.nukkit.network.protocol.InventorySlotPacket)3 User (me.lucko.luckperms.common.model.User)3 IPlayer (cn.nukkit.IPlayer)2 CommandSender (cn.nukkit.command.CommandSender)2 EntityItem (cn.nukkit.entity.item.EntityItem)2 EntityArrow (cn.nukkit.entity.projectile.EntityArrow)2