Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,22 @@ public final class CatalystKeys {
advancedServerInfo) {
};
public static final Key<Boolean> VIA_VERSION_ENABLED = new Key<Boolean>("VIA_VERSION_ENABLED",
false){
false) {
};
public static final Key<String> TELEPORT_REQUEST_PERMISSION = new Key<String>("TELEPORT_REQUEST_PERMISSION",
"catalyst.command.tpa.base") {
};
public static final Key<String> TELEPORT_REQUEST_HERE_PERMISSION = new Key<String> ("TELEPORT_REQUEST_HERE_PERMISSION",
"catalyst.command.tpa.here"){
};
public static final Key<String> TELEPORT_PERMISSION = new Key<String>("TELEPORT_PERMISSION",
"catalyst.command.teleport.base"){
};
public static final Key<String> TELEPORT_HERE_PERMISSION = new Key<String>("TELEPORT_HERE_PERMISSION",
"catalyst.command.teleport.here"){
};
public static final Key<String> TELEPORT_ALL_HERE_PERMISSION = new Key<String>("TELEPORT_ALL_HERE_PERMISSION",
"catalyst.command.teleport.all"){
};
static char emojiChar = '\uac00';

Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ public interface PluginMessages<TString> {

TString getTeleportToSelf();

TString getTeleportRequestPending(String targetUserName);

TString getTeleportRequestAccepted(String targetUserName);

TString getSourceAcceptedTeleport(String targetUserName);

TString getNoPendingRequests();

TString getIncompatibleServerVersion();

TString getExistingSwear(String swear);
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

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<String> getRequestingPlayerName(String recipient);

String getRecipient(String sender);

boolean isPresentInMap(String sender);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@

package org.anvilpowered.catalyst.api.service;

import java.util.concurrent.CompletableFuture;

public interface ExecuteCommandService<TCommandSource> {

void executeCommand(TCommandSource source, String command);

void executeAsConsole(String command);
CompletableFuture<Void> executeAsConsole(String command);

void executeDiscordCommand(String command);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<CommandSender> {

@Inject
Expand All @@ -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<Void> executeAsConsole(String command) {
return CompletableFuture.runAsync(() -> ProxyServer.getInstance().getPluginManager().dispatchCommand(ProxyServer.getInstance().getConsole(), command));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

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<TString, TCommandSource> textService;

@Inject
private PluginMessages<TString> pluginMessages;

@Inject
private PermissionService<TSubject> permissionService;

@Inject
private Registry registry;

@Inject
private CrossServerTeleportationHelper teleportationHelper;

@Inject
private UserService<TUser, TPlayer> 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<String> 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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

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<TString, TCommandSource> textService;

@Inject
private PluginMessages<TString> pluginMessages;

@Inject
private PermissionService<TSubject> permissionService;

@Inject
private Registry registry;

@Inject
private CrossServerTeleportationHelper teleportationHelper;

@Inject
private UserService<TUser, TPlayer> userService;

public void execute(TCommandSource source, TSubject subject) {
}
}
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

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<TString, TCommandSource> textService;

@Inject
private PluginMessages<TString> pluginMessages;

@Inject
private PermissionService<TSubject> permissionService;

@Inject
private Registry registry;

@Inject
private CrossServerTeleportationHelper teleportationHelper;

@Inject
private UserService<TUser, TPlayer> 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<TUser> 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);
}
}
}

Loading