Skip to content

Commit

Permalink
Merge branch 'master' into update
Browse files Browse the repository at this point in the history
  • Loading branch information
SrBedrock committed Jul 2, 2024
2 parents e9bc937 + 0c8eaa4 commit c83fd54
Show file tree
Hide file tree
Showing 7 changed files with 236 additions and 14 deletions.
33 changes: 20 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>com.drtshock</groupId>
<artifactId>PlayerVaultsX</artifactId>
<version>4.2.15</version>
<version>4.3.0</version>
<name>PlayerVaultsX</name>
<url>https://www.spigotmc.org/resources/51204/</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<build.number>SNAPSHOT</build.number>
</properties>

<build>
Expand All @@ -30,16 +30,15 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.13.0</version>
<configuration>
<source>17</source>
<target>17</target>
<release>17</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.0</version>
<version>3.6.0</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<relocations>
Expand All @@ -55,6 +54,10 @@
<pattern>org.kitteh</pattern>
<shadedPattern>com.drtshock.playervaults.lib.org.kitteh</shadedPattern>
</relocation>
<relocation>
<pattern>dev.kitteh</pattern>
<shadedPattern>com.drtshock.playervaults.lib.dev.kitteh</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
Expand All @@ -78,6 +81,10 @@
<id>fuuid-repo</id>
<url>https://github.com/factions-site/repo/raw/public</url>
</repository>
<repository>
<id>dependency-download</id>
<url>https://dependency.download/releases</url>
</repository>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
Expand All @@ -102,7 +109,7 @@
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-platform-bukkit</artifactId>
<version>4.3.2</version>
<version>4.3.3</version>
<scope>compile</scope>
<optional>true</optional>
<exclusions>
Expand All @@ -119,7 +126,7 @@
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-minimessage</artifactId>
<version>4.15.0</version>
<version>4.17.0</version>
<scope>compile</scope>
<optional>true</optional>
<exclusions>
Expand All @@ -140,9 +147,9 @@
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.kitteh</groupId>
<groupId>dev.kitteh</groupId>
<artifactId>cardboardbox</artifactId>
<version>0.2.2</version>
<version>2.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -176,4 +183,4 @@
<scope>provided</scope>
</dependency>
</dependencies>
</project>
</project>
9 changes: 9 additions & 0 deletions src/main/java/com/drtshock/playervaults/PlayerVaults.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package com.drtshock.playervaults;

import com.drtshock.playervaults.commands.ConsoleCommand;
import com.drtshock.playervaults.commands.ConvertCommand;
import com.drtshock.playervaults.commands.DeleteCommand;
import com.drtshock.playervaults.commands.HelpMeCommand;
Expand Down Expand Up @@ -50,10 +51,12 @@
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import dev.kitteh.cardboardbox.CardboardBox;
import sun.misc.Unsafe;

