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;
|
||||
}
|
||||
|
||||
plugin.getMigrationManager().migrateKits(sender);
|
||||
plugin.getMigrationManager().migrate(sender);
|
||||
}
|
||||
|
||||
public void verify(Player player,FileConfiguration messagesConfig,MessagesManager msgManager){
|
||||
|
|
|
|||
|
|
@ -129,9 +129,7 @@ public class PlayersConfigManager {
|
|||
plugin.getPlayerDataManager().setPlayers(players);
|
||||
}
|
||||
|
||||
public void saveConfigs(){
|
||||
ArrayList<PlayerData> players = plugin.getPlayerDataManager().getPlayers();
|
||||
for(PlayerData playerData : players) {
|
||||
public void saveConfig(PlayerData playerData){
|
||||
String playerName = playerData.getName();
|
||||
CustomConfig playerConfig = getConfigFile(playerData.getUuid()+".yml");
|
||||
if(playerConfig == null) {
|
||||
|
|
@ -149,9 +147,15 @@ public class PlayersConfigManager {
|
|||
config.set("kits."+kitName+".one_time",playerDataKit.isOneTime());
|
||||
config.set("kits."+kitName+".bought",playerDataKit.isBought());
|
||||
}
|
||||
|
||||
playerConfig.saveConfig();
|
||||
}
|
||||
|
||||
saveConfigFiles();
|
||||
public void saveConfigs(){
|
||||
ArrayList<PlayerData> players = plugin.getPlayerDataManager().getPlayers();
|
||||
for(PlayerData playerData : players) {
|
||||
saveConfig(playerData);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@ package pk.ajneb97.managers;
|
|||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import pk.ajneb97.PlayerKits2;
|
||||
import pk.ajneb97.configs.KitsConfigManager;
|
||||
import pk.ajneb97.model.Kit;
|
||||
import pk.ajneb97.model.KitAction;
|
||||
import pk.ajneb97.model.KitRequirements;
|
||||
import pk.ajneb97.configs.PlayersConfigManager;
|
||||
import pk.ajneb97.model.*;
|
||||
import pk.ajneb97.model.item.KitItem;
|
||||
import pk.ajneb97.model.item.KitItemSkullData;
|
||||
|
||||
|
|
@ -21,6 +21,18 @@ public class MigrationManager {
|
|||
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){
|
||||
File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "PlayerKits");
|
||||
File configFile = new File(bStatsFolder, "kits.yml");
|
||||
|
|
@ -98,8 +110,50 @@ public class MigrationManager {
|
|||
return;
|
||||
}
|
||||
|
||||
plugin.getConfigsManager().reload();
|
||||
sender.sendMessage(PlayerKits2.prefix+MessagesManager.getColoredMessage(" &aMigration completed."));
|
||||
kitsConfigManager.reloadConfigs();
|
||||
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){
|
||||
|
|
@ -111,7 +165,7 @@ public class MigrationManager {
|
|||
KitItemSkullData skullData = null;
|
||||
if(config.contains(path+".display_item_skulldata")) {
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -2,11 +2,9 @@ package pk.ajneb97.utils;
|
|||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.FireworkEffect.Type;
|
||||
|
|
@ -32,8 +30,11 @@ import com.mojang.authlib.properties.Property;
|
|||
import com.mojang.authlib.properties.PropertyMap;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.chat.ComponentSerializer;
|
||||
import org.bukkit.profile.PlayerProfile;
|
||||
import org.bukkit.profile.PlayerTextures;
|
||||
import pk.ajneb97.PlayerKits2;
|
||||
import pk.ajneb97.model.item.*;
|
||||
import sun.misc.BASE64Decoder;
|
||||
|
||||
public class ItemUtils {
|
||||
|
||||
|
|
@ -154,6 +155,23 @@ public class ItemUtils {
|
|||
return;
|
||||
}
|
||||
|
||||
ServerVersion serverVersion = PlayerKits2.serverVersion;
|
||||
if(serverVersion.serverVersionGreaterEqualThan(serverVersion,ServerVersion.v1_20_R2)){
|
||||
UUID uuid = id != null ? UUID.fromString(id) : UUID.randomUUID();
|
||||
PlayerProfile profile = Bukkit.createPlayerProfile(uuid);
|
||||
PlayerTextures textures = profile.getTextures();
|
||||
URL url;
|
||||
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 : "");
|
||||
|
|
@ -169,6 +187,8 @@ public class ItemUtils {
|
|||
} catch (IllegalArgumentException | NoSuchFieldException | SecurityException | IllegalAccessException error) {
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
item.setItemMeta(skullMeta);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,9 +5,7 @@ import pk.ajneb97.PlayerKits2;
|
|||
import pk.ajneb97.utils.ServerVersion;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
public class NMSManager {
|
||||
|
||||
|
|
@ -186,13 +184,14 @@ public class NMSManager {
|
|||
if((boolean)version.getMethodRef("hasTag").invoke(newItem,null)){
|
||||
Object compound = version.getMethodRef("getTag").invoke(newItem,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) {
|
||||
if(!t.equals("ench") && !t.equals("HideFlags") && !t.equals("display")
|
||||
&& !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(!notTags.contains(t)) {
|
||||
if(t.equals("BlockEntityTag") && !item.getType().name().contains("SHULKER")){
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
main: pk.ajneb97.PlayerKits2
|
||||
version: 1.7.2
|
||||
version: 1.7.3
|
||||
name: PlayerKits2
|
||||
api-version: 1.13
|
||||
softdepend: [Vault,PlaceholderAPI]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue