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.minecraft.command; 018 019import ca.stellardrift.permissionsex.PermissionsEngine; 020import ca.stellardrift.permissionsex.minecraft.MinecraftPermissionsEx; 021import cloud.commandframework.execution.preprocessor.CommandPreprocessingContext; 022import cloud.commandframework.execution.preprocessor.CommandPreprocessor; 023import cloud.commandframework.keys.CloudKey; 024import cloud.commandframework.keys.SimpleCloudKey; 025import io.leangen.geantyref.TypeToken; 026import org.checkerframework.checker.nullness.qual.NonNull; 027 028public class PEXCommandPreprocessor implements CommandPreprocessor<Commander> { 029 030 public static final CloudKey<MinecraftPermissionsEx<?>> PEX_MANAGER = SimpleCloudKey.of( 031 "permissionsex:manager", 032 new TypeToken<MinecraftPermissionsEx<?>>() {} 033 ); 034 public static final CloudKey<PermissionsEngine> PEX_ENGINE = SimpleCloudKey.of( 035 "permissionsex:engine", 036 TypeToken.get(PermissionsEngine.class) 037 ); 038 039 private final MinecraftPermissionsEx<?> manager; 040 041 public PEXCommandPreprocessor(MinecraftPermissionsEx<?> manager) { 042 this.manager = manager; 043 } 044 045 @Override 046 public void accept(@NonNull CommandPreprocessingContext<Commander> ctx) { 047 ctx.getCommandContext().store(PEX_MANAGER, this.manager); 048 ctx.getCommandContext().store(PEX_ENGINE, this.manager.engine()); 049 } 050}