import java.io.BufferedReader;
Expand Down Expand Up @@ -133,6 +136,11 @@ public static void debug(String s) {

@Override
public void onEnable() {
if (!CardboardBox.isReady()) {
this.getLogger().log(Level.SEVERE, "Could not initialize!", CardboardBox.getException());
this.getServer().getPluginManager().disablePlugin(this);
return;
}
instance = this;
long start = System.currentTimeMillis();
long time = System.currentTimeMillis();
Expand Down Expand Up @@ -169,6 +177,7 @@ public void onEnable() {
getCommand("pvconvert").setExecutor(new ConvertCommand(this));
getCommand("pvsign").setExecutor(new SignCommand(this));
getCommand("pvhelpme").setExecutor(new HelpMeCommand(this));
getCommand("pvconsole").setExecutor(new ConsoleCommand(this));
update.meow = this.getClass().getDeclaredMethods().length;
debug("registered commands", time);
time = System.currentTimeMillis();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* PlayerVaultsX
* Copyright (C) 2013 Trent Hensler
*
* 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.commands;

import com.drtshock.playervaults.PlayerVaults;
import com.drtshock.playervaults.vaultmanagement.VaultOperations;
import com.drtshock.playervaults.vaultmanagement.VaultViewInfo;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;

public class ConsoleCommand implements CommandExecutor {
private final PlayerVaults plugin;

public ConsoleCommand(PlayerVaults plugin) {
this.plugin = plugin;
}

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof ConsoleCommandSender)) {
return true;
}
if (VaultOperations.isLocked()) {
this.plugin.getTL().locked().title().send(sender);
return true;
}

if (args.length == 0) {
sender.sendMessage("/" + label + " openforplayer <player> <owner> <vaultid>");
return true;
} else {
if (args[0].equals("openforplayer")) {
if (args.length < 4) {
sender.sendMessage("/" + label + " openforplayer <player> <owner> <vaultid>");
return true;
} else {
String player = args[1];
String owner = args[2];
String vaultId = args[3];
Player plr = this.plugin.getServer().getPlayerExact(player);
if (plr == null) {
sender.sendMessage("NOT ONLINE");
return true;
}
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(owner);
if (offlinePlayer != null) {
owner = offlinePlayer.getUniqueId().toString();
} else {
sender.sendMessage("FAILED TO LOOK UP UUID FOR NAME");
return true;
}
int number;
try {
number = Integer.parseInt(vaultId);
} catch (NumberFormatException e) {
sender.sendMessage("NOT NUMBER");
return true;
}
if (VaultOperations.openOtherVault(plr, owner, vaultId)) {
PlayerVaults.getInstance().getInVault().put(plr.getUniqueId().toString(), new VaultViewInfo(owner, number));
} else {
sender.sendMessage("FAILED!?");
}
}
}
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public ConvertCommand(PlayerVaults plugin) {
converters.add(new Cosmic2Converter());
converters.add(new Cosmic3Converter());
converters.add(new EnderVaultsConverter());
converters.add(new AxVaultsConverter());
this.plugin = plugin;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* 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.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
import org.bukkit.util.io.BukkitObjectInputStream;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.Field;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.*;
import java.util.logging.Level;

public class AxVaultsConverter implements Converter {

@SuppressWarnings("unchecked")
@Override
public int run(CommandSender initiator) {
PlayerVaults plugin = PlayerVaults.getInstance();
VaultManager vaultManager = VaultManager.getInstance();

Plugin axVaultsPlugin = plugin.getServer().getPluginManager().getPlugin("AxVaults");
Object database;

Set<String> uuids = new HashSet<>();

if (axVaultsPlugin == null) {
plugin.getLogger().warning("AxVaults not running. Need it to convert.");
return -1;
}
try {
Class<?> pluginClass = Class.forName("com.artillexstudios.axvaults.AxVaults");
Class<?> databaseClass = Class.forName("com.artillexstudios.axvaults.database.Database");

MethodHandles.Lookup lookup = MethodHandles.publicLookup();

MethodType typeGetDatabase = MethodType.methodType(databaseClass);
MethodHandle getDataStorage = lookup.findStatic(pluginClass, "getDatabase", typeGetDatabase);

database = getDataStorage.invoke();

Field field = database.getClass().getDeclaredField("conn");
field.setAccessible(true);

Object conn = field.get(database);

MethodType typePrepareStatement = MethodType.methodType(PreparedStatement.class, String.class);
MethodHandle prepareStatement = lookup.findVirtual(conn.getClass(), "prepareStatement", typePrepareStatement);

try (PreparedStatement statement = (PreparedStatement) prepareStatement.invoke(conn, "SELECT * FROM axvaults_data ORDER BY uuid ASC")) {
try (ResultSet resultSet = statement.executeQuery()) {
while (resultSet.next()) {
int id = resultSet.getInt("id");
String uuid = resultSet.getString("uuid");
uuids.add(uuid);
ItemStack[] items;
try (BukkitObjectInputStream dataInput = new BukkitObjectInputStream(resultSet.getBinaryStream("storage"))) {
items = (ItemStack[]) dataInput.readObject();
} catch (Exception e) {
initiator.getServer().getLogger().log(Level.WARNING, "Failed to load vault " + id + " for " + uuid, e);
continue;
}
Inventory inventory = Bukkit.createInventory(null, items.length % 9 == 0 ? items.length : (6 * 9), "Converting!");
inventory.setContents(items);
vaultManager.saveVault(inventory, uuid, id);
}
}
}

} catch (Throwable e) {
initiator.getServer().getLogger().log(Level.SEVERE, "Failed to convert vaults", e);
return -1;
}

return uuids.size();
}

@Override
public boolean canConvert() {
return Bukkit.getServer().getPluginManager().isPluginEnabled("AxVaults");
}

@Override
public String getName() {
return "AxVaults";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.bukkit.Material;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.kitteh.cardboardbox.CardboardBox;
import dev.kitteh.cardboardbox.CardboardBox;
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;

import java.io.ByteArrayInputStream;
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ commands:
pvhelpme:
description: Pastes debug info to get better assistance.
permission: playervaults.admin
pvconsole:
description: Console-only commands
permission: playervaults.console

permissions:
playervaults.admin:
Expand Down

0 comments on commit c83fd54

Please sign in to comment.