Hopefully fixed the "No position found" bug.
If dest > origin, any blocks past origin.size will drop you at dest[0] Switched to scheduler instead of our own thread for closing gates and deactivating signs No longer depend on Permissions, use it as an option. isOp() used as defaults.
This commit is contained in:
parent
b3044c6f03
commit
d37adb90ee
5
README
5
README
@ -79,6 +79,11 @@ gate-folder - The folder containing your .gate files
|
|||||||
=============
|
=============
|
||||||
Changes
|
Changes
|
||||||
=============
|
=============
|
||||||
|
[Version 0.10]
|
||||||
|
- Hopefully fixed the "No position found" bug.
|
||||||
|
- If dest > origin, any blocks past origin.size will drop you at dest[0]
|
||||||
|
- Switched to scheduler instead of our own thread for closing gates and deactivating signs
|
||||||
|
- No longer depend on Permissions, use it as an option. isOp() used as defaults.
|
||||||
[Version 0.09]
|
[Version 0.09]
|
||||||
- Gates can now be any shape
|
- Gates can now be any shape
|
||||||
[Version 0.08]
|
[Version 0.08]
|
||||||
|
@ -61,6 +61,7 @@ public class Portal {
|
|||||||
private Player activePlayer;
|
private Player activePlayer;
|
||||||
private boolean alwaysOn = false;
|
private boolean alwaysOn = false;
|
||||||
private World world;
|
private World world;
|
||||||
|
private long openTime;
|
||||||
|
|
||||||
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,
|
||||||
@ -141,6 +142,8 @@ public class Portal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
isOpen = true;
|
isOpen = true;
|
||||||
|
openTime = System.currentTimeMillis() / 1000;
|
||||||
|
Stargate.openList.add(this);
|
||||||
// Open remote gate
|
// Open remote gate
|
||||||
if (!isFixed()) {
|
if (!isFixed()) {
|
||||||
player = openFor;
|
player = openFor;
|
||||||
@ -174,6 +177,7 @@ public class Portal {
|
|||||||
|
|
||||||
player = null;
|
player = null;
|
||||||
isOpen = false;
|
isOpen = false;
|
||||||
|
Stargate.openList.remove(this);
|
||||||
|
|
||||||
deactivate();
|
deactivate();
|
||||||
}
|
}
|
||||||
@ -254,17 +258,31 @@ public class Portal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Location getExit(Location traveller, Portal origin) {
|
public Location getExit(Location traveller, Portal origin) {
|
||||||
Blox entrance = new Blox(world.getBlockAt((int)Math.floor(traveller.getX()), (int)Math.floor(traveller.getY()), (int)Math.floor(traveller.getZ())));
|
// Move the "entrance" to the first portal block up at the current x/z
|
||||||
|
// "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> originExits = origin.getExits();
|
||||||
HashMap<Blox, Integer> destExits = this.getExits();
|
HashMap<Blox, Integer> destExits = this.getExits();
|
||||||
|
|
||||||
if (originExits.containsKey(entrance)) {
|
if (originExits.containsKey(entrance)) {
|
||||||
|
|
||||||
int position = (int)(((float)originExits.get(entrance) / originExits.size()) * destExits.size());
|
int position = (int)(((float)originExits.get(entrance) / originExits.size()) * destExits.size());
|
||||||
Blox exit = getReverseExits().get(position);
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
if (exit != null) {
|
if (exit != null) {
|
||||||
Location loc = exit.modRelativeLoc(0D, 0D, 1D, traveller.getYaw(), traveller.getPitch(), modX, 1, modZ);
|
Location loc = exit.modRelativeLoc(0D, 0D, 1D, traveller.getYaw(), traveller.getPitch(), modX, 1, modZ);
|
||||||
Block block = world.getBlockAt((int)Math.floor(loc.getX()), (int)Math.floor(loc.getY()), (int)Math.floor(loc.getZ()));
|
Block block = world.getBlockAt(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
||||||
|
|
||||||
if (block.getType() == Material.STEP) {
|
if (block.getType() == Material.STEP) {
|
||||||
loc.setY(loc.getY() + 0.5);
|
loc.setY(loc.getY() + 0.5);
|
||||||
@ -336,12 +354,13 @@ public class Portal {
|
|||||||
destinations.clear();
|
destinations.clear();
|
||||||
destination = "";
|
destination = "";
|
||||||
drawSign(true);
|
drawSign(true);
|
||||||
|
Stargate.activeList.add(this);
|
||||||
activePlayer = player;
|
activePlayer = player;
|
||||||
for (String dest : allPortals) {
|
for (String dest : allPortals) {
|
||||||
Portal portal = getByName(dest);
|
Portal portal = getByName(dest);
|
||||||
if ( (portal.getNetwork().equalsIgnoreCase(network)) && // In the network
|
if ( (portal.getNetwork().equalsIgnoreCase(network)) && // In the network
|
||||||
(!dest.equalsIgnoreCase(getName())) && // Not this portal
|
(!dest.equalsIgnoreCase(getName())) && // Not this portal
|
||||||
(!portal.isHidden() || Stargate.Permissions.has(player, "stargate.hidden") || portal.getOwner().equals(player.getName())) // Is not hidden, player can view hidden, or player created
|
(!portal.isHidden() || Stargate.hasPerm(player, "stargate.hidden", player.isOp()) || portal.getOwner().equals(player.getName())) // Is not hidden, player can view hidden, or player created
|
||||||
) {
|
) {
|
||||||
destinations.add(dest);
|
destinations.add(dest);
|
||||||
}
|
}
|
||||||
@ -352,6 +371,7 @@ public class Portal {
|
|||||||
if (fixed) {
|
if (fixed) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Stargate.activeList.remove(this);
|
||||||
destinations.clear();
|
destinations.clear();
|
||||||
destination = "";
|
destination = "";
|
||||||
activePlayer = null;
|
activePlayer = null;
|
||||||
@ -370,6 +390,10 @@ public class Portal {
|
|||||||
return network;
|
return network;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getOpenTime() {
|
||||||
|
return openTime;
|
||||||
|
}
|
||||||
|
|
||||||
public void cycleDestination(Player player) {
|
public void cycleDestination(Player player) {
|
||||||
if (!isActive() || getActivePlayer() != player) {
|
if (!isActive() || getActivePlayer() != player) {
|
||||||
activate(player);
|
activate(player);
|
||||||
@ -382,7 +406,7 @@ public class Portal {
|
|||||||
}
|
}
|
||||||
destination = destinations.get(index);
|
destination = destinations.get(index);
|
||||||
}
|
}
|
||||||
|
openTime = System.currentTimeMillis() / 1000;
|
||||||
drawSign(true);
|
drawSign(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
package net.TheDgtl.Stargate;
|
package net.TheDgtl.Stargate;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.concurrent.SynchronousQueue;
|
import java.util.Iterator;
|
||||||
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@ -41,7 +42,7 @@ import com.nijiko.permissions.PermissionHandler;
|
|||||||
* @author Shaun (sturmeh)
|
* @author Shaun (sturmeh)
|
||||||
* @author Dinnerbone
|
* @author Dinnerbone
|
||||||
*/
|
*/
|
||||||
public class Stargate extends JavaPlugin implements Runnable {
|
public class Stargate extends JavaPlugin {
|
||||||
// Permissions
|
// Permissions
|
||||||
public static PermissionHandler Permissions = null;
|
public static PermissionHandler Permissions = null;
|
||||||
|
|
||||||
@ -60,13 +61,12 @@ public class Stargate extends JavaPlugin implements Runnable {
|
|||||||
private static String invMsg = "Invalid Destination";
|
private static String invMsg = "Invalid Destination";
|
||||||
private static String blockMsg = "Destination Blocked";
|
private static String blockMsg = "Destination Blocked";
|
||||||
private static String defNetwork = "central";
|
private static String defNetwork = "central";
|
||||||
private static SynchronousQueue<Portal> slip = new SynchronousQueue<Portal>();
|
private static int activeLimit = 10;
|
||||||
|
private static int openLimit = 10;
|
||||||
|
public static ConcurrentLinkedQueue<Portal> openList = 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>();
|
||||||
|
|
||||||
// Threading stuff
|
|
||||||
private Thread clock;
|
|
||||||
private long interval = 0;
|
|
||||||
|
|
||||||
public Stargate(PluginLoader pluginLoader, Server instance, PluginDescriptionFile desc, File folder, File plugin, ClassLoader cLoader) {
|
public Stargate(PluginLoader pluginLoader, Server instance, PluginDescriptionFile desc, File folder, File plugin, ClassLoader cLoader) {
|
||||||
super(pluginLoader, instance, desc, folder, plugin, cLoader);
|
super(pluginLoader, instance, desc, folder, plugin, cLoader);
|
||||||
log = Logger.getLogger("Minecraft");
|
log = Logger.getLogger("Minecraft");
|
||||||
@ -86,8 +86,6 @@ public class Stargate extends JavaPlugin implements Runnable {
|
|||||||
|
|
||||||
pm = getServer().getPluginManager();
|
pm = getServer().getPluginManager();
|
||||||
config = this.getConfiguration();
|
config = this.getConfiguration();
|
||||||
if (clock == null)
|
|
||||||
clock = new Thread(this);
|
|
||||||
|
|
||||||
pm.registerEvent(Event.Type.BLOCK_FLOW, blockListener, Priority.Normal, this);
|
pm.registerEvent(Event.Type.BLOCK_FLOW, blockListener, Priority.Normal, this);
|
||||||
pm.registerEvent(Event.Type.BLOCK_PHYSICS, blockListener, Priority.Normal, this);
|
pm.registerEvent(Event.Type.BLOCK_PHYSICS, blockListener, Priority.Normal, this);
|
||||||
@ -105,9 +103,7 @@ public class Stargate extends JavaPlugin implements Runnable {
|
|||||||
pm.registerEvent(Event.Type.VEHICLE_MOVE, vehicleListener, Priority.Normal, this);
|
pm.registerEvent(Event.Type.VEHICLE_MOVE, vehicleListener, Priority.Normal, this);
|
||||||
pm.registerEvent(Event.Type.SIGN_CHANGE, blockListener, Priority.Normal, this);
|
pm.registerEvent(Event.Type.SIGN_CHANGE, blockListener, Priority.Normal, this);
|
||||||
|
|
||||||
setInterval(160); // 8 seconds.
|
getServer().getScheduler().scheduleSyncRepeatingTask(this, new SGThread(), 0L, 100L);
|
||||||
|
|
||||||
clock.start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reloadConfig() {
|
public void reloadConfig() {
|
||||||
@ -162,28 +158,6 @@ public class Stargate extends JavaPlugin implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void doWork() {
|
|
||||||
Portal open = Portal.getNextOpen();
|
|
||||||
|
|
||||||
if (open != null) {
|
|
||||||
try {
|
|
||||||
slip.put(open);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void threadSafeOperation() {
|
|
||||||
Portal open = slip.poll();
|
|
||||||
if (open != null) {
|
|
||||||
if (open.isOpen()) {
|
|
||||||
open.close(false);
|
|
||||||
} else if (open.isActive()) {
|
|
||||||
open.deactivate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getSaveLocation() {
|
public static String getSaveLocation() {
|
||||||
return portalFile;
|
return portalFile;
|
||||||
}
|
}
|
||||||
@ -223,8 +197,7 @@ public class Stargate extends JavaPlugin implements Runnable {
|
|||||||
if(perm != null) {
|
if(perm != null) {
|
||||||
Stargate.Permissions = ((Permissions)perm).getHandler();
|
Stargate.Permissions = ((Permissions)perm).getHandler();
|
||||||
} else {
|
} else {
|
||||||
log.info("[" + this.getDescription().getName() + "] Permission system not enabled. Disabling plugin.");
|
log.info("[" + this.getDescription().getName() + "] Permission system not enabled.");
|
||||||
pm.disablePlugin(this);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -259,7 +232,6 @@ public class Stargate extends JavaPlugin implements Runnable {
|
|||||||
private class pListener extends PlayerListener {
|
private class pListener extends PlayerListener {
|
||||||
@Override
|
@Override
|
||||||
public void onPlayerMove(PlayerMoveEvent event) {
|
public void onPlayerMove(PlayerMoveEvent event) {
|
||||||
threadSafeOperation();
|
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
Portal portal = Portal.getByEntrance(event.getTo());
|
Portal portal = Portal.getByEntrance(event.getTo());
|
||||||
|
|
||||||
@ -300,7 +272,7 @@ public class Stargate extends JavaPlugin implements Runnable {
|
|||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
Block block = event.getBlock();
|
Block block = event.getBlock();
|
||||||
// Initialize a stargate
|
// Initialize a stargate
|
||||||
if (Stargate.Permissions.has(player, "stargate.create")) {
|
if (Stargate.hasPerm(player, "stargate.create", player.isOp())) {
|
||||||
SignPost sign = new SignPost(new Blox(block));
|
SignPost sign = new SignPost(new Blox(block));
|
||||||
// Set sign text so we can create a gate with it.
|
// Set sign text so we can create a gate with it.
|
||||||
sign.setText(0, event.getLine(0));
|
sign.setText(0, event.getLine(0));
|
||||||
@ -331,7 +303,7 @@ public class Stargate extends JavaPlugin implements Runnable {
|
|||||||
Portal portal = Portal.getByBlock(block);
|
Portal portal = Portal.getByBlock(block);
|
||||||
// Cycle through a stargates locations
|
// Cycle through a stargates locations
|
||||||
if (portal != null) {
|
if (portal != null) {
|
||||||
if (Stargate.Permissions.has(player, "stargate.use")) {
|
if (Stargate.hasPerm(player, "stargate.use", true)) {
|
||||||
if ((!portal.isOpen()) && (!portal.isFixed())) {
|
if ((!portal.isOpen()) && (!portal.isFixed())) {
|
||||||
portal.cycleDestination(player);
|
portal.cycleDestination(player);
|
||||||
}
|
}
|
||||||
@ -341,7 +313,7 @@ public class Stargate extends JavaPlugin implements Runnable {
|
|||||||
|
|
||||||
// Implement right-click to toggle a stargate, gets around spawn protection problem.
|
// Implement right-click to toggle a stargate, gets around spawn protection problem.
|
||||||
if ((block.getType() == Material.STONE_BUTTON)) {
|
if ((block.getType() == Material.STONE_BUTTON)) {
|
||||||
if (Stargate.Permissions.has(player, "stargate.use")) {
|
if (Stargate.hasPerm(player, "stargate.use", true)) {
|
||||||
Portal portal = Portal.getByBlock(block);
|
Portal portal = Portal.getByBlock(block);
|
||||||
if (portal != null) {
|
if (portal != null) {
|
||||||
onButtonPressed(player, portal);
|
onButtonPressed(player, portal);
|
||||||
@ -356,7 +328,7 @@ public class Stargate extends JavaPlugin implements Runnable {
|
|||||||
Block block = event.getBlock();
|
Block block = event.getBlock();
|
||||||
// Check if we're pushing a button.
|
// Check if we're pushing a button.
|
||||||
if (block.getType() == Material.STONE_BUTTON && event.getDamageLevel() == BlockDamageLevel.STOPPED) {
|
if (block.getType() == Material.STONE_BUTTON && event.getDamageLevel() == BlockDamageLevel.STOPPED) {
|
||||||
if (Stargate.Permissions.has(player, "stargate.use")) {
|
if (Stargate.hasPerm(player, "stargate.use", true)) {
|
||||||
Portal portal = Portal.getByBlock(block);
|
Portal portal = Portal.getByBlock(block);
|
||||||
if (portal != null) {
|
if (portal != null) {
|
||||||
onButtonPressed(player, portal);
|
onButtonPressed(player, portal);
|
||||||
@ -374,7 +346,7 @@ public class Stargate extends JavaPlugin implements Runnable {
|
|||||||
Portal portal = Portal.getByBlock(block);
|
Portal portal = Portal.getByBlock(block);
|
||||||
if (portal == null) return;
|
if (portal == null) return;
|
||||||
|
|
||||||
if (!Stargate.Permissions.has(player, "stargate.destroy")) {
|
if (!Stargate.hasPerm(player, "stargate.destroy", player.isOp())) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -403,19 +375,29 @@ public class Stargate extends JavaPlugin implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public static Boolean hasPerm(Player player, String perm, Boolean def) {
|
||||||
while (isEnabled()) {
|
if (Permissions != null)
|
||||||
try {
|
return Permissions.has(player, perm);
|
||||||
while (interval <= 0)
|
return def;
|
||||||
Thread.sleep(50); // Thread is dormant
|
|
||||||
for (long i = 0; i < interval && isEnabled(); i++)
|
|
||||||
Thread.sleep(50); // Sleep for an in-game second?
|
|
||||||
if (isEnabled()) doWork();
|
|
||||||
} catch (InterruptedException e) {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setInterval(long interval) {
|
private class SGThread implements Runnable {
|
||||||
this.interval = interval;
|
public void run() {
|
||||||
|
long time = System.currentTimeMillis() / 1000;
|
||||||
|
for (Iterator<Portal> iter = Stargate.openList.iterator(); iter.hasNext();) {
|
||||||
|
Portal p = iter.next();
|
||||||
|
if (time > p.getOpenTime() + Stargate.openLimit) {
|
||||||
|
p.close(false);
|
||||||
|
iter.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (Iterator<Portal> iter = Stargate.activeList.iterator(); iter.hasNext();) {
|
||||||
|
Portal p = iter.next();
|
||||||
|
if (time > p.getOpenTime() + Stargate.activeLimit) {
|
||||||
|
p.deactivate();
|
||||||
|
iter.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
name: Stargate
|
name: Stargate
|
||||||
main: net.TheDgtl.Stargate.Stargate
|
main: net.TheDgtl.Stargate.Stargate
|
||||||
version: 0.09
|
version: 0.10
|
||||||
description: Stargate mod for Bukkit
|
description: Stargate mod for Bukkit
|
||||||
author: Drakia
|
author: Drakia
|
||||||
website: http://www.thedgtl.net
|
website: http://www.thedgtl.net
|
Loading…
x
Reference in New Issue
Block a user