Fully implemented and bug-free version of Filter and Vacuum Cubes
This commit is contained in:
parent
71c1d51d76
commit
68cf1f8500
Binary file not shown.
@ -3838,6 +3838,7 @@ public class GenericFunctions {
|
|||||||
public static boolean giveItem(Player p, ItemStack... items) {
|
public static boolean giveItem(Player p, ItemStack... items) {
|
||||||
HashMap<Integer,ItemStack> remaining = p.getInventory().addItem(items);
|
HashMap<Integer,ItemStack> remaining = p.getInventory().addItem(items);
|
||||||
if (remaining.isEmpty()) {
|
if (remaining.isEmpty()) {
|
||||||
|
SoundUtils.playLocalSound(p, Sound.ENTITY_ITEM_PICKUP, 1.0f, 1.0f);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
for (Integer i : remaining.keySet()) {
|
for (Integer i : remaining.keySet()) {
|
||||||
|
@ -1,5 +1,34 @@
|
|||||||
package sig.plugin.TwosideKeeper.HelperStructures;
|
package sig.plugin.TwosideKeeper.HelperStructures;
|
||||||
|
|
||||||
|
import sig.plugin.TwosideKeeper.TwosideKeeper;
|
||||||
|
|
||||||
public enum CubeType {
|
public enum CubeType {
|
||||||
NORMAL,LARGE,ENDER,VACUUM
|
NORMAL(0,9),LARGE(1,27),ENDER(2,27),VACUUM(3,54),FILTER(4,27);
|
||||||
|
|
||||||
|
int id=0;
|
||||||
|
int size=9;
|
||||||
|
|
||||||
|
private CubeType(int id, int size) {
|
||||||
|
this.id=id;
|
||||||
|
this.size=size;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getID() {
|
||||||
|
return this.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSize() {
|
||||||
|
return this.size;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CubeType getCubeTypeFromID(int id) {
|
||||||
|
for (CubeType ct : CubeType.values()) {
|
||||||
|
if (ct.getID()==id) {
|
||||||
|
return ct;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TwosideKeeper.log("INVALID CUBE ID SPECIFIED: "+id+". THIS SHOULD NOT BE HAPPENING!", 0);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,7 @@ public class CustomItem {
|
|||||||
TwosideKeeper.ENDER_ITEM_CUBE_RECIPE = EnderItemCubeRecipe();
|
TwosideKeeper.ENDER_ITEM_CUBE_RECIPE = EnderItemCubeRecipe();
|
||||||
TwosideKeeper.DUPLICATE_ENDER_ITEM_CUBE_RECIPE = DuplicateEnderItemCubeRecipe();
|
TwosideKeeper.DUPLICATE_ENDER_ITEM_CUBE_RECIPE = DuplicateEnderItemCubeRecipe();
|
||||||
TwosideKeeper.VACUUM_CUBE_RECIPE = VacuumCubeRecipe();
|
TwosideKeeper.VACUUM_CUBE_RECIPE = VacuumCubeRecipe();
|
||||||
|
TwosideKeeper.FILTER_CUBE_RECIPE = FilterCubeRecipe();
|
||||||
TwosideKeeper.ARROW_QUIVER_RECIPE = ArrowQuiverRecipe();
|
TwosideKeeper.ARROW_QUIVER_RECIPE = ArrowQuiverRecipe();
|
||||||
TwosideKeeper.HARDENED_IRON_HELMET_RECIPE = HardenedRecipe(Material.IRON_HELMET,Material.IRON_BLOCK,"aaa","axa","xxx");
|
TwosideKeeper.HARDENED_IRON_HELMET_RECIPE = HardenedRecipe(Material.IRON_HELMET,Material.IRON_BLOCK,"aaa","axa","xxx");
|
||||||
TwosideKeeper.HARDENED_IRON_CHESTPLATE_RECIPE = HardenedRecipe(Material.IRON_CHESTPLATE,Material.IRON_BLOCK,"axa","aaa","aaa");
|
TwosideKeeper.HARDENED_IRON_CHESTPLATE_RECIPE = HardenedRecipe(Material.IRON_CHESTPLATE,Material.IRON_BLOCK,"axa","aaa","aaa");
|
||||||
@ -143,6 +144,30 @@ public class CustomItem {
|
|||||||
return ItemCube;
|
return ItemCube;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static ShapelessRecipe FilterCubeRecipe() {
|
||||||
|
ItemStack item_FilterCube = FilterCube();
|
||||||
|
|
||||||
|
ShapelessRecipe FilterCube = new ShapelessRecipe(item_FilterCube);
|
||||||
|
FilterCube.addIngredient(Material.CHEST);
|
||||||
|
FilterCube.addIngredient(Material.HOPPER);
|
||||||
|
FilterCube.addIngredient(4,Material.DIAMOND_BLOCK);
|
||||||
|
FilterCube.addIngredient(3,Material.IRON_BLOCK);
|
||||||
|
return FilterCube;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ItemStack FilterCube() {
|
||||||
|
ItemStack item_FilterCube = new ItemStack(Material.HOPPER_MINECART);
|
||||||
|
List<String> item_FilterCube_lore = new ArrayList<String>();
|
||||||
|
item_FilterCube_lore.add("A storage container that holds up");
|
||||||
|
item_FilterCube_lore.add("to 27 items. Shift-Right click to");
|
||||||
|
item_FilterCube_lore.add("open up a filtered item list.");
|
||||||
|
ItemMeta item_FilterCube_meta=item_FilterCube.getItemMeta();
|
||||||
|
item_FilterCube_meta.setLore(item_FilterCube_lore);
|
||||||
|
item_FilterCube_meta.setDisplayName(ChatColor.GREEN+""+ChatColor.BOLD+"Filter Cube");
|
||||||
|
item_FilterCube.setItemMeta(item_FilterCube_meta);
|
||||||
|
return item_FilterCube.clone();
|
||||||
|
}
|
||||||
|
|
||||||
private static ShapelessRecipe WorldShopRecipe() {
|
private static ShapelessRecipe WorldShopRecipe() {
|
||||||
ItemStack item_worldShop = WorldShop();
|
ItemStack item_worldShop = WorldShop();
|
||||||
|
|
||||||
@ -563,4 +588,11 @@ public class CustomItem {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isFilterCube(ItemStack item) {
|
||||||
|
if (ItemUtils.isValidLoreItem(item) && ItemUtils.LoreContains(item, "open up a filtered item list.")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package sig.plugin.TwosideKeeper.HelperStructures.Utils;
|
package sig.plugin.TwosideKeeper.HelperStructures.Utils;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
public class ArrayUtils {
|
public class ArrayUtils {
|
||||||
|
@ -55,4 +55,33 @@ public class InventoryUtils {
|
|||||||
}
|
}
|
||||||
return remaining;
|
return remaining;
|
||||||
}
|
}
|
||||||
|
public static boolean isCarryingFilterCube(Player p) {
|
||||||
|
for (ItemStack items : p.getInventory().getContents()) {
|
||||||
|
if (items!=null && CustomItem.isFilterCube(items)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public static ItemStack[] insertItemsInFilterCube(Player p,ItemStack...items) {
|
||||||
|
ItemStack[] remaining = items;
|
||||||
|
for (ItemStack itemStacks : p.getInventory().getContents()) {
|
||||||
|
if (itemStacks!=null && CustomItem.isFilterCube(itemStacks)) {
|
||||||
|
//Insert as many items as possible in here.
|
||||||
|
int id = Integer.parseInt(ItemUtils.GetLoreLineContainingString(itemStacks, ChatColor.DARK_PURPLE+"ID#").split("#")[1]);
|
||||||
|
List<ItemStack> itemCubeContents = TwosideKeeper.itemCube_loadConfig(id);
|
||||||
|
Inventory virtualinventory = Bukkit.createInventory(p, 27);
|
||||||
|
for (int i=0;i<virtualinventory.getSize();i++) {
|
||||||
|
if (itemCubeContents.get(i)!=null) {
|
||||||
|
virtualinventory.setItem(i, itemCubeContents.get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//THIS IS WHERE YOU DO THE FILTERING.
|
||||||
|
HashMap<Integer,ItemStack> remainingitems = ItemCubeUtils.AttemptingToAddItemToFilterCube(id,virtualinventory,remaining);
|
||||||
|
|
||||||
|
remaining = remainingitems.values().toArray(new ItemStack[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return remaining;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,73 @@
|
|||||||
|
package sig.plugin.TwosideKeeper.HelperStructures.Utils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.Hopper;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import sig.plugin.TwosideKeeper.TwosideKeeper;
|
||||||
|
import sig.plugin.TwosideKeeper.HelperStructures.ItemCube;
|
||||||
|
|
||||||
|
public class ItemCubeUtils {
|
||||||
|
public static int getItemCubeID(ItemStack item) {
|
||||||
|
return Integer.parseInt(ItemUtils.GetLoreLineContainingString(item, ChatColor.DARK_PURPLE+"ID#").split("#")[1]);
|
||||||
|
}
|
||||||
|
public static Location getFilterCubeLoc(int id) {
|
||||||
|
int posx = id % 960;
|
||||||
|
int posy = 64;
|
||||||
|
int posz = id / 960;
|
||||||
|
return new Location(Bukkit.getWorld("FilterCube"),posx,posy,posz);
|
||||||
|
}
|
||||||
|
public static Block getFilterCubeBlock(int id) {
|
||||||
|
Block b = Bukkit.getWorld("FilterCube").getBlockAt(getFilterCubeLoc(id));
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
public static Hopper getFilterCubeHopper(int id) {
|
||||||
|
Hopper h = (Hopper)Bukkit.getWorld("FilterCube").getBlockAt(getFilterCubeLoc(id)).getState();
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
public static void createNewFilterCube(int id) {
|
||||||
|
Block b = getFilterCubeBlock(id);
|
||||||
|
b.getWorld().getBlockAt(getFilterCubeLoc(id)).setType(Material.HOPPER);
|
||||||
|
}
|
||||||
|
public static HashMap<Integer, ItemStack> AttemptingToAddItemToFilterCube(int id, Inventory cube_inv, ItemStack[] remaining) {
|
||||||
|
Hopper h = getFilterCubeHopper(id);
|
||||||
|
Inventory inv = h.getInventory();
|
||||||
|
HashMap<Integer,ItemStack> reject_items = new HashMap<Integer,ItemStack>();
|
||||||
|
for (ItemStack it : remaining) {
|
||||||
|
if (it!=null) {
|
||||||
|
if (inv.containsAtLeast(it, 1)) {
|
||||||
|
HashMap<Integer,ItemStack> extras = cube_inv.addItem(it);
|
||||||
|
if (extras.size()==0) {
|
||||||
|
List<ItemStack> itemslist = new ArrayList<ItemStack>();
|
||||||
|
for (int i=0;i<cube_inv.getSize();i++) {
|
||||||
|
itemslist.add(cube_inv.getItem(i));
|
||||||
|
}
|
||||||
|
ItemCube.addToViewersOfItemCube(id,remaining,null);
|
||||||
|
TwosideKeeper.itemCube_saveConfig(id, itemslist);
|
||||||
|
} else {
|
||||||
|
for (ItemStack i : extras.values()) {
|
||||||
|
reject_items.put(reject_items.size(), i);
|
||||||
|
List<ItemStack> itemslist = new ArrayList<ItemStack>();
|
||||||
|
for (int j=0;j<cube_inv.getSize();j++) {
|
||||||
|
itemslist.add(cube_inv.getItem(j));
|
||||||
|
}
|
||||||
|
TwosideKeeper.itemCube_saveConfig(id, itemslist);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
reject_items.put(reject_items.size(), it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return reject_items;
|
||||||
|
}
|
||||||
|
}
|
@ -24,11 +24,13 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Particle;
|
import org.bukkit.Particle;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.WorldCreator;
|
||||||
import org.bukkit.attribute.Attribute;
|
import org.bukkit.attribute.Attribute;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.block.Chest;
|
import org.bukkit.block.Chest;
|
||||||
import org.bukkit.block.DoubleChest;
|
import org.bukkit.block.DoubleChest;
|
||||||
|
import org.bukkit.block.Hopper;
|
||||||
import org.bukkit.block.Sign;
|
import org.bukkit.block.Sign;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -136,6 +138,7 @@ import org.bukkit.event.world.ChunkUnloadEvent;
|
|||||||
import org.bukkit.event.world.WorldSaveEvent;
|
import org.bukkit.event.world.WorldSaveEvent;
|
||||||
import org.bukkit.inventory.EquipmentSlot;
|
import org.bukkit.inventory.EquipmentSlot;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.ShapedRecipe;
|
import org.bukkit.inventory.ShapedRecipe;
|
||||||
import org.bukkit.inventory.ShapelessRecipe;
|
import org.bukkit.inventory.ShapelessRecipe;
|
||||||
@ -188,8 +191,10 @@ import sig.plugin.TwosideKeeper.HelperStructures.Common.RecipeCategory;
|
|||||||
import sig.plugin.TwosideKeeper.HelperStructures.Common.RecipeLinker;
|
import sig.plugin.TwosideKeeper.HelperStructures.Common.RecipeLinker;
|
||||||
import sig.plugin.TwosideKeeper.HelperStructures.Effects.EarthWaveTask;
|
import sig.plugin.TwosideKeeper.HelperStructures.Effects.EarthWaveTask;
|
||||||
import sig.plugin.TwosideKeeper.HelperStructures.Effects.LavaPlume;
|
import sig.plugin.TwosideKeeper.HelperStructures.Effects.LavaPlume;
|
||||||
|
import sig.plugin.TwosideKeeper.HelperStructures.Utils.ArrayUtils;
|
||||||
import sig.plugin.TwosideKeeper.HelperStructures.Utils.BlockUtils;
|
import sig.plugin.TwosideKeeper.HelperStructures.Utils.BlockUtils;
|
||||||
import sig.plugin.TwosideKeeper.HelperStructures.Utils.InventoryUtils;
|
import sig.plugin.TwosideKeeper.HelperStructures.Utils.InventoryUtils;
|
||||||
|
import sig.plugin.TwosideKeeper.HelperStructures.Utils.ItemCubeUtils;
|
||||||
import sig.plugin.TwosideKeeper.HelperStructures.Utils.ItemUtils;
|
import sig.plugin.TwosideKeeper.HelperStructures.Utils.ItemUtils;
|
||||||
import sig.plugin.TwosideKeeper.HelperStructures.Utils.SoundUtils;
|
import sig.plugin.TwosideKeeper.HelperStructures.Utils.SoundUtils;
|
||||||
import sig.plugin.TwosideKeeper.HelperStructures.Utils.TimeUtils;
|
import sig.plugin.TwosideKeeper.HelperStructures.Utils.TimeUtils;
|
||||||
@ -654,6 +659,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
|
|||||||
}
|
}
|
||||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||||
runServerHeartbeat.runVacuumCubeSuckup(p);
|
runServerHeartbeat.runVacuumCubeSuckup(p);
|
||||||
|
runServerHeartbeat.runFilterCubeCollection(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -705,7 +711,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
|
|||||||
Recipes.Initialize_CustomArrow_Recipes();
|
Recipes.Initialize_CustomArrow_Recipes();
|
||||||
Recipes.Initialize_NotchApple_Recipe();
|
Recipes.Initialize_NotchApple_Recipe();
|
||||||
|
|
||||||
//Bukkit.createWorld(new WorldCreator("ItemCube"));
|
Bukkit.createWorld(new WorldCreator("FilterCube"));
|
||||||
|
|
||||||
filesave=getDataFolder(); //Store the location of where our data folder is.
|
filesave=getDataFolder(); //Store the location of where our data folder is.
|
||||||
log("Data folder at "+filesave+".",3);
|
log("Data folder at "+filesave+".",3);
|
||||||
@ -3223,7 +3229,8 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
|
|||||||
if (ev.getCurrentItem().hasItemMeta()) {
|
if (ev.getCurrentItem().hasItemMeta()) {
|
||||||
ItemMeta item_meta = ev.getCurrentItem().getItemMeta();
|
ItemMeta item_meta = ev.getCurrentItem().getItemMeta();
|
||||||
if (item_meta.getDisplayName()!=null &&
|
if (item_meta.getDisplayName()!=null &&
|
||||||
(item_meta.getDisplayName().contains("Item Cube") || item_meta.getDisplayName().contains("Vacuum Cube"))) {
|
(item_meta.getDisplayName().contains("Item Cube") || item_meta.getDisplayName().contains("Vacuum Cube")
|
||||||
|
|| item_meta.getDisplayName().contains("Filter Cube"))) {
|
||||||
if (ev.isShiftClick()) {
|
if (ev.isShiftClick()) {
|
||||||
ev.setCancelled(true);
|
ev.setCancelled(true);
|
||||||
} else {
|
} else {
|
||||||
@ -3234,14 +3241,16 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
|
|||||||
item_lore.add(ChatColor.DARK_PURPLE+"ID#"+ITEMCUBEID);
|
item_lore.add(ChatColor.DARK_PURPLE+"ID#"+ITEMCUBEID);
|
||||||
item_meta.setLore(item_lore);
|
item_meta.setLore(item_lore);
|
||||||
ev.getCurrentItem().setItemMeta(item_meta);
|
ev.getCurrentItem().setItemMeta(item_meta);
|
||||||
if (ev.getCurrentItem().getItemMeta().getDisplayName().contains("Ender Item Cube")) {
|
|
||||||
ev.getCurrentItem().setAmount(2);
|
|
||||||
}
|
|
||||||
CubeType cubetype;
|
CubeType cubetype;
|
||||||
|
if (ev.getCurrentItem().getItemMeta().getDisplayName().contains("Filter Cube")) {
|
||||||
|
cubetype=CubeType.FILTER;
|
||||||
|
ItemCubeUtils.createNewFilterCube(ITEMCUBEID);
|
||||||
|
} else
|
||||||
if (ev.getCurrentItem().getItemMeta().getDisplayName().contains("Vacuum Cube")) {
|
if (ev.getCurrentItem().getItemMeta().getDisplayName().contains("Vacuum Cube")) {
|
||||||
cubetype=CubeType.VACUUM;
|
cubetype=CubeType.VACUUM;
|
||||||
} else
|
} else
|
||||||
if (ev.getCurrentItem().getItemMeta().getDisplayName().contains("Ender Item Cube")) {
|
if (ev.getCurrentItem().getItemMeta().getDisplayName().contains("Ender Item Cube")) {
|
||||||
|
ev.getCurrentItem().setAmount(2);
|
||||||
cubetype=CubeType.ENDER;
|
cubetype=CubeType.ENDER;
|
||||||
} else if (ev.getCurrentItem().getItemMeta().getDisplayName().contains("Large Item Cube")) {
|
} else if (ev.getCurrentItem().getItemMeta().getDisplayName().contains("Large Item Cube")) {
|
||||||
cubetype=CubeType.LARGE;
|
cubetype=CubeType.LARGE;
|
||||||
@ -3541,12 +3550,16 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(this,new DropDeathItems(p,list,deathloc),1);
|
Bukkit.getScheduler().scheduleSyncDelayedTask(this,new DropDeathItems(p,list,deathloc),1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerStructure pd = (PlayerStructure) playerdata.get(p.getUniqueId());
|
PlayerStructure pd = (PlayerStructure) playerdata.get(p.getUniqueId());
|
||||||
pd.isViewingInventory=false;
|
pd.isViewingInventory=false;
|
||||||
log("Closed Inventory.",5);
|
log("Closed Inventory.",5);
|
||||||
|
if (ev.getInventory().getHolder() instanceof Hopper &&
|
||||||
|
((Hopper)(ev.getInventory().getHolder())).getWorld().getName().equalsIgnoreCase("FilterCube")) {
|
||||||
|
SoundUtils.playLocalSound(p, Sound.BLOCK_CHEST_LOCKED, 0.6f, 0.4f);
|
||||||
|
}
|
||||||
|
else
|
||||||
//Check if this is an Item Cube inventory.
|
//Check if this is an Item Cube inventory.
|
||||||
if (pd.isViewingItemCube && ev.getInventory().getTitle().contains("Item Cube")) {
|
if (pd.isViewingItemCube && ev.getInventory().getTitle().contains("Item Cube")) {
|
||||||
//p.sendMessage("This is an Item Cube inventory.");
|
//p.sendMessage("This is an Item Cube inventory.");
|
||||||
@ -3684,16 +3697,6 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
|
|||||||
} else {
|
} else {
|
||||||
AnvilItem item = new AnvilItem(ev.getInventory().getItem(0),ev.getResult());
|
AnvilItem item = new AnvilItem(ev.getInventory().getItem(0),ev.getResult());
|
||||||
ev.setResult(item.renameItemProperly());
|
ev.setResult(item.renameItemProperly());
|
||||||
/*if (ev.getResult()!=null &&
|
|
||||||
ev.getInventory().getItem(0)!=null &&
|
|
||||||
ev.getInventory().getItem(0).getItemMeta().hasDisplayName()) {
|
|
||||||
String oldname = ev.getInventory().getItem(0).getItemMeta().getDisplayName();
|
|
||||||
String strippedname = ChatColor.stripColor(oldname);
|
|
||||||
String colorcodes = oldname.replace(strippedname, "");
|
|
||||||
ItemMeta m = ev.getResult().getItemMeta();
|
|
||||||
m.setDisplayName(strippedname.replace(colorcodes, ""));
|
|
||||||
ev.getResult().setItemMeta(m);
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3715,6 +3718,20 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
|
|||||||
},1);
|
},1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Check for a shift-right click for Filter Cubes.
|
||||||
|
if (ev.getClick()==ClickType.SHIFT_RIGHT) {
|
||||||
|
ItemStack item = ev.getCurrentItem();
|
||||||
|
if (CustomItem.isFilterCube(item)) {
|
||||||
|
int cubeid = ItemCubeUtils.getItemCubeID(item);
|
||||||
|
Hopper targethopper = ItemCubeUtils.getFilterCubeHopper(cubeid);
|
||||||
|
targethopper.getChunk().load();
|
||||||
|
ev.getWhoClicked().openInventory(targethopper.getInventory());
|
||||||
|
SoundUtils.playLocalSound((Player)ev.getWhoClicked(), Sound.BLOCK_CHEST_LOCKED, 1.0f, 1.0f);
|
||||||
|
ev.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ((ev.getClick()==ClickType.SHIFT_LEFT || ev.getClick()==ClickType.SHIFT_RIGHT) &&
|
if ((ev.getClick()==ClickType.SHIFT_LEFT || ev.getClick()==ClickType.SHIFT_RIGHT) &&
|
||||||
ev.getWhoClicked().getInventory().getExtraContents()[0]==null && GenericFunctions.AllowedToBeEquippedToOffHand((Player)ev.getWhoClicked(),ev.getCurrentItem(),ev.getRawSlot()) &&
|
ev.getWhoClicked().getInventory().getExtraContents()[0]==null && GenericFunctions.AllowedToBeEquippedToOffHand((Player)ev.getWhoClicked(),ev.getCurrentItem(),ev.getRawSlot()) &&
|
||||||
((ev.getInventory().getType()!=InventoryType.WORKBENCH && ev.getRawSlot()>=0) ||
|
((ev.getInventory().getType()!=InventoryType.WORKBENCH && ev.getRawSlot()>=0) ||
|
||||||
@ -5706,6 +5723,18 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (GenericFunctions.isValidArrow(ev.getItem().getItemStack())) {
|
||||||
|
ev.setCancelled(true);
|
||||||
|
ev.getItem().remove();
|
||||||
|
SoundUtils.playGlobalSound(ev.getPlayer().getLocation(), Sound.ENTITY_ITEM_PICKUP, 1.0f, 1.0f);
|
||||||
|
AddToPlayerInventory(ev.getItem().getItemStack(), p);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MUST BE HANDLED AFTER EVERYTHING ELSE.
|
||||||
|
*/
|
||||||
|
|
||||||
if (ev.getItem().getItemStack().getType().isBlock() && InventoryUtils.isCarryingVacuumCube(p)) {
|
if (ev.getItem().getItemStack().getType().isBlock() && InventoryUtils.isCarryingVacuumCube(p)) {
|
||||||
//Try to insert it into the Vacuum cube.
|
//Try to insert it into the Vacuum cube.
|
||||||
ItemStack[] remaining = InventoryUtils.insertItemsInVacuumCube(p, ev.getItem().getItemStack());
|
ItemStack[] remaining = InventoryUtils.insertItemsInVacuumCube(p, ev.getItem().getItemStack());
|
||||||
@ -5714,18 +5743,30 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
|
|||||||
ev.getItem().remove();
|
ev.getItem().remove();
|
||||||
SoundUtils.playGlobalSound(ev.getPlayer().getLocation(), Sound.ENTITY_ITEM_PICKUP, 1.0f, 1.0f);
|
SoundUtils.playGlobalSound(ev.getPlayer().getLocation(), Sound.ENTITY_ITEM_PICKUP, 1.0f, 1.0f);
|
||||||
return;
|
return;
|
||||||
|
} else {
|
||||||
|
ev.getItem().setItemStack(remaining[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GenericFunctions.isValidArrow(ev.getItem().getItemStack())) {
|
if (InventoryUtils.isCarryingFilterCube(p)) {
|
||||||
|
//Try to insert it into the Filter cube.
|
||||||
|
ItemStack[] remaining = InventoryUtils.insertItemsInFilterCube(p, ev.getItem().getItemStack());
|
||||||
|
if (remaining.length==0) {
|
||||||
ev.setCancelled(true);
|
ev.setCancelled(true);
|
||||||
ev.getItem().remove();
|
ev.getItem().remove();
|
||||||
SoundUtils.playGlobalSound(ev.getPlayer().getLocation(), Sound.ENTITY_ITEM_PICKUP, 1.0f, 1.0f);
|
SoundUtils.playGlobalSound(ev.getPlayer().getLocation(), Sound.ENTITY_ITEM_PICKUP, 1.0f, 1.0f);
|
||||||
AddToPlayerInventory(ev.getItem().getItemStack(), p);
|
|
||||||
return;
|
return;
|
||||||
|
} else {
|
||||||
|
ev.getItem().setItemStack(remaining[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ev.setCancelled(true);
|
||||||
|
ev.getItem().remove();
|
||||||
|
GenericFunctions.giveItem(p, ev.getItem().getItemStack());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean AutoConsumeItem(Player p, ItemStack item) {
|
private boolean AutoConsumeItem(Player p, ItemStack item) {
|
||||||
if (PlayerMode.getPlayerMode(p)==PlayerMode.BARBARIAN) {
|
if (PlayerMode.getPlayerMode(p)==PlayerMode.BARBARIAN) {
|
||||||
if (GenericFunctions.isAutoConsumeFood(item)) {
|
if (GenericFunctions.isAutoConsumeFood(item)) {
|
||||||
@ -6827,42 +6868,35 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
|
|||||||
File config;
|
File config;
|
||||||
config = new File(TwosideKeeper.filesave,"itemcubes/ItemCube"+id+".data");
|
config = new File(TwosideKeeper.filesave,"itemcubes/ItemCube"+id+".data");
|
||||||
FileConfiguration workable = YamlConfiguration.loadConfiguration(config);
|
FileConfiguration workable = YamlConfiguration.loadConfiguration(config);
|
||||||
|
CubeType type = CubeType.getCubeTypeFromID(workable.getInt("cubetype"));
|
||||||
for (int i=0;i<54;i++) {
|
for (int i=0;i<type.getSize();i++) {
|
||||||
ItemCube_items.add(workable.getItemStack("item"+i, new ItemStack(Material.AIR)));
|
ItemCube_items.add(workable.getItemStack("item"+i, new ItemStack(Material.AIR)));
|
||||||
}
|
}
|
||||||
return ItemCube_items;
|
return ItemCube_items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<ItemStack> itemCube_loadFilterConfig(int id){
|
||||||
|
List<ItemStack> ItemCube_items = new ArrayList<ItemStack>();
|
||||||
|
File config;
|
||||||
|
config = new File(TwosideKeeper.filesave,"itemcubes/ItemCube"+id+".data");
|
||||||
|
FileConfiguration workable = YamlConfiguration.loadConfiguration(config);
|
||||||
|
|
||||||
|
for (int i=0;i<5;i++) {
|
||||||
|
ItemCube_items.add(workable.getItemStack("filter"+i, new ItemStack(Material.AIR)));
|
||||||
|
}
|
||||||
|
return ItemCube_items;
|
||||||
|
}
|
||||||
|
|
||||||
public static CubeType itemCube_getCubeType(int id){
|
public static CubeType itemCube_getCubeType(int id){
|
||||||
File config;
|
File config;
|
||||||
config = new File(TwosideKeeper.filesave,"itemcubes/ItemCube"+id+".data");
|
config = new File(TwosideKeeper.filesave,"itemcubes/ItemCube"+id+".data");
|
||||||
FileConfiguration workable = YamlConfiguration.loadConfiguration(config);
|
FileConfiguration workable = YamlConfiguration.loadConfiguration(config);
|
||||||
|
return CubeType.getCubeTypeFromID(workable.getInt("cubetype"));
|
||||||
switch (workable.getInt("cubetype")) {
|
|
||||||
case 0:{return CubeType.NORMAL;}
|
|
||||||
case 1:{return CubeType.LARGE;}
|
|
||||||
case 2:{return CubeType.ENDER;}
|
|
||||||
case 3:{return CubeType.VACUUM;}
|
|
||||||
default:{return CubeType.NORMAL;}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Item Cube Saving.
|
//Item Cube Saving.
|
||||||
public static void itemCube_saveConfig(int id, List<ItemStack> items){
|
public static void itemCube_saveConfig(int id, List<ItemStack> items){
|
||||||
File config;
|
itemCube_saveConfig(id,items,null);
|
||||||
config = new File(TwosideKeeper.filesave,"itemcubes/ItemCube"+id+".data");
|
|
||||||
FileConfiguration workable = YamlConfiguration.loadConfiguration(config);
|
|
||||||
|
|
||||||
for (int i=0;i<items.size();i++) {
|
|
||||||
workable.set("item"+i, items.get(i));
|
|
||||||
}
|
|
||||||
//workable.set("cubetype", cubetype);
|
|
||||||
try {
|
|
||||||
workable.save(config);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void itemCube_saveConfig(int id, List<ItemStack> items, CubeType cubetype){
|
public static void itemCube_saveConfig(int id, List<ItemStack> items, CubeType cubetype){
|
||||||
@ -6873,11 +6907,8 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
|
|||||||
for (int i=0;i<items.size();i++) {
|
for (int i=0;i<items.size();i++) {
|
||||||
workable.set("item"+i, items.get(i));
|
workable.set("item"+i, items.get(i));
|
||||||
}
|
}
|
||||||
switch (cubetype) { //We have to convert it to a number because it's using the old version. We can't take advantage of the enum at this point.
|
if (cubetype!=null) {
|
||||||
case NORMAL:{workable.set("cubetype", 0);}break;
|
workable.set("cubetype", cubetype.getID());
|
||||||
case LARGE:{workable.set("cubetype", 1);}break;
|
|
||||||
case ENDER:{workable.set("cubetype", 2);}break;
|
|
||||||
case VACUUM:{workable.set("cubetype", 3);}break;
|
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
workable.save(config);
|
workable.save(config);
|
||||||
|
@ -350,6 +350,24 @@ final class runServerHeartbeat implements Runnable {
|
|||||||
TwosideKeeper.TwosideSpleefGames.TickEvent();
|
TwosideKeeper.TwosideSpleefGames.TickEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void runFilterCubeCollection(Player p) {
|
||||||
|
if (InventoryUtils.isCarryingFilterCube(p)) {
|
||||||
|
List<Entity> ents = p.getNearbyEntities(0.25, 0.25, 0.25);
|
||||||
|
for (Entity ent : ents) {
|
||||||
|
if (ent instanceof Item && GenericFunctions.itemCanBeSuckedUp((Item)ent)) {
|
||||||
|
Item it = (Item)ent;
|
||||||
|
ItemStack[] remaining = InventoryUtils.insertItemsInFilterCube(p, it.getItemStack());
|
||||||
|
if (remaining.length==0) {
|
||||||
|
it.remove();
|
||||||
|
SoundUtils.playGlobalSound(p.getLocation(), Sound.ENTITY_ITEM_PICKUP, 1.0f, 1.0f);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void runVacuumCubeSuckup(Player p) {
|
public static void runVacuumCubeSuckup(Player p) {
|
||||||
if (InventoryUtils.isCarryingVacuumCube(p)) {
|
if (InventoryUtils.isCarryingVacuumCube(p)) {
|
||||||
//Suck up nearby item entities.
|
//Suck up nearby item entities.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user