Buggy graph system implementation
This commit is contained in:
parent
a8aa59ed25
commit
c8abd91f50
Binary file not shown.
@ -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:
|
||||||
|
@ -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 (loc!=null) {
|
if (ItemCubeUtils.IsItemCubeInventory(destination)) {
|
||||||
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 = ItemCubeUtils.ParseItemCubeInventoryID(destination);
|
||||||
id = Integer.parseInt(hash);
|
} else
|
||||||
TwosideKeeper.itemCubeGraph.addVertex(id);
|
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;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -429,9 +429,11 @@ 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);
|
||||||
graph.addVertex(id);
|
if (!graph.containsVertex(id)) {
|
||||||
graph.addEdge(PlayerStructure.getPlayerNegativeHash(p), id);
|
graph.addVertex(id);
|
||||||
IterateAndAddToGraph(id,graph);
|
graph.addEdge(PlayerStructure.getPlayerNegativeHash(p), id);
|
||||||
|
IterateAndAddToGraph(id,graph);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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) {
|
||||||
|
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);
|
Set<DefaultEdge> edges = g.edgesOf(vertex);
|
||||||
|
TwosideKeeper.log("Checking all edges connected to vertex "+vertex, TwosideKeeper.GRAPH_DEBUG2);
|
||||||
for (DefaultEdge e : edges) {
|
for (DefaultEdge e : edges) {
|
||||||
Integer target = g.getEdgeTarget(e);
|
|
||||||
Integer newvertex = g.getEdgeSource(e);
|
Integer newvertex = g.getEdgeSource(e);
|
||||||
//TwosideKeeper.log("Vertex: "+vertex+" - "+newvertex+" : "+target,0);
|
TwosideKeeper.log("EDGE: "+e+" || Vertex: "+vertex+" -> "+newvertex+" ",TwosideKeeper.GRAPH_DEBUG2);
|
||||||
if (Integer.compare(target, vertex)==0) {
|
if (!vals.contains(e)) {
|
||||||
TwosideKeeper.log(e.toString(),0);
|
TwosideKeeper.log(e.toString(),TwosideKeeper.GRAPH_DEBUG);
|
||||||
if (Integer.compare(newvertex,vertex)==0) {
|
vals.add(e);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
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 #");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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,9 +4942,18 @@ 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());
|
||||||
}
|
}
|
||||||
|
|
||||||
@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) {
|
public void onInventoryClose(InventoryCloseEvent ev) {
|
||||||
if (ev.getPlayer() instanceof Player) {
|
if (ev.getPlayer() instanceof Player) {
|
||||||
Player p = (Player)ev.getPlayer();
|
Player p = (Player)ev.getPlayer();
|
||||||
@ -5751,63 +5761,54 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
|
|||||||
} else {
|
} else {
|
||||||
itemcubeid = -1;
|
itemcubeid = -1;
|
||||||
}
|
}
|
||||||
if (idnumb==itemcubeid) {
|
TwosideKeeper.log("Got to here. ID is "+itemcubeid, 5);
|
||||||
//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!
|
if (itemcubeid!=-1 && ev.getRawSlot()<=ev.getView().getTopInventory().getSize()-1) {
|
||||||
//Player p = ((Player)ev.getWhoClicked());
|
//This means we are viewing an item cube currently. Add it to our list.
|
||||||
//SoundUtils.playLocalSound(p, Sound.BLOCK_NOTE_HARP, 0.4f, 0.2f);
|
ItemCubeWindow.addItemCubeWindow(p, itemcubeid);
|
||||||
ev.setCancelled(true);
|
} else
|
||||||
return;
|
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 {
|
} else {
|
||||||
TwosideKeeper.log("Got to here. ID is "+itemcubeid, 5);
|
//ev.setCancelled(true);
|
||||||
Player p = (Player)ev.getWhoClicked();
|
ev.setResult(Result.DENY);
|
||||||
if (itemcubeid!=-1 && ev.getRawSlot()<=ev.getView().getTopInventory().getSize()-1) {
|
//ItemCube.displayErrorMessage(p);
|
||||||
//This means we are viewing an item cube currently. Add it to our list.
|
//pd.itemcubeviews.add(p.getOpenInventory());
|
||||||
ItemCubeWindow.addItemCubeWindow(p, itemcubeid);
|
pd.opened_another_cube=true;
|
||||||
} else
|
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {@Override public void run() {p.openInventory(ItemCube.getViewingItemCubeInventory(idnumb, p));
|
||||||
if (itemcubeid!=-1) {
|
//TODO Implement Graphs. //BuildItemCubeGraph(p);
|
||||||
log("Size is "+(ev.getView().getTopInventory().getSize())+", Clicked slot "+ev.getRawSlot(),5);
|
pd2.opened_another_cube=false;
|
||||||
ItemCubeWindow.removeAllItemCubeWindows(p);
|
pd2.isViewingItemCube=true;}},1);
|
||||||
}
|
SoundUtils.playLocalSound(p, Sound.BLOCK_CHEST_OPEN, 1.0f, 1.0f);
|
||||||
log("This is an Item Cube.",5);
|
return;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -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);
|
||||||
|
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) {
|
if (edge!=null) {
|
||||||
TwosideKeeper.log("Added edge "+edge, TwosideKeeper.GRAPH_DEBUG);
|
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 {
|
} 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);
|
||||||
edge = TwosideKeeper.itemCubeGraph.removeEdge(id, cubeid);
|
if (!InventoryUtils.inventoryContainsSameItemCube(cubeid, clickedinv) && !item1.isSimilar(item2)) {
|
||||||
TwosideKeeper.log("Removed edge "+edge, TwosideKeeper.GRAPH_DEBUG);
|
edge = TwosideKeeper.itemCubeGraph.removeEdge(id, cubeid);
|
||||||
|
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;
|
||||||
TwosideKeeper.log("Removed edge "+edge, TwosideKeeper.GRAPH_DEBUG);
|
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);
|
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;
|
||||||
|
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) {
|
if (edge!=null) {
|
||||||
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(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;
|
|
||||||
}
|
|
||||||
} 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]);
|
||||||
edge = TwosideKeeper.itemCubeGraph.removeEdge(id, clickedid);
|
if (!InventoryUtils.inventoryContainsSameItemCube(clickedid, clickedinv)) {
|
||||||
TwosideKeeper.log("Removed 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);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
//This is not an item cube.
|
//This is not an item cube.
|
||||||
int invid = InventoryUtils.getInventoryNumberHash(clickedinv);
|
int invid = InventoryUtils.getInventoryNumberHash(clickedinv);
|
||||||
edge = TwosideKeeper.itemCubeGraph.removeEdge(invid, clickedid);
|
if (!InventoryUtils.inventoryContainsSameItemCube(clickedid, clickedinv)) {
|
||||||
TwosideKeeper.log("Removed edge "+edge, TwosideKeeper.GRAPH_DEBUG);
|
edge = TwosideKeeper.itemCubeGraph.removeEdge(invid, clickedid);
|
||||||
|
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());
|
||||||
DefaultEdge edge = TwosideKeeper.itemCubeGraph.removeEdge(PlayerStructure.getPlayerNegativeHash(p), clickedid);
|
if (!InventoryUtils.inventoryContainsSameItemCube(clickedid, p.getInventory())) {
|
||||||
TwosideKeeper.log("Destroyed edge "+edge, TwosideKeeper.GRAPH_DEBUG);
|
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 {
|
} else {
|
||||||
int clickedid = ItemCubeUtils.getItemCubeID(ev.getCurrentItem());
|
int clickedid = ItemCubeUtils.getItemCubeID(ev.getCurrentItem());
|
||||||
DefaultEdge edge = TwosideKeeper.itemCubeGraph.removeEdge(InventoryUtils.getInventoryNumberHash(clickedinv), clickedid);
|
if (!InventoryUtils.inventoryContainsSameItemCube(clickedid, clickedinv)) {
|
||||||
TwosideKeeper.log("Destroyed edge "+edge, TwosideKeeper.GRAPH_DEBUG);
|
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…
x
Reference in New Issue
Block a user