51 Commits

Author SHA1 Message Date
a0bc62f767 Bumped version to 2.1.0-beta. 2013-03-07 16:51:21 +01:00
850fbf1515 Updated changelog. 2013-02-28 00:22:08 +01:00
b99ecec448 Added toString method for gates. 2013-02-26 14:17:01 +01:00
3a7be837b5 Modified help string for exit command. 2013-02-26 14:16:51 +01:00
1bfc886969 Further work for Issue #6. 2013-02-26 14:16:39 +01:00
880071140a Started work on implementing a permission checking system for Vault. (Issue #6) 2013-02-26 12:50:02 +01:00
5b1ac6e8f7 Added code to send messages when player enter a gate. (Issue #15) 2013-02-26 12:47:38 +01:00
08906f6004 Fixed Vault permissions setup. 2013-02-23 19:53:05 +01:00
e54914bd22 Fix a null pointer exception if a certain world has no gates. 2013-02-23 19:52:41 +01:00
606ea1d5c5 Updated the change log file. 2013-02-23 19:51:54 +01:00
b072229914 small bug fix. 2013-02-20 14:45:16 +01:00
0b8be1ec4b PluginPortalListener clean up. 2013-02-20 14:38:02 +01:00
1fef272af2 Fixed typos in plugin.yml. 2013-02-20 14:37:45 +01:00
26927d35c2 Fix for Issue #14. 2013-02-20 14:32:37 +01:00
c79a856907 New fix for Issue #8. Now using EntityPortalEnterEvent additionally. 2013-02-19 18:59:54 +01:00
c25bb01aa1 Added missing command to readme file. 2013-02-19 12:52:49 +01:00
68bf008bc4 Fixed typo 2013-02-19 12:49:33 +01:00
638afcc82f Updated the readme file. #2 2013-02-19 12:48:31 +01:00
f020096126 Updated the readme file. 2013-02-19 12:43:45 +01:00
a4ee78b88a Updated setLocation and setExit aliases. 2013-02-19 12:43:12 +01:00
f3a87516d6 Sort the output of the help command alphabetically. 2013-02-19 12:27:46 +01:00
984069ff35 Added a change log file. 2013-02-19 11:45:00 +01:00
0dacfaa79b Additional work for Issue #8 2013-02-17 19:43:34 +01:00
02262880da Fixed stupid bug letting the closest gate method fail. 2013-02-17 19:39:15 +01:00
9ce65ed26d Removed unused class. 2013-02-17 14:59:40 +01:00
db173521e4 Removed unused import. 2013-02-17 14:58:17 +01:00
16095226f9 Fixed Issue #8 2013-02-17 14:56:48 +01:00
3ea11da591 Refactoring: Moved code into LocationUtil and GateUtil. 2013-02-17 14:56:01 +01:00
59fdb54a09 Fixed a bug where an already closed gate got used for teleporting. 2013-02-17 13:11:16 +01:00
02b904a78d Removed some whitespace. 2013-02-17 13:10:34 +01:00
0117e7294a Code style applied. Increased the maximum number of gate blocks to 40. 2013-02-17 13:10:11 +01:00
1de6812eb6 Updated and simplified the command aliases. 2013-02-17 12:31:59 +01:00
26e5b68a7d Updated the 'senderMustBePlayer' attribute of all commands. 2013-02-17 12:20:04 +01:00
f09b90f0a6 Code style applied. 2013-02-16 13:21:21 +01:00
32f1cba2bd Do not create yml configuration object on every save/load. 2013-02-15 23:38:04 +01:00
56a5f828ee Added log statements when gates get closed during serialization. 2013-02-15 23:36:14 +01:00
cd0ebc3a7a Added shouldPersistToDisk attribute to BaseCommand. Updated subclasses to reflect the new attribute. 2013-02-15 23:31:39 +01:00
dd5a60cb2a Updated classpath 2013-02-15 23:30:16 +01:00
32fc475a8a Fixed broken colored print for the create command. 2013-02-11 21:59:41 +01:00
43f002032d Removed unused import. 2013-02-11 21:59:11 +01:00
cf2155ab40 Made ingame prints colored. 2013-02-11 21:06:10 +01:00
b9e84b122d Bumped version to 2.1.0-dev 2013-02-11 21:05:19 +01:00
749c04f585 Fixed bug where renaming a gate did create a duplicate gate on save. 2013-02-11 19:27:09 +01:00
dae92a0357 Merge branch 'master' of github.com:craftinc/craftinc-gates 2013-02-10 16:17:51 +01:00
5b4036ac7c Merge branch 'master' of github.com:craftinc/craftinc-gates 2013-02-10 15:40:28 +01:00
ead21c0b79 Removed even more debug prints. 2013-02-10 14:10:40 +01:00
ed58f762fe Removed debug prints. 2013-02-10 03:56:50 +01:00
59a7f4f80e Fixed index out of bounds exception. 2013-02-10 03:56:00 +01:00
58695cadd3 Added untested support for Vault permission handling. 2013-02-10 01:05:12 +01:00
cab78c34cc Updated classpath. 2013-02-09 23:16:21 +01:00
e407d2b9fa added softdepend Vault
symlink of plugin.yml in resources
2013-02-09 23:14:41 +01:00
29 changed files with 856 additions and 373 deletions

View File

@ -2,6 +2,11 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="lib" path="/Users/tobi/Code/craftbukkit-1.4.5-R1.0.jar"/>
<classpathentry kind="lib" path="/Users/tobi/Code/craftbukkit-1.4.5-R1.0.jar" sourcepath="//Users/tobi/Code/Bukkit">
<attributes>
<attribute name="source_encoding" value="UTF-8"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="/Users/tobi/Code/Vault.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -9,6 +9,8 @@ Try the ingame command: __/gate__
Also have a look at the full __[userguide](http://www.craftinc.de/blog/?p=255)__.
Check out our **[Craft Inc. Minecraft Server](http://www.craftinc.de)**! Everyone is welcome!
Thought first you should take a look at the demonstration oloflarsson and karibu6 created:
__[http://www.youtube.com/watch?v=L4hyqTpeEaA](http://www.youtube.com/watch?v=L4hyqTpeEaA)__
@ -27,25 +29,79 @@ __Are there IConnomy integration, Features for user to dial other gates etc?__
Nope. This plugin is very minimalistic and plain. Server operators manage the portals players use them any time they are open.
## Usage
__Note that the commands mentioned in this section will be made available with the upcoming 2.1 release of Craft Inc. Gates! Meanwhile type '/gate help' while playing to see the current set of commands.__
With the __/gate__ plugin you can create gates which will teleport players anywhere you want. Just build a portal (like those nether portal). The gates can look any way you like.
To make the gate work place yourself in a newly created gate frame and type __/gate create [id]__. Afterwards walk to the destination of your portal and type __/gate exit [id]__ to set the destination. With __/gate open [id]__ you can get your newly created gate to work.
To hide a gate simply call __/gate hide [id]__. Now that gate wont have purple blocks when open. You can even remove the frame without stopping the hidden gate from working. But unhiding a gate without a frame is not possible!
Use the following commands to modify your gates even further:
* __/gate close,c [id]__
Closes a gate to prevent players from using it.
* __/gate create,new [id]__
Creates a gate at your current location.
* __/gate delete,del,remove,rm [id]__
Removes the gate from the game.
* __/gate exit,e [id]__
Changes the location where the gate will teleport players to your current location.
* __/gate help,h,? [page]__
Prints the help pages
* __/gate hide,h [id]__
Makes a gate NOT consist of gate blocks while open.
* __/gate info,details,i,d [id]__
Prints detailed informations about a certain gate.
* __/gate list,ls [page]__
Prints all availiable gates.
* __/gate location,l [id]__
Sets the entrance of the gate to your current location.
* __/gate open,o [id]__
Open a gate so players can use it.
* __/gate rename,changename,cn [current name] [new name]__
Changes the name/id of the gate.
* __/gate unhide,uh [id]__
Makes that gate visible.
## Permissions
__craftincgates.info__
* __craftincgates.info__
Gives access to info and list commands.
Gives access to info and list commands.
* __craftincgates.use__
Allows you to travel via gates.
__craftincgates.use__
Allows you to travel via gates.
__craftincgates.manage__
Gives access to commands manipulating gates.
* __craftincgates.manage__
Gives access to commands manipulating gates.
## Installing
1. Download the latest release: __[http://dev.bukkit.org/server-mods/craftinc-gates/files/](http://dev.bukkit.org/server-mods/craftinc-gates/files/)__
2. Put CraftIncGates.jar in the plugins folder.
2. Put the downloaded _CraftIncGates.jar_ in the plugins folder.
3. Start or reload the server.
## Bugs and other Problems
Please use our [issue tracker](https://github.com/craftinc/craftinc-gates/issues?milestone=1&state=open) on github.
## License
This project has a LGPL license just like the Bukkit project.
This project has a LGPL license just like the Bukkit project.

18
changelog.md Normal file
View File

@ -0,0 +1,18 @@
## 2.1.0 (not yet released)
* Command outputs are now colored.
* Fixed a bug where players in creative mode would not be teleported correctly.
* Made various commands available via the server console.
* Simplified command names.
* Improved permissions handling. (Added soft dependency for Vault.)
* A message will be displayed after a player has been teleported. There is also a message displayed if a player is not allowed to use a gate.
## 2.0.1a
* Fixed broken import for gates created with version 2.0.0
## 2.0.1
* Updated permissions to allow everyone to use gates by default.
* Fixed a bug where yaw had not been taken correctly into account while teleporting.
* Re-added persistence of yaw and pitch of gate locations and exits.
## 2.0.0
Initial release under new name

View File

@ -1,7 +1,8 @@
name: Craft Inc. Gates
version: 2.0.1a
version: 2.1.0-beta
description: A plugin to create gates for fast traveling.
author: tomco, s1m0ne
softdepend: [Vault]
author: tomco, s1m0ne
authors: [oloflarsson, locutus, DrAgonmoray, s1m0ne, tomco]
website: http://www.craftinc.de/craftinc-gates/

13
pom.xml
View File

@ -19,6 +19,13 @@
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>Vault</artifactId>
<version>1.2.23-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
@ -28,7 +35,7 @@
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src/resources</directory>
<directory>resources</directory>
</resource>
</resources>
</build>
@ -38,5 +45,9 @@
<id>bukkit-repo</id>
<url>http://repo.bukkit.org/content/groups/public</url>
</repository>
<repository>
<id>vault-repo</id>
<url>http://ci.herocraftonline.com/plugin/repository/everything</url>
</repository>
</repositories>
</project>

1
resources/plugin.yml Symbolic link
View File

@ -0,0 +1 @@
../plugin.yml

View File

@ -190,6 +190,6 @@ public abstract class BaseGate
throw new Exception("Gate got closed. The frame is missing or broken.");
}
}
}
}
}
}

View File

@ -10,7 +10,7 @@ import java.util.Map;
import org.bukkit.Location;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import de.craftinc.gates.util.LocationSerializer;
import de.craftinc.gates.util.LocationUtil;
@ -56,6 +56,12 @@ public class Gate extends BaseGate implements ConfigurationSerializable
this.id = id;
}
public String toString()
{
return super.toString() + " " + this.getId();
}
/*
@ -81,8 +87,8 @@ public class Gate extends BaseGate implements ConfigurationSerializable
isHidden = (Boolean)map.get(isHiddenKey);
isOpen = (Boolean)map.get(isOpenKey);
location = LocationSerializer.deserializeLocation((Map<String, Object>) map.get(locationKey));
exit = LocationSerializer.deserializeLocation((Map<String, Object>) map.get(exitKey));
location = LocationUtil.deserializeLocation((Map<String, Object>) map.get(locationKey));
exit = LocationUtil.deserializeLocation((Map<String, Object>) map.get(exitKey));
if (map.containsKey(exitPitchKey)) {
exit.setPitch(((Double)map.get(exitPitchKey)).floatValue());
@ -98,7 +104,7 @@ public class Gate extends BaseGate implements ConfigurationSerializable
List<Map<String, Object>> serializedGateBlocks = (List<Map<String, Object>>)map.get(gateBlocksKey);
for (Map<String, Object> sgb : serializedGateBlocks) {
gateBlockLocations.add(LocationSerializer.deserializeLocation(sgb));
gateBlockLocations.add(LocationUtil.deserializeLocation(sgb));
}
}
catch (Exception e) {
@ -120,13 +126,14 @@ public class Gate extends BaseGate implements ConfigurationSerializable
validate(); // make sure to not write invalid stuff to disk
}
catch (Exception e) {
Plugin.log("Gate " + this.getId() + " seems to be not valid. It got closed before serializing!");
}
Map<String, Object> retVal = new HashMap<String, Object>();
retVal.put(idKey, id);
retVal.put(locationKey, LocationSerializer.serializeLocation(location));
retVal.put(exitKey, LocationSerializer.serializeLocation(exit));
retVal.put(locationKey, LocationUtil.serializeLocation(location));
retVal.put(exitKey, LocationUtil.serializeLocation(exit));
retVal.put(isHiddenKey, isHidden);
retVal.put(isOpenKey, isOpen);
@ -141,7 +148,7 @@ public class Gate extends BaseGate implements ConfigurationSerializable
List<Map<String, Object>> serializedGateBlocks = new ArrayList<Map<String, Object>>();
for (Location l : gateBlockLocations) {
serializedGateBlocks.add(LocationSerializer.serializeLocation(l));
serializedGateBlocks.add(LocationUtil.serializeLocation(l));
}
retVal.put(gateBlocksKey, serializedGateBlocks);
@ -181,7 +188,7 @@ public class Gate extends BaseGate implements ConfigurationSerializable
gate.setId(newId);
delete(oldId);
instances.remove(oldId);
instances.put(gate.id, gate);
}

View File

@ -10,12 +10,15 @@ import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.configuration.serialization.ConfigurationSerialization;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import de.craftinc.gates.commands.*;
@ -30,13 +33,18 @@ public class Plugin extends JavaPlugin
public static final String permissionInfo = "craftincgates.info";
public static final String permissionManage = "craftincgates.manage";
public static final String permissionAll = "craftincgates.*";
// public static final String permissionAll = "craftincgates.*";
public static final String permissionUse = "craftincgates.use";
public static Permission permission = null;
public PluginPlayerListener playerListener = new PluginPlayerListener();
public PluginBlockListener blockListener = new PluginBlockListener();
public PluginPortalListener portalListener = new PluginPortalListener();
private File gatesConfigFile;
private FileConfiguration gatesConfig;
private String baseCommand;
private String gatesPath = "gates";
@ -58,13 +66,32 @@ public class Plugin extends JavaPlugin
ConfigurationSerialization.registerClass(Gate.class);
}
private void setupPermissions()
{
if (getServer().getPluginManager().getPlugin("Vault") == null) {
return;
}
RegisteredServiceProvider<Permission> rsp = getServer().getServicesManager().getRegistration(Permission.class);
if (rsp != null)
{
log("Using permission provider provided by Vault.");
permission = rsp.getProvider();
}
else
{
log("Not using setup permission provider provided by Vault.");
}
}
@Override
public void onDisable()
{
// Save gates
saveGates();
log("Disabled");
}
@ -72,6 +99,9 @@ public class Plugin extends JavaPlugin
@Override
public void onEnable()
{
// Setup permissions
setupPermissions();
// Add the commands
commands.add(new CommandHelp());
commands.add(new CommandCreate());
@ -94,6 +124,19 @@ public class Plugin extends JavaPlugin
pm.registerEvents(this.portalListener, this);
// Load gates
this.gatesConfigFile = new File(getDataFolder(), "gates.yml");
if(!this.gatesConfigFile.exists())
{
try {
this.gatesConfigFile.createNewFile();
} catch (IOException e) {
log(Level.SEVERE, "Cannot create gate config file! No gates will be persisted.");
}
}
this.gatesConfig = YamlConfiguration.loadConfiguration(gatesConfigFile);
loadGates();
log("Enabled");
@ -177,13 +220,11 @@ public class Plugin extends JavaPlugin
public void saveGates()
{
File gatesFile = new File(getDataFolder(), "gates.yml");
FileConfiguration gatesConfig = YamlConfiguration.loadConfiguration(gatesFile);
gatesConfig.set(gatesPath, new ArrayList<Object>(Gate.getAll()));
try {
gatesConfig.save(gatesFile);
gatesConfig.save(gatesConfigFile);
log("Saved gates to disk.");
}
catch (IOException e) {
log("ERROR: Could not save gates to disk.");

View File

@ -3,6 +3,7 @@ package de.craftinc.gates.commands;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -12,43 +13,36 @@ import de.craftinc.gates.util.TextUtil;
public abstract class BaseCommand
{
public List<String> aliases;
public List<String> requiredParameters;
public List<String> optionalParameters;
protected List<String> aliases = new ArrayList<String>();
protected List<String> requiredParameters = new ArrayList<String>();
protected List<String> optionalParameters = new ArrayList<String>();
public String helpDescription;
protected String helpDescription = "no description";
public CommandSender sender;
public boolean senderMustBePlayer;
public boolean hasGateParam;
public Player player;
public Gate gate;
protected List<String> parameters;
protected CommandSender sender;
protected Player player;
protected Gate gate;
public List<String> parameters;
protected boolean senderMustBePlayer = true;
protected boolean hasGateParam = true;
public String requiredPermission;
protected String requiredPermission;
protected boolean needsPermissionAtCurrentLocation;
public BaseCommand() {
aliases = new ArrayList<String>();
requiredParameters = new ArrayList<String>();
optionalParameters = new ArrayList<String>();
senderMustBePlayer = true;
hasGateParam = true;
helpDescription = "no description";
}
protected boolean shouldPersistToDisk;
public List<String> getAliases() {
return aliases;
}
public void execute(CommandSender sender, List<String> parameters) {
this.sender = sender;
this.parameters = parameters;
if ( ! validateCall()) {
if (!this.validateCall()) {
return;
}
@ -56,84 +50,188 @@ public abstract class BaseCommand
this.player = (Player)sender;
}
perform();
}
public void perform() {
this.perform();
if (this.shouldPersistToDisk) {
Plugin.instance.saveGates();
}
}
public void sendMessage(String message) {
abstract protected void perform();
protected void sendMessage(String message) {
sender.sendMessage(message);
}
public void sendMessage(List<String> messages) {
protected void sendMessage(List<String> messages) {
for(String message : messages) {
this.sendMessage(message);
}
}
public boolean validateCall()
protected boolean validateCall()
{
// validate player
if ( this.senderMustBePlayer && ! (sender instanceof Player))
{
sendMessage("This command can only be used by ingame players.");
return false;
boolean allParamtertersThere = parameters.size() >= requiredParameters.size();
boolean senderIsPlayer = this.sender instanceof Player;
boolean hasGateParameter = false;
if (this.hasGateParam == true && this.parameters.size() > 0 && this.setGateUsingParameter(this.parameters.get(0))) {
hasGateParameter = true;
}
// validate permission
if( !hasPermission(sender))
boolean senderHasPermission = this.hasPermission();
boolean valid = false;
if (this.senderMustBePlayer && !senderIsPlayer)
{
sendMessage("You lack the permissions to "+this.helpDescription.toLowerCase()+".");
return false;
sendMessage(ChatColor.RED + "This command can only be used by ingame players.");
valid = false;
}
else if (!allParamtertersThere)
{
sendMessage(ChatColor.RED + "Some parameters are missing! " + ChatColor.AQUA + "Usage: " + this.getUseageTemplate(true));
valid = false;
}
else if (!senderHasPermission && this.hasGateParam)
{
sendMessage(ChatColor.RED + "You either provided a invalid gate or do not have permission to " + this.helpDescription.toLowerCase());
valid = false;
}
else if (!senderHasPermission)
{
sendMessage(ChatColor.RED + "You lack the permissions to " + this.helpDescription.toLowerCase());
valid = false;
}
// valide parameter count
if (parameters.size() < requiredParameters.size())
else if (this.hasGateParam && !hasGateParameter)
{
sendMessage("Usage: "+this.getUseageTemplate(true));
return false;
sendMessage(ChatColor.RED + "There exists no gate with id " + this.parameters.get(0));
valid = false;
}
else
{
valid = true;
}
// validate gate parameter
if (this.hasGateParam)
{
String id = parameters.get(0);
if ( ! Gate.exists(id))
{
sendMessage("There exists no gate with id "+id);
return false;
}
gate = Gate.get(id);
}
return true;
return valid;
}
public boolean hasPermission(CommandSender sender)
protected boolean setGateUsingParameter(String param)
{
if (sender.hasPermission(Plugin.permissionAll)) {
if (!Gate.exists(param))
{
return false;
}
else
{
gate = Gate.get(param);
return true;
}
if (sender.hasPermission(requiredPermission)) {
return true;
}
return false;
}
/**
* This will return false if a gate is required for this command but this.gate == null.
*/
protected boolean hasPermission()
{
if (Plugin.permission == null) // fallback <20> use the standard bukkit permission system
{
return this.sender.hasPermission(this.requiredPermission);
}
Player p = null;
if (this.sender instanceof Player)
{
p = (Player) this.sender;
}
else
{
// sender is no player <20> there is no information about the senders locations
return Plugin.permission.has(this.sender, this.requiredPermission);
}
boolean hasPermission = false;
if (this.requiredPermission.equals(Plugin.permissionInfo))
{
if (this.hasGateParam)
{
hasPermission = this.hasPermissionAtGateLocationAndExit(p);
}
else
{
hasPermission = Plugin.permission.has(p.getWorld(), p.getName(), this.requiredPermission);
}
}
else if (this.requiredPermission.equals(Plugin.permissionUse) )
{
hasPermission = this.hasPermissionAtGateLocationAndExit(p);
}
else if (this.requiredPermission.equals(Plugin.permissionManage))
{
if (this.needsPermissionAtCurrentLocation && this.hasGateParam)
{
boolean hasPersmissionAtCurrentLocation = Plugin.permission.has(p.getWorld(), p.getName(), this.requiredPermission);
hasPermission = hasPersmissionAtCurrentLocation && this.hasPermissionAtGateLocationAndExit(p);
}
else if (this.needsPermissionAtCurrentLocation)
{
hasPermission = Plugin.permission.has(p.getWorld(), p.getName(), this.requiredPermission);
}
else
{
hasPermission = this.hasPermissionAtGateLocationAndExit(p);
}
}
return hasPermission;
}
protected boolean hasPermissionAtGateLocationAndExit(Player p)
{
if (this.gate == null || p == null) // make sure we don't run into a nullpointer exception
{
return false;
}
boolean permAtLocation = Plugin.permission.has(this.gate.getLocation().getWorld(), p.getName(), this.requiredPermission);
boolean permAtExit;
if (this.gate.getExit() == null)
{
permAtExit = true;
}
else
{
permAtExit = Plugin.permission.has(this.gate.getExit().getWorld(), p.getName(), this.requiredPermission);
}
return permAtLocation & permAtExit;
}
// -------------------------------------------- //
// Help and usage description
// -------------------------------------------- //
public String getUsageTemplate(boolean withColor, boolean withDescription) {
protected String getUsageTemplate(boolean withColor, boolean withDescription) {
String ret = "";
// if (withColor) {
// ret += Conf.colorCommand;
// }
if (withColor) {
ret += ChatColor.AQUA;
}
ret += "/" + Plugin.instance.getBaseCommand() + " " + TextUtil.implode(this.getAliases(), ",")+" ";
@ -147,23 +245,29 @@ public abstract class BaseCommand
parts.add("*["+optionalParameter+"]");
}
// if (withColor) {
// ret += Conf.colorParameter;
// }
if (withColor) {
ret += ChatColor.DARK_AQUA;
}
ret += TextUtil.implode(parts, " ");
// if (withDescription) {
// ret += " "+Conf.colorSystem + this.helpDescription;
// }
if (withDescription) {
ret += " ";
if (withColor) {
ret += ChatColor.YELLOW;
}
ret += this.helpDescription;
}
return ret;
}
public String getUseageTemplate(boolean withColor) {
protected String getUseageTemplate(boolean withColor) {
return getUsageTemplate(withColor, false);
}
public String getUseageTemplate() {
protected String getUseageTemplate() {
return getUseageTemplate(true);
}
}

View File

@ -1,5 +1,9 @@
package de.craftinc.gates.commands;
import java.util.logging.Level;
import org.bukkit.ChatColor;
import de.craftinc.gates.Plugin;
@ -8,25 +12,37 @@ public class CommandClose extends BaseCommand
public CommandClose()
{
aliases.add("close");
aliases.add("c");
requiredParameters.add("id");
helpDescription = "Closes a gate to prevent players from using it.";
requiredPermission = Plugin.permissionManage;
needsPermissionAtCurrentLocation = false;
shouldPersistToDisk = true;
senderMustBePlayer = false;
}
@Override
public void perform()
{
try {
try
{
gate.setOpen(false);
sendMessage(ChatColor.GREEN + "The gate was closed.");
}
catch(Exception e) {
catch(Exception e)
{
sendMessage(ChatColor.RED + "Opening the gate failed! See server log for more information");
Plugin.log(Level.WARNING, e.getMessage());
e.printStackTrace();
}
sendMessage("The gate was closed.");
}
}

View File

@ -1,5 +1,7 @@
package de.craftinc.gates.commands;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import de.craftinc.gates.Gate;
@ -21,6 +23,11 @@ public class CommandCreate extends BaseLocationCommand
helpDescription = "Create a gate at your current location.";
requiredPermission = Plugin.permissionManage;
needsPermissionAtCurrentLocation = true;
shouldPersistToDisk = true;
senderMustBePlayer = true;
}
@ -28,27 +35,34 @@ public class CommandCreate extends BaseLocationCommand
{
String id = parameters.get(0);
try {
try
{
gate = Gate.create(id);
sendMessage(ChatColor.GREEN + "Gate with id '" + id + "' was created.");
}
catch (Exception e) {
System.out.println(e.getMessage());
catch (Exception e)
{
sendMessage(ChatColor.RED + "Creating the gate failed!" + e.getMessage() + "See server log for more information");
return;
}
Location playerLocation = getValidPlayerLocation();
if (playerLocation != null) {
try {
if (playerLocation != null)
{
try
{
gate.setLocation(playerLocation);
sendMessage(ChatColor.AQUA + "The gates location has been set to your current location.");
}
catch (Exception e) {
catch (Exception e)
{
}
sendMessage("Gate with id \"" + id + "\" was created.");
sendMessage("The gates location has been set to your current location.");
}
else {
sendMessage("Gate with id \"" + id + "\" was created.");
else
{
sendMessage(ChatColor.GREEN + "Gate with id \"" + id + "\" was created.");
sendMessage("Now you should build a frame and:");
sendMessage(new CommandSetLocation().getUsageTemplate(true, true));
}

View File

@ -1,5 +1,7 @@
package de.craftinc.gates.commands;
import org.bukkit.ChatColor;
import de.craftinc.gates.Gate;
import de.craftinc.gates.Plugin;
@ -19,13 +21,18 @@ public class CommandDelete extends BaseCommand
helpDescription = "Removes the gate from the game.";
requiredPermission = Plugin.permissionManage;
needsPermissionAtCurrentLocation = false;
shouldPersistToDisk = true;
senderMustBePlayer = false;
}
public void perform()
{
Gate.delete(gate.getId());
sendMessage("Gate with id '" + gate.getId() + "' was deleted.");
sendMessage(ChatColor.GREEN + "Gate with id '" + gate.getId() + "' was deleted.");
}
}

View File

@ -1,13 +1,53 @@
package de.craftinc.gates.commands;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.bukkit.command.CommandSender;
import de.craftinc.gates.Gate;
import de.craftinc.gates.Plugin;
import de.craftinc.gates.util.TextUtil;
public class CommandHelp extends BaseCommand
{
public static List<List<String>> helpPages;
static
{
// sort the usage strings
List<String> allUsageStrings = new ArrayList<String>();
allUsageStrings.add( new CommandHelp().getUsageTemplate(true, true) );
allUsageStrings.add( new CommandCreate().getUsageTemplate(true, true) );
allUsageStrings.add( new CommandDelete().getUsageTemplate(true, true) );
allUsageStrings.add( new CommandSetLocation().getUsageTemplate(true, true) );
allUsageStrings.add( new CommandSetExit().getUsageTemplate(true, true) );
allUsageStrings.add( new CommandOpen().getUsageTemplate(true, true) );
allUsageStrings.add( new CommandRename().getUsageTemplate(true, true) );
allUsageStrings.add( new CommandClose().getUsageTemplate(true, true) );
allUsageStrings.add( new CommandList().getUsageTemplate(true, true) );
allUsageStrings.add( new CommandInfo().getUsageTemplate(true, true) );
allUsageStrings.add( new CommandSetHidden().getUsageTemplate(true, true) );
allUsageStrings.add( new CommandSetVisible().getUsageTemplate(true, true) );
Collections.sort(allUsageStrings);
// put 5 commands on one page
helpPages = new ArrayList<List<String>>();
while (!allUsageStrings.isEmpty())
{
int toIndex = allUsageStrings.size() >= 6 ? 5 : allUsageStrings.size();
List<String> currentHelpPage = new ArrayList<String>(allUsageStrings.subList(0, toIndex));
helpPages.add(currentHelpPage);
allUsageStrings.removeAll(currentHelpPage);
}
}
public CommandHelp()
{
@ -16,13 +56,18 @@ public class CommandHelp extends BaseCommand
aliases.add("?");
optionalParameters.add("page");
hasGateParam = false;
helpDescription = "prints this help page";
helpDescription = "Prints a list of all availible commands.";
requiredPermission = Plugin.permissionInfo;
hasGateParam = false;
needsPermissionAtCurrentLocation = false;
shouldPersistToDisk = false;
senderMustBePlayer = false;
}
@Override
public boolean hasPermission(CommandSender sender)
public boolean hasPermission(CommandSender sender, Gate gate)
{
return true;
}
@ -44,7 +89,7 @@ public class CommandHelp extends BaseCommand
}
}
sendMessage(TextUtil.titleize("Craft Inc. Gates Help ("+page+"/"+helpPages.size()+")"));
sendMessage(TextUtil.titleize("Craft Inc. Gates Help (" + page + "/" + helpPages.size() + ")"));
page -= 1;
if (page < 0 || page >= helpPages.size())
@ -55,40 +100,5 @@ public class CommandHelp extends BaseCommand
sendMessage(helpPages.get(page));
}
//----------------------------------------------//
// Build the help pages
//----------------------------------------------//
public static ArrayList<ArrayList<String>> helpPages;
static
{
helpPages = new ArrayList<ArrayList<String>>();
ArrayList<String> pageLines;
pageLines = new ArrayList<String>();
pageLines.add( new CommandHelp().getUsageTemplate(true, true) );
pageLines.add( new CommandCreate().getUsageTemplate(true, true) );
pageLines.add( new CommandDelete().getUsageTemplate(true, true) );
pageLines.add( new CommandSetLocation().getUsageTemplate(true, true) );
pageLines.add( new CommandSetExit().getUsageTemplate(true, true) );
pageLines.add( new CommandOpen().getUsageTemplate(true, true) );
helpPages.add(pageLines);
pageLines = new ArrayList<String>();
pageLines.add( new CommandRename().getUsageTemplate(true, true) );
pageLines.add( new CommandClose().getUsageTemplate(true, true) );
pageLines.add( new CommandList().getUsageTemplate(true, true) );
pageLines.add( new CommandInfo().getUsageTemplate(true, true) );
pageLines.add( new CommandSetHidden().getUsageTemplate(true, true) );
pageLines.add( new CommandSetVisible().getUsageTemplate(true, true) );
helpPages.add(pageLines);
}
}

View File

@ -1,8 +1,10 @@
package de.craftinc.gates.commands;
import org.bukkit.ChatColor;
import de.craftinc.gates.Plugin;
import de.craftinc.gates.util.TextUtil;
public class CommandInfo extends BaseCommand
@ -11,42 +13,48 @@ public class CommandInfo extends BaseCommand
{
aliases.add("info");
aliases.add("details");
aliases.add("i");
aliases.add("d");
requiredParameters.add("id");
helpDescription = "Prints detailed informations about a certain gate.";
requiredPermission = Plugin.permissionInfo;
needsPermissionAtCurrentLocation = false;
shouldPersistToDisk = false;
senderMustBePlayer = false;
}
public void perform()
{
sendMessage(ChatColor.LIGHT_PURPLE + "Information about " + ChatColor.WHITE + gate.getId() + ChatColor.LIGHT_PURPLE + ":");
sendMessage(TextUtil.titleize("Information about: '" + ChatColor.WHITE + gate.getId() + ChatColor.YELLOW + "'"));
String openHiddenMessage = "This gate is";
String openHiddenMessage = ChatColor.DARK_AQUA + "This gate is";
if (gate.isOpen())
openHiddenMessage += " open";
openHiddenMessage += ChatColor.AQUA + " open";
else
openHiddenMessage += " closed";
openHiddenMessage += ChatColor.AQUA + " closed";
if (gate.isHidden())
openHiddenMessage += " and hidden";
openHiddenMessage += ChatColor.DARK_AQUA +" and" + ChatColor.AQUA + " hidden";
openHiddenMessage += ".";
openHiddenMessage += ".\n";
sendMessage(openHiddenMessage);
if (gate.getLocation() != null)
sendMessage(ChatColor.GREEN + "'from' location: " + ChatColor.YELLOW + "( " + gate.getLocation().getBlockX() + " | " + gate.getLocation().getBlockY() + " | " + gate.getLocation().getBlockZ() + " ) in " + gate.getLocation().getWorld().getName());
sendMessage(ChatColor.DARK_AQUA + "from: " + ChatColor.AQUA + "( " + gate.getLocation().getBlockX() + " | " + gate.getLocation().getBlockY() + " | " + gate.getLocation().getBlockZ() + " ) in " + gate.getLocation().getWorld().getName());
else
sendMessage(ChatColor.GREEN + "this gate has no 'from' location");
sendMessage(ChatColor.DARK_AQUA + "NOTE: this gate has no 'from' location");
if (gate.getExit() != null)
sendMessage(ChatColor.GREEN + "'to' location: " + ChatColor.YELLOW + "( " + gate.getExit().getBlockX() + " | " + gate.getExit().getBlockY() + " | " + gate.getExit().getBlockZ() + " ) in " + gate.getExit().getWorld().getName());
sendMessage(ChatColor.DARK_AQUA + "to: " + ChatColor.AQUA + "( " + gate.getExit().getBlockX() + " | " + gate.getExit().getBlockY() + " | " + gate.getExit().getBlockZ() + " ) in " + gate.getExit().getWorld().getName());
else
sendMessage(ChatColor.GREEN + "this gate has no 'to' location");
sendMessage(ChatColor.DARK_AQUA + "NOTE: this gate has no 'to' location");
}
}

View File

@ -6,6 +6,7 @@ import java.util.Collections;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import de.craftinc.gates.Gate;
import de.craftinc.gates.Plugin;
@ -21,33 +22,66 @@ public class CommandList extends BaseCommand
optionalParameters.add("page");
hasGateParam = false;
needsPermissionAtCurrentLocation = false;
helpDescription = "Prints a list of all availible gates.";
helpDescription = "lists all availible gates.";
requiredPermission = Plugin.permissionInfo;
shouldPersistToDisk = false;
senderMustBePlayer = false;
}
protected String intToTitleString(int i)
{
if ( i < 26 ) {
return ChatColor.GREEN + "" + (char)(i+65) + ":";
return ChatColor.DARK_AQUA + "" + (char)(i+65) + ":";
}
else if ( i == 26 ) {
return ChatColor.GREEN + "0 - 9:";
return ChatColor.DARK_AQUA + "0 - 9:";
}
else {
return ChatColor.GREEN + "!@#$:";
return ChatColor.DARK_AQUA + "!@#$:";
}
}
/**
* Method for returning a collection of gates the player is allowed to see.
*/
protected Collection<Gate> getAllGates()
{
Collection<Gate> gates = Gate.getAll();
if (this.sender instanceof Player && Plugin.permission != null)
{
Player p = (Player)this.sender;
Collection<Gate> gatesCopy = new ArrayList<Gate>(gates); // create a copy since we cannot iterate over a collection while modifying it!
for (Gate gate : gatesCopy) {
if (!Plugin.permission.has(gate.getLocation().getWorld(), p.getName(), this.requiredPermission))
{
gates.remove(gate);
}
else if (gate.getExit() != null && !Plugin.permission.has(gate.getExit().getWorld(), p.getName(), this.requiredPermission))
{
gates.remove(gate);
}
}
}
return gates;
}
// pages start at 1
// will return null if requested page not availible
protected List<String> message(int page)
{
Collection<Gate> gates = Gate.getAll();
Collection<Gate> gates = this.getAllGates();
if (gates.size() == 0) {
return null;
@ -119,7 +153,7 @@ public class CommandList extends BaseCommand
linesLeftOnCurrentPage -= numLinesForCurrentChar;
if (currentPage == page) {
pageMessages.add(TextUtil.implode(currentIds, ", "));
pageMessages.add(ChatColor.AQUA + TextUtil.implode(currentIds, ", "));
if (finishedCurrentIds == false) {
pageMessages.set(pageMessages.size() -2, pageMessages.get(pageMessages.size() -2) + " (more on previous page)");
}
@ -142,7 +176,7 @@ public class CommandList extends BaseCommand
String stringToPutOnCurrentPage = TextUtil.implode(idsToPutOnCurrentPage, ", ");
if (currentPage == page) {
pageMessages.add(stringToPutOnCurrentPage);
pageMessages.add(ChatColor.AQUA + stringToPutOnCurrentPage);
pageMessages.set(pageMessages.size() -2, pageMessages.get(pageMessages.size() -2) + " (more on next page)");
}
@ -160,12 +194,13 @@ public class CommandList extends BaseCommand
currentPage++;
}
if (pageMessages.isEmpty()) {
if (pageMessages.isEmpty())
{
return null;
}
else {
ArrayList<String> retVal = new ArrayList<String>();
retVal.add(ChatColor.LIGHT_PURPLE + "This is page " + ChatColor.WHITE + page + ChatColor.LIGHT_PURPLE + "/" + ChatColor.WHITE + --currentPage + ChatColor.LIGHT_PURPLE + ". There are " + gates.size() + " gates on this server: ");
retVal.add(TextUtil.titleize("List of all gates (" + page + "/" + --currentPage + ")"));
retVal.addAll(pageMessages);
return retVal;
@ -173,30 +208,41 @@ public class CommandList extends BaseCommand
}
protected int getPageParameter()
{
int page = 1;
try {
page = new Integer(parameters.get(0));
}
catch (Exception e) { }
return page;
}
public void perform()
{
Collection<Gate> gates = Gate.getAll();
int page = this.getPageParameter();
if (gates.size() == 0) {
sendMessage("There are no gates yet.");
List<String> messages = message(page);
if (messages == null)
{
if (page == 1) // no gates exist
{
sendMessage(ChatColor.RED + "There are no gates yet. " + ChatColor.RESET +
"(Note that you might not be allowed to get information about certain gates)");
}
else // the requested page does not exist
{
sendMessage(ChatColor.RED + "The requested page is not availible");
}
}
else {
int page = 1;
try {
page = new Integer(parameters.get(0));
}
catch (Exception e) {
}
List<String> messages = message(page);
if (messages == null) {
sendMessage("The requested page is not availible");
}
else {
sendMessage(messages);
}
else
{
sendMessage(messages);
}
}
}

View File

@ -1,5 +1,8 @@
package de.craftinc.gates.commands;
import org.bukkit.ChatColor;
import de.craftinc.gates.Plugin;
@ -9,26 +12,31 @@ public class CommandOpen extends BaseCommand
public CommandOpen()
{
aliases.add("open");
aliases.add("o");
requiredParameters.add("id");
helpDescription = "Open a gate so players can use it.";
requiredPermission = Plugin.permissionManage;
needsPermissionAtCurrentLocation = false;
shouldPersistToDisk = true;
senderMustBePlayer = false;
}
public void perform()
{
try {
try
{
gate.setOpen(true);
} catch (Exception e) {
sendMessage(e.getMessage());
return;
sendMessage(ChatColor.GREEN + "The gate was opened.");
}
catch (Exception e)
{
sendMessage(ChatColor.RED + e.getMessage());
}
sendMessage("The gate was opened.");
}
}

View File

@ -1,5 +1,7 @@
package de.craftinc.gates.commands;
import org.bukkit.ChatColor;
import de.craftinc.gates.Gate;
import de.craftinc.gates.Plugin;
@ -21,6 +23,10 @@ public class CommandRename extends BaseCommand
helpDescription = "Changes the id of a gate.";
requiredPermission = Plugin.permissionManage;
needsPermissionAtCurrentLocation = false;
shouldPersistToDisk = true;
senderMustBePlayer = false;
}
@ -28,14 +34,15 @@ public class CommandRename extends BaseCommand
{
String newId = parameters.get(1);
try {
try
{
Gate.rename(gate.getId(), newId);
sendMessage(ChatColor.GREEN + "Gate " + gate.getId() + " is now known as " + newId + ".");
}
catch (Exception e) {
sendMessage("Cannot rename " + gate.getId() + ". There is already a gate named " + newId + ".");
catch (Exception e)
{
sendMessage(ChatColor.RED + "Cannot rename " + gate.getId() + ". There is already a gate named " + newId + ".");
}
sendMessage("Gate " + gate.getId() + " is now known as " + newId + ".");
}
}

View File

@ -1,5 +1,9 @@
package de.craftinc.gates.commands;
import java.util.logging.Level;
import org.bukkit.ChatColor;
import de.craftinc.gates.Plugin;
@ -8,27 +12,37 @@ public class CommandSetExit extends BaseCommand
public CommandSetExit()
{
aliases.add("setto");
aliases.add("st");
aliases.add("exit");
aliases.add("e");
requiredParameters.add("id");
helpDescription = "Changes the location where the gate will teleport players to your current location.";
helpDescription = "Change exit of location.";
requiredPermission = Plugin.permissionManage;
needsPermissionAtCurrentLocation = true;
shouldPersistToDisk = true;
senderMustBePlayer = true;
}
public void perform()
{
try {
try
{
System.out.println(gate.getExit());
gate.setExit(player.getLocation());
sendMessage(ChatColor.GREEN + "The exit of gate '" + gate.getId() + "' is now where you stand.");
System.out.println(gate.getExit());
}
catch (Exception e) {
sendMessage(e.getMessage());
sendMessage(ChatColor.RED + "Setting the exit for the gate failed! See server log for more information");
Plugin.log(Level.WARNING, e.getMessage());
e.printStackTrace();
}
sendMessage("The exit of gate '" + gate.getId() + "' is now where you stand.");
}
}

View File

@ -1,5 +1,9 @@
package de.craftinc.gates.commands;
import java.util.logging.Level;
import org.bukkit.ChatColor;
import de.craftinc.gates.Plugin;
@ -7,26 +11,33 @@ public class CommandSetHidden extends BaseCommand
{
public CommandSetHidden()
{
aliases.add("setHidden");
aliases.add("sh");
aliases.add("hide");
aliases.add("h");
requiredParameters.add("id");
helpDescription = "Makes a gate NOT consist of gate blocks while open.";
requiredPermission = Plugin.permissionManage;
needsPermissionAtCurrentLocation = false;
shouldPersistToDisk = true;
senderMustBePlayer = false;
}
public void perform()
{
try {
try
{
gate.setHidden(true);
sendMessage(ChatColor.GREEN + "The gate '" + gate.getId() + "' is now hidden.");
}
catch (Exception e) {
sendMessage(e.getMessage());
catch (Exception e)
{
sendMessage(ChatColor.RED + "Hiding the gate failed! See server log for more information");
Plugin.log(Level.WARNING, e.getMessage());
e.printStackTrace();
}
sendMessage("The gate '" + gate.getId() + "' is now hidden.");
}
}

View File

@ -1,6 +1,9 @@
package de.craftinc.gates.commands;
import java.util.logging.Level;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import de.craftinc.gates.Plugin;
@ -11,14 +14,18 @@ public class CommandSetLocation extends BaseLocationCommand
public CommandSetLocation()
{
aliases.add("setlocation");
aliases.add("sl");
aliases.add("location");
aliases.add("l");
requiredParameters.add("id");
helpDescription = "Set the entrance of the gate to your current location.";
requiredPermission = Plugin.permissionManage;
needsPermissionAtCurrentLocation = true;
shouldPersistToDisk = true;
senderMustBePlayer = true;
}
@ -26,19 +33,23 @@ public class CommandSetLocation extends BaseLocationCommand
{
Location playerLocation = getValidPlayerLocation();
if (playerLocation == null) {
if (playerLocation == null)
{
sendMessage("There is not enough room for a gate to open here");
return;
}
try {
try
{
gate.setLocation(playerLocation);
sendMessage(ChatColor.GREEN + "The location of '" + gate.getId() + "' is now at your current location.");
}
catch (Exception e) {
sendMessage(e.getMessage());
catch (Exception e)
{
sendMessage(ChatColor.RED + "Setting the location for the gate failed! See server log for more information");
Plugin.log(Level.WARNING, e.getMessage());
e.printStackTrace();
}
sendMessage("The location of '" + gate.getId() + "' is now at your current location.");
}
}

View File

@ -1,5 +1,7 @@
package de.craftinc.gates.commands;
import org.bukkit.ChatColor;
import de.craftinc.gates.Plugin;
@ -8,27 +10,33 @@ public class CommandSetVisible extends BaseCommand
public CommandSetVisible()
{
aliases.add("makevisible");
aliases.add("mv");
aliases.add("unhide");
aliases.add("uh");
requiredParameters.add("id");
helpDescription = "Make that gate visible";
requiredPermission = Plugin.permissionManage;
needsPermissionAtCurrentLocation = false;
shouldPersistToDisk = true;
senderMustBePlayer = false;
}
public void perform()
{
try {
try
{
gate.setHidden(false);
sendMessage(ChatColor.GREEN + "The gate " + gate.getId() + " is now visible.");
}
catch (Exception e) {
sendMessage(e.getMessage());
sendMessage(ChatColor.RED + e.getMessage());
}
sendMessage("The gate " + gate.getId() + " is now visible.");
}
}

View File

@ -1,97 +0,0 @@
package de.craftinc.gates.listeners;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.event.player.PlayerMoveEvent;
import de.craftinc.gates.Gate;
public abstract class BaseLocationListener
{
protected Gate getValidGateAtPlayerLocation(PlayerMoveEvent e) {
Gate gate = null;
Location playerLocation = e.getPlayer().getLocation();
World playerWorld = playerLocation.getWorld();
Block blockTo = e.getFrom().getBlock();
Block blockToUp = blockTo.getRelative(BlockFace.UP);
for (Gate g : Gate.getAll()) {
// Check if the gate is open and useable
World gateWorld = g.getLocation().getWorld();
if (g.isOpen() == false || !gateWorld.equals(playerWorld)) {
continue;
}
// Check if the location matches
for (Location l: g.getGateBlockLocations()) {
if (locationsAreAtSamePositions(l, blockTo.getLocation()) || locationsAreAtSamePositions(l, blockToUp.getLocation())) {
// Check if the gate is still valid
try {
g.validate();
gate = g;
break;
}
catch (Exception e2) {
// do nothing - gate is closed
}
}
}
}
return gate;
}
protected Gate getGateAtPlayerLocation(PlayerMoveEvent e) {
Gate gate = null;
Block blockTo = e.getFrom().getBlock();
Block blockToUp = blockTo.getRelative(BlockFace.UP);
System.out.println(blockTo.getLocation().getWorld().getName());
for (Gate g : Gate.getAll()) {
// Check if the location matches
for (Location l: g.getGateBlockLocations()) {
if (locationsAreAtSamePositions(l, blockTo.getLocation()) || locationsAreAtSamePositions(l, blockToUp.getLocation())) {
gate = g;
}
}
}
return gate;
}
/**
* Does the same as the equal method of Location but ignores pitch and yaw.
*/
protected boolean locationsAreAtSamePositions(final Location l1, final Location l2)
{
if (l1.getWorld() != l2.getWorld() && (l1.getWorld() == null || !l1.getWorld().equals(l2.getWorld()))) {
return false;
}
if (Double.doubleToLongBits(l1.getX()) != Double.doubleToLongBits(l2.getX())) {
return false;
}
if (Double.doubleToLongBits(l1.getY()) != Double.doubleToLongBits(l2.getY())) {
return false;
}
if (Double.doubleToLongBits(l1.getZ()) != Double.doubleToLongBits(l2.getZ())) {
return false;
}
return true;
}
}

View File

@ -2,6 +2,7 @@ package de.craftinc.gates.listeners;
import java.util.logging.Level;
import org.bukkit.ChatColor;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
@ -14,9 +15,10 @@ import org.bukkit.event.player.PlayerMoveEvent;
import de.craftinc.gates.Gate;
import de.craftinc.gates.Plugin;
import de.craftinc.gates.util.GateUtil;
public class PluginPlayerListener extends BaseLocationListener implements Listener
public class PluginPlayerListener implements Listener
{
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerMove(PlayerMoveEvent event)
@ -25,19 +27,21 @@ public class PluginPlayerListener extends BaseLocationListener implements Listen
return;
}
// Check for permission
if (!hasPermission(event.getPlayer())) {
return;
}
// Find the gate at the current location.
Gate gateAtLocation = getValidGateAtPlayerLocation(event);
Gate gateAtLocation = GateUtil.getGateAtPlayerLocation(event.getTo());
if (gateAtLocation == null) {
return;
}
// Check for permission
if (!hasPermission(event.getPlayer(), gateAtLocation)) {
event.getPlayer().sendMessage(ChatColor.RED + "Sorry, you are not allowed to use this gate!");
return;
}
// Teleport the player
checkChunkLoad(gateAtLocation.getLocation().getBlock());
@ -56,6 +60,8 @@ public class PluginPlayerListener extends BaseLocationListener implements Listen
event.getPlayer().teleport(teleportToLocation);
event.setTo(teleportToLocation);
event.getPlayer().sendMessage(ChatColor.DARK_AQUA + "Thank you for traveling with Craft Inc. Gates.");
}
@ -64,7 +70,7 @@ public class PluginPlayerListener extends BaseLocationListener implements Listen
World w = b.getWorld();
Chunk c = b.getChunk();
if ( ! w.isChunkLoaded(c) )
if (!w.isChunkLoaded(c))
{
Plugin.log(Level.FINE, "Loading chunk: " + c.toString() + " on: " + w.toString());
w.loadChunk(c);
@ -72,7 +78,17 @@ public class PluginPlayerListener extends BaseLocationListener implements Listen
}
protected boolean hasPermission(Player player) {
return player.hasPermission(Plugin.permissionUse) || player.hasPermission(Plugin.permissionAll);
protected boolean hasPermission(Player player, Gate gate)
{
if (Plugin.permission == null) // fallback <20> use the standard bukkit permission system
{
return player.hasPermission(Plugin.permissionUse);
}
else {
boolean permAtLocation = Plugin.permission.has(gate.getLocation().getWorld(), player.getName(), Plugin.permissionUse);
boolean permAtExit = Plugin.permission.has(gate.getExit().getWorld(), player.getName(), Plugin.permissionUse);
return permAtLocation && permAtExit;
}
}
}

View File

@ -1,27 +1,94 @@
package de.craftinc.gates.listeners;
import java.util.HashMap;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityPortalEnterEvent;
import org.bukkit.event.player.PlayerPortalEvent;
import de.craftinc.gates.Gate;
import de.craftinc.gates.Plugin;
import de.craftinc.gates.util.GateUtil;
public class PluginPortalListener extends BaseLocationListener implements Listener
public class PluginPortalListener implements Listener
{
private HashMap<Player, Gate> currentGateAtEvent = new HashMap<Player, Gate>();
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerPortal(PlayerPortalEvent event)
{
if (event.isCancelled()) {
if (event.isCancelled())
{
return;
}
Location playerLocation = event.getPlayer().getLocation();
Gate gateAtLocation = GateUtil.getGateAtPlayerLocation(playerLocation);
// Find the gate at the current location.
Gate gateAtLocation = getGateAtPlayerLocation(event);
if (gateAtLocation != null) {
// If the player's gamemode is creative no gate might be found!
// It seems like players get teleported on a move event when the 'to' location is
// inside a gate. This meens the location obtained earlier is NOT inside a gate.
if (gateAtLocation == null && event.getPlayer().getGameMode() == GameMode.CREATIVE)
{
gateAtLocation = this.currentGateAtEvent.get(event.getPlayer());
}
if (gateAtLocation != null)
{
event.setCancelled(true);
}
this.currentGateAtEvent.put(event.getPlayer(), null);
}
@EventHandler(priority = EventPriority.NORMAL)
public void onEntityPortalEnterEvent(EntityPortalEnterEvent event)
{
if (event.getEntity() instanceof Player)
{
Player player = (Player)event.getEntity();
if (player.getGameMode() == GameMode.CREATIVE)
{
if (this.currentGateAtEvent.get(player) != null)
{
return;
}
Location eventLocation = event.getLocation();
Gate closestGate = GateUtil.closestGate(eventLocation);
if (closestGate != null)
{
// Make sure gate and event locations are on the same height (y-value).
// Otherwise the distance will be messed up when players are flying.
// FIX ME: this could potentially let a nearby nether portal fail!
eventLocation.setY(closestGate.getLocation().getY());
double distToClosestGate = closestGate.getLocation().distance(eventLocation);
Plugin.log("closest gate: " + closestGate.getId());
Plugin.log("distance: " + distToClosestGate);
if (distToClosestGate < 2.0) {
this.currentGateAtEvent.put(player, closestGate);
return;
}
}
}
this.currentGateAtEvent.put(player, null);
}
}
}

View File

@ -13,7 +13,7 @@ import de.craftinc.gates.Plugin;
public class FloodUtil
{
private final static int frameBlockSearchLimit = 20;
private final static int frameBlockSearchLimit = 40;
private static final Set<BlockFace> exp1 = new HashSet<BlockFace>();
private static final Set<BlockFace> exp2 = new HashSet<BlockFace>();
@ -38,19 +38,23 @@ public class FloodUtil
Set<Block> blocks1 = getAirFloodBlocks(block, new HashSet<Block>(), exp1, frameBlockSearchLimit);
Set<Block> blocks2 = getAirFloodBlocks(block, new HashSet<Block>(), exp2, frameBlockSearchLimit);
if (blocks1 == null && blocks2 == null) {
if (blocks1 == null && blocks2 == null)
{
return null;
}
if (blocks1 == null) {
if (blocks1 == null)
{
return blocks2;
}
if (blocks2 == null) {
if (blocks2 == null)
{
return blocks1;
}
if (blocks1.size() > blocks2.size()) {
if (blocks1.size() > blocks2.size())
{
return blocks2;
}
@ -58,10 +62,12 @@ public class FloodUtil
}
public static Set<Block> getAirFloodBlocks(Block startBlock, Set<Block> foundBlocks, Set<BlockFace> expandFaces, int limit)
private static Set<Block> getAirFloodBlocks(Block startBlock, Set<Block> foundBlocks, Set<BlockFace> expandFaces, int limit)
{
if (foundBlocks == null)
{
return null;
}
if (foundBlocks.size() > limit)
{

View File

@ -0,0 +1,83 @@
package de.craftinc.gates.util;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.BlockFace;
import de.craftinc.gates.Gate;
public class GateUtil
{
public static Gate closestGate(Location location)
{
Gate gate = null;
double minmalDist = Double.MAX_VALUE;
for (Gate g : Gate.getAll()) {
if (!g.getLocation().getWorld().equals(location.getWorld()))
{
continue;
}
double tempDist = g.getLocation().distance(location);
if (tempDist < minmalDist)
{
gate = g;
minmalDist = tempDist;
}
}
return gate;
}
public static Gate getGateAtPlayerLocation(Location location)
{
Gate gate = null;
World playerWorld = location.getWorld();
// players are sometime stuck into the ground
Location locationUp = location.getBlock().getRelative(BlockFace.UP).getLocation();
for (Gate g : Gate.getAll())
{
if (gate != null)
{
break;
}
// Check if the gate is open and useable
World gateWorld = g.getLocation().getWorld();
if (!g.isOpen() || !gateWorld.equals(playerWorld))
{
continue;
}
// Check if the location matches
for (Location l: g.getGateBlockLocations()) {
if (LocationUtil.locationsAreAtSamePositions(l, location) || LocationUtil.locationsAreAtSamePositions(l, locationUp))
{
// Check if the gate is still valid
try {
g.validate();
gate = g;
break;
}
catch (Exception e2) {
break; // do nothing - gate got closed
}
}
}
}
return gate;
}
}

View File

@ -1,15 +0,0 @@
package de.craftinc.gates.util;
import org.bukkit.Location;
public class GeometryUtil {
// How long between two locations?
public static double distanceBetweenLocations(Location location1, Location location2) {
double X = location1.getX() - location2.getX();
double Y = location1.getY() - location2.getY();
double Z = location1.getZ() - location2.getZ();
return Math.sqrt(X*X+Y*Y+Z*Z);
}
}

View File

@ -12,7 +12,7 @@ import de.craftinc.gates.Plugin;
/**
* NOTE: We do not care about yaw and pitch for gate locations. So we won't serialize them.
*/
public class LocationSerializer
public class LocationUtil
{
protected static String worldKey = "world";
protected static String xKey = "x";
@ -83,4 +83,23 @@ public class LocationSerializer
return new Location(w, x, y, z);
}
public static boolean locationsAreAtSamePositions(final Location l1, final Location l2)
{
if (l1.getWorld() != l2.getWorld() && (l1.getWorld() == null || !l1.getWorld().equals(l2.getWorld()))) {
return false;
}
if (new Double(l1.getX()).longValue() != new Double(l2.getX()).longValue()) {
return false;
}
if (new Double(l1.getY()).longValue() != new Double(l2.getY()).longValue()) {
return false;
}
if (new Double(l1.getZ()).longValue() != new Double(l2.getZ()).longValue()) {
return false;
}
return true;
}
}