57 Commits

Author SHA1 Message Date
3481c2a10f Bumped version to 2.1.0 2013-03-26 20:53:21 +01:00
a319f793b2 Removed unused import. 2013-03-26 20:52:10 +01:00
6373f98894 Removed debug prints. 2013-03-26 20:49:48 +01:00
e49c5c0acb Updated classpath file. 2013-03-26 20:49:29 +01:00
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
ca982f5ba9 Bumped version to 2.0.1a 2013-02-10 16:17:17 +01:00
5b4036ac7c Merge branch 'master' of github.com:craftinc/craftinc-gates 2013-02-10 15:40:28 +01:00
bf1f2bcff2 Fixed loading of gates created by version 2.0.0 2013-02-10 15:40:18 +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 854 additions and 377 deletions

View File

@ -1,7 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" path="src"/> <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" sourcepath="/Users/tobi/Code/Bukkit">
<classpathentry kind="lib" path="/Users/tobi/Code/craftbukkit-1.4.5-R1.0.jar"/> <attributes>
<attribute name="source_encoding" value="UTF-8"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="/Users/tobi/Code/Vault.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </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)__. 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: 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)__ __[http://www.youtube.com/watch?v=L4hyqTpeEaA](http://www.youtube.com/watch?v=L4hyqTpeEaA)__
@ -27,24 +29,78 @@ __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. 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 ## Permissions
__craftincgates.info__ * __craftincgates.info__
Gives access to info and list commands. Gives access to info and list commands.
__craftincgates.use__ * __craftincgates.use__
Allows you to travel via gates. Allows you to travel via gates.
__craftincgates.manage__ * __craftincgates.manage__
Gives access to commands manipulating gates. Gives access to commands manipulating gates.
## Installing ## Installing
1. Download the latest release: __[http://dev.bukkit.org/server-mods/craftinc-gates/files/](http://dev.bukkit.org/server-mods/craftinc-gates/files/)__ 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 ## License

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

13
pom.xml
View File

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

1
resources/plugin.yml Symbolic link
View File

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

View File

@ -10,7 +10,7 @@ import java.util.Map;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.configuration.serialization.ConfigurationSerializable; import org.bukkit.configuration.serialization.ConfigurationSerializable;
import de.craftinc.gates.util.LocationSerializer; import de.craftinc.gates.util.LocationUtil;
@ -58,6 +58,12 @@ public class Gate extends BaseGate implements ConfigurationSerializable
} }
public String toString()
{
return super.toString() + " " + this.getId();
}
/* /*
* INTERFACE: ConfigurationSerializable * INTERFACE: ConfigurationSerializable
*/ */
@ -81,22 +87,24 @@ public class Gate extends BaseGate implements ConfigurationSerializable
isHidden = (Boolean)map.get(isHiddenKey); isHidden = (Boolean)map.get(isHiddenKey);
isOpen = (Boolean)map.get(isOpenKey); isOpen = (Boolean)map.get(isOpenKey);
location = LocationSerializer.deserializeLocation((Map<String, Object>) map.get(locationKey)); location = LocationUtil.deserializeLocation((Map<String, Object>) map.get(locationKey));
exit = LocationSerializer.deserializeLocation((Map<String, Object>) map.get(exitKey)); exit = LocationUtil.deserializeLocation((Map<String, Object>) map.get(exitKey));
if (exit != null) { if (map.containsKey(exitPitchKey)) {
exit.setPitch(((Double)map.get(exitPitchKey)).floatValue()); exit.setPitch(((Double)map.get(exitPitchKey)).floatValue());
exit.setYaw(((Double)map.get(exitYawKey)).floatValue()); exit.setYaw(((Double)map.get(exitYawKey)).floatValue());
} }
if (map.containsKey(locationPitchKey)) {
location.setPitch(((Double)map.get(locationPitchKey)).floatValue()); location.setPitch(((Double)map.get(locationPitchKey)).floatValue());
location.setYaw(((Double)map.get(locationYawKey)).floatValue()); location.setYaw(((Double)map.get(locationYawKey)).floatValue());
}
gateBlockLocations = new HashSet<Location>(); gateBlockLocations = new HashSet<Location>();
List<Map<String, Object>> serializedGateBlocks = (List<Map<String, Object>>)map.get(gateBlocksKey); List<Map<String, Object>> serializedGateBlocks = (List<Map<String, Object>>)map.get(gateBlocksKey);
for (Map<String, Object> sgb : serializedGateBlocks) { for (Map<String, Object> sgb : serializedGateBlocks) {
gateBlockLocations.add(LocationSerializer.deserializeLocation(sgb)); gateBlockLocations.add(LocationUtil.deserializeLocation(sgb));
} }
} }
catch (Exception e) { catch (Exception e) {
@ -118,13 +126,14 @@ public class Gate extends BaseGate implements ConfigurationSerializable
validate(); // make sure to not write invalid stuff to disk validate(); // make sure to not write invalid stuff to disk
} }
catch (Exception e) { 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>(); Map<String, Object> retVal = new HashMap<String, Object>();
retVal.put(idKey, id); retVal.put(idKey, id);
retVal.put(locationKey, LocationSerializer.serializeLocation(location)); retVal.put(locationKey, LocationUtil.serializeLocation(location));
retVal.put(exitKey, LocationSerializer.serializeLocation(exit)); retVal.put(exitKey, LocationUtil.serializeLocation(exit));
retVal.put(isHiddenKey, isHidden); retVal.put(isHiddenKey, isHidden);
retVal.put(isOpenKey, isOpen); retVal.put(isOpenKey, isOpen);
@ -139,7 +148,7 @@ public class Gate extends BaseGate implements ConfigurationSerializable
List<Map<String, Object>> serializedGateBlocks = new ArrayList<Map<String, Object>>(); List<Map<String, Object>> serializedGateBlocks = new ArrayList<Map<String, Object>>();
for (Location l : gateBlockLocations) { for (Location l : gateBlockLocations) {
serializedGateBlocks.add(LocationSerializer.serializeLocation(l)); serializedGateBlocks.add(LocationUtil.serializeLocation(l));
} }
retVal.put(gateBlocksKey, serializedGateBlocks); retVal.put(gateBlocksKey, serializedGateBlocks);
@ -179,7 +188,7 @@ public class Gate extends BaseGate implements ConfigurationSerializable
gate.setId(newId); gate.setId(newId);
delete(oldId); instances.remove(oldId);
instances.put(gate.id, gate); instances.put(gate.id, gate);
} }

