Changed portals to per-world file
Lotsa null checks Better blox.equals
This commit is contained in:
		
							
								
								
									
										10
									
								
								README
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								README
									
									
									
									
									
								
							@@ -13,7 +13,8 @@ Known Issues
 | 
				
			|||||||
=============
 | 
					=============
 | 
				
			||||||
 - Vehicle implementation is nowhere near done.
 | 
					 - Vehicle implementation is nowhere near done.
 | 
				
			||||||
 - Signs aren't always updating, I don't know what's causing this, I think it's a Bukkit thing.
 | 
					 - Signs aren't always updating, I don't know what's causing this, I think it's a Bukkit thing.
 | 
				
			||||||
 - Minecraft bug is causing buttons to look odd, they still work though.
 | 
					 - There are many bugs with portal material not showing properly. This is a bug I can not track down, and have no fix for at the moment.
 | 
				
			||||||
 | 
					 - Multi-world support is VERY BETA. Please don't just say "it doesn't work" I will ignore you.
 | 
				
			||||||
 
 | 
					 
 | 
				
			||||||
=============
 | 
					=============
 | 
				
			||||||
 Permissions
 | 
					 Permissions
 | 
				
			||||||
@@ -75,12 +76,17 @@ portal-create-message - The message when a gate is created
 | 
				
			|||||||
not-owner-message - The message when you aren't allowed to push the gate button
 | 
					not-owner-message - The message when you aren't allowed to push the gate button
 | 
				
			||||||
other-side-blocked-message - The message when the gate you're dialing is open
 | 
					other-side-blocked-message - The message when the gate you're dialing is open
 | 
				
			||||||
teleport-message - The message when you are teleported
 | 
					teleport-message - The message when you are teleported
 | 
				
			||||||
portal-save-location - The file your portal database is saved as
 | 
					portal-folder - The folder your portal databases are saved in
 | 
				
			||||||
gate-folder - The folder containing your .gate files
 | 
					gate-folder - The folder containing your .gate files
 | 
				
			||||||
 
 | 
					 
 | 
				
			||||||
=============
 | 
					=============
 | 
				
			||||||
  Changes
 | 
					  Changes
 | 
				
			||||||
=============
 | 
					=============
 | 
				
			||||||
 | 
					[Version 0.20]
 | 
				
			||||||
 | 
					 - Fixed the bug SIGN_CHANGE exception when using plugins such as Lockette
 | 
				
			||||||
 | 
					[Version 0.19]
 | 
				
			||||||
 | 
					 - Set button facing on new gates, fixes weirdass button glitch
 | 
				
			||||||
 | 
					 - Beginning of very buggy multi-world support
 | 
				
			||||||
[Version 0.18]
 | 
					[Version 0.18]
 | 
				
			||||||
 - Small permissions handling update.
 | 
					 - Small permissions handling update.
 | 
				
			||||||
