-
Notifications
You must be signed in to change notification settings - Fork 3
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
Showing
8 changed files
with
211 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,40 @@ | ||
<?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"> | ||
<parent> | ||
<artifactId>i18n</artifactId> | ||
<groupId>de.helixdevs</groupId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>i18n-velocity</artifactId> | ||
|
||
<properties> | ||
<maven.compiler.source>17</maven.compiler.source> | ||
<maven.compiler.target>17</maven.compiler.target> | ||
</properties> | ||
|
||
<repositories> | ||
<repository> | ||
<id>papermc</id> | ||
<url>https://papermc.io/repo/repository/maven-public/</url> | ||
</repository> | ||
</repositories> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>de.helixdevs</groupId> | ||
<artifactId>i18n-adventure</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.velocitypowered</groupId> | ||
<artifactId>velocity-api</artifactId> | ||
<version>3.1.2-SNAPSHOT</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
114 changes: 114 additions & 0 deletions
114
i18n-velocity/src/main/java/de/helixdevs/i18n/velocity/I18nVelocityPlugin.java
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,114 @@ | ||
package de.helixdevs.i18n.velocity; | ||
|
||
import com.google.common.reflect.TypeToken; | ||
import com.google.inject.Inject; | ||
import com.velocitypowered.api.command.RawCommand; | ||
import com.velocitypowered.api.command.SimpleCommand; | ||
import com.velocitypowered.api.event.Subscribe; | ||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; | ||
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent; | ||
import com.velocitypowered.api.plugin.Plugin; | ||
import com.velocitypowered.api.plugin.annotation.DataDirectory; | ||
import com.velocitypowered.api.proxy.ProxyServer; | ||
import de.helixdevs.i18n.adventure.AdventureTranslationConsumer; | ||
import de.helixdevs.i18n.api.TranslationConsumer; | ||
import de.helixdevs.i18n.common.command.api.Command; | ||
import de.helixdevs.i18n.common.platform.I18nPlatform; | ||
import de.helixdevs.i18n.common.platform.I18nPlugin; | ||
import de.helixdevs.i18n.velocity.command.VelocitySender; | ||
import ninja.leaping.configurate.ConfigurationNode; | ||
import ninja.leaping.configurate.objectmapping.ObjectMappingException; | ||
import ninja.leaping.configurate.yaml.YAMLConfigurationLoader; | ||
import org.yaml.snakeyaml.DumperOptions; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.logging.Logger; | ||
|
||
@Plugin( | ||
id = "i18n", | ||
name = "I18n", | ||
version = "1.0-SNAPSHOT", | ||
description = "Velocity implementation of I18n", | ||
authors = {"MCMDEV"} | ||
) | ||
public class I18nVelocityPlugin implements I18nPlugin { | ||
|
||
private final ProxyServer proxyServer; | ||
private final Logger logger; | ||
private final Path dataDirectory; | ||
private final I18nPlatform platform; | ||
|
||
private ConfigurationNode configurationNode; | ||
|
||
@Inject | ||
public I18nVelocityPlugin(ProxyServer proxyServer, Logger logger, @DataDirectory Path dataDirectory) { | ||
this.proxyServer = proxyServer; | ||
this.logger = logger; | ||
this.dataDirectory = dataDirectory; | ||
this.platform = new I18nPlatform(this); | ||
} | ||
|
||
@Subscribe | ||
private void onProxyInitialization(ProxyInitializeEvent event) throws IOException { | ||
YAMLConfigurationLoader configurationLoader = YAMLConfigurationLoader.builder() | ||
.setFlowStyle(DumperOptions.FlowStyle.FLOW) | ||
.setIndent(2) | ||
.setPath(dataDirectory.resolve("config.yml")) | ||
.build(); | ||
this.configurationNode = configurationLoader.load(); | ||
|
||
platform.enable(); | ||
} | ||
|
||
@Subscribe | ||
private void onProxyShutdown(ProxyShutdownEvent event) { | ||
platform.disable(); | ||
} | ||
|
||
@Override | ||
public String getConfigString(String key) { | ||
return configurationNode.getNode(key).getString(); | ||
} | ||
|
||
@Override | ||
public List<String> getConfigStringList(String key) { | ||
try { | ||
return configurationNode.getNode(key).getList(TypeToken.of(String.class)); | ||
} catch (ObjectMappingException e) { | ||
e.printStackTrace(); | ||
} | ||
return Collections.emptyList(); | ||
} | ||
|
||
@Override | ||
public Set<TranslationConsumer> getConsumers() { | ||
Set<TranslationConsumer> consumers = new HashSet<>(); | ||
consumers.add(new AdventureTranslationConsumer()); | ||
return consumers; | ||
} | ||
|
||
@Override | ||
public Logger getLogger() { | ||
return this.logger; | ||
} | ||
|
||
@Override | ||
public void registerCommand(Command command) { | ||
proxyServer.getCommandManager().register(command.getLabel(), new SimpleCommand() { | ||
@Override | ||
public void execute(Invocation invocation) { | ||
command.execute(new VelocitySender(invocation.source()), invocation.arguments()); | ||
} | ||
|
||
@Override | ||
public boolean hasPermission(Invocation invocation) { | ||
return invocation.source().hasPermission(command.getPermission()); | ||
} | ||
}); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
i18n-velocity/src/main/java/de/helixdevs/i18n/velocity/command/VelocitySender.java
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,19 @@ | ||
package de.helixdevs.i18n.velocity.command; | ||
|
||
import com.velocitypowered.api.command.CommandSource; | ||
import de.helixdevs.i18n.common.command.api.Sender; | ||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; | ||
|
||
public class VelocitySender implements Sender { | ||
|
||
private final CommandSource holder; | ||
|
||
public VelocitySender(CommandSource holder) { | ||
this.holder = holder; | ||
} | ||
|
||
@Override | ||
public void sendMessage(String message) { | ||
holder.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(message)); | ||
} | ||
} |
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