Created
October 14, 2011 17:46
-
-
Save Edoxile/1287795 to your computer and use it in GitHub Desktop.
TweakCart diff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/libs/craftbukkit-0.0.1-SNAPSHOT.jar b/libs/craftbukkit-0.0.1-SNAPSHOT.jar | |
index 5567fe6..7aff0e0 100644 | |
Binary files a/libs/craftbukkit-0.0.1-SNAPSHOT.jar and b/libs/craftbukkit-0.0.1-SNAPSHOT.jar differ | |
diff --git a/plugin.yml b/plugin.yml | |
index 2129efc..7b9475c 100644 | |
--- a/plugin.yml | |
+++ b/plugin.yml | |
@@ -2,5 +2,9 @@ name: TweakCart | |
main: com.tweakcart.TweakCart | |
authors: [Meaglin, The-Sec, windwarrior, Edoxile] | |
website: https://github.com/Edoxile/TweakCart | |
-version: 0.2.4 | |
- | |
+version: 0.3.0 | |
+commands: | |
+ cartdebug: | |
+ description: Show TweakCart debug info | |
+ usage: /cartdebug | |
+ aliases: [cd] | |
diff --git a/src/com/tweakcart/TweakCart.java b/src/com/tweakcart/TweakCart.java | |
index ebba177..006785c 100644 | |
--- a/src/com/tweakcart/TweakCart.java | |
+++ b/src/com/tweakcart/TweakCart.java | |
@@ -2,12 +2,17 @@ package com.tweakcart; | |
import com.tweakcart.listeners.TweakCartBlockListener; | |
import com.tweakcart.listeners.TweakCartVehicleListener; | |
+ | |
+import org.bukkit.ChatColor; | |
+import org.bukkit.command.Command; | |
+import org.bukkit.command.CommandSender; | |
import org.bukkit.event.Event; | |
import org.bukkit.plugin.PluginManager; | |
import org.bukkit.plugin.java.JavaPlugin; | |
import java.util.logging.Logger; | |
+ | |
/** | |
* Created by IntelliJ IDEA. | |
* User: Edoxile | |
@@ -27,7 +32,7 @@ public class TweakCart extends JavaPlugin { | |
pm.registerEvent(Event.Type.VEHICLE_MOVE, vehicleListener, Event.Priority.Normal, this); | |
pm.registerEvent(Event.Type.BLOCK_DISPENSE, blockListener, Event.Priority.Normal, this); | |
pm.registerEvent(Event.Type.VEHICLE_COLLISION_BLOCK, vehicleListener, Event.Priority.Normal, this); | |
- | |
+ pm.registerEvent(Event.Type.SIGN_CHANGE, blockListener , Event.Priority.Normal, this); | |
// Loaded! | |
log.info("[" + getDescription().getName() + "] Enabled! version:" + getDescription().getVersion()); | |
} | |
@@ -35,4 +40,20 @@ public class TweakCart extends JavaPlugin { | |
public void onDisable() { | |
log.info("[" + getDescription().getName() + "] Disabled!"); | |
} | |
+ | |
+ | |
+ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { | |
+ if(cmd.getName().toLowerCase().equals("cartdebug")){ | |
+ sender.sendMessage("SoftMap peformance," + ChatColor.GREEN + " Hits: " + vehicleListener.getSoftMapHits() + ChatColor.YELLOW + ", Partial misses: " + vehicleListener.getPartialMisses() + ChatColor.RED + ", Misses: " + vehicleListener.getSoftMapMisses() + ChatColor.GOLD + ", Average Full hits: " + (float) vehicleListener.getSoftMapHits() / ((float) vehicleListener.getSoftMapHits() + (float) vehicleListener.getSoftMapMisses()) * 100.0f + "%"); | |
+ } | |
+ return false; | |
+ } | |
+ | |
+ public TweakCartBlockListener getBlockListener(){ | |
+ return blockListener; | |
+ } | |
+ | |
+ public TweakCartVehicleListener getVehicleListener(){ | |
+ return vehicleListener; | |
+ } | |
} | |
diff --git a/src/com/tweakcart/listeners/TweakCartBlockListener.java b/src/com/tweakcart/listeners/TweakCartBlockListener.java | |
index bf21275..ad7e3a4 100644 | |
--- a/src/com/tweakcart/listeners/TweakCartBlockListener.java | |
+++ b/src/com/tweakcart/listeners/TweakCartBlockListener.java | |
@@ -2,6 +2,8 @@ package com.tweakcart.listeners; | |
import com.tweakcart.TweakCart; | |
import com.tweakcart.model.Direction; | |
+import com.tweakcart.model.SignLocation; | |
+ | |
import org.bukkit.block.Block; | |
import org.bukkit.block.BlockFace; | |
import org.bukkit.block.Dispenser; | |
@@ -10,20 +12,25 @@ import org.bukkit.entity.PoweredMinecart; | |
import org.bukkit.entity.StorageMinecart; | |
import org.bukkit.event.block.BlockDispenseEvent; | |
import org.bukkit.event.block.BlockListener; | |
+import org.bukkit.event.block.SignChangeEvent; | |
-import java.util.logging.Logger; | |
/** | |
* Created by IntelliJ IDEA. | |
* User: Edoxile | |
*/ | |
public class TweakCartBlockListener extends BlockListener { | |
- private static final Logger log = Logger.getLogger("Minecraft"); | |
private TweakCart plugin; | |
public TweakCartBlockListener(TweakCart plugin) { | |
this.plugin = plugin; | |
} | |
+ | |
+ public void onSignChange(SignChangeEvent event){ | |
+ Block b = event.getBlock(); | |
+ SignLocation loc = new SignLocation(b.getX(), b.getY(), b.getZ()); | |
+ plugin.getVehicleListener().removeEntry(loc); | |
+ } | |
public void onBlockDispense(BlockDispenseEvent event) { | |
switch (event.getItem().getTypeId()) { | |
diff --git a/src/com/tweakcart/listeners/TweakCartVehicleListener.java b/src/com/tweakcart/listeners/TweakCartVehicleListener.java | |
index f1116af..6629d6f 100644 | |
--- a/src/com/tweakcart/listeners/TweakCartVehicleListener.java | |
+++ b/src/com/tweakcart/listeners/TweakCartVehicleListener.java | |
@@ -1,12 +1,15 @@ | |
package com.tweakcart.listeners; | |
+import com.google.common.collect.MapMaker; | |
import com.tweakcart.TweakCart; | |
import com.tweakcart.model.Direction; | |
import com.tweakcart.model.IntMap; | |
+import com.tweakcart.model.SignLocation; | |
import com.tweakcart.model.SignParser; | |
import com.tweakcart.util.CartUtil; | |
import com.tweakcart.util.ChestUtil; | |
import com.tweakcart.util.MathUtil; | |
+ | |
import org.bukkit.Material; | |
import org.bukkit.block.*; | |
import org.bukkit.entity.Minecart; | |
@@ -18,30 +21,33 @@ import org.bukkit.event.vehicle.VehicleMoveEvent; | |
import org.bukkit.inventory.ItemStack; | |
import org.bukkit.util.Vector; | |
-import java.util.HashMap; | |
+import java.util.ArrayList; | |
+import java.util.Iterator; | |
import java.util.List; | |
-import java.util.Map; | |
-import java.util.logging.Logger; | |
+import java.util.concurrent.ConcurrentMap; | |
/** | |
* Created by IntelliJ IDEA. | |
- * User: Edoxile | |
+ * | |
+ * @author Edoxile | |
*/ | |
public class TweakCartVehicleListener extends VehicleListener { | |
- private static final Logger log = Logger.getLogger("Minecraft"); | |
- private static TweakCart plugin = null; | |
- | |
+ //private static TweakCart plugin = null; | |
+ private static ConcurrentMap<SignLocation, List<IntMap>> softmap; | |
+ private static int softMapHits = 0; | |
+ private static int softMapMisses = 0; | |
+ private int softMapPartialMisses = 0; | |
public TweakCartVehicleListener(TweakCart instance) { | |
- plugin = instance; | |
+ //plugin = instance; | |
+ softmap = new MapMaker().concurrencyLevel(4).softValues().makeMap(); | |
} | |
public void onVehicleMove(VehicleMoveEvent event) { | |
- if (MathUtil.isSameBlock(event.getFrom(), event.getTo())) { | |
- return; | |
- } | |
- | |
- if (event.getVehicle() instanceof Minecart) { | |
- Minecart cart = (Minecart) event.getVehicle(); | |
+ if (event.getVehicle() instanceof StorageMinecart) { | |
+ if (MathUtil.isSameBlock(event.getFrom(), event.getTo())) { | |
+ return; | |
+ } | |
+ StorageMinecart cart = (StorageMinecart) event.getVehicle(); | |
Vector cartSpeed = cart.getVelocity(); // We are gonna use this 1 object everywhere(a new Vector() is made on every call ;) ). | |
Block toBlock = event.getTo().getBlock(); //Use this object everywhere as well. | |
@@ -50,39 +56,58 @@ public class TweakCartVehicleListener extends VehicleListener { | |
return; | |
} | |
- switch (horizontalDirection) { | |
- case NORTH: | |
- case SOUTH: | |
- for (int dy = -1; dy <= 0; dy++) { | |
- for (int dz = -1; dz <= 1; dz += 2) { | |
- Block tempBlock = toBlock.getRelative(0, dy, dz); | |
- if (tempBlock.getTypeId() == Material.SIGN_POST.getId() | |
- || tempBlock.getTypeId() == Material.WALL_SIGN.getId()) { | |
- Sign s = (Sign) tempBlock.getState(); | |
- parseSign(s, cart, horizontalDirection); | |
+ switch (toBlock.getType()) { | |
+ case RAILS: | |
+ case POWERED_RAIL: | |
+ case DETECTOR_RAIL: | |
+ switch (horizontalDirection) { | |
+ case NORTH: | |
+ case SOUTH: | |
+ for (int dy = -1; dy <= 0; dy++) { | |
+ for (int dz = -1; dz <= 1; dz += 2) { | |
+ Block tempBlock = toBlock.getRelative(0, dy, dz); | |
+ if (tempBlock.getTypeId() == Material.SIGN_POST.getId() | |
+ || tempBlock.getTypeId() == Material.WALL_SIGN.getId()) { | |
+ Sign s = (Sign) tempBlock.getState(); | |
+ parseItemSign(s, cart, horizontalDirection); | |
+ } | |
+ } | |
} | |
- } | |
- } | |
- break; | |
- case EAST: | |
- case WEST: | |
- for (int dy = -1; dy <= 0; dy++) { | |
- for (int dx = -1; dx <= 1; dx += 2) { | |
- Block tempBlock = toBlock.getRelative(dx, dy, 0); | |
- if (tempBlock.getTypeId() == Material.SIGN_POST.getId() | |
- || tempBlock.getTypeId() == Material.WALL_SIGN.getId()) { | |
- Sign s = (Sign) tempBlock.getState(); | |
- parseSign(s, cart, horizontalDirection); | |
+ break; | |
+ case EAST: | |
+ case WEST: | |
+ for (int dy = -1; dy <= 0; dy++) { | |
+ for (int dx = -1; dx <= 1; dx += 2) { | |
+ Block tempBlock = toBlock.getRelative(dx, dy, 0); | |
+ if (tempBlock.getTypeId() == Material.SIGN_POST.getId() | |
+ || tempBlock.getTypeId() == Material.WALL_SIGN.getId()) { | |
+ Sign s = (Sign) tempBlock.getState(); | |
+ parseItemSign(s, cart, horizontalDirection); | |
+ } | |
+ } | |
} | |
- } | |
+ break; | |
+ } | |
+ Block tempBlock = toBlock.getRelative(0, 1, 0); | |
+ if (tempBlock.getTypeId() == Material.SIGN_POST.getId() | |
+ || tempBlock.getTypeId() == Material.WALL_SIGN.getId()) { | |
+ Sign s = (Sign) tempBlock.getState(); | |
+ parseItemSign(s, cart, horizontalDirection); | |
} | |
break; | |
+ case SIGN_POST: | |
+ case WALL_SIGN: | |
+ | |
+ break; | |
} | |
} | |
+ else{ | |
+ | |
+ } | |
} | |
public void onVehicleBlockCollision(VehicleBlockCollisionEvent event) { | |
- if (event.getBlock().getRelative(BlockFace.UP).getTypeId() == 23 && event.getVehicle() instanceof Minecart) { | |
+ if (event.getVehicle() instanceof Minecart && event.getBlock().getRelative(BlockFace.UP).getTypeId() == Material.DISPENSER.getId()) { | |
ItemStack item; | |
if (event.getVehicle() instanceof PoweredMinecart) { | |
item = new ItemStack(Material.POWERED_MINECART, 1); | |
@@ -110,32 +135,98 @@ public class TweakCartVehicleListener extends VehicleListener { | |
} | |
} | |
- private void parseSign(Sign sign, Minecart cart, Direction direction) { | |
- HashMap<SignParser.Action, IntMap> dataMap = SignParser.parseSign(sign, direction); | |
- if (SignParser.checkStorageCart(cart)) { | |
- StorageMinecart storageCart = (StorageMinecart) cart; | |
- List<Chest> chests; | |
- for (Map.Entry<SignParser.Action, IntMap> entry : dataMap.entrySet()) { | |
- if (entry.getValue() == null) | |
- continue; | |
- switch (entry.getKey()) { | |
- case COLLECT: | |
- //Collect items (from cart to chest) | |
- chests = ChestUtil.getChestsAroundBlock(sign.getBlock(), 1); | |
- IntMap temp = entry.getValue(); | |
- for (Chest c : chests) { | |
- temp = ChestUtil.moveItems(storageCart.getInventory(), c.getInventory(), temp); | |
- } | |
- break; | |
- case DEPOSIT: | |
- //Deposit items (from chest to cart) | |
- chests = ChestUtil.getChestsAroundBlock(sign.getBlock(), 1); | |
- for (Chest c : chests) { | |
- ChestUtil.moveItems(c.getInventory(), storageCart.getInventory(), entry.getValue()); | |
- } | |
- break; | |
+ | |
+ private void parseItemSign(Sign sign, StorageMinecart cart, Direction direction) { | |
+ List<IntMap> intmaps; | |
+ List<Chest> chests; | |
+ SignLocation loc = new SignLocation(sign.getX(), sign.getY(), sign.getZ()); | |
+ List<IntMap> temp = softmap.get(loc); | |
+ if(temp != null && containsDirection(temp, direction)){ | |
+ intmaps = stripDirection(temp, direction); | |
+ softMapHits++; | |
+ } | |
+ else{ | |
+ intmaps = SignParser.parseItemSign(sign, direction); | |
+ if(softmap.get(loc) != null){ | |
+ List<IntMap> prevresult = softmap.get(loc); | |
+ for(int i = 0; i < prevresult.size(); i++){ | |
+ if(!intmaps.contains(prevresult.get(i))){ | |
+ intmaps.add(prevresult.get(i)); | |
+ } | |
} | |
+ softmap.put(loc, intmaps); | |
+ softMapPartialMisses++; | |
+ } | |
+ else{ | |
+ softmap.put(loc, intmaps); | |
+ softMapMisses++; | |
} | |
+ | |
} | |
+ for (IntMap map: intmaps) { | |
+ if (map == null) | |
+ continue; | |
+ switch (map.getAction()) { | |
+ case COLLECT: | |
+ //Collect items (from cart to chest) | |
+ chests = ChestUtil.getChestsAroundBlock(sign.getBlock(), 1); | |
+ for (Chest c : chests) { | |
+ ChestUtil.moveItems(cart.getInventory(), c.getInventory(), map, true); | |
+ } | |
+ break; | |
+ case DEPOSIT: | |
+ //Deposit items (from chest to cart) | |
+ chests = ChestUtil.getChestsAroundBlock(sign.getBlock(), 1); | |
+ for (Chest c : chests) { | |
+ ChestUtil.moveItems(c.getInventory(), cart.getInventory(), map, false); | |
+ } | |
+ break; | |
+ } | |
+ } | |
+ } | |
+ | |
+ private List<IntMap> stripDirection(List<IntMap> temp, Direction dir) { | |
+ List<IntMap> result = new ArrayList<IntMap>(); | |
+ for(int i = 0; i < temp.size(); i++){ | |
+ if(temp.get(i).getDirection() == dir || temp.get(i).getDirection() == Direction.SELF){ | |
+ result.add(temp.get(i)); | |
+ } | |
+ } | |
+ | |
+ return result; | |
+ } | |
+ | |
+ private boolean containsDirection(List<IntMap> list, Direction dir) { | |
+ for(Iterator<IntMap> it = list.iterator(); it.hasNext();){ | |
+ Direction dir2 = it.next().getDirection(); | |
+ if(dir2 == dir){ | |
+ return true; | |
+ } | |
+ } | |
+ return false; | |
+ | |
+ } | |
+ | |
+ public int getSoftMapHits(){ | |
+ return softMapHits; | |
+ } | |
+ | |
+ public int getSoftMapMisses(){ | |
+ return softMapMisses; | |
+ } | |
+ | |
+ public int getPartialMisses(){ | |
+ return softMapPartialMisses; | |
+ } | |
+ | |
+ /** | |
+ * TODO: write this function. | |
+ */ | |
+ public void parseRouteSign(Sign sign, Minecart cart, Direction direction) { | |
+ //fill this | |
+ } | |
+ | |
+ public void removeEntry(SignLocation loc) { | |
+ softmap.remove(loc); | |
} | |
} | |
diff --git a/src/com/tweakcart/model/Direction.java b/src/com/tweakcart/model/Direction.java | |
index e3935fa..4f45d77 100644 | |
--- a/src/com/tweakcart/model/Direction.java | |
+++ b/src/com/tweakcart/model/Direction.java | |
@@ -39,29 +39,14 @@ public enum Direction { | |
this.modZ = dir1.getModZ() + dir2.getModZ(); | |
} | |
- /** | |
- * Get the amount of X-coordinates to modify to get the represented block | |
- * | |
- * @return Amount of X-coordinates to modify | |
- */ | |
public int getModX() { | |
return modX; | |
} | |
- /** | |
- * Get the amount of Y-coordinates to modify to get the represented block | |
- * | |
- * @return Amount of Y-coordinates to modify | |
- */ | |
public int getModY() { | |
return modY; | |
} | |
- /** | |
- * Get the amount of Z-coordinates to modify to get the represented block | |
- * | |
- * @return Amount of Z-coordinates to modify | |
- */ | |
public int getModZ() { | |
return modZ; | |
} | |
@@ -74,16 +59,7 @@ public enum Direction { | |
return directions[modx + 1][mody + 1][modz + 1]; | |
} | |
- | |
- /** | |
- * Returns the direction the track is pointing at. | |
- * few rules: | |
- * - curved rails will return the direction their CURVE is pointing AT. | |
- * - ascending tracks will return the direction they are ascending TO. | |
- * | |
- * @param track | |
- * @return direction. | |
- */ | |
+ @Deprecated | |
public static final Direction getHorizontalTrackDirection(Block track) { | |
byte data = track.getData(); | |
switch (track.getTypeId()) { | |
@@ -121,15 +97,7 @@ public enum Direction { | |
} | |
} | |
- /** | |
- * Returns the vertical direction the track is pointing to. | |
- * few rules: | |
- * - returns UP for all ascending tracks. | |
- * - return SELF for the rest. | |
- * | |
- * @param track | |
- * @return direction | |
- */ | |
+ @Deprecated | |
public static final Direction getVerticalTrackDirection(Block track) { | |
switch (track.getTypeId()) { | |
case 27: | |
diff --git a/src/com/tweakcart/model/IntMap.java b/src/com/tweakcart/model/IntMap.java | |
index fae97ab..60d433f 100644 | |
--- a/src/com/tweakcart/model/IntMap.java | |
+++ b/src/com/tweakcart/model/IntMap.java | |
@@ -1,25 +1,30 @@ | |
package com.tweakcart.model; | |
+import org.bukkit.Bukkit; | |
+import org.bukkit.ChatColor; | |
import org.bukkit.Material; | |
import org.bukkit.material.MaterialData; | |
+import com.tweakcart.model.SignParser.Action; | |
+ | |
/** | |
- * Created by Eclipse. | |
+ * Created by IntelliJ IDEA. | |
* | |
* @author TheSec, Edoxile | |
*/ | |
public class IntMap { | |
- public static final int materialSize = Material.values().length; | |
- public static final int mapSize = materialSize + 54; | |
+ private static final int materialSize = Material.values().length - 1; | |
private int[] mapData; | |
+ private Direction dir; | |
+ private Action act; | |
public IntMap() { | |
- mapData = new int[mapSize]; | |
+ mapData = new int[materialSize + 50]; | |
} | |
private IntMap(int[] data) { | |
- if (data.length != (mapSize)) { | |
- mapData = new int[mapSize]; | |
+ if (data.length != (materialSize + 50)) { | |
+ mapData = new int[materialSize + 50]; | |
} else { | |
mapData = data; | |
} | |
@@ -33,7 +38,7 @@ public class IntMap { | |
public int getInt(int id, byte data) { | |
int intLocation = IntMap.getIntIndex(id, data); | |
- if (intLocation == -1 || intLocation >= mapSize) { | |
+ if (intLocation == -1) { | |
return 0; | |
} | |
@@ -72,9 +77,6 @@ public class IntMap { | |
} | |
private static int getIntIndex(Material m, byte data) { | |
- if(m == null){ | |
- return -1; | |
- } | |
switch (data) { | |
case 0: | |
//Alle items waarop we .ordinal kunnen doen | |
@@ -107,17 +109,6 @@ public class IntMap { | |
return materialSize + (int) data + 34; | |
else | |
return -1; | |
- case COAL: | |
- if (data < 2) | |
- return materialSize + (int) data + 49; | |
- else | |
- return -1; | |
- case STEP: | |
- if (data < 7) | |
- return materialSize + (int) data + 50; | |
- else | |
- return -1; | |
- | |
default: | |
return m.ordinal(); | |
} | |
@@ -132,8 +123,6 @@ public class IntMap { | |
case 17: | |
case 18: | |
case 35: | |
- case 44: | |
- case 263: | |
case 351: | |
return true; | |
default: | |
@@ -194,14 +183,15 @@ public class IntMap { | |
} | |
private boolean setDataRange(int id, byte start, byte end, int amount) { | |
- if (!hasDataValue(id)){ | |
+ Bukkit.getServer().broadcastMessage("" + ChatColor.RED + materialSize); | |
+ if (!hasDataValue(id)) | |
return false; | |
- } | |
+ | |
for (byte data = start; data <= end; data++) { | |
int key = getIntIndex(id, data); | |
- if (key == -1){ | |
+ Bukkit.getServer().broadcastMessage(id + " " + data + " " + key); | |
+ if (key == -1) | |
break; | |
- } | |
mapData[key] = amount; | |
} | |
return true; | |
@@ -211,11 +201,16 @@ public class IntMap { | |
public boolean equals(Object other) { | |
if (other instanceof IntMap) { | |
IntMap otherMap = (IntMap) other; | |
- for (int index = 0; index <= mapData.length; index++) { | |
- if (mapData[index] != otherMap.mapData[index]) | |
- return false; | |
+ if(otherMap.getDirection() == this.getDirection()){ | |
+ for (int index = 0; index < mapData.length; index++) { | |
+ if (mapData[index] != otherMap.mapData[index]) | |
+ return false; | |
+ } | |
+ return true; | |
+ } | |
+ else{ | |
+ return false; | |
} | |
- return true; | |
} else { | |
return false; | |
} | |
@@ -249,4 +244,22 @@ public class IntMap { | |
} | |
} | |
+ | |
+ public void setDirection(Direction dir) { | |
+ this.dir = dir; | |
+ } | |
+ | |
+ public Direction getDirection(){ | |
+ return dir; | |
+ } | |
+ | |
+ public void setAction(Action act) { | |
+ this.act = act; | |
+ | |
+ } | |
+ | |
+ public Action getAction(){ | |
+ return act; | |
+ } | |
+ | |
} | |
diff --git a/src/com/tweakcart/model/SignParser.java b/src/com/tweakcart/model/SignParser.java | |
index 694e1b2..76dd966 100644 | |
--- a/src/com/tweakcart/model/SignParser.java | |
+++ b/src/com/tweakcart/model/SignParser.java | |
@@ -5,8 +5,8 @@ import org.bukkit.entity.Minecart; | |
import org.bukkit.entity.PoweredMinecart; | |
import org.bukkit.entity.StorageMinecart; | |
-import java.util.HashMap; | |
-import java.util.logging.Logger; | |
+import java.util.ArrayList; | |
+import java.util.List; | |
/** | |
* Created by IntelliJ IDEA. | |
@@ -22,7 +22,6 @@ public class SignParser { | |
ALL | |
} | |
- private static final Logger log = Logger.getLogger("Minecraft"); | |
public static String removeBrackets(String line) { | |
if (line.length() > 2 && line.charAt(0) == '[' && line.charAt(line.length() - 1) == ']') { | |
@@ -32,61 +31,53 @@ public class SignParser { | |
} | |
} | |
- public static Action parseAction(String line) { | |
- if (line == null) { | |
+ public static Action parseAction(String line, Direction direction) { | |
+ if (line == null || line.equals("")) { | |
return Action.NULL; | |
} | |
- line = line.toLowerCase(); | |
+ char firstChar = line.charAt(0); | |
if (line.length() > 0) { | |
- if (Character.isDigit(line.charAt(0))) { | |
+ if (Character.isDigit(firstChar) || firstChar == '!') { | |
return Action.ITEM; | |
- } else { | |
- | |
- switch (line.charAt(0)) { | |
- case '[': | |
- case '!': | |
+ } else if (line.charAt(1) == '+') { | |
+ switch (firstChar) { | |
case 'n': | |
case 's': | |
case 'w': | |
case 'e': | |
- case 'N': | |
- case 'S': | |
- case 'W': | |
- case 'E': | |
- if (line.length() > 2) { | |
- if (line.charAt(2) == 'a' && line.equals(Character.toString(line.charAt(0)) + "+all items")) { | |
+ if (checkDirection(firstChar, direction)) { | |
+ if (line.charAt(2) == 'a' && line.contains("all items")) { | |
return Action.ALL; | |
- } else { | |
- return Action.ITEM; | |
} | |
+ return Action.ITEM; | |
} else { | |
return Action.NULL; | |
} | |
default: | |
+ return Action.NULL; | |
+ } | |
+ } else { | |
+ switch (firstChar) { | |
+ case 'c': | |
+ if (line.equals("collect items")) { | |
+ return Action.COLLECT; | |
+ } | |
+ return Action.NULL; | |
+ case 'd': | |
+ if (line.equals("deposit items")) { | |
+ return Action.DEPOSIT; | |
+ } | |
+ return Action.NULL; | |
+ case 'a': | |
+ if (line.equals("all items")) { | |
+ return Action.ALL; | |
+ } | |
+ return Action.NULL; | |
+ default: | |
+ return Action.NULL; | |
} | |
- } | |
- | |
- | |
- switch (line.charAt(0)) { | |
- case 'c': | |
- if (line.equals("collect items")) { | |
- return Action.COLLECT; | |
- } | |
- return Action.NULL; | |
- case 'd': | |
- if (line.equals("deposit items")) { | |
- return Action.DEPOSIT; | |
- } | |
- return Action.NULL; | |
- case 'a': | |
- if (line.equals("all items")) { | |
- return Action.ALL; | |
- } | |
- return Action.NULL; | |
- default: | |
- return Action.NULL; | |
} | |
} else { | |
return Action.NULL; | |
@@ -96,10 +87,14 @@ public class SignParser { | |
public static IntMap buildIntMap(String line) { | |
IntMap map = new IntMap(); | |
boolean isNegate = false; | |
- | |
if (line.length() >= 2 && line.charAt(1) == '+') { | |
+ //TODO Eigenlijk is dit niet net, gezien we deze opvraag net ook al gedaan hebben | |
+ map.setDirection(getDirection(line.charAt(0))); | |
line = line.substring(2); | |
} | |
+ else{ | |
+ map.setDirection(Direction.SELF); | |
+ } | |
if (line.charAt(0) == '!') { | |
isNegate = true; | |
line = line.substring(1); | |
@@ -110,24 +105,23 @@ public class SignParser { | |
for (String command : commands) { | |
int value = 0; | |
- String[] splitline = command.split("@"); | |
+ String[] splitLine = command.split("@"); | |
- if (splitline.length == 2) { | |
+ if (splitLine.length == 2) { | |
try { | |
- value = Integer.parseInt(splitline[1]); | |
+ value = Integer.parseInt(splitLine[1]); | |
value = (value < 1 ? Integer.MAX_VALUE : value); | |
- command = splitline[0]; | |
+ command = splitLine[0]; | |
} catch (NumberFormatException e) { | |
return null; | |
} | |
- } else if (splitline.length != 1) { | |
+ } else if (splitLine.length != 1) { | |
return null; | |
} | |
- | |
- splitline = command.split("-"); | |
- if (splitline.length == 2) { | |
- int[] startPair = checkIDData(splitline[0]); | |
- int[] endPair = checkIDData(splitline[1]); | |
+ splitLine = command.split("-"); | |
+ if (splitLine.length == 2) { | |
+ int[] startPair = checkIdData(splitLine[0]); | |
+ int[] endPair = checkIdData(splitLine[1]); | |
if (startPair != null && endPair != null) { | |
if (value == 0) { | |
if (isNegate) { | |
@@ -140,8 +134,8 @@ public class SignParser { | |
} else { | |
return null; | |
} | |
- } else if (splitline.length == 1) { | |
- int[] pair = checkIDData(splitline[0]); | |
+ } else if (splitLine.length == 1) { | |
+ int[] pair = checkIdData(splitLine[0]); | |
if (pair != null) { | |
if (value == 0) { | |
if (isNegate) { | |
@@ -149,41 +143,33 @@ public class SignParser { | |
} else { | |
value = Integer.MAX_VALUE; | |
} | |
- | |
} | |
map.setInt(pair[0], (byte) (pair[1] & 0xff), value); | |
} else { | |
- //Ah er is dus iets mis gegaan bij het parsen | |
return null; | |
} | |
- | |
} else { | |
- //De gebruiker heeft meerdere '-' tekens aangegeven, en dat kan niet | |
return null; | |
} | |
- | |
- | |
} | |
return map; | |
} | |
- private static int[] checkIDData(String line) { | |
+ private static int[] checkIdData(String line) { | |
int[] result = new int[2]; | |
- String[] linesplit = line.split(";"); | |
- if (linesplit.length == 2) { | |
+ String[] splitLine = line.split(";"); | |
+ if (splitLine.length == 2) { | |
try { | |
- result[0] = Integer.parseInt(linesplit[0]); | |
- result[1] = Integer.parseInt(linesplit[1]); | |
+ result[0] = Integer.parseInt(splitLine[0]); | |
+ result[1] = Integer.parseInt(splitLine[1]); | |
} catch (NumberFormatException e) { | |
- | |
} | |
- } else if (linesplit.length == 1) { | |
+ } else if (splitLine.length == 1) { | |
try { | |
- result[0] = Integer.parseInt(linesplit[0]); | |
+ result[0] = Integer.parseInt(splitLine[0]); | |
result[1] = -1; | |
} catch (NumberFormatException e) { | |
- | |
} | |
} | |
@@ -191,115 +177,186 @@ public class SignParser { | |
} | |
- private static boolean checkDirection(String line, Direction d) { | |
- if (line.length() >= 2 && line.charAt(1) == '+') { | |
- char c = line.charAt(0); | |
- switch (c) { | |
- case 'n': | |
- if (d != Direction.NORTH) { | |
- return false; | |
- } | |
- break; | |
- case 's': | |
- if (d != Direction.SOUTH) { | |
- return false; | |
+ private static boolean checkDirection(char c, Direction d) { | |
+ return (getDirection(c) == d || getDirection(c) == Direction.SELF); //Yay, 10 keer zo kort ofzo :) | |
+ } | |
+ | |
+ /** | |
+ * TODO: implement this function. It automatically teleports the cart to the correct location and in the correct direction (this is why cart is an argument). | |
+ */ | |
+ public static boolean parseRouteSign(Sign sign, Direction direction, Minecart cart) { | |
+ //BASIC syntax: [Direction from <N,S,E,W>];[Type of cart <S,M,P>],[Full/Empty <F,E>];[Direction to go <N,S,E,W>] | |
+ //Example: S,F;N: makes storagecarts that are full go north :) | |
+ String[] lines = sign.getLines(); | |
+ | |
+ for(int i = 0; i < lines.length; i++){ | |
+ String line = lines[i]; | |
+ Minecart type; | |
+ | |
+ String[] temp = line.split(":"); | |
+ for(String partline: temp){ | |
+ String[] directionalparts = partline.split(";"); | |
+ if(directionalparts.length == 3){ | |
+ //deel 1 is een direction | |
+ Direction from = getDirection(directionalparts[0].toLowerCase().charAt(0)); | |
+ if(from != direction && direction != Direction.SELF){ | |
+ continue; | |
} | |
- break; | |
- case 'e': | |
- if (d != Direction.EAST) { | |
- return false; | |
+ Direction to = getDirection(directionalparts[2].toLowerCase().charAt(0)); | |
+ String[] cartTypeFullness = directionalparts[1].split(";"); | |
+ if(cartTypeFullness.length == 2 && checkCartType(cartTypeFullness[0], cart)){ | |
+ boolean fullcart = getFull(cartTypeFullness[1].toLowerCase().charAt(0)); | |
+ if(cart instanceof StorageMinecart){ | |
+ StorageMinecart storecart = (StorageMinecart) cart; | |
+ if(storecart.isEmpty() == !fullcart){ | |
+ //oke moven dan maar ;) | |
+ } | |
+ }else if(cart instanceof PoweredMinecart){ | |
+ PoweredMinecart powcart = (PoweredMinecart) cart; | |
+ if(powcart.isEmpty() == !fullcart){ | |
+ //ook maar moven | |
+ } | |
+ }else{ | |
+ if(cart.isEmpty() == !fullcart){ | |
+ //whatever :) | |
+ } | |
+ } | |
} | |
- break; | |
- case 'w': | |
- if (d != Direction.WEST) { | |
- return false; | |
+ else{ | |
+ continue; | |
} | |
- break; | |
+ | |
+ }else if(directionalparts.length == 2){ | |
+ Direction to = getDirection(directionalparts[1].toLowerCase().charAt(0)); | |
+ String[] cartTypeFullness = directionalparts[1].split(";"); | |
+ }else{ | |
+ //User fail | |
+ } | |
+ | |
} | |
- | |
} | |
- return true; | |
+ | |
+ return false; | |
+ } | |
+ | |
+ /** | |
+ * Langste methode EVURR! | |
+ * @param c | |
+ * @return | |
+ */ | |
+ private static boolean getFull(char c) { | |
+ return c == 'f'; | |
+ } | |
+ private static boolean checkCartType(String type, Minecart cart) { | |
+ char carttypechar = type.toLowerCase().charAt(0); | |
+ switch(carttypechar){ | |
+ case 's': | |
+ if(cart instanceof StorageMinecart) return true; | |
+ break; | |
+ case 'p': | |
+ if(cart instanceof PoweredMinecart) return true; | |
+ break; | |
+ case 'm': | |
+ if(cart instanceof Minecart) return true; | |
+ break; | |
+ } | |
+ return false; | |
} | |
- public static HashMap<Action, IntMap> parseSign(Sign sign, Direction direction) { | |
+ private static Direction getDirection(char c){ | |
+ switch(c){ | |
+ case 'n': | |
+ return Direction.NORTH; | |
+ case 's': | |
+ return Direction.SOUTH; | |
+ case 'e': | |
+ return Direction.EAST; | |
+ case 'w': | |
+ return Direction.WEST; | |
+ default: | |
+ return Direction.SELF; | |
+ } | |
+ } | |
+ | |
+ | |
+ public static List<IntMap> parseItemSign(Sign sign, Direction direction) { | |
Action oldAction = Action.NULL; | |
- HashMap<Action, IntMap> returnData = new HashMap<Action, IntMap>(); | |
+ List<IntMap> returndata = new ArrayList<IntMap>(); | |
IntMap map; | |
- | |
for (String line : sign.getLines()) { | |
line = removeBrackets(line); | |
- Action newAction = SignParser.parseAction(line); | |
+ line = line.toLowerCase(); | |
+ Action newAction = SignParser.parseAction(line, direction); | |
if (newAction == Action.NULL) { | |
continue; | |
} else if (newAction != Action.ITEM && newAction != Action.ALL) { | |
oldAction = newAction; | |
continue; | |
} else if (oldAction != Action.NULL) { | |
- if (checkDirection(line, direction)) { | |
- switch (oldAction) { | |
- case DEPOSIT: | |
- case COLLECT: | |
- switch (newAction) { | |
- case ALL: | |
- if (returnData.containsKey(oldAction)) { | |
- map = returnData.get(oldAction); | |
- map.fillAll(); | |
- returnData.put(oldAction, map); | |
- } else { | |
- map = new IntMap(); | |
- map.fillAll(); | |
- returnData.put(oldAction, map); | |
+ switch (oldAction) { | |
+ case DEPOSIT: | |
+ case COLLECT: | |
+ switch (newAction) { | |
+ case ALL: | |
+ IntMap tempmap = null; | |
+ int maplocation = -1; | |
+ boolean running = true; | |
+ for(int i = 0; i < returndata.size() && running; i++){ | |
+ IntMap nextmap = returndata.get(i); | |
+ if(nextmap.getAction().equals(oldAction)){ | |
+ tempmap = nextmap; | |
+ maplocation = i; | |
+ running = false; | |
} | |
- break; | |
- case ITEM: | |
- IntMap parsed = buildIntMap(line); | |
- | |
- if (parsed != null) { | |
- // Mooi het is gelukt! Maps combinen dan maar! | |
- if (returnData.containsKey(oldAction)) { | |
- map = returnData.get(oldAction); | |
- map.combine(parsed); | |
- returnData.put(oldAction, map); | |
- } else { | |
- if (parsed != null) | |
- returnData.put(oldAction, parsed); | |
+ } | |
+ if (tempmap != null) { | |
+ map = tempmap; | |
+ map.fillAll(); | |
+ map.setAction(oldAction); | |
+ returndata.set(maplocation, map); | |
+ } else { | |
+ map = new IntMap(); | |
+ map.fillAll(); | |
+ map.setAction(oldAction); | |
+ returndata.add(map); | |
+ } | |
+ break; | |
+ case ITEM: | |
+ IntMap parsed = buildIntMap(line); | |
+ if (parsed != null) { | |
+ //OEEEH, daar gebruikte ik control v, dat moet toch netter kunen :) | |
+ IntMap tempmap2 = null; | |
+ int maplocation2 = -1; | |
+ boolean running2 = true; | |
+ for(int i = 0; i < returndata.size() && running2; i++){ | |
+ IntMap nextmap = returndata.get(i); | |
+ if(nextmap.getAction().equals(oldAction)){ | |
+ tempmap2 = nextmap; | |
+ maplocation2 = i; | |
+ running2 = false; | |
} | |
} | |
- break; | |
- default: | |
- //WTH? | |
- break; | |
- } | |
- break; | |
- //case ELEVATE? | |
- default: | |
- //Weird stuff is going on! | |
- break; | |
- } | |
- } else { | |
- continue; | |
+ | |
+ | |
+ if (tempmap2 != null) { | |
+ map = tempmap2; | |
+ map.combine(parsed); | |
+ map.setAction(oldAction); | |
+ returndata.set(maplocation2, map); | |
+ } else { | |
+ parsed.setAction(oldAction); | |
+ returndata.add(parsed); | |
+ } | |
+ } | |
+ break; | |
+ } | |
+ break; | |
} | |
- } else { | |
- //Oldaction == Null and newAction is Item, so don't do anything. | |
- continue; | |
} | |
} | |
- | |
- //Yay, we hebben een IntMap | |
- //For simplicity sake, gaan we er vanuit dat het of collect of deposit is, oke :) | |
- | |
- return returnData; | |
- } | |
- | |
- | |
- public static boolean checkStorageCart(Minecart cart) { | |
- return (cart instanceof StorageMinecart); | |
- } | |
- | |
- public static boolean checkCart(Minecart cart) { | |
- return !((cart instanceof StorageMinecart) || (cart instanceof PoweredMinecart)); | |
+ return returndata; | |
} | |
} | |
\ No newline at end of file | |
diff --git a/src/com/tweakcart/test/IntMapTest.java b/src/com/tweakcart/test/IntMapTest.java | |
deleted file mode 100644 | |
index 0558574..0000000 | |
--- a/src/com/tweakcart/test/IntMapTest.java | |
+++ /dev/null | |
@@ -1,269 +0,0 @@ | |
-package com.tweakcart.test; | |
- | |
-import org.bukkit.Material; | |
-import org.bukkit.material.MaterialData; | |
- | |
-import com.tweakcart.model.Direction; | |
-import com.tweakcart.model.IntMap; | |
-import com.tweakcart.model.SignParser; | |
- | |
-public class IntMapTest { | |
- public static void main(String[] args){ | |
-// System.out.println(IntMap.getIntIndex(0, (byte) 0)); | |
-// System.out.println(IntMap.getIntIndex(1, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(2, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(3, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(4, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(5, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(6, (byte)0));//sapling | |
-// System.out.println(IntMap.getIntIndex(6, (byte)1));//sapling | |
-// System.out.println(IntMap.getIntIndex(6, (byte)2));//sapling | |
-// System.out.println(IntMap.getIntIndex(7, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(8, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(9, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(10, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(11, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(12, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(13, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(14, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(15, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(16, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(17, (byte)0));//wood | |
-// System.out.println(IntMap.getIntIndex(17, (byte)1));//wood | |
-// System.out.println(IntMap.getIntIndex(17, (byte)2));//wood | |
-// System.out.println(IntMap.getIntIndex(18, (byte)0));//leaves | |
-// System.out.println(IntMap.getIntIndex(18, (byte)1));//leaves | |
-// System.out.println(IntMap.getIntIndex(18, (byte)2));//leaves | |
-// System.out.println(IntMap.getIntIndex(19, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(20, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(21, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(22, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(23, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(24, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(25, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(26, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(27, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(28, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(29, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(30, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(31, (byte)0));//tallgrass | |
-// System.out.println(IntMap.getIntIndex(32, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(33, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(34, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(35, (byte)0));//wool | |
-// System.out.println(IntMap.getIntIndex(35, (byte)1));//wool | |
-// System.out.println(IntMap.getIntIndex(35, (byte)2));//wool | |
-// System.out.println(IntMap.getIntIndex(35, (byte)3));//wool | |
-// System.out.println(IntMap.getIntIndex(35, (byte)4));//wool | |
-// System.out.println(IntMap.getIntIndex(35, (byte)5));//wool | |
-// System.out.println(IntMap.getIntIndex(35, (byte)6));//wool | |
-// System.out.println(IntMap.getIntIndex(35, (byte)7));//wool | |
-// System.out.println(IntMap.getIntIndex(35, (byte)8));//wool | |
-// System.out.println(IntMap.getIntIndex(35, (byte)9));//wool | |
-// System.out.println(IntMap.getIntIndex(35, (byte)10));//wool | |
-// System.out.println(IntMap.getIntIndex(35, (byte)11));//wool | |
-// System.out.println(IntMap.getIntIndex(35, (byte)12));//wool | |
-// System.out.println(IntMap.getIntIndex(35, (byte)13));//wool | |
-// System.out.println(IntMap.getIntIndex(35, (byte)14));//wool | |
-// System.out.println(IntMap.getIntIndex(35, (byte)15));//wool | |
-// System.out.println(IntMap.getIntIndex(36, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(37, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(38, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(39, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(40, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(41, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(42, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(43, (byte)0));//doubleslabs, only inventory edit | |
- System.out.println("STEPS"); | |
- System.out.println(IntMap.getIntIndex(44, (byte)0));//slabs <----- DIT IS SOWIESO FOUT | |
- System.out.println(IntMap.getIntIndex(44, (byte)1));//slabs <----- DIT IS SOWIESO FOUT | |
- System.out.println(IntMap.getIntIndex(44, (byte)2));//slabs <----- DIT IS SOWIESO FOUT | |
- System.out.println(IntMap.getIntIndex(44, (byte)3));//slabs <----- DIT IS SOWIESO FOUT | |
- System.out.println(IntMap.getIntIndex(44, (byte)4));//slabs <----- DIT IS SOWIESO FOUT | |
- System.out.println(IntMap.getIntIndex(44, (byte)5));//slabs <----- DIT IS SOWIESO FOUT | |
- System.out.println(IntMap.getIntIndex(44, (byte)6));//slabs <----- DIT IS SOWIESO FOUT | |
-// System.out.println(IntMap.getIntIndex(45, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(46, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(47, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(48, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(49, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(50, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(51, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(52, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(53, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(54, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(55, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(56, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(57, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(58, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(59, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(60, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(61, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(62, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(63, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(64, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(65, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(66, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(67, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(68, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(69, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(70, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(71, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(72, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(73, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(74, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(75, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(76, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(77, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(78, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(79, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(80, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(81, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(82, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(83, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(84, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(85, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(86, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(87, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(88, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(89, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(90, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(91, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(92, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(93, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(94, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(95, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(96, (byte)0)); //==Eind van Alle blockid's== | |
-// | |
-// System.out.println(IntMap.getIntIndex(256, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(257, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(258, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(259, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(260, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(261, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(262, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(263, (byte)0));//coal | |
-// System.out.println("coal incoming"); | |
-// System.out.println(IntMap.getIntIndex(263, (byte)1));//coal | |
-// System.out.println(IntMap.getIntIndex(264, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(265, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(266, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(267, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(268, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(269, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(270, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(271, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(272, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(273, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(274, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(275, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(276, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(277, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(278, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(279, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(280, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(281, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(282, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(283, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(284, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(285, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(286, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(287, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(288, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(289, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(290, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(291, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(292, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(293, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(294, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(295, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(296, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(297, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(298, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(299, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(300, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(301, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(302, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(303, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(304, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(305, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(306, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(307, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(308, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(309, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(310, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(311, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(312, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(313, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(314, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(315, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(316, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(317, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(318, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(319, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(320, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(321, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(322, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(323, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(324, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(325, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(326, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(327, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(328, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(329, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(330, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(331, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(332, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(333, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(334, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(335, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(336, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(337, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(338, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(339, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(340, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(341, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(342, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(343, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(344, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(345, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(346, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(347, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(348, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(349, (byte)0)); | |
-// System.out.println(IntMap.getIntIndex(350, (byte)0)); | |
-// System.out.println("==Wol=="); | |
-// System.out.println(IntMap.getIntIndex(351, (byte)0)); //WOL | |
-// System.out.println(IntMap.getIntIndex(351, (byte)1)); //WOL | |
-// System.out.println(IntMap.getIntIndex(351, (byte)2)); //WOL | |
-// System.out.println(IntMap.getIntIndex(351, (byte)3)); //WOL | |
-// System.out.println(IntMap.getIntIndex(351, (byte)4)); //WOL | |
-// System.out.println(IntMap.getIntIndex(351, (byte)5)); //WOL | |
-// System.out.println(IntMap.getIntIndex(351, (byte)6)); //WOL | |
-// System.out.println(IntMap.getIntIndex(351, (byte)7)); //WOL | |
-// System.out.println(IntMap.getIntIndex(351, (byte)8)); //WOL | |
-// System.out.println(IntMap.getIntIndex(351, (byte)9)); //WOL | |
-// System.out.println(IntMap.getIntIndex(351, (byte)10)); //WOL | |
-// System.out.println(IntMap.getIntIndex(351, (byte)11)); //WOL | |
-// System.out.println(IntMap.getIntIndex(351, (byte)12)); //WOL | |
-// System.out.println(IntMap.getIntIndex(351, (byte)13)); //WOL | |
-// System.out.println(IntMap.getIntIndex(351, (byte)14)); //WOL | |
-// System.out.println(IntMap.getIntIndex(351, (byte)15)); //WOL | |
-// System.out.println(IntMap.getIntIndex(352, (byte) 0)); | |
-// System.out.println(IntMap.getIntIndex(353, (byte) 0)); | |
-// System.out.println(IntMap.getIntIndex(354, (byte) 0)); | |
-// System.out.println(IntMap.getIntIndex(355, (byte) 0)); | |
-// System.out.println(IntMap.getIntIndex(356, (byte) 0)); | |
-// System.out.println(IntMap.getIntIndex(357, (byte) 0)); | |
-// System.out.println(IntMap.getIntIndex(358, (byte) 0)); | |
-// System.out.println(IntMap.getIntIndex(359, (byte) 0)); | |
-// System.out.println(IntMap.getIntIndex(2256, (byte) 0)); | |
-// System.out.println(IntMap.getIntIndex(3333, (byte) 0)); | |
- | |
- System.out.println("Material Size: " + Material.values().length + " Total: " + (Material.values().length + 54)); | |
- System.out.println("IntMap reporting size: " + IntMap.mapSize); | |
- System.out.println("Wol data 4: " + new MaterialData(351, (byte)4)); | |
- | |
- System.out.println(SignParser.buildIntMap("44,0")); | |
- } | |
-} | |
diff --git a/src/com/tweakcart/test/testwriter.java b/src/com/tweakcart/test/testwriter.java | |
deleted file mode 100644 | |
index 0c82ce7..0000000 | |
--- a/src/com/tweakcart/test/testwriter.java | |
+++ /dev/null | |
@@ -1,11 +0,0 @@ | |
-package com.tweakcart.test; | |
- | |
- | |
-public class testwriter { | |
- public static void main(String[] args){ | |
- for(int i=352; i<359; i++){ | |
- System.out.println("System.out.println(IntMap.getIntIndex(" + i + ", (byte) 0));" ); | |
- } | |
- | |
- } | |
-} | |
diff --git a/src/com/tweakcart/util/CartUtil.java b/src/com/tweakcart/util/CartUtil.java | |
index 50ab19f..34ee1c3 100644 | |
--- a/src/com/tweakcart/util/CartUtil.java | |
+++ b/src/com/tweakcart/util/CartUtil.java | |
@@ -1,32 +1,27 @@ | |
package com.tweakcart.util; | |
import com.tweakcart.model.Direction; | |
- | |
-import org.bukkit.Bukkit; | |
import org.bukkit.block.Block; | |
-import org.bukkit.entity.Minecart; | |
+import org.bukkit.entity.StorageMinecart; | |
import org.bukkit.util.Vector; | |
- | |
/** | |
* Created by IntelliJ IDEA. | |
- * User: Edoxile | |
+ * | |
+ * @author Edoxile, Meaglin | |
*/ | |
public class CartUtil { | |
- /* | |
- * The minimal speed needed for a cart to be able to reach the next block. | |
- */ | |
+ /** | |
+ * The minimal speed needed for a cart to be able to reach the next block. | |
+ */ | |
private static final double min_movement = 0.04d; | |
/** | |
- * Checks whereather the cart is moving at a very small pace | |
- * and needs to be stopped to prevent unnececary server load. | |
- * | |
- * @param cart | |
- * @return true if the cart was stopped, false if nothing was changed. | |
+ * Checks whether the cart is moving at a very small pace | |
+ * and needs to be stopped to prevent unnecessary server load. | |
*/ | |
- public static final boolean stoppedSlowCart(Minecart cart, Vector velocity, Block to, Direction horizontalDirection) { | |
+ public static final boolean stoppedSlowCart(StorageMinecart cart, Vector velocity, Block to, Direction horizontalDirection) { | |
switch (Direction.getVerticalDirection(to, horizontalDirection)) { | |
case DOWN: | |
case UP: | |
diff --git a/src/com/tweakcart/util/ChestUtil.java b/src/com/tweakcart/util/ChestUtil.java | |
index 21abc13..26c5edf 100644 | |
--- a/src/com/tweakcart/util/ChestUtil.java | |
+++ b/src/com/tweakcart/util/ChestUtil.java | |
@@ -1,7 +1,6 @@ | |
package com.tweakcart.util; | |
import com.tweakcart.model.IntMap; | |
- | |
import org.bukkit.Material; | |
import org.bukkit.block.Block; | |
import org.bukkit.block.Chest; | |
@@ -18,7 +17,7 @@ import java.util.List; | |
* @author Edoxile | |
*/ | |
public class ChestUtil { | |
- public static final ItemStack[] putItems(ItemStack[] from, ContainerBlock containerBlock) { | |
+ public static ItemStack[] putItems(ItemStack[] from, ContainerBlock containerBlock) { | |
ItemStack[] to = containerBlock.getInventory().getContents(); | |
for (int i1 = 0; i1 < from.length; i1++) { | |
if (from[i1] == null) | |
@@ -33,7 +32,6 @@ public class ChestUtil { | |
from[i1].setAmount((to[i2].getAmount() + from[i1].getAmount()) - 64); | |
to[i2].setAmount(64); | |
i1--; | |
- | |
} else { | |
to[i2].setAmount(to[i2].getAmount() + from[i1].getAmount()); | |
from[i1] = null; | |
@@ -51,146 +49,56 @@ public class ChestUtil { | |
ItemStack[] stacks = {from}; | |
return putItems(stacks, containerBlock); | |
} | |
- | |
- public static IntMap moveItems(Inventory iFrom, Inventory iTo, IntMap settings) { | |
+ | |
+ public static boolean moveItems(Inventory iFrom, Inventory iTo, IntMap through, boolean toChest) { | |
+ int slots = 0; | |
ItemStack[] from = iFrom.getContents(); | |
ItemStack[] to = iTo.getContents(); | |
- main:for(int index = 0; index < from.length; index++ ) { | |
- if(from[index] == null) continue; | |
- byte data = from[index].getDurability() > Byte.MAX_VALUE ? 0 : IntMap.isAllowedMaterial(from[index].getTypeId(), (byte) from[index].getDurability()) ? (byte) from[index].getDurability() : 0; | |
- | |
- ItemStack itemFrom = from[index]; | |
- int typeid = itemFrom.getTypeId(); | |
- if(settings.getInt(typeid, data) <= 0) continue; | |
- //System.out.println("[0]f: (" + typeid + ")" + itemFrom.getAmount() + " d:" + data); | |
- /* | |
- * First we try to append an existing stack. | |
- */ | |
- for(int indexto = 0; indexto < to.length; indexto++ ) { | |
- if(itemFrom.getAmount() <= 0) break; | |
- ItemStack itemTo = to[indexto]; | |
- if(itemTo == null) continue; | |
- if(itemTo.getAmount() == 0) { | |
- to[indexto] = null; | |
- continue; | |
- } | |
- if(itemTo.getTypeId() != typeid || itemTo.getDurability() != itemFrom.getDurability()) continue; | |
- if(itemTo.getAmount() >= 64) continue; | |
- | |
- int maxamount = settings.getInt(typeid, data); | |
- if(maxamount <= 0) continue main; | |
- | |
- int stackspace = 64 - itemTo.getAmount(); | |
- int moveamount = (itemFrom.getAmount() >= stackspace && maxamount >= stackspace ? stackspace : | |
- itemFrom.getAmount() < stackspace && maxamount >= stackspace ? itemFrom.getAmount() : | |
- maxamount < stackspace && itemFrom.getAmount() >= stackspace ? maxamount : | |
- maxamount > itemFrom.getAmount() ? itemFrom.getAmount() : maxamount); | |
- //System.out.println("[1]f: (" + itemFrom.getTypeId() + ")" + itemFrom.getAmount() + " t: (" + itemTo.getTypeId() + ")" + itemTo.getAmount() + " d:" + data + " m:" + maxamount + " mv:" + moveamount); | |
- itemFrom.setAmount(itemFrom.getAmount() - moveamount); | |
- itemTo.setAmount(itemTo.getAmount() + moveamount); | |
- if(maxamount != Integer.MAX_VALUE) { | |
- settings.setInt(typeid, data, maxamount-moveamount); | |
- } | |
- //System.out.println("[1]f: (" + itemFrom.getTypeId() + ")" + itemFrom.getAmount() + " t: (" + itemTo.getTypeId() + ")" + itemTo.getAmount() + " d:" + data + " m:" + settings.getInt(itemFrom.getTypeId(), data) + " mv:" + moveamount); | |
+ int i1, i2; | |
+ for (i1 = 0; i1 < from.length; i1++) { | |
+ if (from[i1] == null) { | |
+ if (!toChest) | |
+ slots++; | |
+ continue; | |
} | |
- | |
- if(itemFrom.getAmount() <= 0) { | |
- from[index] = null; | |
- itemFrom.setAmount(0); | |
+ int mapAmount = through.getInt(from[i1].getType(), (byte) from[i1].getDurability()); | |
+ int startAmount = from[i1].getAmount(); | |
+ if (mapAmount == 0 || mapAmount == Integer.MIN_VALUE) { | |
continue; | |
} | |
- /* | |
- * Put item in an empty slot | |
- */ | |
- for(int indexto = 0; indexto < to.length; indexto++ ) { | |
- if(to[indexto] != null) continue; | |
- int maxamount = settings.getInt(typeid, data); | |
- if(maxamount <= 0) break; //FIX, PROFIT | |
- if(itemFrom.getAmount() > maxamount) { | |
- //System.out.println("[2]f: (" + itemFrom.getTypeId() + ")" + itemFrom.getAmount() + " m:" + maxamount + " d:" + data); | |
- itemFrom.setAmount(itemFrom.getAmount() - maxamount); | |
- to[indexto] = new ItemStack(typeid, maxamount, data); | |
- settings.setInt(typeid, data, 0); | |
- //System.out.println("[2]f: (" + itemFrom.getTypeId() + ")" + itemFrom.getAmount() + " m:" + settings.getInt(itemFrom.getTypeId(), data) + " d:" + data); | |
- break; // We can't put more of this item type so we skip to the next item. | |
- } else { | |
- //System.out.println("[3]f: (" + itemFrom.getTypeId() + ")" + itemFrom.getAmount() + " m:" + maxamount + " d:" + data); | |
- to[indexto] = itemFrom; | |
- from[index] = null; | |
- if(maxamount != Integer.MAX_VALUE){ | |
- maxamount -= itemFrom.getAmount(); | |
- settings.setInt(typeid, data, maxamount); | |
+ | |
+ int amountToMove = (mapAmount == Integer.MAX_VALUE ? startAmount : mapAmount); | |
+ from[i1].setAmount(from[i1].getAmount() - amountToMove + 1); | |
+ for (i2 = 0; i2 < to.length; i2++) { | |
+ if (to[i2] == null) { | |
+ to[i2] = from[i1].clone(); | |
+ to[i2].setAmount(amountToMove); | |
+ amountToMove = 0; | |
+ if (!toChest || to[i2].getAmount() == 64) | |
+ slots++; | |
+ break; | |
+ } else if (to[i2].getTypeId() == from[i1].getTypeId() && to[i2].getDurability() == from[i1].getDurability() && to[i2].getAmount() < 64) { | |
+ if (amountToMove + to[i2].getAmount() > 64) { | |
+ amountToMove += to[i2].getAmount() - 64; | |
+ to[i2].setAmount(64); | |
+ if (toChest) | |
+ slots++; | |
+ } else { | |
+ to[i2].setAmount(amountToMove + to[i2].getAmount()); | |
+ amountToMove = 0; | |
} | |
- //System.out.println("[3]f: (" + itemFrom.getTypeId() + ")" + itemFrom.getAmount() + " m:" + settings.getInt(itemFrom.getTypeId(), data) + " d:" + data); | |
break; | |
} | |
} | |
+ from[i1].setAmount(from[i1].getAmount() + amountToMove - 1); | |
+ if (!toChest && from[i1] == null || from[i1].getAmount() == 0 || from[i1].getTypeId() == Material.AIR.getId()) | |
+ slots++; | |
+ through.setInt(from[i1].getType(), (byte) from[i1].getDurability(), amountToMove); | |
} | |
- iFrom.setContents(from); | |
iTo.setContents(to); | |
- return settings; | |
+ iFrom.setContents(from); | |
+ return (toChest ? slots == to.length : slots == from.length); | |
} | |
-// public static void moveItems(Inventory iFrom, Inventory iTo, IntMap through) { | |
-// ItemStack[] from = iFrom.getContents(); | |
-// ItemStack[] to = iTo.getContents(); | |
-// int i1, i2; | |
-// for (i1 = 0; i1 < from.length; i1++) { | |
-// if (from[i1] == null) { | |
-// //Dat betekent dus dat er geen item in dat slot zit :) | |
-// continue; | |
-// } | |
-// int mapAmount = through.getInt(from[i1].getType(), (byte) from[i1].getDurability()); | |
-// mapAmount = (mapAmount > 64 && mapAmount < Integer.MAX_VALUE)? 64 : mapAmount; //64 stacksizes :) | |
-// int startAmount = from[i1].getAmount(); //De hoeveelheid die in de cart of chest zit | |
-// if (mapAmount == 0 || mapAmount == Integer.MIN_VALUE) { | |
-// continue; | |
-// } | |
-// | |
-// int amountToMove = (mapAmount == Integer.MAX_VALUE ? startAmount : mapAmount); //de hoeveelheid die te moven is | |
-// from[i1].setAmount(from[i1].getAmount() - amountToMove + 1); | |
-// boolean hasPutSomethingIn = true; | |
-// for (i2 = 0; i2 < to.length; i2++) { | |
-// if (to[i2] == null) { | |
-// to[i2] = from[i1].clone(); | |
-// to[i2].setAmount(amountToMove); | |
-// amountToMove = 0; | |
-// break; | |
-// } else if (to[i2].getTypeId() == from[i1].getTypeId() && to[i2].getDurability() == from[i1].getDurability() && to[i2].getAmount() < 64) { | |
-// if (amountToMove + to[i2].getAmount() > 64) { | |
-// //hier gaat iets mis | |
-// | |
-// amountToMove += to[i2].getAmount() - 64; | |
-// to[i2].setAmount(64); | |
-// | |
-// } else { | |
-// to[i2].setAmount(amountToMove + to[i2].getAmount()); | |
-// amountToMove = 0; | |
-// | |
-// } | |
-// break; | |
-// } | |
-// | |
-// if(i2 == to.length -1){ | |
-// //OEEH, we konden dus niets terug plaatsen | |
-// hasPutSomethingIn = false; | |
-// Bukkit.getServer().broadcastMessage("vol is vol"); | |
-// } | |
-// | |
-// | |
-// } | |
-// int amountToPlaceBack = from[i1].getAmount() + amountToMove - 1; | |
-// Bukkit.getServer().broadcastMessage(ChatColor.AQUA + "" + amountToPlaceBack); | |
-// from[i1].setAmount(amountToPlaceBack); | |
-// //through.setInt(from[i1].getType(), (byte) from[i1].getDurability(), amountToMove); | |
-// //de bovenstaande regel slaat werkelijk waar nergens over | |
-// | |
-// if((amountToPlaceBack) > 0 && hasPutSomethingIn){ | |
-// i1--; | |
-// } | |
-// } | |
-// iTo.setContents(to); | |
-// iFrom.setContents(from); | |
-// } | |
public static List<Chest> getChestsAroundBlock(Block block, int sw) { | |
int nsw = -sw; | |
@@ -198,40 +106,11 @@ public class ChestUtil { | |
for (int dx = nsw; dx <= sw; dx++) { | |
for (int dy = nsw; dy <= sw; dy++) { | |
for (int dz = nsw; dz <= sw; dz++) { | |
- if (block.getRelative(dx, dy, dz).getTypeId() == Material.CHEST.getId()){ | |
+ if (block.getRelative(dx, dy, dz).getTypeId() == Material.CHEST.getId()) | |
chestList.add((Chest) block.getRelative(dx, dy, dz).getState()); | |
- chestList = getChestsAdjacent(chestList, block, dx, dy, dz); | |
- } | |
} | |
} | |
} | |
- | |
- return chestList; | |
- } | |
- | |
- public static List<Chest> getChestsAdjacent(List<Chest> chestList, Block block, int x, int y, int z){ | |
- | |
- if((x == 1 || x == -1) && (z == 1 || z == -1)){ | |
- if(block.getRelative(x+x, y, z).getTypeId() == Material.CHEST.getId()){ | |
- chestList.add((Chest) block.getRelative(x+x, y, z).getState()); | |
- //Bukkit.getServer().broadcastMessage("ik heb een kist gevonden op X: " + x + " Y: " + y + " Z: " + z); | |
- } | |
- else if(block.getRelative(x, y, z+z).getTypeId() == Material.CHEST.getId()){ | |
- chestList.add((Chest) block.getRelative(x, y, z+z).getState()); | |
- //Bukkit.getServer().broadcastMessage("ik heb een kist gevonden op X: " + x + " Y: " + y + " Z: " + z); | |
- } | |
- }else if(x == 1 || x == -1){ | |
- if(block.getRelative(x+x, y, z).getTypeId() == Material.CHEST.getId()){ | |
- chestList.add((Chest) block.getRelative(x+x, y, z).getState()); | |
- //Bukkit.getServer().broadcastMessage("ik heb een kist gevonden op X: " + x + " Y: " + y + " Z: " + z); | |
- } | |
- }else if(z == 1 || z == -1){ | |
- if(block.getRelative(x, y, z+z).getTypeId() == Material.CHEST.getId()){ | |
- chestList.add((Chest) block.getRelative(x, y, z+z).getState()); | |
- //Bukkit.getServer().broadcastMessage("ik heb een kist gevonden op X: " + x + " Y: " + y + " Z: " + z); | |
- } | |
- } | |
- | |
return chestList; | |
} | |
} | |
diff --git a/src/com/tweakcart/util/MathUtil.java b/src/com/tweakcart/util/MathUtil.java | |
index 22df60f..466094d 100644 | |
--- a/src/com/tweakcart/util/MathUtil.java | |
+++ b/src/com/tweakcart/util/MathUtil.java | |
@@ -4,7 +4,7 @@ import org.bukkit.Location; | |
public class MathUtil { | |
- public static final int floor(double d) { | |
+ private static final int floor(double d) { | |
int rt = (int) d; | |
return rt > d ? rt - 1 : rt; | |
} | |
diff --git a/src/com/tweakcart/util/SoftSignMap.java b/src/com/tweakcart/util/SoftSignMap.java | |
deleted file mode 100644 | |
index b45ed8b..0000000 | |
--- a/src/com/tweakcart/util/SoftSignMap.java | |
+++ /dev/null | |
@@ -1,16 +0,0 @@ | |
-package com.tweakcart.util; | |
- | |
-import java.util.concurrent.ConcurrentMap; | |
- | |
-import com.google.common.collect.MapMaker; | |
-import com.tweakcart.model.IntMap; | |
-import com.tweakcart.model.SignLocation; | |
- | |
-public class SoftSignMap{ | |
- ConcurrentMap<SignLocation, IntMap> signmap; | |
- | |
- public SoftSignMap(){ | |
- signmap = new MapMaker().concurrencyLevel(4).softKeys().makeMap(); | |
- } | |
- | |
-} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment