-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
4.2.0 Loop detection, click and hover resolving, bukkit platform
- Loading branch information
Showing
70 changed files
with
896 additions
and
127 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?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> | ||
<parent> | ||
<groupId>de.cubbossa</groupId> | ||
<artifactId>TinyTranslations</artifactId> | ||
<version>4.2.0</version> | ||
</parent> | ||
|
||
<artifactId>TinyTranslations-bukkit</artifactId> | ||
|
||
<properties> | ||
<maven.compiler.source>17</maven.compiler.source> | ||
<maven.compiler.target>17</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<repositories> | ||
<repository> | ||
<id>spigot-repo</id> | ||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url> | ||
</repository> | ||
</repositories> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>de.cubbossa</groupId> | ||
<artifactId>TinyTranslations-common</artifactId> | ||
<version>4.2.0</version> | ||
</dependency> | ||
|
||
<!--This adds the Spigot API artifact to the build --> | ||
<dependency> | ||
<groupId>org.spigotmc</groupId> | ||
<artifactId>spigot-api</artifactId> | ||
<version>1.20.2-R0.1-SNAPSHOT</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
38 changes: 38 additions & 0 deletions
38
TinyTranslations-bukkit/src/main/java/de/cubbossa/tinytranslations/BukkitGlobalMessages.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,38 @@ | ||
package de.cubbossa.tinytranslations; | ||
|
||
public class BukkitGlobalMessages { | ||
|
||
|
||
public static final Message FORMAT_PLAYER = new MessageBuilder("format.player") | ||
.withDefault("<hover:show_text:'{player:uuid}'>{player:name}</hover>") | ||
.withPlaceholder("player") | ||
.build(); | ||
public static final Message FORMAT_ENTITY = new MessageBuilder("format.entity") | ||
.withDefault("{selector:'@[uuid={entity:uuid}]'}") | ||
.withPlaceholder("entity") | ||
.build(); | ||
public static final Message FORMAT_WORLD = new MessageBuilder("format.world") | ||
.withDefault("{world:name}") | ||
.withPlaceholder("world") | ||
.build(); | ||
public static final Message FORMAT_BLOCK = new MessageBuilder("format.block") | ||
.withDefault("<hover:show_text:'X: {bloc:x}\nY: {bloc:y}\nZ: {bloc:z}\nWorld: {bloc:world:name}'>{block:type}<{bloc:x};{bloc:y};{bloc:z}></hover>") | ||
.withPlaceholder("block") | ||
.build(); | ||
public static final Message FORMAT_LOCATION = new MessageBuilder("format.location") | ||
.withDefault("<hover:show_text:'X: {loc:x}\nY: {loc:y}\nZ: {loc:z}\nYaw: {loc:yaw}\nPitch: {loc:pitch}\nWorld: {loc:world:name}'><{loc:x};{loc:y};{loc:z}></hover>") | ||
.withPlaceholder("loc") | ||
.build(); | ||
public static final Message FORMAT_VECTOR = new MessageBuilder("format.vector") | ||
.withDefault("<{vector:x};{vector:y};{vector:z}>") | ||
.withPlaceholder("vector") | ||
.build(); | ||
public static final Message FORMAT_MATERIAL = new MessageBuilder("format.material") | ||
.withDefault("{material}") | ||
.withPlaceholders("material") | ||
.build(); | ||
public static final Message FORMAT_ENTITY_TYPE = new MessageBuilder("format.entity_type") | ||
.withDefault("{type}") | ||
.withPlaceholders("type") | ||
.build(); | ||
} |
123 changes: 123 additions & 0 deletions
123
...ranslations-bukkit/src/main/java/de/cubbossa/tinytranslations/TinyTranslationsBukkit.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,123 @@ | ||
package de.cubbossa.tinytranslations; | ||
|
||
import de.cubbossa.tinytranslations.nanomessage.ObjectTagResolverMap; | ||
import net.kyori.adventure.audience.Audience; | ||
import net.kyori.adventure.identity.Identity; | ||
import net.kyori.adventure.platform.bukkit.BukkitAudiences; | ||
import net.kyori.adventure.text.Component; | ||
import net.kyori.adventure.text.ComponentLike; | ||
import net.kyori.adventure.text.minimessage.MiniMessage; | ||
import org.bukkit.Location; | ||
import org.bukkit.Material; | ||
import org.bukkit.World; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Entity; | ||
import org.bukkit.entity.EntityType; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.generator.WorldInfo; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
import org.bukkit.util.Vector; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.io.File; | ||
import java.util.Collections; | ||
import java.util.Locale; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
|
||
public final class TinyTranslationsBukkit extends TinyTranslations { | ||
|
||
private TinyTranslationsBukkit() {} | ||
private static BukkitAudiences audiences; | ||
|
||
public static void enable(JavaPlugin plugin) { | ||
audiences = BukkitAudiences.create(plugin); | ||
TinyTranslations.enable(new File(plugin.getDataFolder(), "/../")); | ||
|
||
global().addMessages(messageFieldsFromClass(BukkitGlobalMessages.class)); | ||
applyBukkitObjectResolvers(global().getObjectTypeResolverMap()); | ||
global().saveLocale(Locale.ENGLISH); | ||
} | ||
|
||
public static void disable() { | ||
TinyTranslations.disable(); | ||
audiences.close(); | ||
} | ||
|
||
public static Translator application(JavaPlugin plugin) { | ||
if (!isEnabled()) { | ||
enable(plugin); | ||
} | ||
var app = application(plugin.getName()); | ||
applyBukkitObjectResolvers(app.getObjectTypeResolverMap()); | ||
return app; | ||
} | ||
|
||
public static Function<@Nullable Audience, Locale> getPerPlayerLocaleProvider(Locale fallback) { | ||
return audience -> { | ||
if (audience == null) { | ||
return fallback; | ||
} | ||
return audience.getOrDefault(Identity.LOCALE, fallback); | ||
}; | ||
} | ||
|
||
public static Locale getLocale(CommandSender sender) { | ||
return getLocale(sender, DEFAULT_LOCALE); | ||
} | ||
|
||
public static Locale getLocale(CommandSender sender, Locale fallback) { | ||
return audiences.sender(sender).get(Identity.LOCALE).orElse(fallback); | ||
} | ||
|
||
public static void sendActionBar(CommandSender sender, ComponentLike message) { | ||
audiences.sender(sender).sendActionBar(message); | ||
} | ||
|
||
public static void sendMessage(CommandSender sender, ComponentLike message) { | ||
audiences.sender(sender).sendMessage(message); | ||
} | ||
|
||
private static void applyBukkitObjectResolvers(ObjectTagResolverMap map) { | ||
map.put(Player.class, Map.of( | ||
"name", Player::getName, | ||
"uuid", Entity::getUniqueId, | ||
"type", Entity::getType, | ||
"display", Player::getDisplayName, | ||
"location", Player::getLocation | ||
), p -> BukkitGlobalMessages.FORMAT_PLAYER.insertObject("player", p)); | ||
map.put(Entity.class, Map.of( | ||
"name", Entity::getName, | ||
"uuid", Entity::getUniqueId, | ||
"type", Entity::getType, | ||
"location", Entity::getLocation | ||
), p -> BukkitGlobalMessages.FORMAT_ENTITY.insertObject("entity", p)); | ||
map.put(World.class, Map.of( | ||
"name", WorldInfo::getName, | ||
"uuid", WorldInfo::getUID | ||
), w -> BukkitGlobalMessages.FORMAT_WORLD.insertObject("world", w)); | ||
map.put(Block.class, Map.of( | ||
"type", Block::getType, | ||
"x", Block::getX, | ||
"y", Block::getY, | ||
"z", Block::getZ, | ||
"world", Block::getWorld | ||
), b -> BukkitGlobalMessages.FORMAT_BLOCK.insertObject("block", b)); | ||
map.put(Location.class, Map.of( | ||
"x", Location::getX, | ||
"y", Location::getY, | ||
"z", Location::getZ, | ||
"yaw", Location::getZ, | ||
"pitch", Location::getZ, | ||
"world", Location::getWorld | ||
), l -> BukkitGlobalMessages.FORMAT_LOCATION.insertObject("loc", l)); | ||
map.put(Vector.class, Map.of( | ||
"x", Vector::getX, | ||
"y", Vector::getY, | ||
"z", Vector::getZ | ||
), v -> BukkitGlobalMessages.FORMAT_VECTOR.insertObject("vector", v)); | ||
map.put(Material.class, Collections.emptyMap(), m -> BukkitGlobalMessages.FORMAT_MATERIAL.insertObject("material", m)); | ||
map.put(EntityType.class, Collections.emptyMap(), m -> BukkitGlobalMessages.FORMAT_ENTITY_TYPE.insertObject("type", m)); | ||
} | ||
} |
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,116 @@ | ||
<?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> | ||
<parent> | ||
<groupId>de.cubbossa</groupId> | ||
<artifactId>TinyTranslations</artifactId> | ||
<version>4.2.0</version> | ||
</parent> | ||
|
||
<artifactId>TinyTranslations-common</artifactId> | ||
|
||
<properties> | ||
<maven.compiler.source>17</maven.compiler.source> | ||
<maven.compiler.target>17</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<repositories> | ||
<repository> | ||
<id>spigot-repo</id> | ||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url> | ||
</repository> | ||
|
||
<repository> | ||
<id>codemc-repo</id> | ||
<url>https://repo.codemc.org/repository/maven-public/</url> | ||
<layout>default</layout> | ||
</repository> | ||
|
||
<repository> | ||
<id>codemc-snapshots</id> | ||
<url>https://repo.codemc.io/repository/maven-snapshots/</url> | ||
</repository> | ||
|
||
<repository> | ||
<id>jitpack.io</id> | ||
<url>https://jitpack.io</url> | ||
</repository> | ||
</repositories> | ||
|
||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.github.crowdin</groupId> | ||
<artifactId>crowdin-api-client-java</artifactId> | ||
<version>1.13.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.google.code.gson</groupId> | ||
<artifactId>gson</artifactId> | ||
<version>2.10.1</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>1.18.22</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<!-- https://mvnrepository.com/artifact/junit/junit --> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-engine</artifactId> | ||
<version>5.10.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.yaml</groupId> | ||
<artifactId>snakeyaml</artifactId> | ||
<version>2.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>net.kyori</groupId> | ||
<artifactId>adventure-api</artifactId> | ||
<version>4.15.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>net.kyori</groupId> | ||
<artifactId>adventure-platform-bukkit</artifactId> | ||
<version>4.3.2</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>net.kyori</groupId> | ||
<artifactId>adventure-text-minimessage</artifactId> | ||
<version>4.15.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>net.kyori</groupId> | ||
<artifactId>adventure-text-serializer-legacy</artifactId> | ||
<version>4.15.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>net.kyori</groupId> | ||
<artifactId>adventure-text-serializer-gson</artifactId> | ||
<version>4.15.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>net.kyori</groupId> | ||
<artifactId>adventure-text-serializer-plain</artifactId> | ||
<version>4.15.0</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
|
||
</project> |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.