Implementation of Graph data structure inside Item Cubes. Fully

functional and bug-free.
testdev
sigonasr2 8 years ago
parent 1fa2a080c8
commit 87dbf99a31
  1. 12
      .externalToolBuilders/New_Builder.launch
  2. 2
      .project
  3. BIN
      TwosideKeeper.jar
  4. 1
      src/sig/plugin/TwosideKeeper/HelperStructures/ItemSet.java
  5. 5
      src/sig/plugin/TwosideKeeper/HelperStructures/Utils/InventoryUtils.java
  6. 19
      src/sig/plugin/TwosideKeeper/HelperStructures/Utils/ItemCubeUtils.java
  7. 99
      src/sig/plugin/TwosideKeeper/TwosideKeeper.java

@ -3,12 +3,18 @@
<booleanAttribute key="org.eclipse.ant.ui.ATTR_TARGETS_UPDATED" value="true"/>
<booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/>
<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${resource}"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/TwosideKeeper"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="4"/>
</listAttribute>
<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/>
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="true"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="Project"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/Project/projectBuilder.xml}"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="TwosideKeeper"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/TwosideKeeper/projectBuilder.xml}"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,"/>
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${workspace_loc:/Project}"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${workspace_loc:/TwosideKeeper}"/>
</launchConfiguration>

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>AutoPluginUpdate</name>
<name>TwosideKeeper</name>
<comment></comment>
<projects>
</projects>

Binary file not shown.

@ -12,6 +12,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import aPlugin.API;
import sig.plugin.TwosideKeeper.TwosideKeeper;
import sig.plugin.TwosideKeeper.HelperStructures.Common.BaublePouch;
import sig.plugin.TwosideKeeper.HelperStructures.Common.GenericFunctions;

@ -283,6 +283,11 @@ public class InventoryUtils {
return destination.getLocation().getX()+destination.getLocation().getY()+destination.getLocation().getZ()+destination.getLocation().getWorld().getName();
}
public static int getInventoryNumberHash(Inventory 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);
return Integer.parseInt(hash);
}
public static ItemStack[] RemoveAllNullItems(ItemStack[] contents) {
List<ItemStack> items = new ArrayList<ItemStack>();
for (int i=0;i<contents.length;i++) {

@ -460,7 +460,7 @@ public class ItemCubeUtils {
UndirectedGraph<Integer,DefaultEdge> graph = TwosideKeeper.itemCubeGraph;
graph.addVertex(id);
DefaultEdge edge = graph.addEdge(PlayerStructure.getPlayerNegativeHash(p), id);
//TwosideKeeper.log("Added edge "+edge, 0);
TwosideKeeper.log("Added edge "+edge, TwosideKeeper.GRAPH_DEBUG);
ItemCubeUtils.IterateAndAddToGraph(id, graph);
}
}
@ -472,7 +472,7 @@ public class ItemCubeUtils {
UndirectedGraph<Integer,DefaultEdge> graph = TwosideKeeper.itemCubeGraph;
graph.addVertex(id);
DefaultEdge edge = graph.addEdge(sourceCubeID, id);
//TwosideKeeper.log("Added edge "+edge, 0);
TwosideKeeper.log("Added edge "+edge, TwosideKeeper.GRAPH_DEBUG);
ItemCubeUtils.IterateAndAddToGraph(id, graph);
}
}
@ -499,7 +499,7 @@ public class ItemCubeUtils {
if (id!=newid) { //We don't need to link to itself.
graph.addVertex(newid);
DefaultEdge edge = graph.addEdge(id, newid);
//TwosideKeeper.log("Reconnected edge "+edge, 0);
TwosideKeeper.log("Reconnected edge "+edge, TwosideKeeper.GRAPH_DEBUG);
}
}
}
@ -511,7 +511,7 @@ public class ItemCubeUtils {
int newid = getItemCubeID(it);
graph.addVertex(newid);
DefaultEdge edge = graph.addEdge(PlayerStructure.getPlayerNegativeHash(p), newid);
//TwosideKeeper.log("Reconnected edge "+edge, 0);
TwosideKeeper.log("Reconnected edge "+edge, TwosideKeeper.GRAPH_DEBUG);
}
}
}
@ -525,7 +525,7 @@ public class ItemCubeUtils {
}
while (destroyed.size()>0) {
DefaultEdge edge = destroyed.remove(0);
//TwosideKeeper.log("Destroyed edge "+edge, 0);
TwosideKeeper.log("Destroyed edge "+edge, TwosideKeeper.GRAPH_DEBUG);
graph.removeEdge(edge);
}
}
@ -539,8 +539,9 @@ public class ItemCubeUtils {
}
while (destroyed.size()>0) {
DefaultEdge edge = destroyed.remove(0);
//TwosideKeeper.log("Destroyed edge "+edge, 0);
TwosideKeeper.log("Destroyed edge "+edge, TwosideKeeper.GRAPH_DEBUG);
graph.removeEdge(edge);
}
}
@ -581,4 +582,10 @@ public class ItemCubeUtils {
}
return false;
}
/*public static void setupGraphForChest(Inventory inv) {
if (inv.getType()==InventoryType.CHEST ||
inv.getType()==InventoryType.) {
}
}*/
}

