forked from drtshock/PlayerVaults
-
Notifications
You must be signed in to change notification settings - Fork 0
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
7 changed files
with
236 additions
and
14 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
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
90 changes: 90 additions & 0 deletions
90
src/main/java/com/drtshock/playervaults/commands/ConsoleCommand.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,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; | ||
} | ||
} |
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
112 changes: 112 additions & 0 deletions
112
src/main/java/com/drtshock/playervaults/converters/AxVaultsConverter.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,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"; | ||
} | ||
} |
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
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