Added ShopManager

This commit is contained in:
Niels Vergucht 2018-11-30 23:20:36 +01:00
parent f71b0ecabc
commit 9a970de01a
9 changed files with 145 additions and 42 deletions

View File

@ -52,8 +52,17 @@
<id>vault</id>
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
</repository>
<repository>
<id>aikar</id>
<url>https://repo.aikar.co/content/groups/aikar/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>co.aikar</groupId>
<artifactId>acf-bukkit</artifactId>
<version>0.5.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>me.lucko</groupId>
<artifactId>helper</artifactId>

View File

@ -1,16 +1,24 @@
package com.songoda.epicbuckets;
import com.songoda.epicbuckets.file.ConfigManager;
import com.songoda.epicbuckets.shop.ShopManager;
import org.bukkit.plugin.java.JavaPlugin;
public class EpicBuckets extends JavaPlugin {
private static EpicBuckets instance;
private ConfigManager configManager;
private ShopManager shopManager;
public static EpicBuckets getInstance() { return instance; }
@Override
public void onEnable() {
instance = this;
configManager = new ConfigManager();
shopManager = new ShopManager();
}
@Override
@ -18,4 +26,12 @@ public class EpicBuckets extends JavaPlugin {
}
public ConfigManager getConfigManager() {
return configManager;
}
public ShopManager getShopManager() {
return shopManager;
}
}

View File

@ -0,0 +1,47 @@
package com.songoda.epicbuckets.file;
import com.songoda.epicbuckets.EpicBuckets;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.io.IOException;
public class Config {
private FileConfiguration handler;
private File file;
private boolean isResource;
public Config(File file, boolean resource) {
this.file = file;
this.isResource = resource;
initializeHandler();
}
private void initializeHandler() {
if (!file.exists()) {
try {
if (isResource) EpicBuckets.getInstance().saveResource(file.getName(), false);
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
handler = YamlConfiguration.loadConfiguration(file);
}
public void reloadConfig() {
try {
handler.load(file);
} catch (InvalidConfigurationException | IOException e) {
e.printStackTrace();
}
}
public FileConfiguration getConfig() {
return handler;
}
}

View File

@ -1,4 +1,4 @@
package com.songoda.epicbuckets.files;
package com.songoda.epicbuckets.file;
import com.songoda.epicbuckets.EpicBuckets;
import org.bukkit.configuration.file.FileConfiguration;
@ -18,16 +18,17 @@ public class ConfigManager {
private void setup() {
epicBuckets.saveDefaultConfig();
createConfig("shops");
createConfig("shops", true);
}
public void createConfig(String name) {
public void createConfig(String name, boolean resource) {
File f = new File(epicBuckets.getDataFolder(), name + ".yml");
configDatabase.put(name, new Config(f));
configDatabase.put(name, new Config(f, resource));
}
public FileConfiguration getConfig() {
return epicBuckets.getConfig();
public void reloadConfig(String name) {
if (!configDatabase.containsKey(name)) return;
configDatabase.get(name).reloadConfig();
}
public FileConfiguration getConfig(String name) {

View File

@ -1,34 +0,0 @@
package com.songoda.epicbuckets.files;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.io.IOException;
public class Config {
private FileConfiguration handler;
private File file;
public Config(File file) {
initializeHandler(file);
}
private void initializeHandler(File file) {
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
this.file = file;
handler = YamlConfiguration.loadConfiguration(this.file);
}
public FileConfiguration getConfig() {
return handler;
}
}

View File

@ -0,0 +1,30 @@
package com.songoda.epicbuckets.shop;
import com.songoda.epicbuckets.EpicBuckets;
import org.bukkit.inventory.ItemStack;
public class Shop {
private EpicBuckets epicBuckets;
private String name;
private String path;
private ItemStack shopItem;
public Shop(String name, String path) {
this.epicBuckets = EpicBuckets.getInstance();
this.name = name;
this.path = path;
setupShopItem();
}
private void setupShopItem() {
String itemPath = path + ".item";
//TODO: create the shopitem
}
}

View File

@ -0,0 +1,34 @@
package com.songoda.epicbuckets.shop;
import com.songoda.epicbuckets.EpicBuckets;
import org.bukkit.configuration.file.FileConfiguration;
import java.util.HashMap;
public class ShopManager {
private HashMap<String, Shop> shopDatabase;
private FileConfiguration shops;
private EpicBuckets epicBuckets;
private String path = "MENU-ITEMS";
public ShopManager() {
epicBuckets = EpicBuckets.getInstance();
shopDatabase = new HashMap<>();
shops = EpicBuckets.getInstance().getConfigManager().getConfig("shops");
loadShops();
}
private void loadShops() {
for (String key : epicBuckets.getConfig().getConfigurationSection(path).getKeys(false)) {
if (!epicBuckets.getConfig().isConfigurationSection(path + "." + key)) {
continue;
}
shopDatabase.put(epicBuckets.getConfig().getString(path + "." + key), new Shop(epicBuckets.getConfig().getString(path + "." + key), path + "." + key));
}
}
}

View File

@ -4,7 +4,7 @@
###############################################
# All files files can be found on
# All file file can be found on
# https://www.spigotmc.org/resources/ezbucket-1-7-1-12-region-support-gui-horizontal-vertical-and-infused-gens-genbucket.50944/
FACTIONS-SUPPORT: false # MassiveCore and Factions/FactionsUUID/SavageFactions is needed

View File

@ -4,7 +4,7 @@ shops:
vertical:
goBackButton: 31 # back button will display if enabled in files.yml
goBackButton: 31 # back button will display if enabled in file.yml
trait: "VERTICAL" # Which genbucket type does this shop have?