mirror of
https://gitlab.com/SamB440/rpgregions-2.git
synced 2025-12-27 18:59:10 +00:00
Add title animation, bump to 1.0.1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module external.linked.project.id="RPGRegions" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="net.islandearth" external.system.module.version="1.0.0" type="JAVA_MODULE" version="4">
|
||||
<module external.linked.project.id="RPGRegions" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="net.islandearth" external.system.module.version="1.0.1" type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
pluginGroup=net.islandearth
|
||||
pluginVersion=1.0.0
|
||||
pluginVersion=1.0.1
|
||||
|
||||
@@ -106,6 +106,7 @@ public final class RPGRegions extends JavaPlugin implements RPGRegionsAPI, Langu
|
||||
config.addDefault("settings.server.discoveries.discovered.title.fadeout", 20);
|
||||
config.addDefault("settings.server.discoveries.discovered.sound.name", Sound.UI_TOAST_CHALLENGE_COMPLETE.toString());
|
||||
config.addDefault("settings.server.discoveries.discovered.sound.pitch", 1);
|
||||
config.addDefault("settings.server.discoveries.discovered.title.animation_speed", 20);
|
||||
config.options().copyDefaults(true);
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
@@ -22,9 +22,12 @@ public class AbstractAdapter<T> implements JsonSerializer<T>, JsonDeserializer<T
|
||||
public JsonElement serialize(T src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
JsonObject result = new JsonObject();
|
||||
if (thePackage != null)
|
||||
result.add("type", new JsonPrimitive(src.getClass().getSimpleName()));
|
||||
result.add("type",
|
||||
new JsonPrimitive(src.getClass().getSimpleName()));
|
||||
else
|
||||
result.add("type", new JsonPrimitive(src.getClass().getPackage().getName() + "." + src.getClass().getSimpleName()));
|
||||
result.add("type",
|
||||
new JsonPrimitive(src.getClass().getPackage().getName() + "." + src.getClass().getSimpleName()));
|
||||
|
||||
result.add("properties", context.serialize(src, src.getClass()));
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -16,9 +16,9 @@ public class ItemStackAdapter implements JsonSerializer<ItemStack>, JsonDeserial
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException {
|
||||
Map<String, Object> map = gson.fromJson(jsonElement, new TypeToken<Map<String, Object>>(){}.getType());
|
||||
return ItemStack.deserialize(map);
|
||||
public ItemStack deserialize(JsonElement jsonElement, Type type,
|
||||
JsonDeserializationContext context) throws JsonParseException {
|
||||
return ItemStack.deserialize(gson.fromJson(jsonElement, new TypeToken<Map<String, Object>>(){}.getType()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -7,6 +7,7 @@ import net.islandearth.rpgregions.managers.data.region.ConfiguredRegion;
|
||||
import net.islandearth.rpgregions.managers.data.region.Discovery;
|
||||
import net.islandearth.rpgregions.managers.data.region.WorldDiscovery;
|
||||
import net.islandearth.rpgregions.translation.Translations;
|
||||
import net.islandearth.rpgregions.utils.TitleAnimator;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -15,6 +16,7 @@ import org.bukkit.event.Listener;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
|
||||
public class RegionListener implements Listener {
|
||||
|
||||
@@ -60,13 +62,13 @@ public class RegionListener implements Listener {
|
||||
String region = rde.getRegion();
|
||||
if (plugin.getManagers().getRegionsCache().getConfiguredRegions().containsKey(region)) {
|
||||
ConfiguredRegion configuredRegion = plugin.getManagers().getRegionsCache().getConfiguredRegion(region);
|
||||
player.sendTitle(
|
||||
Translations.DISCOVERED_TITLE.get(player, configuredRegion.getCustomName()),
|
||||
Translations.DISCOVERED_SUBTITLE.get(player, configuredRegion.getCustomName()),
|
||||
plugin.getConfig().getInt("settings.server.discoveries.discovered.title.fadein"),
|
||||
plugin.getConfig().getInt("settings.server.discoveries.discovered.title.stay"),
|
||||
plugin.getConfig().getInt("settings.server.discoveries.discovered.title.fadeout")
|
||||
);
|
||||
List<String> title = Translations.DISCOVERED_TITLE.getList(player, configuredRegion.getCustomName());
|
||||
List<String> subtitle = Translations.DISCOVERED_SUBTITLE.getList(player, configuredRegion.getCustomName());
|
||||
new TitleAnimator(player,
|
||||
plugin,
|
||||
title,
|
||||
subtitle,
|
||||
plugin.getConfig().getInt("settings.server.discoveries.discovered.title.animation_speed"));
|
||||
|
||||
if (configuredRegion.getSound() == null) {
|
||||
player.playSound(
|
||||
|
||||
@@ -8,6 +8,8 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public enum Translations {
|
||||
@@ -15,19 +17,30 @@ public enum Translations {
|
||||
PREVIOUS_PAGE("&cPrevious Page"),
|
||||
REGIONS("Regions"),
|
||||
DISCOVERED_ON("&7Discovered on: %0"),
|
||||
DISCOVERED_TITLE("&d%0 discovered!"),
|
||||
DISCOVERED_SUBTITLE("&fKeep exploring to discover more!");
|
||||
DISCOVERED_TITLE("&d%0 discovered!", true),
|
||||
DISCOVERED_SUBTITLE("&fKeep exploring to discover more!", true);
|
||||
|
||||
private final String defaultValue;
|
||||
private final boolean isList;
|
||||
|
||||
Translations(String defaultValue) {
|
||||
this.defaultValue = defaultValue;
|
||||
this.isList = false;
|
||||
}
|
||||
|
||||
Translations(String defaultValue, boolean isList) {
|
||||
this.defaultValue = defaultValue;
|
||||
this.isList = isList;
|
||||
}
|
||||
|
||||
public String getDefaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
|
||||
public boolean isList() {
|
||||
return isList;
|
||||
}
|
||||
|
||||
private String getPath() {
|
||||
return this.toString().toLowerCase();
|
||||
}
|
||||
@@ -39,11 +52,7 @@ public enum Translations {
|
||||
|
||||
public void send(Player player, String... values) {
|
||||
String message = RPGRegions.getAPI().getTranslator().getTranslationFor(player, this.getPath());
|
||||
for (int i = 0; i < 10; i++) {
|
||||
if (values.length > i) message = message.replaceAll("%" + i, values[i]);
|
||||
else break;
|
||||
}
|
||||
|
||||
message = replaceVariables(message, values);
|
||||
player.sendMessage(message);
|
||||
}
|
||||
|
||||
@@ -55,11 +64,7 @@ public enum Translations {
|
||||
public void sendList(Player player, String... values) {
|
||||
List<String> messages = RPGRegions.getAPI().getTranslator().getTranslationListFor(player, this.getPath());
|
||||
messages.forEach(message -> {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
if (values.length > i) message = message.replaceAll("%" + i, values[i]);
|
||||
else break;
|
||||
}
|
||||
|
||||
message = replaceVariables(message, values);
|
||||
player.sendMessage(message);
|
||||
});
|
||||
}
|
||||
@@ -70,17 +75,21 @@ public enum Translations {
|
||||
|
||||
public String get(Player player, String... values) {
|
||||
String message = RPGRegions.getAPI().getTranslator().getTranslationFor(player, this.getPath());
|
||||
for (int i = 0; i < 10; i++) {
|
||||
if (values.length > i) message = message.replaceAll("%" + i, values[i]);
|
||||
else break;
|
||||
}
|
||||
|
||||
message = replaceVariables(message, values);
|
||||
return message;
|
||||
}
|
||||
|
||||
public List<String> getList(Player player) {
|
||||
return RPGRegions.getAPI().getTranslator().getTranslationListFor(player, this.getPath());
|
||||
}
|
||||
|
||||
public List<String> getList(Player player, String... values) {
|
||||
List<String> messages = new ArrayList<>();
|
||||
RPGRegions.getAPI().getTranslator()
|
||||
.getTranslationListFor(player, this.getPath())
|
||||
.forEach(message -> messages.add(replaceVariables(message, values)));
|
||||
return messages;
|
||||
}
|
||||
|
||||
public static void generateLang(RPGRegions plugin) {
|
||||
File lang = new File(plugin.getDataFolder() + "/lang/");
|
||||
@@ -97,7 +106,8 @@ public enum Translations {
|
||||
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||
config.options().copyDefaults(true);
|
||||
for (Translations key : values()) {
|
||||
config.addDefault(key.toString().toLowerCase(), key.getDefaultValue());
|
||||
if (!key.isList()) config.addDefault(key.toString().toLowerCase(), key.getDefaultValue());
|
||||
else config.addDefault(key.toString().toLowerCase(), Collections.singletonList(key.getDefaultValue()));
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -107,4 +117,14 @@ public enum Translations {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String replaceVariables(String message, String... values) {
|
||||
String modifiedMessage = message;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
if (values.length > i) modifiedMessage = modifiedMessage.replaceAll("%" + i, values[i]);
|
||||
else break;
|
||||
}
|
||||
|
||||
return modifiedMessage;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package net.islandearth.rpgregions.utils;
|
||||
|
||||
import net.islandearth.rpgregions.RPGRegions;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TitleAnimator {
|
||||
|
||||
public TitleAnimator(Player player, RPGRegions plugin, List<String> titles, List<String> subtitles, int speed) {
|
||||
new BukkitRunnable() {
|
||||
int current = 0;
|
||||
@Override
|
||||
public void run() {
|
||||
String title = current < titles.size() ? titles.get(current) : "";
|
||||
String subtitle = current < subtitles.size() ? subtitles.get(current) : "";
|
||||
if (current > titles.size()
|
||||
&& current > subtitles.size()) {
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
player.sendTitle(title,
|
||||
subtitle,
|
||||
plugin.getConfig().getInt("settings.server.discoveries.discovered.title.fadein"),
|
||||
plugin.getConfig().getInt("settings.server.discoveries.discovered.title.stay"),
|
||||
plugin.getConfig().getInt("settings.server.discoveries.discovered.title.fadeout"));
|
||||
current++;
|
||||
}
|
||||
}.runTaskTimer(plugin, 0L, speed);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user