master
commit
dad3ac76e3
7 changed files with 569 additions and 0 deletions
@ -0,0 +1,113 @@ |
||||
# User-specific stuff |
||||
.idea/ |
||||
|
||||
*.iml |
||||
*.ipr |
||||
*.iws |
||||
|
||||
# IntelliJ |
||||
out/ |
||||
|
||||
# Compiled class file |
||||
*.class |
||||
|
||||
# Log file |
||||
*.log |
||||
|
||||
# BlueJ files |
||||
*.ctxt |
||||
|
||||
# Package Files # |
||||
*.jar |
||||
*.war |
||||
*.nar |
||||
*.ear |
||||
*.zip |
||||
*.tar.gz |
||||
*.rar |
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml |
||||
hs_err_pid* |
||||
|
||||
*~ |
||||
|
||||
# temporary files which can be created if a process still has a handle open of a deleted file |
||||
.fuse_hidden* |
||||
|
||||
# KDE directory preferences |
||||
.directory |
||||
|
||||
# Linux trash folder which might appear on any partition or disk |
||||
.Trash-* |
||||
|
||||
# .nfs files are created when an open file is removed but is still being accessed |
||||
.nfs* |
||||
|
||||
# General |
||||
.DS_Store |
||||
.AppleDouble |
||||
.LSOverride |
||||
|
||||
# Icon must end with two \r |
||||
Icon |
||||
|
||||
# Thumbnails |
||||
._* |
||||
|
||||
# Files that might appear in the root of a volume |
||||
.DocumentRevisions-V100 |
||||
.fseventsd |
||||
.Spotlight-V100 |
||||
.TemporaryItems |
||||
.Trashes |
||||
.VolumeIcon.icns |
||||
.com.apple.timemachine.donotpresent |
||||
|
||||
# Directories potentially created on remote AFP share |
||||
.AppleDB |
||||
.AppleDesktop |
||||
Network Trash Folder |
||||
Temporary Items |
||||
.apdisk |
||||
|
||||
# Windows thumbnail cache files |
||||
Thumbs.db |
||||
Thumbs.db:encryptable |
||||
ehthumbs.db |
||||
ehthumbs_vista.db |
||||
|
||||
# Dump file |
||||
*.stackdump |
||||
|
||||
# Folder config file |
||||
[Dd]esktop.ini |
||||
|
||||
# Recycle Bin used on file shares |
||||
$RECYCLE.BIN/ |
||||
|
||||
# Windows Installer files |
||||
*.cab |
||||
*.msi |
||||
*.msix |
||||
*.msm |
||||
*.msp |
||||
|
||||
# Windows shortcuts |
||||
*.lnk |
||||
|
||||
target/ |
||||
|
||||
pom.xml.tag |
||||
pom.xml.releaseBackup |
||||
pom.xml.versionsBackup |
||||
pom.xml.next |
||||
|
||||
release.properties |
||||
dependency-reduced-pom.xml |
||||
buildNumber.properties |
||||
.mvn/timing.properties |
||||
.mvn/wrapper/maven-wrapper.jar |
||||
.flattened-pom.xml |
||||
|
||||
# Common working directory |
||||
run/ |
||||
@ -0,0 +1,164 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
|
||||
<groupId>xyz.soukup</groupId> |
||||
<artifactId>ecocraftvelocity</artifactId> |
||||
<version>1.0-SNAPSHOT</version> |
||||
<packaging>jar</packaging> |
||||
|
||||
<name>ecocraftvelocity</name> |
||||
|
||||
<properties> |
||||
<java.version>17</java.version> |
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
||||
</properties> |
||||
|
||||
<profiles> |
||||
<profile> |
||||
<id>release</id> |
||||
<build> |
||||
<plugins> |
||||
<plugin> |
||||
<groupId>org.apache.maven.plugins</groupId> |
||||
<artifactId>maven-source-plugin</artifactId> |
||||
<version>3.3.1</version> |
||||
<executions> |
||||
<execution> |
||||
<id>attach-sources</id> |
||||
<goals> |
||||
<goal>jar-no-fork</goal> |
||||
</goals> |
||||
</execution> |
||||
</executions> |
||||
</plugin> |
||||
<plugin> |
||||
<groupId>org.apache.maven.plugins</groupId> |
||||
<artifactId>maven-javadoc-plugin</artifactId> |
||||
<version>3.6.3</version> |
||||
<executions> |
||||
<execution> |
||||
<id>attach-javadocs</id> |
||||
<goals> |
||||
<goal>jar</goal> |
||||
</goals> |
||||
</execution> |
||||
</executions> |
||||
</plugin> |
||||
<plugin> |
||||
<groupId>org.apache.maven.plugins</groupId> |
||||
<artifactId>maven-gpg-plugin</artifactId> |
||||
<version>3.2.4</version> |
||||
<executions> |
||||
<execution> |
||||
<id>sign-artifacts</id> |
||||
<phase>verify</phase> |
||||
<goals> |
||||
<goal>sign</goal> |
||||
</goals> |
||||
</execution> |
||||
</executions> |
||||
</plugin> |
||||
</plugins> |
||||
<resources> |
||||
<resource> |
||||
<directory>src/main/resources</directory> |
||||
<filtering>true</filtering> |
||||
</resource> |
||||
</resources> |
||||
</build> |
||||
</profile> |
||||
</profiles> |
||||
|
||||
<build> |
||||
<defaultGoal>clean package</defaultGoal> |
||||
<resources> |
||||
<resource> |
||||
<directory>${project.basedir}/src/main/resources</directory> |
||||
<filtering>true</filtering> |
||||
</resource> |
||||
</resources> |
||||
<plugins> |
||||
<plugin> |
||||
<groupId>org.apache.maven.plugins</groupId> |
||||
<artifactId>maven-compiler-plugin</artifactId> |
||||
<version>3.13.0</version> |
||||
<configuration> |
||||
<source>${java.version}</source> |
||||
<target>${java.version}</target> |
||||
</configuration> |
||||
</plugin> |
||||
<plugin> |
||||
<groupId>org.codehaus.mojo</groupId> |
||||
<artifactId>templating-maven-plugin</artifactId> |
||||
<version>1.0.0</version> |
||||
<executions> |
||||
<execution> |
||||
<id>filter-src</id> |
||||
<goals> |
||||
<goal>filter-sources</goal> |
||||
</goals> |
||||
</execution> |
||||
</executions> |
||||
</plugin> |
||||
<plugin> |
||||
<groupId>org.apache.maven.plugins</groupId> |
||||
<artifactId>maven-site-plugin</artifactId> |
||||
<version>3.12.1</version> |
||||
<dependencies> |
||||
<dependency> |
||||
<groupId>net.trajano.wagon</groupId> |
||||
<artifactId>wagon-git</artifactId> |
||||
<version>2.0.4</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.apache.maven.doxia</groupId> |
||||
<artifactId>doxia-module-markdown</artifactId> |
||||
<version>1.12.0</version> |
||||
</dependency> |
||||
</dependencies> |
||||
</plugin> |
||||
<plugin> |
||||
<groupId>org.apache.maven.plugins</groupId> |
||||
<artifactId>maven-release-plugin</artifactId> |
||||
<version>3.0.1</version> |
||||
<configuration> |
||||
<autoVersionSubmodules>true</autoVersionSubmodules> |
||||
<tagNameFormat>@{project.version}</tagNameFormat> |
||||
<scmCommentPrefix xml:space="preserve">[RELEASE] </scmCommentPrefix> |
||||
<goals>install deploy site-deploy |
||||
</goals> <!-- install is here to fix javadoc generation in multi-module projects --> |
||||
<releaseProfiles>release</releaseProfiles> |
||||
</configuration> |
||||
</plugin> |
||||
</plugins> |
||||
</build> |
||||
|
||||
<reporting> |
||||
<plugins> |
||||
<plugin> |
||||
<groupId>org.apache.maven.plugins</groupId> |
||||
<artifactId>maven-javadoc-plugin</artifactId> |
||||
<version>3.6.3</version> |
||||
</plugin> |
||||
</plugins> |
||||
</reporting> |
||||
|
||||
<repositories> |
||||
<repository> |
||||
<id>papermc-repo</id> |
||||
<url>https://repo.papermc.io/repository/maven-public/</url> |
||||
</repository> |
||||
</repositories> |
||||
|
||||
<dependencies> |
||||
<dependency> |
||||
<groupId>com.velocitypowered</groupId> |
||||
<artifactId>velocity-api</artifactId> |
||||
<version>3.4.0-SNAPSHOT</version> |
||||
<scope>provided</scope> |
||||
</dependency> |
||||
</dependencies> |
||||
</project> |
||||
@ -0,0 +1,52 @@ |
||||
package xyz.soukup.ecocraftVelocity; |
||||
|
||||
import com.google.inject.Inject; |
||||
import com.velocitypowered.api.command.BrigadierCommand; |
||||
import com.velocitypowered.api.command.CommandManager; |
||||
import com.velocitypowered.api.command.CommandMeta; |
||||
import com.velocitypowered.api.event.EventManager; |
||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; |
||||
import com.velocitypowered.api.event.Subscribe; |
||||
import com.velocitypowered.api.plugin.Plugin; |
||||
import com.velocitypowered.api.proxy.ProxyServer; |
||||
import org.slf4j.Logger; |
||||
import xyz.soukup.ecocraftVelocity.chat.DirectMessages; |
||||
import xyz.soukup.ecocraftVelocity.chat.GlobalChat; |
||||
import xyz.soukup.ecocraftVelocity.chat.JoinLeaveMessages; |
||||
import xyz.soukup.ecocraftVelocity.tab.GlobalTab; |
||||
|
||||
@Plugin(id = "ecocraftvelocity", name = "EcocraftVelocity", version = "1.0-SNAPSHOT") |
||||
public class EcocraftVelocity { |
||||
|
||||
@Inject |
||||
private Logger logger; |
||||
|
||||
@Inject |
||||
private ProxyServer server; |
||||
|
||||
@Subscribe |
||||
public void onProxyInitialization(ProxyInitializeEvent event) { |
||||
logger.info("Startujeme!"); |
||||
registerEvents(); |
||||
registerCommands(); |
||||
} |
||||
|
||||
private void registerEvents(){ |
||||
EventManager eventManager = server.getEventManager(); |
||||
eventManager.register(this, new GlobalChat(server)); |
||||
eventManager.register(this, new GlobalTab(server)); |
||||
eventManager.register(this, new JoinLeaveMessages(server)); |
||||
} |
||||
|
||||
private void registerCommands(){ |
||||
CommandManager commandManager = server.getCommandManager(); |
||||
|
||||
CommandMeta commandMeta = commandManager.metaBuilder("msg") |
||||
.plugin(this) |
||||
.build(); |
||||
|
||||
BrigadierCommand commandToRegister = DirectMessages.messageCommand(server); |
||||
|
||||
commandManager.register(commandMeta, commandToRegister); |
||||
} |
||||
} |
||||
@ -0,0 +1,74 @@ |
||||
package xyz.soukup.ecocraftVelocity.chat; |
||||
|
||||
import com.mojang.brigadier.Command; |
||||
import com.mojang.brigadier.arguments.StringArgumentType; |
||||
import com.mojang.brigadier.context.CommandContext; |
||||
import com.mojang.brigadier.suggestion.Suggestions; |
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder; |
||||
import com.mojang.brigadier.tree.LiteralCommandNode; |
||||
import com.velocitypowered.api.command.BrigadierCommand; |
||||
import com.velocitypowered.api.command.CommandSource; |
||||
import com.velocitypowered.api.proxy.Player; |
||||
import com.velocitypowered.api.proxy.ProxyServer; |
||||
import net.kyori.adventure.text.Component; |
||||
import net.kyori.adventure.text.minimessage.MiniMessage; |
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; |
||||
|
||||
import java.util.Optional; |
||||
import java.util.concurrent.CompletableFuture; |
||||
|
||||
public class DirectMessages { |
||||
public static BrigadierCommand messageCommand(final ProxyServer proxy) { |
||||
LiteralCommandNode<CommandSource> msg = BrigadierCommand.literalArgumentBuilder("msg") |
||||
.then(BrigadierCommand.requiredArgumentBuilder("player", StringArgumentType.word()) |
||||
.suggests((ctx, builder) -> playerSuggestor(proxy, ctx, builder)) |
||||
.then(BrigadierCommand.requiredArgumentBuilder("message", StringArgumentType.greedyString()) |
||||
.executes((ctx) -> sendDirectMessage(proxy, ctx))) |
||||
) |
||||
.build(); |
||||
|
||||
return new BrigadierCommand(msg); |
||||
} |
||||
|
||||
private static CompletableFuture<Suggestions> playerSuggestor(ProxyServer proxy, CommandContext<CommandSource> ctx, SuggestionsBuilder builder) { |
||||
proxy.getAllPlayers().forEach(player -> { |
||||
builder.suggest(player.getUsername()); |
||||
}); |
||||
builder.suggest("all"); |
||||
return builder.buildFuture(); |
||||
} |
||||
|
||||
private static int sendDirectMessage(ProxyServer proxy, CommandContext<CommandSource> context) { |
||||
String playerName = context.getArgument("player", String.class); |
||||
String message = context.getArgument("message", String.class); |
||||
MiniMessage mm = MiniMessage.miniMessage(); |
||||
|
||||
|
||||
Player sender = (Player) context.getSource(); |
||||
Optional<Player> playerOptional = proxy.getPlayer(playerName); |
||||
|
||||
if (playerOptional.isEmpty()){ |
||||
sender.sendMessage(mm.deserialize("<red>Není online.")); |
||||
return Command.SINGLE_SUCCESS; |
||||
} |
||||
|
||||
|
||||
String senderFormat = "<hover:show_text:\"<yellow><bold><name></bold><br><white>Klikni pro odepsání\"><click:suggest_command:\"/msg " + playerName + " \">" + |
||||
"<blue>já <white><bold>▶ </bold><blue><name></click></hover>" + |
||||
"<gray>: <white><msg>"; |
||||
|
||||
|
||||
|
||||
sender.sendMessage(mm.deserialize(senderFormat, Placeholder.unparsed("msg", message), Placeholder.unparsed("name", playerName))); |
||||
|
||||
proxy.getPlayer(playerName).ifPresent(player -> |
||||
{ |
||||
String receiverFormat = "<hover:show_text:\"<yellow><bold><name></bold><br><white>Klikni pro odepsání\"><click:suggest_command:\"/msg " + sender.getUsername() + " \">" + |
||||
"<blue><name> <white><bold>▶ </bold><blue>já</click></hover>" + |
||||
"<gray>: <white><msg>"; |
||||
player.sendMessage(mm.deserialize(receiverFormat, Placeholder.unparsed("msg", message), Placeholder.unparsed("name", sender.getUsername()))); |
||||
} |
||||
); |
||||
return Command.SINGLE_SUCCESS; |
||||
} |
||||
} |
||||
@ -0,0 +1,50 @@ |
||||
package xyz.soukup.ecocraftVelocity.chat; |
||||
|
||||
import com.velocitypowered.api.event.Subscribe; |
||||
import com.velocitypowered.api.event.player.PlayerChatEvent; |
||||
import com.velocitypowered.api.proxy.Player; |
||||
import com.velocitypowered.api.proxy.ProxyServer; |
||||
import net.kyori.adventure.text.Component; |
||||
import net.kyori.adventure.text.minimessage.MiniMessage; |
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; |
||||
|
||||
public class GlobalChat { |
||||
|
||||
private final ProxyServer server; |
||||
private final MiniMessage miniMessage = MiniMessage.miniMessage(); |
||||
|
||||
public GlobalChat(ProxyServer server){ |
||||
this.server = server; |
||||
} |
||||
|
||||
@Subscribe |
||||
public void onChat(PlayerChatEvent event){ |
||||
//noinspection deprecation
|
||||
event.setResult(PlayerChatEvent.ChatResult.denied()); |
||||
|
||||
String message = event.getMessage(); |
||||
Player player = event.getPlayer(); |
||||
|
||||
server.sendMessage(prepareMessageComponent(message, player)); |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} |
||||
|
||||
private static Component prepareMessageComponent(String text, Player player){ |
||||
final MiniMessage miniMessage = MiniMessage.miniMessage(); |
||||
|
||||
String format = "<hover:show_text:'<yellow><bold><name><br><white>Klikni pro napsání hráči'><click:suggest_command:/msg <name> >" + |
||||
"<yellow><bold><name></click></hover>" + |
||||
": <white><msg>"; |
||||
|
||||
|
||||
return miniMessage.deserialize( |
||||
format, |
||||
Placeholder.parsed("name", player.getUsername()), |
||||
Placeholder.unparsed("msg", text) |
||||
); |
||||
} |
||||
} |
||||
@ -0,0 +1,37 @@ |
||||
package xyz.soukup.ecocraftVelocity.chat; |
||||
|
||||
import com.velocitypowered.api.event.Subscribe; |
||||
import com.velocitypowered.api.event.connection.DisconnectEvent; |
||||
import com.velocitypowered.api.event.player.ServerPostConnectEvent; |
||||
import com.velocitypowered.api.proxy.ProxyServer; |
||||
import net.kyori.adventure.text.minimessage.MiniMessage; |
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; |
||||
|
||||
public class JoinLeaveMessages { |
||||
|
||||
private final ProxyServer server; |
||||
private final MiniMessage miniMessage = MiniMessage.miniMessage(); |
||||
|
||||
public JoinLeaveMessages(ProxyServer server){ |
||||
this.server = server; |
||||
} |
||||
|
||||
@Subscribe |
||||
public void onJoin(ServerPostConnectEvent event){ |
||||
String name = event.getPlayer().getUsername(); |
||||
|
||||
String messageFormat = "<gray>[<green>+<gray>] <name>"; |
||||
|
||||
server.sendMessage(miniMessage.deserialize(messageFormat, Placeholder.parsed("name", name))); |
||||
} |
||||
|
||||
@Subscribe |
||||
public void onLeave(DisconnectEvent event){ |
||||
String name = event.getPlayer().getUsername(); |
||||
|
||||
String messageFormat = "<gray>[<red>-<gray>] <name>"; |
||||
|
||||
server.sendMessage(miniMessage.deserialize(messageFormat, Placeholder.parsed("name", name))); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,79 @@ |
||||
package xyz.soukup.ecocraftVelocity.tab; |
||||
|
||||
import com.velocitypowered.api.event.Subscribe; |
||||
import com.velocitypowered.api.event.connection.DisconnectEvent; |
||||
import com.velocitypowered.api.event.player.ServerPostConnectEvent; |
||||
import com.velocitypowered.api.proxy.Player; |
||||
import com.velocitypowered.api.proxy.ProxyServer; |
||||
import com.velocitypowered.api.proxy.player.TabListEntry; |
||||
import net.kyori.adventure.text.Component; |
||||
import net.kyori.adventure.text.format.NamedTextColor; |
||||
import net.kyori.adventure.text.format.TextDecoration; |
||||
import net.kyori.adventure.text.minimessage.MiniMessage; |
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; |
||||
|
||||
import java.util.UUID; |
||||
|
||||
public class GlobalTab { |
||||
private final ProxyServer server; |
||||
private final MiniMessage miniMessage = MiniMessage.miniMessage(); |
||||
|
||||
public GlobalTab(ProxyServer server) { |
||||
this.server = server; |
||||
} |
||||
|
||||
@Subscribe |
||||
public void onJoin(ServerPostConnectEvent event) { |
||||
|
||||
for (Player recipient : server.getAllPlayers()) { |
||||
for (Player onlinePlayer : server.getAllPlayers()) { |
||||
|
||||
Component displayName = formatPlayerName(onlinePlayer); |
||||
|
||||
if (!recipient.getTabList().containsEntry(onlinePlayer.getUniqueId())) { |
||||
TabListEntry entry = TabListEntry.builder() |
||||
.profile(onlinePlayer.getGameProfile()) |
||||
.displayName(displayName) |
||||
.tabList(recipient.getTabList()) |
||||
.build(); |
||||
|
||||
recipient.getTabList().addEntry(entry); |
||||
} else { |
||||
recipient.getTabList().getEntry(onlinePlayer.getUniqueId()) |
||||
.ifPresent(entry -> entry.setDisplayName(displayName)); |
||||
} |
||||
} |
||||
} |
||||
|
||||
updateTablist(); |
||||
} |
||||
|
||||
@Subscribe |
||||
public void onQuit(DisconnectEvent event) { |
||||
UUID quittingUuid = event.getPlayer().getUniqueId(); |
||||
|
||||
for (Player player : server.getAllPlayers()) { |
||||
player.getTabList().removeEntry(quittingUuid); |
||||
} |
||||
|
||||
updateTablist(); |
||||
} |
||||
|
||||
public void updateTablist() { |
||||
int onlineCount = server.getPlayerCount(); |
||||
|
||||
String header = "<br><gold><bold>EcoCraft.cz" + |
||||
"<br><red><bold> BETA SERVER <br>"; |
||||
|
||||
String footer = "<yellow><br> www.ecocraft.cz <br>"; |
||||
|
||||
for (Player player : server.getAllPlayers()) { |
||||
player.sendPlayerListHeaderAndFooter(miniMessage.deserialize(header), miniMessage.deserialize(footer)); |
||||
} |
||||
} |
||||
|
||||
private Component formatPlayerName(Player player) { |
||||
String format = "<white><bold><name>"; |
||||
return miniMessage.deserialize(format, Placeholder.unparsed("name", player.getUsername())); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue