001/* 002 * PermissionsEx 003 * Copyright (C) zml and PermissionsEx contributors 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package ca.stellardrift.permissionsex.proxycommon; 018 019import ca.stellardrift.permissionsex.context.ContextDefinition; 020import ca.stellardrift.permissionsex.subject.CalculatedSubject; 021import org.checkerframework.checker.nullness.qual.NonNull; 022import org.checkerframework.checker.nullness.qual.Nullable; 023import org.spongepowered.configurate.serialize.Scalars; 024 025import java.util.Objects; 026import java.util.function.Consumer; 027 028public final class ProxyContextDefinition extends ContextDefinition<Boolean> { 029 public static final ProxyContextDefinition INSTANCE = new ProxyContextDefinition(); 030 031 private ProxyContextDefinition() { 032 super("proxy"); 033 } 034 035 @Override 036 public @NonNull String serialize(final Boolean canonicalValue) { 037 return String.valueOf(canonicalValue); 038 } 039 040 @Override 041 public @Nullable Boolean deserialize(final String userValue) { 042 return Scalars.BOOLEAN.tryDeserialize(userValue); 043 } 044 045 @Override 046 public boolean matches(final Boolean ownVal, final Boolean testVal) { 047 return Objects.equals(ownVal, testVal); 048 } 049 050 @Override 051 public void accumulateCurrentValues(final CalculatedSubject subject, final Consumer<Boolean> consumer) { 052 consumer.accept(true); 053 } 054}