当前位置: 首页>>代码示例>>Java>>正文


Java Tristate类代码示例

本文整理汇总了Java中org.spongepowered.api.util.Tristate的典型用法代码示例。如果您正苦于以下问题:Java Tristate类的具体用法?Java Tristate怎么用?Java Tristate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Tristate类属于org.spongepowered.api.util包,在下文中一共展示了Tristate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setPermission

import org.spongepowered.api.util.Tristate; //导入依赖的package包/类
public static CompletableFuture<Boolean> setPermission(SubjectData data, Set<Context> contexts, String permission)
{
    try
    {
        Object result = SUBJECT_DATA_SET_PERMISSION.invoke(data, contexts, permission, Tristate.TRUE);
        if (result instanceof CompletableFuture)
        {
            @SuppressWarnings("unchecked")
            CompletableFuture<Boolean> future = (CompletableFuture) result;
            return future;
        }
        else
        {
            return CompletableFuture.completedFuture((Boolean) result);
        }
    }
    catch (Throwable throwable)
    {
        throw new UnsupportedOperationException(throwable);
    }
}
 
开发者ID:ustc-zzzz,项目名称:VirtualChest,代码行数:22,代码来源:SpongeUnimplemented.java

示例2: onClientAuthMonitor

import org.spongepowered.api.util.Tristate; //导入依赖的package包/类
@Listener(order = Order.LAST)
@IsCancelled(Tristate.UNDEFINED)
public void onClientAuthMonitor(ClientConnectionEvent.Auth e) {
    /* Listen to see if the event was cancelled after we initially handled the connection
       If the connection was cancelled here, we need to do something to clean up the data that was loaded. */

    // Check to see if this connection was denied at LOW.
    if (this.deniedAsyncLogin.remove(e.getProfile().getUniqueId())) {

        // This is a problem, as they were denied at low priority, but are now being allowed.
        if (e.isCancelled()) {
            this.plugin.getLog().severe("Player connection was re-allowed for " + e.getProfile().getUniqueId());
            e.setCancelled(true);
        }
    }
}
 
开发者ID:lucko,项目名称:LuckPerms,代码行数:17,代码来源:SpongeConnectionListener.java

示例3: onClientLogin

import org.spongepowered.api.util.Tristate; //导入依赖的package包/类
@Listener(order = Order.FIRST)
@IsCancelled(Tristate.UNDEFINED)
public void onClientLogin(ClientConnectionEvent.Login e) {
    /* Called when the player starts logging into the server.
       At this point, the users data should be present and loaded.
       Listening on LOW priority to allow plugins to further modify data here. (auth plugins, etc.) */

    final GameProfile player = e.getProfile();

    if (this.plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) {
        this.plugin.getLog().info("Processing login event for " + player.getUniqueId() + " - " + player.getName());
    }

    final User user = this.plugin.getUserManager().getIfLoaded(this.plugin.getUuidCache().getUUID(player.getUniqueId()));

    /* User instance is null for whatever reason. Could be that it was unloaded between asyncpre and now. */
    if (user == null) {
        this.deniedLogin.add(player.getUniqueId());

        this.plugin.getLog().warn("User " + player.getUniqueId() + " - " + player.getName() + " doesn't have data pre-loaded. - denying login.");
        e.setCancelled(true);
        e.setMessageCancelled(false);
        //noinspection deprecation
        e.setMessage(TextSerializers.LEGACY_FORMATTING_CODE.deserialize(Message.LOADING_ERROR.asString(this.plugin.getLocaleManager())));
    }
}
 
开发者ID:lucko,项目名称:LuckPerms,代码行数:27,代码来源:SpongeConnectionListener.java

示例4: onChangeBlock

import org.spongepowered.api.util.Tristate; //导入依赖的package包/类
@Listener(order=Order.FIRST)
@IsCancelled(Tristate.UNDEFINED)
public void onChangeBlock(ChangeBlockEvent.Place event) {
	Optional<Player> optPlayer = event.getCause().get(NamedCause.SOURCE, Player.class);
	if (!optPlayer.isPresent()) return;
	
	Player player = optPlayer.get();
	if (!this.players.contains(player.getUniqueId())) return;
	
	event.setCancelled(true);
	
	event.getTransactions().forEach(transaction -> {
		player.sendMessage(Text.of(TextColors.GRAY, TextStyles.BOLD, "============================================"));
		player.sendMessage(Text.of(TextColors.DARK_GREEN, TextStyles.BOLD, "Block Type: ", TextColors.BLUE, TextStyles.RESET, transaction.getOriginal().getState().getId()));
		player.sendMessage(Text.of(TextColors.DARK_GREEN, TextStyles.BOLD, "Block Owner: ", TextColors.BLUE, TextStyles.RESET, transaction.getOriginal().getCreator()));
		player.sendMessage(Text.of(TextColors.DARK_GREEN, TextStyles.BOLD, "Block Notifier: ", TextColors.BLUE, TextStyles.RESET, transaction.getOriginal().getNotifier()));
	});
}
 
