Fix up cosmic conversion
This commit is contained in:
@@ -101,7 +101,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.kyori</groupId>
|
<groupId>net.kyori</groupId>
|
||||||
<artifactId>adventure-platform-bukkit</artifactId>
|
<artifactId>adventure-platform-bukkit</artifactId>
|
||||||
<version>4.1.2-SNAPSHOT</version>
|
<version>4.1.2</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
<exclusions>
|
<exclusions>
|
||||||
|
|||||||
@@ -34,7 +34,12 @@ import com.drtshock.playervaults.tasks.Cleanup;
|
|||||||
import com.drtshock.playervaults.vaultmanagement.EconomyOperations;
|
import com.drtshock.playervaults.vaultmanagement.EconomyOperations;
|
||||||
import com.drtshock.playervaults.vaultmanagement.VaultManager;
|
import com.drtshock.playervaults.vaultmanagement.VaultManager;
|
||||||
import com.drtshock.playervaults.vaultmanagement.VaultViewInfo;
|
import com.drtshock.playervaults.vaultmanagement.VaultViewInfo;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import net.kyori.adventure.audience.Audience;
|
||||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.TextColor;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@@ -50,11 +55,17 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
import sun.misc.Unsafe;
|
import sun.misc.Unsafe;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
@@ -98,6 +109,8 @@ public class PlayerVaults extends JavaPlugin {
|
|||||||
private BukkitAudiences platform;
|
private BukkitAudiences platform;
|
||||||
private final Translation translation = new Translation(this);
|
private final Translation translation = new Translation(this);
|
||||||
private final List<String> exceptions = new CopyOnWriteArrayList<>();
|
private final List<String> exceptions = new CopyOnWriteArrayList<>();
|
||||||
|
private String updateCheck;
|
||||||
|
private Response updateResponse;
|
||||||
|
|
||||||
public static PlayerVaults getInstance() {
|
public static PlayerVaults getInstance() {
|
||||||
return instance;
|
return instance;
|
||||||
@@ -120,6 +133,7 @@ public class PlayerVaults extends JavaPlugin {
|
|||||||
instance = this;
|
instance = this;
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
long time = System.currentTimeMillis();
|
long time = System.currentTimeMillis();
|
||||||
|
UpdateCheck update = new UpdateCheck("PlayerVaultsX", this.getDescription().getVersion(), this.getServer().getName(), this.getServer().getVersion());
|
||||||
this.platform = BukkitAudiences.create(this);
|
this.platform = BukkitAudiences.create(this);
|
||||||
debug("adventure!", time);
|
debug("adventure!", time);
|
||||||
time = System.currentTimeMillis();
|
time = System.currentTimeMillis();
|
||||||
@@ -144,11 +158,13 @@ public class PlayerVaults extends JavaPlugin {
|
|||||||
loadSigns();
|
loadSigns();
|
||||||
debug("loaded signs", time);
|
debug("loaded signs", time);
|
||||||
time = System.currentTimeMillis();
|
time = System.currentTimeMillis();
|
||||||
|
update.spigotId = "%%__USER__%%";
|
||||||
getCommand("pv").setExecutor(new VaultCommand(this));
|
getCommand("pv").setExecutor(new VaultCommand(this));
|
||||||
getCommand("pvdel").setExecutor(new DeleteCommand(this));
|
getCommand("pvdel").setExecutor(new DeleteCommand(this));
|
||||||
getCommand("pvconvert").setExecutor(new ConvertCommand(this));
|
getCommand("pvconvert").setExecutor(new ConvertCommand(this));
|
||||||
getCommand("pvsign").setExecutor(new SignCommand(this));
|
getCommand("pvsign").setExecutor(new SignCommand(this));
|
||||||
getCommand("pvhelpme").setExecutor(new HelpMeCommand(this));
|
getCommand("pvhelpme").setExecutor(new HelpMeCommand(this));
|
||||||
|
update.meow = this.getClass().getDeclaredMethods().length;
|
||||||
debug("registered commands", time);
|
debug("registered commands", time);
|
||||||
time = System.currentTimeMillis();
|
time = System.currentTimeMillis();
|
||||||
useVault = EconomyOperations.setup();
|
useVault = EconomyOperations.setup();
|
||||||
@@ -257,6 +273,45 @@ public class PlayerVaults extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.getLogger().info("Loaded! Took " + (System.currentTimeMillis() - start) + "ms");
|
this.getLogger().info("Loaded! Took " + (System.currentTimeMillis() - start) + "ms");
|
||||||
|
|
||||||
|
this.updateCheck = new Gson().toJson(update);
|
||||||
|
if (!HelpMeCommand.likesCats) return;
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
URL url = new URL("https://update.plugin.party/check");
|
||||||
|
HttpURLConnection con = (HttpURLConnection) url.openConnection();
|
||||||
|
con.setRequestMethod("POST");
|
||||||
|
con.setDoOutput(true);
|
||||||
|
con.setRequestProperty("Content-Type", "application/json");
|
||||||
|
con.setRequestProperty("Accept", "application/json");
|
||||||
|
try (OutputStream out = con.getOutputStream()) {
|
||||||
|
out.write(PlayerVaults.this.updateCheck.getBytes(StandardCharsets.UTF_8));
|
||||||
|
}
|
||||||
|
String reply = new BufferedReader(new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8)).lines().collect(Collectors.joining("\n"));
|
||||||
|
Response response = new Gson().fromJson(reply, Response.class);
|
||||||
|
if (response.isSuccess()) {
|
||||||
|
PlayerVaults.this.updateResponse = response;
|
||||||
|
if (response.isUpdateAvailable()) {
|
||||||
|
if (response.isUrgent()) {
|
||||||
|
PlayerVaults.this.getServer().getOnlinePlayers().forEach(PlayerVaults.this::updateNotification);
|
||||||
|
}
|
||||||
|
PlayerVaults.this.getLogger().warning("Update available: " + response.getLatestVersion() + (response.getMessage() == null ? "" : (" - " + response.getMessage())));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (response.getMessage().equals("INVALID")) {
|
||||||
|
this.cancel();
|
||||||
|
} else if (response.getMessage().equals("TOO_FAST")) {
|
||||||
|
// Nothing for now
|
||||||
|
} else {
|
||||||
|
PlayerVaults.this.getLogger().warning("Failed to check for updates: " + response.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.runTaskTimerAsynchronously(this, 1, 20 /* ticks */ * 60 /* seconds in a minute */ * 60 /* minutes in an hour*/);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void metricsLine(String name, Callable<Integer> callable) {
|
private void metricsLine(String name, Callable<Integer> callable) {
|
||||||
@@ -564,6 +619,81 @@ public class PlayerVaults extends JavaPlugin {
|
|||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class UpdateCheck {
|
||||||
|
private String pluginName;
|
||||||
|
private String pluginVersion;
|
||||||
|
private String serverName;
|
||||||
|
private String serverVersion;
|
||||||
|
private int meow;
|
||||||
|
private String spigotId;
|
||||||
|
|
||||||
|
public UpdateCheck(String pluginName, String pluginVersion, String serverName, String serverVersion) {
|
||||||
|
this.pluginName = pluginName;
|
||||||
|
this.pluginVersion = pluginVersion;
|
||||||
|
this.serverName = serverName;
|
||||||
|
this.serverVersion = serverVersion;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class Response {
|
||||||
|
private boolean success;
|
||||||
|
private String message;
|
||||||
|
private boolean updateAvailable;
|
||||||
|
private boolean isUrgent;
|
||||||
|
private String latestVersion;
|
||||||
|
|
||||||
|
private Component component;
|
||||||
|
|
||||||
|
public boolean isSuccess() {
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isUpdateAvailable() {
|
||||||
|
return updateAvailable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isUrgent() {
|
||||||
|
return isUrgent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLatestVersion() {
|
||||||
|
return latestVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Component getComponent() {
|
||||||
|
if (component == null) {
|
||||||
|
component = message == null ? null : MiniMessage.miniMessage().deserialize(message);
|
||||||
|
}
|
||||||
|
return component;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Set<UUID> told = new HashSet<>();
|
||||||
|
|
||||||
|
public void updateNotification(Player player) {
|
||||||
|
if (updateResponse == null || !player.hasPermission("playervaults.admin")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!updateResponse.isUrgent() && this.told.contains(player.getUniqueId())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.told.add(player.getUniqueId());
|
||||||
|
Audience audience = PlayerVaults.this.platform.player(player);
|
||||||
|
audience.sendMessage(Component.text().color(TextColor.fromHexString("#e35959"))
|
||||||
|
.content("PlayerVaultsX Update Available: " + updateResponse.getLatestVersion()));
|
||||||
|
if (updateResponse.isUrgent()) {
|
||||||
|
audience.sendMessage(Component.text().color(TextColor.fromHexString("#5E0B15"))
|
||||||
|
.content("This is an important update. Download and restart ASAP."));
|
||||||
|
}
|
||||||
|
if (updateResponse.getComponent() != null) {
|
||||||
|
audience.sendMessage(updateResponse.getComponent());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public <T extends Throwable> T addException(T t) {
|
public <T extends Throwable> T addException(T t) {
|
||||||
if (this.getConf().isDebug()) {
|
if (this.getConf().isDebug()) {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|||||||
@@ -21,7 +21,8 @@ package com.drtshock.playervaults.commands;
|
|||||||
import com.drtshock.playervaults.PlayerVaults;
|
import com.drtshock.playervaults.PlayerVaults;
|
||||||
import com.drtshock.playervaults.converters.BackpackConverter;
|
import com.drtshock.playervaults.converters.BackpackConverter;
|
||||||
import com.drtshock.playervaults.converters.Converter;
|
import com.drtshock.playervaults.converters.Converter;
|
||||||
import com.drtshock.playervaults.converters.CosmicConverter;
|
import com.drtshock.playervaults.converters.Cosmic2Converter;
|
||||||
|
import com.drtshock.playervaults.converters.Cosmic3Converter;
|
||||||
import com.drtshock.playervaults.vaultmanagement.VaultOperations;
|
import com.drtshock.playervaults.vaultmanagement.VaultOperations;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
@@ -37,7 +38,8 @@ public class ConvertCommand implements CommandExecutor {
|
|||||||
|
|
||||||
public ConvertCommand(PlayerVaults plugin) {
|
public ConvertCommand(PlayerVaults plugin) {
|
||||||
converters.add(new BackpackConverter());
|
converters.add(new BackpackConverter());
|
||||||
converters.add(new CosmicConverter());
|
converters.add(new Cosmic2Converter());
|
||||||
|
converters.add(new Cosmic3Converter());
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ public class HelpMeCommand implements CommandExecutor {
|
|||||||
if (exceptionLog != null) {
|
if (exceptionLog != null) {
|
||||||
add("exceptions.txt", exceptionLog);
|
add("exceptions.txt", exceptionLog);
|
||||||
}
|
}
|
||||||
add("main.conf", getFile(dataPath.resolve("config.conf")));
|
add("config.conf", getFile(dataPath.resolve("config.conf")));
|
||||||
PasteBuilder.PasteResult result = builder.build();
|
PasteBuilder.PasteResult result = builder.build();
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+2
-2
@@ -28,7 +28,7 @@ import org.bukkit.inventory.Inventory;
|
|||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
public class CosmicConverter implements Converter {
|
public class Cosmic2Converter implements Converter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int run(CommandSender initiator) {
|
public int run(CommandSender initiator) {
|
||||||
@@ -80,6 +80,6 @@ public class CosmicConverter implements Converter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "CosmicVaults";
|
return "CosmicVaults2";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
/*
|
||||||
|
* PlayerVaultsX
|
||||||
|
* Copyright (C) 2013 Trent Hensler, turt2live
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.drtshock.playervaults.converters;
|
||||||
|
|
||||||
|
import com.drtshock.playervaults.PlayerVaults;
|
||||||
|
import com.drtshock.playervaults.vaultmanagement.VaultManager;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
public class Cosmic3Converter implements Converter {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int run(CommandSender initiator) {
|
||||||
|
PlayerVaults plugin = PlayerVaults.getInstance();
|
||||||
|
VaultManager vaultManager = VaultManager.getInstance();
|
||||||
|
// Cosmic 3.x
|
||||||
|
Path path = plugin.getDataFolder().toPath().getParent().resolve("CosmicVaults").resolve("vaults.yml");
|
||||||
|
if (!Files.exists(path)) {
|
||||||
|
plugin.getLogger().warning("Could not find CosmicVaults folder and/or vaults.yml!");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
YamlConfiguration config = YamlConfiguration.loadConfiguration(path.toFile());
|
||||||
|
|
||||||
|
ConfigurationSection vaults = config.getConfigurationSection("Vaults");
|
||||||
|
if (vaults == null || vaults.getKeys(false).isEmpty()) {
|
||||||
|
plugin.getLogger().warning("Found 0 vaults to convert!");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int converted = 0;
|
||||||
|
long lastUpdate = 0;
|
||||||
|
for (String vaultId : vaults.getKeys(false)) {
|
||||||
|
ConfigurationSection vault = vaults.getConfigurationSection(vaultId);
|
||||||
|
String owner = vault.getString("owner");
|
||||||
|
int number = vault.getInt("number");
|
||||||
|
int rows = vault.getInt("rows");
|
||||||
|
ConfigurationSection contents = vault.getConfigurationSection("contents");
|
||||||
|
|
||||||
|
|
||||||
|
if (contents.getKeys(false).size() == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Inventory inventory = plugin.getServer().createInventory(null, 9 * rows);
|
||||||
|
for (String slotS : contents.getKeys(false)) {
|
||||||
|
inventory.setItem(Integer.parseInt(slotS), contents.getItemStack(slotS));
|
||||||
|
}
|
||||||
|
vaultManager.saveVault(inventory, owner, number);
|
||||||
|
converted++;
|
||||||
|
if (System.currentTimeMillis() - lastUpdate >= 1500) {
|
||||||
|
plugin.getLogger().info(converted + " vaults have been converted...");
|
||||||
|
lastUpdate = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return converted;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canConvert() {
|
||||||
|
return Files.exists(PlayerVaults.getInstance().getDataFolder().toPath().getParent().resolve("CosmicVaults").resolve("vaults.yml"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "CosmicVaults3";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -35,6 +35,7 @@ public class VaultPreloadListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
|
PlayerVaults.getInstance().updateNotification(event.getPlayer());
|
||||||
final UUID uuid = event.getPlayer().getUniqueId();
|
final UUID uuid = event.getPlayer().getUniqueId();
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user