cn.nukkit.event.entity.EntityLevelChangeEvent Java Examples

The following examples show how to use cn.nukkit.event.entity.EntityLevelChangeEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Entity.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
protected boolean switchLevel(Level targetLevel) {
    if (this.closed) {
        return false;
    }

    if (this.isValid()) {
        EntityLevelChangeEvent ev = new EntityLevelChangeEvent(this, this.level, targetLevel);
        this.server.getPluginManager().callEvent(ev);
        if (ev.isCancelled()) {
            return false;
        }

        this.level.removeEntity(this);
        if (this.chunk != null) {
            this.chunk.removeEntity(this);
        }
        this.despawnFromAll();
    }

    this.setLevel(targetLevel);
    this.level.addEntity(this);
    this.chunk = null;

    return true;
}
 
Example #2
Source File: WorldChangeListener.java    From Plan with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void actOnEvent(EntityLevelChangeEvent event) {
    long time = System.currentTimeMillis();

    // Checked earlier
    Player player = (Player) event.getEntity();
    UUID uuid = player.getUniqueId();

    String worldName = player.getLevel().getName();
    String gameMode = GMTimes.magicNumberToGMName(player.getGamemode());

    dbSystem.getDatabase().executeTransaction(new WorldNameStoreTransaction(serverInfo.getServerUUID(), worldName));
    worldAliasSettings.addWorld(worldName);

    Optional<Session> cachedSession = SessionCache.getCachedSession(uuid);
    cachedSession.ifPresent(session -> session.changeState(worldName, gameMode, time));
}
 
Example #3
Source File: WorldChangeListener.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onWorldChange(EntityLevelChangeEvent event) {
    if (event.getEntity() instanceof Player) {
        try {
            actOnEvent(event);
        } catch (Exception e) {
            errorLogger.log(L.ERROR, e, ErrorContext.builder().related(event).build());
        }
    }
}
 
Example #4
Source File: WorldCalculator.java    From LuckPerms with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onWorldChange(EntityLevelChangeEvent e) {
    if (e.getEntity() instanceof Player) {
        Player player = (Player) e.getEntity();
        this.plugin.getContextManager().signalContextUpdate(player);
    }
}