Vacuum Cube implementation completed.

This commit is contained in:
sigonasr2 2016-12-04 23:12:55 -06:00
parent e100ccaadc
commit 5507546ac5
8 changed files with 344 additions and 108 deletions

Binary file not shown.

View File

@ -45,4 +45,11 @@ public class ItemCube {
inv.addItem(cursor); inv.addItem(cursor);
} }
} }
public static void addToViewersOfItemCube(int idnumb, ItemStack[] cursor, Player check) {
Inventory inv = getViewingItemCubeInventory(idnumb, check);
if (inv!=null) {
inv.addItem(cursor);
}
}
} }

View File

@ -0,0 +1,21 @@
package sig.plugin.TwosideKeeper.HelperStructures.Utils;
import org.bukkit.inventory.ItemStack;
public class ArrayUtils {
public static String toString(ItemStack[] items) {
StringBuilder string = new StringBuilder();
boolean first=false;
for (ItemStack i : items) {
if (i!=null) {
if (!first) {
string.append(i.toString());
first=true;
} else {
string.append(","+i.toString());
}
}
}
return string.toString();
}
}

View File

@ -0,0 +1,58 @@
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.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import sig.plugin.TwosideKeeper.TwosideKeeper;
import sig.plugin.TwosideKeeper.HelperStructures.CubeType;
import sig.plugin.TwosideKeeper.HelperStructures.CustomItem;
import sig.plugin.TwosideKeeper.HelperStructures.ItemCube;
public class InventoryUtils {
public static boolean isCarryingVacuumCube(Player p) {
for (ItemStack items : p.getInventory().getContents()) {
if (items!=null && CustomItem.isVacuumCube(items)) {
return true;
}
}
return false;
}
public static ItemStack[] insertItemsInVacuumCube(Player p,ItemStack...items) {
ItemStack[] remaining = items;
for (ItemStack itemStacks : p.getInventory().getContents()) {
if (itemStacks!=null && CustomItem.isVacuumCube(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, itemCubeContents.size());
for (int i=0;i<virtualinventory.getSize();i++) {
if (itemCubeContents.get(i)!=null) {
virtualinventory.setItem(i, itemCubeContents.get(i));
}
}
//TwosideKeeper.log("Items: "+ArrayUtils.toString(remaining), 0);
HashMap<Integer,ItemStack> remainingitems = virtualinventory.addItem(remaining);
List<ItemStack> itemslist = new ArrayList<ItemStack>();
for (int i=0;i<virtualinventory.getSize();i++) {
itemslist.add(virtualinventory.getItem(i));
}
ItemCube.addToViewersOfItemCube(id,remaining,null);
TwosideKeeper.itemCube_saveConfig(id, itemslist, CubeType.VACUUM);
/*for (ItemStack i : remainingitems.values()) {
TwosideKeeper.log("Item "+i+" remains", 0);
}*/
remaining = remainingitems.values().toArray(new ItemStack[0]);
//TwosideKeeper.log("Remaining items: "+ArrayUtils.toString(remaining), 0);
}
}
return remaining;
}
}

View File

