Compare commits
68 Commits
version2.0
...
version2.1
Author | SHA1 | Date | |
---|---|---|---|
8c6718d13f | |||
6a34d44f20 | |||
b196c53335 | |||
d54fd7f72e | |||
cede47deab | |||
1ef178f6a0 | |||
802f8c07e3 | |||
a8a95af497 | |||
0af3631693 | |||
4d40b140fa | |||
8830355216 | |||
3481c2a10f | |||
a319f793b2 | |||
6373f98894 | |||
e49c5c0acb | |||
a0bc62f767 | |||
850fbf1515 | |||
b99ecec448 | |||
3a7be837b5 | |||
1bfc886969 | |||
880071140a | |||
5b1ac6e8f7 | |||
08906f6004 | |||
e54914bd22 | |||
606ea1d5c5 | |||
b072229914 | |||
0b8be1ec4b | |||
1fef272af2 | |||
26927d35c2 | |||
c79a856907 | |||
c25bb01aa1 | |||
68bf008bc4 | |||
638afcc82f | |||
f020096126 | |||
a4ee78b88a | |||
f3a87516d6 | |||
984069ff35 | |||
0dacfaa79b | |||
02262880da | |||
9ce65ed26d | |||
db173521e4 | |||
16095226f9 | |||
3ea11da591 | |||
59fdb54a09 | |||
02b904a78d | |||
0117e7294a | |||
1de6812eb6 | |||
26e5b68a7d | |||
f09b90f0a6 | |||
32f1cba2bd | |||
56a5f828ee | |||
cd0ebc3a7a | |||
dd5a60cb2a | |||
32fc475a8a | |||
43f002032d | |||
cf2155ab40 | |||
b9e84b122d | |||
749c04f585 | |||
dae92a0357 | |||
ca982f5ba9 | |||
5b4036ac7c | |||
bf1f2bcff2 | |||
ead21c0b79 | |||
ed58f762fe | |||
59a7f4f80e | |||
58695cadd3 | |||
cab78c34cc | |||
e407d2b9fa |
@ -1,7 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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/Vault.jar"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="lib" path="/Users/tobi/Code/craftbukkit-1.5.1-R0.1.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
78
README.md
78
README.md
@ -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 won’t 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.
|
21
changelog.md
Normal file
21
changelog.md
Normal file
@ -0,0 +1,21 @@
|
||||
## 2.1.1
|
||||
* Made the list command more reliable.
|
||||
* Error messages will be displayed less frequent.
|
||||
## 2.1.0
|
||||
* 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
|
@ -1,7 +1,8 @@
|
||||
name: Craft Inc. Gates
|
||||
version: 2.0.1
|
||||
version: 2.1.1
|
||||
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
13
pom.xml
@ -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
1
resources/plugin.yml
Symbolic link
@ -0,0 +1 @@
|
||||
../plugin.yml
|
@ -190,6 +190,6 @@ public abstract class BaseGate
|
||||
throw new Exception("Gate got closed. The frame is missing or broken.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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,22 +87,24 @@ 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 (exit != null) {
|
||||
if (map.containsKey(exitPitchKey)) {
|
||||
exit.setPitch(((Double)map.get(exitPitchKey)).floatValue());
|
||||
exit.setYaw(((Double)map.get(exitYawKey)).floatValue());
|
||||
}
|
||||
|
||||
location.setPitch(((Double)map.get(locationPitchKey)).floatValue());
|
||||
location.setYaw(((Double)map.get(locationYawKey)).floatValue());
|
||||
if (map.containsKey(locationPitchKey)) {
|
||||
location.setPitch(((Double)map.get(locationPitchKey)).floatValue());
|
||||
location.setYaw(((Double)map.get(locationYawKey)).floatValue());
|
||||
}
|
||||
|
||||
gateBlockLocations = new HashSet<Location>();
|
||||
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) {
|
||||
@ -118,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);
|
||||
|
||||
@ -139,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);
|
||||
@ -179,7 +188,7 @@ public class Gate extends BaseGate implements ConfigurationSerializable
|
||||
|
||||
gate.setId(newId);
|
||||
|
||||
delete(oldId);
|
||||
instances.remove(oldId);
|
||||
instances.put(gate.id, gate);
|
||||
}
|
||||
|
||||
|
@ -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.");
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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.");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
@ -14,6 +15,15 @@ import de.craftinc.gates.util.TextUtil;
|
||||
|
||||
public class CommandList extends BaseCommand
|
||||
{
|
||||
protected static final int linesPerPage = 10;
|
||||
protected static final int charactersPerLine = 52; /* this is actually no true. the
|
||||
font used by minecraft is not
|
||||
monospace. but I don't think
|
||||
there is a (easy) way for a
|
||||
bukkit plugin to calculate
|
||||
the drawing-size of a string.
|
||||
*/
|
||||
|
||||
public CommandList()
|
||||
{
|
||||
aliases.add("list");
|
||||
@ -21,51 +31,157 @@ 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)
|
||||
protected static List<String> linesOfGateIds(List<String> gates)
|
||||
{
|
||||
List<String> lines = new ArrayList<String>();
|
||||
|
||||
int index = 0;
|
||||
List<String> gateIdsForCurrentLine = new ArrayList<String>();
|
||||
int numCharactersInCurrentLine = 0;
|
||||
|
||||
|
||||
while (index < gates.size()) {
|
||||
String gateId = gates.get(index);
|
||||
int gateIdLength = gateId.length() + 2; // actual length + comma + whitespace
|
||||
|
||||
// special case: very long gate id
|
||||
if (gateIdLength > charactersPerLine && numCharactersInCurrentLine == 0) {
|
||||
gateIdsForCurrentLine = new ArrayList<String>();
|
||||
numCharactersInCurrentLine = 0;
|
||||
|
||||
while ((gateId.length() + 2) > charactersPerLine) {
|
||||
|
||||
int cutPos = charactersPerLine;
|
||||
|
||||
// is the id too long to add comma and whitespace but not longer than the line?
|
||||
if (gateId.length() <= charactersPerLine) {
|
||||
cutPos -= 2;
|
||||
}
|
||||
|
||||
lines.add(gateId.substring(0, cutPos));
|
||||
gateId = gateId.substring(cutPos, gateId.length());
|
||||
|
||||
}
|
||||
|
||||
gateIdsForCurrentLine.add(gateId);
|
||||
|
||||
numCharactersInCurrentLine += gateId.length();
|
||||
index++;
|
||||
}
|
||||
|
||||
// gate fits into current line
|
||||
else if ((numCharactersInCurrentLine + gateIdLength) <= charactersPerLine) {
|
||||
gateIdsForCurrentLine.add(gateId);
|
||||
numCharactersInCurrentLine += gateIdLength;
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
// the current gate does not fit on the
|
||||
else {
|
||||
lines.add(TextUtil.implode(gateIdsForCurrentLine, ", ") + ", ");
|
||||
|
||||
gateIdsForCurrentLine = new ArrayList<String>();
|
||||
numCharactersInCurrentLine = 0;
|
||||
}
|
||||
}
|
||||
|
||||
lines.add(TextUtil.implode(gateIdsForCurrentLine, ", "));
|
||||
return lines;
|
||||
}
|
||||
|
||||
|
||||
protected static String intToTitleString(int i, boolean addPreviousPageNote, boolean addNextPageNote)
|
||||
{
|
||||
String retVal = ChatColor.DARK_AQUA + "";
|
||||
|
||||
if ( i < 26 ) {
|
||||
return ChatColor.GREEN + "" + (char)(i+65) + ":";
|
||||
retVal += (char)(i+65);
|
||||
}
|
||||
else if ( i == 26 ) {
|
||||
return ChatColor.GREEN + "0 - 9:";
|
||||
retVal += "0-9";
|
||||
}
|
||||
else {
|
||||
return ChatColor.GREEN + "!@#$:";
|
||||
retVal += "!@#$";
|
||||
}
|
||||
|
||||
if (addPreviousPageNote && addNextPageNote) {
|
||||
retVal += " (more on previous and next page)";
|
||||
}
|
||||
else if (addPreviousPageNote) {
|
||||
retVal += " (more on previous page)";
|
||||
}
|
||||
else if (addNextPageNote) {
|
||||
retVal += " (more on next page)";
|
||||
}
|
||||
|
||||
return retVal + "\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
// pages start at 1
|
||||
// will return null if requested page not availible
|
||||
protected List<String> message(int page)
|
||||
/**
|
||||
* Method for getting a collection of gates the player is allowed to see.
|
||||
*/
|
||||
protected Collection<Gate> getAllGates()
|
||||
{
|
||||
Collection<Gate> gates = Gate.getAll();
|
||||
|
||||
if (gates.size() == 0) {
|
||||
return null;
|
||||
if (this.sender instanceof Player && Plugin.permission != null) {
|
||||
Player p = (Player)this.sender;
|
||||
|
||||
// create a copy since we cannot iterate over a collection while modifying it!
|
||||
Collection<Gate> gatesCopy = new ArrayList<Gate>(gates);
|
||||
|
||||
for (Gate gate : gatesCopy) {
|
||||
|
||||
boolean permissionAtGateLocation = Plugin.permission.has(gate.getLocation().getWorld(), p.getName(), this.requiredPermission);
|
||||
if (!permissionAtGateLocation) {
|
||||
gates.remove(gate);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (gate.getExit() != null) {
|
||||
|
||||
boolean permissionAtGateExit = Plugin.permission.has(gate.getExit().getWorld(), p.getName(), this.requiredPermission);
|
||||
if (!permissionAtGateExit) {
|
||||
gates.remove(gate);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* sort all gates by there first character
|
||||
* put gates in corresponding Lists
|
||||
* list 0-25: a,b,c, ... ,z
|
||||
* list 26: 0-9
|
||||
* list 27: other
|
||||
*/
|
||||
return gates;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sorts all gates by there first character.
|
||||
* Puts gates in corresponding Lists: (all returned lists will be sorted alphabetically)
|
||||
* list 0-25: a,b,c,..,z
|
||||
* list 26: 0-9
|
||||
* list 27: other
|
||||
*/
|
||||
protected static List<List<String>> gatesSortedByName(Collection<Gate> allGates)
|
||||
{
|
||||
// create the lists
|
||||
List<List<String>> ids = new ArrayList<List<String>>();
|
||||
|
||||
for (int i=0; i<28; i++) {
|
||||
ids.add(new ArrayList<String>());
|
||||
}
|
||||
|
||||
for (Gate gate : gates) {
|
||||
// put all gates into correct lists
|
||||
for (Gate gate : allGates) {
|
||||
String id = gate.getId();
|
||||
int first = id.charAt(0);
|
||||
|
||||
@ -85,119 +201,139 @@ public class CommandList extends BaseCommand
|
||||
ids.get(first).add(id);
|
||||
}
|
||||
|
||||
// sort everything
|
||||
for (int i=0; i<28; i++) {
|
||||
Collections.sort(ids.get(i));
|
||||
}
|
||||
|
||||
/* calculating which gates will be displayed on which page.
|
||||
* this is a little bit fuzzy. but hopefully it will look
|
||||
* great. (tell me if there is a better way!)
|
||||
*/
|
||||
return ids;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a list of strings.
|
||||
* Each string is the text for a page.
|
||||
* The maximum number of lines per page is 'linesPerPage' minus 1.
|
||||
* Will return an empty list if no gates are availible.
|
||||
*/
|
||||
protected List<String> pagedGateIds()
|
||||
{
|
||||
Collection<Gate> gates = this.getAllGates();
|
||||
|
||||
int currentPage = 1;
|
||||
int currentStartingCharList = 0;
|
||||
boolean finishedCurrentIds = true;
|
||||
if (gates.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<String> pageMessages = new ArrayList<String>();
|
||||
List<List<String>> gatesSortedByName = gatesSortedByName(gates);
|
||||
List<String> allPages = new ArrayList<String>();
|
||||
int linesLeftOnPage = linesPerPage - 1;
|
||||
String currentPageString = "";
|
||||
|
||||
while (currentStartingCharList < ids.size()) {
|
||||
int linesLeftOnCurrentPage = 9;
|
||||
for (int i=0; i<gatesSortedByName.size(); i++) {
|
||||
|
||||
while (linesLeftOnCurrentPage > 1 && currentStartingCharList < ids.size()) {
|
||||
List<String> currentIds = ids.get(currentStartingCharList);
|
||||
|
||||
if (currentIds.size() > 0) {
|
||||
// add header line
|
||||
if (currentPage == page) {
|
||||
pageMessages.add(intToTitleString(currentStartingCharList));
|
||||
}
|
||||
|
||||
//sort
|
||||
Collections.sort(currentIds);
|
||||
|
||||
// add ids
|
||||
int numLinesForCurrentChar = TextUtil.implode(currentIds, ", ").length() / 52 + 2;
|
||||
|
||||
if (numLinesForCurrentChar <= linesLeftOnCurrentPage) { // all ids fit on current page
|
||||
linesLeftOnCurrentPage -= numLinesForCurrentChar;
|
||||
|
||||
if (currentPage == page) {
|
||||
pageMessages.add(TextUtil.implode(currentIds, ", "));
|
||||
if (finishedCurrentIds == false) {
|
||||
pageMessages.set(pageMessages.size() -2, pageMessages.get(pageMessages.size() -2) + " (more on previous page)");
|
||||
}
|
||||
}
|
||||
|
||||
finishedCurrentIds = true;
|
||||
}
|
||||
else { // NOT all ids fit on current page
|
||||
int charsAvailible = (linesLeftOnCurrentPage - 1) * 52;
|
||||
int idsPos = 0;
|
||||
|
||||
do {
|
||||
charsAvailible -= currentIds.get(idsPos).length() + 2;
|
||||
idsPos++;
|
||||
} while (charsAvailible > 0);
|
||||
|
||||
List<String> idsToPutOnCurrentPage = currentIds.subList(0, idsPos);
|
||||
currentIds.remove(idsToPutOnCurrentPage);
|
||||
|
||||
String stringToPutOnCurrentPage = TextUtil.implode(idsToPutOnCurrentPage, ", ");
|
||||
|
||||
if (currentPage == page) {
|
||||
pageMessages.add(stringToPutOnCurrentPage);
|
||||
pageMessages.set(pageMessages.size() -2, pageMessages.get(pageMessages.size() -2) + " (more on next page)");
|
||||
}
|
||||
|
||||
linesLeftOnCurrentPage -= stringToPutOnCurrentPage.length() / 52 + 2;
|
||||
|
||||
finishedCurrentIds = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (finishedCurrentIds) {
|
||||
currentStartingCharList++;
|
||||
}
|
||||
List<String> currentGates = gatesSortedByName.get(i);
|
||||
|
||||
if(currentGates.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
currentPage++;
|
||||
List<String> currentGatesAsLines = linesOfGateIds(currentGates);
|
||||
boolean moreGatesOnLastPage = false;
|
||||
|
||||
while (!currentGatesAsLines.isEmpty()) {
|
||||
|
||||
if (linesLeftOnPage < 2) {
|
||||
currentPageString = currentPageString.substring(0, currentPageString.length()-2); // remove newlines add the end of the page
|
||||
allPages.add(currentPageString);
|
||||
currentPageString = "";
|
||||
|
||||
linesLeftOnPage = linesPerPage - 1;
|
||||
}
|
||||
|
||||
// calculate number of lines to add to current page
|
||||
int linesNecessaryForCurrentGates = currentGatesAsLines.size();
|
||||
int linesToFill;
|
||||
boolean moreGatesOnNextPage;
|
||||
|
||||
if (linesNecessaryForCurrentGates < linesLeftOnPage) {
|
||||
linesToFill = linesNecessaryForCurrentGates;
|
||||
moreGatesOnNextPage = false;
|
||||
}
|
||||
else {
|
||||
linesToFill = linesLeftOnPage -1;
|
||||
moreGatesOnNextPage = true;
|
||||
}
|
||||
|
||||
// add title
|
||||
currentPageString += intToTitleString(i, moreGatesOnLastPage, moreGatesOnNextPage);
|
||||
currentPageString += ChatColor.AQUA;
|
||||
linesLeftOnPage--;
|
||||
|
||||
// add gate lines
|
||||
for (int j=0; j<linesToFill; j++) {
|
||||
currentPageString += currentGatesAsLines.get(j) + "\n";
|
||||
}
|
||||
|
||||
// remove lines added
|
||||
for (int j=0; j<linesToFill; j++) {
|
||||
currentGatesAsLines.remove(0);
|
||||
}
|
||||
|
||||
// cleanup
|
||||
if (linesNecessaryForCurrentGates < linesLeftOnPage) {
|
||||
moreGatesOnLastPage = false;
|
||||
}
|
||||
else {
|
||||
moreGatesOnLastPage = true;
|
||||
}
|
||||
|
||||
linesLeftOnPage -= linesToFill;
|
||||
}
|
||||
}
|
||||
|
||||
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.addAll(pageMessages);
|
||||
|
||||
return retVal;
|
||||
// add the last page
|
||||
if (!currentPageString.isEmpty()) {
|
||||
currentPageString = currentPageString.substring(0, currentPageString.length()-2); // remove newlines add the end of the page
|
||||
allPages.add(currentPageString);
|
||||
}
|
||||
|
||||
return allPages;
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
List<String> allPages = this.pagedGateIds();
|
||||
|
||||
if (allPages == null) { // 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)");
|
||||
return;
|
||||
}
|
||||
|
||||
if (page > allPages.size() || page < 1) {
|
||||
sendMessage(ChatColor.RED + "The requested page is not availible");
|
||||
return;
|
||||
}
|
||||
|
||||
if (gates.size() == 0) {
|
||||
sendMessage("There are no gates yet.");
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
String message = TextUtil.titleize("List of all gates (" + page + "/" + allPages.size() + ")") + "\n";
|
||||
message += allPages.get(page-1);
|
||||
|
||||
sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -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 + ".");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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,33 @@ 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
|
||||
{
|
||||
gate.setExit(player.getLocation());
|
||||
sendMessage(ChatColor.GREEN + "The exit of gate '" + gate.getId() + "' is now where you stand.");
|
||||
}
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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.");
|
||||
}
|
||||
}
|
@ -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.");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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.");
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -1,7 +1,10 @@
|
||||
package de.craftinc.gates.listeners;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@ -14,10 +17,13 @@ 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
|
||||
{
|
||||
protected HashMap<String, Long> lastBorderMessage = new HashMap<String, Long>();
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPlayerMove(PlayerMoveEvent event)
|
||||
{
|
||||
@ -25,19 +31,36 @@ 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)) {
|
||||
|
||||
String playerName = event.getPlayer().getName();
|
||||
|
||||
if (playerName == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// get the current time
|
||||
Long now = Calendar.getInstance().getTimeInMillis();
|
||||
|
||||
// do not display messages more often than once per second
|
||||
if (!this.lastBorderMessage.containsKey(playerName) || this.lastBorderMessage.get(playerName) < now - 10000L) {
|
||||
event.getPlayer().sendMessage(ChatColor.RED + "You are not allowed to use this gate!");
|
||||
this.lastBorderMessage.put(playerName, now);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Teleport the player
|
||||
checkChunkLoad(gateAtLocation.getLocation().getBlock());
|
||||
|
||||
@ -56,6 +79,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 +89,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 +97,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: 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,27 +1,90 @@
|
||||
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.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);
|
||||
|
||||
if (distToClosestGate < 2.0) {
|
||||
this.currentGateAtEvent.put(player, closestGate);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.currentGateAtEvent.put(player, null);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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)
|
||||
{
|
||||
|
83
src/de/craftinc/gates/util/GateUtil.java
Normal file
83
src/de/craftinc/gates/util/GateUtil.java
Normal 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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user