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);
}
}
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);
}
}
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);
}
}
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();
}
});
}
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);
}
}
Aggregations