开发者ID:EverCraft,项目名称:EverAPI,代码行数:19,代码来源:EAInfo.java

示例5: onInteractBlock

import org.spongepowered.api.util.Tristate; //导入依赖的package包/类
@Listener(order=Order.FIRST)
@IsCancelled(Tristate.UNDEFINED)
public void onInteractBlock(InteractBlockEvent.Primary event) {
	Optional<Player> optPlayer = event.getCause().get(NamedCause.SOURCE, Player.class);
	if (!optPlayer.isPresent()) return;
	
	Player player = optPlayer.get();
	if (!this.players.contains(player.getUniqueId())) return;
	
	event.setCancelled(true);
	
	player.sendMessage(Text.of(TextColors.GRAY, TextStyles.BOLD, "============================================"));
	player.sendMessage(Text.of(TextColors.DARK_GREEN, TextStyles.BOLD, "Block Type: ", TextColors.BLUE, TextStyles.RESET, event.getTargetBlock().getState().getId()));
	player.sendMessage(Text.of(TextColors.DARK_GREEN, TextStyles.BOLD, "Block Owner: ", TextColors.BLUE, TextStyles.RESET, event.getTargetBlock().getCreator()));
	player.sendMessage(Text.of(TextColors.DARK_GREEN, TextStyles.BOLD, "Block Notifier: ", TextColors.BLUE, TextStyles.RESET, event.getTargetBlock().getNotifier()));
}
 
开发者ID:EverCraft,项目名称:EverAPI,代码行数:17,代码来源:EAInfo.java

示例6: onInteractEntity

import org.spongepowered.api.util.Tristate; //导入依赖的package包/类
@Listener(order=Order.FIRST)
@IsCancelled(Tristate.UNDEFINED)
public void onInteractEntity(InteractEntityEvent.Primary event) {
	Optional<Player> optPlayer = event.getCause().get(NamedCause.SOURCE, Player.class);
	if (!optPlayer.isPresent()) return;
	
	Player player = optPlayer.get();
	if (!this.players.contains(player.getUniqueId())) return;
	
	event.setCancelled(true);
	
	player.sendMessage(Text.of(TextColors.GRAY, TextStyles.BOLD, "============================================"));
	player.sendMessage(Text.of(TextColors.DARK_GREEN, TextStyles.BOLD, "Entity Type: ", TextColors.BLUE, TextStyles.RESET, event.getTargetEntity().getType().getId()));
	player.sendMessage(Text.of(TextColors.DARK_GREEN, TextStyles.BOLD, "Entity Owner: ", TextColors.BLUE, TextStyles.RESET, event.getTargetEntity().getCreator()));
	player.sendMessage(Text.of(TextColors.DARK_GREEN, TextStyles.BOLD, "Entity Notifier: ", TextColors.BLUE, TextStyles.RESET, event.getTargetEntity().getNotifier()));
}
 
开发者ID:EverCraft,项目名称:EverAPI,代码行数:17,代码来源:EAInfo.java

示例7: EPUserSubject

import org.spongepowered.api.util.Tristate; //导入依赖的package包/类
public EPUserSubject(final EverPermissions plugin, final String identifier, final EPSubjectCollection<?> collection) {
 	super(plugin, identifier, collection);

 	this.data = new EPUserData(this.plugin, this, false);
     this.transientData = new EPUserData(this.plugin, this, true);
     
     // Cache
this.cachePermissions = CacheBuilder.newBuilder()
	    .maximumSize(16)
	    .expireAfterAccess(10, TimeUnit.MINUTES)
	    .build(new CacheLoader<String, Tristate>() {
		@Override
		public Tristate load(String permission) throws Exception {
			return EPUserSubject.this.getPermissionValue(permission);
		}
	    });
this.cacheOptions = CacheBuilder.newBuilder()
	    .maximumSize(16)
	    .expireAfterAccess(10, TimeUnit.MINUTES)
	    .build(new CacheLoader<String, Optional<String>>() {
		@Override
		public Optional<String> load(String option) throws Exception {
			return EPUserSubject.this.getOption(option);
		}
	    });
 }
 
