1.7.3
This commit is contained in:
parent
c782e8d834
commit
fe88b6ae8f
6 changed files with 133 additions and 56 deletions
|
|
@ -123,7 +123,7 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.getMigrationManager().migrateKits(sender);
|
plugin.getMigrationManager().migrate(sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void verify(Player player,FileConfiguration messagesConfig,MessagesManager msgManager){
|
public void verify(Player player,FileConfiguration messagesConfig,MessagesManager msgManager){
|
||||||
|
|
|
||||||
|
|
@ -129,29 +129,33 @@ public class PlayersConfigManager {
|
||||||
plugin.getPlayerDataManager().setPlayers(players);
|
plugin.getPlayerDataManager().setPlayers(players);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void saveConfig(PlayerData playerData){
|
||||||
|
String playerName = playerData.getName();
|
||||||
|
CustomConfig playerConfig = getConfigFile(playerData.getUuid()+".yml");
|
||||||
|
if(playerConfig == null) {
|
||||||
|
registerConfigFile(playerData.getUuid()+".yml");
|
||||||
|
playerConfig = getConfigFile(playerData.getUuid()+".yml");
|
||||||
|
}
|
||||||
|
FileConfiguration config = playerConfig.getConfig();
|
||||||
|
|
||||||
|
config.set("name", playerName);
|
||||||
|
config.set("kits",null);
|
||||||
|
|
||||||
|
for(PlayerDataKit playerDataKit : playerData.getKits()){
|
||||||
|
String kitName = playerDataKit.getName();
|
||||||
|
config.set("kits."+kitName+".cooldown",playerDataKit.getCooldown());
|
||||||
|
config.set("kits."+kitName+".one_time",playerDataKit.isOneTime());
|
||||||
|
config.set("kits."+kitName+".bought",playerDataKit.isBought());
|
||||||
|
}
|
||||||
|
|
||||||
|
playerConfig.saveConfig();
|
||||||
|
}
|
||||||
|
|
||||||
public void saveConfigs(){
|
public void saveConfigs(){
|
||||||
ArrayList<PlayerData> players = plugin.getPlayerDataManager().getPlayers();
|
ArrayList<PlayerData> players = plugin.getPlayerDataManager().getPlayers();
|
||||||
for(PlayerData playerData : players) {
|
for(PlayerData playerData : players) {
|
||||||
String playerName = playerData.getName();
|
saveConfig(playerData);
|
||||||
CustomConfig playerConfig = getConfigFile(playerData.getUuid()+".yml");
|
|
||||||
if(playerConfig == null) {
|
|
||||||
registerConfigFile(playerData.getUuid()+".yml");
|
|
||||||
playerConfig = getConfigFile(playerData.getUuid()+".yml");
|
|
||||||
}
|
|
||||||
FileConfiguration config = playerConfig.getConfig();
|
|
||||||
|
|
||||||
config.set("name", playerName);
|
|
||||||
config.set("kits",null);
|
|
||||||
|
|
||||||
for(PlayerDataKit playerDataKit : playerData.getKits()){
|
|
||||||
String kitName = playerDataKit.getName();
|
|
||||||
config.set("kits."+kitName+".cooldown",playerDataKit.getCooldown());
|
|
||||||
config.set("kits."+kitName+".one_time",playerDataKit.isOneTime());
|
|
||||||
config.set("kits."+kitName+".bought",playerDataKit.isBought());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
saveConfigFiles();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,11 @@ package pk.ajneb97.managers;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
import pk.ajneb97.PlayerKits2;
|
import pk.ajneb97.PlayerKits2;
|
||||||
import pk.ajneb97.configs.KitsConfigManager;
|
import pk.ajneb97.configs.KitsConfigManager;
|
||||||
import pk.ajneb97.model.Kit;
|
import pk.ajneb97.configs.PlayersConfigManager;
|
||||||
import pk.ajneb97.model.KitAction;
|
import pk.ajneb97.model.*;
|
||||||
import pk.ajneb97.model.KitRequirements;
|
|
||||||
import pk.ajneb97.model.item.KitItem;
|
import pk.ajneb97.model.item.KitItem;
|
||||||
import pk.ajneb97.model.item.KitItemSkullData;
|
import pk.ajneb97.model.item.KitItemSkullData;
|
||||||
|
|
||||||
|
|
@ -21,6 +21,18 @@ public class MigrationManager {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void migrate(CommandSender sender){
|
||||||
|
new BukkitRunnable(){
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
migrateKits(sender);
|
||||||
|
migratePlayers(sender);
|
||||||
|
|
||||||
|
sender.sendMessage(PlayerKits2.prefix+MessagesManager.getColoredMessage(" &aMigration completed."));
|
||||||
|
}
|
||||||
|
}.runTaskAsynchronously(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
public void migrateKits(CommandSender sender){
|
public void migrateKits(CommandSender sender){
|
||||||
File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "PlayerKits");
|
File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "PlayerKits");
|
||||||
File configFile = new File(bStatsFolder, "kits.yml");
|
File configFile = new File(bStatsFolder, "kits.yml");
|
||||||
|
|
@ -98,8 +110,50 @@ public class MigrationManager {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.getConfigsManager().reload();
|
kitsConfigManager.reloadConfigs();
|
||||||
sender.sendMessage(PlayerKits2.prefix+MessagesManager.getColoredMessage(" &aMigration completed."));
|
plugin.getVerifyManager().verify();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void migratePlayers(CommandSender sender){
|
||||||
|
File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "PlayerKits");
|
||||||
|
File configFile = new File(bStatsFolder, "players.yml");
|
||||||
|
if(!configFile.exists()){
|
||||||
|
sender.sendMessage(PlayerKits2.prefix+MessagesManager.getColoredMessage(" &cPlayerKits1 players.yml file not found."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
|
||||||
|
PlayersConfigManager playersConfigManager = plugin.getConfigsManager().getPlayersConfigManager();
|
||||||
|
|
||||||
|
if(config.contains("Players")) {
|
||||||
|
for (String uuid : config.getConfigurationSection("Players").getKeys(false)) {
|
||||||
|
try {
|
||||||
|
String path = "Players."+uuid;
|
||||||
|
String name = config.getString(path+".name");
|
||||||
|
PlayerData playerData = new PlayerData(name,uuid);
|
||||||
|
for(String kitName : config.getConfigurationSection(path).getKeys(false)){
|
||||||
|
if(kitName.equals("name")){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
PlayerDataKit playerDataKit = new PlayerDataKit(kitName);
|
||||||
|
playerDataKit.setBought(config.getBoolean(path+"."+kitName+".buyed"));
|
||||||
|
playerDataKit.setCooldown(config.getLong(path+"."+kitName+".cooldown"));
|
||||||
|
playerDataKit.setOneTime(config.getBoolean(path+"."+kitName+".one_time"));
|
||||||
|
playerData.addKit(playerDataKit);
|
||||||
|
}
|
||||||
|
|
||||||
|
playersConfigManager.saveConfig(playerData);
|
||||||
|
|
||||||
|
sender.sendMessage(PlayerKits2.prefix+MessagesManager.getColoredMessage(" &aPlayer &7"+name+" &amigrated."));
|
||||||
|
} catch (Exception e) {
|
||||||
|
sender.sendMessage(PlayerKits2.prefix + MessagesManager.getColoredMessage(" &cError while trying to migrate player data with uuid &7" + uuid + "&c, check console."));
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
playersConfigManager.reloadConfigs();
|
||||||
}
|
}
|
||||||
|
|
||||||
public KitItem getDisplayItem(YamlConfiguration config,String path){
|
public KitItem getDisplayItem(YamlConfiguration config,String path){
|
||||||
|
|
@ -111,7 +165,7 @@ public class MigrationManager {
|
||||||
KitItemSkullData skullData = null;
|
KitItemSkullData skullData = null;
|
||||||
if(config.contains(path+".display_item_skulldata")) {
|
if(config.contains(path+".display_item_skulldata")) {
|
||||||
String[] fullSkull = config.getString(path+".display_item_skulldata").split(";");
|
String[] fullSkull = config.getString(path+".display_item_skulldata").split(";");
|
||||||
skullData = new KitItemSkullData(null,fullSkull[0],fullSkull[1]);
|
skullData = new KitItemSkullData(null,fullSkull[1],fullSkull[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
kitItem.setName(name);
|
kitItem.setName(name);
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,9 @@ package pk.ajneb97.utils;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.ArrayList;
|
import java.net.MalformedURLException;
|
||||||
import java.util.Collection;
|
import java.net.URL;
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
import org.bukkit.FireworkEffect.Type;
|
import org.bukkit.FireworkEffect.Type;
|
||||||
|
|
@ -32,8 +30,11 @@ import com.mojang.authlib.properties.Property;
|
||||||
import com.mojang.authlib.properties.PropertyMap;
|
import com.mojang.authlib.properties.PropertyMap;
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
import net.md_5.bungee.chat.ComponentSerializer;
|
import net.md_5.bungee.chat.ComponentSerializer;
|
||||||
|
import org.bukkit.profile.PlayerProfile;
|
||||||
|
import org.bukkit.profile.PlayerTextures;
|
||||||
import pk.ajneb97.PlayerKits2;
|
import pk.ajneb97.PlayerKits2;
|
||||||
import pk.ajneb97.model.item.*;
|
import pk.ajneb97.model.item.*;
|
||||||
|
import sun.misc.BASE64Decoder;
|
||||||
|
|
||||||
public class ItemUtils {
|
public class ItemUtils {
|
||||||
|
|
||||||
|
|
@ -154,21 +155,40 @@ public class ItemUtils {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GameProfile profile = null;
|
ServerVersion serverVersion = PlayerKits2.serverVersion;
|
||||||
if(id == null) {
|
if(serverVersion.serverVersionGreaterEqualThan(serverVersion,ServerVersion.v1_20_R2)){
|
||||||
profile = new GameProfile(UUID.randomUUID(), owner != null ? owner : "");
|
UUID uuid = id != null ? UUID.fromString(id) : UUID.randomUUID();
|
||||||
}else {
|
PlayerProfile profile = Bukkit.createPlayerProfile(uuid);
|
||||||
profile = new GameProfile(UUID.fromString(id), owner != null ? owner : "");
|
PlayerTextures textures = profile.getTextures();
|
||||||
}
|
URL url;
|
||||||
profile.getProperties().put("textures", new Property("textures", texture));
|
try {
|
||||||
|
String decoded = new String(Base64.getDecoder().decode(texture));
|
||||||
|
url = new URL(decoded.substring("{\"textures\":{\"SKIN\":{\"url\":\"".length(), decoded.length() - "\"}}}".length()));
|
||||||
|
} catch (MalformedURLException error) {
|
||||||
|
error.printStackTrace();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
textures.setSkin(url);
|
||||||
|
profile.setTextures(textures);
|
||||||
|
skullMeta.setOwnerProfile(profile);
|
||||||
|
}else{
|
||||||
|
GameProfile profile = null;
|
||||||
|
if(id == null) {
|
||||||
|
profile = new GameProfile(UUID.randomUUID(), owner != null ? owner : "");
|
||||||
|
}else {
|
||||||
|
profile = new GameProfile(UUID.fromString(id), owner != null ? owner : "");
|
||||||
|
}
|
||||||
|
profile.getProperties().put("textures", new Property("textures", texture));
|
||||||
|
|
||||||
|
try {
|
||||||
|
Field profileField = skullMeta.getClass().getDeclaredField("profile");
|
||||||
|
profileField.setAccessible(true);
|
||||||
|
profileField.set(skullMeta, profile);
|
||||||
|
} catch (IllegalArgumentException | NoSuchFieldException | SecurityException | IllegalAccessException error) {
|
||||||
|
error.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
Field profileField = skullMeta.getClass().getDeclaredField("profile");
|
|
||||||
profileField.setAccessible(true);
|
|
||||||
profileField.set(skullMeta, profile);
|
|
||||||
} catch (IllegalArgumentException|NoSuchFieldException|SecurityException|IllegalAccessException error) {
|
|
||||||
error.printStackTrace();
|
|
||||||
}
|
|
||||||
item.setItemMeta(skullMeta);
|
item.setItemMeta(skullMeta);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,7 @@ import pk.ajneb97.PlayerKits2;
|
||||||
import pk.ajneb97.utils.ServerVersion;
|
import pk.ajneb97.utils.ServerVersion;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class NMSManager {
|
public class NMSManager {
|
||||||
|
|
||||||
|
|
@ -186,13 +184,14 @@ public class NMSManager {
|
||||||
if((boolean)version.getMethodRef("hasTag").invoke(newItem,null)){
|
if((boolean)version.getMethodRef("hasTag").invoke(newItem,null)){
|
||||||
Object compound = version.getMethodRef("getTag").invoke(newItem,null);
|
Object compound = version.getMethodRef("getTag").invoke(newItem,null);
|
||||||
Set<String> tags = (Set<String>) version.getMethodRef("getKeys").invoke(compound,null);
|
Set<String> tags = (Set<String>) version.getMethodRef("getKeys").invoke(compound,null);
|
||||||
|
Set<String> notTags = new HashSet<>(Arrays.asList(
|
||||||
|
"ench", "HideFlags", "display", "SkullOwner", "AttributeModifiers", "Enchantments",
|
||||||
|
"Damage", "CustomModelData", "Potion", "StoredEnchantments", "CustomPotionColor",
|
||||||
|
"CustomPotionEffects", "Fireworks", "Explosion", "pages", "title", "author", "resolved",
|
||||||
|
"generation", "Trim", "custom_potion_effects"
|
||||||
|
));
|
||||||
for(String t : tags) {
|
for(String t : tags) {
|
||||||
if(!t.equals("ench") && !t.equals("HideFlags") && !t.equals("display")
|
if(!notTags.contains(t)) {
|
||||||
&& !t.equals("SkullOwner") && !t.equals("AttributeModifiers")
|
|
||||||
&& !t.equals("Enchantments") && !t.equals("Damage") && !t.equals("CustomModelData") && !t.equals("Potion")
|
|
||||||
&& !t.equals("StoredEnchantments") && !t.equals("CustomPotionColor") && !t.equals("CustomPotionEffects") && !t.equals("Fireworks")
|
|
||||||
&& !t.equals("Explosion")&& !t.equals("pages") && !t.equals("title") && !t.equals("author") && !t.equals("resolved")
|
|
||||||
&& !t.equals("generation") && !t.equals("Trim")) {
|
|
||||||
if(t.equals("BlockEntityTag") && !item.getType().name().contains("SHULKER")){
|
if(t.equals("BlockEntityTag") && !item.getType().name().contains("SHULKER")){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
main: pk.ajneb97.PlayerKits2
|
main: pk.ajneb97.PlayerKits2
|
||||||
version: 1.7.2
|
version: 1.7.3
|
||||||
name: PlayerKits2
|
name: PlayerKits2
|
||||||
api-version: 1.13
|
api-version: 1.13
|
||||||
softdepend: [Vault,PlaceholderAPI]
|
softdepend: [Vault,PlaceholderAPI]
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue