[Version 0.7.7.0]\

- Added Random option - This still follows the permission rules defined for normal gate usage\
- Added a bit more debug output
This commit is contained in:
Steven Scott 2012-05-09 19:05:20 -07:00
parent 9ef67b2cce
commit b3e84ae958
4 changed files with 108 additions and 46 deletions

5
README
View File

@ -205,6 +205,11 @@ createConflict=Gate conflicts with existing gate
============= =============
Changes Changes
============= =============
[Version 0.7.7.0]
- Added 'R'andom option - This still follows the permission rules defined for normal gate usage
- Added a bit more debug output
[Version 0.7.6.8]
- Hopefully fix backwards gate exiting
[Version 0.7.6.7] [Version 0.7.6.7]
- Reload all gates on world unload, this stops gates with invalid destinations being in memory. - Reload all gates on world unload, this stops gates with invalid destinations being in memory.
[Version 0.7.6.6] [Version 0.7.6.6]

View File

@ -7,6 +7,7 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Random;
import java.util.Scanner; import java.util.Scanner;
import java.util.logging.Level; import java.util.logging.Level;
@ -93,6 +94,7 @@ public class Portal {
private boolean backwards = false; private boolean backwards = false;
private boolean show = false; private boolean show = false;
private boolean noNetwork = false; private boolean noNetwork = false;
private boolean random = false;
// In-use information // In-use information
private Player player; private Player player;
@ -105,7 +107,7 @@ public class Portal {
float rotX, Blox id, Blox button, float rotX, Blox id, Blox button,
String dest, String name, String dest, String name,
boolean verified, String network, Gate gate, String owner, boolean verified, String network, Gate gate, String owner,
boolean hidden, boolean alwaysOn, boolean priv, boolean free, boolean backwards, boolean show, boolean noNetwork) { boolean hidden, boolean alwaysOn, boolean priv, boolean free, boolean backwards, boolean show, boolean noNetwork, boolean random) {
this.topLeft = topLeft; this.topLeft = topLeft;
this.modX = modX; this.modX = modX;
this.modZ = modZ; this.modZ = modZ;
@ -125,14 +127,20 @@ public class Portal {
this.backwards = backwards; this.backwards = backwards;
this.show = show; this.show = show;
this.noNetwork = noNetwork; this.noNetwork = noNetwork;
this.random = random;
this.world = topLeft.getWorld(); this.world = topLeft.getWorld();
this.fixed = dest.length() > 0; this.fixed = dest.length() > 0 || this.random;
if (this.isAlwaysOn() && !this.isFixed()) { if (this.isAlwaysOn() && !this.isFixed()) {
this.alwaysOn = false; this.alwaysOn = false;
Stargate.debug("Portal", "Can not create a non-fixed always-on gate. Setting AlwaysOn = false"); Stargate.debug("Portal", "Can not create a non-fixed always-on gate. Setting AlwaysOn = false");
} }
if (this.random && !this.isAlwaysOn()) {
this.random = false;
Stargate.debug("Portal", "Can not create a random gate that is not always on");
}
if (verified) { if (verified) {
this.drawSign(); this.drawSign();
} }
@ -173,6 +181,10 @@ public class Portal {
return noNetwork; return noNetwork;
} }
public boolean isRandom() {
return random;
}
public void setAlwaysOn(boolean alwaysOn) { public void setAlwaysOn(boolean alwaysOn) {
this.alwaysOn = alwaysOn; this.alwaysOn = alwaysOn;
} }
@ -201,6 +213,10 @@ public class Portal {
this.noNetwork = noNetwork; this.noNetwork = noNetwork;
} }
public void setRandom(boolean random) {
this.random = random;
}
/** /**
* Getters and Setters * Getters and Setters
*/ */
@ -234,10 +250,24 @@ public class Portal {
drawSign(); drawSign();
} }
public Portal getDestination() { public Portal getDestination(Player player) {
if (isRandom()) {
destinations = getDestinations(player, getNetwork());
if (destinations.size() == 0) {
destinations.clear();
return null;
}
String dest = destinations.get((new Random()).nextInt(destinations.size()));
destinations.clear();
return Portal.getByName(dest, getNetwork());
}
return Portal.getByName(destination, getNetwork()); return Portal.getByName(destination, getNetwork());
} }
public Portal getDestination() {
return getDestination(null);
}
public void setDestination(Portal destination) { public void setDestination(Portal destination) {
setDestination(destination.getName()); setDestination(destination.getName());
} }
@ -337,7 +367,7 @@ public class Portal {
Portal end = getDestination(); Portal end = getDestination();
// Only open dest if it's not-fixed or points at this gate // Only open dest if it's not-fixed or points at this gate
if (end != null && (!end.isFixed() || end.getDestinationName().equalsIgnoreCase(getName())) && !end.isOpen()) { if (!random && end != null && (!end.isFixed() || end.getDestinationName().equalsIgnoreCase(getName())) && !end.isOpen()) {
end.open(openFor, false); end.open(openFor, false);
end.setDestination(this); end.setDestination(this);
if (end.isVerified()) end.drawSign(); if (end.isVerified()) end.drawSign();
@ -412,7 +442,11 @@ public class Portal {
Location exit = getExit(traveller); Location exit = getExit(traveller);
// Handle backwards gates // Handle backwards gates
int adjust = isBackwards() ? 0 :180; int adjust = 180;
if (isBackwards() || origin.isBackwards())
adjust = 0;
if (isBackwards() && origin.isBackwards())
adjust = 180;
exit.setYaw(origin.getRotation() - traveller.getYaw() + this.getRotation() + adjust); exit.setYaw(origin.getRotation() - traveller.getYaw() + this.getRotation() + adjust);
// Call the StargatePortalEvent to allow plugins to change destination // Call the StargatePortalEvent to allow plugins to change destination
@ -527,27 +561,40 @@ public class Portal {
return gate.matches(topLeft, modX, modZ); return gate.matches(topLeft, modX, modZ);
} }
public ArrayList<String> getDestinations(Player player, String network) {
ArrayList<String> destinations = new ArrayList<String>();
for (String dest : allPortalsNet.get(network.toLowerCase())) {
Portal portal = getByName(dest, network);
// Check if dest is a random gate
if (portal.isRandom()) continue;
// Check if dest is always open (Don't show if so)
if (portal.isAlwaysOn() && !portal.isShown()) continue;
// Check if dest is this portal
if (dest.equalsIgnoreCase(getName())) continue;
// Check if dest is a fixed gate not pointing to this gate
if (portal.isFixed() && !portal.getDestinationName().equalsIgnoreCase(getName())) continue;
// Allow random use by non-players (Minecarts)
if (player == null) {
destinations.add(portal.getName());
continue;
}
// Check if this player can access the dest world
if (!Stargate.canAccessWorld(player, portal.getWorld().getName())) continue;
// Visible to this player.
if (Stargate.canSee(player, portal)) {
destinations.add(portal.getName());
}
}
return destinations;
}
public boolean activate(Player player) { public boolean activate(Player player) {
destinations.clear(); destinations.clear();
destination = ""; destination = "";
Stargate.activeList.add(this); Stargate.activeList.add(this);
activePlayer = player; activePlayer = player;
String network = getNetwork(); String network = getNetwork();
for (String dest : allPortalsNet.get(network.toLowerCase())) { destinations = getDestinations(player, network);
Portal portal = getByName(dest, network);
// Check if dest is always open (Don't show if so)
if (portal.isAlwaysOn() && !portal.isShown()) continue;
// Check if this player can access the dest world
if (!Stargate.canAccessWorld(player, portal.getWorld().getName())) continue;
// Check if dest is this portal
if (dest.equalsIgnoreCase(getName())) continue;
// Check if dest is a fixed gate not pointing to this gate
if (portal.isFixed() && !portal.getDestinationName().equalsIgnoreCase(getName())) continue;
// Visible to this player.
if (Stargate.canSee(player, portal)) {
destinations.add(portal.getName());
}
}
if (Stargate.sortLists) { if (Stargate.sortLists) {
Collections.sort(destinations); Collections.sort(destinations);
} }
@ -640,14 +687,18 @@ public class Portal {
} }
} else { } else {
if (isFixed()) { if (isFixed()) {
if (isRandom()) {
Stargate.setLine(sign, ++done, "> Random <");
} else {
Stargate.setLine(sign, ++done, ">" + destination + "<"); Stargate.setLine(sign, ++done, ">" + destination + "<");
}
if (noNetwork) { if (noNetwork) {
Stargate.setLine(sign, ++done, ""); Stargate.setLine(sign, ++done, "");
} else { } else {
Stargate.setLine(sign, ++done, "(" + network + ")"); Stargate.setLine(sign, ++done, "(" + network + ")");
} }
Portal dest = Portal.getByName(destination, network); Portal dest = Portal.getByName(destination, network);
if (dest == null) { if (dest == null && !isRandom()) {
Stargate.setLine(sign, ++done, "Disconnected"); Stargate.setLine(sign, ++done, "Disconnected");
} else { } else {
Stargate.setLine(sign, ++done, ""); Stargate.setLine(sign, ++done, "");
@ -762,7 +813,7 @@ public class Portal {
} }
private void register() { private void register() {
fixed = destination.length() > 0; fixed = destination.length() > 0 || random;
if (!lookupNamesNet.containsKey(getNetwork().toLowerCase())) { if (!lookupNamesNet.containsKey(getNetwork().toLowerCase())) {
Stargate.debug("register", "Network not in lookupNamesNet, adding"); Stargate.debug("register", "Network not in lookupNamesNet, adding");
lookupNamesNet.put(getNetwork().toLowerCase(), new HashMap<String, Portal>()); lookupNamesNet.put(getNetwork().toLowerCase(), new HashMap<String, Portal>());
@ -814,14 +865,15 @@ public class Portal {
String name = filterName(event.getLine(0)); String name = filterName(event.getLine(0));
String destName = filterName(event.getLine(1)); String destName = filterName(event.getLine(1));
String network = filterName(event.getLine(2)); String network = filterName(event.getLine(2));
String options = filterName(event.getLine(3)); String options = filterName(event.getLine(3)).toLowerCase();
boolean hidden = (options.indexOf('h') != -1 || options.indexOf('H') != -1); boolean hidden = (options.indexOf('h') != -1);
boolean alwaysOn = (options.indexOf('a') != -1 || options.indexOf('A') != -1); boolean alwaysOn = (options.indexOf('a') != -1);
boolean priv = (options.indexOf('p') != -1 || options.indexOf('P') != -1); boolean priv = (options.indexOf('p') != -1);
boolean free = (options.indexOf('f') != - 1|| options.indexOf('F') != -1); boolean free = (options.indexOf('f') != - 1);
boolean backwards = (options.indexOf('b') != -1 || options.indexOf('B') != -1); boolean backwards = (options.indexOf('b') != -1);
boolean show = (options.indexOf('s') != -1 || options.indexOf('S') != -1); boolean show = (options.indexOf('s') != -1);
boolean noNetwork = (options.indexOf('n') != -1 || options.indexOf('N') != -1); boolean noNetwork = (options.indexOf('n') != -1);
boolean random = (options.indexOf('r') != -1);
// Check permissions for options. // Check permissions for options.
if (hidden && !Stargate.canOption(player, "hidden")) hidden = false; if (hidden && !Stargate.canOption(player, "hidden")) hidden = false;
@ -833,7 +885,7 @@ public class Portal {
if (noNetwork && !Stargate.canOption(player, "nonetwork")) noNetwork = false; if (noNetwork && !Stargate.canOption(player, "nonetwork")) noNetwork = false;
// Can not create a non-fixed always-on gate. // Can not create a non-fixed always-on gate.
if (alwaysOn && destName.length() == 0) { if (alwaysOn && destName.length() == 0 && !random) {
alwaysOn = false; alwaysOn = false;
} }
@ -902,7 +954,7 @@ public class Portal {
} }
// Debug // Debug
Stargate.debug("createPortal", "h = " + hidden + " a = " + alwaysOn + " p = " + priv + " f = " + free + " b = " + backwards + " s = " + show + " n = " + noNetwork); Stargate.debug("createPortal", "h = " + hidden + " a = " + alwaysOn + " p = " + priv + " f = " + free + " b = " + backwards + " s = " + show + " n = " + noNetwork + " r = " + random);
if ((network.length() < 1) || (network.length() > 11)) { if ((network.length() < 1) || (network.length() > 11)) {
network = Stargate.getDefaultNetwork(); network = Stargate.getDefaultNetwork();
@ -934,8 +986,6 @@ public class Portal {
Stargate.debug("createPortal", "Player does not have access to gate layout"); Stargate.debug("createPortal", "Player does not have access to gate layout");
deny = true; deny = true;
denyMsg = Stargate.getString("createGateDeny"); denyMsg = Stargate.getString("createGateDeny");
//Stargate.sendMessage(player, Stargate.getString("createGateDeny"));
//return null;
} }
// Check if the user can create gates to this world. // Check if the user can create gates to this world.
@ -945,10 +995,8 @@ public class Portal {
String world = p.getWorld().getName(); String world = p.getWorld().getName();
if (!Stargate.canAccessWorld(player, world)) { if (!Stargate.canAccessWorld(player, world)) {
Stargate.debug("canCreate", "Player does not have access to destination world"); Stargate.debug("canCreate", "Player does not have access to destination world");
//Stargate.sendMessage(player, Stargate.getString("createWorldDeny"));
deny = true; deny = true;
denyMsg = Stargate.getString("createWorldDeny"); denyMsg = Stargate.getString("createWorldDeny");
//return null;
} }
} }
} }
@ -965,7 +1013,7 @@ public class Portal {
Blox button = null; Blox button = null;
Portal portal = null; Portal portal = null;
portal = new Portal(topleft, modX, modZ, rotX, id, button, destName, name, false, network, gate, player.getName(), hidden, alwaysOn, priv, free, backwards, show, noNetwork); portal = new Portal(topleft, modX, modZ, rotX, id, button, destName, name, false, network, gate, player.getName(), hidden, alwaysOn, priv, free, backwards, show, noNetwork, random);
int cost = Stargate.getCreateCost(player, gate); int cost = Stargate.getCreateCost(player, gate);
@ -1026,7 +1074,9 @@ public class Portal {
portal.register(); portal.register();
portal.drawSign(); portal.drawSign();
// Open always on gate // Open always on gate
if (portal.isAlwaysOn()) { if (portal.isRandom()) {
portal.open(true);
} else if (portal.isAlwaysOn()) {
Portal dest = Portal.getByName(destName, portal.getNetwork()); Portal dest = Portal.getByName(destName, portal.getNetwork());
if (dest != null) { if (dest != null) {
portal.open(true); portal.open(true);
@ -1126,6 +1176,8 @@ public class Portal {
builder.append(portal.isShown()); builder.append(portal.isShown());
builder.append(':'); builder.append(':');
builder.append(portal.isNoNetwork()); builder.append(portal.isNoNetwork());
builder.append(':');
builder.append(portal.isRandom());
bw.append(builder.toString()); bw.append(builder.toString());
bw.newLine(); bw.newLine();
@ -1195,8 +1247,9 @@ public class Portal {
boolean backwards = (split.length > 16) ? split[16].equalsIgnoreCase("true") : false; boolean backwards = (split.length > 16) ? split[16].equalsIgnoreCase("true") : false;
boolean show = (split.length > 17) ? split[17].equalsIgnoreCase("true") : false; boolean show = (split.length > 17) ? split[17].equalsIgnoreCase("true") : false;
boolean noNetwork = (split.length > 18) ? split[18].equalsIgnoreCase("true") : false; boolean noNetwork = (split.length > 18) ? split[18].equalsIgnoreCase("true") : false;
boolean random = (split.length > 19) ? split[19].equalsIgnoreCase("true") : false;
Portal portal = new Portal(topLeft, modX, modZ, rotX, sign, button, dest, name, false, network, gate, owner, hidden, alwaysOn, priv, free, backwards, show, noNetwork); Portal portal = new Portal(topLeft, modX, modZ, rotX, sign, button, dest, name, false, network, gate, owner, hidden, alwaysOn, priv, free, backwards, show, noNetwork, random);
portal.register(); portal.register();
portal.close(true); portal.close(true);
} }

View File

@ -301,6 +301,10 @@ public class Stargate extends JavaPlugin {
return; return;
} }
// Random gate -- Do nothing
if (portal.isRandom())
return;
// Invalid destination // Invalid destination
if ((destination == null) || (destination == portal)) { if ((destination == null) || (destination == portal)) {
Stargate.sendMessage(player, Stargate.getString("invalidMsg")); Stargate.sendMessage(player, Stargate.getString("invalidMsg"));
@ -344,11 +348,11 @@ public class Stargate extends JavaPlugin {
public static boolean hasPerm(Player player, String perm) { public static boolean hasPerm(Player player, String perm) {
if (permissions != null) { if (permissions != null) {
if (permDebug) if (permDebug)
Stargate.debug("hasPerm::Permissions", perm + " => " + permissions.getHandler().has(player, perm)); Stargate.debug("hasPerm::Permissions(" + player.getName() + ")", perm + " => " + permissions.getHandler().has(player, perm));
return permissions.getHandler().has(player, perm); return permissions.getHandler().has(player, perm);
} else { } else {
if (permDebug) if (permDebug)
Stargate.debug("hasPerm::SuperPerm", perm + " => " + player.hasPermission(perm)); Stargate.debug("hasPerm::SuperPerm(" + player.getName() + ")", perm + " => " + player.hasPermission(perm));
return player.hasPermission(perm); return player.hasPermission(perm);
} }
} }
@ -637,7 +641,7 @@ public class Stargate extends JavaPlugin {
return; return;
} }
Portal dest = portal.getDestination(); Portal dest = portal.getDestination(player);
if (dest == null) return; if (dest == null) return;
boolean deny = false; boolean deny = false;
// Check if player has access to this network // Check if player has access to this network
@ -735,7 +739,7 @@ public class Stargate extends JavaPlugin {
return; return;
} }
Portal destination = portal.getDestination(); Portal destination = portal.getDestination(player);
if (destination == null) return; if (destination == null) return;
boolean deny = false; boolean deny = false;

View File

@ -1,6 +1,6 @@
name: Stargate name: Stargate
main: net.TheDgtl.Stargate.Stargate main: net.TheDgtl.Stargate.Stargate
version: 0.7.6.7 version: 0.7.7.0
description: Stargate mod for Bukkit description: Stargate mod for Bukkit
author: Drakia author: Drakia
website: http://www.thedgtl.net website: http://www.thedgtl.net