Skip to content

Commit

Permalink
Updated to 1.3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
benfah committed Jun 7, 2016
1 parent ee3c79f commit a6d6a66
Show file tree
Hide file tree
Showing 8 changed files with 234 additions and 53 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>Bags</groupId>
<artifactId>Bags</artifactId>
<version>1.3.2</version>
<version>1.3.4</version>
<name>Bags</name>
<build>
<sourceDirectory>src</sourceDirectory>
Expand Down
56 changes: 56 additions & 0 deletions src/me/benfah/bags/command/CommandBags.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,62 @@ public boolean onCommand(CommandSender sender, Command command, String label, St

}
}
if(args[0].equalsIgnoreCase("list"))
{
if(sender.hasPermission(new Permission("bag.list", PermissionDefault.OP)))
{
if(args.length >= 2)
{
if(Util.isInteger(args[1]))
{
int value = Integer.parseInt(args[1]);

sender.sendMessage(ChatColor.DARK_AQUA + "-----------------------------------------------------");





for(int i = value * 25 - 24; i < value * 25 + 1; i++)
{
Object[] obj = BagManager.bag.get(i);

if(obj != null)
{
if(obj.length >= 4)
sender.sendMessage(ChatColor.DARK_AQUA + "BagID: §2" + i + "§3 | Last Used By: §2" + obj[2] + "§3 | Owner: §2" + obj[3]);
else
sender.sendMessage(ChatColor.DARK_AQUA + "BagID: §2" + i + "§3 | Last Used By: §2Unknown " + "§3| Owner: " + "§2Unknown");
}

}
sender.sendMessage(ChatColor.DARK_AQUA + "-----------------------------------------------------");
sender.sendMessage("");

}
}
else
{
sender.sendMessage(ChatColor.DARK_AQUA + "-----------------------------------------------------");
for(int i = 1; i < 25 + 1; i++)
{
Object[] obj = BagManager.bag.get(i);
if(obj != null)
{
if(obj.length >= 4)
sender.sendMessage(ChatColor.DARK_AQUA + "BagID: §2" + i + "§3 | Last Used By: §2" + obj[2] + "§3 | Owner: §2" + obj[3]);
else
sender.sendMessage(ChatColor.DARK_AQUA + "BagID: §2" + i + "§3 | Last Used By: §2Unknown " + "§3| Owner: " + "§2Unknown");
}

}
sender.sendMessage(ChatColor.DARK_AQUA + "-----------------------------------------------------");
sender.sendMessage("");
}
}
else
sender.sendMessage(Translation.not_allowed);
}
if(args[0].equalsIgnoreCase("lang"))
{
if(sender.hasPermission(new Permission("bag.lang", PermissionDefault.OP)))
Expand Down
22 changes: 18 additions & 4 deletions src/me/benfah/bags/event/PlayerInteractListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void onInteract(PlayerInteractEvent e)
String ints = h.getItemMeta().getLore().iterator().next();
int id = Integer.parseInt(ints);
Inventory inv = BagManager.bag.get(id) != null ? BagManager.getInventory(id) : Bukkit.createInventory(p, Bags.cfg.getInt("bag_size"), Translation.bag_inventory);

if(stack.getItemMeta().getDisplayName().startsWith(ChatColor.RESET + ""))
if(!stack.getItemMeta().getDisplayName().equals(Translation.bag))
{
Expand All @@ -74,7 +74,14 @@ public void onInteract(PlayerInteractEvent e)
stack.setItemMeta(im);
}
p.openInventory(inv);
BagManager.bag.put(id, new Object[]{inv, inv.getSize()});

if(BagManager.bag.get(id) != null ? BagManager.bag.get(id).length >= 4 : false)
{
BagManager.bag.put(id, new Object[]{inv, inv.getSize(), p.getName(), BagManager.bag.get(id)[3]});
}
else
BagManager.bag.put(id, new Object[]{inv, inv.getSize(), p.getName(), p.getName()});

}
else
p.sendMessage(Bags.not_allowed);
Expand Down Expand Up @@ -108,6 +115,7 @@ public void onInteract(PlayerInteractEvent e)
Bags.playOpenSound(p);
String ints = h.getItemMeta().getLore().iterator().next();
int id = Integer.parseInt(ints);