View File

@ -10,12 +10,15 @@ import java.util.Map;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.configuration.serialization.ConfigurationSerialization; import org.bukkit.configuration.serialization.ConfigurationSerialization;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import de.craftinc.gates.commands.*; 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 permissionInfo = "craftincgates.info";
public static final String permissionManage = "craftincgates.manage"; 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 final String permissionUse = "craftincgates.use";
public static Permission permission = null;
public PluginPlayerListener playerListener = new PluginPlayerListener(); public PluginPlayerListener playerListener = new PluginPlayerListener();
public PluginBlockListener blockListener = new PluginBlockListener(); public PluginBlockListener blockListener = new PluginBlockListener();
public PluginPortalListener portalListener = new PluginPortalListener(); public PluginPortalListener portalListener = new PluginPortalListener();
private File gatesConfigFile;
private FileConfiguration gatesConfig;
private String baseCommand; private String baseCommand;
private String gatesPath = "gates"; private String gatesPath = "gates";
@ -59,12 +67,31 @@ public class Plugin extends JavaPlugin
} }
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 @Override
public void onDisable() public void onDisable()
{ {
// Save gates // Save gates
saveGates(); saveGates();
log("Disabled"); log("Disabled");
} }
@ -72,6 +99,9 @@ public class Plugin extends JavaPlugin
@Override @Override
public void onEnable() public void onEnable()
{ {
// Setup permissions
setupPermissions();
// Add the commands // Add the commands
commands.add(new CommandHelp()); commands.add(new CommandHelp());
commands.add(new CommandCreate()); commands.add(new CommandCreate());
@ -94,6 +124,19 @@ public class Plugin extends JavaPlugin
pm.registerEvents(this.portalListener, this); pm.registerEvents(this.portalListener, this);
// Load gates // 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(); loadGates();
log("Enabled"); log("Enabled");
@ -177,13 +220,11 @@ public class Plugin extends JavaPlugin
public void saveGates() public void saveGates()
{ {
File gatesFile = new File(getDataFolder(), "gates.yml");
FileConfiguration gatesConfig = YamlConfiguration.loadConfiguration(gatesFile);
gatesConfig.set(gatesPath, new ArrayList<Object>(Gate.getAll())); gatesConfig.set(gatesPath, new ArrayList<Object>(Gate.getAll()));
try { try {
gatesConfig.save(gatesFile); gatesConfig.save(gatesConfigFile);
log("Saved gates to disk.");
} }
catch (IOException e) { catch (IOException e) {
log("ERROR: Could not save gates to disk."); 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.ArrayList;
import java.util.List; import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -12,43 +13,36 @@ import de.craftinc.gates.util.TextUtil;
public abstract class BaseCommand public abstract class BaseCommand
{ {
public List<String> aliases; protected List<String> aliases = new ArrayList<String>();
public List<String> requiredParameters; protected List<String> requiredParameters = new ArrayList<String>();
public List<String> optionalParameters; protected List<String> optionalParameters = new ArrayList<String>();
public String helpDescription; protected String helpDescription = "no description";
public CommandSender sender; protected List<String> parameters;
public boolean senderMustBePlayer; protected CommandSender sender;
public boolean hasGateParam; protected Player player;
public Player player; protected Gate gate;
public Gate gate;
public List<String> parameters; protected boolean senderMustBePlayer = true;
protected boolean hasGateParam = true;
public String requiredPermission; protected String requiredPermission;
protected boolean needsPermissionAtCurrentLocation;
protected boolean shouldPersistToDisk;
public BaseCommand() {
aliases = new ArrayList<String>();
requiredParameters = new ArrayList<String>();
optionalParameters = new ArrayList<String>();
senderMustBePlayer = true;
hasGateParam = true;
helpDescription = "no description";
}
public List<String> getAliases() { public List<String> getAliases() {
return aliases; return aliases;
} }
public void execute(CommandSender sender, List<String> parameters) { public void execute(CommandSender sender, List<String> parameters) {
this.sender = sender; this.sender = sender;
this.parameters = parameters; this.parameters = parameters;
if ( ! validateCall()) { if (!this.validateCall()) {
return; return;
} }
@ -56,84 +50,188 @@ public abstract class BaseCommand
this.player = (Player)sender; this.player = (Player)sender;
} }
perform(); this.perform();
if (this.shouldPersistToDisk) {
Plugin.instance.saveGates();
}
} }
public void perform() {
} abstract protected void perform();
public void sendMessage(String message) {
protected void sendMessage(String message) {
sender.sendMessage(message); sender.sendMessage(message);
} }
public void sendMessage(List<String> messages) {
protected void sendMessage(List<String> messages) {
for(String message : messages) { for(String message : messages) {
this.sendMessage(message); this.sendMessage(message);
} }
} }
public boolean validateCall()
protected boolean validateCall()
{ {
// validate player boolean allParamtertersThere = parameters.size() >= requiredParameters.size();
if ( this.senderMustBePlayer && ! (sender instanceof Player)) boolean senderIsPlayer = this.sender instanceof Player;
{ boolean hasGateParameter = false;
sendMessage("This command can only be used by ingame players.");
return false; if (this.hasGateParam == true && this.parameters.size() > 0 && this.setGateUsingParameter(this.parameters.get(0))) {
hasGateParameter = true;
} }
// validate permission boolean senderHasPermission = this.hasPermission();
if( !hasPermission(sender))
boolean valid = false;
if (this.senderMustBePlayer && !senderIsPlayer)
{ {
sendMessage("You lack the permissions to "+this.helpDescription.toLowerCase()+"."); sendMessage(ChatColor.RED + "This command can only be used by ingame players.");
return false; 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 else if (this.hasGateParam && !hasGateParameter)
if (parameters.size() < requiredParameters.size())
{ {
sendMessage("Usage: "+this.getUseageTemplate(true)); sendMessage(ChatColor.RED + "There exists no gate with id " + this.parameters.get(0));
return false; valid = false;
}
else
{
valid = true;
} }
// validate gate parameter return valid;
}
protected boolean setGateUsingParameter(String param)
{
if (!Gate.exists(param))
{
return false;
}
else
{
gate = Gate.get(param);
return true;
}
}
/**
* 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) if (this.hasGateParam)
{ {
String id = parameters.get(0); hasPermission = this.hasPermissionAtGateLocationAndExit(p);
}
if ( ! Gate.exists(id)) 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
{ {
sendMessage("There exists no gate with id "+id);
return false; return false;
} }
gate = Gate.get(id);
}
return true; boolean permAtLocation = Plugin.permission.has(this.gate.getLocation().getWorld(), p.getName(), this.requiredPermission);
}
public boolean hasPermission(CommandSender sender) boolean permAtExit;
if (this.gate.getExit() == null)
{ {
if (sender.hasPermission(Plugin.permissionAll)) { permAtExit = true;
return true; }
else
{
permAtExit = Plugin.permission.has(this.gate.getExit().getWorld(), p.getName(), this.requiredPermission);
} }
if (sender.hasPermission(requiredPermission)) { return permAtLocation & permAtExit;
return true;
} }
return false;
}
// -------------------------------------------- // // -------------------------------------------- //
// Help and usage description // Help and usage description
// -------------------------------------------- // // -------------------------------------------- //
public String getUsageTemplate(boolean withColor, boolean withDescription) { protected String getUsageTemplate(boolean withColor, boolean withDescription) {
String ret = ""; String ret = "";
// if (withColor) { if (withColor) {
// ret += Conf.colorCommand; ret += ChatColor.AQUA;
// } }
ret += "/" + Plugin.instance.getBaseCommand() + " " + TextUtil.implode(this.getAliases(), ",")+" "; ret += "/" + Plugin.instance.getBaseCommand() + " " + TextUtil.implode(this.getAliases(), ",")+" ";
@ -147,23 +245,29 @@ public abstract class BaseCommand
parts.add("*["+optionalParameter+"]"); parts.add("*["+optionalParameter+"]");
} }
// if (withColor) { if (withColor) {
// ret += Conf.colorParameter; ret += ChatColor.DARK_AQUA;
// } }
ret += TextUtil.implode(parts, " "); ret += TextUtil.implode(parts, " ");
// if (withDescription) { if (withDescription) {
// ret += " "+Conf.colorSystem + this.helpDescription; ret += " ";
// }
if (withColor) {
ret += ChatColor.YELLOW;
}
ret += this.helpDescription;
}
return ret; return ret;
} }
public String getUseageTemplate(boolean withColor) { protected String getUseageTemplate(boolean withColor) {
return getUsageTemplate(withColor, false); return getUsageTemplate(withColor, false);
} }
public String getUseageTemplate() { protected String getUseageTemplate() {
return getUseageTemplate(true); return getUseageTemplate(true);
} }
} }

View File

@ -1,5 +1,9 @@
package de.craftinc.gates.commands; package de.craftinc.gates.commands;
import java.util.logging.Level;
import org.bukkit.ChatColor;
import de.craftinc.gates.Plugin; import de.craftinc.gates.Plugin;
@ -8,25 +12,37 @@ public class CommandClose extends BaseCommand
public CommandClose() public CommandClose()
{ {
aliases.add("close"); aliases.add("close");
aliases.add("c");
requiredParameters.add("id"); requiredParameters.add("id");
helpDescription = "Closes a gate to prevent players from using it."; helpDescription = "Closes a gate to prevent players from using it.";
requiredPermission = Plugin.permissionManage; requiredPermission = Plugin.permissionManage;
needsPermissionAtCurrentLocation = false;
shouldPersistToDisk = true;
senderMustBePlayer = false;
} }
@Override @Override
public void perform() public void perform()
{ {
try { try
{
gate.setOpen(false); 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; package de.craftinc.gates.commands;
import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import de.craftinc.gates.Gate; import de.craftinc.gates.Gate;
@ -21,6 +23,11 @@ public class CommandCreate extends BaseLocationCommand
helpDescription = "Create a gate at your current location."; helpDescription = "Create a gate at your current location.";
requiredPermission = Plugin.permissionManage; requiredPermission = Plugin.permissionManage;
needsPermissionAtCurrentLocation = true;
shouldPersistToDisk = true;
senderMustBePlayer = true;
} }
@ -28,27 +35,34 @@ public class CommandCreate extends BaseLocationCommand
{ {
String id = parameters.get(0); String id = parameters.get(0);
try { try
{
gate = Gate.create(id); gate = Gate.create(id);
sendMessage(ChatColor.GREEN + "Gate with id '" + id + "' was created.");
} }
catch (Exception e) { catch (Exception e)
System.out.println(e.getMessage()); {
sendMessage(ChatColor.RED + "Creating the gate failed!" + e.getMessage() + "See server log for more information");
return;
} }
Location playerLocation = getValidPlayerLocation(); Location playerLocation = getValidPlayerLocation();
if (playerLocation != null) { if (playerLocation != null)
try { {
try
{
gate.setLocation(playerLocation); 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 { else
sendMessage("Gate with id \"" + id + "\" was created."); {
sendMessage(ChatColor.GREEN + "Gate with id \"" + id + "\" was created.");
sendMessage("Now you should build a frame and:"); sendMessage("Now you should build a frame and:");
sendMessage(new CommandSetLocation().getUsageTemplate(true, true)); sendMessage(new CommandSetLocation().getUsageTemplate(true, true));
} }

View File

@ -1,5 +1,7 @@
package de.craftinc.gates.commands; package de.craftinc.gates.commands;
import org.bukkit.ChatColor;
import de.craftinc.gates.Gate; import de.craftinc.gates.Gate;
import de.craftinc.gates.Plugin; import de.craftinc.gates.Plugin;
@ -19,13 +21,18 @@ public class CommandDelete extends BaseCommand
helpDescription = "Removes the gate from the game."; helpDescription = "Removes the gate from the game.";
requiredPermission = Plugin.permissionManage; requiredPermission = Plugin.permissionManage;
needsPermissionAtCurrentLocation = false;
shouldPersistToDisk = true;
senderMustBePlayer = false;
} }
public void perform() public void perform()
{ {
Gate.delete(gate.getId()); 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; package de.craftinc.gates.commands;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import de.craftinc.gates.Gate;
import de.craftinc.gates.Plugin;
import de.craftinc.gates.util.TextUtil; import de.craftinc.gates.util.TextUtil;
public class CommandHelp extends BaseCommand 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() public CommandHelp()
{ {
@ -16,13 +56,18 @@ public class CommandHelp extends BaseCommand
aliases.add("?"); aliases.add("?");
optionalParameters.add("page"); 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; return true;
} }
@ -55,40 +100,5 @@ public class CommandHelp extends BaseCommand
sendMessage(helpPages.get(page)); 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; package de.craftinc.gates.commands;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import de.craftinc.gates.Plugin; import de.craftinc.gates.Plugin;
import de.craftinc.gates.util.TextUtil;
public class CommandInfo extends BaseCommand public class CommandInfo extends BaseCommand
@ -11,42 +13,48 @@ public class CommandInfo extends BaseCommand
{ {
aliases.add("info"); aliases.add("info");
aliases.add("details"); aliases.add("details");
aliases.add("i");
aliases.add("d");
requiredParameters.add("id"); requiredParameters.add("id");
helpDescription = "Prints detailed informations about a certain gate."; helpDescription = "Prints detailed informations about a certain gate.";
requiredPermission = Plugin.permissionInfo; requiredPermission = Plugin.permissionInfo;
needsPermissionAtCurrentLocation = false;
shouldPersistToDisk = false;
senderMustBePlayer = false;
} }
public void perform() 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()) if (gate.isOpen())
openHiddenMessage += " open"; openHiddenMessage += ChatColor.AQUA + " open";
else else
openHiddenMessage += " closed"; openHiddenMessage += ChatColor.AQUA + " closed";
if (gate.isHidden()) if (gate.isHidden())
openHiddenMessage += " and hidden"; openHiddenMessage += ChatColor.DARK_AQUA +" and" + ChatColor.AQUA + " hidden";
openHiddenMessage += "."; openHiddenMessage += ".\n";
sendMessage(openHiddenMessage); sendMessage(openHiddenMessage);
if (gate.getLocation() != null) 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 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) 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 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 java.util.List;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import de.craftinc.gates.Gate; import de.craftinc.gates.Gate;
import de.craftinc.gates.Plugin; import de.craftinc.gates.Plugin;
@ -21,33 +22,66 @@ public class CommandList extends BaseCommand
optionalParameters.add("page"); optionalParameters.add("page");
hasGateParam = false; hasGateParam = false;
needsPermissionAtCurrentLocation = false;
helpDescription = "Prints a list of all availible gates."; helpDescription = "lists all availible gates.";
requiredPermission = Plugin.permissionInfo; requiredPermission = Plugin.permissionInfo;
shouldPersistToDisk = false;
senderMustBePlayer = false;
} }
protected String intToTitleString(int i) protected String intToTitleString(int i)
{ {
if ( i < 26 ) { if ( i < 26 ) {
return ChatColor.GREEN + "" + (char)(i+65) + ":"; return ChatColor.DARK_AQUA + "" + (char)(i+65) + ":";
} }
else if ( i == 26 ) { else if ( i == 26 ) {
return ChatColor.GREEN + "0 - 9:"; return ChatColor.DARK_AQUA + "0 - 9:";
} }
else { 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 // pages start at 1
// will return null if requested page not availible // will return null if requested page not availible
protected List<String> message(int page) protected List<String> message(int page)
{ {
Collection<Gate> gates = Gate.getAll(); Collection<Gate> gates = this.getAllGates();
if (gates.size() == 0) { if (gates.size() == 0) {
return null; return null;
@ -119,7 +153,7 @@ public class CommandList extends BaseCommand
linesLeftOnCurrentPage -= numLinesForCurrentChar; linesLeftOnCurrentPage -= numLinesForCurrentChar;
if (currentPage == page) { if (currentPage == page) {
pageMessages.add(TextUtil.implode(currentIds, ", ")); pageMessages.add(ChatColor.AQUA + TextUtil.implode(currentIds, ", "));
if (finishedCurrentIds == false) { if (finishedCurrentIds == false) {
pageMessages.set(pageMessages.size() -2, pageMessages.get(pageMessages.size() -2) + " (more on previous page)"); 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, ", "); String stringToPutOnCurrentPage = TextUtil.implode(idsToPutOnCurrentPage, ", ");
if (currentPage == page) { 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)"); pageMessages.set(pageMessages.size() -2, pageMessages.get(pageMessages.size() -2) + " (more on next page)");
} }
@ -160,12 +194,13 @@ public class CommandList extends BaseCommand
currentPage++; currentPage++;
} }
if (pageMessages.isEmpty()) { if (pageMessages.isEmpty())
{
return null; return null;
} }
else { else {
ArrayList<String> retVal = new ArrayList<String>(); 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); retVal.addAll(pageMessages);
return retVal; return retVal;
@ -173,31 +208,42 @@ public class CommandList extends BaseCommand
} }
public void perform() protected int getPageParameter()
{ {
Collection<Gate> gates = Gate.getAll();
if (gates.size() == 0) {
sendMessage("There are no gates yet.");
}
else {
int page = 1; int page = 1;
try { try {
page = new Integer(parameters.get(0)); page = new Integer(parameters.get(0));
} }
catch (Exception e) { catch (Exception e) { }
return page;
} }
public void perform()
{
int page = this.getPageParameter();
List<String> messages = message(page); List<String> messages = message(page);
if (messages == null) { if (messages == null)
sendMessage("The requested page is not availible"); {
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 { else // the requested page does not exist
{
sendMessage(ChatColor.RED + "The requested page is not availible");
}
}
else
{
sendMessage(messages); sendMessage(messages);
} }
} }
} }
}

View File

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

View File

@ -1,5 +1,7 @@
package de.craftinc.gates.commands; package de.craftinc.gates.commands;
import org.bukkit.ChatColor;
import de.craftinc.gates.Gate; import de.craftinc.gates.Gate;
import de.craftinc.gates.Plugin; import de.craftinc.gates.Plugin;
@ -21,6 +23,10 @@ public class CommandRename extends BaseCommand
helpDescription = "Changes the id of a gate."; helpDescription = "Changes the id of a gate.";
requiredPermission = Plugin.permissionManage; requiredPermission = Plugin.permissionManage;
needsPermissionAtCurrentLocation = false;
shouldPersistToDisk = true;
senderMustBePlayer = false;
} }
@ -28,14 +34,15 @@ public class CommandRename extends BaseCommand
{ {
String newId = parameters.get(1); String newId = parameters.get(1);
try { try
{
Gate.rename(gate.getId(), newId); Gate.rename(gate.getId(), newId);
sendMessage(ChatColor.GREEN + "Gate " + gate.getId() + " is now known as " + newId + ".");
} }
catch (Exception e) { catch (Exception e)
sendMessage("Cannot rename " + gate.getId() + ". There is already a gate named " + newId + "."); {
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; package de.craftinc.gates.commands;
import java.util.logging.Level;
import org.bukkit.ChatColor;
import de.craftinc.gates.Plugin; import de.craftinc.gates.Plugin;
@ -8,27 +12,33 @@ public class CommandSetExit extends BaseCommand
public CommandSetExit() public CommandSetExit()
{ {
aliases.add("setto"); aliases.add("exit");
aliases.add("st"); aliases.add("e");
requiredParameters.add("id"); 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; requiredPermission = Plugin.permissionManage;
needsPermissionAtCurrentLocation = true;
shouldPersistToDisk = true;
senderMustBePlayer = true;
} }
public void perform() public void perform()
{ {
try { try
{
gate.setExit(player.getLocation()); gate.setExit(player.getLocation());
sendMessage(ChatColor.GREEN + "The exit of gate '" + gate.getId() + "' is now where you stand.");
} }
catch (Exception e) { 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; package de.craftinc.gates.commands;
import java.util.logging.Level;
import org.bukkit.ChatColor;
import de.craftinc.gates.Plugin; import de.craftinc.gates.Plugin;
@ -7,26 +11,33 @@ public class CommandSetHidden extends BaseCommand
{ {
public CommandSetHidden() public CommandSetHidden()
{ {
aliases.add("setHidden"); aliases.add("hide");
aliases.add("sh"); aliases.add("h");
requiredParameters.add("id"); requiredParameters.add("id");
helpDescription = "Makes a gate NOT consist of gate blocks while open."; helpDescription = "Makes a gate NOT consist of gate blocks while open.";
requiredPermission = Plugin.permissionManage; requiredPermission = Plugin.permissionManage;
needsPermissionAtCurrentLocation = false;
shouldPersistToDisk = true;
senderMustBePlayer = false;
} }
public void perform() public void perform()
{ {
try { try
{
gate.setHidden(true); gate.setHidden(true);
sendMessage(ChatColor.GREEN + "The gate '" + gate.getId() + "' is now hidden.");
}
catch (Exception e)
{
sendMessage(ChatColor.RED + "Hiding the gate failed! See server log for more information");
Plugin.log(Level.WARNING, e.getMessage());
e.printStackTrace();
} }
catch (Exception e) {
sendMessage(e.getMessage());
}
sendMessage("The gate '" + gate.getId() + "' is now hidden.");
} }
} }

View File

@ -1,6 +1,9 @@
package de.craftinc.gates.commands; package de.craftinc.gates.commands;
import java.util.logging.Level;
import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import de.craftinc.gates.Plugin; import de.craftinc.gates.Plugin;
@ -11,14 +14,18 @@ public class CommandSetLocation extends BaseLocationCommand
public CommandSetLocation() public CommandSetLocation()
{ {
aliases.add("setlocation"); aliases.add("location");
aliases.add("sl"); aliases.add("l");
requiredParameters.add("id"); requiredParameters.add("id");
helpDescription = "Set the entrance of the gate to your current location."; helpDescription = "Set the entrance of the gate to your current location.";
requiredPermission = Plugin.permissionManage; requiredPermission = Plugin.permissionManage;
needsPermissionAtCurrentLocation = true;
shouldPersistToDisk = true;
senderMustBePlayer = true;
} }
@ -26,19 +33,23 @@ public class CommandSetLocation extends BaseLocationCommand
{ {
Location playerLocation = getValidPlayerLocation(); Location playerLocation = getValidPlayerLocation();
if (playerLocation == null) { if (playerLocation == null)
{
sendMessage("There is not enough room for a gate to open here"); sendMessage("There is not enough room for a gate to open here");
return; return;
} }
try { try
{
gate.setLocation(playerLocation); gate.setLocation(playerLocation);
sendMessage(ChatColor.GREEN + "The location of '" + gate.getId() + "' is now at your current location.");
} }
catch (Exception e) { catch (Exception e)
sendMessage(e.getMessage()); {
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; package de.craftinc.gates.commands;
import org.bukkit.ChatColor;
import de.craftinc.gates.Plugin; import de.craftinc.gates.Plugin;
@ -8,27 +10,33 @@ public class CommandSetVisible extends BaseCommand
public CommandSetVisible() public CommandSetVisible()
{ {
aliases.add("makevisible"); aliases.add("unhide");
aliases.add("mv"); aliases.add("uh");
requiredParameters.add("id"); requiredParameters.add("id");
helpDescription = "Make that gate visible"; helpDescription = "Make that gate visible";
requiredPermission = Plugin.permissionManage; requiredPermission = Plugin.permissionManage;
needsPermissionAtCurrentLocation = false;
shouldPersistToDisk = true;
senderMustBePlayer = false;
} }
public void perform() public void perform()
{ {
try { try
{
gate.setHidden(false); gate.setHidden(false);
sendMessage(ChatColor.GREEN + "The gate " + gate.getId() + " is now visible.");
} }
catch (Exception e) { 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 java.util.logging.Level;
import org.bukkit.ChatColor;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
@ -14,9 +15,10 @@ import org.bukkit.event.player.PlayerMoveEvent;
import de.craftinc.gates.Gate; import de.craftinc.gates.Gate;
import de.craftinc.gates.Plugin; 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) @EventHandler(priority = EventPriority.NORMAL)
public void onPlayerMove(PlayerMoveEvent event) public void onPlayerMove(PlayerMoveEvent event)
@ -25,19 +27,21 @@ public class PluginPlayerListener extends BaseLocationListener implements Listen
return; return;
} }
// Check for permission
if (!hasPermission(event.getPlayer())) {
return;
}
// Find the gate at the current location. // Find the gate at the current location.
Gate gateAtLocation = getValidGateAtPlayerLocation(event); Gate gateAtLocation = GateUtil.getGateAtPlayerLocation(event.getTo());
if (gateAtLocation == null) { if (gateAtLocation == null) {
return; 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 // Teleport the player
checkChunkLoad(gateAtLocation.getLocation().getBlock()); checkChunkLoad(gateAtLocation.getLocation().getBlock());
@ -56,6 +60,8 @@ public class PluginPlayerListener extends BaseLocationListener implements Listen
event.getPlayer().teleport(teleportToLocation); event.getPlayer().teleport(teleportToLocation);
event.setTo(teleportToLocation); event.setTo(teleportToLocation);
event.getPlayer().sendMessage(ChatColor.DARK_AQUA + "Thank you for traveling with Craft Inc. Gates.");
} }
@ -72,7 +78,17 @@ public class PluginPlayerListener extends BaseLocationListener implements Listen
} }
protected boolean hasPermission(Player player) { protected boolean hasPermission(Player player, Gate gate)
return player.hasPermission(Plugin.permissionUse) || player.hasPermission(Plugin.permissionAll); {
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,90 @@
package de.craftinc.gates.listeners; 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.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityPortalEnterEvent;
import org.bukkit.event.player.PlayerPortalEvent; import org.bukkit.event.player.PlayerPortalEvent;
import de.craftinc.gates.Gate; import de.craftinc.gates.Gate;
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) @EventHandler(priority = EventPriority.NORMAL)
public void onPlayerPortal(PlayerPortalEvent event) public void onPlayerPortal(PlayerPortalEvent event)
{ {
if (event.isCancelled()) { if (event.isCancelled())
{
return; return;
} }
// Find the gate at the current location. Location playerLocation = event.getPlayer().getLocation();
Gate gateAtLocation = getGateAtPlayerLocation(event); Gate gateAtLocation = GateUtil.getGateAtPlayerLocation(playerLocation);
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); 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);
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 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> exp1 = new HashSet<BlockFace>();
private static final Set<BlockFace> exp2 = 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> blocks1 = getAirFloodBlocks(block, new HashSet<Block>(), exp1, frameBlockSearchLimit);
Set<Block> blocks2 = getAirFloodBlocks(block, new HashSet<Block>(), exp2, frameBlockSearchLimit); Set<Block> blocks2 = getAirFloodBlocks(block, new HashSet<Block>(), exp2, frameBlockSearchLimit);
if (blocks1 == null && blocks2 == null) { if (blocks1 == null && blocks2 == null)
{
return null; return null;
} }
if (blocks1 == null) { if (blocks1 == null)
{
return blocks2; return blocks2;
} }
if (blocks2 == null) { if (blocks2 == null)
{
return blocks1; return blocks1;
} }
if (blocks1.size() > blocks2.size()) { if (blocks1.size() > blocks2.size())
{
return blocks2; 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) if (foundBlocks == null)
{
return null; return null;
}
if (foundBlocks.size() > limit) 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. * 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 worldKey = "world";
protected static String xKey = "x"; protected static String xKey = "x";
@ -83,4 +83,23 @@ public class LocationSerializer
return new Location(w, x, y, z); 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;
}
} }