1.17.1
This commit is contained in:
parent
dfd0cd597f
commit
151a8d011d
10 changed files with 138 additions and 147 deletions
|
|
@ -7,11 +7,6 @@ import pk.ajneb97.model.inventory.ItemKitInventory;
|
|||
import pk.ajneb97.model.inventory.KitInventory;
|
||||
import pk.ajneb97.model.item.KitItem;
|
||||
import pk.ajneb97.utils.OtherUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -28,6 +23,7 @@ public class InventoryConfigManager {
|
|||
if(this.configFile.isFirstTime() && OtherUtils.isLegacy()){
|
||||
checkAndFix();
|
||||
}
|
||||
checkClickCommands();
|
||||
}
|
||||
|
||||
public void checkAndFix(){
|
||||
|
|
@ -39,6 +35,38 @@ public class InventoryConfigManager {
|
|||
configFile.saveConfig();
|
||||
}
|
||||
|
||||
public void checkClickCommands(){
|
||||
boolean needsSave = false;
|
||||
FileConfiguration config = configFile.getConfig();
|
||||
if(config.contains("inventories")) {
|
||||
for (String key : config.getConfigurationSection("inventories").getKeys(false)) {
|
||||
for(String slotString : config.getConfigurationSection("inventories."+key).getKeys(false)) {
|
||||
String path = "inventories."+key+"."+slotString;
|
||||
if(config.contains(path+".click_commands")){
|
||||
List<String> clickActions = new ArrayList<>();
|
||||
List<String> clickCommands = config.getStringList(path+".click_commands");
|
||||
for(String c : clickCommands){
|
||||
if(c.startsWith("msg %player% ")) {
|
||||
String text = c.replace("msg %player% ", "");
|
||||
clickActions.add("message: "+text);
|
||||
}else if(c.equals("close_inventory")){
|
||||
clickActions.add(c);
|
||||
}else{
|
||||
clickActions.add("console_command: "+c);
|
||||
}
|
||||
}
|
||||
config.set(path+".click_actions",clickActions);
|
||||
needsSave = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(needsSave){
|
||||
configFile.saveConfig();
|
||||
}
|
||||
}
|
||||
|
||||
public void configure(){
|
||||
FileConfiguration config = configFile.getConfig();
|
||||
|
||||
|
|
@ -46,7 +74,7 @@ public class InventoryConfigManager {
|
|||
KitItemManager kitItemManager = plugin.getKitItemManager();
|
||||
if(config.contains("inventories")) {
|
||||
for(String key : config.getConfigurationSection("inventories").getKeys(false)) {
|
||||
int slots = Integer.valueOf(config.getString("inventories."+key+".slots"));
|
||||
int slots = config.getInt("inventories."+key+".slots");
|
||||
String title = config.getString("inventories."+key+".title");
|
||||
|
||||
List<ItemKitInventory> items = new ArrayList<>();
|
||||
|
|
@ -61,13 +89,13 @@ public class InventoryConfigManager {
|
|||
String openInventory = config.contains(path+".open_inventory") ?
|
||||
config.getString(path+".open_inventory") : null;
|
||||
|
||||
List<String> commands = config.contains(path+".click_commands") ?
|
||||
config.getStringList(path+".click_commands") : null;
|
||||
List<String> clickActions = config.contains(path+".click_actions") ?
|
||||
config.getStringList(path+".click_actions") : null;
|
||||
|
||||
String type = config.contains(path+".type") ?
|
||||
config.getString(path+".type") : null;
|
||||
|
||||
ItemKitInventory itemCraft = new ItemKitInventory(slotString,item,openInventory,commands,type);
|
||||
ItemKitInventory itemCraft = new ItemKitInventory(slotString,item,openInventory,clickActions,type);
|
||||
items.add(itemCraft);
|
||||
}
|
||||
}
|
||||
|
|
@ -108,8 +136,8 @@ public class InventoryConfigManager {
|
|||
if(item.getOpenInventory() != null){
|
||||
config.set(path+".open_inventory",item.getOpenInventory());
|
||||
}
|
||||
if(item.getCommands() != null && !item.getCommands().isEmpty()){
|
||||
config.set(path+".click_commands",item.getCommands());
|
||||
if(item.getClickActions() != null && !item.getClickActions().isEmpty()){
|
||||
config.set(path+".click_actions",item.getClickActions());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -128,21 +156,4 @@ public class InventoryConfigManager {
|
|||
public FileConfiguration getConfig(){
|
||||
return configFile.getConfig();
|
||||
}
|
||||
|
||||
public void checkUpdate(){
|
||||
Path pathConfig = Paths.get(configFile.getRoute());
|
||||
try{
|
||||
String text = new String(Files.readAllBytes(pathConfig));
|
||||
/*
|
||||
if(!text.contains("register_commands:")){
|
||||
List<String> commands = new ArrayList<>();
|
||||
getConfig().set("Config.register_commands", commands);
|
||||
saveConfig();
|
||||
}
|
||||
*/
|
||||
}catch(IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,24 +12,16 @@ import java.util.Map;
|
|||
import java.util.UUID;
|
||||
|
||||
public class PlayersConfigManager {
|
||||
private ArrayList<CustomConfig> configFiles;
|
||||
private String folderName;
|
||||
private PlayerKits2 plugin;
|
||||
|
||||
public PlayersConfigManager(PlayerKits2 plugin, String folderName){
|
||||
this.plugin = plugin;
|
||||
this.folderName = folderName;
|
||||
this.configFiles = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void configure() {
|
||||
createFolder();
|
||||
reloadConfigs();
|
||||
}
|
||||
|
||||
public void reloadConfigs(){
|
||||
this.configFiles = new ArrayList<>();
|
||||
registerConfigFiles();
|
||||
loadConfigs();
|
||||
}
|
||||
|
||||
|
|
@ -45,89 +37,50 @@ public class PlayersConfigManager {
|
|||
}
|
||||
}
|
||||
|
||||
public void saveConfigFiles() {
|
||||
for(int i=0;i<configFiles.size();i++) {
|
||||
configFiles.get(i).saveConfig();
|
||||
}
|
||||
}
|
||||
|
||||
public void registerConfigFiles(){
|
||||
String path = plugin.getDataFolder() + File.separator + folderName;
|
||||
File folder = new File(path);
|
||||
File[] listOfFiles = folder.listFiles();
|
||||
for (int i=0;i<listOfFiles.length;i++) {
|
||||
if(listOfFiles[i].isFile()) {
|
||||
String pathName = listOfFiles[i].getName();
|
||||
CustomConfig config = new CustomConfig(pathName, plugin, folderName, true);
|
||||
config.registerConfig();
|
||||
configFiles.add(config);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<CustomConfig> getConfigs(){
|
||||
return this.configFiles;
|
||||
}
|
||||
|
||||
public boolean fileAlreadyRegistered(String pathName) {
|
||||
for(int i=0;i<configFiles.size();i++) {
|
||||
if(configFiles.get(i).getPath().equals(pathName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public CustomConfig getConfigFile(String pathName) {
|
||||
for(int i=0;i<configFiles.size();i++) {
|
||||
if(configFiles.get(i).getPath().equals(pathName)) {
|
||||
return configFiles.get(i);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean registerConfigFile(String pathName) {
|
||||
if(!fileAlreadyRegistered(pathName)) {
|
||||
CustomConfig config = new CustomConfig(pathName, plugin, folderName, true);
|
||||
config.registerConfig();
|
||||
configFiles.add(config);
|
||||
return true;
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
CustomConfig config = new CustomConfig(pathName, plugin, folderName, true);
|
||||
config.registerConfig();
|
||||
return config;
|
||||
}
|
||||
|
||||
public void loadConfigs(){
|
||||
Map<UUID, PlayerData> players = new HashMap<>();
|
||||
|
||||
for(CustomConfig configFile : configFiles) {
|
||||
FileConfiguration config = configFile.getConfig();
|
||||
String path = plugin.getDataFolder() + File.separator + folderName;
|
||||
File folder = new File(path);
|
||||
File[] listOfFiles = folder.listFiles();
|
||||
for (File file : listOfFiles) {
|
||||
if (file.isFile()) {
|
||||
String pathName = file.getName();
|
||||
CustomConfig configFile = new CustomConfig(pathName, plugin, folderName, true);
|
||||
configFile.registerConfig();
|
||||
|
||||
String uuidString = configFile.getPath().replace(".yml", "");
|
||||
String name = config.getString("name");
|
||||
ArrayList<PlayerDataKit> playerDataKits = new ArrayList<>();
|
||||
FileConfiguration config = configFile.getConfig();
|
||||
String uuidString = configFile.getPath().replace(".yml", "");
|
||||
String name = config.getString("name");
|
||||
ArrayList<PlayerDataKit> playerDataKits = new ArrayList<>();
|
||||
|
||||
if(config.contains("kits")){
|
||||
for(String key : config.getConfigurationSection("kits").getKeys(false)){
|
||||
long cooldown = config.getLong("kits."+key+".cooldown");
|
||||
boolean oneTime = config.getBoolean("kits."+key+".one_time");
|
||||
boolean bought = config.getBoolean("kits."+key+".bought");
|
||||
if (config.contains("kits")) {
|
||||
for (String key : config.getConfigurationSection("kits").getKeys(false)) {
|
||||
long cooldown = config.getLong("kits." + key + ".cooldown");
|
||||
boolean oneTime = config.getBoolean("kits." + key + ".one_time");
|
||||
boolean bought = config.getBoolean("kits." + key + ".bought");
|
||||
|
||||
PlayerDataKit playerDataKit = new PlayerDataKit(key);
|
||||
playerDataKit.setCooldown(cooldown);
|
||||
playerDataKit.setOneTime(oneTime);
|
||||
playerDataKit.setBought(bought);
|
||||
PlayerDataKit playerDataKit = new PlayerDataKit(key);
|
||||
playerDataKit.setCooldown(cooldown);
|
||||
playerDataKit.setOneTime(oneTime);
|
||||
playerDataKit.setBought(bought);
|
||||
|
||||
playerDataKits.add(playerDataKit);
|
||||
playerDataKits.add(playerDataKit);
|
||||
}
|
||||
}
|
||||
|
||||
UUID uuid = UUID.fromString(uuidString);
|
||||
PlayerData playerData = new PlayerData(uuid, name);
|
||||
playerData.setKits(playerDataKits);
|
||||
|
||||
players.put(uuid, playerData);
|
||||
}
|
||||
|
||||
UUID uuid = UUID.fromString(uuidString);
|
||||
PlayerData playerData = new PlayerData(uuid,name);
|
||||
playerData.setKits(playerDataKits);
|
||||
|
||||
players.put(uuid,playerData);
|
||||
}
|
||||
|
||||
plugin.getPlayerDataManager().setPlayers(players);
|
||||
|
|
@ -136,10 +89,6 @@ public class PlayersConfigManager {
|
|||
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);
|
||||
|
|
|
|||
|
|
@ -20,10 +20,12 @@ import pk.ajneb97.model.inventory.InventoryPlayer;
|
|||
import pk.ajneb97.model.inventory.ItemKitInventory;
|
||||
import pk.ajneb97.model.inventory.KitInventory;
|
||||
import pk.ajneb97.model.item.KitItem;
|
||||
import pk.ajneb97.utils.ActionUtils;
|
||||
import pk.ajneb97.utils.ItemUtils;
|
||||
import pk.ajneb97.utils.PlayerUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class InventoryManager {
|
||||
|
|
@ -94,7 +96,6 @@ public class InventoryManager {
|
|||
KitItemManager kitItemManager = plugin.getKitItemManager();
|
||||
KitsManager kitsManager = plugin.getKitsManager();
|
||||
PlayerDataManager playerDataManager = plugin.getPlayerDataManager();
|
||||
MessagesManager msgManager = plugin.getMessagesManager();
|
||||
|
||||
//Add items for all inventories
|
||||
for(ItemKitInventory itemInventory : items){
|
||||
|
|
@ -102,7 +103,7 @@ public class InventoryManager {
|
|||
String type = itemInventory.getType();
|
||||
if(type != null && type.startsWith("kit: ")){
|
||||
setKit(type.replace("kit: ",""),inventoryPlayer.getPlayer(),inv,slot,kitsManager
|
||||
,playerDataManager,kitItemManager,msgManager);
|
||||
,playerDataManager,kitItemManager);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -119,18 +120,7 @@ public class InventoryManager {
|
|||
if(openInventory != null) {
|
||||
item = ItemUtils.setTagStringItem(plugin,item, "playerkits_open_inventory", openInventory);
|
||||
}
|
||||
List<String> commands = itemInventory.getCommands();
|
||||
if(commands != null && !commands.isEmpty()) {
|
||||
String commandList = "";
|
||||
for(int i=0;i<commands.size();i++) {
|
||||
if(i==commands.size()-1) {
|
||||
commandList=commandList+commands.get(i);
|
||||
}else {
|
||||
commandList=commandList+commands.get(i)+"|";
|
||||
}
|
||||
}
|
||||
item = ItemUtils.setTagStringItem(plugin,item, "playerkits_item_commands", commandList);
|
||||
}
|
||||
item = setItemActions(itemInventory,item);
|
||||
|
||||
inv.setItem(slot,item);
|
||||
}
|
||||
|
|
@ -146,6 +136,22 @@ public class InventoryManager {
|
|||
players.add(inventoryPlayer);
|
||||
}
|
||||
|
||||
private ItemStack setItemActions(ItemKitInventory itemInventory, ItemStack item) {
|
||||
List<String> clickActions = itemInventory.getClickActions();
|
||||
if(clickActions != null && !clickActions.isEmpty()) {
|
||||
String actionsList = "";
|
||||
for(int i=0;i<clickActions.size();i++) {
|
||||
if(i==clickActions.size()-1) {
|
||||
actionsList=actionsList+clickActions.get(i);
|
||||
}else {
|
||||
actionsList=actionsList+clickActions.get(i)+"|";
|
||||
}
|
||||
}
|
||||
item = ItemUtils.setTagStringItem(plugin, item, "playerkits_item_actions", actionsList);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
public void setKitPreviewItems(Inventory inv,InventoryPlayer inventoryPlayer,KitInventory kitInventory){
|
||||
KitItemManager kitItemManager = plugin.getKitItemManager();
|
||||
KitsManager kitsManager = plugin.getKitsManager();
|
||||
|
|
@ -188,17 +194,17 @@ public class InventoryManager {
|
|||
return;
|
||||
}
|
||||
|
||||
String itemActions = ItemUtils.getTagStringItem(plugin,item,"playerkits_item_actions");
|
||||
if(itemActions != null){
|
||||
clickOnActionItem(inventoryPlayer,itemActions);
|
||||
}
|
||||
|
||||
String openInventory = ItemUtils.getTagStringItem(plugin,item,"playerkits_open_inventory");
|
||||
if(openInventory != null){
|
||||
clickOnOpenInventoryItem(inventoryPlayer,openInventory);
|
||||
return;
|
||||
}
|
||||
|
||||
String itemCommands = ItemUtils.getTagStringItem(plugin,item,"playerkits_item_commands");
|
||||
if(itemCommands != null){
|
||||
clickOnCommandItem(inventoryPlayer,itemCommands);
|
||||
}
|
||||
|
||||
//Requirements inventory
|
||||
if(inventoryPlayer.getInventoryName().equals("buy_requirements_inventory")){
|
||||
String buyTag = ItemUtils.getTagStringItem(plugin,item,"playerkits_buy");
|
||||
|
|
@ -289,8 +295,18 @@ public class InventoryManager {
|
|||
}
|
||||
}
|
||||
|
||||
public void clickOnActionItem(InventoryPlayer inventoryPlayer,String itemActions) {
|
||||
String[] sep = itemActions.split("\\|");
|
||||
|
||||
KitsManager kitsManager = plugin.getKitsManager();
|
||||
Player player = inventoryPlayer.getPlayer();
|
||||
for(String action : sep){
|
||||
kitsManager.executeAction(player,action);
|
||||
}
|
||||
}
|
||||
|
||||
public void setKit(String kitName, Player player, Inventory inv, int slot, KitsManager kitsManager, PlayerDataManager playerDataManager
|
||||
,KitItemManager kitItemManager,MessagesManager msgManager){
|
||||
,KitItemManager kitItemManager){
|
||||
Kit kit = kitsManager.getKitByName(kitName);
|
||||
if(kit == null){
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -377,12 +377,19 @@ public class KitsManager {
|
|||
}
|
||||
|
||||
public void executeAction(Player player,String actionText){
|
||||
if(actionText.equals("close_inventory")){
|
||||
ActionUtils.closeInventory(player);
|
||||
return;
|
||||
}
|
||||
int indexFirst = actionText.indexOf(" ");
|
||||
String actionType = actionText.substring(0,indexFirst).replace(":","");
|
||||
String actionLine = actionText.substring(indexFirst+1);
|
||||
actionLine = OtherUtils.replaceGlobalVariables(actionLine,player,plugin);
|
||||
|
||||
switch(actionType){
|
||||
case "message":
|
||||
ActionUtils.message(player,actionLine);
|
||||
break;
|
||||
case "console_command":
|
||||
ActionUtils.consoleCommand(actionLine);
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -154,7 +154,7 @@ public class MigrationManager {
|
|||
}
|
||||
}
|
||||
|
||||
playersConfigManager.reloadConfigs();
|
||||
playersConfigManager.configure();
|
||||
}
|
||||
|
||||
public KitItem getDisplayItem(YamlConfiguration config,String path){
|
||||
|
|
|
|||
|
|
@ -112,7 +112,8 @@ public class VerifyManager {
|
|||
String actionName = actionText[0];
|
||||
if(actionName.equals("console_command:") || actionName.equals("player_command:")
|
||||
|| actionName.equals("playsound:") || actionName.equals("actionbar:")
|
||||
|| actionName.equals("title:") || actionName.equals("firework:")){
|
||||
|| actionName.equals("title:") || actionName.equals("firework:")
|
||||
|| actionName.equals("close_inventory") || actionName.equals("message:")){
|
||||
continue;
|
||||
}
|
||||
errors.add(new PKKitActionError(kitName+".yml",action.getAction(),false,kitName,actionGroup,(i+1)+""));
|
||||
|
|
|
|||
|
|
@ -10,10 +10,10 @@ public class ItemKitInventory {
|
|||
private String slotsString;
|
||||
private KitItem item;
|
||||
private String openInventory;
|
||||
private List<String> commands;
|
||||
private List<String> clickActions;
|
||||
private String type;
|
||||
|
||||
public ItemKitInventory(String slotsString, KitItem item, String openInventory, List<String> commands, String type) {
|
||||
public ItemKitInventory(String slotsString, KitItem item, String openInventory, List<String> clickActions, String type) {
|
||||
slots = new ArrayList<>();
|
||||
this.slotsString = slotsString;
|
||||
String[] slotsSep = slotsString.split(";");
|
||||
|
|
@ -32,7 +32,7 @@ public class ItemKitInventory {
|
|||
|
||||
this.item = item;
|
||||
this.openInventory = openInventory;
|
||||
this.commands = commands;
|
||||
this.clickActions = clickActions;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
|
@ -60,14 +60,6 @@ public class ItemKitInventory {
|
|||
this.openInventory = openInventory;
|
||||
}
|
||||
|
||||
public List<String> getCommands() {
|
||||
return commands;
|
||||
}
|
||||
|
||||
public void setCommands(List<String> commands) {
|
||||
this.commands = commands;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
|
@ -83,4 +75,12 @@ public class ItemKitInventory {
|
|||
public void setSlotsString(String slotsString) {
|
||||
this.slotsString = slotsString;
|
||||
}
|
||||
|
||||
public List<String> getClickActions() {
|
||||
return clickActions;
|
||||
}
|
||||
|
||||
public void setClickActions(List<String> clickActions) {
|
||||
this.clickActions = clickActions;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ public class InventoryUpdateTaskManager {
|
|||
public void execute(){
|
||||
InventoryManager inventoryManager = plugin.getInventoryManager();
|
||||
KitsManager kitsManager = plugin.getKitsManager();
|
||||
MessagesManager msgManager = plugin.getMessagesManager();
|
||||
PlayerDataManager playerDataManager = plugin.getPlayerDataManager();
|
||||
KitItemManager kitItemManager = plugin.getKitItemManager();
|
||||
|
||||
|
|
@ -51,7 +50,7 @@ public class InventoryUpdateTaskManager {
|
|||
String kitName = ItemUtils.getTagStringItem(plugin,item,"playerkits_kit");
|
||||
if(kitName != null){
|
||||
inventoryManager.setKit(kitName,player.getPlayer(),inv,i,kitsManager,
|
||||
playerDataManager,kitItemManager,msgManager);
|
||||
playerDataManager,kitItemManager);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,10 @@ import java.util.ArrayList;
|
|||
|
||||
public class ActionUtils {
|
||||
|
||||
public static void message(Player player,String actionLine) {
|
||||
player.sendMessage(MessagesManager.getColoredMessage(actionLine));
|
||||
}
|
||||
|
||||
public static void consoleCommand(String actionLine){
|
||||
ConsoleCommandSender sender = Bukkit.getConsoleSender();
|
||||
Bukkit.dispatchCommand(sender, actionLine);
|
||||
|
|
@ -129,4 +133,8 @@ public class ActionUtils {
|
|||
firework.setFireworkMeta(fireworkMeta);
|
||||
firework.setMetadata("playerkits", new FixedMetadataValue(plugin, "no_damage"));
|
||||
}
|
||||
|
||||
public static void closeInventory(Player player) {
|
||||
player.closeInventory();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
main: pk.ajneb97.PlayerKits2
|
||||
version: 1.16.1
|
||||
version: 1.17.1
|
||||
name: PlayerKits2
|
||||
api-version: 1.13
|
||||
softdepend: [Vault,PlaceholderAPI]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue