aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorPetr Ilin <hevav@hevav.dev>2022-03-25 18:12:16 +0300
committerPetr Ilin <hevav@hevav.dev>2022-03-25 18:32:05 +0300
commita992cfc04be8f330f669923360199b7b57a49e35 (patch)
tree19ce4f06ea28f1be49efb05bee8698b26e709471 /src/main
parentef636472638b0aec8b7f56fbd3a22943aaa2a47a (diff)
downloadLimboAuth-a992cfc04be8f330f669923360199b7b57a49e35.tar.gz
LimboAuth-a992cfc04be8f330f669923360199b7b57a49e35.tar.bz2
LimboAuth-a992cfc04be8f330f669923360199b7b57a49e35.zip
Events implementation
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/net/elytrium/limboauth/LimboAuth.java12
-rw-r--r--src/main/java/net/elytrium/limboauth/Settings.java6
-rw-r--r--src/main/java/net/elytrium/limboauth/event/PostAuthorizationEvent.java27
-rw-r--r--src/main/java/net/elytrium/limboauth/event/PostEvent.java42
-rw-r--r--src/main/java/net/elytrium/limboauth/event/PostRegisterEvent.java27
-rw-r--r--src/main/java/net/elytrium/limboauth/event/PreAuthorizationEvent.java34
-rw-r--r--src/main/java/net/elytrium/limboauth/event/PreEvent.java33
-rw-r--r--src/main/java/net/elytrium/limboauth/event/PreRegisterEvent.java26
-rw-r--r--src/main/java/net/elytrium/limboauth/event/TaskEvent.java53
-rw-r--r--src/main/java/net/elytrium/limboauth/handler/AuthSessionHandler.java23
10 files changed, 278 insertions, 5 deletions
diff --git a/src/main/java/net/elytrium/limboauth/LimboAuth.java b/src/main/java/net/elytrium/limboauth/LimboAuth.java
index 15b2222..8a471ca 100644
--- a/src/main/java/net/elytrium/limboauth/LimboAuth.java
+++ b/src/main/java/net/elytrium/limboauth/LimboAuth.java
@@ -80,6 +80,8 @@ import net.elytrium.limboauth.command.LimboAuthCommand;
import net.elytrium.limboauth.command.PremiumCommand;
import net.elytrium.limboauth.command.TotpCommand;
import net.elytrium.limboauth.command.UnregisterCommand;
+import net.elytrium.limboauth.event.PreAuthorizationEvent;
+import net.elytrium.limboauth.event.PreRegisterEvent;
import net.elytrium.limboauth.floodgate.FloodgateApiHolder;
import net.elytrium.limboauth.handler.AuthSessionHandler;
import net.elytrium.limboauth.listener.AuthListener;
@@ -416,6 +418,16 @@ public class LimboAuth {
}
}
+ if (registeredPlayer == null) {
+ this.server.getEventManager().fire(new PreRegisterEvent(player)).thenAcceptAsync((event)
+ -> this.sendPlayer(event.getPlayer(), null));
+ } else {
+ this.server.getEventManager().fire(new PreAuthorizationEvent(player, registeredPlayer)).thenAcceptAsync((event)
+ -> this.sendPlayer(event.getPlayer(), event.getPlayerInfo()));
+ }
+ }
+
+ private void sendPlayer(Player player, RegisteredPlayer registeredPlayer) {
// Send player to auth virtual server.
try {
this.authServer.spawnPlayer(player, new AuthSessionHandler(this.playerDao, player, this, registeredPlayer));
diff --git a/src/main/java/net/elytrium/limboauth/Settings.java b/src/main/java/net/elytrium/limboauth/Settings.java
index 5ce38ab..825ce61 100644
--- a/src/main/java/net/elytrium/limboauth/Settings.java
+++ b/src/main/java/net/elytrium/limboauth/Settings.java
@@ -134,7 +134,7 @@ public class Settings extends Config {
public boolean CLEAR_AFTER_LOGIN = false;
public Title.Times toTimes() {
- return Title.Times.of(Ticks.duration(this.FADE_IN), Ticks.duration(this.STAY), Ticks.duration(this.FADE_OUT));
+ return Title.Times.times(Ticks.duration(this.FADE_IN), Ticks.duration(this.STAY), Ticks.duration(this.FADE_OUT));
}
}
@@ -149,7 +149,7 @@ public class Settings extends Config {
public int FADE_OUT = 20;
public Title.Times toTimes() {
- return Title.Times.of(Ticks.duration(this.FADE_IN), Ticks.duration(this.STAY), Ticks.duration(this.FADE_OUT));
+ return Title.Times.times(Ticks.duration(this.FADE_IN), Ticks.duration(this.STAY), Ticks.duration(this.FADE_OUT));
}
}
@@ -240,6 +240,8 @@ public class Settings extends Config {
public String NOT_PREMIUM = "{PRFX} &cYour account is not &6PREMIUM&c!";
public String PREMIUM_USAGE = "{PRFX} Usage: &6/premium <current password> confirm";
+ public String EVENT_CANCELLED = "{PRFX} Authorization event was cancelled";
+
public String FORCE_UNREGISTER_SUCCESSFUL = "{PRFX} &6{0} &asuccessfully unregistered!";
public String FORCE_UNREGISTER_KICK = "{PRFX}{NL}&aYou have been unregistered by administrator!";
public String FORCE_UNREGISTER_NOT_SUCCESSFUL = "{PRFX} &cUnable to unregister &6{0}&c. Most likely this player has never been on this server.";
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 <http://www.gnu.org/licenses/>.
+ */
+
+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 <http://www.gnu.org/licenses/>.
+ */
+
+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 <http://www.gnu.org/licenses/>.
+ */
+
+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 <http://www.gnu.org/licenses/>.
+ */
+
+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 <http://www.gnu.org/licenses/>.
+ */
+
+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 <http://www.gnu.org/licenses/>.
+ */
+
+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 <http://www.gnu.org/licenses/>.
+ */
+
+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
+ }
+}
diff --git a/src/main/java/net/elytrium/limboauth/handler/AuthSessionHandler.java b/src/main/java/net/elytrium/limboauth/handler/AuthSessionHandler.java
index c4c4587..03f9d5f 100644
--- a/src/main/java/net/elytrium/limboauth/handler/AuthSessionHandler.java
+++ b/src/main/java/net/elytrium/limboauth/handler/AuthSessionHandler.java
@@ -38,6 +38,10 @@ import net.elytrium.limboapi.api.LimboSessionHandler;
import net.elytrium.limboapi.api.player.LimboPlayer;
import net.elytrium.limboauth.LimboAuth;
import net.elytrium.limboauth.Settings;
+import net.elytrium.limboauth.event.PostAuthorizationEvent;
+import net.elytrium.limboauth.event.PostEvent;
+import net.elytrium.limboauth.event.PostRegisterEvent;
+import net.elytrium.limboauth.event.TaskEvent;
import net.elytrium.limboauth.migration.MigrationHash;
import net.elytrium.limboauth.model.RegisteredPlayer;
import net.kyori.adventure.bossbar.BossBar;
@@ -128,7 +132,7 @@ public class AuthSessionHandler implements LimboSessionHandler {
)
);
}
- this.finishAuth();
+ this.finishRegister();
}
} else {
this.sendMessage(false);
@@ -313,14 +317,27 @@ public class AuthSessionHandler implements LimboSessionHandler {
)
);
}
- this.finishAuth();
+
+ this.plugin.getServer().getEventManager()
+ .fire(new PostAuthorizationEvent(this.player, this.playerInfo))
+ .thenAcceptAsync(this::finishAuth);
+ }
+
+ private void finishRegister() {
+ this.plugin.getServer().getEventManager()
+ .fire(new PostRegisterEvent(this.player, this.playerInfo))
+ .thenAcceptAsync(this::finishAuth);
}
- private void finishAuth() {
+ private void finishAuth(PostEvent event) {
if (Settings.IMP.MAIN.CRACKED_TITLE_SETTINGS.CLEAR_AFTER_LOGIN) {
this.proxyPlayer.clearTitle();
}
+ if (event.getResult() == TaskEvent.Result.CANCEL) {
+ this.proxyPlayer.disconnect(event.getReason());
+ }
+
this.plugin.cacheAuthUser(this.proxyPlayer);
this.player.disconnect();
}