Add source to UserPromote & UserDemote events (#722)

This commit is contained in:
Luck
2018-02-01 21:33:32 +00:00
Unverified
parent a1a2e189b6
commit 31df29194b
45 changed files with 570 additions and 126 deletions
@@ -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
}
}
@@ -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();
}
@@ -25,13 +25,11 @@
package me.lucko.luckperms.api.event.log;
import me.lucko.luckperms.api.Entity;
import me.lucko.luckperms.api.LogEntry;
import me.lucko.luckperms.api.event.Cancellable;
import me.lucko.luckperms.api.event.LuckPermsEvent;
import java.util.Optional;
import java.util.UUID;
import javax.annotation.Nonnull;
/**
@@ -60,7 +58,7 @@ public interface LogNotifyEvent extends LuckPermsEvent, Cancellable {
* @return the origin of the log
*/
@Nonnull
LogBroadcastEvent.Origin getOrigin();
Origin getOrigin();
/**
* Gets the object to be notified.
@@ -68,46 +66,27 @@ public interface LogNotifyEvent extends LuckPermsEvent, Cancellable {
* @return the object to notify
*/
@Nonnull
Notifiable getNotifiable();
Entity getNotifiable();
/**
* Represents an object which could be notified as a result of a
* {@link LogNotifyEvent}.
* Represents where a log entry is from
*/
interface Notifiable {
enum Origin {
/**
* Gets a {@link UUID} for the object, if it has one.
*
* <p>For Players, this method returns their unique id.</p>
*
* @return the uuid of the object, if available
* Marks a log entry which originated from the current server instance
*/
@Nonnull
Optional<UUID> getUuid();
LOCAL,
/**
* Gets the name of the object
*
* @return the name
* Marks a log entry which originated from an API call on the current server instance
*/
@Nonnull
String getName();
LOCAL_API,
/**
* Gets if the object is a console
*
* @return if the object is a console
* Marks a log entry which was sent to this server via the messaging service
*/
boolean isConsole();
/**
* Gets if the object is a player
*
* @return if the object is a player
*/
boolean isPlayer();
REMOTE
}
}
@@ -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();
}
@@ -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
}
}
@@ -28,6 +28,7 @@ package me.lucko.luckperms.api.event.user.track;
import me.lucko.luckperms.api.Track;
import me.lucko.luckperms.api.User;
import me.lucko.luckperms.api.event.LuckPermsEvent;
import me.lucko.luckperms.api.event.Sourced;
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
*/
public interface UserTrackEvent extends LuckPermsEvent {
public interface UserTrackEvent extends LuckPermsEvent, Sourced {
/**
* Gets the track involved in the event