开发者ID:EverCraft,项目名称:EverPermissions,代码行数:27,代码来源:EPUserSubject.java

示例8: getTristate

import org.spongepowered.api.util.Tristate; //导入依赖的package包/类
/**
 * Retourne la valeur de la permission
 * @param permission La permission
 * @return La valeur de la permission
 */
public Tristate getTristate(final String permission) {
    Iterable<String> parts = NODE_SPLITTER.split(permission.toLowerCase());
    EPNode currentNode = this;
    Tristate lastUndefinedVal = Tristate.UNDEFINED;
    for (String str : parts) {
        if (!currentNode.containsKey(str)) {
            break;
        }
        currentNode = currentNode.get(str);
        
        if (currentNode.getTristate() != Tristate.UNDEFINED) {
            lastUndefinedVal = currentNode.getTristate();
        }
    }
    return lastUndefinedVal;

}
 
开发者ID:EverCraft,项目名称:EverPermissions,代码行数:23,代码来源:EPNode.java

示例9: of

import org.spongepowered.api.util.Tristate; //导入依赖的package包/类
/**
 * Création d'un node à partir d'une map
 * @param values Permission : Valeur
 * @param defaultValue La valeur par défaut
 * @return Le node
 */
public static EPNode of(final Map<String, Boolean> values, final Tristate defaultValue) {
	EPNode newTree = new EPNode(defaultValue);
    for (Map.Entry<String, Boolean> value : values.entrySet()) {
        Iterable<String> parts = NODE_SPLITTER.split(value.getKey().toLowerCase());
        EPNode currentNode = newTree;
        for (String part : parts) {
            if (currentNode.containsKey(part)) {
                currentNode = currentNode.get(part);
            } else {
            	EPNode newNode = new EPNode();
                currentNode.put(part, newNode);
                currentNode = newNode;
            }
        }
        currentNode.setTristate(Tristate.fromBoolean(value.getValue()));
    }
    return newTree;
}
 
开发者ID:EverCraft,项目名称:EverPermissions,代码行数:25,代码来源:EPNode.java

示例10: withValue

import org.spongepowered.api.util.Tristate; //导入依赖的package包/类
/**
 * Modifie une permission
 * @param node Le node
 * @param value La valeur
 * @return Le nouveau node
 */
public EPNode withValue(final String node, final Tristate value) {
    Iterable<String> parts = NODE_SPLITTER.split(node.toLowerCase());
    EPNode newRoot = this.copy();
    EPNode currentPtr = newRoot;

    for (String part : parts) {
    	EPNode oldChild = currentPtr.get(part);
    	EPNode newChild;
        if (oldChild == null) {
        	newChild = new EPNode();
        } else {
        	newChild = oldChild.copy();
        }
        currentPtr.put(part, newChild);
        currentPtr = newChild;
    }
    currentPtr.setTristate(value);
    return newRoot;
}
 
开发者ID:EverCraft,项目名称:EverPermissions,代码行数:26,代码来源:EPNode.java

示例11: setPermission

import org.spongepowered.api.util.Tristate; //导入依赖的package包/类
@Override
public CompletableFuture<Boolean> setPermission(final String typeWorld, final String permission, final Tristate value) {
	Preconditions.checkNotNull(typeWorld, "typeWorld");
	Preconditions.checkNotNull(permission, "permission");
	Preconditions.checkNotNull(value, "value");
	
	return CompletableFuture.supplyAsync(() -> {
		Boolean oldValue = this.getNodeTree(typeWorld).asMap().get(permission);
		boolean insert = oldValue == null;
		
		if (insert && value.equals(Tristate.UNDEFINED)) return false;
		if (!insert && !value.equals(Tristate.UNDEFINED) && oldValue.booleanValue() == value.asBoolean()) return false;
		
		if (!this.getSubject().getContainingCollection().getStorage().setPermission(this, typeWorld, permission, value, insert)) return false;
		
		this.setPermissionExecute(typeWorld, permission, value);
		this.onUpdate();
		return true;
	}, this.plugin.getThreadAsync());
}
 
