Buggy graph system implementation

This commit is contained in:
sigonasr2 2017-04-07 23:48:59 -05:00
parent a8aa59ed25
commit c8abd91f50
5 changed files with 207 additions and 134 deletions

Binary file not shown.

View File

@ -1,6 +1,6 @@
name: TwosideKeeper name: TwosideKeeper
main: sig.plugin.TwosideKeeper.TwosideKeeper main: sig.plugin.TwosideKeeper.TwosideKeeper
version: 3.10.9dr1 version: 3.10.9e
loadbefore: [aPlugin] loadbefore: [aPlugin]
commands: commands:
money: money:

View File

@ -9,10 +9,13 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
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 sig.plugin.TwosideKeeper.PlayerStructure;
import sig.plugin.TwosideKeeper.TwosideKeeper; import sig.plugin.TwosideKeeper.TwosideKeeper;
import sig.plugin.TwosideKeeper.HelperStructures.CubeType; import sig.plugin.TwosideKeeper.HelperStructures.CubeType;
import sig.plugin.TwosideKeeper.HelperStructures.CustomItem; import sig.plugin.TwosideKeeper.HelperStructures.CustomItem;
@ -285,15 +288,26 @@ public class InventoryUtils {
} }
public static int getInventoryNumberHash(Inventory destination) { public static int getInventoryNumberHash(Inventory destination) {
Location loc = destination.getLocation(); InventoryHolder holder = destination.getHolder();
int id=-99; int id=-99;
if (ItemCubeUtils.IsItemCubeInventory(destination)) {
id = ItemCubeUtils.ParseItemCubeInventoryID(destination);
} else
if (holder instanceof Entity) {
id = getEntityNegativeHash((Entity)holder);
} else {
Location loc = destination.getLocation();
if (loc!=null) { if (loc!=null) {
String hash = "-"+(Math.signum(destination.getLocation().getBlockX()+destination.getLocation().getBlockZ())>0?1:0)+Integer.toString(Math.abs(destination.getLocation().getBlockX())%1000)+Integer.toString(Math.abs(destination.getLocation().getBlockY())%1000)+Integer.toString(Math.abs(destination.getLocation().getBlockZ())%1000); String hash = "-"+(Math.signum(destination.getLocation().getBlockX()+destination.getLocation().getBlockZ())>0?1:0)+Integer.toString(Math.abs(destination.getLocation().getBlockX())%1000)+Integer.toString(Math.abs(destination.getLocation().getBlockY())%1000)+Integer.toString(Math.abs(destination.getLocation().getBlockZ())%1000);
id = Integer.parseInt(hash); id = Integer.parseInt(hash);
TwosideKeeper.itemCubeGraph.addVertex(id); TwosideKeeper.itemCubeGraph.addVertex(id);
} }
}
return id; return id;
} }
public static int getEntityNegativeHash(Entity e) {
return Math.min(e.getUniqueId().hashCode(), -e.getUniqueId().hashCode());
}
public static ItemStack[] RemoveAllNullItems(ItemStack[] contents) { public static ItemStack[] RemoveAllNullItems(ItemStack[] contents) {
List<ItemStack> items = new ArrayList<ItemStack>(); List<ItemStack> items = new ArrayList<ItemStack>();
@ -304,4 +318,25 @@ public class InventoryUtils {
} }
return items.toArray(new ItemStack[items.size()]); return items.toArray(new ItemStack[items.size()]);
} }
public static boolean inventoryContainsSameItemCube(int id, Inventory inv) {
return inventoryContainsSameItemCube(id,inv,0);
}
public static boolean inventoryContainsSameItemCube(int id, Inventory inv, int startcount) {
int count=startcount;
for (ItemStack it : inv.getContents()) {
if (ItemCubeUtils.isItemCube(it)) {
int tempid = ItemCubeUtils.getItemCubeID(it);
TwosideKeeper.log("Comparing "+id+" to "+tempid, 5);
if (id==tempid) {
count++;
}
if (count>=2) {
return true;
}
}
}
return false;
}
} }

View File

