From a992cfc04be8f330f669923360199b7b57a49e35 Mon Sep 17 00:00:00 2001 From: Petr Ilin Date: Fri, 25 Mar 2022 18:12:16 +0300 Subject: Events implementation --- .../limboauth/event/PostAuthorizationEvent.java | 27 +++++++++++ .../net/elytrium/limboauth/event/PostEvent.java | 42 +++++++++++++++++ .../limboauth/event/PostRegisterEvent.java | 27 +++++++++++ .../limboauth/event/PreAuthorizationEvent.java | 34 ++++++++++++++ .../net/elytrium/limboauth/event/PreEvent.java | 33 ++++++++++++++ .../elytrium/limboauth/event/PreRegisterEvent.java | 26 +++++++++++ .../net/elytrium/limboauth/event/TaskEvent.java | 53 ++++++++++++++++++++++ 7 files changed, 242 insertions(+) create mode 100644 src/main/java/net/elytrium/limboauth/event/PostAuthorizationEvent.java create mode 100644 src/main/java/net/elytrium/limboauth/event/PostEvent.java create mode 100644 src/main/java/net/elytrium/limboauth/event/PostRegisterEvent.java create mode 100644 src/main/java/net/elytrium/limboauth/event/PreAuthorizationEvent.java create mode 100644 src/main/java/net/elytrium/limboauth/event/PreEvent.java create mode 100644 src/main/java/net/elytrium/limboauth/event/PreRegisterEvent.java create mode 100644 src/main/java/net/elytrium/limboauth/event/TaskEvent.java (limited to 'src/main/java/net/elytrium/limboauth/event') diff --git a/src/main/java/net/elytrium/limboauth/event/PostAuthorizationEvent.java b/src/main/java/net/elytrium/limboauth/event/PostAuthorizationEvent.java new file mode 100644 index 0000000..cd13c73 --- /dev/null +++ b/src/main/java/net/elytrium/limboauth/event/PostAuthorizationEvent.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2021 Elytrium + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package net.elytrium.limboauth.event; + +import net.elytrium.limboapi.api.player.LimboPlayer; +import net.elytrium.limboauth.model.RegisteredPlayer; + +public class PostAuthorizationEvent extends PostEvent { + public PostAuthorizationEvent(LimboPlayer player, RegisteredPlayer playerInfo) { + super(player, playerInfo); + } +} diff --git a/src/main/java/net/elytrium/limboauth/event/PostEvent.java b/src/main/java/net/elytrium/limboauth/event/PostEvent.java new file mode 100644 index 0000000..e86fbcf --- /dev/null +++ b/src/main/java/net/elytrium/limboauth/event/PostEvent.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2021 Elytrium + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package net.elytrium.limboauth.event; + +import net.elytrium.limboapi.api.player.LimboPlayer; +import net.elytrium.limboauth.model.RegisteredPlayer; + +public abstract class PostEvent extends TaskEvent { + + private final LimboPlayer player; + private final RegisteredPlayer playerInfo; + + protected PostEvent(LimboPlayer player, RegisteredPlayer playerInfo) { + super(); + + this.player = player; + this.playerInfo = playerInfo; + } + + public RegisteredPlayer getPlayerInfo() { + return this.playerInfo; + } + + public LimboPlayer getPlayer() { + return this.player; + } +} diff --git a/src/main/java/net/elytrium/limboauth/event/PostRegisterEvent.java b/src/main/java/net/elytrium/limboauth/event/PostRegisterEvent.java new file mode 100644 index 0000000..df2fd2a --- /dev/null +++ b/src/main/java/net/elytrium/limboauth/event/PostRegisterEvent.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2021 Elytrium + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package net.elytrium.limboauth.event; + +import net.elytrium.limboapi.api.player.LimboPlayer; +import net.elytrium.limboauth.model.RegisteredPlayer; + +public class PostRegisterEvent extends PostEvent { + public PostRegisterEvent(LimboPlayer player, RegisteredPlayer playerInfo) { + super(player, playerInfo); + } +} diff --git a/src/main/java/net/elytrium/limboauth/event/PreAuthorizationEvent.java b/src/main/java/net/elytrium/limboauth/event/PreAuthorizationEvent.java new file mode 100644 index 0000000..d8e4dc7 --- /dev/null +++ b/src/main/java/net/elytrium/limboauth/event/PreAuthorizationEvent.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2021 Elytrium + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package net.elytrium.limboauth.event; + +import com.velocitypowered.api.proxy.Player; +import net.elytrium.limboauth.model.RegisteredPlayer; + +public class PreAuthorizationEvent extends PreEvent { + private final RegisteredPlayer playerInfo; + + public PreAuthorizationEvent(Player player, RegisteredPlayer playerInfo) { + super(player); + this.playerInfo = playerInfo; + } + + public RegisteredPlayer getPlayerInfo() { + return this.playerInfo; + } +} diff --git a/src/main/java/net/elytrium/limboauth/event/PreEvent.java b/src/main/java/net/elytrium/limboauth/event/PreEvent.java new file mode 100644 index 0000000..08f9b6b --- /dev/null +++ b/src/main/java/net/elytrium/limboauth/event/PreEvent.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2021 Elytrium + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package net.elytrium.limboauth.event; + +import com.velocitypowered.api.proxy.Player; + +public abstract class PreEvent extends TaskEvent { + private final Player player; + + protected PreEvent(Player player) { + super(); + this.player = player; + } + + public Player getPlayer() { + return this.player; + } +} diff --git a/src/main/java/net/elytrium/limboauth/event/PreRegisterEvent.java b/src/main/java/net/elytrium/limboauth/event/PreRegisterEvent.java new file mode 100644 index 0000000..8f642d3 --- /dev/null +++ b/src/main/java/net/elytrium/limboauth/event/PreRegisterEvent.java @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2021 Elytrium + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package net.elytrium.limboauth.event; + +import com.velocitypowered.api.proxy.Player; + +public class PreRegisterEvent extends PreEvent { + public PreRegisterEvent(Player player) { + super(player); + } +} diff --git a/src/main/java/net/elytrium/limboauth/event/TaskEvent.java b/src/main/java/net/elytrium/limboauth/event/TaskEvent.java new file mode 100644 index 0000000..4df70c8 --- /dev/null +++ b/src/main/java/net/elytrium/limboauth/event/TaskEvent.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2021 Elytrium + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package net.elytrium.limboauth.event; + +import net.elytrium.limboauth.Settings; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import org.jetbrains.annotations.NotNull; + +public abstract class TaskEvent { + private static final Component defaultReason + = LegacyComponentSerializer.legacyAmpersand().deserialize(Settings.IMP.MAIN.STRINGS.EVENT_CANCELLED); + private Result result = Result.NORMAL; + private Component reason = defaultReason; + + public Result getResult() { + return this.result; + } + + public void setResult(@NotNull Result result) { + this.result = result; + } + + public void cancel(@NotNull Component reason) { + this.result = Result.CANCEL; + this.reason = reason; + } + + public Component getReason() { + return this.reason; + } + + public enum Result { + CANCEL, + BYPASS, + NORMAL + } +} -- cgit