本文整理汇总了Java中org.spongepowered.api.service.context.Context类的典型用法代码示例。如果您正苦于以下问题:Java Context类的具体用法?Java Context怎么用?Java Context使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Context类属于org.spongepowered.api.service.context包,在下文中一共展示了Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: accumulateContexts
import org.spongepowered.api.service.context.Context; //导入依赖的package包/类
@Override
public void accumulateContexts(Subject calculable, Set<Context> accumulator)
{
Optional<CommandSource> sourceOptional = calculable.getCommandSource();
if (sourceOptional.isPresent())
{
CommandSource source = sourceOptional.get();
if (source instanceof Identifiable)
{
UUID uuid = ((Identifiable) source).getUniqueId();
if (this.plugin.getVirtualChestActions().isPlayerActivated(uuid))
{
accumulator.add(this.contextInAction);
SubjectData data = source.getTransientSubjectData();
Map<String, Boolean> permissions = data.getPermissions(Collections.singleton(this.contextInAction));
this.logger.debug("Ignored {} permission(s) for {} (context):", permissions.size(), uuid);
permissions.forEach((permission, state) -> this.logger.debug("- {} ({})", permission, state));
}
else
{
accumulator.add(this.contextNotInAction);
}
}
}
}
示例2: matches
import org.spongepowered.api.service.context.Context; //导入依赖的package包/类
@Override
public boolean matches(Context context, Subject subject)
{
Optional<CommandSource> sourceOptional = subject.getCommandSource();
if (sourceOptional.isPresent())
{
CommandSource source = sourceOptional.get();
if (source instanceof Identifiable)
{
UUID uuid = ((Identifiable) source).getUniqueId();
if (this.plugin.getVirtualChestActions().isPlayerActivated(uuid))
{
return this.contextInAction.equals(context);
}
else
{
return this.contextNotInAction.equals(context);
}
}
}
return false;
}
示例3: clearPermissions
import org.spongepowered.api.service.context.Context; //导入依赖的package包/类
public static CompletableFuture<Boolean> clearPermissions(SubjectData data, Set<Context> contexts)
{
try
{
Object result = SUBJECT_DATA_CLEAR_PERMISSIONS.invoke(data, contexts);
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);
}
}
示例4: setPermission
import org.spongepowered.api.service.context.Context; //导入依赖的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);
}
}
示例5: command
import org.spongepowered.api.service.context.Context; //导入依赖的package包/类
private CompletableFuture<Boolean> command(final CommandSource player, final String groupName, final String option, final String worldName) throws EMessageException {
String typeGroup = EPCommand.getTypeWorld(player, this.plugin.getService().getGroupSubjects(), worldName);
EGroupSubject group = EPCommand.getGroup(player, this.plugin.getService(), groupName, typeGroup);
Set<Context> contexts = EPContextCalculator.of(worldName);
String value = group.getSubjectData().getOptions(contexts).get(option);
// Si il y a une valeur
if (value != null) {
EPMessages.GROUP_OPTION_CHECK_DEFINED.sender()
.replace("{group}", group.getFriendlyIdentifier().orElse(groupName))
.replace("{option}", option)
.replace("{type}", typeGroup)
.replace("{value}", Text.of(value))
.sendTo(player);
// Il n'y a pas de valeur
} else {
EPMessages.GROUP_OPTION_CHECK_UNDEFINED.sender()
.replace("{group}", group.getFriendlyIdentifier().orElse(groupName))
.replace("{option}", option)
.replace("{type}", typeGroup)
.sendTo(player);
}
return CompletableFuture.completedFuture(true);
}
示例6: setBalance
import org.spongepowered.api.service.context.Context; //导入依赖的package包/类
@Override
public TransactionResult setBalance(final Currency currency, final BigDecimal after, final Cause cause, final Set<Context> contexts) {
TransactionType transaction = TransactionTypes.WITHDRAW;
BigDecimal before = this.getBalance(currency);
BigDecimal amount = before.subtract(after);
// Si le changement est supérieur ou égal à 0 c'est que l'on dépose de l'argent
if (amount.compareTo(BigDecimal.ZERO) >= 0) {
transaction = TransactionTypes.DEPOSIT;
}
// Transfére
this.setBalance(currency, after);
this.log(currency, before, after, transaction, cause);
return new ETransactionResult(this.plugin, this, currency, amount.abs(), contexts, ResultType.SUCCESS, transaction);
}
示例7: resetBalances
import org.spongepowered.api.service.context.Context; //导入依赖的package包/类
@Override
public Map<Currency, TransactionResult> resetBalances(final Cause cause, final Set<Context> contexts) {
Map<Currency, TransactionResult> list = new HashMap<Currency, TransactionResult>();
// Pour tous les monnaies
for (Currency currency : this.currencies.keySet()){
TransactionType transaction = TransactionTypes.WITHDRAW;
BigDecimal before = this.getBalance(currency);
BigDecimal after = getDefaultBalance(currency);
BigDecimal amount = before.subtract(after);
// Si le changement est supérieur ou égal à 0 c'est que l'on dépose de l'argent
if (amount.compareTo(BigDecimal.ZERO) >= 0) {
transaction = TransactionTypes.DEPOSIT;
}
// Transfére
this.setBalance(currency, after);
this.log(currency, before, after, transaction, cause);
list.put(currency, new ETransactionResult(this.plugin, this, currency, amount.abs(), contexts, ResultType.SUCCESS, transaction));
}
this.plugin.getThreadAsync().execute(() -> this.delete());
return list;
}
示例8: setIgnored
import org.spongepowered.api.service.context.Context; //导入依赖的package包/类
public CompletableFuture<Void> setIgnored(Player player, Collection<String> permissions)
{
SubjectData data = player.getTransientSubjectData();
Set<Context> contexts = Collections.singleton(this.contextInAction);
return this.clearPermissions(data, contexts)
.thenCompose(succeed -> CompletableFuture.allOf(this.setPermissions(permissions, data, contexts)))
.thenRun(() -> this.addIgnoredPermissionsToLog(permissions, player.getUniqueId(), player.getName()));
}
示例9: command
import org.spongepowered.api.service.context.Context; //导入依赖的package包/类
private CompletableFuture<Boolean> command(final CommandSource player, final String groupName, final String permission, final String worldName) throws EMessageException {
String typeGroup = EPCommand.getTypeWorld(player, this.plugin.getService().getGroupSubjects(), worldName);
EGroupSubject group = EPCommand.getGroup(player, this.plugin.getService(), groupName, typeGroup);
Set<Context> contexts = EPContextCalculator.of(worldName);
Tristate value = group.getPermissionValue(contexts, permission);
// Permission : True
if (value.equals(Tristate.TRUE)) {
EPMessages.GROUP_PERMISSION_CHECK_TRUE.sender()
.replace("{group}", group.getFriendlyIdentifier().orElse(groupName))
.replace("{permission}", permission)
.replace("{type}", typeGroup)
.sendTo(player);
// Permission : False
} else if (value.equals(Tristate.FALSE)) {
EPMessages.GROUP_PERMISSION_CHECK_FALSE.sender()
.replace("{group}", group.getFriendlyIdentifier().orElse(groupName))
.replace("{permission}", permission)
.replace("{type}", typeGroup)
.sendTo(player);
// Permission : Undefined
} else {
EPMessages.GROUP_PERMISSION_CHECK_UNDEFINED.sender()
.replace("{group}", group.getFriendlyIdentifier().orElse(groupName))
.replace("{permission}", permission)
.replace("{type}", typeGroup)
.sendTo(player);
}
return CompletableFuture.completedFuture(true);
}
示例10: getLoadedWithPermission
import org.spongepowered.api.service.context.Context; //导入依赖的package包/类
@Override
public Map<Subject, Boolean> getLoadedWithPermission(Set<Context> contexts, String permission) {
Preconditions.checkNotNull(contexts, "contexts");
Preconditions.checkNotNull(permission, "permission");
ImmutableMap.Builder<Subject, Boolean> builder = ImmutableMap.builder();
for (Subject subject : this.identifierSubjects.values()) {
Tristate value = subject.getPermissionValue(contexts, permission);
if (!value.equals(Tristate.UNDEFINED)) {
builder.put(subject, value.asBoolean());
}
}
return builder.build();
}
示例11: ETransactionResult
import org.spongepowered.api.service.context.Context; //导入依赖的package包/类
public ETransactionResult(final EPlugin<EverEconomy> plugin, final Account account, final Currency currency,
final BigDecimal amount, final Set<Context> contexts, final ResultType result, final TransactionType transaction) {
this.account = account;
this.currency = currency;
this.amount = amount;
this.contexts = contexts;
this.result = result;
this.transaction = transaction;
plugin.getELogger().debug("Event EconomyTransactionEvent : (Account='" + this.account.getIdentifier() +"')");
EconomyTransactionEvent event = new EEconomyTransactionEvent(Cause.source(plugin).build(), this);
plugin.getGame().getEventManager().post(event);
}
示例12: getGroup
import org.spongepowered.api.service.context.Context; //导入依赖的package包/类
@Override
public Optional<SubjectReference> getGroup(final Set<Context> contexts) {
Optional<SubjectReference> group = this.transientData.getGroup(contexts);
if (group.isPresent()) return group;
return this.data.getGroup(contexts);
}
示例13: setPermission
import org.spongepowered.api.service.context.Context; //导入依赖的package包/类
@Nonnull
@Override
public CompletableFuture<Boolean> setPermission(@Nonnull Set<Context> contexts, @Nonnull String permission, @Nonnull Tristate value) {
return handle().thenCompose(handle -> handle.setPermission(
CompatibilityUtil.convertContexts(contexts),
permission,
CompatibilityUtil.convertTristate(value)
));
}
示例14: getAllOptions
import org.spongepowered.api.service.context.Context; //导入依赖的package包/类
@Override
public Map<Set<Context>, Map<String, String>> getAllOptions() {
ImmutableMap.Builder<Set<Context>, Map<String, String>> builder = ImmutableMap.builder();
for (Entry<String, Map<String, String>> option : this.options.entrySet()) {
builder.put(EPContextCalculator.of(option.getKey()), ImmutableMap.copyOf(option.getValue()));
}
return builder.build();
}
示例15: getGroup
import org.spongepowered.api.service.context.Context; //导入依赖的package包/类
private Optional<SubjectReference> getGroup(final Subject subject, final Set<Context> contexts) {
Preconditions.checkNotNull(subject, "subject");
Preconditions.checkNotNull(contexts, "contexts");
List<SubjectReference> groups = subject.getSubjectData().getParents(contexts);
if (!groups.isEmpty()) {
return Optional.of(groups.get(0));
}
return Optional.empty();
}