Remove messenger system & more cleanup

This commit is contained in:
Luck 2016-11-06 14:56:13 +00:00
parent 4f6e229943
commit 5ebbc178a5
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
6 changed files with 90 additions and 91 deletions

View File

@ -225,7 +225,6 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
updateTaskBuffer.requestDirectly();
// register tasks
getServer().getScheduler().runTaskTimer(this, BukkitSenderFactory.get(this), 1L, 1L);
getServer().getScheduler().runTaskTimerAsynchronously(this, new ExpireTemporaryTask(this), 60L, 60L);
getServer().getScheduler().runTaskTimerAsynchronously(this, consecutiveExecutor, 20L, 20L);
@ -382,12 +381,12 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
);
// Check for and include varying Vault config options
try {
assert getConfiguration().isVaultIncludingGlobal() == getConfiguration().isIncludingGlobalPerms();
assert getConfiguration().isIncludingGlobalWorldPerms();
assert getConfiguration().isApplyingGlobalGroups();
assert getConfiguration().isApplyingGlobalWorldGroups();
} catch (AssertionError e) {
boolean vaultDiff = getConfiguration().isVaultIncludingGlobal() != getConfiguration().isIncludingGlobalPerms() ||
!getConfiguration().isIncludingGlobalWorldPerms() ||
!getConfiguration().isApplyingGlobalGroups() ||
!getConfiguration().isApplyingGlobalWorldGroups();
if (vaultDiff) {
contexts.addAll(c.stream()
.map(map -> new Contexts(map, getConfiguration().isVaultIncludingGlobal(), true, true, true, true, op))
.collect(Collectors.toSet())

View File

@ -173,7 +173,6 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
updateTaskBuffer.requestDirectly();
// register tasks
getProxy().getScheduler().schedule(this, BungeeSenderFactory.get(this), 50L, 50L, TimeUnit.MILLISECONDS); // 20 times per second (once per "tick")
getProxy().getScheduler().schedule(this, new ExpireTemporaryTask(this), 3L, 3L, TimeUnit.SECONDS);
getProxy().getScheduler().schedule(this, consecutiveExecutor, 1L, 1L, TimeUnit.SECONDS);

View File

@ -104,7 +104,6 @@ public class MetaCache implements MetaData {
this.meta.put(meta.getKey(), meta.getValue());
}
}
this.meta.put(meta.getKey(), meta.getValue());
}
}
}

View File

@ -0,0 +1,81 @@
/*
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
*
* 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.commands;
import lombok.Getter;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.constants.Constants;
import me.lucko.luckperms.common.constants.Permission;
import java.lang.ref.WeakReference;
import java.util.UUID;
/**
* Simple implementation of {@link Sender} using a {@link SenderFactory}
* @param <T> the command sender type
*/
@Getter
public class AbstractSender<T> implements Sender {
private final LuckPermsPlugin platform;
private final SenderFactory<T> factory;
private final WeakReference<T> ref;
private final String name;
private final UUID uuid;
AbstractSender(LuckPermsPlugin platform, SenderFactory<T> factory, T t) {
this.platform = platform;
this.factory = factory;
this.ref = new WeakReference<>(t);
this.name = factory.getName(t);
this.uuid = factory.getUuid(t);
}
@Override
public void sendMessage(String s) {
final T t = ref.get();
if (t != null) {
factory.sendMessage(t, s);
}
}
@Override
public boolean hasPermission(Permission permission) {
if (isConsole()) return true;
T t = ref.get();
if (t != null) {
for (String s : permission.getNodes()) {
if (factory.hasPermission(t, s)) {
return true;
}
}
}
return false;
}
private boolean isConsole() {
return this.uuid.equals(Constants.getConsoleUUID()) || this.uuid.equals(Constants.getImporterUUID());
}
}

View File

@ -22,26 +22,18 @@
package me.lucko.luckperms.common.commands;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.constants.Constants;
import me.lucko.luckperms.common.constants.Permission;
import java.lang.ref.WeakReference;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.UUID;
/**
* Factory class to make a thread-safe sender instance
* @param <T> the command sender type
*/
@RequiredArgsConstructor
public abstract class SenderFactory<T> implements Runnable {
public abstract class SenderFactory<T> {
private final LuckPermsPlugin plugin;
private final Map<T, List<String>> messages = new HashMap<>();
private final AtomicBoolean shouldSend = new AtomicBoolean(false);
private final SenderFactory<T> factory = this;
protected abstract String getName(T t);
protected abstract UUID getUuid(T t);
@ -49,76 +41,6 @@ public abstract class SenderFactory<T> implements Runnable {
protected abstract boolean hasPermission(T t, String node);
public final Sender wrap(T t) {
return new SenderImp(plugin, t);
}
@Override
public final void run() {
if (!shouldSend.getAndSet(false)) {
return;
}
synchronized (messages) {
for (Map.Entry<T, List<String>> e : messages.entrySet()) {
for (String s : e.getValue()) {
factory.sendMessage(e.getKey(), s);
}
}
messages.clear();
}
}
private class SenderImp implements Sender {
private final WeakReference<T> tRef;
@Getter
private final String name;
@Getter
private final UUID uuid;
private final boolean console;
@Getter
private final LuckPermsPlugin platform;
private SenderImp(LuckPermsPlugin platform, T t) {
this.platform = platform;
this.tRef = new WeakReference<>(t);
this.name = factory.getName(t);
this.uuid = factory.getUuid(t);
this.console = this.uuid.equals(Constants.getConsoleUUID()) || this.uuid.equals(Constants.getImporterUUID());
}
@Override
public void sendMessage(String s) {
final T t = tRef.get();
if (t != null) {
synchronized (messages) {
if (!messages.containsKey(t)) {
messages.put(t, new ArrayList<>());
}
messages.get(t).add(s);
}
shouldSend.set(true);
}
}
@Override
public boolean hasPermission(Permission permission) {
if (console) return true;
T t = tRef.get();
if (t == null) return false;
for (String s : permission.getNodes()) {
if (factory.hasPermission(t, s)) {
return true;
}
}
return false;
}
return new AbstractSender<>(plugin, this, t);
}
}

View File

@ -215,7 +215,6 @@ public class LPSpongePlugin implements LuckPermsPlugin {
updateTaskBuffer.requestDirectly();
// register tasks
scheduler.createTaskBuilder().intervalTicks(1L).execute(SpongeSenderFactory.get(this)).submit(this);
scheduler.createTaskBuilder().async().intervalTicks(60L).execute(new ExpireTemporaryTask(this)).submit(this);
scheduler.createTaskBuilder().async().intervalTicks(20L).execute(consecutiveExecutor).submit(this);