Buggy graph system implementation

testdev
sigonasr2 8 years ago
parent a8aa59ed25
commit c8abd91f50
  1. BIN
      TwosideKeeper.jar
  2. 2
      src/plugin.yml
  3. 45
      src/sig/plugin/TwosideKeeper/HelperStructures/Utils/InventoryUtils.java
  4. 48
      src/sig/plugin/TwosideKeeper/HelperStructures/Utils/ItemCubeUtils.java
  5. 246
      src/sig/plugin/TwosideKeeper/TwosideKeeper.java

Binary file not shown.

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

@ -9,10 +9,13 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import sig.plugin.TwosideKeeper.PlayerStructure;
import sig.plugin.TwosideKeeper.TwosideKeeper;
import sig.plugin.TwosideKeeper.HelperStructures.CubeType;
import sig.plugin.TwosideKeeper.HelperStructures.CustomItem;
@ -285,15 +288,26 @@ public class InventoryUtils {
}
public static int getInventoryNumberHash(Inventory destination) {
Location loc = destination.getLocation();
InventoryHolder holder = destination.getHolder();
int id=-99;
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);
id = Integer.parseInt(hash);
TwosideKeeper.itemCubeGraph.addVertex(id);
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) {
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);
TwosideKeeper.itemCubeGraph.addVertex(id);
}
}
return id;
}
public static int getEntityNegativeHash(Entity e) {
return Math.min(e.getUniqueId().hashCode(), -e.getUniqueId().hashCode());
}
public static ItemStack[] RemoveAllNullItems(ItemStack[] contents) {
List<ItemStack> items = new ArrayList<ItemStack>();
@ -304,4 +318,25 @@ public class InventoryUtils {
}
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;
}
}

@ -429,9 +429,11 @@ public class ItemCubeUtils {
for (ItemStack it : p.getInventory().getContents()) {
if (ItemUtils.isValidItem(it) && isItemCube(it)) {
int id = getItemCubeID(it);
graph.addVertex(id);
graph.addEdge(PlayerStructure.getPlayerNegativeHash(p), id);
IterateAndAddToGraph(id,graph);
if (!graph.containsVertex(id)) {
graph.addVertex(id);
graph.addEdge(PlayerStructure.getPlayerNegativeHash(p), id);
IterateAndAddToGraph(id,graph);
}
}
}
@ -461,19 +463,24 @@ public class ItemCubeUtils {
}
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) {
IterateAndAddToGraph(id,graph,new ArrayList<Integer>());
}
public static void IterateAndAddToGraph(int id, UndirectedGraph<Integer, DefaultEdge> graph, List<Integer> ids) {
List<ItemStack> contents = getItemCubeContents(id);
for (ItemStack it : contents) {
if (ItemUtils.isValidItem(it) && isItemCube(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.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) {
return isConnectedToRootNode(g,vertex,new ArrayList<DefaultEdge>());
}
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 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;
}
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) {
TwosideKeeper.log("Is connected to root node.",TwosideKeeper.GRAPH_DEBUG2);
return true;
} else {
return isConnectedToRootNode(g,newvertex);
return isConnectedToRootNode(g,newvertex,vals);
}
}
}
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 #");
}
}

