diff --git a/api/src/main/java/org/anvilpowered/catalyst/api/data/key/CatalystKeys.java b/api/src/main/java/org/anvilpowered/catalyst/api/data/key/CatalystKeys.java index f5d2aadc..4c58e0a4 100644 --- a/api/src/main/java/org/anvilpowered/catalyst/api/data/key/CatalystKeys.java +++ b/api/src/main/java/org/anvilpowered/catalyst/api/data/key/CatalystKeys.java @@ -267,7 +267,22 @@ public final class CatalystKeys { advancedServerInfo) { }; public static final Key VIA_VERSION_ENABLED = new Key("VIA_VERSION_ENABLED", - false){ + false) { + }; + public static final Key TELEPORT_REQUEST_PERMISSION = new Key("TELEPORT_REQUEST_PERMISSION", + "catalyst.command.tpa.base") { + }; + public static final Key TELEPORT_REQUEST_HERE_PERMISSION = new Key ("TELEPORT_REQUEST_HERE_PERMISSION", + "catalyst.command.tpa.here"){ + }; + public static final Key TELEPORT_PERMISSION = new Key("TELEPORT_PERMISSION", + "catalyst.command.teleport.base"){ + }; + public static final Key TELEPORT_HERE_PERMISSION = new Key("TELEPORT_HERE_PERMISSION", + "catalyst.command.teleport.here"){ + }; + public static final Key TELEPORT_ALL_HERE_PERMISSION = new Key("TELEPORT_ALL_HERE_PERMISSION", + "catalyst.command.teleport.all"){ }; static char emojiChar = '\uac00'; @@ -378,6 +393,7 @@ public final class CatalystKeys { Keys.registerKey(EMOJI_MAP); Keys.registerKey(EMOJI_PERMISSION); Keys.registerKey(VIA_VERSION_ENABLED); + Keys.registerKey(TELEPORT_REQUEST_PERMISSION); } static { diff --git a/api/src/main/java/org/anvilpowered/catalyst/api/plugin/PluginMessages.java b/api/src/main/java/org/anvilpowered/catalyst/api/plugin/PluginMessages.java index 91a1451d..fe09b81f 100644 --- a/api/src/main/java/org/anvilpowered/catalyst/api/plugin/PluginMessages.java +++ b/api/src/main/java/org/anvilpowered/catalyst/api/plugin/PluginMessages.java @@ -57,6 +57,14 @@ public interface PluginMessages { TString getTeleportToSelf(); + TString getTeleportRequestPending(String targetUserName); + + TString getTeleportRequestAccepted(String targetUserName); + + TString getSourceAcceptedTeleport(String targetUserName); + + TString getNoPendingRequests(); + TString getIncompatibleServerVersion(); TString getExistingSwear(String swear); diff --git a/api/src/main/java/org/anvilpowered/catalyst/api/service/CrossServerTeleportationHelper.java b/api/src/main/java/org/anvilpowered/catalyst/api/service/CrossServerTeleportationHelper.java new file mode 100644 index 00000000..f897a1fe --- /dev/null +++ b/api/src/main/java/org/anvilpowered/catalyst/api/service/CrossServerTeleportationHelper.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2020 STG_Allen + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.anvilpowered.catalyst.api.service; + +import java.util.Optional; + +public interface CrossServerTeleportationHelper { + + void teleport(String sender, String recipient); + + boolean isOnSameServer(String sender, String recipient); + + void sendTeleportMessage(String serverName, String sender, String recipient); + + void insertIntoTeleportationMap(String sender, String recipient); + + Optional getRequestingPlayerName(String recipient); + + String getRecipient(String sender); + + boolean isPresentInMap(String sender); +} diff --git a/api/src/main/java/org/anvilpowered/catalyst/api/service/ExecuteCommandService.java b/api/src/main/java/org/anvilpowered/catalyst/api/service/ExecuteCommandService.java index 0288c5b0..1739e945 100644 --- a/api/src/main/java/org/anvilpowered/catalyst/api/service/ExecuteCommandService.java +++ b/api/src/main/java/org/anvilpowered/catalyst/api/service/ExecuteCommandService.java @@ -17,11 +17,13 @@ package org.anvilpowered.catalyst.api.service; +import java.util.concurrent.CompletableFuture; + public interface ExecuteCommandService { void executeCommand(TCommandSource source, String command); - void executeAsConsole(String command); + CompletableFuture executeAsConsole(String command); void executeDiscordCommand(String command); } diff --git a/bungeecord/src/main/java/org/anvilpowered/catalyst/bungee/service/BungeeExecuteCommandService.java b/bungeecord/src/main/java/org/anvilpowered/catalyst/bungee/service/BungeeExecuteCommandService.java index c2daaf01..ea77512f 100644 --- a/bungeecord/src/main/java/org/anvilpowered/catalyst/bungee/service/BungeeExecuteCommandService.java +++ b/bungeecord/src/main/java/org/anvilpowered/catalyst/bungee/service/BungeeExecuteCommandService.java @@ -23,6 +23,8 @@ import org.anvilpowered.catalyst.api.service.ExecuteCommandService; import org.anvilpowered.catalyst.bungee.discord.DiscordCommandSource; +import java.util.concurrent.CompletableFuture; + public class BungeeExecuteCommandService implements ExecuteCommandService { @Inject @@ -34,8 +36,8 @@ public void executeCommand(CommandSender commandSender, String command) { } @Override - public void executeAsConsole(String command) { - ProxyServer.getInstance().getPluginManager().dispatchCommand(ProxyServer.getInstance().getConsole(), command); + public CompletableFuture executeAsConsole(String command) { + return CompletableFuture.runAsync(() -> ProxyServer.getInstance().getPluginManager().dispatchCommand(ProxyServer.getInstance().getConsole(), command)); } @Override diff --git a/common/src/main/java/org/anvilpowered/catalyst/common/command/CommonTeleportAcceptCommand.java b/common/src/main/java/org/anvilpowered/catalyst/common/command/CommonTeleportAcceptCommand.java new file mode 100644 index 00000000..1bf68320 --- /dev/null +++ b/common/src/main/java/org/anvilpowered/catalyst/common/command/CommonTeleportAcceptCommand.java @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2020 STG_Allen + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.anvilpowered.catalyst.common.command; + +import com.google.inject.Inject; +import org.anvilpowered.anvil.api.data.registry.Registry; +import org.anvilpowered.anvil.api.util.PermissionService; +import org.anvilpowered.anvil.api.util.TextService; +import org.anvilpowered.anvil.api.util.UserService; +import org.anvilpowered.catalyst.api.data.key.CatalystKeys; +import org.anvilpowered.catalyst.api.plugin.PluginMessages; +import org.anvilpowered.catalyst.api.service.CrossServerTeleportationHelper; + +import java.util.Optional; + +public class CommonTeleportAcceptCommand< + TString, + TUser, + TPlayer, + TCommandSource, + TSubject> { + + @Inject + private TextService textService; + + @Inject + private PluginMessages pluginMessages; + + @Inject + private PermissionService permissionService; + + @Inject + private Registry registry; + + @Inject + private CrossServerTeleportationHelper teleportationHelper; + + @Inject + private UserService userService; + + public void execute(TCommandSource source, TSubject subject) { + if (permissionService.hasPermission(subject, registry.getOrDefault(CatalystKeys.TELEPORT_REQUEST_PERMISSION))) { + if (teleportationHelper.getRequestingPlayerName(userService.getUserName((TUser) source)).isPresent()) { + Optional requestingPlayerName = teleportationHelper.getRequestingPlayerName(userService.getUserName((TUser) source)); + if (userService.get(requestingPlayerName.get()).isPresent()) { + TUser requesting = userService.get(requestingPlayerName.get()).get(); + textService.send( + pluginMessages.getTeleportRequestAccepted(userService.getUserName((TUser) source)), + (TCommandSource) requesting); + textService.send( + pluginMessages.getSourceAcceptedTeleport(requestingPlayerName.get()), + source + ); + teleportationHelper.teleport(requestingPlayerName.get(), userService.getUserName((TUser) source)); + } else { + textService.send(pluginMessages.offlineOrInvalidPlayer(), source); + } + } else { + textService.send(pluginMessages.getNoPendingRequests(), source); + } + } else { + textService.send(pluginMessages.getNoPermission(), source); + } + } +} diff --git a/common/src/main/java/org/anvilpowered/catalyst/common/command/CommonTeleportAllHereCommand.java b/common/src/main/java/org/anvilpowered/catalyst/common/command/CommonTeleportAllHereCommand.java new file mode 100644 index 00000000..a22ef242 --- /dev/null +++ b/common/src/main/java/org/anvilpowered/catalyst/common/command/CommonTeleportAllHereCommand.java @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2020 STG_Allen + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.anvilpowered.catalyst.common.command; + +import com.google.inject.Inject; +import org.anvilpowered.anvil.api.data.registry.Registry; +import org.anvilpowered.anvil.api.util.PermissionService; +import org.anvilpowered.anvil.api.util.TextService; +import org.anvilpowered.anvil.api.util.UserService; +import org.anvilpowered.catalyst.api.plugin.PluginMessages; +import org.anvilpowered.catalyst.api.service.CrossServerTeleportationHelper; + +public class CommonTeleportAllHereCommand< + TString, + TUser, + TPlayer, + TCommandSource, + TSubject> { + + @Inject + private TextService textService; + + @Inject + private PluginMessages pluginMessages; + + @Inject + private PermissionService permissionService; + + @Inject + private Registry registry; + + @Inject + private CrossServerTeleportationHelper teleportationHelper; + + @Inject + private UserService userService; + + public void execute(TCommandSource source, TSubject subject) { + } +} diff --git a/common/src/main/java/org/anvilpowered/catalyst/common/command/CommonTeleportAskCommand.java b/common/src/main/java/org/anvilpowered/catalyst/common/command/CommonTeleportAskCommand.java new file mode 100644 index 00000000..3e1f8377 --- /dev/null +++ b/common/src/main/java/org/anvilpowered/catalyst/common/command/CommonTeleportAskCommand.java @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2020 STG_Allen + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.anvilpowered.catalyst.common.command; + +import com.google.inject.Inject; +import org.anvilpowered.anvil.api.data.registry.Registry; +import org.anvilpowered.anvil.api.util.PermissionService; +import org.anvilpowered.anvil.api.util.TextService; +import org.anvilpowered.anvil.api.util.UserService; +import org.anvilpowered.catalyst.api.data.key.CatalystKeys; +import org.anvilpowered.catalyst.api.plugin.PluginMessages; +import org.anvilpowered.catalyst.api.service.CrossServerTeleportationHelper; + +import java.util.Optional; + +public class CommonTeleportAskCommand< + TString, + TUser, + TPlayer, + TCommandSource, + TSubject> { + + @Inject + private TextService textService; + + @Inject + private PluginMessages pluginMessages; + + @Inject + private PermissionService permissionService; + + @Inject + private Registry registry; + + @Inject + private CrossServerTeleportationHelper teleportationHelper; + + @Inject + private UserService userService; + + public void execute(TCommandSource source, TSubject subject, String[] args) { + if (permissionService.hasPermission(subject, registry.getOrDefault(CatalystKeys.TELEPORT_REQUEST_PERMISSION))) { + if (args.length == 0) { + textService.send(pluginMessages.getNotEnoughArgs(), source); + return; + } + Optional recipient = userService.get(args[0]); + if (recipient.isPresent()) { + if (userService.getUserName(recipient.get()).equalsIgnoreCase(userService.getUserName((TUser) source))) { + textService.send(pluginMessages.getTeleportToSelf(), source); + return; + } + if (teleportationHelper.isPresentInMap(userService.getUserName((TUser) source)) + && teleportationHelper.getRecipient(userService.getUserName((TUser) source)).equalsIgnoreCase(args[0])) { + textService.send(pluginMessages.getTeleportRequestPending(args[0]), source); + } else { + //insert them into the map + //source -> recipient + teleportationHelper.insertIntoTeleportationMap(userService.getUserName((TUser) source), userService.getUserName(recipient.get())); + //Send message to target + textService.send( + pluginMessages.getTeleportRequestReceived(userService.getUserName((TUser) source)), + (TCommandSource) recipient.get()); + //Send message to source + textService.send( + pluginMessages.getTeleportRequestSent(userService.getUserName(recipient.get())), + source + ); + } + } else { + textService.send(pluginMessages.offlineOrInvalidPlayer(), source); + } + } else { + textService.send(pluginMessages.getNoPermission(), source); + } + } +} + diff --git a/common/src/main/java/org/anvilpowered/catalyst/common/command/CommonTeleportAskHereCommand.java b/common/src/main/java/org/anvilpowered/catalyst/common/command/CommonTeleportAskHereCommand.java new file mode 100644 index 00000000..d77d9964 --- /dev/null +++ b/common/src/main/java/org/anvilpowered/catalyst/common/command/CommonTeleportAskHereCommand.java @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2020 STG_Allen + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.anvilpowered.catalyst.common.command; + +import com.google.inject.Inject; +import org.anvilpowered.anvil.api.data.registry.Registry; +import org.anvilpowered.anvil.api.util.PermissionService; +import org.anvilpowered.anvil.api.util.TextService; +import org.anvilpowered.anvil.api.util.UserService; +import org.anvilpowered.catalyst.api.data.key.CatalystKeys; +import org.anvilpowered.catalyst.api.plugin.PluginMessages; +import org.anvilpowered.catalyst.api.service.CrossServerTeleportationHelper; + +import java.util.Optional; + +public class CommonTeleportAskHereCommand< + TString, + TUser, + TPlayer, + TCommandSource, + TSubject> { + + @Inject + private TextService textService; + + @Inject + private PluginMessages pluginMessages; + + @Inject + private PermissionService permissionService; + + @Inject + private Registry registry; + + @Inject + private CrossServerTeleportationHelper teleportationHelper; + + @Inject + private UserService userService; + + public void execute(TCommandSource source, TSubject subject, String[] args) { + if (permissionService.hasPermission(subject, registry.getOrDefault(CatalystKeys.TELEPORT_REQUEST_HERE_PERMISSION))) { + if (args.length == 0) { + textService.send(pluginMessages.getNotEnoughArgs(), source); + return; + } + + Optional target = userService.get(args[0]); + if (target.isPresent()) { + if (userService.getUserName(target.get()).equalsIgnoreCase(userService.getUserName((TUser) source))) { + textService.send(pluginMessages.getTeleportToSelf(), source); + return; + } + + + } else { + textService.send(pluginMessages.getNoPermission(), source); + } + } + } +} diff --git a/common/src/main/java/org/anvilpowered/catalyst/common/command/CommonTeleportCommand.java b/common/src/main/java/org/anvilpowered/catalyst/common/command/CommonTeleportCommand.java new file mode 100644 index 00000000..8721883d --- /dev/null +++ b/common/src/main/java/org/anvilpowered/catalyst/common/command/CommonTeleportCommand.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2020 STG_Allen + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.anvilpowered.catalyst.common.command; + +import com.google.inject.Inject; +import org.anvilpowered.anvil.api.data.registry.Registry; +import org.anvilpowered.anvil.api.util.PermissionService; +import org.anvilpowered.anvil.api.util.TextService; +import org.anvilpowered.anvil.api.util.UserService; +import org.anvilpowered.catalyst.api.plugin.PluginMessages; +import org.anvilpowered.catalyst.api.service.CrossServerTeleportationHelper; + +public class CommonTeleportCommand< + TString, + TUser, + TPlayer, + TCommandSource, + TSubject> { + + @Inject + private TextService textService; + + @Inject + private PluginMessages pluginMessages; + + @Inject + private PermissionService permissionService; + + @Inject + private Registry registry; + + @Inject + private CrossServerTeleportationHelper teleportationHelper; + + @Inject + private UserService userService; + + public void execute(TCommandSource source, TSubject subject) { + + } +} diff --git a/common/src/main/java/org/anvilpowered/catalyst/common/command/CommonTeleportHereCommand.java b/common/src/main/java/org/anvilpowered/catalyst/common/command/CommonTeleportHereCommand.java new file mode 100644 index 00000000..6d35197b --- /dev/null +++ b/common/src/main/java/org/anvilpowered/catalyst/common/command/CommonTeleportHereCommand.java @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2020 STG_Allen + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.anvilpowered.catalyst.common.command; + +import com.google.inject.Inject; +import org.anvilpowered.anvil.api.data.registry.Registry; +import org.anvilpowered.anvil.api.util.PermissionService; +import org.anvilpowered.anvil.api.util.TextService; +import org.anvilpowered.anvil.api.util.UserService; +import org.anvilpowered.catalyst.api.plugin.PluginMessages; +import org.anvilpowered.catalyst.api.service.CrossServerTeleportationHelper; + +public class CommonTeleportHereCommand { + + @Inject + private TextService textService; + + @Inject + private PluginMessages pluginMessages; + + @Inject + private PermissionService permissionService; + + @Inject + private Registry registry; + + @Inject + private CrossServerTeleportationHelper teleportationHelper; + + @Inject + private UserService userService; + + public void execute(TCommandSource source, TSubject subject) { + + } +} diff --git a/common/src/main/java/org/anvilpowered/catalyst/common/data/config/ProxyConfigurationService.java b/common/src/main/java/org/anvilpowered/catalyst/common/data/config/ProxyConfigurationService.java index 7629df66..f000e1b0 100644 --- a/common/src/main/java/org/anvilpowered/catalyst/common/data/config/ProxyConfigurationService.java +++ b/common/src/main/java/org/anvilpowered/catalyst/common/data/config/ProxyConfigurationService.java @@ -30,6 +30,7 @@ public class ProxyConfigurationService extends BaseConfigurationService { @Inject public ProxyConfigurationService(ConfigurationLoader configLoader) { super(configLoader); + withRedis(); setName(CatalystKeys.CHAT_FILTER_SWEARS, "chat.filter.swears"); setName(CatalystKeys.CHAT_FILTER_EXCEPTIONS, "chat.filter.exceptions"); setName(CatalystKeys.CHAT_FILTER_ENABLED, "chat.filter.enabled"); diff --git a/common/src/main/java/org/anvilpowered/catalyst/common/module/CommonModule.java b/common/src/main/java/org/anvilpowered/catalyst/common/module/CommonModule.java index b8c03479..95971b4a 100644 --- a/common/src/main/java/org/anvilpowered/catalyst/common/module/CommonModule.java +++ b/common/src/main/java/org/anvilpowered/catalyst/common/module/CommonModule.java @@ -20,7 +20,6 @@ import com.google.common.reflect.TypeToken; import com.google.inject.AbstractModule; import org.anvilpowered.anvil.api.Anvil; -import org.anvilpowered.anvil.api.data.config.ConfigurationService; import org.anvilpowered.anvil.api.data.registry.Registry; import org.anvilpowered.anvil.api.misc.BindingExtensions; import org.anvilpowered.anvil.api.plugin.BasicPluginInfo; @@ -39,6 +38,7 @@ import org.anvilpowered.catalyst.api.plugin.PluginMessages; import org.anvilpowered.catalyst.api.service.ChatFilter; import org.anvilpowered.catalyst.api.service.ChatService; +import org.anvilpowered.catalyst.api.service.CrossServerTeleportationHelper; import org.anvilpowered.catalyst.api.service.EmojiService; import org.anvilpowered.catalyst.api.service.JDAService; import org.anvilpowered.catalyst.api.service.LuckpermsService; @@ -46,7 +46,6 @@ import org.anvilpowered.catalyst.api.service.StaffChatService; import org.anvilpowered.catalyst.api.service.StaffListService; import org.anvilpowered.catalyst.api.service.TabService; -import org.anvilpowered.catalyst.common.data.config.ProxyConfigurationService; import org.anvilpowered.catalyst.common.data.registry.CatalystRegistry; import org.anvilpowered.catalyst.common.discord.CommonJDAService; import org.anvilpowered.catalyst.common.discord.CommonWebhookSender; @@ -65,6 +64,7 @@ import org.anvilpowered.catalyst.common.plugin.CommonStaffListService; import org.anvilpowered.catalyst.common.service.CommonChatFilter; import org.anvilpowered.catalyst.common.service.CommonChatService; +import org.anvilpowered.catalyst.common.service.CommonCrossServerTeleportationHelper; import org.anvilpowered.catalyst.common.service.CommonEmojiService; import org.anvilpowered.catalyst.common.service.CommonLuckpermsService; import org.anvilpowered.catalyst.common.service.CommonPrivateMessageService; @@ -206,6 +206,12 @@ protected void configure() { new TypeToken>(getClass()) { } ); + be.bind( + new TypeToken(getClass()) { + }, + new TypeToken>(getClass()) { + } + ); bind(ChatFilter.class).to(CommonChatFilter.class); bind(Registry.class).to(CatalystRegistry.class); diff --git a/common/src/main/java/org/anvilpowered/catalyst/common/plugin/Catalyst.java b/common/src/main/java/org/anvilpowered/catalyst/common/plugin/Catalyst.java index 022f2be7..4d2281eb 100644 --- a/common/src/main/java/org/anvilpowered/catalyst/common/plugin/Catalyst.java +++ b/common/src/main/java/org/anvilpowered/catalyst/common/plugin/Catalyst.java @@ -42,4 +42,9 @@ protected void whenLoaded(Environment environment) { protected void whenReady(Environment environment) { super.whenReady(environment); } + + @Override + protected void applyToBuilder(Environment.Builder builder) { + super.applyToBuilder(builder); + } } diff --git a/common/src/main/java/org/anvilpowered/catalyst/common/plugin/CatalystPluginMessages.java b/common/src/main/java/org/anvilpowered/catalyst/common/plugin/CatalystPluginMessages.java index fc75e8d4..b80d82c4 100644 --- a/common/src/main/java/org/anvilpowered/catalyst/common/plugin/CatalystPluginMessages.java +++ b/common/src/main/java/org/anvilpowered/catalyst/common/plugin/CatalystPluginMessages.java @@ -186,6 +186,38 @@ public TString getTeleportToSelf() { .build(); } + @Override + public TString getTeleportRequestPending(String targetUserName) { + return textService.builder() + .append(pluginInfo.getPrefix()) + .yellow().append("You have a pending request to " + targetUserName) + .build(); + } + + @Override + public TString getTeleportRequestAccepted(String sourceUserNamae) { + return textService.builder() + .append(pluginInfo.getPrefix()) + .green().append(sourceUserNamae + " has accepted your teleportation request.") + .build(); + } + + @Override + public TString getSourceAcceptedTeleport(String targetUserName) { + return textService.builder() + .append(pluginInfo.getPrefix()) + .green().append("Accepted " + targetUserName + "'s teleport request.") + .build(); + } + + @Override + public TString getNoPendingRequests() { + return textService.builder() + .append(pluginInfo.getPrefix()) + .yellow().append("You don't have any pending teleportation requests!") + .build(); + } + @Override public TString getIncompatibleServerVersion() { return textService.builder() diff --git a/common/src/main/java/org/anvilpowered/catalyst/common/service/CommonChatFilter.java b/common/src/main/java/org/anvilpowered/catalyst/common/service/CommonChatFilter.java index af5e2fab..e05404f5 100644 --- a/common/src/main/java/org/anvilpowered/catalyst/common/service/CommonChatFilter.java +++ b/common/src/main/java/org/anvilpowered/catalyst/common/service/CommonChatFilter.java @@ -36,9 +36,9 @@ public class CommonChatFilter implements ChatFilter { @Override public String stripMessage(String checkMessage) { return checkMessage.toLowerCase() - .replaceAll("[*()/.,;'#~^+\\-]", " ").replaceAll("[0@]", "o") - .replaceAll("1", "i").replaceAll("\\$", "s" - ); // Replaces any special characters with their letter equivalent or a space + .replaceAll("[*()/.,;'#~^+\\-]", " ").replaceAll("[0@]", "o") + .replaceAll("1", "i").replaceAll("\\$", "s" + ); // Replaces any special characters with their letter equivalent or a space } // Generates a list with the locations of all the spaces in the original message - for index replacement later @@ -60,7 +60,7 @@ public List findSpacePositions(String message, String noSpaces) { public List findSwears(String message, List spacePositions) { List swearList = new ArrayList<>(); // List of all swear word locations List exceptions = registry.getOrDefault(CatalystKeys.CHAT_FILTER_EXCEPTIONS).stream() - .map(String::toLowerCase).collect(Collectors.toList()); /* Gets exceptions from API, then, via a map, + .map(String::toLowerCase).collect(Collectors.toList()); /* Gets exceptions from API, then, via a map, makes them lowercase. */ for (String bannedWord : registry.getOrDefault(CatalystKeys.CHAT_FILTER_SWEARS)) { /* Iterates through every banned word to see if the message contains it.*/ @@ -76,7 +76,7 @@ public List findSwears(String message, List spacePositions) { int[] wordLocation = new int[]{startIndex + extraStartSpace, endIndex + extraEndSpace + 1}; swearList.add(wordLocation); } else if ((spacePositions.contains(startIndex - 1) || startIndex == 0) && - (endIndex == message.length() - 1|| spacePositions.contains(endIndex))) { + (endIndex == message.length() - 1 || spacePositions.contains(endIndex))) { if (endIndex == message.length() - 1) { extraEndSpace = spacePositions.size(); } @@ -84,7 +84,7 @@ public List findSwears(String message, List spacePositions) { int[] wordLocation = new int[]{startIndex + extraStartSpace, endIndex + extraEndSpace + 1}; swearList.add(wordLocation); } - startIndex = message.indexOf(bannedWord, startIndex+1); // checks for any more instances of the banned word + startIndex = message.indexOf(bannedWord, startIndex + 1); // checks for any more instances of the banned word } } } @@ -106,11 +106,11 @@ public String replaceSwears(String message) { */ if (swearEnd >= message.length()) { // If the swear is at the end of the message, skip adding the rest message = message.substring(0, swearStart) + // This join method adds swearLength '*'s. - String.join("", Collections.nCopies(swearLength, "*")); + String.join("", Collections.nCopies(swearLength, "*")); } else { // Add the beginning & the end of the message around the swear message = message.substring(0, swearStart) + - String.join("", Collections.nCopies(swearLength, "*")) - + message.substring(swearEnd); + String.join("", Collections.nCopies(swearLength, "*")) + + message.substring(swearEnd); } } return message; diff --git a/common/src/main/java/org/anvilpowered/catalyst/common/service/CommonCrossServerTeleportationHelper.java b/common/src/main/java/org/anvilpowered/catalyst/common/service/CommonCrossServerTeleportationHelper.java new file mode 100644 index 00000000..3006b2b3 --- /dev/null +++ b/common/src/main/java/org/anvilpowered/catalyst/common/service/CommonCrossServerTeleportationHelper.java @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2020 STG_Allen + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.anvilpowered.catalyst.common.service; + +import com.google.inject.Inject; +import com.google.inject.Singleton; +import org.anvilpowered.anvil.api.redis.RedisService; +import org.anvilpowered.anvil.api.util.CurrentServerService; +import org.anvilpowered.catalyst.api.service.CrossServerTeleportationHelper; +import org.anvilpowered.catalyst.api.service.ExecuteCommandService; + +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.atomic.AtomicReference; + +@Singleton +public class CommonCrossServerTeleportationHelper implements CrossServerTeleportationHelper { + + @Inject + private CurrentServerService currentServerService; + + @Inject + private RedisService redisService; + + @Inject + private ExecuteCommandService executeCommandService; + + public Map teleportationAcceptMap = new HashMap<>(); + + @Override + public void teleport(String sender, String recipient) { + if (currentServerService.getName(sender).isPresent() && currentServerService.getName(recipient).isPresent()) { + if (isOnSameServer(sender, recipient)) { + sendTeleportMessage(currentServerService.getName(sender).get(), sender, recipient); + } else { + sendTeleportMessage(currentServerService.getName(recipient).get(), sender, recipient); + executeCommandService.executeAsConsole("send " + sender + " " + currentServerService.getName(recipient).get()); + } + teleportationAcceptMap.remove(sender); + } + } + + @Override + public boolean isOnSameServer(String sender, String recipient) { + if (currentServerService.getName(sender).isPresent() && currentServerService.getName(recipient).isPresent()) { + return currentServerService.getName(sender).get().equalsIgnoreCase(currentServerService.getName(recipient).get()); + } + return false; + } + + @Override + public void sendTeleportMessage(String serverName, String sender, String recipient) { + CompletableFuture.runAsync(() -> { + redisService.getJedisPool().getResource().publish(serverName, "Teleport " + sender + " " + recipient); + }); + } + + @Override + public void insertIntoTeleportationMap(String sender, String recipient) { + teleportationAcceptMap.put(sender, recipient); + } + + //To be run when the player being teleported to does /tpaccept + @Override + public Optional getRequestingPlayerName(String recipient) { + AtomicReference s = new AtomicReference<>("null"); + teleportationAcceptMap.forEach((k, v) -> { + if (v.equalsIgnoreCase(recipient)) { + s.set(k); + } + }); + if(s.get().equalsIgnoreCase("null")) { + return Optional.empty(); + } + return Optional.of(s.get()); + } + + @Override + public String getRecipient(String sender) { + System.out.println(sender); + return teleportationAcceptMap.get(sender); + } + + @Override + public boolean isPresentInMap(String sender) { + return teleportationAcceptMap.containsKey(sender); + } +} diff --git a/sponge/src/main/java/org/anvilpowered/catalyst/sponge/command/CatalystSpongeCommandNode.java b/sponge/src/main/java/org/anvilpowered/catalyst/sponge/command/CatalystSpongeCommandNode.java index a49d10c9..5026adbf 100644 --- a/sponge/src/main/java/org/anvilpowered/catalyst/sponge/command/CatalystSpongeCommandNode.java +++ b/sponge/src/main/java/org/anvilpowered/catalyst/sponge/command/CatalystSpongeCommandNode.java @@ -19,26 +19,43 @@ import com.google.inject.Inject; import com.google.inject.Singleton; +import org.anvilpowered.anvil.api.Environment; +import org.anvilpowered.anvil.api.data.key.Keys; import org.anvilpowered.anvil.api.data.registry.Registry; import org.anvilpowered.anvil.api.plugin.Plugin; +import org.anvilpowered.anvil.api.redis.RedisService; import org.anvilpowered.catalyst.api.data.key.CatalystKeys; +import org.anvilpowered.catalyst.sponge.listener.SpongeJedisListener; import org.spongepowered.api.Sponge; import org.spongepowered.api.command.args.GenericArguments; import org.spongepowered.api.command.spec.CommandSpec; +import org.spongepowered.api.scheduler.Task; import org.spongepowered.api.text.Text; +import javax.inject.Named; + @Singleton public class CatalystSpongeCommandNode { @Inject private CommandSyncCommand syncCommand; + @Inject + private RedisService redisService; + @Inject private Plugin plugin; + @Inject + private SpongeJedisListener spongeJedisListener; + private Registry registry; private boolean alreadyLoaded = false; + @Inject + @Named("anvil") + Environment environment; + @Inject public CatalystSpongeCommandNode(Registry registry) { this.registry = registry; @@ -48,6 +65,10 @@ public CatalystSpongeCommandNode(Registry registry) { protected void loadCommands() { if (alreadyLoaded) return; alreadyLoaded = true; + Task.builder() + .execute(() -> redisService.getJedisPool().getResource().subscribe(spongeJedisListener, environment.getRegistry().getOrDefault(Keys.SERVER_NAME), "all")) + .async() + .submit(plugin); CommandSpec root = CommandSpec.builder() .description(Text.of("Sync commands to other servers!")) .arguments( diff --git a/sponge/src/main/java/org/anvilpowered/catalyst/sponge/data/config/SpongeConfigurationService.java b/sponge/src/main/java/org/anvilpowered/catalyst/sponge/data/config/SpongeConfigurationService.java index 7e8075cc..a943fbf2 100644 --- a/sponge/src/main/java/org/anvilpowered/catalyst/sponge/data/config/SpongeConfigurationService.java +++ b/sponge/src/main/java/org/anvilpowered/catalyst/sponge/data/config/SpongeConfigurationService.java @@ -29,6 +29,5 @@ public class SpongeConfigurationService extends BackendConfigurationService { @Inject public SpongeConfigurationService(@DefaultConfig(sharedRoot = false) ConfigurationLoader configLoader) { super(configLoader); - withRedis(); } } diff --git a/sponge/src/main/java/org/anvilpowered/catalyst/sponge/listener/SpongeJedisListener.java b/sponge/src/main/java/org/anvilpowered/catalyst/sponge/listener/SpongeJedisListener.java new file mode 100644 index 00000000..1080ddf8 --- /dev/null +++ b/sponge/src/main/java/org/anvilpowered/catalyst/sponge/listener/SpongeJedisListener.java @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2020 STG_Allen + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.anvilpowered.catalyst.sponge.listener; + +import com.google.inject.Inject; +import org.anvilpowered.anvil.api.Environment; +import org.anvilpowered.anvil.api.data.key.Keys; +import org.anvilpowered.catalyst.api.service.EventService; +import org.anvilpowered.catalyst.sponge.service.SpongeTeleportationService; +import org.slf4j.Logger; +import org.spongepowered.api.Sponge; +import org.spongepowered.api.event.Event; +import redis.clients.jedis.JedisPubSub; + +import javax.inject.Named; + +public class SpongeJedisListener extends JedisPubSub { + + @Inject + @Named("anvil") + private Environment environment; + + @Inject + private SpongeTeleportationService teleportationService; + + @Inject + private EventService eventService; + + @Inject + Logger logger; + + @Override + public void onMessage(String channel, String message) { + logger.warn(channel); + logger.warn(message); + if (environment.getRegistry().getOrDefault(Keys.SERVER_NAME).equalsIgnoreCase(channel)) { + if (message.startsWith("Teleport")) { + message = message.replace("Teleport", ""); + System.out.println(message); + String[] mess = message.split("\\s+"); + System.out.println(mess[1]); + System.out.println(Sponge.getServer().getPlayer(mess[1]).isPresent()); + System.out.println(mess[2]); + System.out.println(Sponge.getServer().getPlayer(mess[2]).isPresent()); + if (Sponge.getServer().getPlayer(mess[1]).isPresent()) { + logger.warn(""); + eventService.run(() -> teleportationService.teleport(mess[1], mess[2], true)); + } else { + eventService.run(() -> teleportationService.teleport(mess[1], mess[2], false)); + } + } + } + } +} diff --git a/sponge/src/main/java/org/anvilpowered/catalyst/sponge/listener/SpongeListener.java b/sponge/src/main/java/org/anvilpowered/catalyst/sponge/listener/SpongeListener.java new file mode 100644 index 00000000..5b0d36b5 --- /dev/null +++ b/sponge/src/main/java/org/anvilpowered/catalyst/sponge/listener/SpongeListener.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2020 STG_Allen + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.anvilpowered.catalyst.sponge.listener; + +import com.google.inject.Inject; +import org.anvilpowered.anvil.api.plugin.Plugin; +import org.anvilpowered.catalyst.sponge.service.SpongeTeleportationService; +import org.slf4j.Logger; +import org.spongepowered.api.entity.living.player.Player; +import org.spongepowered.api.event.Listener; +import org.spongepowered.api.event.network.ClientConnectionEvent; +import org.spongepowered.api.scheduler.Task; + +import java.util.concurrent.TimeUnit; + +public class SpongeListener { + + @Inject + private SpongeTeleportationService service; + + @Inject + private Plugin plugin; + + @Listener + public void onPlayerJoin(ClientConnectionEvent.Join event) { + Player player = event.getTargetEntity(); + Task.builder() + .execute(() -> { + if (service.teleportationMap.containsKey(player.getName())) { + service.teleport(player.getName(), service.teleportationMap.get(player.getName()), true); + service.teleportationMap.remove(player.getName()); + } + }) + .delay(10, TimeUnit.SECONDS) + .submit(plugin); + } + + @Listener + public void onPlayerLeave(ClientConnectionEvent.Disconnect event) { + Player player = event.getTargetEntity(); + service.teleportationMap.remove(player.getName()); + } +} diff --git a/sponge/src/main/java/org/anvilpowered/catalyst/sponge/module/SpongeModule.java b/sponge/src/main/java/org/anvilpowered/catalyst/sponge/module/SpongeModule.java index 548117a2..e0d2f24d 100644 --- a/sponge/src/main/java/org/anvilpowered/catalyst/sponge/module/SpongeModule.java +++ b/sponge/src/main/java/org/anvilpowered/catalyst/sponge/module/SpongeModule.java @@ -30,6 +30,7 @@ import org.anvilpowered.catalyst.sponge.service.SpongeEventService; import org.anvilpowered.catalyst.sponge.service.SpongeExecuteCommandService; import org.anvilpowered.catalyst.sponge.service.SpongeLoggerService; +import org.anvilpowered.catalyst.sponge.service.SpongeTeleportationService; import org.spongepowered.api.command.CommandSource; import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.entity.living.player.User; diff --git a/sponge/src/main/java/org/anvilpowered/catalyst/sponge/plugin/CatalystSponge.java b/sponge/src/main/java/org/anvilpowered/catalyst/sponge/plugin/CatalystSponge.java index 18f525f7..83bc5286 100644 --- a/sponge/src/main/java/org/anvilpowered/catalyst/sponge/plugin/CatalystSponge.java +++ b/sponge/src/main/java/org/anvilpowered/catalyst/sponge/plugin/CatalystSponge.java @@ -23,7 +23,9 @@ import org.anvilpowered.catalyst.common.plugin.Catalyst; import org.anvilpowered.catalyst.common.plugin.CatalystPluginInfo; import org.anvilpowered.catalyst.sponge.command.CatalystSpongeCommandNode; +import org.anvilpowered.catalyst.sponge.listener.SpongeListener; import org.anvilpowered.catalyst.sponge.module.SpongeModule; +import org.spongepowered.api.Sponge; import org.spongepowered.api.plugin.Dependency; import org.spongepowered.api.plugin.Plugin; import org.spongepowered.api.plugin.PluginContainer; @@ -47,4 +49,10 @@ public CatalystSponge(Injector rootInjector) { protected void whenReady(Environment environment) { super.whenReady(environment); } + + @Override + protected void applyToBuilder(Environment.Builder builder) { + builder.addEarlyServices(SpongeListener.class, t -> + Sponge.getEventManager().registerListeners(this, t)); + } } diff --git a/sponge/src/main/java/org/anvilpowered/catalyst/sponge/service/SpongeExecuteCommandService.java b/sponge/src/main/java/org/anvilpowered/catalyst/sponge/service/SpongeExecuteCommandService.java index fe709c6f..e79a4905 100644 --- a/sponge/src/main/java/org/anvilpowered/catalyst/sponge/service/SpongeExecuteCommandService.java +++ b/sponge/src/main/java/org/anvilpowered/catalyst/sponge/service/SpongeExecuteCommandService.java @@ -19,16 +19,23 @@ import com.google.inject.Inject; import org.anvilpowered.anvil.api.plugin.Plugin; +import org.anvilpowered.catalyst.api.service.EventService; import org.anvilpowered.catalyst.api.service.ExecuteCommandService; import org.spongepowered.api.Sponge; import org.spongepowered.api.command.CommandSource; +import org.spongepowered.api.event.Event; import org.spongepowered.api.scheduler.Task; +import java.util.concurrent.CompletableFuture; + public class SpongeExecuteCommandService implements ExecuteCommandService { @Inject Plugin plugin; + @Inject + private EventService eventService; + @Override public void executeCommand(CommandSource commandSource, String command) { Task.builder() @@ -39,8 +46,10 @@ public void executeCommand(CommandSource commandSource, String command) { } @Override - public void executeAsConsole(String command) { - executeCommand(Sponge.getServer().getConsole(), command); + public CompletableFuture executeAsConsole(String command) { + return CompletableFuture.runAsync(() -> { + eventService.run(() -> executeCommand(Sponge.getServer().getConsole(), command)); + }); } @Override diff --git a/sponge/src/main/java/org/anvilpowered/catalyst/sponge/service/SpongeTeleportationService.java b/sponge/src/main/java/org/anvilpowered/catalyst/sponge/service/SpongeTeleportationService.java new file mode 100644 index 00000000..788e6e02 --- /dev/null +++ b/sponge/src/main/java/org/anvilpowered/catalyst/sponge/service/SpongeTeleportationService.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2020 STG_Allen + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.anvilpowered.catalyst.sponge.service; + +import com.google.inject.Inject; +import com.google.inject.Singleton; +import org.anvilpowered.anvil.api.util.UserService; +import org.spongepowered.api.entity.living.player.Player; +import org.spongepowered.api.entity.living.player.User; + +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + +@Singleton +public class SpongeTeleportationService { + + public Map teleportationMap = new HashMap<>(); + + @Inject + private UserService userService; + + public void teleport(String sender, String recipient, boolean onSameServer) { + final Optional teleporter = userService.get(sender); + final Optional target = userService.get(recipient); + if (onSameServer && teleporter.isPresent() && target.isPresent()) { + target.flatMap(User::getWorldUniqueId) + .filter(uuid -> teleporter.get().setLocation(target.get().getPosition(), uuid)); + } else { + teleportationMap.put(sender, recipient); + } + } +} diff --git a/velocity/src/main/java/org/anvilpowered/catalyst/velocity/command/CatalystCommandManager.java b/velocity/src/main/java/org/anvilpowered/catalyst/velocity/command/CatalystCommandManager.java index b5be6a81..ed03a613 100644 --- a/velocity/src/main/java/org/anvilpowered/catalyst/velocity/command/CatalystCommandManager.java +++ b/velocity/src/main/java/org/anvilpowered/catalyst/velocity/command/CatalystCommandManager.java @@ -77,6 +77,11 @@ public class CatalystCommandManager { private ExceptionCommand exceptionCommand; @Inject private IgnoreCommand ignoreCommand; + @Inject + private TeleportAskCommand teleportRequestCommand; + + @Inject + private TeleportAcceptCommand teleportAcceptCommand; private boolean alreadyLoaded = false; @@ -136,5 +141,11 @@ public void registryLoaded() { proxyServer.getCommandManager().register( "ignore", ignoreCommand ); + proxyServer.getCommandManager().register( + "teleport", teleportRequestCommand + ); + proxyServer.getCommandManager().register( + "teleportaccept", teleportAcceptCommand + ); } } diff --git a/velocity/src/main/java/org/anvilpowered/catalyst/velocity/command/SendCommand.java b/velocity/src/main/java/org/anvilpowered/catalyst/velocity/command/SendCommand.java index 5d3dd8f9..5afb7055 100644 --- a/velocity/src/main/java/org/anvilpowered/catalyst/velocity/command/SendCommand.java +++ b/velocity/src/main/java/org/anvilpowered/catalyst/velocity/command/SendCommand.java @@ -75,7 +75,10 @@ public void execute(CommandSource source, @NonNull String[] args) { TextComponent.of(player.get().getUsername() + " is already connected to that server."))); } else { - Player sender = (Player) source; + String sender = "Console"; + if(source instanceof Player) { + sender = ((Player) source).getUsername(); + } source.sendMessage( pluginInfo.getPrefix().append( TextComponent.of("sending " + player.get().getUsername() @@ -84,7 +87,7 @@ public void execute(CommandSource source, @NonNull String[] args) { pluginInfo.getPrefix().append( TextComponent.of("you have been sent to " + server.get().getServerInfo().getName() - + " by " + sender.getUsername()))); + + " by " + sender))); player.get().createConnectionRequest(server.get()).fireAndForget(); } } else { diff --git a/velocity/src/main/java/org/anvilpowered/catalyst/velocity/command/TeleportAcceptCommand.java b/velocity/src/main/java/org/anvilpowered/catalyst/velocity/command/TeleportAcceptCommand.java new file mode 100644 index 00000000..2174be82 --- /dev/null +++ b/velocity/src/main/java/org/anvilpowered/catalyst/velocity/command/TeleportAcceptCommand.java @@ -0,0 +1,41 @@ +package org.anvilpowered.catalyst.velocity.command; + +import com.google.inject.Inject; +import com.velocitypowered.api.command.Command; +import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.permission.PermissionSubject; +import com.velocitypowered.api.proxy.Player; +import com.velocitypowered.api.proxy.ProxyServer; +import net.kyori.text.TextComponent; +import org.anvilpowered.catalyst.common.command.CommonTeleportAcceptCommand; +import org.checkerframework.checker.nullness.qual.NonNull; + +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +public class TeleportAcceptCommand extends CommonTeleportAcceptCommand< + TextComponent, + Player, + Player, + CommandSource, + PermissionSubject> +implements Command { + + @Inject + private ProxyServer proxyServer; + + @Override + public void execute(CommandSource source, @NonNull String[] args) { + execute(source, source); + } + + @Override + public List suggest(CommandSource src, String[] args) { + if (args.length == 1) { + return proxyServer.matchPlayer(args[0]) + .stream().map(Player::getUsername).collect(Collectors.toList()); + } + return Collections.emptyList(); + } +} diff --git a/velocity/src/main/java/org/anvilpowered/catalyst/velocity/command/TeleportAllHereCommand.java b/velocity/src/main/java/org/anvilpowered/catalyst/velocity/command/TeleportAllHereCommand.java new file mode 100644 index 00000000..a162b803 --- /dev/null +++ b/velocity/src/main/java/org/anvilpowered/catalyst/velocity/command/TeleportAllHereCommand.java @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2020 STG_Allen + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.anvilpowered.catalyst.velocity.command; + +public class TeleportAllHereCommand { +} diff --git a/velocity/src/main/java/org/anvilpowered/catalyst/velocity/command/TeleportAskCommand.java b/velocity/src/main/java/org/anvilpowered/catalyst/velocity/command/TeleportAskCommand.java new file mode 100644 index 00000000..8aac690a --- /dev/null +++ b/velocity/src/main/java/org/anvilpowered/catalyst/velocity/command/TeleportAskCommand.java @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2020 STG_Allen + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.anvilpowered.catalyst.velocity.command; + +import com.google.inject.Inject; +import com.velocitypowered.api.command.Command; +import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.permission.PermissionSubject; +import com.velocitypowered.api.proxy.Player; +import com.velocitypowered.api.proxy.ProxyServer; +import net.kyori.text.TextComponent; +import org.anvilpowered.catalyst.common.command.CommonTeleportAskCommand; +import org.checkerframework.checker.nullness.qual.NonNull; + +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +public class TeleportAskCommand extends CommonTeleportAskCommand implements Command { + + @Inject + private ProxyServer proxyServer; + + @Override + public void execute(CommandSource source, @NonNull String[] args) { + execute(source, source, args); + } + + @Override + public List suggest(CommandSource src, String[] args) { + if (args.length == 1) { + return proxyServer.matchPlayer(args[0]) + .stream().map(Player::getUsername).collect(Collectors.toList()); + } + return Collections.emptyList(); + } +} diff --git a/velocity/src/main/java/org/anvilpowered/catalyst/velocity/command/TeleportAskHere.java b/velocity/src/main/java/org/anvilpowered/catalyst/velocity/command/TeleportAskHere.java new file mode 100644 index 00000000..56686fd5 --- /dev/null +++ b/velocity/src/main/java/org/anvilpowered/catalyst/velocity/command/TeleportAskHere.java @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2020 STG_Allen + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.anvilpowered.catalyst.velocity.command; + +public class TeleportAskHere { +} diff --git a/velocity/src/main/java/org/anvilpowered/catalyst/velocity/command/TeleportCommand.java b/velocity/src/main/java/org/anvilpowered/catalyst/velocity/command/TeleportCommand.java new file mode 100644 index 00000000..58558d8a --- /dev/null +++ b/velocity/src/main/java/org/anvilpowered/catalyst/velocity/command/TeleportCommand.java @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2020 STG_Allen + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.anvilpowered.catalyst.velocity.command; + +public class TeleportCommand { +} diff --git a/velocity/src/main/java/org/anvilpowered/catalyst/velocity/command/TeleportHereCommand.java b/velocity/src/main/java/org/anvilpowered/catalyst/velocity/command/TeleportHereCommand.java new file mode 100644 index 00000000..91cce5b0 --- /dev/null +++ b/velocity/src/main/java/org/anvilpowered/catalyst/velocity/command/TeleportHereCommand.java @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2020 STG_Allen + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.anvilpowered.catalyst.velocity.command; + +public class TeleportHereCommand { +} diff --git a/velocity/src/main/java/org/anvilpowered/catalyst/velocity/listener/VelocityListener.java b/velocity/src/main/java/org/anvilpowered/catalyst/velocity/listener/VelocityListener.java index 5bd04a80..f51db2ff 100644 --- a/velocity/src/main/java/org/anvilpowered/catalyst/velocity/listener/VelocityListener.java +++ b/velocity/src/main/java/org/anvilpowered/catalyst/velocity/listener/VelocityListener.java @@ -250,6 +250,8 @@ public void onServerListPing(ProxyPingEvent proxyPingEvent) { if (serverPing.getFavicon().isPresent()) { builder.favicon(serverPing.getFavicon().get()); + } else if (proxyServer.getConfiguration().getFavicon().isPresent()) { + builder.favicon(proxyServer.getConfiguration().getFavicon().get()); } builder.onlinePlayers(proxyServer.getPlayerCount()); diff --git a/velocity/src/main/java/org/anvilpowered/catalyst/velocity/service/VelocityExecuteCommandService.java b/velocity/src/main/java/org/anvilpowered/catalyst/velocity/service/VelocityExecuteCommandService.java index cfcb880f..87edbe37 100644 --- a/velocity/src/main/java/org/anvilpowered/catalyst/velocity/service/VelocityExecuteCommandService.java +++ b/velocity/src/main/java/org/anvilpowered/catalyst/velocity/service/VelocityExecuteCommandService.java @@ -25,6 +25,8 @@ import org.anvilpowered.catalyst.velocity.discord.DiscordCommandSource; import org.slf4j.Logger; +import java.util.concurrent.CompletableFuture; + public class VelocityExecuteCommandService implements ExecuteCommandService { @Inject @@ -45,8 +47,11 @@ public void executeCommand(CommandSource source, String command) { } @Override - public void executeAsConsole(String command) { - proxyServer.getCommandManager().execute(proxyServer.getConsoleCommandSource(), command); + public CompletableFuture executeAsConsole(String command) { + return CompletableFuture.runAsync(() ->{ + System.out.println("Sending Command " + command); + proxyServer.getCommandManager().execute(proxyServer.getConsoleCommandSource(), command); + }); } @Override