Add source to UserPromote & UserDemote events (#722)

This commit is contained in:
Luck 2018-02-01 21:33:32 +00:00
parent a1a2e189b6
commit 31df29194b
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
45 changed files with 570 additions and 126 deletions

View File

@ -0,0 +1,87 @@
/*
* 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.api;
import java.util.UUID;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/**
* Represents an entity on the server.
*
* <p>This does not relate directly to a "Minecraft Entity". The closest
* comparison is to a "CommandSender" or "CommandSource" in Bukkit/Sponge.</p>
*
* <p>The various types of {@link Entity} are detailed in {@link Type}.</p>
*
* @since 4.1
*/
public interface Entity {
/**
* Gets the unique id of the entity, if it has one.
*
* <p>For players, this returns their uuid assigned by the server.</p>
*
* @return the uuid of the object, if available
*/
@Nullable
UUID getUniqueId();
/**
* Gets the name of the object
*
* @return the object name
*/
@Nonnull
String getName();
/**
* Gets the entities type.
*
* @return the type
*/
@Nonnull
Type getType();
/**
* The different types of {@link Entity}
*/
enum Type {
/**
* Represents a player connected to the server
*/
PLAYER,
/**
* Represents the server console
*/
CONSOLE
}
}

View File

@ -0,0 +1,50 @@
/*
* 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.api.event;
import me.lucko.luckperms.api.event.source.Source;
import javax.annotation.Nonnull;
/**
* Represents an event with a {@link Source}.
*
* @since 4.1
*/
public interface Sourced {
/**
* Gets the events source.
*
* <p>Never returns null. In situations where the source is unknown, a
* {@link Source} with type {@link Source.Type#UNKNOWN} is returned.</p>
*
* @return the source
*/
@Nonnull
Source getSource();
}

View File

@ -25,13 +25,11 @@
package me.lucko.luckperms.api.event.log; package me.lucko.luckperms.api.event.log;
import me.lucko.luckperms.api.Entity;
import me.lucko.luckperms.api.LogEntry; import me.lucko.luckperms.api.LogEntry;
import me.lucko.luckperms.api.event.Cancellable; import me.lucko.luckperms.api.event.Cancellable;
import me.lucko.luckperms.api.event.LuckPermsEvent; import me.lucko.luckperms.api.event.LuckPermsEvent;
import java.util.Optional;
import java.util.UUID;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
/** /**
@ -60,7 +58,7 @@ public interface LogNotifyEvent extends LuckPermsEvent, Cancellable {
* @return the origin of the log * @return the origin of the log
*/ */
@Nonnull @Nonnull
LogBroadcastEvent.Origin getOrigin(); Origin getOrigin();
/** /**
* Gets the object to be notified. * Gets the object to be notified.
@ -68,46 +66,27 @@ public interface LogNotifyEvent extends LuckPermsEvent, Cancellable {
* @return the object to notify * @return the object to notify
*/ */
@Nonnull @Nonnull
Notifiable getNotifiable(); Entity getNotifiable();
/** /**
* Represents an object which could be notified as a result of a * Represents where a log entry is from
* {@link LogNotifyEvent}.
*/ */
interface Notifiable { enum Origin {
/** /**
* Gets a {@link UUID} for the object, if it has one. * Marks a log entry which originated from the current server instance
*
* <p>For Players, this method returns their unique id.</p>
*
* @return the uuid of the object, if available
*/ */
@Nonnull LOCAL,
Optional<UUID> getUuid();
/** /**
* Gets the name of the object * Marks a log entry which originated from an API call on the current server instance
*
* @return the name
*/ */
@Nonnull LOCAL_API,
String getName();
/** /**
* Gets if the object is a console * Marks a log entry which was sent to this server via the messaging service
*
* @return if the object is a console
*/ */
boolean isConsole(); REMOTE
/**
* Gets if the object is a player
*
* @return if the object is a player
*/
boolean isPlayer();
} }
} }

View File

@ -0,0 +1,47 @@
/*
* 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.api.event.source;
import me.lucko.luckperms.api.Entity;
import javax.annotation.Nonnull;
/**
* Represents an {@link Entity} which was the {@link Source} of something.
*
* @since 4.1
*/
public interface EntitySource extends Source {
/**
* Gets the entity.
*
* @return the entity
*/
@Nonnull
Entity getEntity();
}

View File

@ -0,0 +1,67 @@
/*
* 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.api.event.source;
import me.lucko.luckperms.api.Entity;
import javax.annotation.Nonnull;
/**
* Represents the source of an event.
*
* <p>Could also be described as the "thing" that caused an event to occur.</p>
*
* @since 4.1
*/
public interface Source {
/**
* Gets the source type
*
* @return the type
*/
@Nonnull
Type getType();
/**
* Represents a type of source
*/
enum Type {
/**
* Represents an {@link Entity} source
*
* @see EntitySource
*/
ENTITY,
/**
* Represents an unknown source
*/
UNKNOWN
}
}