@ -429,11 +429,13 @@ public class ItemCubeUtils {
for (ItemStack it : p.getInventory().getContents()) { for (ItemStack it : p.getInventory().getContents()) {
if (ItemUtils.isValidItem(it) && isItemCube(it)) { if (ItemUtils.isValidItem(it) && isItemCube(it)) {
int id = getItemCubeID(it); int id = getItemCubeID(it);
if (!graph.containsVertex(id)) {
graph.addVertex(id); graph.addVertex(id);
graph.addEdge(PlayerStructure.getPlayerNegativeHash(p), id); graph.addEdge(PlayerStructure.getPlayerNegativeHash(p), id);
IterateAndAddToGraph(id,graph); IterateAndAddToGraph(id,graph);
} }
} }
}
for (DefaultEdge edge : graph.edgeSet()) { for (DefaultEdge edge : graph.edgeSet()) {
TwosideKeeper.log(" "+edge.toString(), 0); TwosideKeeper.log(" "+edge.toString(), 0);
@ -461,19 +463,24 @@ public class ItemCubeUtils {
} }
for (DefaultEdge edge : graph.edgeSet()) { for (DefaultEdge edge : graph.edgeSet()) {
TwosideKeeper.log(" "+edge.toString(), 0); TwosideKeeper.log(" "+edge, TwosideKeeper.GRAPH_DEBUG);
} }
} }
public static void IterateAndAddToGraph(int id, UndirectedGraph<Integer, DefaultEdge> graph) { public static void IterateAndAddToGraph(int id, UndirectedGraph<Integer, DefaultEdge> graph) {
IterateAndAddToGraph(id,graph,new ArrayList<Integer>());
}
public static void IterateAndAddToGraph(int id, UndirectedGraph<Integer, DefaultEdge> graph, List<Integer> ids) {
List<ItemStack> contents = getItemCubeContents(id); List<ItemStack> contents = getItemCubeContents(id);
for (ItemStack it : contents) { for (ItemStack it : contents) {
if (ItemUtils.isValidItem(it) && isItemCube(it)) { if (ItemUtils.isValidItem(it) && isItemCube(it)) {
int newid = getItemCubeID(it); int newid = getItemCubeID(it);
if (id!=newid) { //We don't need to link to itself. if (id!=newid && !ids.contains(newid)) { //We don't need to link to itself.
graph.addVertex(newid); graph.addVertex(newid);
graph.addEdge(id, newid); graph.addEdge(id, newid);
IterateAndAddToGraph(newid,graph); ids.add(newid);
IterateAndAddToGraph(newid,graph,ids);
} }
} }
} }
@ -587,25 +594,36 @@ public class ItemCubeUtils {
} }
} }
}*/ }*/
public static boolean isConnectedToRootNode(Graph<Integer,DefaultEdge> g, Integer vertex) { public static boolean isConnectedToRootNode(Graph<Integer,DefaultEdge> g, Integer vertex) {
Set<DefaultEdge> edges = g.edgesOf(vertex); return isConnectedToRootNode(g,vertex,new ArrayList<DefaultEdge>());
for (DefaultEdge e : edges) {
Integer target = g.getEdgeTarget(e);
Integer newvertex = g.getEdgeSource(e);
//TwosideKeeper.log("Vertex: "+vertex+" - "+newvertex+" : "+target,0);
if (Integer.compare(target, vertex)==0) {
TwosideKeeper.log(e.toString(),0);
if (Integer.compare(newvertex,vertex)==0) {
return false;
} }
private static boolean isConnectedToRootNode(Graph<Integer,DefaultEdge> g, Integer vertex, List<DefaultEdge> vals) {
Set<DefaultEdge> edges = g.edgesOf(vertex);
TwosideKeeper.log("Checking all edges connected to vertex "+vertex, TwosideKeeper.GRAPH_DEBUG2);
for (DefaultEdge e : edges) {
Integer newvertex = g.getEdgeSource(e);
TwosideKeeper.log("EDGE: "+e+" || Vertex: "+vertex+" -> "+newvertex+" ",TwosideKeeper.GRAPH_DEBUG2);
if (!vals.contains(e)) {
TwosideKeeper.log(e.toString(),TwosideKeeper.GRAPH_DEBUG);
vals.add(e);
if (newvertex<0) { if (newvertex<0) {
TwosideKeeper.log("Is connected to root node.",TwosideKeeper.GRAPH_DEBUG2);
return true; return true;
} else { } else {
return isConnectedToRootNode(g,newvertex); return isConnectedToRootNode(g,newvertex,vals);
} }
} }
} }
return false; return false;
} }
public static int ParseItemCubeInventoryID(Inventory destination) {
return Integer.parseInt(destination.getTitle().split("#")[1]);
}
public static boolean IsItemCubeInventory(Inventory destination) {
return destination!=null && destination.getHolder() instanceof Player &&
(PlayerStructure.GetPlayerStructure(((Player)destination.getHolder())).isViewingItemCube ||
PlayerStructure.GetPlayerStructure(((Player)destination.getHolder())).opened_another_cube)&&
destination.getTitle()!=null && destination.getTitle().contains("Item Cube #");
}
} }

