本文整理汇总了Java中org.spongepowered.api.util.Tristate.TRUE属性的典型用法代码示例。如果您正苦于以下问题:Java Tristate.TRUE属性的具体用法?Java Tristate.TRUE怎么用?Java Tristate.TRUE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.spongepowered.api.util.Tristate
的用法示例。
在下文中一共展示了Tristate.TRUE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onPlayerUseItem
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerUseItem(UseItemStackEvent.Start event, @First Player player) {
if (!GPFlags.ITEM_USE || !GriefPreventionPlugin.instance.claimsEnabledForWorld(player.getWorld().getProperties())) {
return;
}
GPTimings.PLAYER_USE_ITEM_EVENT.startTimingIfSync();
Location<World> location = player.getLocation();
GPPlayerData playerData = this.dataStore.getOrCreatePlayerData(location.getExtent(), player.getUniqueId());
GPClaim claim = this.dataStore.getClaimAtPlayer(playerData, location);
final Tristate result = GPPermissionHandler.getClaimPermission(event, location, claim, GPPermissions.ITEM_USE, player, event.getItemStackInUse().getType(), player, TrustType.ACCESSOR, true);
if (result == Tristate.FALSE) {
if (GPPermissionHandler.getClaimPermission(event, location, claim, GPPermissions.ITEM_USE, player, event.getItemStackInUse().getType(), player) == Tristate.TRUE) {
GPTimings.PLAYER_USE_ITEM_EVENT.stopTimingIfSync();
return;
}
final Text message = GriefPreventionPlugin.instance.messageData.townName
.apply(ImmutableMap.of(
"item", event.getItemStackInUse().getType().getId())).build();
GriefPreventionPlugin.sendClaimDenyMessage(claim, player, message);
event.setCancelled(true);
}
GPTimings.PLAYER_USE_ITEM_EVENT.stopTimingIfSync();
}
示例2: createFlagConsumer
public static Consumer<CommandSource> createFlagConsumer(CommandSource src, Subject subject, String subjectName, Set<Context> contexts, GPClaim claim, String flagPermission, Tristate flagValue, String source) {
return consumer -> {
String target = flagPermission.replace(GPPermissions.FLAG_BASE + ".", "");
if (target.isEmpty()) {
target = "any";
}
Tristate newValue = Tristate.UNDEFINED;
if (flagValue == Tristate.TRUE) {
newValue = Tristate.FALSE;
} else if (flagValue == Tristate.UNDEFINED) {
newValue = Tristate.TRUE;
}
CommandHelper.applyFlagPermission(src, subject, subjectName, claim, flagPermission, source, target, newValue, null, FlagType.GROUP);
};
}
示例3: write
@Override
public int write(String name, ClassWriter cw, MethodVisitor mv, Method method, int locals) {
if (this.state == Tristate.UNDEFINED) {
return locals;
}
if (!Cancellable.class.isAssignableFrom(method.getParameters()[0].getType())) {
throw new IllegalStateException("Attempted to filter a non-cancellable event type by its cancellation status");
}
mv.visitVarInsn(ALOAD, 1);
mv.visitTypeInsn(CHECKCAST, Type.getInternalName(Cancellable.class));
mv.visitMethodInsn(INVOKEINTERFACE, Type.getInternalName(Cancellable.class), "isCancelled", "()Z", true);
Label success = new Label();
if (this.state == Tristate.TRUE) {
mv.visitJumpInsn(IFNE, success);
} else {
mv.visitJumpInsn(IFEQ, success);
}
mv.visitInsn(ACONST_NULL);
mv.visitInsn(ARETURN);
mv.visitLabel(success);
return locals;
}
示例4: parseCommand
public static List<String> parseCommand(String commandSequence)
{
StringBuilder stringBuilder = new StringBuilder();
List<String> commands = new LinkedList<>();
Tristate isCommandFinished = Tristate.TRUE;
for (char c : commandSequence.toCharArray())
{
if (c != SEQUENCE_SPLITTER)
{
if (isCommandFinished == Tristate.UNDEFINED)
{
commands.add(stringBuilder.toString());
stringBuilder.setLength(0);
}
if (isCommandFinished != Tristate.FALSE && Character.isWhitespace(c))
{
isCommandFinished = Tristate.TRUE;
continue;
}
}
else if (isCommandFinished != Tristate.UNDEFINED)
{
isCommandFinished = Tristate.UNDEFINED;
continue;
}
isCommandFinished = Tristate.FALSE;
stringBuilder.append(c);
}
commands.add(stringBuilder.toString());
return commands;
}
示例5: setPermission
@Override
public boolean setPermission(Player player, Subject subject, Set<Context> contexts, String permission, Tristate value) {
Boolean perm = subject.getSubjectData().getPermissions(contexts).get(permission);
if ((perm == null && value == Tristate.UNDEFINED)
|| (perm == Boolean.TRUE && value == Tristate.TRUE)
|| (perm == Boolean.FALSE && value == Tristate.FALSE)) {
return true;
}
return subject.getSubjectData().setPermission(contexts, permission, value);
}
示例6: onProjectileImpactEntity
@Listener(order = Order.FIRST, beforeModifications = true)
public void onProjectileImpactEntity(CollideEntityEvent.Impact event) {
if (!GPFlags.PROJECTILE_IMPACT_ENTITY) {
return;
}
final User user = CauseContextHelper.getEventUser(event);
if (user == null || !GriefPreventionPlugin.instance.claimsEnabledForWorld(event.getImpactPoint().getExtent().getProperties())) {
return;
}
GPTimings.PROJECTILE_IMPACT_ENTITY_EVENT.startTimingIfSync();
Object source = event.getCause().root();
Location<World> impactPoint = event.getImpactPoint();
GPClaim targetClaim = null;
for (Entity entity : event.getEntities()) {
targetClaim = this.dataStore.getClaimAt(impactPoint, targetClaim);
final Tristate result = GPPermissionHandler.getClaimPermission(event, impactPoint, targetClaim, GPPermissions.PROJECTILE_IMPACT_ENTITY, source, entity, user, TrustType.ACCESSOR, true);
if (result == Tristate.FALSE) {
if (GPPermissionHandler.getClaimPermission(event, impactPoint, targetClaim, GPPermissions.PROJECTILE_IMPACT_ENTITY, source, entity, user) == Tristate.TRUE) {
GPTimings.PROJECTILE_IMPACT_ENTITY_EVENT.stopTimingIfSync();
return;
}
event.setCancelled(true);
}
}
GPTimings.PROJECTILE_IMPACT_ENTITY_EVENT.stopTimingIfSync();
}
示例7: onPlayerInteractInventoryOpen
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerInteractInventoryOpen(InteractInventoryEvent.Open event, @First Player player) {
if (!GPFlags.INTERACT_INVENTORY || !GriefPreventionPlugin.instance.claimsEnabledForWorld(player.getWorld().getProperties())) {
return;
}
GPTimings.PLAYER_INTERACT_INVENTORY_OPEN_EVENT.startTimingIfSync();
final Cause cause = event.getCause();
final EventContext context = cause.getContext();
final BlockSnapshot blockSnapshot = context.get(EventContextKeys.BLOCK_HIT).orElse(BlockSnapshot.NONE);
if (blockSnapshot == BlockSnapshot.NONE) {
GPTimings.PLAYER_INTERACT_INVENTORY_OPEN_EVENT.stopTimingIfSync();
return;
}
final Location<World> location = blockSnapshot.getLocation().get();
final GPClaim claim = this.dataStore.getClaimAt(location);
final GPPlayerData playerData = this.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
if (playerData.lastInteractItemBlockResult == Tristate.TRUE) {
GPTimings.PLAYER_INTERACT_INVENTORY_OPEN_EVENT.stopTimingIfSync();
return;
}
final Tristate result = GPPermissionHandler.getClaimPermission(event, location, claim, GPPermissions.INVENTORY_OPEN, player, blockSnapshot, player, TrustType.CONTAINER, true);
if (result == Tristate.FALSE) {
Text message = GriefPreventionPlugin.instance.messageData.permissionInventoryOpen
.apply(ImmutableMap.of(
"owner", claim.getOwnerName(),
"block", blockSnapshot.getState().getType().getId())).build();
GriefPreventionPlugin.sendClaimDenyMessage(claim, player, message);
((EntityPlayerMP) player).closeScreen();
event.setCancelled(true);
}
GPTimings.PLAYER_INTERACT_INVENTORY_OPEN_EVENT.stopTimingIfSync();
}
示例8: onPlayerInteractEntity
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerInteractEntity(InteractEntityEvent.Primary event, @First Player player) {
if (!GPFlags.INTERACT_ENTITY_PRIMARY || !GriefPreventionPlugin.instance.claimsEnabledForWorld(player.getWorld().getProperties())) {
return;
}
final Entity targetEntity = event.getTargetEntity();
GPTimings.PLAYER_INTERACT_ENTITY_PRIMARY_EVENT.startTimingIfSync();
Location<World> location = targetEntity.getLocation();
GPClaim claim = this.dataStore.getClaimAt(location);
GPPlayerData playerData = this.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
if (playerData.lastInteractItemBlockResult == Tristate.TRUE || playerData.lastInteractItemEntityResult == Tristate.TRUE) {
GPTimings.PLAYER_INTERACT_ENTITY_PRIMARY_EVENT.stopTimingIfSync();
return;
}
Tristate result = GPPermissionHandler.getClaimPermission(event, location, claim, GPPermissions.INTERACT_ENTITY_PRIMARY, player, targetEntity, player, TrustType.ACCESSOR, true);
if (result == Tristate.FALSE) {
final Text message = GriefPreventionPlugin.instance.messageData.claimProtectedEntity
.apply(ImmutableMap.of(
"owner", claim.getOwnerName())).build();
GriefPreventionPlugin.sendMessage(player, message);
event.setCancelled(true);
GPTimings.PLAYER_INTERACT_ENTITY_PRIMARY_EVENT.stopTimingIfSync();
return;
}
}
示例9: onPlayerInteractBlockPrimary
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerInteractBlockPrimary(InteractBlockEvent.Primary.MainHand event, @First Player player) {
if (!GPFlags.INTERACT_BLOCK_PRIMARY || !GriefPreventionPlugin.instance.claimsEnabledForWorld(player.getWorld().getProperties())) {
return;
}
GPTimings.PLAYER_INTERACT_BLOCK_PRIMARY_EVENT.startTimingIfSync();
final BlockSnapshot clickedBlock = event.getTargetBlock();
final Location<World> location = clickedBlock.getLocation().orElse(null);
if (location == null) {
GPTimings.PLAYER_INTERACT_BLOCK_PRIMARY_EVENT.stopTimingIfSync();
return;
}
final GPPlayerData playerData = this.dataStore.getOrCreatePlayerData(location.getExtent(), player.getUniqueId());
if (playerData.lastInteractItemBlockResult == Tristate.TRUE || playerData.lastInteractItemEntityResult == Tristate.TRUE) {
GPTimings.PLAYER_INTERACT_BLOCK_PRIMARY_EVENT.stopTimingIfSync();
return;
}
final GPClaim claim = this.dataStore.getClaimAt(location);
final Tristate result = GPPermissionHandler.getClaimPermission(event, location, claim, GPPermissions.INTERACT_BLOCK_PRIMARY, player, clickedBlock.getState(), player, TrustType.BUILDER, true);
if (result == Tristate.FALSE) {
if (GPPermissionHandler.getClaimPermission(event, location, claim, GPPermissions.BLOCK_BREAK, player, clickedBlock.getState(), player, TrustType.BUILDER, true) == Tristate.TRUE) {
GPTimings.PLAYER_INTERACT_BLOCK_PRIMARY_EVENT.stopTimingIfSync();
playerData.setLastInteractData(claim);
return;
}
final Text message = GriefPreventionPlugin.instance.messageData.permissionAccess
.apply(ImmutableMap.of(
"player", Text.of(claim.getOwnerName()))).build();
GriefPreventionPlugin.sendClaimDenyMessage(claim, player, message);
event.setCancelled(true);
GPTimings.PLAYER_INTERACT_BLOCK_PRIMARY_EVENT.stopTimingIfSync();
return;
}
playerData.setLastInteractData(claim);
GPTimings.PLAYER_INTERACT_BLOCK_PRIMARY_EVENT.stopTimingIfSync();
}
示例10: getPermissionValue
@Override
public Tristate getPermissionValue(Set<Context> contexts, String permission) {
Tristate ret = super.getPermissionValue(contexts, permission);
if (ret == Tristate.UNDEFINED) {
ret = getDataPermissionValue(this.collection.getDefaults().getSubjectData(), permission);
}
if (ret == Tristate.UNDEFINED) {
ret = getDataPermissionValue(this.collection.getService().getDefaults().getSubjectData(), permission);
}
if (ret == Tristate.UNDEFINED && getOpLevel() >= Lantern.getGame().getGlobalConfig().getDefaultOpPermissionLevel()) {
ret = Tristate.TRUE;
}
return ret;
}
示例11: onBlockPlace
@Listener(order = Order.POST)
@IsCancelled(value = Tristate.TRUE)
public void onBlockPlace(ChangeBlockEvent.Place event, @Root Player player) {
final Location<World> playerLoc = player.getLocation();
for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
Optional<Location<World>> optLoc = transaction.getOriginal().getLocation();
if (!optLoc.isPresent()) {
continue;
}
Location<World> blockLoc = optLoc.get();
final int blockY = blockLoc.getBlockY();
if (Math.abs(player.getVelocity().getY()) > UPWARDS_VELOCITY && playerLoc.getY() > blockY) {
Task.builder().execute(() -> {
Vector3d position = player.getLocation().getPosition();
if (position.getY() >= (blockY + LEAP_DISTANCE)) {
if (playerLoc.getPosition().distanceSquared(blockLoc.getPosition()) > Math.pow(RADIUS, 2)) {
return;
}
player.sendMessage(Text.of(TextColors.RED, "Hack jumping detected."));
player.setLocation(playerLoc.setPosition(new Vector3d(position.getX(), blockY, position.getZ())));
}
}).delayTicks(4).submit(SkreePlugin.inst());
}
}
}
示例12: getPermissionValue
@Override
public Tristate getPermissionValue(Set<Context> contexts, String permission) {
return Tristate.TRUE;
}
示例13: asInt
private static int asInt(Tristate tristate) {
return tristate == Tristate.TRUE ? 1 : tristate == Tristate.FALSE ? -1 : 0;
}
示例14: onPlayerDispenseItem
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerDispenseItem(DropItemEvent.Dispense event, @Root Entity spawncause) {
if (!GPFlags.ITEM_DROP || !(spawncause instanceof User)) {
return;
}
final User user = (User) spawncause;
final World world = spawncause.getWorld();
if (!GriefPreventionPlugin.instance.claimsEnabledForWorld(world.getProperties())) {
return;
}
// in creative worlds, dropping items is blocked
if (GriefPreventionPlugin.instance.claimModeIsActive(world.getProperties(), ClaimsMode.Creative)) {
event.setCancelled(true);
return;
}
GPTimings.PLAYER_DISPENSE_ITEM_EVENT.startTimingIfSync();
Player player = user instanceof Player ? (Player) user : null;
GPPlayerData playerData = this.dataStore.getOrCreatePlayerData(world, user.getUniqueId());
// FEATURE: players in PvP combat, can't throw items on the ground to hide
// them or give them away to other players before they are defeated
// if in combat, don't let him drop it
if (player != null && !GriefPreventionPlugin.getActiveConfig(world.getProperties()).getConfig().pvp.allowCombatItemDrops && playerData.inPvpCombat(player.getWorld())) {
GriefPreventionPlugin.sendMessage(player, GriefPreventionPlugin.instance.messageData.pvpNoItemDrop.toText());
event.setCancelled(true);
GPTimings.PLAYER_DISPENSE_ITEM_EVENT.stopTimingIfSync();
return;
}
for (Entity entityItem : event.getEntities()) {
Location<World> location = entityItem.getLocation();
GPClaim claim = this.dataStore.getClaimAtPlayer(playerData, location);
if (claim != null) {
final Tristate override = GPPermissionHandler.getFlagOverride(event, location, claim, GPPermissions.ITEM_DROP, user, entityItem, user, playerData, true);
if (override != Tristate.UNDEFINED) {
if (override == Tristate.TRUE) {
GPTimings.PLAYER_DISPENSE_ITEM_EVENT.stopTimingIfSync();
return;
}
event.setCancelled(true);
GPTimings.PLAYER_DISPENSE_ITEM_EVENT.stopTimingIfSync();
return;
}
// allow trusted users
if (claim.isUserTrusted(user, TrustType.ACCESSOR)) {
GPTimings.PLAYER_DISPENSE_ITEM_EVENT.stopTimingIfSync();
return;
}
Tristate perm = GPPermissionHandler.getClaimPermission(event, location, claim, GPPermissions.ITEM_DROP, user, entityItem, user);
if (perm == Tristate.TRUE) {
GPTimings.PLAYER_DISPENSE_ITEM_EVENT.stopTimingIfSync();
return;
} else if (perm == Tristate.FALSE) {
event.setCancelled(true);
if (spawncause instanceof Player) {
final Text message = GriefPreventionPlugin.instance.messageData.permissionItemDrop
.apply(ImmutableMap.of(
"owner", claim.getOwnerName(),
"item", entityItem.getType().getId())).build();
GriefPreventionPlugin.sendClaimDenyMessage(claim, player, message);
}
GPTimings.PLAYER_DISPENSE_ITEM_EVENT.stopTimingIfSync();
return;
}
}
}
GPTimings.PLAYER_DISPENSE_ITEM_EVENT.stopTimingIfSync();
}
示例15: createFlagConsumer
private Consumer<CommandSource> createFlagConsumer(CommandSource src, GPClaim claim, String flagPermission, Tristate flagValue, String source, FlagType displayType, FlagType flagType, boolean toggleType) {
return consumer -> {
// Toggle DEFAULT type
final String sourceId = GPPermissionHandler.getSourcePermission(flagPermission);
final String targetId = GPPermissionHandler.getTargetPermission(flagPermission);
final ClaimFlag claimFlag = GPPermissionHandler.getFlagFromPermission(flagPermission);
if (claimFlag == null) {
return;
}
Context claimContext = claim.getContext();
Tristate newValue = Tristate.UNDEFINED;
if (flagType == FlagType.DEFAULT) {
if (toggleType) {
if (flagValue == Tristate.TRUE) {
newValue = Tristate.FALSE;
} else {
newValue = Tristate.TRUE;
}
ClaimType claimType = claim.getType();
if (claimType == ClaimType.SUBDIVISION) {
claimType = ClaimType.BASIC;
}
final Boolean defaultValue = DataStore.CLAIM_FLAG_DEFAULTS.get(claimType).get(claimFlag.toString());
if (defaultValue != null && defaultValue == newValue.asBoolean()) {
newValue = Tristate.UNDEFINED;
}
}
claimContext = CommandHelper.validateCustomContext(src, claim, "default");
// Toggle CLAIM type
} else if (flagType == FlagType.CLAIM) {
if (flagValue == Tristate.TRUE) {
newValue = Tristate.FALSE;
} else if (flagValue == Tristate.UNDEFINED) {
newValue = Tristate.TRUE;
}
// Toggle OVERRIDE type
} else if (flagType == FlagType.OVERRIDE) {
if (flagValue == Tristate.TRUE) {
newValue = Tristate.FALSE;
} else if (flagValue == Tristate.UNDEFINED) {
newValue = Tristate.TRUE;
}
claimContext = CommandHelper.validateCustomContext(src, claim, "override");
}
try (final CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
Sponge.getCauseStackManager().pushCause(src);
GPFlagClaimEvent.Set event = new GPFlagClaimEvent.Set(claim, this.subject, claimFlag, sourceId, targetId, toggleType ? newValue : flagValue, claimContext);
Sponge.getEventManager().post(event);
if (event.isCancelled()) {
return;
}
FlagResult result = CommandHelper.applyFlagPermission(src, this.subject, "ALL", claim, flagPermission, source, "any", toggleType ? newValue : flagValue, claimContext, flagType, null, true);
if (result.successful()) {
showFlagPermissions(src, claim, displayType, source);
}
}
};
}