mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2025-02-05 23:21:22 +01:00
Log the name of the calculator when an exception is thrown
This commit is contained in:
parent
0eba5f1cbc
commit
6923c4e247
@ -186,7 +186,7 @@ public abstract class AbstractContextManager<T> implements ContextManager<T> {
|
||||
}
|
||||
accumulator = ret;
|
||||
} catch (Exception e) {
|
||||
AbstractContextManager.this.plugin.getLog().warn("An exception was thrown whilst calculating the context of subject " + subject);
|
||||
AbstractContextManager.this.plugin.getLog().warn("An exception was thrown by " + getCalculatorClass(calculator) + " whilst calculating the context of subject " + subject);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@ -209,7 +209,7 @@ public abstract class AbstractContextManager<T> implements ContextManager<T> {
|
||||
}
|
||||
accumulator = ret;
|
||||
} catch (Exception e) {
|
||||
AbstractContextManager.this.plugin.getLog().warn("An exception was thrown whilst calculating static contexts");
|
||||
AbstractContextManager.this.plugin.getLog().warn("An exception was thrown by " + getCalculatorClass(calculator) + " whilst calculating static contexts");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@ -218,4 +218,14 @@ public abstract class AbstractContextManager<T> implements ContextManager<T> {
|
||||
}
|
||||
}
|
||||
|
||||
private static String getCalculatorClass(ContextCalculator<?> calculator) {
|
||||
Class<?> calculatorClass;
|
||||
if (calculator instanceof ProxiedContextCalculator) {
|
||||
calculatorClass = ((ProxiedContextCalculator) calculator).getDelegate().getClass();
|
||||
} else {
|
||||
calculatorClass = calculator.getClass();
|
||||
}
|
||||
return calculatorClass.getName();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* This file is part of LuckPerms, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.common.contexts;
|
||||
|
||||
import me.lucko.luckperms.api.context.ContextCalculator;
|
||||
|
||||
/**
|
||||
* Represents a {@link ContextCalculator} which delegates calls to another object.
|
||||
*/
|
||||
public interface ProxiedContextCalculator<T> extends ContextCalculator<T> {
|
||||
|
||||
Object getDelegate();
|
||||
|
||||
}
|
@ -25,21 +25,22 @@
|
||||
|
||||
package me.lucko.luckperms.sponge.contexts;
|
||||
|
||||
import me.lucko.luckperms.api.context.ContextCalculator;
|
||||
import me.lucko.luckperms.api.context.MutableContextSet;
|
||||
import me.lucko.luckperms.common.contexts.ProxiedContextCalculator;
|
||||
import me.lucko.luckperms.sponge.service.context.DelegatingMutableContextSet;
|
||||
|
||||
import org.spongepowered.api.service.context.Context;
|
||||
import org.spongepowered.api.service.context.ContextCalculator;
|
||||
import org.spongepowered.api.service.permission.Subject;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class ProxiedContextCalculator implements ContextCalculator<Subject> {
|
||||
private final org.spongepowered.api.service.context.ContextCalculator<Subject> delegate;
|
||||
public class SpongeProxiedContextCalculator implements ProxiedContextCalculator<Subject> {
|
||||
private final ContextCalculator<Subject> delegate;
|
||||
|
||||
public ProxiedContextCalculator(org.spongepowered.api.service.context.ContextCalculator<Subject> delegate) {
|
||||
public SpongeProxiedContextCalculator(ContextCalculator<Subject> delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@ -51,4 +52,9 @@ public class ProxiedContextCalculator implements ContextCalculator<Subject> {
|
||||
return accumulator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getDelegate() {
|
||||
return this.delegate;
|
||||
}
|
||||
|
||||
}
|
@ -34,7 +34,7 @@ import com.google.common.collect.ImmutableSet;
|
||||
import me.lucko.luckperms.common.model.Group;
|
||||
import me.lucko.luckperms.common.utils.Predicates;
|
||||
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
||||
import me.lucko.luckperms.sponge.contexts.ProxiedContextCalculator;
|
||||
import me.lucko.luckperms.sponge.contexts.SpongeProxiedContextCalculator;
|
||||
import me.lucko.luckperms.sponge.managers.SpongeGroupManager;
|
||||
import me.lucko.luckperms.sponge.managers.SpongeUserManager;
|
||||
import me.lucko.luckperms.sponge.service.legacy.LegacyDataMigrator;
|
||||
@ -48,6 +48,7 @@ import me.lucko.luckperms.sponge.service.reference.SubjectReferenceFactory;
|
||||
import me.lucko.luckperms.sponge.service.storage.SubjectStorage;
|
||||
|
||||
import org.spongepowered.api.plugin.PluginContainer;
|
||||
import org.spongepowered.api.service.context.ContextCalculator;
|
||||
import org.spongepowered.api.service.permission.PermissionService;
|
||||
import org.spongepowered.api.service.permission.Subject;
|
||||
import org.spongepowered.api.text.Text;
|
||||
@ -205,9 +206,9 @@ public class LuckPermsService implements LPPermissionService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerContextCalculator(org.spongepowered.api.service.context.ContextCalculator<Subject> calculator) {
|
||||
public void registerContextCalculator(ContextCalculator<Subject> calculator) {
|
||||
Objects.requireNonNull(calculator);
|
||||
this.plugin.getContextManager().registerCalculator(new ProxiedContextCalculator(calculator));
|
||||
this.plugin.getContextManager().registerCalculator(new SpongeProxiedContextCalculator(calculator));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user