ItemStack stack = e.getPlayer().getInventory().getItemInMainHand();
Inventory inv = BagManager.bag.get(id) != null ? (Inventory) BagManager.getInventory(id) : Bukkit.createInventory(p, Bags.cfg.getInt("bag_big_size"), Translation.bag_inventory);
if(stack.getItemMeta().getDisplayName().startsWith(ChatColor.RESET + ""))
Expand All @@ -118,7 +126,13 @@ public void onInteract(PlayerInteractEvent e)
stack.setItemMeta(im);
}
p.openInventory(inv);
BagManager.bag.put(id, new Object[]{inv, inv.getSize()});
if(BagManager.bag.get(id) != null ? BagManager.bag.get(id).length >= 4 : false)
{
BagManager.bag.put(id, new Object[]{inv, inv.getSize(), p.getName(), BagManager.bag.get(id)[3]});
}
else
BagManager.bag.put(id, new Object[]{inv, inv.getSize(), p.getName(), p.getName()});

}
else
p.sendMessage(Bags.not_allowed);
Expand Down Expand Up @@ -319,7 +333,7 @@ public void onInventoryMove(InventoryClickEvent e)
{
if(e.getInventory().getName().equals(Translation.bag_inventory))
{
if(e.getCurrentItem().getType() != Material.AIR)
if(e.getCurrentItem().getType() != Material.AIR && !Bags.cfg.getBoolean("bags-in-bags"))
{
if(Util.isUnbreakableAndHasDamage(e.getCurrentItem(), (short)10))
e.setCancelled(true);
Expand Down
31 changes: 25 additions & 6 deletions src/me/benfah/bags/main/Bags.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ public class Bags extends JavaPlugin{
public static BagManager bm;
public static String not_allowed;

public static FileConfiguration recipeCfg;
public static File recipeCfgFile;

public static boolean rlActive = false;

public static void playOpenSound(Player p){p.playSound(p.getLocation(), Sound.ENTITY_BAT_TAKEOFF, 0.5f, 1f);}

@Override
public void onLoad()
{
}


@Override
public void onEnable()
Expand All @@ -57,27 +57,42 @@ public void onEnable()
inst = this;
initInv();

recipeCfgFile = new File(getDataFolder(), "recipes.yml");

getCommand("bags").setExecutor(new CommandBags());
cfgFile = new File(getDataFolder(), "cfg.yml");

countCfgFile = new File(getDataFolder(), "count.yml");

if(!recipeCfgFile.exists())
{
try {
recipeCfgFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}


if(!countCfgFile.exists())
try {
countCfgFile.createNewFile();
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
countCfg = YamlConfiguration.loadConfiguration(countCfgFile);

recipeCfg = YamlConfiguration.loadConfiguration(recipeCfgFile);
not_allowed = ChatColor.RED + "You are not allowed to do this!";
cfg = YamlConfiguration.loadConfiguration(cfgFile);
Bukkit.getPluginManager().registerEvents(new PlayerInteractListener(), this);
Bukkit.getPluginManager().registerEvents(new PlayerJoinListener(), this);
Bukkit.getPluginManager().registerEvents(new CraftListener(), this);
bm = new BagManager(this);





if(!cfg.contains("resourcepack-enabled"))
cfg.set("resourcepack-enabled", true);
if(!cfg.contains("langfile"))
Expand Down Expand Up @@ -107,6 +122,10 @@ public void onEnable()
if(!cfg.contains("custom-resourcepack-link"))
cfg.set("custom-resourcepack-link", "Replace_me_with_the_link");

if(!cfg.contains("bags-in-bags"))
cfg.set("bags-in-bags", false);


try {
cfg.save(cfgFile);
} catch (IOException e1) {
Expand Down
123 changes: 93 additions & 30 deletions src/me/benfah/bags/main/RecipeManager.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package me.benfah.bags.main;

import java.io.IOException;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
Expand All @@ -15,73 +17,117 @@ public class RecipeManager {

public RecipeManager()
{
init();
doRecipes();
}

public void init()
{
setRecipeInConfig("nor", Material.IRON_INGOT, Material.LEATHER, Material.IRON_INGOT, Material.LEATHER, Material.STRING, Material.LEATHER, Material.LEATHER, Material.LEATHER, Material.LEATHER);
setRecipeInConfig("big", Material.GOLD_INGOT, Material.LEATHER, Material.GOLD_INGOT, Material.LEATHER, Material.STRING, Material.LEATHER, Material.LEATHER, Material.LEATHER, Material.LEATHER);
setRecipeInConfig("cra", Material.IRON_INGOT, Material.LEATHER, Material.IRON_INGOT, Material.LEATHER, Material.STRING, Material.LEATHER, Material.LEATHER, Material.WORKBENCH, Material.LEATHER);
setRecipeInConfig("anv", Material.IRON_BLOCK, Material.LEATHER, Material.IRON_BLOCK, Material.LEATHER, Material.STRING, Material.LEATHER, Material.LEATHER, Material.ANVIL, Material.LEATHER);
setRecipeInConfig("enc", Material.GOLD_INGOT, Material.LEATHER, Material.GOLD_INGOT, Material.LEATHER, Material.STRING, Material.LEATHER, Material.LEATHER, Material.ENCHANTMENT_TABLE, Material.LEATHER);
setRecipeInConfig("end", Material.GOLD_INGOT, Material.DIAMOND, Material.GOLD_INGOT, Material.LEATHER, Material.STRING, Material.LEATHER, Material.LEATHER, Material.ENDER_CHEST, Material.LEATHER);

}

public void doRecipes()
{
//Standard Bag
ShapedRecipe sr = new ShapedRecipe(getBag());



sr.shape("ILI", "LSL", "LLL");
sr.setIngredient('S', Material.STRING);
sr.setIngredient('L', Material.LEATHER);
sr.setIngredient('I', Material.IRON_INGOT);
sr.shape("ABC", "DEF", "GHI");
sr.setIngredient('A', Material.valueOf(Bags.recipeCfg.getString("recipes.nor.1")));
sr.setIngredient('B', Material.valueOf(Bags.recipeCfg.getString("recipes.nor.2")));
sr.setIngredient('C', Material.valueOf(Bags.recipeCfg.getString("recipes.nor.3")));
sr.setIngredient('D', Material.valueOf(Bags.recipeCfg.getString("recipes.nor.4")));
sr.setIngredient('E', Material.valueOf(Bags.recipeCfg.getString("recipes.nor.5")));
sr.setIngredient('F', Material.valueOf(Bags.recipeCfg.getString("recipes.nor.6")));
sr.setIngredient('G', Material.valueOf(Bags.recipeCfg.getString("recipes.nor.7")));
sr.setIngredient('H', Material.valueOf(Bags.recipeCfg.getString("recipes.nor.8")));
sr.setIngredient('I', Material.valueOf(Bags.recipeCfg.getString("recipes.nor.9")));

Bukkit.addRecipe(sr);

//Big Bag
ShapedRecipe srB = new ShapedRecipe(getBigBag());
srB.shape("GLG", "LSL", "LLL");
srB.setIngredient('S', Material.STRING);
srB.setIngredient('L', Material.LEATHER);
srB.setIngredient('G', Material.GOLD_INGOT);
srB.shape("123", "456", "789");
srB.setIngredient('1', Material.valueOf(Bags.recipeCfg.getString("recipes.big.1")));
srB.setIngredient('2', Material.valueOf(Bags.recipeCfg.getString("recipes.big.2")));
srB.setIngredient('3', Material.valueOf(Bags.recipeCfg.getString("recipes.big.3")));
srB.setIngredient('4', Material.valueOf(Bags.recipeCfg.getString("recipes.big.4")));
srB.setIngredient('5', Material.valueOf(Bags.recipeCfg.getString("recipes.big.5")));
srB.setIngredient('6', Material.valueOf(Bags.recipeCfg.getString("recipes.big.6")));
srB.setIngredient('7', Material.valueOf(Bags.recipeCfg.getString("recipes.big.7")));
srB.setIngredient('8', Material.valueOf(Bags.recipeCfg.getString("recipes.big.8")));
srB.setIngredient('9', Material.valueOf(Bags.recipeCfg.getString("recipes.big.9")));

Bukkit.addRecipe(srB);

//Enchantment Bag
ShapedRecipe srE = new ShapedRecipe(getEnchantmentBag());
srE.shape("GLG", "LSL", "LEL");
srE.setIngredient('S', Material.STRING);
srE.setIngredient('L', Material.LEATHER);
srE.setIngredient('G', Material.GOLD_INGOT);
srE.setIngredient('E', Material.ENCHANTMENT_TABLE);

srE.shape("123", "456", "789");
srE.setIngredient('1', Material.valueOf(Bags.recipeCfg.getString("recipes.enc.1")));
srE.setIngredient('2', Material.valueOf(Bags.recipeCfg.getString("recipes.enc.2")));
srE.setIngredient('3', Material.valueOf(Bags.recipeCfg.getString("recipes.enc.3")));
srE.setIngredient('4', Material.valueOf(Bags.recipeCfg.getString("recipes.enc.4")));
srE.setIngredient('5', Material.valueOf(Bags.recipeCfg.getString("recipes.enc.5")));
srE.setIngredient('6', Material.valueOf(Bags.recipeCfg.getString("recipes.enc.6")));
srE.setIngredient('7', Material.valueOf(Bags.recipeCfg.getString("recipes.enc.7")));
srE.setIngredient('8', Material.valueOf(Bags.recipeCfg.getString("recipes.enc.8")));
srE.setIngredient('9', Material.valueOf(Bags.recipeCfg.getString("recipes.enc.9")));

Bukkit.addRecipe(srE);

//Crafting Bag
ShapedRecipe srC = new ShapedRecipe(getCraftingBag());
srC.shape("ILI", "LSL", "LCL");
srC.setIngredient('S', Material.STRING);
srC.setIngredient('L', Material.LEATHER);
srC.setIngredient('C', Material.WORKBENCH);
srC.setIngredient('I', Material.IRON_INGOT);
srC.shape("123", "456", "789");
srC.setIngredient('1', Material.valueOf(Bags.recipeCfg.getString("recipes.cra.1")));
srC.setIngredient('2', Material.valueOf(Bags.recipeCfg.getString("recipes.cra.2")));
srC.setIngredient('3', Material.valueOf(Bags.recipeCfg.getString("recipes.cra.3")));
srC.setIngredient('4', Material.valueOf(Bags.recipeCfg.getString("recipes.cra.4")));
srC.setIngredient('5', Material.valueOf(Bags.recipeCfg.getString("recipes.cra.5")));
srC.setIngredient('6', Material.valueOf(Bags.recipeCfg.getString("recipes.cra.6")));
srC.setIngredient('7', Material.valueOf(Bags.recipeCfg.getString("recipes.cra.7")));
srC.setIngredient('8', Material.valueOf(Bags.recipeCfg.getString("recipes.cra.8")));
srC.setIngredient('9', Material.valueOf(Bags.recipeCfg.getString("recipes.cra.9")));


Bukkit.addRecipe(srC);

//Ender Bag
ShapedRecipe srEN = new ShapedRecipe(getEnderBag());
srEN.shape("GDG", "LSL", "LEL");
srEN.setIngredient('S', Material.STRING);
srEN.setIngredient('L', Material.LEATHER);
srEN.setIngredient('G', Material.GOLD_INGOT);
srEN.setIngredient('D', Material.DIAMOND);
srEN.setIngredient('E', Material.ENDER_CHEST);
srEN.shape("123", "456", "789");
srEN.setIngredient('1', Material.valueOf(Bags.recipeCfg.getString("recipes.end.1")));
srEN.setIngredient('2', Material.valueOf(Bags.recipeCfg.getString("recipes.end.2")));
srEN.setIngredient('3', Material.valueOf(Bags.recipeCfg.getString("recipes.end.3")));
srEN.setIngredient('4', Material.valueOf(Bags.recipeCfg.getString("recipes.end.4")));
srEN.setIngredient('5', Material.valueOf(Bags.recipeCfg.getString("recipes.end.5")));
srEN.setIngredient('6', Material.valueOf(Bags.recipeCfg.getString("recipes.end.6")));
srEN.setIngredient('7', Material.valueOf(Bags.recipeCfg.getString("recipes.end.7")));
srEN.setIngredient('8', Material.valueOf(Bags.recipeCfg.getString("recipes.end.8")));
srEN.setIngredient('9', Material.valueOf(Bags.recipeCfg.getString("recipes.end.9")));


Bukkit.addRecipe(srEN);

//Anvil Bag
ShapedRecipe srAN = new ShapedRecipe(getAnvilBag());
srAN.shape("ILI", "LSL", "LAL");
srAN.setIngredient('I', Material.IRON_BLOCK);
srAN.setIngredient('L', Material.LEATHER);
srAN.setIngredient('S', Material.STRING);
srAN.setIngredient('A', Material.ANVIL);
srAN.shape("123", "456", "789");
srAN.setIngredient('1', Material.valueOf(Bags.recipeCfg.getString("recipes.anv.1")));
srAN.setIngredient('2', Material.valueOf(Bags.recipeCfg.getString("recipes.anv.2")));
srAN.setIngredient('3', Material.valueOf(Bags.recipeCfg.getString("recipes.anv.3")));
srAN.setIngredient('4', Material.valueOf(Bags.recipeCfg.getString("recipes.anv.4")));
srAN.setIngredient('5', Material.valueOf(Bags.recipeCfg.getString("recipes.anv.5")));
srAN.setIngredient('6', Material.valueOf(Bags.recipeCfg.getString("recipes.anv.6")));
srAN.setIngredient('7', Material.valueOf(Bags.recipeCfg.getString("recipes.anv.7")));
srAN.setIngredient('8', Material.valueOf(Bags.recipeCfg.getString("recipes.anv.8")));
srAN.setIngredient('9', Material.valueOf(Bags.recipeCfg.getString("recipes.anv.9")));


Bukkit.addRecipe(srAN);
}

Expand Down Expand Up @@ -174,4 +220,21 @@ public static ItemStack doStandardModifiers(ItemStack stack)
}
return null;
}
public void setRecipeInConfig(String s, Material m1, Material m2, Material m3, Material m4, Material m5, Material m6, Material m7, Material m8, Material m9)
{
if (!Bags.recipeCfg.contains("recipes." + s + ".1")) Bags.recipeCfg.set("recipes." + s + ".1", m1.toString());
if (!Bags.recipeCfg.contains("recipes." + s + ".2")) Bags.recipeCfg.set("recipes." + s + ".2", m2.toString());
if (!Bags.recipeCfg.contains("recipes." + s + ".3")) Bags.recipeCfg.set("recipes." + s + ".3", m3.toString());
if (!Bags.recipeCfg.contains("recipes." + s + ".4")) Bags.recipeCfg.set("recipes." + s + ".4", m4.toString());
if (!Bags.recipeCfg.contains("recipes." + s + ".5")) Bags.recipeCfg.set("recipes." + s + ".5", m5.toString());
if (!Bags.recipeCfg.contains("recipes." + s + ".6")) Bags.recipeCfg.set("recipes." + s + ".6", m6.toString());
if (!Bags.recipeCfg.contains("recipes." + s + ".7")) Bags.recipeCfg.set("recipes." + s + ".7", m7.toString());
if (!Bags.recipeCfg.contains("recipes." + s + ".8")) Bags.recipeCfg.set("recipes." + s + ".8", m8.toString());
if (!Bags.recipeCfg.contains("recipes." + s + ".9")) Bags.recipeCfg.set("recipes." + s + ".9", m9.toString());
try {
Bags.recipeCfg.save(Bags.recipeCfgFile);
} catch (IOException e) {
e.printStackTrace();
}
}
}
Loading

0 comments on commit a6d6a66

Please sign in to comment.