View File

@ -459,7 +459,8 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
public static final int CLEANUP_DEBUG = 2; public static final int CLEANUP_DEBUG = 2;
public static final int LOOT_DEBUG = 3; public static final int LOOT_DEBUG = 3;
public static final int COMBAT_DEBUG = 3; public static final int COMBAT_DEBUG = 3;
public static final int GRAPH_DEBUG = 0; public static final int GRAPH_DEBUG = 5;
public static final int GRAPH_DEBUG2 = 0;
public static double worldShopDistanceSquared = 1000000; public static double worldShopDistanceSquared = 1000000;
public static double worldShopPriceMult = 2.0; //How much higher the price increases for every increment of worlsShopDistanceSquared. public static double worldShopPriceMult = 2.0; //How much higher the price increases for every increment of worlsShopDistanceSquared.
@ -4941,6 +4942,15 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
GenericFunctions.updateSetItemsInInventory(ev.getView().getBottomInventory()); GenericFunctions.updateSetItemsInInventory(ev.getView().getBottomInventory());
GenericFunctions.updateSetItemsInInventory(ev.getView().getTopInventory()); GenericFunctions.updateSetItemsInInventory(ev.getView().getTopInventory());
ItemCubeUtils.setupGraphForChest(ev.getInventory()); ItemCubeUtils.setupGraphForChest(ev.getInventory());
showAllIncomingEdges(ev.getInventory());
}
private void showAllIncomingEdges(Inventory inventory) {
int invID = InventoryUtils.getInventoryNumberHash(inventory);
TwosideKeeper.log("===============", TwosideKeeper.GRAPH_DEBUG2);
for (DefaultEdge edge : TwosideKeeper.itemCubeGraph.edgesOf(invID)) {
TwosideKeeper.log(edge.toString(), TwosideKeeper.GRAPH_DEBUG2);
}
} }
@EventHandler(priority=EventPriority.LOW,ignoreCancelled = true) @EventHandler(priority=EventPriority.LOW,ignoreCancelled = true)
@ -5751,14 +5761,6 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
} else { } else {
itemcubeid = -1; itemcubeid = -1;
} }
if (idnumb==itemcubeid) {
//The inventory we are viewing is the same as the item cube we have clicked on!
//Stop this before the player does something dumb!
//Player p = ((Player)ev.getWhoClicked());
//SoundUtils.playLocalSound(p, Sound.BLOCK_NOTE_HARP, 0.4f, 0.2f);
ev.setCancelled(true);
return;
} else {
TwosideKeeper.log("Got to here. ID is "+itemcubeid, 5); 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) {
@ -5812,7 +5814,6 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
} }
} }
} }
}
if (ev.getClickedInventory()!=null && if (ev.getClickedInventory()!=null &&
ev.getInventory().getType()!=InventoryType.CRAFTING) { ev.getInventory().getType()!=InventoryType.CRAFTING) {
@ -5828,20 +5829,24 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
if (ItemCubeUtils.isItemCube(item1)) { if (ItemCubeUtils.isItemCube(item1)) {
int cubeid = ItemCubeUtils.getItemCubeID(item1); int cubeid = ItemCubeUtils.getItemCubeID(item1);
if (id!=cubeid) { if (id!=cubeid) {
DefaultEdge edge = TwosideKeeper.itemCubeGraph.addEdge(id, cubeid); DefaultEdge edge = TwosideKeeper.itemCubeGraph.removeEdge(PlayerStructure.getPlayerNegativeHash(p), cubeid);
if (edge!=null) {
TwosideKeeper.log("Added edge "+edge, TwosideKeeper.GRAPH_DEBUG);
edge = TwosideKeeper.itemCubeGraph.removeEdge(PlayerStructure.getPlayerNegativeHash(p), cubeid);
TwosideKeeper.log("Removed edge "+edge, TwosideKeeper.GRAPH_DEBUG); TwosideKeeper.log("Removed edge "+edge, TwosideKeeper.GRAPH_DEBUG);
if (!ItemCubeUtils.isConnectedToRootNode(TwosideKeeper.itemCubeGraph, id)) { if (!ItemCubeUtils.isConnectedToRootNode(TwosideKeeper.itemCubeGraph, id)) {
edge = TwosideKeeper.itemCubeGraph.addEdge(PlayerStructure.getPlayerNegativeHash(p), cubeid); edge = TwosideKeeper.itemCubeGraph.addEdge(PlayerStructure.getPlayerNegativeHash(p), cubeid);
TwosideKeeper.log("Added edge "+edge, TwosideKeeper.GRAPH_DEBUG); TwosideKeeper.log("Added edge "+edge, TwosideKeeper.GRAPH_DEBUG);
edge = TwosideKeeper.itemCubeGraph.removeEdge(id, cubeid); //edge = TwosideKeeper.itemCubeGraph.removeEdge(id, cubeid);
TwosideKeeper.log("Removed edge "+edge, TwosideKeeper.GRAPH_DEBUG); //TwosideKeeper.log("Removed edge "+edge, TwosideKeeper.GRAPH_DEBUG);
ev.setCancelled(true); ev.setCancelled(true);
ev.setCursor(ev.getCursor()); ev.setCursor(ev.getCursor());
return; return;
} }
if (InventoryUtils.inventoryContainsSameItemCube(cubeid, p.getInventory(),1)) {
edge = TwosideKeeper.itemCubeGraph.addEdge(PlayerStructure.getPlayerNegativeHash(p), cubeid);
TwosideKeeper.log("Added edge "+edge, TwosideKeeper.GRAPH_DEBUG);
}
edge = TwosideKeeper.itemCubeGraph.addEdge(id, cubeid);
if (edge!=null) {
TwosideKeeper.log("Added edge "+edge, TwosideKeeper.GRAPH_DEBUG);
} else { } else {
ev.setCancelled(true); ev.setCancelled(true);
ev.setCursor(ev.getCursor()); ev.setCursor(ev.getCursor());
@ -5858,8 +5863,10 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
try { try {
DefaultEdge edge = TwosideKeeper.itemCubeGraph.addEdge(PlayerStructure.getPlayerNegativeHash(p), cubeid); DefaultEdge edge = TwosideKeeper.itemCubeGraph.addEdge(PlayerStructure.getPlayerNegativeHash(p), cubeid);
TwosideKeeper.log("Added edge "+edge, TwosideKeeper.GRAPH_DEBUG); TwosideKeeper.log("Added edge "+edge, TwosideKeeper.GRAPH_DEBUG);
if (!InventoryUtils.inventoryContainsSameItemCube(cubeid, clickedinv) && !item1.isSimilar(item2)) {
edge = TwosideKeeper.itemCubeGraph.removeEdge(id, cubeid); edge = TwosideKeeper.itemCubeGraph.removeEdge(id, cubeid);
TwosideKeeper.log("Removed edge "+edge, TwosideKeeper.GRAPH_DEBUG); TwosideKeeper.log("Removed edge "+edge, TwosideKeeper.GRAPH_DEBUG);
}
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
ev.setCancelled(true); ev.setCancelled(true);
ev.setCursor(ev.getCursor()); ev.setCursor(ev.getCursor());
@ -5870,8 +5877,11 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
if (ItemCubeUtils.isItemCube(item1)) { if (ItemCubeUtils.isItemCube(item1)) {
int cubeid = ItemCubeUtils.getItemCubeID(item1); int cubeid = ItemCubeUtils.getItemCubeID(item1);
int invid = InventoryUtils.getInventoryNumberHash(clickedinv); int invid = InventoryUtils.getInventoryNumberHash(clickedinv);
DefaultEdge edge = TwosideKeeper.itemCubeGraph.removeEdge(PlayerStructure.getPlayerNegativeHash(p), cubeid); DefaultEdge edge;
if (!InventoryUtils.inventoryContainsSameItemCube(cubeid, p.getInventory())) {
edge = TwosideKeeper.itemCubeGraph.removeEdge(PlayerStructure.getPlayerNegativeHash(p), cubeid);
TwosideKeeper.log("Removed edge "+edge, TwosideKeeper.GRAPH_DEBUG); TwosideKeeper.log("Removed edge "+edge, TwosideKeeper.GRAPH_DEBUG);
}
edge = TwosideKeeper.itemCubeGraph.addEdge(invid, cubeid); edge = TwosideKeeper.itemCubeGraph.addEdge(invid, cubeid);
TwosideKeeper.log("Added edge "+edge, TwosideKeeper.GRAPH_DEBUG); TwosideKeeper.log("Added edge "+edge, TwosideKeeper.GRAPH_DEBUG);
TwosideKeeper.log("Vertices in "+clickedinv.getType()+" (ID:"+invid+"):", TwosideKeeper.GRAPH_DEBUG); TwosideKeeper.log("Vertices in "+clickedinv.getType()+" (ID:"+invid+"):", TwosideKeeper.GRAPH_DEBUG);
@ -5882,8 +5892,11 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
if (ItemCubeUtils.isItemCube(item2)) { if (ItemCubeUtils.isItemCube(item2)) {
int cubeid = ItemCubeUtils.getItemCubeID(item2); int cubeid = ItemCubeUtils.getItemCubeID(item2);
int invid = InventoryUtils.getInventoryNumberHash(clickedinv); int invid = InventoryUtils.getInventoryNumberHash(clickedinv);
DefaultEdge edge = TwosideKeeper.itemCubeGraph.removeEdge(invid, cubeid); DefaultEdge edge;
TwosideKeeper.log("Removed edge "+edge, TwosideKeeper.GRAPH_DEBUG); if (!InventoryUtils.inventoryContainsSameItemCube(cubeid, clickedinv) && !item1.isSimilar(item2)) {
edge = TwosideKeeper.itemCubeGraph.removeEdge(invid, cubeid);
TwosideKeeper.log("Removed edge "+TwosideKeeper.itemCubeGraph.getEdgeSource(edge)+","+TwosideKeeper.itemCubeGraph.getEdgeTarget(edge), TwosideKeeper.GRAPH_DEBUG);
}
edge = TwosideKeeper.itemCubeGraph.addEdge(PlayerStructure.getPlayerNegativeHash(p), cubeid); edge = TwosideKeeper.itemCubeGraph.addEdge(PlayerStructure.getPlayerNegativeHash(p), cubeid);
TwosideKeeper.log("Added edge "+edge, TwosideKeeper.GRAPH_DEBUG); TwosideKeeper.log("Added edge "+edge, TwosideKeeper.GRAPH_DEBUG);
} }
@ -5902,20 +5915,25 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
int id = Integer.parseInt(clickedinv.getTitle().split("#")[1]); int id = Integer.parseInt(clickedinv.getTitle().split("#")[1]);
TwosideKeeper.log("ID is "+id+":"+clickedid, 0); TwosideKeeper.log("ID is "+id+":"+clickedid, 0);
if (id!=clickedid) { if (id!=clickedid) {
DefaultEdge edge = TwosideKeeper.itemCubeGraph.addEdge(id, clickedid); DefaultEdge edge;
if (edge!=null) {
TwosideKeeper.log("Added edge "+TwosideKeeper.itemCubeGraph.getEdgeSource(edge)+","+TwosideKeeper.itemCubeGraph.getEdgeTarget(edge), TwosideKeeper.GRAPH_DEBUG);
edge = TwosideKeeper.itemCubeGraph.removeEdge(PlayerStructure.getPlayerNegativeHash(p), clickedid); edge = TwosideKeeper.itemCubeGraph.removeEdge(PlayerStructure.getPlayerNegativeHash(p), clickedid);
TwosideKeeper.log("Removed edge "+TwosideKeeper.itemCubeGraph.getEdgeSource(edge)+","+TwosideKeeper.itemCubeGraph.getEdgeTarget(edge), TwosideKeeper.GRAPH_DEBUG); TwosideKeeper.log("Removed edge "+edge, TwosideKeeper.GRAPH_DEBUG);
if (!ItemCubeUtils.isConnectedToRootNode(TwosideKeeper.itemCubeGraph, id)) { if (!ItemCubeUtils.isConnectedToRootNode(TwosideKeeper.itemCubeGraph, id)) {
edge = TwosideKeeper.itemCubeGraph.addEdge(PlayerStructure.getPlayerNegativeHash(p), clickedid); edge = TwosideKeeper.itemCubeGraph.addEdge(PlayerStructure.getPlayerNegativeHash(p), clickedid);
TwosideKeeper.log("Added edge "+TwosideKeeper.itemCubeGraph.getEdgeSource(edge)+","+TwosideKeeper.itemCubeGraph.getEdgeTarget(edge), TwosideKeeper.GRAPH_DEBUG); TwosideKeeper.log("Added edge "+edge, TwosideKeeper.GRAPH_DEBUG);
edge = TwosideKeeper.itemCubeGraph.removeEdge(id, clickedid); /*edge = TwosideKeeper.itemCubeGraph.removeEdge(id, clickedid);
TwosideKeeper.log("Removed edge "+TwosideKeeper.itemCubeGraph.getEdgeSource(edge)+","+TwosideKeeper.itemCubeGraph.getEdgeTarget(edge), TwosideKeeper.GRAPH_DEBUG); TwosideKeeper.log("Removed edge "+TwosideKeeper.itemCubeGraph.getEdgeSource(edge)+","+TwosideKeeper.itemCubeGraph.getEdgeTarget(edge), TwosideKeeper.GRAPH_DEBUG);*/
ev.setCancelled(true); ev.setCancelled(true);
ev.setCursor(ev.getCursor()); ev.setCursor(ev.getCursor());
return; return;
} }
if (InventoryUtils.inventoryContainsSameItemCube(clickedid, p.getInventory(),1)) {
edge = TwosideKeeper.itemCubeGraph.addEdge(PlayerStructure.getPlayerNegativeHash(p), clickedid);
TwosideKeeper.log("Added edge "+edge, TwosideKeeper.GRAPH_DEBUG);
}
edge = TwosideKeeper.itemCubeGraph.addEdge(id, clickedid);
if (edge!=null) {
TwosideKeeper.log("Added edge "+edge, TwosideKeeper.GRAPH_DEBUG);
} else { } else {
ev.setCancelled(true); ev.setCancelled(true);
ev.setCursor(ev.getCursor()); ev.setCursor(ev.getCursor());
@ -5929,10 +5947,13 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
} }
} else { //This is not an item cube. } else { //This is not an item cube.
int invid = InventoryUtils.getInventoryNumberHash(clickedinv); int invid = InventoryUtils.getInventoryNumberHash(clickedinv);
DefaultEdge edge = TwosideKeeper.itemCubeGraph.removeEdge(PlayerStructure.getPlayerNegativeHash(p), clickedid); DefaultEdge edge;
TwosideKeeper.log("Removed edge "+TwosideKeeper.itemCubeGraph.getEdgeSource(edge)+","+TwosideKeeper.itemCubeGraph.getEdgeTarget(edge), TwosideKeeper.GRAPH_DEBUG); if (!InventoryUtils.inventoryContainsSameItemCube(clickedid, p.getInventory())) {
edge = TwosideKeeper.itemCubeGraph.removeEdge(PlayerStructure.getPlayerNegativeHash(p), clickedid);
TwosideKeeper.log("Removed edge "+edge, TwosideKeeper.GRAPH_DEBUG);
}
edge = TwosideKeeper.itemCubeGraph.addEdge(invid, clickedid); edge = TwosideKeeper.itemCubeGraph.addEdge(invid, clickedid);
TwosideKeeper.log("Added edge "+TwosideKeeper.itemCubeGraph.getEdgeSource(edge)+","+TwosideKeeper.itemCubeGraph.getEdgeTarget(edge), TwosideKeeper.GRAPH_DEBUG); TwosideKeeper.log("Added edge "+edge, TwosideKeeper.GRAPH_DEBUG);
} }
return; return;
} else { } else {
@ -5949,13 +5970,17 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
if (pd.isViewingItemCube && clickedinv.getTitle()!=null && if (pd.isViewingItemCube && clickedinv.getTitle()!=null &&
clickedinv.getTitle().contains("Item Cube #")) { clickedinv.getTitle().contains("Item Cube #")) {
int id = Integer.parseInt(clickedinv.getTitle().split("#")[1]); int id = Integer.parseInt(clickedinv.getTitle().split("#")[1]);
if (!InventoryUtils.inventoryContainsSameItemCube(clickedid, clickedinv)) {
edge = TwosideKeeper.itemCubeGraph.removeEdge(id, clickedid); edge = TwosideKeeper.itemCubeGraph.removeEdge(id, clickedid);
TwosideKeeper.log("Removed edge "+edge, TwosideKeeper.GRAPH_DEBUG); TwosideKeeper.log("Removed edge "+TwosideKeeper.itemCubeGraph.getEdgeSource(edge)+","+TwosideKeeper.itemCubeGraph.getEdgeTarget(edge), TwosideKeeper.GRAPH_DEBUG);
}
} else { } else {
//This is not an item cube. //This is not an item cube.
int invid = InventoryUtils.getInventoryNumberHash(clickedinv); int invid = InventoryUtils.getInventoryNumberHash(clickedinv);
if (!InventoryUtils.inventoryContainsSameItemCube(clickedid, clickedinv)) {
edge = TwosideKeeper.itemCubeGraph.removeEdge(invid, clickedid); edge = TwosideKeeper.itemCubeGraph.removeEdge(invid, clickedid);
TwosideKeeper.log("Removed edge "+edge, TwosideKeeper.GRAPH_DEBUG); TwosideKeeper.log("Removed edge "+TwosideKeeper.itemCubeGraph.getEdgeSource(edge)+","+TwosideKeeper.itemCubeGraph.getEdgeTarget(edge), TwosideKeeper.GRAPH_DEBUG);
}
} }
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
ev.setCancelled(true); ev.setCancelled(true);
@ -5984,9 +6009,6 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
DefaultEdge edge = TwosideKeeper.itemCubeGraph.addEdge(id, clickedid); DefaultEdge edge = TwosideKeeper.itemCubeGraph.addEdge(id, clickedid);
TwosideKeeper.log("Added edge "+edge, TwosideKeeper.GRAPH_DEBUG); TwosideKeeper.log("Added edge "+edge, TwosideKeeper.GRAPH_DEBUG);
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
ev.setCancelled(true);
ev.setCursor(ev.getCursor());
return;
} }
return; return;
//ItemCube.addItemCubeToAllViewerGraphs(id, ev.getCursor(), p); //ItemCube.addItemCubeToAllViewerGraphs(id, ev.getCursor(), p);
@ -5997,9 +6019,6 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
DefaultEdge edge = TwosideKeeper.itemCubeGraph.addEdge(PlayerStructure.getPlayerNegativeHash(p), clickedid); DefaultEdge edge = TwosideKeeper.itemCubeGraph.addEdge(PlayerStructure.getPlayerNegativeHash(p), clickedid);
TwosideKeeper.log("Added edge "+edge, TwosideKeeper.GRAPH_DEBUG); TwosideKeeper.log("Added edge "+edge, TwosideKeeper.GRAPH_DEBUG);
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
ev.setCancelled(true);
ev.setCursor(ev.getCursor());
return;
} }
} else { } else {
int clickedid = ItemCubeUtils.getItemCubeID(ev.getCursor()); int clickedid = ItemCubeUtils.getItemCubeID(ev.getCursor());
@ -6007,9 +6026,6 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
DefaultEdge edge = TwosideKeeper.itemCubeGraph.addEdge(InventoryUtils.getInventoryNumberHash(clickedinv), clickedid); DefaultEdge edge = TwosideKeeper.itemCubeGraph.addEdge(InventoryUtils.getInventoryNumberHash(clickedinv), clickedid);
TwosideKeeper.log("Added edge "+edge, TwosideKeeper.GRAPH_DEBUG); TwosideKeeper.log("Added edge "+edge, TwosideKeeper.GRAPH_DEBUG);
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
ev.setCancelled(true);
ev.setCursor(ev.getCursor());
return;
} }
} }
} }
@ -6020,20 +6036,24 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
clickedinv.getTitle().contains("Item Cube #")) { clickedinv.getTitle().contains("Item Cube #")) {
int id = Integer.parseInt(clickedinv.getTitle().split("#")[1]); int id = Integer.parseInt(clickedinv.getTitle().split("#")[1]);
int clickedid = ItemCubeUtils.getItemCubeID(ev.getCurrentItem()); int clickedid = ItemCubeUtils.getItemCubeID(ev.getCurrentItem());
DefaultEdge edge = TwosideKeeper.itemCubeGraph.addEdge(id, clickedid); if (!InventoryUtils.inventoryContainsSameItemCube(clickedid, clickedinv)) {
TwosideKeeper.log("Added edge "+edge, TwosideKeeper.GRAPH_DEBUG); DefaultEdge edge = TwosideKeeper.itemCubeGraph.removeEdge(id, clickedid);
edge = TwosideKeeper.itemCubeGraph.removeEdge(id, clickedid); TwosideKeeper.log("Removed edge "+TwosideKeeper.itemCubeGraph.getEdgeSource(edge)+","+TwosideKeeper.itemCubeGraph.getEdgeTarget(edge), TwosideKeeper.GRAPH_DEBUG);
TwosideKeeper.log("Destroyed edge "+edge, TwosideKeeper.GRAPH_DEBUG); }
//ItemCubeUtils.DestroyAllTargetEdges(clickedid, TwosideKeeper.itemCubeGraph); //ItemCubeUtils.DestroyAllTargetEdges(clickedid, TwosideKeeper.itemCubeGraph);
} else } else
if (clickedinv.getType()==InventoryType.PLAYER) { if (clickedinv.getType()==InventoryType.PLAYER) {
int clickedid = ItemCubeUtils.getItemCubeID(ev.getCurrentItem()); int clickedid = ItemCubeUtils.getItemCubeID(ev.getCurrentItem());
if (!InventoryUtils.inventoryContainsSameItemCube(clickedid, p.getInventory())) {
DefaultEdge edge = TwosideKeeper.itemCubeGraph.removeEdge(PlayerStructure.getPlayerNegativeHash(p), clickedid); DefaultEdge edge = TwosideKeeper.itemCubeGraph.removeEdge(PlayerStructure.getPlayerNegativeHash(p), clickedid);
TwosideKeeper.log("Destroyed edge "+edge, TwosideKeeper.GRAPH_DEBUG); TwosideKeeper.log("Removed edge "+TwosideKeeper.itemCubeGraph.getEdgeSource(edge)+","+TwosideKeeper.itemCubeGraph.getEdgeTarget(edge), TwosideKeeper.GRAPH_DEBUG);
}
} else { } else {
int clickedid = ItemCubeUtils.getItemCubeID(ev.getCurrentItem()); int clickedid = ItemCubeUtils.getItemCubeID(ev.getCurrentItem());
if (!InventoryUtils.inventoryContainsSameItemCube(clickedid, clickedinv)) {
DefaultEdge edge = TwosideKeeper.itemCubeGraph.removeEdge(InventoryUtils.getInventoryNumberHash(clickedinv), clickedid); DefaultEdge edge = TwosideKeeper.itemCubeGraph.removeEdge(InventoryUtils.getInventoryNumberHash(clickedinv), clickedid);
TwosideKeeper.log("Destroyed edge "+edge, TwosideKeeper.GRAPH_DEBUG); TwosideKeeper.log("Removed edge "+TwosideKeeper.itemCubeGraph.getEdgeSource(edge)+","+TwosideKeeper.itemCubeGraph.getEdgeTarget(edge), TwosideKeeper.GRAPH_DEBUG);
}
} }
} }
} }