Dicecraft Furniture Plugin

This commit is contained in:
BuildTools 2015-04-08 20:29:14 +02:00
parent 056a0ca914
commit 61571cc8d7
2 changed files with 236 additions and 0 deletions

View File

@ -0,0 +1,127 @@
package de.Ste3et_C0st.Furniture.Main;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import de.Ste3et_C0st.DiceEaster.config;
import de.Ste3et_C0st.Furniture.Objects.laterne;
import de.Ste3et_C0st.Furniture.Objects.stuhl;
import de.Ste3et_C0st.Furniture.Objects.tisch;
public class Manager {
private static config cc;
private static FileConfiguration fc;
private String folder = "/furniture/";
public void loadStuhl(){
cc = new config();
if(cc.ExistConfig(folder, "chair.yml")){
fc = cc.getConfig("chair.yml", folder);
if(fc.isSet("Furniture.chair")){
for(String s : fc.getConfigurationSection("Furniture.chair").getKeys(false)){
String path = "Furniture.chair";
path+= "." + s;
Double x = fc.getDouble(path+".Location.x");
Double y = fc.getDouble(path+".Location.x");
Double z = fc.getDouble(path+".Location.x");
World w = Bukkit.getWorld(fc.getString(path+".Location.w"));
Float yaw = (float) fc.getInt(fc.getString(path+".Location.Yaw"));
Location l = new Location(w, x, y, z);
l.setYaw(yaw);
new stuhl(l, main.getInstance());
}
}
}
}
public void loadLatern(){
cc = new config();
if(cc.ExistConfig(folder, "latern.yml")){
fc = cc.getConfig("latern.yml", folder);
if(fc.isSet("Furniture.latern")){
for(String s : fc.getConfigurationSection("Furniture.latern").getKeys(false)){
String path = "Furniture.latern";
path+= "." + s;
Double x = fc.getDouble(path+".Location.x");
Double y = fc.getDouble(path+".Location.x");
Double z = fc.getDouble(path+".Location.x");
World w = Bukkit.getWorld(fc.getString(path+".Location.w"));
Float yaw = (float) fc.getInt(fc.getString(path+".Location.Yaw"));
Boolean b = fc.getBoolean(path+".settings.Light");
Location l = new Location(w, x, y, z);
l.setYaw(yaw);
new laterne(l, main.getInstance(), b);
}
}
}
}
@SuppressWarnings("deprecation")
public void loadTisch(){
cc = new config();
if(cc.ExistConfig(folder, "table.yml")){
fc = cc.getConfig("table.yml", folder);
if(fc.isSet("Furniture.table")){
for(String s : fc.getConfigurationSection("Furniture.table").getKeys(false)){
String path = "Furniture.table";
path+= "." + s;
Double x = fc.getDouble(path+".Location.x");
Double y = fc.getDouble(path+".Location.x");
Double z = fc.getDouble(path+".Location.x");
World w = Bukkit.getWorld(fc.getString(path+".Location.w"));
Float yaw = (float) fc.getInt(fc.getString(path+".Location.Yaw"));
Location l = new Location(w, x, y, z);
l.setYaw(yaw);
ItemStack is = null;
if(fc.isSet(path+".settings.ItemStack")){
Material m = Material.getMaterial(fc.getInt(path+".settings.ItemStack.Material"));
Short subID = (short) fc.getInt(path+".settings.ItemStack.Durability");
Integer amount = fc.getInt(path+".settings.ItemStack.Amount");
is = new ItemStack(m,amount,subID);
ItemMeta im = is.getItemMeta();
List<String> lore = new ArrayList<String>();
if(fc.isSet(path+".settings.ItemStack.Lore")){
lore = fc.getStringList(path+".settings.ItemStack.Lore");
im.setLore(lore);
}
if(fc.isSet(path+".settings.ItemStack.Enchantment")){
for(String enchant : fc.getConfigurationSection(path+".settings.ItemStack.Enchantment").getKeys(false)){
Enchantment en = Enchantment.getByName(enchant);
im.addEnchant(en, fc.getInt(path+".settings.ItemStack.Enchantment." + enchant + ".id"), true);
}
}
is.setItemMeta(im);
if(is.getItemMeta() instanceof LeatherArmorMeta){
LeatherArmorMeta lim = (LeatherArmorMeta) is.getItemMeta();
if(fc.isSet(path+".settings.ItemStack.LeatherMeta")){
lim.setColor(Color.fromBGR(
fc.getInt(path+".settings.ItemStack.LeatherMeta.Color.blue"),
fc.getInt(path+".settings.ItemStack.LeatherMeta.Color.green"),
fc.getInt(path+".settings.ItemStack.LeatherMeta.Color.red")));
}
is.setItemMeta(lim);
}
}
new tisch(l, main.getInstance(), is);
}
}
}
}
}

View File

@ -0,0 +1,109 @@
package de.Ste3et_C0st.Furniture.Main;
import java.io.File;
import java.io.IOException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
public class config
{
public JavaPlugin plugin;
public String fileName;
public String path = "plugins/";
public config()
{
this.path = "plugins/DiceEaster";
}
public FileConfiguration createConfig(String name, String Folder)
{
if (!name.endsWith(".yml")) {
name = name + ".yml";
}
File f = new File(path + Folder + "/");
if (!f.exists()) {
f.mkdirs();
}
File arena = new File(path + Folder, name);
if (!arena.exists()) {
try
{
arena.createNewFile();
}
catch (IOException e)
{
e.printStackTrace();
}
}
return YamlConfiguration.loadConfiguration(arena);
}
public void saveConfig(String name, FileConfiguration config, String Folder)
{
if (!name.endsWith(".yml")) {
name = name + ".yml";
}
File arena = new File(path + Folder, name);
try
{
config.save(arena);
}
catch (IOException e)
{
e.printStackTrace();
}
}
public FileConfiguration getConfig(String name, String Folder)
{
if (!name.endsWith(".yml")) {
name = name + ".yml";
}
createConfig(name, Folder);
File arena = new File(path + Folder, name);
return YamlConfiguration.loadConfiguration(arena);
}
public boolean ExistMaps(String folder){
if(new File(path + folder).exists()){
return true;
}
return false;
}
public boolean ExistConfig(String folder, String name){
System.out.print(path + folder + "," + name);
if(new File(path + folder, name).exists()){
return true;
}
return false;
}
public boolean isMaps(String folder){
if(new File(path + folder).list().length > 0){
return true;
}
return false;
}
public void deleteFolder(File folder)
{
File[] files = folder.listFiles();
if(files!=null) { //some JVMs return null for empty dirs
for(File f: files) {
if(f.isDirectory()) {
deleteFolder(f);
} else {
f.delete();
}
}
}
folder.delete();
}
}