@ -459,6 +459,7 @@ 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 double worldShopDistanceSquared = 1000000;
public static double worldShopPriceMult = 2.0; //How much higher the price increases for every increment of worlsShopDistanceSquared.
@ -4903,6 +4904,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
//GenericFunctions.updateSetItemsInInventory(ev.getInventory());
GenericFunctions.updateSetItemsInInventory(ev.getView().getBottomInventory());
GenericFunctions.updateSetItemsInInventory(ev.getView().getTopInventory());
//ItemCubeUtils.setupGraphForChest(ev.getInventory());
}
@EventHandler(priority=EventPriority.LOW,ignoreCancelled = true)
@ -5772,30 +5774,33 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
Inventory clickedinv = p.getOpenInventory().getTopInventory();
ItemStack item1 = p.getInventory().getItem(ev.getHotbarButton()); //Bottom to Top
ItemStack item2 = p.getOpenInventory().getItem(ev.getRawSlot()); //Top to Bottom
TwosideKeeper.log(item1+" ||| "+item2, 0);
if (clickedinv!=null && clickedinv.getTitle()!=null && clickedinv.getTitle().contains("Item Cube #") &&
ev.getRawSlot()<p.getOpenInventory().getTopInventory().getSize()) {
int id = Integer.parseInt(clickedinv.getTitle().split("#")[1]);
if (ItemCubeUtils.isItemCube(item1)) {
int cubeid = ItemCubeUtils.getItemCubeID(item1);
try {
if (id!=cubeid) {
DefaultEdge edge = TwosideKeeper.itemCubeGraph.addEdge(id, cubeid);
edge = TwosideKeeper.itemCubeGraph.removeEdge(PlayerStructure.getPlayerNegativeHash(p), cubeid);
} catch (IllegalArgumentException ex) {
ev.setCancelled(true);
ev.setCursor(ev.getCursor());
return;
}
if (!ItemCubeUtils.isConnectedToRootNode(TwosideKeeper.itemCubeGraph, id)) {
try {
DefaultEdge edge = TwosideKeeper.itemCubeGraph.addEdge(PlayerStructure.getPlayerNegativeHash(p), cubeid);
edge = TwosideKeeper.itemCubeGraph.removeEdge(id, cubeid);
//TwosideKeeper.log("Added edge "+edge, 0);
} catch (IllegalArgumentException ex) {
ev.setCancelled(true);
ev.setCursor(ev.getCursor());
return;
}
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());
return;
}
return;
} else {
ev.setCancelled(true);
ev.setCursor(ev.getCursor());
return;
@ -5805,8 +5810,9 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
int cubeid = ItemCubeUtils.getItemCubeID(item2);
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("Added edge "+edge, 0);
TwosideKeeper.log("Removed edge "+edge, TwosideKeeper.GRAPH_DEBUG);
} catch (IllegalArgumentException ex) {
ev.setCancelled(true);
ev.setCursor(ev.getCursor());
@ -5825,16 +5831,29 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
if (!InventoryUtils.hasFullInventory(clickedinv)) {
int id = Integer.parseInt(clickedinv.getTitle().split("#")[1]);
int clickedid = ItemCubeUtils.getItemCubeID(ev.getCurrentItem());
if (!ItemCubeUtils.isConnectedToRootNode(TwosideKeeper.itemCubeGraph, id)) {
ev.setCancelled(true);
ev.setCursor(ev.getCursor());
return;
}
try {
DefaultEdge edge = TwosideKeeper.itemCubeGraph.addEdge(id, clickedid);
edge = TwosideKeeper.itemCubeGraph.removeEdge(PlayerStructure.getPlayerNegativeHash(p), clickedid);
//TwosideKeeper.log("Added edge "+edge, 0);
} catch (IllegalArgumentException ex) {
TwosideKeeper.log("ID is "+id+":"+clickedid, 0);
if (id!=clickedid) {
DefaultEdge 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;
}
} else {
ev.setCancelled(true);
ev.setCursor(ev.getCursor());
return;
}
return;
} else {
ev.setCancelled(true);
ev.setCursor(ev.getCursor());
return;
@ -5848,12 +5867,13 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
Inventory clickedinv = p.getOpenInventory().getTopInventory();
try {
DefaultEdge edge = TwosideKeeper.itemCubeGraph.addEdge(PlayerStructure.getPlayerNegativeHash(p), clickedid);
TwosideKeeper.log("Added edge "+edge, TwosideKeeper.GRAPH_DEBUG);
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);
}
//TwosideKeeper.log("Added edge "+edge, 0);
} catch (IllegalArgumentException ex) {
ev.setCancelled(true);
ev.setCursor(ev.getCursor());
@ -5876,19 +5896,20 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
}
try {
DefaultEdge edge = TwosideKeeper.itemCubeGraph.addEdge(id, clickedid);
//TwosideKeeper.log("Added edge "+edge, 0);
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);
} else
if (clickedinv.getType()==InventoryType.PLAYER) {
int clickedid = ItemCubeUtils.getItemCubeID(ev.getCursor());
try {
DefaultEdge edge = TwosideKeeper.itemCubeGraph.addEdge(PlayerStructure.getPlayerNegativeHash(p), clickedid);
//TwosideKeeper.log("Added edge "+edge, 0);
TwosideKeeper.log("Added edge "+edge, TwosideKeeper.GRAPH_DEBUG);
} catch (IllegalArgumentException ex) {
ev.setCancelled(true);
ev.setCursor(ev.getCursor());
@ -5903,15 +5924,16 @@ 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());
//TwosideKeeper.itemCubeGraph.addEdge(id, clickedid);
DefaultEdge edge = TwosideKeeper.itemCubeGraph.removeEdge(id, clickedid);
//TwosideKeeper.log("Destroyed edge "+edge, 0);
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);
//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, 0);
TwosideKeeper.log("Destroyed edge "+edge, TwosideKeeper.GRAPH_DEBUG);
}
}
}
@ -5939,12 +5961,13 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
}
try {
DefaultEdge edge = TwosideKeeper.itemCubeGraph.addEdge(id, clickedid);
TwosideKeeper.log("Added edge "+edge, 0);
TwosideKeeper.log("Added edge "+edge, TwosideKeeper.GRAPH_DEBUG);
} catch (IllegalArgumentException ex) {
ev.setCancelled(true);
ev.setCursor(ev.getCursor());
return;
}
return;
} else
{
TwosideKeeper.log("Clicked "+clickedslot, 0);
@ -5952,7 +5975,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
int clickedid = ItemCubeUtils.getItemCubeID(item);
try {
DefaultEdge edge = TwosideKeeper.itemCubeGraph.addEdge(PlayerStructure.getPlayerNegativeHash(p), clickedid);
TwosideKeeper.log("Added edge "+edge, 0);
TwosideKeeper.log("Added edge "+edge, TwosideKeeper.GRAPH_DEBUG);
} catch (IllegalArgumentException ex) {
ev.setCancelled(true);
ev.setCursor(ev.getCursor());

Loading…
Cancel
Save