@ -8,6 +8,8 @@ import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import sig.plugin.TwosideKeeper.TwosideKeeper;
public class ItemUtils { public class ItemUtils {
public static void addLore(ItemStack item, String string) { public static void addLore(ItemStack item, String string) {
@ -65,6 +67,18 @@ public class ItemUtils {
return false; return false;
} }
public static String GetLoreLineContainingString(ItemStack item, String string) {
if (isValidLoreItem(item)) {
List<String> lore = item.getItemMeta().getLore();
for (String l : lore) {
if (l.contains(string)) {
return l;
}
}
}
return "";
}
public static String GetLoreLine(ItemStack item, int line_numb) { public static String GetLoreLine(ItemStack item, int line_numb) {
if (isValidLoreItem(item)) { if (isValidLoreItem(item)) {
List<String> lore = item.getItemMeta().getLore(); List<String> lore = item.getItemMeta().getLore();

View File

@ -14,7 +14,7 @@ public class ItemCubeWindow {
public static void addItemCubeWindow(Player p, int id) { public static void addItemCubeWindow(Player p, int id) {
PlayerStructure pd = PlayerStructure.GetPlayerStructure(p); PlayerStructure pd = PlayerStructure.GetPlayerStructure(p);
pd.itemcubelist.add(id); pd.itemcubelist.add(id);
TwosideKeeper.log("Added cube "+id+" to Item Cube List for Player "+p.getName()+". New list: "+pd.itemcubelist.toString(),0); TwosideKeeper.log("Added cube "+id+" to Item Cube List for Player "+p.getName()+". New list: "+pd.itemcubelist.toString(),3);
} }
public static void popItemCubeWindow(Player p) { public static void popItemCubeWindow(Player p) {
//Opens the next possible item cube inventory from the list of inventories. //Opens the next possible item cube inventory from the list of inventories.
@ -22,7 +22,7 @@ public class ItemCubeWindow {
if (pd.itemcubelist.size()>0 && !pd.opened_another_cube) { if (pd.itemcubelist.size()>0 && !pd.opened_another_cube) {
int index = pd.itemcubelist.size()-1; int index = pd.itemcubelist.size()-1;
Integer itemcubeid = pd.itemcubelist.get(index); Integer itemcubeid = pd.itemcubelist.get(index);
TwosideKeeper.log("Popping Item Cube ID "+index+" from "+p.getName()+"'s list.", 0); TwosideKeeper.log("Popping Item Cube ID "+index+" from "+p.getName()+"'s list.", 3);
pd.itemcubelist.remove(index); pd.itemcubelist.remove(index);
Bukkit.getScheduler().scheduleSyncDelayedTask(TwosideKeeper.plugin, new Runnable() { Bukkit.getScheduler().scheduleSyncDelayedTask(TwosideKeeper.plugin, new Runnable() {
@ -32,6 +32,7 @@ public class ItemCubeWindow {
CubeType size = TwosideKeeper.itemCube_getCubeType(itemcubeid); CubeType size = TwosideKeeper.itemCube_getCubeType(itemcubeid);
int inv_size = 9; int inv_size = 9;
if (size==CubeType.VACUUM) { if (size==CubeType.VACUUM) {
TwosideKeeper.log("Opening Vacuum cube.", 5);
inv_size=54; inv_size=54;
} else } else
if (size!=CubeType.NORMAL) { if (size!=CubeType.NORMAL) {
@ -47,9 +48,11 @@ public class ItemCubeWindow {
SoundUtils.playLocalSound(p,Sound.BLOCK_CHEST_OPEN,1.0f,1.0f); SoundUtils.playLocalSound(p,Sound.BLOCK_CHEST_OPEN,1.0f,1.0f);
} else { } else {
pd.opened_another_cube=true; pd.opened_another_cube=true;
Bukkit.getScheduler().scheduleSyncDelayedTask(TwosideKeeper.plugin, new Runnable() {@Override public void run() {p.openInventory(ItemCube.getViewingItemCubeInventory(itemcubeid, p)); Bukkit.getScheduler().scheduleSyncDelayedTask(TwosideKeeper.plugin, new Runnable() {@Override public void run() {
pd.opened_another_cube=false; p.openInventory(ItemCube.getViewingItemCubeInventory(itemcubeid, p));
pd.isViewingItemCube=true;}},1); pd.opened_another_cube=false;
pd.isViewingItemCube=true;
}},1);
SoundUtils.playLocalSound(p, Sound.BLOCK_CHEST_OPEN, 1.0f, 1.0f); SoundUtils.playLocalSound(p, Sound.BLOCK_CHEST_OPEN, 1.0f, 1.0f);
} }
}},1); }},1);

View File

@ -189,6 +189,7 @@ 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.BlockUtils; import sig.plugin.TwosideKeeper.HelperStructures.Utils.BlockUtils;
import sig.plugin.TwosideKeeper.HelperStructures.Utils.InventoryUtils;
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;
@ -650,6 +651,9 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
ScheduleRemoval(lavaplume_list,lp); ScheduleRemoval(lavaplume_list,lp);
} }
} }
for (Player p : Bukkit.getOnlinePlayers()) {
runServerHeartbeat.runVacuumCubeSuckup(p);
}
} }
private void UpdateLavaBlock(Block lavamod) { private void UpdateLavaBlock(Block lavamod) {
@ -984,9 +988,17 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
case "WITHER":{ case "WITHER":{
LivingEntity m = MonsterController.convertMonster((Monster)p.getWorld().spawnEntity(p.getLocation(),EntityType.WITHER), MonsterDifficulty.ELITE); LivingEntity m = MonsterController.convertMonster((Monster)p.getWorld().spawnEntity(p.getLocation(),EntityType.WITHER), MonsterDifficulty.ELITE);
}break; }break;
case "VACUUM":{
ItemStack[] remaining = InventoryUtils.insertItemsInVacuumCube(p, new ItemStack(Material.ENDER_PEARL,16), new ItemStack(Material.IRON_PICKAXE,1), new ItemStack(Material.GOLDEN_APPLE,64));
for (ItemStack items : remaining) {
if (items!=null) {
p.getWorld().dropItemNaturally(p.getLocation(), items);
}
}
}break;
} }
} }
LivingEntity m = MonsterController.convertMonster((Monster)p.getWorld().spawnEntity(p.getLocation(),EntityType.ZOMBIE), MonsterDifficulty.ELITE); //LivingEntity m = MonsterController.convertMonster((Monster)p.getWorld().spawnEntity(p.getLocation(),EntityType.ZOMBIE), MonsterDifficulty.ELITE);
/* /*
StackTraceElement[] stacktrace = new Throwable().getStackTrace(); StackTraceElement[] stacktrace = new Throwable().getStackTrace();
StringBuilder stack = new StringBuilder("Mini stack tracer:"); StringBuilder stack = new StringBuilder("Mini stack tracer:");
@ -2475,7 +2487,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
} else { } else {
size=27; size=27;
} }
CubeType cub = (size==9)?CubeType.NORMAL:CubeType.LARGE; CubeType cub = (size==9)?CubeType.NORMAL:(size==54)?CubeType.VACUUM:CubeType.LARGE;
//Now that we have the item cube. Dump whatever contents we can into the container. //Now that we have the item cube. Dump whatever contents we can into the container.
//We need to make sure the chest is not a world shop. If it is, we can see if we're the owner of it. //We need to make sure the chest is not a world shop. If it is, we can see if we're the owner of it.
@ -3363,7 +3375,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
itemlist.add(ev.getPlayer().getOpenInventory().getTopInventory().getItem(i)); itemlist.add(ev.getPlayer().getOpenInventory().getTopInventory().getItem(i));
} }
final Player p = ev.getPlayer(); final Player p = ev.getPlayer();
itemCube_saveConfig(itemcube_id,itemlist,((ev.getItemDrop().getItemStack().getType()==Material.CHEST)?CubeType.NORMAL:(ev.getItemDrop().getItemStack().getType()==Material.STORAGE_MINECART)?CubeType.LARGE:CubeType.ENDER)); itemCube_saveConfig(itemcube_id,itemlist,((ev.getItemDrop().getItemStack().getType()==Material.CHEST)?CubeType.NORMAL:(ev.getItemDrop().getItemStack().getType()==Material.STORAGE_MINECART)?CubeType.LARGE:((CustomItem.isVacuumCube(ev.getItemDrop().getItemStack())))?CubeType.VACUUM:CubeType.ENDER));
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() { Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
@Override @Override
public void run() { public void run() {
@ -3549,7 +3561,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
itemcube_contents.add(new ItemStack(Material.AIR)); itemcube_contents.add(new ItemStack(Material.AIR));
} }
} }
CubeType cub = p.getOpenInventory().getTopInventory().getSize()==9?CubeType.NORMAL:CubeType.LARGE; CubeType cub = p.getOpenInventory().getTopInventory().getSize()==9?CubeType.NORMAL:p.getOpenInventory().getTopInventory().getSize()==54?CubeType.VACUUM:CubeType.LARGE;
SoundUtils.playLocalSound(p, Sound.BLOCK_CHEST_CLOSE, 1.0f, 1.0f); SoundUtils.playLocalSound(p, Sound.BLOCK_CHEST_CLOSE, 1.0f, 1.0f);
itemCube_saveConfig(id,itemcube_contents,cub); itemCube_saveConfig(id,itemcube_contents,cub);
if (!pd.opened_another_cube) { if (!pd.opened_another_cube) {
@ -3865,49 +3877,54 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
} }
} }
//Check for a Vacuum Cube. If this is a Vacuum Cube and we're trying to do something with the item, then don't allow it.
PerformVacuumCubeChecks(ev);
//LEFT CLICK STUFF. //LEFT CLICK STUFF.
//WARNING! This only happens for ITEM CUBES! Do not add other items in here! //WARNING! This only happens for ITEM CUBES! Do not add other items in here!
pd = (PlayerStructure) playerdata.get(ev.getWhoClicked().getUniqueId()); pd = (PlayerStructure) playerdata.get(ev.getWhoClicked().getUniqueId());
if (((ev.getInventory().getType()!=InventoryType.WORKBENCH && ev.getRawSlot()>=0) || if (ev.getClick()==ClickType.RIGHT || ev.getClick()==ClickType.SHIFT_RIGHT || (ev.getCursor()==null || ev.getCursor().getType()==Material.AIR)) {
(ev.getInventory().getType()==InventoryType.WORKBENCH && ev.getRawSlot()>9)) && ev.getCurrentItem()!=null) { if (((ev.getInventory().getType()!=InventoryType.WORKBENCH && ev.getRawSlot()>=0) ||
if (ev.getCurrentItem().hasItemMeta() && (ev.getCurrentItem().getType()!=Material.AIR)) { (ev.getInventory().getType()==InventoryType.WORKBENCH && ev.getRawSlot()>9)) && ev.getCurrentItem()!=null) {
ItemMeta item_meta = ev.getCurrentItem().getItemMeta(); if (ev.getCurrentItem().hasItemMeta() && (ev.getCurrentItem().getType()!=Material.AIR)) {
if (item_meta.hasLore()) { ItemMeta item_meta = ev.getCurrentItem().getItemMeta();
List<String> item_meta_lore = item_meta.getLore(); if (item_meta.hasLore()) {
if (item_meta_lore.size()==4 && item_meta_lore.get(3).contains(ChatColor.DARK_PURPLE+"ID#")) { List<String> item_meta_lore = item_meta.getLore();
int itemcubeid = -1; if (item_meta_lore.size()==4 && item_meta_lore.get(3).contains(ChatColor.DARK_PURPLE+"ID#")) {
if (((PlayerStructure)playerdata.get(ev.getWhoClicked().getUniqueId())).isViewingItemCube && int itemcubeid = -1;
ev.getWhoClicked().getOpenInventory().getTitle().contains("Item Cube #")) { if (((PlayerStructure)playerdata.get(ev.getWhoClicked().getUniqueId())).isViewingItemCube &&
itemcubeid = Integer.parseInt(ev.getWhoClicked().getOpenInventory().getTitle().split("#")[1]); //This is the ID of the window we are looking at, if one exists. ev.getWhoClicked().getOpenInventory().getTitle().contains("Item Cube #")) {
} else { itemcubeid = Integer.parseInt(ev.getWhoClicked().getOpenInventory().getTitle().split("#")[1]); //This is the ID of the window we are looking at, if one exists.
itemcubeid = -1; } else {
} itemcubeid = -1;
//This is an Item Cube. }
//Check to see if the cursor item is an item cube. //This is an Item Cube.
if ((ev.getCurrentItem().getType()==Material.CHEST || //Check to see if the cursor item is an item cube.
ev.getCurrentItem().getType()==Material.STORAGE_MINECART || if ((ev.getCurrentItem().getType()==Material.CHEST ||
ev.getCurrentItem().getType()==Material.ENDER_CHEST) && ev.getCurrentItem().getType()==Material.STORAGE_MINECART ||
ev.getCurrentItem().hasItemMeta() && ev.getCurrentItem().getType()==Material.ENDER_CHEST) &&
ev.getCurrentItem().getItemMeta().hasLore()) { ev.getCurrentItem().hasItemMeta() &&
log("The clicked item has lore...",5); ev.getCurrentItem().getItemMeta().hasLore()) {
for (int i=0;i<ev.getCurrentItem().getItemMeta().getLore().size();i++) { log("The clicked item has lore...",5);
if (ev.getCurrentItem().getItemMeta().getLore().get(i).contains(ChatColor.DARK_PURPLE+"ID#")) { for (int i=0;i<ev.getCurrentItem().getItemMeta().getLore().size();i++) {
log("We clicked an item cube, checking ID.",5); if (ev.getCurrentItem().getItemMeta().getLore().get(i).contains(ChatColor.DARK_PURPLE+"ID#")) {
//We clicked an item cube. Check its ID. log("We clicked an item cube, checking ID.",5);
int clicked_id = Integer.parseInt(ev.getCurrentItem().getItemMeta().getLore().get(i).split("#")[1]); //We clicked an item cube. Check its ID.
log("ID is "+clicked_id+" and we are viewing "+itemcubeid,5); int clicked_id = Integer.parseInt(ev.getCurrentItem().getItemMeta().getLore().get(i).split("#")[1]);
if (clicked_id==itemcubeid) { log("ID is "+clicked_id+" and we are viewing "+itemcubeid,5);
//The inventory we are viewing is the same as the item cube we have clicked on! if (clicked_id==itemcubeid) {
//Stop this before the player does something dumb! //The inventory we are viewing is the same as the item cube we have clicked on!
//Player p = ((Player)ev.getWhoClicked()); //Stop this before the player does something dumb!
//SoundUtils.playLocalSound(p, Sound.BLOCK_NOTE_HARP, 0.4f, 0.2f); //Player p = ((Player)ev.getWhoClicked());
ev.setCancelled(true); //SoundUtils.playLocalSound(p, Sound.BLOCK_NOTE_HARP, 0.4f, 0.2f);
return; ev.setCancelled(true);
return;
}
} }
} }
} }
} }}}}
}}}} }
//WARNING! This only happens for ITEM CUBES! Do not add other items in here! //WARNING! This only happens for ITEM CUBES! Do not add other items in here!
if (((ev.getInventory().getType()!=InventoryType.WORKBENCH && ev.getRawSlot()>=0) || if (((ev.getInventory().getType()!=InventoryType.WORKBENCH && ev.getRawSlot()>=0) ||
@ -3924,16 +3941,6 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
ev.setCancelled(true); ev.setCancelled(true);
//ev.setResult(Result.DENY); //ev.setResult(Result.DENY);
if (ev.getCurrentItem().getType()==Material.CHEST) {
cubetype=CubeType.NORMAL;
} else {
if (ev.getCurrentItem().getType()==Material.STORAGE_MINECART) {
cubetype=CubeType.LARGE;
} else {
cubetype=CubeType.ENDER;
}
}
int clicked_size; int clicked_size;
if (ev.getCurrentItem().getType()==Material.CHEST) { if (ev.getCurrentItem().getType()==Material.CHEST) {
@ -3941,6 +3948,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
cubetype=CubeType.NORMAL; cubetype=CubeType.NORMAL;
} else { } else {
if (CustomItem.isVacuumCube(ev.getCurrentItem())) { if (CustomItem.isVacuumCube(ev.getCurrentItem())) {
cubetype=CubeType.VACUUM;
clicked_size=54; clicked_size=54;
} else { } else {
clicked_size=27; clicked_size=27;
@ -3948,7 +3956,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
cubetype=CubeType.LARGE; cubetype=CubeType.LARGE;
} else { } else {
cubetype=CubeType.ENDER; cubetype=CubeType.ENDER;
} }
} }
} }
@ -3992,57 +4000,70 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
} }
else else
//Make sure we are not already inside the cube we're placing into. //Make sure we are not already inside the cube we're placing into.
if (idnumb!=itemcubeid) { {
//See if someone has this inventory opened already. CubeType cub = clicked_size==9?CubeType.NORMAL:clicked_size==54?CubeType.VACUUM:CubeType.LARGE;
Inventory virtualinventory = null; if (cub==CubeType.VACUUM) {
virtualinventory = ItemCube.getViewingItemCubeInventory(idnumb, (Player)ev.getWhoClicked()); //A Vacuum Cube only accepts blocks, not items.
if (virtualinventory==null) { TwosideKeeper.log("Cursor is "+ev.getCursor(), 5);
virtualinventory = Bukkit.createInventory((Player)ev.getWhoClicked(), clicked_size); if (!ev.getCursor().getType().isBlock()) {
log("Inventory size is "+clicked_size,5); TwosideKeeper.log("Not allowed! "+ev.getCurrentItem()+","+ev.getCursor(), 5);
List<ItemStack> items = itemCube_loadConfig(idnumb); ev.getWhoClicked().sendMessage(ChatColor.RED+"You can only insert/remove Blocks in a Vacuum Cube.");
for (int i=0;i<virtualinventory.getSize();i++) { ev.setCursor(ev.getCursor());
if (items.get(i)!=null) { ev.setCancelled(true);
virtualinventory.setItem(i, items.get(i)); return;
log("Load up with "+items.get(i).toString(),5);
}
}
ItemCube.addToViewersOfItemCube(idnumb,ev.getCursor(),(Player)ev.getWhoClicked());
} }
HashMap<Integer,ItemStack> result = virtualinventory.addItem(ev.getCursor()); }
log("Clicked ID number "+idnumb,5); if (idnumb!=itemcubeid) {
//Set whatever's left back to the cursor. //See if someone has this inventory opened already.
if (result.size()>0) { Inventory virtualinventory = null;
ev.setCursor((ItemStack)result.get(0)); virtualinventory = ItemCube.getViewingItemCubeInventory(idnumb, (Player)ev.getWhoClicked());
if (virtualinventory==null) {
virtualinventory = Bukkit.createInventory((Player)ev.getWhoClicked(), clicked_size);
log("Inventory size is "+clicked_size,5);
List<ItemStack> items = itemCube_loadConfig(idnumb);
for (int i=0;i<virtualinventory.getSize();i++) {
if (items.get(i)!=null) {
virtualinventory.setItem(i, items.get(i));
log("Load up with "+items.get(i).toString(),5);
}
}
ItemCube.addToViewersOfItemCube(idnumb,ev.getCursor(),(Player)ev.getWhoClicked());
}
HashMap<Integer,ItemStack> result = virtualinventory.addItem(ev.getCursor());
log("Clicked ID number "+idnumb,5);
//Set whatever's left back to the cursor.
if (result.size()>0) {
ev.setCursor((ItemStack)result.get(0));
} else {
ev.setCursor(new ItemStack(Material.AIR));
log("Cursor should be air.",5);
}
List<ItemStack> itemslist = new ArrayList<ItemStack>();
for (int i=0;i<virtualinventory.getSize();i++) {
itemslist.add(virtualinventory.getItem(i));
}
itemCube_saveConfig(idnumb,itemslist,cub);
return;
} else { } else {
ev.setCursor(new ItemStack(Material.AIR)); //Well, we're already in here, I don't know why they didn't just use the
log("Cursor should be air.",5); //minecraft inventory management system. Now I have to do math...
} //Add it to the inventory being viewed.
List<ItemStack> itemslist = new ArrayList<ItemStack>(); HashMap<Integer,ItemStack> result = ev.getWhoClicked().getOpenInventory().getTopInventory().addItem(ev.getCursor());
for (int i=0;i<virtualinventory.getSize();i++) { //Add it to everyone viewing the cube.
itemslist.add(virtualinventory.getItem(i)); //ItemCube.addToViewersOfItemCube(idnumb, ev.getCursor(), (Player)ev.getWhoClicked());
}
CubeType cub = clicked_size==9?CubeType.NORMAL:CubeType.LARGE;
itemCube_saveConfig(idnumb,itemslist,cub);
return;
} else {
//Well, we're already in here, I don't know why they didn't just use the
//minecraft inventory management system. Now I have to do math...
//Add it to the inventory being viewed.
HashMap<Integer,ItemStack> result = ev.getWhoClicked().getOpenInventory().getTopInventory().addItem(ev.getCursor());
//Add it to everyone viewing the cube.
//ItemCube.addToViewersOfItemCube(idnumb, ev.getCursor(), (Player)ev.getWhoClicked());
if (result.size()>0) { if (result.size()>0) {
ev.setCursor((ItemStack)result.get(0)); ev.setCursor((ItemStack)result.get(0));
} else { } else {
ev.setCursor(new ItemStack(Material.AIR)); ev.setCursor(new ItemStack(Material.AIR));
} }
List<ItemStack> itemslist = new ArrayList<ItemStack>(); List<ItemStack> itemslist = new ArrayList<ItemStack>();
for (int i=0;i<ev.getWhoClicked().getOpenInventory().getTopInventory().getSize();i++) { for (int i=0;i<ev.getWhoClicked().getOpenInventory().getTopInventory().getSize();i++) {
itemslist.add(ev.getWhoClicked().getOpenInventory().getTopInventory().getItem(i)); itemslist.add(ev.getWhoClicked().getOpenInventory().getTopInventory().getItem(i));
} }
itemCube_saveConfig(idnumb,itemslist); itemCube_saveConfig(idnumb,itemslist);
return; return;
}
} }
} }
} }
@ -4077,6 +4098,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
ev.setCancelled(true); ev.setCancelled(true);
return; return;
} else { } else {
TwosideKeeper.log("Got to here. ID is "+itemcubeid, 5);
Player p = (Player)ev.getWhoClicked(); Player p = (Player)ev.getWhoClicked();
if (itemcubeid!=-1 && ev.getRawSlot()<=ev.getView().getTopInventory().getSize()-1) { if (itemcubeid!=-1 && ev.getRawSlot()<=ev.getView().getTopInventory().getSize()-1) {
//This means we are viewing an item cube currently. Add it to our list. //This means we are viewing an item cube currently. Add it to our list.
@ -4130,6 +4152,34 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
} }
} }
public void PerformVacuumCubeChecks(InventoryClickEvent ev) {
if (((ev.getInventory().getType()!=InventoryType.WORKBENCH && ev.getRawSlot()>=0) ||
(ev.getInventory().getType()==InventoryType.WORKBENCH && ev.getRawSlot()>9)) && ev.getCurrentItem()!=null) {
//int idnumb = Integer.parseInt(item_meta_lore.get(3).split("#")[1]);
int itemcubeid = -1; //This is the ID of the window we are looking at, if one exists.
CubeType cubetype = CubeType.NORMAL;
//This is an Item Cube.
//ev.setResult(Result.DENY);
if (((PlayerStructure)playerdata.get(ev.getWhoClicked().getUniqueId())).isViewingItemCube &&
ev.getWhoClicked().getOpenInventory().getTitle().contains("Item Cube #")) {
itemcubeid = Integer.parseInt(ev.getWhoClicked().getOpenInventory().getTitle().split("#")[1]); //This is the ID of the window we are looking at, if one exists.
cubetype = itemCube_getCubeType(itemcubeid);
if (cubetype==CubeType.VACUUM) {
//TwosideKeeper.log(ev.getCurrentItem()+"|||"+ev.getCursor(), 0);
if ((ev.getCurrentItem().getType()!=Material.AIR && !ev.getCurrentItem().getType().isBlock()) || (ev.getCursor().getType()!=Material.AIR && !ev.getCursor().getType().isBlock())) {
ev.getWhoClicked().sendMessage(ChatColor.RED+"You can only insert/remove Blocks in a Vacuum Cube.");
//TwosideKeeper.log((ev.getCurrentItem().getType()!=Material.AIR)+","+(!ev.getCurrentItem().getType().isBlock())+"|||"+(ev.getCursor().getType()!=Material.AIR)+","+(!ev.getCursor().getType().isBlock()), 0);
ev.setCancelled(true);
return;
}
}
} else {
itemcubeid = -1;
}
}
}
@EventHandler(priority=EventPriority.LOW,ignoreCancelled = true) @EventHandler(priority=EventPriority.LOW,ignoreCancelled = true)
public void onItemSpawn(ItemSpawnEvent ev) { public void onItemSpawn(ItemSpawnEvent ev) {
//If the item is of a rare type, we will highlight it for emphasis. //If the item is of a rare type, we will highlight it for emphasis.
@ -5655,11 +5705,23 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
return; return;
} }
if (ev.getItem().getItemStack().getType().isBlock() && InventoryUtils.isCarryingVacuumCube(p)) {
//Try to insert it into the Vacuum cube.
ItemStack[] remaining = InventoryUtils.insertItemsInVacuumCube(p, ev.getItem().getItemStack());
if (remaining.length==0) {
ev.setCancelled(true);
ev.getItem().remove();
SoundUtils.playGlobalSound(ev.getPlayer().getLocation(), Sound.ENTITY_ITEM_PICKUP, 1.0f, 1.0f);
return;
}
}
if (GenericFunctions.isValidArrow(ev.getItem().getItemStack())) { if (GenericFunctions.isValidArrow(ev.getItem().getItemStack())) {
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); AddToPlayerInventory(ev.getItem().getItemStack(), p);
return;
} }
} }
@ -6786,7 +6848,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
} }
//Item Cube Saving. //Item Cube Saving.
public void itemCube_saveConfig(int id, List<ItemStack> items){ public static void itemCube_saveConfig(int id, List<ItemStack> items){
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);
@ -6802,7 +6864,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
} }
} }
public void itemCube_saveConfig(int id, List<ItemStack> items, CubeType cubetype){ public static void itemCube_saveConfig(int id, List<ItemStack> items, CubeType cubetype){
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);

View File

@ -15,7 +15,9 @@ import org.bukkit.Particle;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.attribute.Attribute; import org.bukkit.attribute.Attribute;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.FallingBlock; import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.Item;
import org.bukkit.entity.Monster; import org.bukkit.entity.Monster;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -35,6 +37,7 @@ import sig.plugin.TwosideKeeper.HelperStructures.ServerType;
import sig.plugin.TwosideKeeper.HelperStructures.WorldShop; import sig.plugin.TwosideKeeper.HelperStructures.WorldShop;
import sig.plugin.TwosideKeeper.HelperStructures.Common.GenericFunctions; import sig.plugin.TwosideKeeper.HelperStructures.Common.GenericFunctions;
import sig.plugin.TwosideKeeper.HelperStructures.Effects.LavaPlume; import sig.plugin.TwosideKeeper.HelperStructures.Effects.LavaPlume;
import sig.plugin.TwosideKeeper.HelperStructures.Utils.InventoryUtils;
import sig.plugin.TwosideKeeper.HelperStructures.Utils.MessageUtils; import sig.plugin.TwosideKeeper.HelperStructures.Utils.MessageUtils;
import sig.plugin.TwosideKeeper.HelperStructures.Utils.SoundUtils; import sig.plugin.TwosideKeeper.HelperStructures.Utils.SoundUtils;
@ -335,6 +338,7 @@ final class runServerHeartbeat implements Runnable {
GenericFunctions.applyStealth(p, true); GenericFunctions.applyStealth(p, true);
} }
} }
} }
//TwosideKeeper.outputArmorDurability(p,">"); //TwosideKeeper.outputArmorDurability(p,">");
} }
@ -346,6 +350,73 @@ final class runServerHeartbeat implements Runnable {
TwosideKeeper.TwosideSpleefGames.TickEvent(); TwosideKeeper.TwosideSpleefGames.TickEvent();
} }
public static void runVacuumCubeSuckup(Player p) {
if (InventoryUtils.isCarryingVacuumCube(p)) {
//Suck up nearby item entities.
List<Entity> ents = p.getNearbyEntities(8, 8, 8);
for (Entity ent : ents) {
if (ent instanceof Item) {
//Pull towards the player.
double SPD = 0.2;
double deltax = ent.getLocation().getX()-p.getLocation().getX();
double deltay = ent.getLocation().getY()-p.getLocation().getY();
double deltaz = ent.getLocation().getZ()-p.getLocation().getZ();
double xvel = 0;
double yvel = 0;
double zvel = 0;
if (deltax>0.25) {
xvel=-SPD*(Math.min(10, Math.abs(deltax)));
} else
if (deltax<-0.25) {
xvel=SPD*(Math.min(10, Math.abs(deltax)));
}
if (deltay>0.01) {
yvel=-SPD*deltay*4;
} else
if (deltay<-0.01) {
yvel=SPD*deltay*4;
}
if (deltaz>0.25) {
zvel=-SPD*(Math.min(10, Math.abs(deltaz)));
} else
if (deltaz<-0.25) {
zvel=SPD*(Math.min(10, Math.abs(deltaz)));
}
if (Math.abs(deltax)<0.25 &&
Math.abs(deltay)<0.25 &&
Math.abs(deltaz)<0.25) {
//Collect this item.
if (((Item)ent).getItemStack().getType().isBlock()) {
ItemStack[] remaining = InventoryUtils.insertItemsInVacuumCube(p, ((Item) ent).getItemStack());
if (remaining.length==0) {
SoundUtils.playGlobalSound(ent.getLocation(), Sound.ENTITY_ITEM_PICKUP, 1.0f, 1.4f);
ent.remove();
return;
}
}
} else {
ent.setVelocity(new Vector(xvel,yvel,zvel));
}
/*if (ent.getLocation().getX()<p.getLocation().getX()) {
ent.setVelocity(ent.getVelocity().setX(SPD*(10-Math.min(10,Math.abs()))));
} else {
ent.setVelocity(ent.getVelocity().setX(-SPD*(10-Math.min(10,Math.abs(p.getLocation().getX()-ent.getLocation().getX())))));
}
if (ent.getLocation().getY()<p.getLocation().getY()) {
ent.setVelocity(ent.getVelocity().setY(SPD*(10-Math.min(10,Math.abs(p.getLocation().getY()-ent.getLocation().getY())))));
} else {
ent.setVelocity(ent.getVelocity().setY(-SPD*(10-Math.min(10,Math.abs(p.getLocation().getY()-ent.getLocation().getY())))));
}
if (ent.getLocation().getZ()<p.getLocation().getZ()) {
ent.setVelocity(ent.getVelocity().setZ(SPD*(10-Math.min(10,Math.abs(p.getLocation().getZ()-ent.getLocation().getZ())))));
} else {
ent.setVelocity(ent.getVelocity().setZ(-SPD*(10-Math.min(10,Math.abs(p.getLocation().getZ()-ent.getLocation().getZ())))));
}*/
}
}
}
}
private void PopRandomLavaBlock(Player p) { private void PopRandomLavaBlock(Player p) {
if (p.getWorld().getName().equalsIgnoreCase("world_nether") && if (p.getWorld().getName().equalsIgnoreCase("world_nether") &&
TwosideKeeper.last_lava_plume_time+(TwosideKeeper.LAVA_PLUME_COOLDOWN/(Math.max(Bukkit.getOnlinePlayers().size(),1)))<TwosideKeeper.getServerTickTime()) { TwosideKeeper.last_lava_plume_time+(TwosideKeeper.LAVA_PLUME_COOLDOWN/(Math.max(Bukkit.getOnlinePlayers().size(),1)))<TwosideKeeper.getServerTickTime()) {