Skip to content

Commit

Permalink
Added config
Browse files Browse the repository at this point in the history
  • Loading branch information
hugo4715 committed Apr 15, 2016
1 parent 224a9ac commit 55fd7b6
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CrackedBackPack/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#
#WARNING: Changer les options rends les sacs crées precedemments iutilisables!
#
material: FIREWORK_CHARGE
slots: 36
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ public void onInteract(PlayerInteractEvent e){
if(e.getItem() == null)return;
ItemStack i = e.getItem();
if(!(i.getType().equals(Options.getItem().getType())))return;
if(!(i.getData().equals(Options.getItem().getData())))return;
if(i.getItemMeta() == null)return;
if(i.getItemMeta().getDisplayName() == null)return;
if(!i.getItemMeta().getDisplayName().equals(Options.getItem().getItemMeta().getDisplayName()))return;
if(i.getAmount() > 1)return;

if(Main.getInstance().cooldown.containsKey(e.getPlayer()) && Main.getInstance().cooldown.get(e.getPlayer()) > System.currentTimeMillis()){
Expand All @@ -45,7 +47,7 @@ public void onInteract(PlayerInteractEvent e){
lore.add("id:" + UUID.randomUUID());
m.setLore(lore);
e.getItem().setItemMeta(m);
e.getPlayer().openInventory(Bukkit.createInventory(null, 36, "BackPack"));
e.getPlayer().openInventory(Bukkit.createInventory(null, Options.getSlots(), "BackPack"));
}
else{
//show the inventory
Expand Down
30 changes: 29 additions & 1 deletion CrackedBackPack/src/fr/hugo4715/CrackedBackPack/Main.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package fr.hugo4715.CrackedBackPack;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;

import org.bukkit.Bukkit;
Expand All @@ -21,7 +23,33 @@ public class Main extends JavaPlugin{
public void onEnable(){
instance = this;
this.getDataFolder().mkdir();
Options.load();
try {
Options.load();
} catch (FileNotFoundException e) {
getLogger().severe("Erreur lors du chargement de la config:");
getLogger().severe(e.getMessage());
getLogger().severe("Erreur complete:");
e.printStackTrace();

Bukkit.getPluginManager().disablePlugin(this);
return;
} catch (IllegalArgumentException e) {
getLogger().severe("Erreur lors du chargement de la config:");
getLogger().severe(e.getMessage());
getLogger().severe("Erreur complete:");
e.printStackTrace();

Bukkit.getPluginManager().disablePlugin(this);
return;
} catch (IOException e) {
getLogger().severe("Erreur lors du chargement de la config:");
getLogger().severe(e.getMessage());
getLogger().severe("Erreur complete:");
e.printStackTrace();

Bukkit.getPluginManager().disablePlugin(this);
return;
}
this.registerRecipe();
EventManager.registerEvents();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,43 @@
package fr.hugo4715.CrackedBackPack.Options;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.commons.io.IOUtils;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import fr.hugo4715.CrackedBackPack.Main;
import lombok.Getter;

public class Options {

@Getter private static ItemStack item;
@Getter private static int slots;


public static void load(){
item = new ItemStack(Material.FIREWORK_CHARGE);
public static void load() throws FileNotFoundException, IOException, IllegalArgumentException{

File file = new File(Main.getInstance().getDataFolder(), "config.yml");
if(!file.exists()){
IOUtils.copyLarge(Main.getInstance().getResource("config.yml"), new FileOutputStream(file));
}
YamlConfiguration config = YamlConfiguration.loadConfiguration(file);

slots = config.getInt("slots");

if(slots % 9 != 0){
throw new IllegalArgumentException("Le nombre de slots du sac doit etre divisible par 9");
}
if(slots < 9){
throw new IllegalArgumentException("Le nombre de slots du sac doit etre au minimum 9");
}

item = new ItemStack(Material.valueOf(config.getString("material")));
item.setAmount(1);
ItemMeta m = item.getItemMeta();
m.setDisplayName(ChatColor.GREEN + "BackPack");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@

// For 1.7.2
public class ItemSerialization {






public static String toBase64(Inventory inventory) {
try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Expand Down

0 comments on commit 55fd7b6

Please sign in to comment.