-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
70c5c7b
commit 4ce367e
Showing
14 changed files
with
388 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.vcmi.commands; | ||
|
||
import com.vcmi.VCMI; | ||
import com.vcmi.config.Lang; | ||
import com.velocitypowered.api.command.CommandSource; | ||
import com.velocitypowered.api.command.SimpleCommand; | ||
import com.velocitypowered.api.proxy.Player; | ||
import com.velocitypowered.api.proxy.server.RegisteredServer; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
public class PlayerSendCommand implements SimpleCommand { | ||
@Override | ||
public void execute(Invocation invocation) { | ||
CommandSource source = invocation.source(); | ||
if (!hasPermission(invocation)) { | ||
source.sendMessage(Lang.no_perms.get()); | ||
return; | ||
} | ||
String[] args = invocation.arguments(); | ||
if (args.length < 2) { | ||
source.sendMessage(Lang.send_usage.get()); | ||
return; | ||
} | ||
|
||
Optional<RegisteredServer> toServer = VCMI.server.getServer(args[1]); | ||
if (toServer.isEmpty()) { | ||
source.sendMessage(Lang.server_not_found.replace("{server}", args[1])); | ||
return; | ||
} | ||
|
||
if (args[0].equals("all")) { | ||
for (Player p : VCMI.server.getAllPlayers()) { | ||
p.createConnectionRequest(toServer.get()).fireAndForget(); | ||
} | ||
source.sendMessage(Lang.send_success.replace("{player}", "all", "{server}", args[1])); | ||
return; | ||
} | ||
|
||
Optional<Player> player = VCMI.server.getPlayer(args[0]); | ||
if (player.isEmpty()) { | ||
source.sendMessage(Lang.player_not_found.replace("{player}", args[0])); | ||
return; | ||
} | ||
|
||
player.get().createConnectionRequest(toServer.get()).fireAndForget(); | ||
source.sendMessage(Lang.send_success.replace("{player}", args[0], "{server}", args[1])); | ||
} | ||
|
||
@Override | ||
public CompletableFuture<List<String>> suggestAsync(Invocation invocation) { | ||
ArrayList<String> args = new ArrayList<>(); | ||
int argNum = invocation.arguments().length; | ||
if (argNum == 0 || argNum == 1) { | ||
args.add("all"); | ||
for (Player player : VCMI.server.getAllPlayers()) { | ||
args.add(player.getUsername().trim()); | ||
} | ||
} | ||
if (argNum == 2) { | ||
VCMI.server.getAllServers().forEach(serverConnection -> args.add(serverConnection.getServerInfo().getName())); | ||
} | ||
return CompletableFuture.completedFuture(args); | ||
} | ||
|
||
@Override | ||
public boolean hasPermission(Invocation invocation) { | ||
return invocation.source().hasPermission("vcmi.send.player"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.vcmi.config.data; | ||
|
||
import com.vcmi.Message; | ||
import com.vcmi.VCMI; | ||
import org.simpleyaml.configuration.file.YamlConfiguration; | ||
import org.simpleyaml.configuration.file.YamlFile; | ||
|
||
import java.io.File; | ||
|
||
public class ChatYAML { | ||
private static final String FILE_PATH = VCMI.pluginPath + File.separator + "chats.yml"; | ||
private static YamlFile yamlFile; | ||
|
||
private ChatYAML() { | ||
throw new IllegalStateException("Utility class"); | ||
} | ||
|
||
public static void reload() { | ||
try { | ||
yamlFile = new YamlFile(FILE_PATH); | ||
if (!yamlFile.exists()) { | ||
yamlFile.createNewFile(true); | ||
} | ||
yamlFile.load(); | ||
|
||
yamlFile.setHeader( | ||
"Chat Manager \n" + "Placeholders: {player}, {server}, {message}" | ||
); | ||
|
||
yamlFile.setComment("global", "Global chat"); | ||
setConfigValue("global.enabled", true); | ||
setConfigValue("global.alias", "!"); | ||
setConfigValue("global.command", "g"); | ||
setConfigValue("global.permission", "vcmi.chat.global"); | ||
setConfigValue("global.see_all", true); | ||
setConfigValue("global.format", "&8[&6G&8] &a{player} &6=> &f{message}"); | ||
|
||
yamlFile.setComment("staff", "Staff chat"); | ||
setConfigValue("staff.enabled", true); | ||
setConfigValue("staff.alias", "@"); | ||
setConfigValue("staff.command", "s"); | ||
setConfigValue("staff.permission", "vcmi.chat.staff"); | ||
setConfigValue("global.see_all", false); | ||
setConfigValue("staff.format", "&8&l[&4&lS&8&l] &b&l{server} &a&l{player} &6&l=> &f&l{message}"); | ||
|
||
yamlFile.setComment("alert", "Alert chat"); | ||
setConfigValue("alert.enabled", true); | ||
setConfigValue("alert.alias", ""); | ||
setConfigValue("alert.command", "alert"); | ||
yamlFile.setComment("alert.permission", "If empty, everyone can use this chat and see the messages"); | ||
setConfigValue("alert.permission", ""); | ||
setConfigValue("alert.see_all", true); | ||
setConfigValue("alert.format", "&8[&4ALERT&8] &f{message}"); | ||
|
||
yamlFile.save(); | ||
} catch (Exception e) { | ||
Message.error(e.getMessage()); | ||
} | ||
} | ||
|
||
private static void setConfigValue(String path, Object defaultValue) { | ||
if (!yamlFile.contains(path)) { | ||
yamlFile.set(path, defaultValue); | ||
} | ||
} | ||
|
||
public static YamlConfiguration getReloadedFile() { | ||
reload(); | ||
return new YamlConfiguration(yamlFile); | ||
} | ||
|
||
public static YamlConfiguration getConfig() { | ||
return new YamlConfiguration(yamlFile); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.