View File

@ -28,6 +28,7 @@ package me.lucko.luckperms.api.event.user.track;
import me.lucko.luckperms.api.Track; import me.lucko.luckperms.api.Track;
import me.lucko.luckperms.api.User; import me.lucko.luckperms.api.User;
import me.lucko.luckperms.api.event.LuckPermsEvent; import me.lucko.luckperms.api.event.LuckPermsEvent;
import me.lucko.luckperms.api.event.Sourced;
import java.util.Optional; import java.util.Optional;
@ -36,7 +37,7 @@ import javax.annotation.Nonnull;
/** /**
* Called when a user interacts with a track through a promotion or demotion * Called when a user interacts with a track through a promotion or demotion
*/ */
public interface UserTrackEvent extends LuckPermsEvent { public interface UserTrackEvent extends LuckPermsEvent, Sourced {
/** /**
* Gets the track involved in the event * Gets the track involved in the event

View File

@ -26,6 +26,7 @@
package me.lucko.luckperms.common.actionlog; package me.lucko.luckperms.common.actionlog;
import me.lucko.luckperms.api.event.log.LogBroadcastEvent; import me.lucko.luckperms.api.event.log.LogBroadcastEvent;
import me.lucko.luckperms.api.event.log.LogNotifyEvent;
import me.lucko.luckperms.common.commands.CommandPermission; import me.lucko.luckperms.common.commands.CommandPermission;
import me.lucko.luckperms.common.commands.impl.log.LogNotify; import me.lucko.luckperms.common.commands.impl.log.LogNotify;
import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.commands.sender.Sender;
@ -43,7 +44,7 @@ public class LogDispatcher {
this.plugin = plugin; this.plugin = plugin;
} }
private void broadcast(ExtendedLogEntry entry, LogBroadcastEvent.Origin origin, Sender sender) { private void broadcast(ExtendedLogEntry entry, LogNotifyEvent.Origin origin, Sender sender) {
this.plugin.getOnlineSenders() this.plugin.getOnlineSenders()
.filter(CommandPermission.LOG_NOTIFY::isAuthorized) .filter(CommandPermission.LOG_NOTIFY::isAuthorized)
.filter(s -> { .filter(s -> {
@ -76,7 +77,7 @@ public class LogDispatcher {
boolean shouldCancel = !this.plugin.getConfiguration().get(ConfigKeys.LOG_NOTIFY); boolean shouldCancel = !this.plugin.getConfiguration().get(ConfigKeys.LOG_NOTIFY);
if (!this.plugin.getEventFactory().handleLogBroadcast(shouldCancel, entry, LogBroadcastEvent.Origin.LOCAL)) { if (!this.plugin.getEventFactory().handleLogBroadcast(shouldCancel, entry, LogBroadcastEvent.Origin.LOCAL)) {
broadcast(entry, LogBroadcastEvent.Origin.LOCAL, sender); broadcast(entry, LogNotifyEvent.Origin.LOCAL, sender);
} }
} }
@ -97,14 +98,14 @@ public class LogDispatcher {
boolean shouldCancel = !this.plugin.getConfiguration().get(ConfigKeys.LOG_NOTIFY); boolean shouldCancel = !this.plugin.getConfiguration().get(ConfigKeys.LOG_NOTIFY);
if (!this.plugin.getEventFactory().handleLogBroadcast(shouldCancel, entry, LogBroadcastEvent.Origin.LOCAL_API)) { if (!this.plugin.getEventFactory().handleLogBroadcast(shouldCancel, entry, LogBroadcastEvent.Origin.LOCAL_API)) {
broadcast(entry, LogBroadcastEvent.Origin.LOCAL_API, null); broadcast(entry, LogNotifyEvent.Origin.LOCAL_API, null);
} }
} }
public void dispatchFromRemote(ExtendedLogEntry entry) { public void dispatchFromRemote(ExtendedLogEntry entry) {
boolean shouldCancel = !this.plugin.getConfiguration().get(ConfigKeys.BROADCAST_RECEIVED_LOG_ENTRIES) || !this.plugin.getConfiguration().get(ConfigKeys.LOG_NOTIFY); boolean shouldCancel = !this.plugin.getConfiguration().get(ConfigKeys.BROADCAST_RECEIVED_LOG_ENTRIES) || !this.plugin.getConfiguration().get(ConfigKeys.LOG_NOTIFY);
if (!this.plugin.getEventFactory().handleLogBroadcast(shouldCancel, entry, LogBroadcastEvent.Origin.REMOTE)) { if (!this.plugin.getEventFactory().handleLogBroadcast(shouldCancel, entry, LogBroadcastEvent.Origin.REMOTE)) {
broadcast(entry, LogBroadcastEvent.Origin.LOCAL_API, null); broadcast(entry, LogNotifyEvent.Origin.LOCAL_API, null);
} }
} }
} }

View File

@ -133,7 +133,7 @@ public class UserDemote extends SubCommand<User> {
.build().submit(plugin, sender); .build().submit(plugin, sender);
save(user, sender, plugin); save(user, sender, plugin);
plugin.getEventFactory().handleUserDemote(user, track, old, null); plugin.getEventFactory().handleUserDemote(user, track, old, null, sender);
return CommandResult.SUCCESS; return CommandResult.SUCCESS;
} }
@ -160,7 +160,7 @@ public class UserDemote extends SubCommand<User> {
.build().submit(plugin, sender); .build().submit(plugin, sender);
save(user, sender, plugin); save(user, sender, plugin);
plugin.getEventFactory().handleUserDemote(user, track, old, previousGroup.getName()); plugin.getEventFactory().handleUserDemote(user, track, old, previousGroup.getName(), sender);
return CommandResult.SUCCESS; return CommandResult.SUCCESS;
} }

View File

@ -120,7 +120,7 @@ public class UserPromote extends SubCommand<User> {
.build().submit(plugin, sender); .build().submit(plugin, sender);
save(user, sender, plugin); save(user, sender, plugin);
plugin.getEventFactory().handleUserPromote(user, track, null, first); plugin.getEventFactory().handleUserPromote(user, track, null, first, sender);
return CommandResult.SUCCESS; return CommandResult.SUCCESS;
} }
@ -177,7 +177,7 @@ public class UserPromote extends SubCommand<User> {
.build().submit(plugin, sender); .build().submit(plugin, sender);
save(user, sender, plugin); save(user, sender, plugin);
plugin.getEventFactory().handleUserPromote(user, track, old, nextGroup.getName()); plugin.getEventFactory().handleUserPromote(user, track, old, nextGroup.getName(), sender);
return CommandResult.SUCCESS; return CommandResult.SUCCESS;
} }

View File

@ -36,6 +36,7 @@ import me.lucko.luckperms.api.event.LuckPermsEvent;
import me.lucko.luckperms.api.event.cause.CreationCause; import me.lucko.luckperms.api.event.cause.CreationCause;
import me.lucko.luckperms.api.event.cause.DeletionCause; import me.lucko.luckperms.api.event.cause.DeletionCause;
import me.lucko.luckperms.api.event.log.LogBroadcastEvent; import me.lucko.luckperms.api.event.log.LogBroadcastEvent;
import me.lucko.luckperms.api.event.log.LogNotifyEvent;
import me.lucko.luckperms.common.api.LuckPermsApiProvider; import me.lucko.luckperms.common.api.LuckPermsApiProvider;
import me.lucko.luckperms.common.api.delegates.model.ApiPermissionHolder; import me.lucko.luckperms.common.api.delegates.model.ApiPermissionHolder;
import me.lucko.luckperms.common.api.delegates.model.ApiUser; import me.lucko.luckperms.common.api.delegates.model.ApiUser;
@ -72,6 +73,8 @@ import me.lucko.luckperms.common.event.impl.EventUserFirstLogin;
import me.lucko.luckperms.common.event.impl.EventUserLoad; import me.lucko.luckperms.common.event.impl.EventUserLoad;
import me.lucko.luckperms.common.event.impl.EventUserLoginProcess; import me.lucko.luckperms.common.event.impl.EventUserLoginProcess;
import me.lucko.luckperms.common.event.impl.EventUserPromote; import me.lucko.luckperms.common.event.impl.EventUserPromote;
import me.lucko.luckperms.common.event.model.EntitySender;
import me.lucko.luckperms.common.event.model.SourceEntity;
import me.lucko.luckperms.common.model.Group; import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.model.PermissionHolder; import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.model.Track; import me.lucko.luckperms.common.model.Track;
@ -153,7 +156,7 @@ public final class EventFactory {
return cancel.get(); return cancel.get();
} }
public boolean handleLogNotify(boolean initialState, LogEntry entry, LogBroadcastEvent.Origin origin, Sender sender) { public boolean handleLogNotify(boolean initialState, LogEntry entry, LogNotifyEvent.Origin origin, Sender sender) {
AtomicBoolean cancel = new AtomicBoolean(initialState); AtomicBoolean cancel = new AtomicBoolean(initialState);
EventLogNotify event = new EventLogNotify(cancel, entry, origin, sender); EventLogNotify event = new EventLogNotify(cancel, entry, origin, sender);
fireEvent(event); fireEvent(event);
@ -264,13 +267,13 @@ public final class EventFactory {
fireEvent(event); fireEvent(event);
} }
public void handleUserDemote(User user, Track track, String from, String to) { public void handleUserDemote(User user, Track track, String from, String to, Sender source) {
EventUserDemote event = new EventUserDemote(track.getApiDelegate(), new ApiUser(user), from, to); EventUserDemote event = new EventUserDemote(track.getApiDelegate(), new ApiUser(user), from, to, new SourceEntity(new EntitySender(source)));
fireEventAsync(event); fireEventAsync(event);
} }
public void handleUserPromote(User user, Track track, String from, String to) { public void handleUserPromote(User user, Track track, String from, String to, Sender source) {
EventUserPromote event = new EventUserPromote(track.getApiDelegate(), new ApiUser(user), from, to); EventUserPromote event = new EventUserPromote(track.getApiDelegate(), new ApiUser(user), from, to, new SourceEntity(new EntitySender(source)));
fireEventAsync(event); fireEventAsync(event);
} }

View File

@ -32,6 +32,6 @@ public class EventConfigReload extends AbstractEvent implements ConfigReloadEven
@Override @Override
public String toString() { public String toString() {
return "EventConfigReload()"; return "ConfigReloadEvent()";
} }
} }

View File

@ -56,6 +56,6 @@ public class EventGroupCacheLoad extends AbstractEvent implements GroupCacheLoad
@Override @Override
public String toString() { public String toString() {
return "EventGroupCacheLoad(group=" + this.getGroup() + ", loadedData=" + this.getLoadedData() + ")"; return "GroupCacheLoadEvent(group=" + this.getGroup() + ", loadedData=" + this.getLoadedData() + ")";
} }
} }

View File

@ -56,6 +56,6 @@ public class EventGroupCreate extends AbstractEvent implements GroupCreateEvent
@Override @Override
public String toString() { public String toString() {
return "EventGroupCreate(group=" + this.getGroup() + ", cause=" + this.getCause() + ")"; return "GroupCreateEvent(group=" + this.getGroup() + ", cause=" + this.getCause() + ")";
} }
} }

View File

@ -56,6 +56,6 @@ public class EventGroupDataRecalculate extends AbstractEvent implements GroupDat
@Override @Override
public String toString() { public String toString() {
return "EventGroupDataRecalculate(group=" + this.getGroup() + ", data=" + this.getData() + ")"; return "GroupDataRecalculateEvent(group=" + this.getGroup() + ", data=" + this.getData() + ")";
} }
} }

View File

@ -66,6 +66,9 @@ public class EventGroupDelete extends AbstractEvent implements GroupDeleteEvent
@Override @Override
public String toString() { public String toString() {
return "EventGroupDelete(groupName=" + this.getGroupName() + ", existingData=" + this.getExistingData() + ", cause=" + this.getCause() + ")"; return "GroupDeleteEvent(" +
"groupName=" + this.getGroupName() + ", " +
"existingData=" + this.getExistingData() + ", " +
"cause=" + this.getCause() + ")";
} }
} }

View File

@ -47,6 +47,6 @@ public class EventGroupLoad extends AbstractEvent implements GroupLoadEvent {
@Override @Override
public String toString() { public String toString() {
return "EventGroupLoad(group=" + this.getGroup() + ")"; return "GroupLoadEvent(group=" + this.getGroup() + ")";
} }
} }

View File

@ -32,6 +32,6 @@ public class EventGroupLoadAll extends AbstractEvent implements GroupLoadAllEven
@Override @Override
public String toString() { public String toString() {
return "EventGroupLoadAll()"; return "GroupLoadAllEvent()";
} }
} }

View File

@ -65,6 +65,9 @@ public class EventLogBroadcast extends AbstractEvent implements LogBroadcastEven
@Override @Override
public String toString() { public String toString() {
return "EventLogBroadcast(cancellationState=" + this.getCancellationState() + ", entry=" + this.getEntry() + ", origin=" + this.getOrigin() + ")"; return "LogBroadcastEvent(" +
"cancellationState=" + this.getCancellationState() + ", " +
"entry=" + this.getEntry() + ", " +
"origin=" + this.getOrigin() + ")";
} }
} }

View File

@ -66,6 +66,9 @@ public class EventLogNetworkPublish extends AbstractEvent implements LogNetworkP
@Override @Override
public String toString() { public String toString() {
return "EventLogNetworkPublish(cancellationState=" + this.getCancellationState() + ", logId=" + this.getLogId() + ", entry=" + this.getEntry() + ")"; return "LogNetworkPublishEvent(" +
"cancellationState=" + this.getCancellationState() + ", " +
"logId=" + this.getLogId() + ", " +
"entry=" + this.getEntry() + ")";
} }
} }

View File

@ -25,14 +25,13 @@
package me.lucko.luckperms.common.event.impl; package me.lucko.luckperms.common.event.impl;
import me.lucko.luckperms.api.Entity;
import me.lucko.luckperms.api.LogEntry; import me.lucko.luckperms.api.LogEntry;
import me.lucko.luckperms.api.event.log.LogBroadcastEvent;
import me.lucko.luckperms.api.event.log.LogNotifyEvent; import me.lucko.luckperms.api.event.log.LogNotifyEvent;
import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.event.AbstractEvent; import me.lucko.luckperms.common.event.AbstractEvent;
import me.lucko.luckperms.common.event.model.EntitySender;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -41,12 +40,12 @@ public class EventLogNotify extends AbstractEvent implements LogNotifyEvent {
private final AtomicBoolean cancellationState; private final AtomicBoolean cancellationState;
private final LogEntry entry; private final LogEntry entry;
private final LogBroadcastEvent.Origin origin; private final Origin origin;
private final Sender sender; private final Sender sender;
private Notifiable notifiable; private Entity notifiable;
public EventLogNotify(AtomicBoolean cancellationState, LogEntry entry, LogBroadcastEvent.Origin origin, Sender sender) { public EventLogNotify(AtomicBoolean cancellationState, LogEntry entry, Origin origin, Sender sender) {
this.cancellationState = cancellationState; this.cancellationState = cancellationState;
this.entry = entry; this.entry = entry;
this.origin = origin; this.origin = origin;
@ -55,9 +54,9 @@ public class EventLogNotify extends AbstractEvent implements LogNotifyEvent {
@Nonnull @Nonnull
@Override @Override
public synchronized Notifiable getNotifiable() { public synchronized Entity getNotifiable() {
if (this.notifiable == null) { if (this.notifiable == null) {
this.notifiable = new SenderNotifiable(this.sender); this.notifiable = new EntitySender(this.sender);
} }
return this.notifiable; return this.notifiable;
} }
@ -76,50 +75,17 @@ public class EventLogNotify extends AbstractEvent implements LogNotifyEvent {
@Nonnull @Nonnull
@Override @Override
public LogBroadcastEvent.Origin getOrigin() { public Origin getOrigin() {
return this.origin; return this.origin;
} }
public Sender getSender() {
return this.sender;
}
@Override @Override
public String toString() { public String toString() {
return "EventLogNotify(cancellationState=" + this.getCancellationState() + ", entry=" + this.getEntry() + ", origin=" + this.getOrigin() + ", sender=" + this.getSender() + ", notifiable=" + this.getNotifiable() + ")"; return "LogNotifyEvent(" +
} "cancellationState=" + this.getCancellationState() + ", " +
"entry=" + this.getEntry() + ", " +
private static final class SenderNotifiable implements Notifiable { "origin=" + this.getOrigin() + ", " +
private final Sender sender; "notifiable=" + this.getNotifiable() + ")";
public SenderNotifiable(Sender sender) {
this.sender = sender;
}
@Nonnull
@Override
public Optional<UUID> getUuid() {
if (this.sender.isConsole()) {
return Optional.empty();
}
return Optional.of(this.sender.getUuid());
}
@Nonnull
@Override
public String getName() {
return this.sender.getName();
}
@Override
public boolean isConsole() {
return this.sender.isConsole();
}
@Override
public boolean isPlayer() {
return !this.sender.isConsole();
}
} }
} }

View File

@ -57,6 +57,6 @@ public class EventLogPublish extends AbstractEvent implements LogPublishEvent {
@Override @Override
public String toString() { public String toString() {
return "EventLogPublish(cancellationState=" + this.getCancellationState() + ", entry=" + this.getEntry() + ")"; return "LogPublishEvent(cancellationState=" + this.getCancellationState() + ", entry=" + this.getEntry() + ")";
} }
} }

View File

@ -57,6 +57,6 @@ public class EventLogReceive extends AbstractEvent implements LogReceiveEvent {
@Override @Override
public String toString() { public String toString() {
return "EventLogReceive(logId=" + this.getLogId() + ", entry=" + this.getEntry() + ")"; return "LogReceiveEvent(logId=" + this.getLogId() + ", entry=" + this.getEntry() + ")";
} }
} }

View File

@ -86,6 +86,10 @@ public class EventNodeAdd extends AbstractEvent implements NodeAddEvent {
@Override @Override
public String toString() { public String toString() {
return "EventNodeAdd(node=" + this.getNode() + ", target=" + this.getTarget() + ", dataBefore=" + this.getDataBefore() + ", dataAfter=" + this.getDataAfter() + ")"; return "NodeAddEvent(" +
"node=" + this.getNode() + ", " +
"target=" + this.getTarget() + ", " +
"dataBefore=" + this.getDataBefore() + ", " +
"dataAfter=" + this.getDataAfter() + ")";
} }
} }

View File

@ -78,6 +78,9 @@ public class EventNodeClear extends AbstractEvent implements NodeClearEvent {
@Override @Override
public String toString() { public String toString() {
return "EventNodeClear(target=" + this.getTarget() + ", dataBefore=" + this.getDataBefore() + ", dataAfter=" + this.getDataAfter() + ")"; return "NodeClearEvent(" +
"target=" + this.getTarget() + ", " +
"dataBefore=" + this.getDataBefore() + ", " +
"dataAfter=" + this.getDataAfter() + ")";
} }
} }

View File

@ -86,6 +86,10 @@ public class EventNodeRemove extends AbstractEvent implements NodeRemoveEvent {
@Override @Override
public String toString() { public String toString() {
return "EventNodeRemove(node=" + this.getNode() + ", target=" + this.getTarget() + ", dataBefore=" + this.getDataBefore() + ", dataAfter=" + this.getDataAfter() + ")"; return "NodeRemoveEvent(" +
"node=" + this.getNode() + ", " +
"target=" + this.getTarget() + ", " +
"dataBefore=" + this.getDataBefore() + ", " +
"dataAfter=" + this.getDataAfter() + ")";
} }
} }

View File

@ -32,6 +32,6 @@ public class EventPostSync extends AbstractEvent implements PostSyncEvent {
@Override @Override
public String toString() { public String toString() {
return "EventPostSync()"; return "PostSyncEvent()";
} }
} }

View File

@ -57,6 +57,8 @@ public class EventPreNetworkSync extends AbstractEvent implements PreNetworkSync
@Override @Override
public String toString() { public String toString() {
return "EventPreNetworkSync(cancellationState=" + this.getCancellationState() + ", syncId=" + this.getSyncId() + ")"; return "PreNetworkSyncEvent(" +
"cancellationState=" + this.getCancellationState() + ", " +
"syncId=" + this.getSyncId() + ")";
} }
} }

View File

@ -48,6 +48,6 @@ public class EventPreSync extends AbstractEvent implements PreSyncEvent {
@Override @Override
public String toString() { public String toString() {
return "EventPreSync(cancellationState=" + this.getCancellationState() + ")"; return "PreSyncEvent(cancellationState=" + this.getCancellationState() + ")";
} }
} }

View File

@ -73,6 +73,10 @@ public class EventTrackAddGroup extends AbstractEvent implements TrackAddGroupEv
@Override @Override
public String toString() { public String toString() {
return "EventTrackAddGroup(group=" + this.getGroup() + ", track=" + this.getTrack() + ", dataBefore=" + this.getDataBefore() + ", dataAfter=" + this.getDataAfter() + ")"; return "TrackAddGroupEvent(" +
"group=" + this.getGroup() + ", " +
"track=" + this.getTrack() + ", " +
"dataBefore=" + this.getDataBefore() + ", " +
"dataAfter=" + this.getDataAfter() + ")";
} }
} }

View File

@ -65,6 +65,9 @@ public class EventTrackClear extends AbstractEvent implements TrackClearEvent {
@Override @Override
public String toString() { public String toString() {
return "EventTrackClear(track=" + this.getTrack() + ", dataBefore=" + this.getDataBefore() + ", dataAfter=" + this.getDataAfter() + ")"; return "TrackClearEvent(" +
"track=" + this.getTrack() + ", " +
"dataBefore=" + this.getDataBefore() + ", " +
"dataAfter=" + this.getDataAfter() + ")";
} }
} }

View File

@ -56,6 +56,6 @@ public class EventTrackCreate extends AbstractEvent implements TrackCreateEvent
@Override @Override
public String toString() { public String toString() {
return "EventTrackCreate(track=" + this.getTrack() + ", cause=" + this.getCause() + ")"; return "TrackCreateEvent(track=" + this.getTrack() + ", cause=" + this.getCause() + ")";
} }
} }

View File

@ -65,6 +65,9 @@ public class EventTrackDelete extends AbstractEvent implements TrackDeleteEvent
@Override @Override
public String toString() { public String toString() {
return "EventTrackDelete(trackName=" + this.getTrackName() + ", existingData=" + this.getExistingData() + ", cause=" + this.getCause() + ")"; return "TrackDeleteEvent(" +
"trackName=" + this.getTrackName() + ", " +
"existingData=" + this.getExistingData() + ", " +
"cause=" + this.getCause() + ")";
} }
} }

View File

@ -47,6 +47,6 @@ public class EventTrackLoad extends AbstractEvent implements TrackLoadEvent {
@Override @Override
public String toString() { public String toString() {
return "EventTrackLoad(track=" + this.getTrack() + ")"; return "TrackLoadEvent(track=" + this.getTrack() + ")";
} }
} }

View File

@ -32,6 +32,6 @@ public class EventTrackLoadAll extends AbstractEvent implements TrackLoadAllEven
@Override @Override
public String toString() { public String toString() {
return "EventTrackLoadAll()"; return "TrackLoadAllEvent()";
} }
} }

View File

@ -73,6 +73,10 @@ public class EventTrackRemoveGroup extends AbstractEvent implements TrackRemoveG
@Override @Override
public String toString() { public String toString() {
return "EventTrackRemoveGroup(group=" + this.getGroup() + ", track=" + this.getTrack() + ", dataBefore=" + this.getDataBefore() + ", dataAfter=" + this.getDataAfter() + ")"; return "TrackRemoveGroupEvent(" +
"group=" + this.getGroup() + ", " +
"track=" + this.getTrack() + ", " +
"dataBefore=" + this.getDataBefore() + ", " +
"dataAfter=" + this.getDataAfter() + ")";
} }
} }

View File

@ -56,6 +56,6 @@ public class EventUserCacheLoad extends AbstractEvent implements UserCacheLoadEv
@Override @Override
public String toString() { public String toString() {
return "EventUserCacheLoad(user=" + this.getUser() + ", loadedData=" + this.getLoadedData() + ")"; return "UserCacheLoadEvent(user=" + this.getUser() + ", loadedData=" + this.getLoadedData() + ")";
} }
} }

View File

@ -56,6 +56,6 @@ public class EventUserDataRecalculate extends AbstractEvent implements UserDataR
@Override @Override
public String toString() { public String toString() {
return "EventUserDataRecalculate(user=" + this.getUser() + ", data=" + this.getData() + ")"; return "UserDataRecalculateEvent(user=" + this.getUser() + ", data=" + this.getData() + ")";
} }
} }

View File

@ -27,6 +27,7 @@ package me.lucko.luckperms.common.event.impl;
import me.lucko.luckperms.api.Track; import me.lucko.luckperms.api.Track;
import me.lucko.luckperms.api.User; import me.lucko.luckperms.api.User;
import me.lucko.luckperms.api.event.source.Source;
import me.lucko.luckperms.api.event.user.track.TrackAction; import me.lucko.luckperms.api.event.user.track.TrackAction;
import me.lucko.luckperms.api.event.user.track.UserDemoteEvent; import me.lucko.luckperms.api.event.user.track.UserDemoteEvent;
import me.lucko.luckperms.common.event.AbstractEvent; import me.lucko.luckperms.common.event.AbstractEvent;
@ -43,11 +44,14 @@ public class EventUserDemote extends AbstractEvent implements UserDemoteEvent {
private final String groupFrom; private final String groupFrom;
private final String groupTo; private final String groupTo;
public EventUserDemote(Track track, User user, String groupFrom, String groupTo) { private final Source source;
public EventUserDemote(Track track, User user, String groupFrom, String groupTo, Source source) {
this.track = track; this.track = track;
this.user = user; this.user = user;
this.groupFrom = groupFrom; this.groupFrom = groupFrom;
this.groupTo = groupTo; this.groupTo = groupTo;
this.source = source;
} }
@Nonnull @Nonnull
@ -80,9 +84,20 @@ public class EventUserDemote extends AbstractEvent implements UserDemoteEvent {
return Optional.ofNullable(this.groupTo); return Optional.ofNullable(this.groupTo);
} }
@Nonnull
@Override
public Source getSource() {
return this.source;
}
@Override @Override
public String toString() { public String toString() {
return "EventUserDemote(track=" + this.track + ", user=" + this.user + ", groupFrom=" + this.getGroupFrom() + ", groupTo=" + this.getGroupTo() + ")"; return "UserDemoteEvent(" +
"track=" + this.track + ", " +
"user=" + this.user + ", " +
"groupFrom=" + this.getGroupFrom() + ", " +
"groupTo=" + this.getGroupTo() + ", " +
"source=" + this.getSource() + ")";
} }
} }

View File

@ -56,6 +56,6 @@ public class EventUserFirstLogin extends AbstractEvent implements UserFirstLogin
@Override @Override
public String toString() { public String toString() {
return "EventUserFirstLogin(uuid=" + this.getUuid() + ", username=" + this.getUsername() + ")"; return "UserFirstLoginEvent(uuid=" + this.getUuid() + ", username=" + this.getUsername() + ")";
} }
} }

View File

@ -47,6 +47,6 @@ public class EventUserLoad extends AbstractEvent implements UserLoadEvent {
@Override @Override
public String toString() { public String toString() {
return "EventUserLoad(user=" + this.getUser() + ")"; return "UserLoadEvent(user=" + this.getUser() + ")";
} }
} }

View File

@ -64,6 +64,6 @@ public class EventUserLoginProcess extends AbstractEvent implements UserLoginPro
@Override @Override
public String toString() { public String toString() {
return "EventUserLoginProcess(uuid=" + this.getUuid() + ", username=" + this.getUsername() + ", user=" + this.getUser() + ")"; return "UserLoginProcessEvent(uuid=" + this.getUuid() + ", username=" + this.getUsername() + ", user=" + this.getUser() + ")";
} }
} }

View File

@ -27,6 +27,7 @@ package me.lucko.luckperms.common.event.impl;
import me.lucko.luckperms.api.Track; import me.lucko.luckperms.api.Track;
import me.lucko.luckperms.api.User; import me.lucko.luckperms.api.User;
import me.lucko.luckperms.api.event.source.Source;
import me.lucko.luckperms.api.event.user.track.TrackAction; import me.lucko.luckperms.api.event.user.track.TrackAction;
import me.lucko.luckperms.api.event.user.track.UserPromoteEvent; import me.lucko.luckperms.api.event.user.track.UserPromoteEvent;
import me.lucko.luckperms.common.event.AbstractEvent; import me.lucko.luckperms.common.event.AbstractEvent;
@ -43,11 +44,14 @@ public class EventUserPromote extends AbstractEvent implements UserPromoteEvent
private final String groupFrom; private final String groupFrom;
private final String groupTo; private final String groupTo;
public EventUserPromote(Track track, User user, String groupFrom, String groupTo) { private final Source source;
public EventUserPromote(Track track, User user, String groupFrom, String groupTo, Source source) {
this.track = track; this.track = track;
this.user = user; this.user = user;
this.groupFrom = groupFrom; this.groupFrom = groupFrom;
this.groupTo = groupTo; this.groupTo = groupTo;
this.source = source;
} }
@Nonnull @Nonnull
@ -80,9 +84,20 @@ public class EventUserPromote extends AbstractEvent implements UserPromoteEvent
return Optional.ofNullable(this.groupTo); return Optional.ofNullable(this.groupTo);
} }
@Nonnull
@Override
public Source getSource() {
return this.source;
}
@Override @Override
public String toString() { public String toString() {
return "EventUserPromote(track=" + this.track + ", user=" + this.user + ", groupFrom=" + this.getGroupFrom() + ", groupTo=" + this.getGroupTo() + ")"; return "UserPromoteEvent(" +
"track=" + this.track + ", " +
"user=" + this.user + ", " +
"groupFrom=" + this.getGroupFrom() + ", " +
"groupTo=" + this.getGroupTo() + ", " +
"source=" + this.getSource() + ")";
} }
} }

View File

@ -0,0 +1,72 @@
/*
* 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.event.model;
import me.lucko.luckperms.api.Entity;
import me.lucko.luckperms.common.commands.sender.Sender;
import java.util.UUID;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class EntitySender implements Entity {
private final Sender sender;
public EntitySender(Sender sender) {
this.sender = sender;
}
@Nullable
@Override
public UUID getUniqueId() {
if (this.sender.isConsole()) {
return null;
}
return this.sender.getUuid();
}
@Nonnull
@Override
public String getName() {
return this.sender.getName();
}
@Nonnull
@Override
public Type getType() {
if (this.sender.isConsole()) {
return Type.CONSOLE;
} else {
return Type.PLAYER;
}
}
@Override
public String toString() {
return "Sender(type=" + getType() + ", sender=" + this.sender + ")";
}
}

View File

@ -0,0 +1,56 @@
/*
* 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.event.model;
import me.lucko.luckperms.api.Entity;
import me.lucko.luckperms.api.event.source.EntitySource;
import javax.annotation.Nonnull;
public class SourceEntity implements EntitySource {
private final Entity entity;
public SourceEntity(Entity entity) {
this.entity = entity;
}
@Nonnull
@Override
public Entity getEntity() {
return this.entity;
}
@Nonnull
@Override
public Type getType() {
return Type.ENTITY;
}
@Override
public String toString() {
return "Sender(type=ENTITY, entity=" + this.entity + ")";
}
}

View File

@ -0,0 +1,49 @@
/*
* 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.event.model;
import me.lucko.luckperms.api.event.source.Source;
import javax.annotation.Nonnull;
public final class SourceUnknown implements Source {
private static final Source INSTANCE = new SourceUnknown();
private SourceUnknown() {
}
@Nonnull
@Override
public Type getType() {
return Type.UNKNOWN;
}
@Override
public String toString() {
return "Source(type=UNKNOWN)";
}
}