Cleanup all migration commands - closes #63
This commit is contained in:
+72
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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.migration;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||
import me.lucko.luckperms.common.constants.Message;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class MigrationLogger {
|
||||
private static final int NOTIFY_FREQUENCY = 100;
|
||||
|
||||
private final String pluginName;
|
||||
private final Set<Sender> listeners = new HashSet<>();
|
||||
|
||||
public void addListener(Sender sender) {
|
||||
listeners.add(sender);
|
||||
}
|
||||
|
||||
public void log(String msg) {
|
||||
listeners.forEach(s -> Message.MIGRATION_LOG.send(s, pluginName, msg));
|
||||
}
|
||||
|
||||
public void logErr(String msg) {
|
||||
listeners.forEach(s -> Message.MIGRATION_LOG.send(s, pluginName, "Error -> " + msg));
|
||||
}
|
||||
|
||||
public void logAllProgress(String msg, int amount) {
|
||||
listeners.forEach(s -> Message.MIGRATION_LOG_PROGRESS.send(s, pluginName, msg.replace("{}", "" + amount)));
|
||||
}
|
||||
|
||||
public void logProgress(String msg, int amount) {
|
||||
if (amount % NOTIFY_FREQUENCY == 0) {
|
||||
// migrated {} groups so far.
|
||||
logAllProgress(msg, amount);
|
||||
}
|
||||
}
|
||||
|
||||
public void handleException(Exception ex) {
|
||||
if (ex instanceof ObjectAlreadyHasException || ex instanceof ObjectLacksException) {
|
||||
return;
|
||||
}
|
||||
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
package me.lucko.luckperms.common.commands.sender;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
|
||||
import me.lucko.luckperms.common.constants.Constants;
|
||||
@@ -39,6 +40,7 @@ import java.util.UUID;
|
||||
* @param <T> the command sender type
|
||||
*/
|
||||
@Getter
|
||||
@EqualsAndHashCode(of = "uuid")
|
||||
public class AbstractSender<T> implements Sender {
|
||||
private final LuckPermsPlugin platform;
|
||||
private final SenderFactory<T> factory;
|
||||
|
||||
@@ -49,7 +49,8 @@ public enum Message {
|
||||
OP_DISABLED_SPONGE("&2Server Operator status has no effect when a permission plugin is installed. Please edit user data directly.", true),
|
||||
LOG("&3LOG &3&l> {0}", true),
|
||||
EXPORT_LOG("&3EXPORT &3&l> &f{0}", true),
|
||||
MIGRATION_LOG("&3MIGRATION &3&l> &f{0}", true),
|
||||
MIGRATION_LOG("&3MIGRATION &7[&3{0}&7] &3&l> &f{1}", true),
|
||||
MIGRATION_LOG_PROGRESS("&3MIGRATION &7[&3{0}&7] &3&l> &7{1}", true),
|
||||
|
||||
COMMAND_NOT_RECOGNISED("Command not recognised.", true),
|
||||
COMMAND_NO_PERMISSION("You do not have permission to use this command!", true),
|
||||
|
||||
Reference in New Issue
Block a user