@ -459,7 +459,8 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
public static final int CLEANUP_DEBUG = 2;
public static final int LOOT_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 worldShopPriceMult = 2.0; //How much higher the price increases for every increment of worlsShopDistanceSquared.
@ -4941,9 +4942,18 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
GenericFunctions.updateSetItemsInInventory(ev.getView().getBottomInventory());
GenericFunctions.updateSetItemsInInventory(ev.getView().getTopInventory());
ItemCubeUtils.setupGraphForChest(ev.getInventory());
showAllIncomingEdges(ev.getInventory());
}
@EventHandler(priority=EventPriority.LOW,ignoreCancelled = true)
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)
public void onInventoryClose(InventoryCloseEvent ev) {
if (ev.getPlayer() instanceof Player) {
Player p = (Player)ev.getPlayer();
@ -5751,63 +5761,54 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
} else {
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;
TwosideKeeper.log("Got to here. ID is "+itemcubeid, 5);
Player p = (Player)ev.getWhoClicked();
if (itemcubeid!=-1 && ev.getRawSlot()<=ev.getView().getTopInventory().getSize()-1) {
//This means we are viewing an item cube currently. Add it to our list.
ItemCubeWindow.addItemCubeWindow(p, itemcubeid);
} else
if (itemcubeid!=-1) {
log("Size is "+(ev.getView().getTopInventory().getSize())+", Clicked slot "+ev.getRawSlot(),5);
ItemCubeWindow.removeAllItemCubeWindows(p);
}
log("This is an Item Cube.",5);
int inventory_size;
if (ev.getCurrentItem().getType()==Material.CHEST) {
inventory_size=9;
} else {
if (CustomItem.isVacuumCube(ev.getCurrentItem())) {
inventory_size=54;
} else {
inventory_size=27;
}
}
final PlayerStructure pd2 = pd;
if (!ItemCube.isSomeoneViewingItemCube(idnumb,p)) {
log("Attempting to open",5);
//ev.setCancelled(true);
ev.setResult(Result.DENY);
//pd.itemcubeviews.add(p.getOpenInventory());
pd.opened_another_cube=true;
Inventory temp = Bukkit.getServer().createInventory(p, inventory_size, "Item Cube #"+idnumb);
openItemCubeInventory(temp);
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {@Override public void run() {p.openInventory(temp);
//TODO Implement Graphs. //BuildItemCubeGraph(p);
pd2.opened_another_cube=false;
pd2.isViewingItemCube=true;}},1);
SoundUtils.playLocalSound(p,Sound.BLOCK_CHEST_OPEN,1.0f,1.0f);
return;
} else {
TwosideKeeper.log("Got to here. ID is "+itemcubeid, 5);
Player p = (Player)ev.getWhoClicked();
if (itemcubeid!=-1 && ev.getRawSlot()<=ev.getView().getTopInventory().getSize()-1) {
//This means we are viewing an item cube currently. Add it to our list.
ItemCubeWindow.addItemCubeWindow(p, itemcubeid);
} else
if (itemcubeid!=-1) {
log("Size is "+(ev.getView().getTopInventory().getSize())+", Clicked slot "+ev.getRawSlot(),5);
ItemCubeWindow.removeAllItemCubeWindows(p);
}
log("This is an Item Cube.",5);
int inventory_size;
if (ev.getCurrentItem().getType()==Material.CHEST) {
inventory_size=9;
} else {
if (CustomItem.isVacuumCube(ev.getCurrentItem())) {
inventory_size=54;
} else {
inventory_size=27;
}
}
final PlayerStructure pd2 = pd;
if (!ItemCube.isSomeoneViewingItemCube(idnumb,p)) {
log("Attempting to open",5);
//ev.setCancelled(true);
ev.setResult(Result.DENY);
//pd.itemcubeviews.add(p.getOpenInventory());
pd.opened_another_cube=true;
Inventory temp = Bukkit.getServer().createInventory(p, inventory_size, "Item Cube #"+idnumb);
openItemCubeInventory(temp);
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {@Override public void run() {p.openInventory(temp);
//TODO Implement Graphs. //BuildItemCubeGraph(p);
pd2.opened_another_cube=false;
pd2.isViewingItemCube=true;}},1);
SoundUtils.playLocalSound(p,Sound.BLOCK_CHEST_OPEN,1.0f,1.0f);
return;
} else {
//ev.setCancelled(true);
ev.setResult(Result.DENY);
//ItemCube.displayErrorMessage(p);
//pd.itemcubeviews.add(p.getOpenInventory());
pd.opened_another_cube=true;
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {@Override public void run() {p.openInventory(ItemCube.getViewingItemCubeInventory(idnumb, p));
//TODO Implement Graphs. //BuildItemCubeGraph(p);
pd2.opened_another_cube=false;
pd2.isViewingItemCube=true;}},1);
SoundUtils.playLocalSound(p, Sound.BLOCK_CHEST_OPEN, 1.0f, 1.0f);
return;
}
//ev.setCancelled(true);
ev.setResult(Result.DENY);
//ItemCube.displayErrorMessage(p);
//pd.itemcubeviews.add(p.getOpenInventory());
pd.opened_another_cube=true;
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {@Override public void run() {p.openInventory(ItemCube.getViewingItemCubeInventory(idnumb, p));
//TODO Implement Graphs. //BuildItemCubeGraph(p);
pd2.opened_another_cube=false;
pd2.isViewingItemCube=true;}},1);
SoundUtils.playLocalSound(p, Sound.BLOCK_CHEST_OPEN, 1.0f, 1.0f);
return;
}
}
}
@ -5828,20 +5829,24 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
if (ItemCubeUtils.isItemCube(item1)) {
int cubeid = ItemCubeUtils.getItemCubeID(item1);
if (id!=cubeid) {
DefaultEdge edge = TwosideKeeper.itemCubeGraph.addEdge(id, cubeid);
DefaultEdge edge = TwosideKeeper.itemCubeGraph.removeEdge(PlayerStructure.getPlayerNegativeHash(p), cubeid);
TwosideKeeper.log("Removed edge "+edge, TwosideKeeper.GRAPH_DEBUG);
if (!ItemCubeUtils.isConnectedToRootNode(TwosideKeeper.itemCubeGraph, id)) {
edge = TwosideKeeper.itemCubeGraph.addEdge(PlayerStructure.getPlayerNegativeHash(p), cubeid);
TwosideKeeper.log("Added edge "+edge, TwosideKeeper.GRAPH_DEBUG);
//edge = TwosideKeeper.itemCubeGraph.removeEdge(id, cubeid);
//TwosideKeeper.log("Removed edge "+edge, TwosideKeeper.GRAPH_DEBUG);
ev.setCancelled(true);
ev.setCursor(ev.getCursor());
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);
edge = TwosideKeeper.itemCubeGraph.removeEdge(PlayerStructure.getPlayerNegativeHash(p), cubeid);
TwosideKeeper.log("Removed edge "+edge, TwosideKeeper.GRAPH_DEBUG);
if (!ItemCubeUtils.isConnectedToRootNode(TwosideKeeper.itemCubeGraph, id)) {
edge = TwosideKeeper.itemCubeGraph.addEdge(PlayerStructure.getPlayerNegativeHash(p), cubeid);
TwosideKeeper.log("Added edge "+edge, TwosideKeeper.GRAPH_DEBUG);
edge = TwosideKeeper.itemCubeGraph.removeEdge(id, cubeid);
TwosideKeeper.log("Removed edge "+edge, TwosideKeeper.GRAPH_DEBUG);
ev.setCancelled(true);
ev.setCursor(ev.getCursor());
return;
}
} else {
ev.setCancelled(true);
ev.setCursor(ev.getCursor());
@ -5858,8 +5863,10 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
try {
DefaultEdge edge = TwosideKeeper.itemCubeGraph.addEdge(PlayerStructure.getPlayerNegativeHash(p), cubeid);
TwosideKeeper.log("Added edge "+edge, TwosideKeeper.GRAPH_DEBUG);
edge = TwosideKeeper.itemCubeGraph.removeEdge(id, cubeid);
TwosideKeeper.log("Removed edge "+edge, TwosideKeeper.GRAPH_DEBUG);
if (!InventoryUtils.inventoryContainsSameItemCube(cubeid, clickedinv) && !item1.isSimilar(item2)) {
edge = TwosideKeeper.itemCubeGraph.removeEdge(id, cubeid);
TwosideKeeper.log("Removed edge "+edge, TwosideKeeper.GRAPH_DEBUG);
}
} catch (IllegalArgumentException ex) {
ev.setCancelled(true);
ev.setCursor(ev.getCursor());
@ -5870,8 +5877,11 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
if (ItemCubeUtils.isItemCube(item1)) {
int cubeid = ItemCubeUtils.getItemCubeID(item1);
int invid = InventoryUtils.getInventoryNumberHash(clickedinv);
DefaultEdge edge = TwosideKeeper.itemCubeGraph.removeEdge(PlayerStructure.getPlayerNegativeHash(p), cubeid);
TwosideKeeper.log("Removed edge "+edge, TwosideKeeper.GRAPH_DEBUG);
DefaultEdge edge;
if (!InventoryUtils.inventoryContainsSameItemCube(cubeid, p.getInventory())) {
edge = TwosideKeeper.itemCubeGraph.removeEdge(PlayerStructure.getPlayerNegativeHash(p), cubeid);
TwosideKeeper.log("Removed edge "+edge, TwosideKeeper.GRAPH_DEBUG);
}
edge = TwosideKeeper.itemCubeGraph.addEdge(invid, cubeid);
TwosideKeeper.log("Added edge "+edge, 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)) {
int cubeid = ItemCubeUtils.getItemCubeID(item2);
int invid = InventoryUtils.getInventoryNumberHash(clickedinv);
DefaultEdge edge = TwosideKeeper.itemCubeGraph.removeEdge(invid, cubeid);
TwosideKeeper.log("Removed edge "+edge, TwosideKeeper.GRAPH_DEBUG);
DefaultEdge edge;
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);
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]);
TwosideKeeper.log("ID is "+id+":"+clickedid, 0);
if (id!=clickedid) {
DefaultEdge edge = TwosideKeeper.itemCubeGraph.addEdge(id, clickedid);
DefaultEdge edge;
edge = TwosideKeeper.itemCubeGraph.removeEdge(PlayerStructure.getPlayerNegativeHash(p), clickedid);
TwosideKeeper.log("Removed edge "+edge, TwosideKeeper.GRAPH_DEBUG);
if (!ItemCubeUtils.isConnectedToRootNode(TwosideKeeper.itemCubeGraph, id)) {
edge = TwosideKeeper.itemCubeGraph.addEdge(PlayerStructure.getPlayerNegativeHash(p), clickedid);
TwosideKeeper.log("Added edge "+edge, TwosideKeeper.GRAPH_DEBUG);
/*edge = TwosideKeeper.itemCubeGraph.removeEdge(id, clickedid);
TwosideKeeper.log("Removed edge "+TwosideKeeper.itemCubeGraph.getEdgeSource(edge)+","+TwosideKeeper.itemCubeGraph.getEdgeTarget(edge), TwosideKeeper.GRAPH_DEBUG);*/
ev.setCancelled(true);
ev.setCursor(ev.getCursor());
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 "+TwosideKeeper.itemCubeGraph.getEdgeSource(edge)+","+TwosideKeeper.itemCubeGraph.getEdgeTarget(edge), TwosideKeeper.GRAPH_DEBUG);
edge = TwosideKeeper.itemCubeGraph.removeEdge(PlayerStructure.getPlayerNegativeHash(p), clickedid);
TwosideKeeper.log("Removed edge "+TwosideKeeper.itemCubeGraph.getEdgeSource(edge)+","+TwosideKeeper.itemCubeGraph.getEdgeTarget(edge), TwosideKeeper.GRAPH_DEBUG);
if (!ItemCubeUtils.isConnectedToRootNode(TwosideKeeper.itemCubeGraph, id)) {
edge = TwosideKeeper.itemCubeGraph.addEdge(PlayerStructure.getPlayerNegativeHash(p), clickedid);
TwosideKeeper.log("Added edge "+TwosideKeeper.itemCubeGraph.getEdgeSource(edge)+","+TwosideKeeper.itemCubeGraph.getEdgeTarget(edge), TwosideKeeper.GRAPH_DEBUG);
edge = TwosideKeeper.itemCubeGraph.removeEdge(id, clickedid);
TwosideKeeper.log("Removed edge "+TwosideKeeper.itemCubeGraph.getEdgeSource(edge)+","+TwosideKeeper.itemCubeGraph.getEdgeTarget(edge), TwosideKeeper.GRAPH_DEBUG);
ev.setCancelled(true);
ev.setCursor(ev.getCursor());
return;
}
TwosideKeeper.log("Added edge "+edge, TwosideKeeper.GRAPH_DEBUG);
} else {
ev.setCancelled(true);
ev.setCursor(ev.getCursor());
@ -5929,10 +5947,13 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
}
} else { //This is not an item cube.
int invid = InventoryUtils.getInventoryNumberHash(clickedinv);
DefaultEdge edge = TwosideKeeper.itemCubeGraph.removeEdge(PlayerStructure.getPlayerNegativeHash(p), clickedid);
TwosideKeeper.log("Removed edge "+TwosideKeeper.itemCubeGraph.getEdgeSource(edge)+","+TwosideKeeper.itemCubeGraph.getEdgeTarget(edge), TwosideKeeper.GRAPH_DEBUG);
DefaultEdge edge;
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);
TwosideKeeper.log("Added edge "+TwosideKeeper.itemCubeGraph.getEdgeSource(edge)+","+TwosideKeeper.itemCubeGraph.getEdgeTarget(edge), TwosideKeeper.GRAPH_DEBUG);
TwosideKeeper.log("Added edge "+edge, TwosideKeeper.GRAPH_DEBUG);
}
return;
} else {
@ -5949,13 +5970,17 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
if (pd.isViewingItemCube && clickedinv.getTitle()!=null &&
clickedinv.getTitle().contains("Item Cube #")) {
int id = Integer.parseInt(clickedinv.getTitle().split("#")[1]);
edge = TwosideKeeper.itemCubeGraph.removeEdge(id, clickedid);
TwosideKeeper.log("Removed edge "+edge, TwosideKeeper.GRAPH_DEBUG);
if (!InventoryUtils.inventoryContainsSameItemCube(clickedid, clickedinv)) {
edge = TwosideKeeper.itemCubeGraph.removeEdge(id, clickedid);
TwosideKeeper.log("Removed edge "+TwosideKeeper.itemCubeGraph.getEdgeSource(edge)+","+TwosideKeeper.itemCubeGraph.getEdgeTarget(edge), TwosideKeeper.GRAPH_DEBUG);
}
} else {
//This is not an item cube.
int invid = InventoryUtils.getInventoryNumberHash(clickedinv);
edge = TwosideKeeper.itemCubeGraph.removeEdge(invid, clickedid);
TwosideKeeper.log("Removed edge "+edge, TwosideKeeper.GRAPH_DEBUG);
if (!InventoryUtils.inventoryContainsSameItemCube(clickedid, clickedinv)) {
edge = TwosideKeeper.itemCubeGraph.removeEdge(invid, clickedid);
TwosideKeeper.log("Removed edge "+TwosideKeeper.itemCubeGraph.getEdgeSource(edge)+","+TwosideKeeper.itemCubeGraph.getEdgeTarget(edge), TwosideKeeper.GRAPH_DEBUG);
}
}
} catch (IllegalArgumentException ex) {
ev.setCancelled(true);
@ -5984,9 +6009,6 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
DefaultEdge edge = TwosideKeeper.itemCubeGraph.addEdge(id, clickedid);
TwosideKeeper.log("Added edge "+edge, TwosideKeeper.GRAPH_DEBUG);
} catch (IllegalArgumentException ex) {
ev.setCancelled(true);
ev.setCursor(ev.getCursor());
return;
}
return;
//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);
TwosideKeeper.log("Added edge "+edge, TwosideKeeper.GRAPH_DEBUG);
} catch (IllegalArgumentException ex) {
ev.setCancelled(true);
ev.setCursor(ev.getCursor());
return;
}
} else {
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);
TwosideKeeper.log("Added edge "+edge, TwosideKeeper.GRAPH_DEBUG);
} 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 #")) {
int id = Integer.parseInt(clickedinv.getTitle().split("#")[1]);
int clickedid = ItemCubeUtils.getItemCubeID(ev.getCurrentItem());
DefaultEdge edge = TwosideKeeper.itemCubeGraph.addEdge(id, clickedid);
TwosideKeeper.log("Added edge "+edge, TwosideKeeper.GRAPH_DEBUG);
edge = TwosideKeeper.itemCubeGraph.removeEdge(id, clickedid);
TwosideKeeper.log("Destroyed edge "+edge, TwosideKeeper.GRAPH_DEBUG);
if (!InventoryUtils.inventoryContainsSameItemCube(clickedid, clickedinv)) {
DefaultEdge edge = TwosideKeeper.itemCubeGraph.removeEdge(id, clickedid);
TwosideKeeper.log("Removed edge "+TwosideKeeper.itemCubeGraph.getEdgeSource(edge)+","+TwosideKeeper.itemCubeGraph.getEdgeTarget(edge), TwosideKeeper.GRAPH_DEBUG);
}
//ItemCubeUtils.DestroyAllTargetEdges(clickedid, TwosideKeeper.itemCubeGraph);
} else
if (clickedinv.getType()==InventoryType.PLAYER) {
int clickedid = ItemCubeUtils.getItemCubeID(ev.getCurrentItem());
DefaultEdge edge = TwosideKeeper.itemCubeGraph.removeEdge(PlayerStructure.getPlayerNegativeHash(p), clickedid);
TwosideKeeper.log("Destroyed edge "+edge, TwosideKeeper.GRAPH_DEBUG);
if (!InventoryUtils.inventoryContainsSameItemCube(clickedid, p.getInventory())) {
DefaultEdge edge = TwosideKeeper.itemCubeGraph.removeEdge(PlayerStructure.getPlayerNegativeHash(p), clickedid);
TwosideKeeper.log("Removed edge "+TwosideKeeper.itemCubeGraph.getEdgeSource(edge)+","+TwosideKeeper.itemCubeGraph.getEdgeTarget(edge), TwosideKeeper.GRAPH_DEBUG);
}
} else {
int clickedid = ItemCubeUtils.getItemCubeID(ev.getCurrentItem());
DefaultEdge edge = TwosideKeeper.itemCubeGraph.removeEdge(InventoryUtils.getInventoryNumberHash(clickedinv), clickedid);
TwosideKeeper.log("Destroyed edge "+edge, TwosideKeeper.GRAPH_DEBUG);
if (!InventoryUtils.inventoryContainsSameItemCube(clickedid, clickedinv)) {
DefaultEdge edge = TwosideKeeper.itemCubeGraph.removeEdge(InventoryUtils.getInventoryNumberHash(clickedinv), clickedid);
TwosideKeeper.log("Removed edge "+TwosideKeeper.itemCubeGraph.getEdgeSource(edge)+","+TwosideKeeper.itemCubeGraph.getEdgeTarget(edge), TwosideKeeper.GRAPH_DEBUG);
}
}
}
}

Loading…
Cancel
Save