开发者ID:EverCraft,项目名称:EverPermissions,代码行数:21,代码来源:EPSubjectData.java

示例12: setPermissionExecute

import org.spongepowered.api.util.Tristate; //导入依赖的package包/类
public void setPermissionExecute(final String typeWorld, final String permission, final Tristate value) {
	this.write_lock.lock();
	try {
		EPNode oldTree = this.permissions.get(typeWorld);
		if (oldTree == null) {
			if (value != Tristate.UNDEFINED) {
				this.permissions.putIfAbsent(typeWorld, EPNode.of(ImmutableMap.of(permission, value.asBoolean())));
			}
		} else if (value == Tristate.UNDEFINED) {
			if (oldTree.getTristate(permission) != Tristate.UNDEFINED) {
				this.permissions.put(typeWorld, oldTree.withValue(permission, value));
			}
		} else if (!oldTree.asMap().containsKey(permission) || oldTree.asMap().get(permission) != value.asBoolean()) {
			this.permissions.put(typeWorld, oldTree.withValue(permission, value));
		} 
	} finally {
		this.write_lock.unlock();
	}
}
 
开发者ID:EverCraft,项目名称:EverPermissions,代码行数:20,代码来源:EPSubjectData.java

示例13: onMoveEntityEventTeleport

import org.spongepowered.api.util.Tristate; //导入依赖的package包/类
@Listener
@IsCancelled(Tristate.FALSE)
public void onMoveEntityEventTeleport(MoveEntityEvent.Teleport event, @Root Player player) {
    if (event.getFromTransform().getExtent().equals(event.getToTransform().getExtent())) {
        return;
    }

    World world = event.getToTransform().getExtent();
    Vector3d rotation = null;
    for (SpawnEntity spawnEntity : SpawnCache.instance.get()) {
        if (spawnEntity.getWorld().getIdentifier().equals(world.getUniqueId().toString())) {
            rotation = spawnEntity.getRotation();
        }
    }

    if (rotation != null) {
        Transform<World> to = new Transform<>(world.getSpawnLocation());
        event.setToTransform(to.setRotation(rotation));
    }
}
 
开发者ID:mmonkey,项目名称:Destinations,代码行数:21,代码来源:PlayerListeners.java

示例14: onPlayerTeleportPreEvent

import org.spongepowered.api.util.Tristate; //导入依赖的package包/类
@Listener(order = Order.LATE)
@IsCancelled(Tristate.FALSE)
@Include(PlayerTeleportEvent.Pre.class)
public void onPlayerTeleportPreEvent(PlayerTeleportEvent event) {
    Player player = event.getTargetEntity();
    PlayerEntity playerEntity = PlayerCache.instance.get(player);

    for (BackEntity backEntity : playerEntity.getBacks()) {
        if (backEntity.getLocation().getWorld().getIdentifier().equals(event.getLocation().getExtent().getUniqueId().toString())) {
            playerEntity.getBacks().remove(backEntity);
        }
    }

    playerEntity.getBacks().add(new BackEntity(new LocationEntity(event.getLocation(), event.getRotation())));
    playerEntity = PlayerRepository.instance.save(playerEntity);
    PlayerCache.instance.set(player, playerEntity);
}
 
开发者ID:mmonkey,项目名称:Destinations,代码行数:18,代码来源:TeleportListeners.java

示例15: onPlayerTeleportEvent

import org.spongepowered.api.util.Tristate; //导入依赖的package包/类
@Listener(order = Order.LATE)
@IsCancelled(Tristate.FALSE)
@Exclude(PlayerTeleportEvent.Pre.class)
public void onPlayerTeleportEvent(PlayerTeleportEvent event) {
    Optional<SleepingData> optional = event.getTargetEntity().get(SleepingData.class);
    if (optional.isPresent() && optional.get().asImmutable().sleeping().get()) {
        event.getTargetEntity().sendMessage(MessagesUtil.get(event.getTargetEntity(), "teleport.sleep"));
        return;
    }

    if (event.getRotation() == null) {
        event.getTargetEntity().setLocationSafely(event.getLocation());
    } else {
        event.getTargetEntity().setLocationAndRotationSafely(event.getLocation(), event.getRotation());
    }
}
 
开发者ID:mmonkey,项目名称:Destinations,代码行数:17,代码来源:TeleportListeners.java


注:本文中的org.spongepowered.api.util.Tristate类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。