[Version 0.17]
 | 
					[Version 0.17]
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -121,6 +121,6 @@ public class Blox {
 | 
				
			|||||||
		if (getClass() != obj.getClass()) return false;
 | 
							if (getClass() != obj.getClass()) return false;
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		Blox blox = (Blox) obj;
 | 
							Blox blox = (Blox) obj;
 | 
				
			||||||
		return (x == blox.x) && (y == blox.y) && (z == blox.z) && (world == blox.world); 
 | 
							return (x == blox.x) && (y == blox.y) && (z == blox.z) && (world.getName().equals(blox.world.getName())); 
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -63,7 +63,6 @@ public class Portal {
 | 
				
			|||||||
    private boolean priv = false;
 | 
					    private boolean priv = false;
 | 
				
			||||||
    private World world;
 | 
					    private World world;
 | 
				
			||||||
    private long openTime;
 | 
					    private long openTime;
 | 
				
			||||||
    private boolean loaded = false;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private Portal(Blox topLeft, int modX, int modZ,
 | 
					    private Portal(Blox topLeft, int modX, int modZ,
 | 
				
			||||||
            float rotX, SignPost id, Blox button,
 | 
					            float rotX, SignPost id, Blox button,
 | 
				
			||||||
@@ -114,10 +113,6 @@ public class Portal {
 | 
				
			|||||||
    public boolean isPrivate() {
 | 
					    public boolean isPrivate() {
 | 
				
			||||||
    	return priv;
 | 
					    	return priv;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    public boolean isLoaded() {
 | 
					 | 
				
			||||||
    	return loaded;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public boolean open(boolean force) {
 | 
					    public boolean open(boolean force) {
 | 
				
			||||||
        return open(null, force);
 | 
					        return open(null, force);
 | 
				
			||||||
@@ -254,35 +249,11 @@ public class Portal {
 | 
				
			|||||||
    public Location getExit(Location traveller, Portal origin) {
 | 
					    public Location getExit(Location traveller, Portal origin) {
 | 
				
			||||||
    	Location loc = null;
 | 
					    	Location loc = null;
 | 
				
			||||||
    	// Check if the gate has an exit block
 | 
					    	// Check if the gate has an exit block
 | 
				
			||||||
    	 if (gate.getExit() != null) {
 | 
							if (gate.getExit() != null) {
 | 
				
			||||||
    		 Blox exit = getBlockAt(gate.getExit());
 | 
								Blox exit = getBlockAt(gate.getExit());
 | 
				
			||||||
    		 loc = exit.modRelativeLoc(0D, 0D, 1D, traveller.getYaw(), traveller.getPitch(), modX, 1, modZ);
 | 
								loc = exit.modRelativeLoc(0D, 0D, 1D, traveller.getYaw(), traveller.getPitch(), modX, 1, modZ);
 | 
				
			||||||
    	 } else {
 | 
							} else {
 | 
				
			||||||
	    	// Move the "entrance" to the first portal block up at the current x/z
 | 
					    		Stargate.log.log(Level.WARNING, "[Stargate] Missing destination point in .gate file " + gate.getFilename());
 | 
				
			||||||
	    	// "Exits" seem to only consist of the lowest Y coord
 | 
					 | 
				
			||||||
	    	int bX = traveller.getBlockX();
 | 
					 | 
				
			||||||
	    	int bY = traveller.getBlockY();
 | 
					 | 
				
			||||||
	    	int bZ = traveller.getBlockZ();
 | 
					 | 
				
			||||||
	    	while (traveller.getWorld().getBlockTypeIdAt(bX, bY, bZ) == gate.getPortalBlockOpen())
 | 
					 | 
				
			||||||
	    		bY --;
 | 
					 | 
				
			||||||
	    	bY++;
 | 
					 | 
				
			||||||
	    	// End
 | 
					 | 
				
			||||||
	    	
 | 
					 | 
				
			||||||
	        Blox entrance = new Blox(world, bX, bY, bZ);
 | 
					 | 
				
			||||||
	        HashMap<Blox, Integer> originExits = origin.getExits();
 | 
					 | 
				
			||||||
	        HashMap<Blox, Integer> destExits = this.getExits();
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	        if (originExits.containsKey(entrance)) {
 | 
					 | 
				
			||||||
	            int position = (int)(((float)originExits.get(entrance) / originExits.size()) * destExits.size());
 | 
					 | 
				
			||||||
	            Blox exit = getReverseExits().get(position);
 | 
					 | 
				
			||||||
	            // Workaround for different size gates. Just drop them at the first exit block.
 | 
					 | 
				
			||||||
	            if (exit == null) {
 | 
					 | 
				
			||||||
	            	exit = (Blox)getReverseExits().values().toArray()[0];
 | 
					 | 
				
			||||||
	            }
 | 
					 | 
				
			||||||
	            if (exit != null) {
 | 
					 | 
				
			||||||
	                loc = exit.modRelativeLoc(0D, 0D, 1D, traveller.getYaw(), traveller.getPitch(), modX, 1, modZ);
 | 
					 | 
				
			||||||
	            }
 | 
					 | 
				
			||||||
	        }
 | 
					 | 
				
			||||||
    	}
 | 
					    	}
 | 
				
			||||||
    	if (loc != null) {
 | 
					    	if (loc != null) {
 | 
				
			||||||
            Block block = world.getBlockAt(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
 | 
					            Block block = world.getBlockAt(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
 | 
				
			||||||
@@ -294,8 +265,6 @@ public class Portal {
 | 
				
			|||||||
            loc.setPitch(traveller.getPitch());
 | 
					            loc.setPitch(traveller.getPitch());
 | 
				
			||||||
            return loc;
 | 
					            return loc;
 | 
				
			||||||
    	}
 | 
					    	}
 | 
				
			||||||
 | 
					 | 
				
			||||||
        Stargate.log.log(Level.WARNING, "No position found calculating route from " + this + " to " + origin);
 | 
					 | 
				
			||||||
        return traveller;
 | 
					        return traveller;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -568,7 +537,7 @@ public class Portal {
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        saveAllGates();
 | 
					        saveAllGates(world);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private Blox getBlockAt(int right, int depth) {
 | 
					    private Blox getBlockAt(int right, int depth) {
 | 
				
			||||||
@@ -615,6 +584,7 @@ public class Portal {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public static Portal createPortal(SignPost id, Player player) {
 | 
					    public static Portal createPortal(SignPost id, Player player) {
 | 
				
			||||||
        Block idParent = id.getParent();
 | 
					        Block idParent = id.getParent();
 | 
				
			||||||
 | 
					        if (idParent == null) return null;
 | 
				
			||||||
        if (Gate.getGatesByControlBlock(idParent).length == 0) return null;
 | 
					        if (Gate.getGatesByControlBlock(idParent).length == 0) return null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Blox parent = new Blox(player.getWorld(), idParent.getX(), idParent.getY(), idParent.getZ());
 | 
					        Blox parent = new Blox(player.getWorld(), idParent.getX(), idParent.getY(), idParent.getZ());
 | 
				
			||||||
@@ -642,19 +612,24 @@ public class Portal {
 | 
				
			|||||||
        int modX = 0;
 | 
					        int modX = 0;
 | 
				
			||||||
        int modZ = 0;
 | 
					        int modZ = 0;
 | 
				
			||||||
        float rotX = 0f;
 | 
					        float rotX = 0f;
 | 
				
			||||||
 | 
					        int facing = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (idParent.getX() > id.getBlock().getX()) {
 | 
					        if (idParent.getX() > id.getBlock().getX()) {
 | 
				
			||||||
            modZ -= 1;
 | 
					            modZ -= 1;
 | 
				
			||||||
            rotX = 90f;
 | 
					            rotX = 90f;
 | 
				
			||||||
 | 
					            facing = 2;
 | 
				
			||||||
        } else if (idParent.getX() < id.getBlock().getX()) {
 | 
					        } else if (idParent.getX() < id.getBlock().getX()) {
 | 
				
			||||||
            modZ += 1;
 | 
					            modZ += 1;
 | 
				
			||||||
            rotX = 270f;
 | 
					            rotX = 270f;
 | 
				
			||||||
 | 
					            facing = 1;
 | 
				
			||||||
        } else if (idParent.getZ() > id.getBlock().getZ()) {
 | 
					        } else if (idParent.getZ() > id.getBlock().getZ()) {
 | 
				
			||||||
            modX += 1;
 | 
					            modX += 1;
 | 
				
			||||||
            rotX = 180f;
 | 
					            rotX = 180f;
 | 
				
			||||||
 | 
					            facing = 4;
 | 
				
			||||||
        } else if (idParent.getZ() < id.getBlock().getZ()) {
 | 
					        } else if (idParent.getZ() < id.getBlock().getZ()) {
 | 
				
			||||||
            modX -= 1;
 | 
					            modX -= 1;
 | 
				
			||||||
            rotX = 0f;
 | 
					            rotX = 0f;
 | 
				
			||||||
 | 
					            facing = 3;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Gate[] possibleGates = Gate.getGatesByControlBlock(idParent);
 | 
					        Gate[] possibleGates = Gate.getGatesByControlBlock(idParent);
 | 
				
			||||||
@@ -698,6 +673,7 @@ public class Portal {
 | 
				
			|||||||
        if (!alwaysOn) {
 | 
					        if (!alwaysOn) {
 | 
				
			||||||
        	button = topleft.modRelative(buttonVector.getRight(), buttonVector.getDepth(), buttonVector.getDistance() + 1, modX, 1, modZ);
 | 
					        	button = topleft.modRelative(buttonVector.getRight(), buttonVector.getDepth(), buttonVector.getDistance() + 1, modX, 1, modZ);
 | 
				
			||||||
        	button.setType(BUTTON);
 | 
					        	button.setType(BUTTON);
 | 
				
			||||||
 | 
					        	button.setData(facing);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        portal = new Portal(topleft, modX, modZ, rotX, id, button, destName, name, true, network, gate, player.getName(), hidden, alwaysOn, priv);
 | 
					        portal = new Portal(topleft, modX, modZ, rotX, id, button, destName, name, true, network, gate, player.getName(), hidden, alwaysOn, priv);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -715,7 +691,7 @@ public class Portal {
 | 
				
			|||||||
        		origin.open(true);
 | 
					        		origin.open(true);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        saveAllGates();
 | 
					        saveAllGates(topleft.getWorld());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return portal;
 | 
					        return portal;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -738,13 +714,14 @@ public class Portal {
 | 
				
			|||||||
        return lookupBlocks.get(new Blox(block));
 | 
					        return lookupBlocks.get(new Blox(block));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static void saveAllGates() {
 | 
					    public static void saveAllGates(World world) {
 | 
				
			||||||
        String loc = Stargate.getSaveLocation();
 | 
					        String loc = Stargate.getSaveLocation() + File.separator + world.getName() + ".db";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            BufferedWriter bw = new BufferedWriter(new FileWriter(loc, false));
 | 
					            BufferedWriter bw = new BufferedWriter(new FileWriter(loc, false));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            for (Portal portal : allPortals) {
 | 
					            for (Portal portal : allPortals) {
 | 
				
			||||||
 | 
					            	if (!portal.world.getName().equals(world.getName())) continue;
 | 
				
			||||||
                StringBuilder builder = new StringBuilder();
 | 
					                StringBuilder builder = new StringBuilder();
 | 
				
			||||||
                Blox sign = new Blox(portal.id.getBlock());
 | 
					                Blox sign = new Blox(portal.id.getBlock());
 | 
				
			||||||
                Blox button = portal.button;
 | 
					                Blox button = portal.button;
 | 
				
			||||||
@@ -789,20 +766,25 @@ public class Portal {
 | 
				
			|||||||
            Stargate.log.log(Level.SEVERE, "Exception while writing stargates to " + loc + ": " + e);
 | 
					            Stargate.log.log(Level.SEVERE, "Exception while writing stargates to " + loc + ": " + e);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    public static void loadAllGates(World world) {
 | 
					    public static void clearGates() {
 | 
				
			||||||
        String location = Stargate.getSaveLocation();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        lookupBlocks.clear();
 | 
					        lookupBlocks.clear();
 | 
				
			||||||
        lookupNamesNet.clear();
 | 
					        lookupNamesNet.clear();
 | 
				
			||||||
        lookupEntrances.clear();
 | 
					        lookupEntrances.clear();
 | 
				
			||||||
        allPortals.clear();
 | 
					        allPortals.clear();
 | 
				
			||||||
        allPortalsNet.clear();
 | 
					        allPortalsNet.clear();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (new File(location).exists()) {
 | 
					    public static void loadAllGates(World world) {
 | 
				
			||||||
 | 
					        String location = Stargate.getSaveLocation();
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        File db = new File(location, world.getName() + ".db");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (db.exists()) {
 | 
				
			||||||
        	int l = 0;
 | 
					        	int l = 0;
 | 
				
			||||||
 | 
					        	int portalCount = 0;
 | 
				
			||||||
            try {
 | 
					            try {
 | 
				
			||||||
                Scanner scanner = new Scanner(new File(location));
 | 
					                Scanner scanner = new Scanner(db);
 | 
				
			||||||
                while (scanner.hasNextLine()) {
 | 
					                while (scanner.hasNextLine()) {
 | 
				
			||||||
                	l++;
 | 
					                	l++;
 | 
				
			||||||
                    String line = scanner.nextLine().trim();
 | 
					                    String line = scanner.nextLine().trim();
 | 
				
			||||||
@@ -841,9 +823,10 @@ public class Portal {
 | 
				
			|||||||
                    if (!portal.isVerified() || !portal.checkIntegrity()) {
 | 
					                    if (!portal.isVerified() || !portal.checkIntegrity()) {
 | 
				
			||||||
                            portal.close(true);
 | 
					                            portal.close(true);
 | 
				
			||||||
                            portal.unregister();
 | 
					                            portal.unregister();
 | 
				
			||||||
                            Stargate.log.info("Destroying stargate at " + portal.toString());
 | 
					                            Stargate.log.info("[Stargate] Destroying stargate at " + portal.toString());
 | 
				
			||||||
                    } else {
 | 
					                    } else {
 | 
				
			||||||
                    	portal.drawSign();
 | 
					                    	portal.drawSign();
 | 
				
			||||||
 | 
					                    	portalCount++;
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
@@ -862,11 +845,13 @@ public class Portal {
 | 
				
			|||||||
                		OpenCount++;
 | 
					                		OpenCount++;
 | 
				
			||||||
                	}
 | 
					                	}
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                Stargate.log.info("[Stargate] Loaded " + allPortals.size() + " stargates with " + OpenCount + " set as always-on");
 | 
					                Stargate.log.info("[Stargate] {" + world.getName() + "} Loaded " + portalCount + " stargates with " + OpenCount + " set as always-on");
 | 
				
			||||||
            } catch (Exception e) {
 | 
					            } catch (Exception e) {
 | 
				
			||||||
                Stargate.log.log(Level.SEVERE, "Exception while reading stargates from " + location + ": " + l);
 | 
					                Stargate.log.log(Level.SEVERE, "Exception while reading stargates from " + location + ": " + l);
 | 
				
			||||||
                e.printStackTrace();
 | 
					                e.printStackTrace();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					        	Stargate.log.info("[Stargate] {" + world.getName() + "} No stargates for world ");
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -24,6 +24,7 @@ public class SignPost {
 | 
				
			|||||||
	
 | 
						
 | 
				
			||||||
	public Block getParent() {
 | 
						public Block getParent() {
 | 
				
			||||||
		if (parent == null) findParent();
 | 
							if (parent == null) findParent();
 | 
				
			||||||
 | 
							if (parent == null) return null;
 | 
				
			||||||
		return parent.getBlock();
 | 
							return parent.getBlock();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
@@ -61,8 +62,11 @@ public class SignPost {
 | 
				
			|||||||
	
 | 
						
 | 
				
			||||||
	public void update() {
 | 
						public void update() {
 | 
				
			||||||
		Sign sign = findSign();
 | 
							Sign sign = findSign();
 | 
				
			||||||
		if (sign == null) return;
 | 
							if (sign == null) {
 | 
				
			||||||
		sign.update();
 | 
								Stargate.log.info("[Stargate::SignPost::update] Sign null");
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							sign.update(true);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	private void findParent() {
 | 
						private void findParent() {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,6 +7,7 @@ import java.util.logging.Logger;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import org.bukkit.ChatColor;
 | 
					import org.bukkit.ChatColor;
 | 
				
			||||||
import org.bukkit.Material;
 | 
					import org.bukkit.Material;
 | 
				
			||||||
 | 
					import org.bukkit.World;
 | 
				
			||||||
import org.bukkit.block.Block;
 | 
					import org.bukkit.block.Block;
 | 
				
			||||||
import org.bukkit.block.BlockDamageLevel;
 | 
					import org.bukkit.block.BlockDamageLevel;
 | 
				
			||||||
import org.bukkit.entity.Entity;
 | 
					import org.bukkit.entity.Entity;
 | 
				
			||||||
@@ -54,7 +55,8 @@ public class Stargate extends JavaPlugin {
 | 
				
			|||||||
    public static Logger log;
 | 
					    public static Logger log;
 | 
				
			||||||
    private Configuration config;
 | 
					    private Configuration config;
 | 
				
			||||||
    private PluginManager pm;
 | 
					    private PluginManager pm;
 | 
				
			||||||
    private static String portalFile;
 | 
					    
 | 
				
			||||||
 | 
					    private static String portalFolder;
 | 
				
			||||||
    private static String gateFolder;
 | 
					    private static String gateFolder;
 | 
				
			||||||
    private static String teleMsg = "Teleported";
 | 
					    private static String teleMsg = "Teleported";
 | 
				
			||||||
    private static String regMsg = "Gate Created";
 | 
					    private static String regMsg = "Gate Created";
 | 
				
			||||||
@@ -65,12 +67,14 @@ public class Stargate extends JavaPlugin {
 | 
				
			|||||||
    private static String defNetwork = "central";
 | 
					    private static String defNetwork = "central";
 | 
				
			||||||
    private static int activeLimit = 10;
 | 
					    private static int activeLimit = 10;
 | 
				
			||||||
    private static int openLimit = 10;
 | 
					    private static int openLimit = 10;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    public static ConcurrentLinkedQueue<Portal> openList = new ConcurrentLinkedQueue<Portal>();
 | 
					    public static ConcurrentLinkedQueue<Portal> openList = new ConcurrentLinkedQueue<Portal>();
 | 
				
			||||||
    public static ConcurrentLinkedQueue<Portal> activeList = new ConcurrentLinkedQueue<Portal>();
 | 
					    public static ConcurrentLinkedQueue<Portal> activeList = new ConcurrentLinkedQueue<Portal>();
 | 
				
			||||||
    //private HashMap<Integer, Location> vehicles = new HashMap<Integer, Location>();
 | 
					    //private HashMap<Integer, Location> vehicles = new HashMap<Integer, Location>();
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
    public void onDisable() {
 | 
					    public void onDisable() {
 | 
				
			||||||
    	Portal.closeAllGates();
 | 
					    	Portal.closeAllGates();
 | 
				
			||||||
 | 
					    	Portal.clearGates();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void onEnable() {
 | 
					    public void onEnable() {
 | 
				
			||||||
@@ -80,7 +84,7 @@ public class Stargate extends JavaPlugin {
 | 
				
			|||||||
    	log = Logger.getLogger("Minecraft");
 | 
					    	log = Logger.getLogger("Minecraft");
 | 
				
			||||||
    	
 | 
					    	
 | 
				
			||||||
    	// Set portalFile and gateFolder to the plugin folder as defaults.
 | 
					    	// Set portalFile and gateFolder to the plugin folder as defaults.
 | 
				
			||||||
    	portalFile = getDataFolder() + File.separator + "stargate.db";
 | 
					    	portalFolder = getDataFolder() + File.separator + "portals";
 | 
				
			||||||
    	gateFolder = getDataFolder() + File.separator + "gates" + File.separator;
 | 
					    	gateFolder = getDataFolder() + File.separator + "gates" + File.separator;
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        log.info(pdfFile.getName() + " v." + pdfFile.getVersion() + " is enabled.");
 | 
					        log.info(pdfFile.getName() + " v." + pdfFile.getVersion() + " is enabled.");
 | 
				
			||||||
@@ -91,6 +95,7 @@ public class Stargate extends JavaPlugin {
 | 
				
			|||||||
    	this.reloadConfig();
 | 
					    	this.reloadConfig();
 | 
				
			||||||
    	this.migrate();
 | 
					    	this.migrate();
 | 
				
			||||||
    	this.reloadGates();
 | 
					    	this.reloadGates();
 | 
				
			||||||
 | 
					    	
 | 
				
			||||||
    	if (!this.setupPermissions()) {
 | 
					    	if (!this.setupPermissions()) {
 | 
				
			||||||
    		log.info("[Stargate] Permissions not loaded, using defaults");
 | 
					    		log.info("[Stargate] Permissions not loaded, using defaults");
 | 
				
			||||||
    	} else {
 | 
					    	} else {
 | 
				
			||||||
@@ -114,7 +119,7 @@ public class Stargate extends JavaPlugin {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	public void reloadConfig() {
 | 
						public void reloadConfig() {
 | 
				
			||||||
    	config.load();
 | 
					    	config.load();
 | 
				
			||||||
        portalFile = config.getString("portal-save-location", portalFile);
 | 
					        portalFolder = config.getString("portal-folder", portalFolder);
 | 
				
			||||||
        gateFolder = config.getString("gate-folder", gateFolder);
 | 
					        gateFolder = config.getString("gate-folder", gateFolder);
 | 
				
			||||||
        teleMsg = config.getString("teleport-message", teleMsg);
 | 
					        teleMsg = config.getString("teleport-message", teleMsg);
 | 
				
			||||||
        regMsg = config.getString("portal-create-message", regMsg);
 | 
					        regMsg = config.getString("portal-create-message", regMsg);
 | 
				
			||||||
@@ -127,7 +132,7 @@ public class Stargate extends JavaPlugin {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	public void saveConfig() {
 | 
						public void saveConfig() {
 | 
				
			||||||
        config.setProperty("portal-save-location", portalFile);
 | 
					        config.setProperty("portal-folder", portalFolder);
 | 
				
			||||||
        config.setProperty("gate-folder", gateFolder);
 | 
					        config.setProperty("gate-folder", gateFolder);
 | 
				
			||||||
        config.setProperty("teleport-message", teleMsg);
 | 
					        config.setProperty("teleport-message", teleMsg);
 | 
				
			||||||
        config.setProperty("portal-create-message", regMsg);
 | 
					        config.setProperty("portal-create-message", regMsg);
 | 
				
			||||||
@@ -141,24 +146,29 @@ public class Stargate extends JavaPlugin {
 | 
				
			|||||||
	
 | 
						
 | 
				
			||||||
	public void reloadGates() {
 | 
						public void reloadGates() {
 | 
				
			||||||
		Gate.loadGates(gateFolder);
 | 
							Gate.loadGates(gateFolder);
 | 
				
			||||||
        Portal.loadAllGates(this.getServer().getWorlds().get(0));
 | 
							// Replace nethergate.gate if it doesn't have an exit point.
 | 
				
			||||||
 | 
							if (Gate.getGateByName("nethergate.gate").getExit() == null) {
 | 
				
			||||||
 | 
								Gate.populateDefaults(gateFolder);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							for (World world : getServer().getWorlds()) {
 | 
				
			||||||
 | 
								Portal.loadAllGates(world);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	private void migrate() {
 | 
						private void migrate() {
 | 
				
			||||||
		// Only migrate if new file doesn't exist.
 | 
							// Only migrate if new file doesn't exist.
 | 
				
			||||||
		File newFile = new File(portalFile);
 | 
							File newPortalDir = new File(portalFolder);
 | 
				
			||||||
 | 
							if (!newPortalDir.exists()) {
 | 
				
			||||||
 | 
								newPortalDir.mkdirs();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							File newFile = new File(portalFolder, getServer().getWorlds().get(0).getName() + ".db");
 | 
				
			||||||
		if (!newFile.exists()) {
 | 
							if (!newFile.exists()) {
 | 
				
			||||||
			// Migrate REALLY old stargates if applicable
 | 
						        // Migrate not-so-old stargate db
 | 
				
			||||||
			File olderFile = new File("stargates.txt");
 | 
						        File oldishFile = new File("plugins/Stargate/stargate.db");
 | 
				
			||||||
			if (olderFile.exists()) {
 | 
						        if (oldishFile.exists()) {
 | 
				
			||||||
				Stargate.log.info("[Stargate] Migrated old stargates.txt");
 | 
						        	Stargate.log.info("[Stargate] Migrating existing stargate.db");
 | 
				
			||||||
				olderFile.renameTo(newFile);
 | 
						        	oldishFile.renameTo(newFile);
 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
	    	// Migrate old stargates if applicable.
 | 
					 | 
				
			||||||
	        File oldFile = new File("stargates/locations.dat");
 | 
					 | 
				
			||||||
	        if (oldFile.exists()) {
 | 
					 | 
				
			||||||
	        	Stargate.log.info("[Stargate] Migrated existing locations.dat");
 | 
					 | 
				
			||||||
	            oldFile.renameTo(newFile);
 | 
					 | 
				
			||||||
	        }
 | 
						        }
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
@@ -169,13 +179,13 @@ public class Stargate extends JavaPlugin {
 | 
				
			|||||||
        	if (!newDir.exists()) newDir.mkdirs();
 | 
					        	if (!newDir.exists()) newDir.mkdirs();
 | 
				
			||||||
            for (File file : oldDir.listFiles(new Gate.StargateFilenameFilter())) {
 | 
					            for (File file : oldDir.listFiles(new Gate.StargateFilenameFilter())) {
 | 
				
			||||||
            	Stargate.log.info("[Stargate] Migrating existing gate " + file.getName());
 | 
					            	Stargate.log.info("[Stargate] Migrating existing gate " + file.getName());
 | 
				
			||||||
            	file.renameTo(new File(gateFolder + file.getName()));
 | 
					            	file.renameTo(new File(gateFolder, file.getName()));
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static String getSaveLocation() {
 | 
					    public static String getSaveLocation() {
 | 
				
			||||||
        return portalFile;
 | 
					        return portalFolder;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static String getDefaultNetwork() {
 | 
					    public static String getDefaultNetwork() {
 | 
				
			||||||
@@ -216,8 +226,6 @@ public class Stargate extends JavaPlugin {
 | 
				
			|||||||
	 */
 | 
						 */
 | 
				
			||||||
	private boolean setupPermissions() {
 | 
						private boolean setupPermissions() {
 | 
				
			||||||
		Plugin perm;
 | 
							Plugin perm;
 | 
				
			||||||
		// Apparently GM isn't a new permissions plugin, it's Permissions "2.0.1"
 | 
					 | 
				
			||||||
		// API change broke my plugin.
 | 
					 | 
				
			||||||
		perm = pm.getPlugin("Permissions");
 | 
							perm = pm.getPlugin("Permissions");
 | 
				
			||||||
		// We're running Permissions
 | 
							// We're running Permissions
 | 
				
			||||||
		if (perm != null) {
 | 
							if (perm != null) {
 | 
				
			||||||
@@ -325,6 +333,8 @@ public class Stargate extends JavaPlugin {
 | 
				
			|||||||
    	public void onSignChange(SignChangeEvent event) {
 | 
					    	public void onSignChange(SignChangeEvent event) {
 | 
				
			||||||
    		Player player = event.getPlayer();
 | 
					    		Player player = event.getPlayer();
 | 
				
			||||||
    		Block block = event.getBlock();
 | 
					    		Block block = event.getBlock();
 | 
				
			||||||
 | 
					    		if (block.getType() != Material.WALL_SIGN) return;
 | 
				
			||||||
 | 
					    		
 | 
				
			||||||
    		// Initialize a stargate
 | 
					    		// Initialize a stargate
 | 
				
			||||||
            if (hasPerm(player, "stargate.create", player.isOp())) {
 | 
					            if (hasPerm(player, "stargate.create", player.isOp())) {
 | 
				
			||||||
	            SignPost sign = new SignPost(new Blox(block));
 | 
						            SignPost sign = new SignPost(new Blox(block));
 | 
				
			||||||
@@ -339,7 +349,7 @@ public class Stargate extends JavaPlugin {
 | 
				
			|||||||
                if (!regMsg.isEmpty()) {
 | 
					                if (!regMsg.isEmpty()) {
 | 
				
			||||||
                    player.sendMessage(ChatColor.GREEN + regMsg);
 | 
					                    player.sendMessage(ChatColor.GREEN + regMsg);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                log.info("Initialized stargate: " + portal.getName());
 | 
					                log.info("[Stargate] Initialized stargate: " + portal.getName());
 | 
				
			||||||
                portal.drawSign();
 | 
					                portal.drawSign();
 | 
				
			||||||
                // Set event text so our new sign is instantly initialized
 | 
					                // Set event text so our new sign is instantly initialized
 | 
				
			||||||
                event.setLine(0, sign.getText(0));
 | 
					                event.setLine(0, sign.getText(0));
 | 
				
			||||||
@@ -438,7 +448,7 @@ public class Stargate extends JavaPlugin {
 | 
				
			|||||||
    private class wListener extends WorldListener {
 | 
					    private class wListener extends WorldListener {
 | 
				
			||||||
    	@Override
 | 
					    	@Override
 | 
				
			||||||
    	public void onWorldLoaded(WorldEvent event) {
 | 
					    	public void onWorldLoaded(WorldEvent event) {
 | 
				
			||||||
    		//Portal.loadQueue(event.getWorld());
 | 
					    		Portal.loadAllGates(event.getWorld());
 | 
				
			||||||
    	}
 | 
					    	}
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,6 @@
 | 
				
			|||||||
name: Stargate
 | 
					name: Stargate
 | 
				
			||||||
main: net.TheDgtl.Stargate.Stargate
 | 
					main: net.TheDgtl.Stargate.Stargate
 | 
				
			||||||
version: 0.18
 | 
					version: 0.20
 | 
				
			||||||
description: Stargate mod for Bukkit
 | 
					description: Stargate mod for Bukkit
 | 
				
			||||||
author: Drakia
 | 
					author: Drakia
 | 
				
			||||||
website: http://www.thedgtl.net
 | 
					website: http://www.thedgtl.net
 | 
				
			||||||
		Reference in New Issue
	
	Block a user