Compare commits
22 Commits
version2.1
...
version2.1
Author | SHA1 | Date | |
---|---|---|---|
7f8b8eee0f | |||
e0b30135cc | |||
1056fbf969 | |||
916dc1b3a1 | |||
4b7fff2277 | |||
ed2683affc | |||
cac6eb6022 | |||
8c6718d13f | |||
6a34d44f20 | |||
b196c53335 | |||
d54fd7f72e | |||
cede47deab | |||
1ef178f6a0 | |||
802f8c07e3 | |||
a8a95af497 | |||
0af3631693 | |||
4d40b140fa | |||
8830355216 | |||
3481c2a10f | |||
a319f793b2 | |||
6373f98894 | |||
e49c5c0acb |
@ -1,12 +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" sourcepath="//Users/tobi/Code/Bukkit">
|
||||
<attributes>
|
||||
<attribute name="source_encoding" value="UTF-8"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="lib" path="/Users/tobi/Code/Vault.jar"/>
|
||||
<classpathentry kind="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>
|
||||
|
@ -1,4 +1,10 @@
|
||||
## 2.1.0 (not yet released)
|
||||
## 2.1.2
|
||||
* Fixed a bug where players got teleported one block beside the real portal.
|
||||
* Fixed a bug where gates with no location caused multiply exceptions.
|
||||
## 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.
|
||||
|
@ -1,5 +1,5 @@
|
||||
name: Craft Inc. Gates
|
||||
version: 2.1.0-beta
|
||||
version: 2.1.2
|
||||
description: A plugin to create gates for fast traveling.
|
||||
softdepend: [Vault]
|
||||
author: tomco, s1m0ne
|
||||
|
68
pom.xml
68
pom.xml
@ -5,41 +5,79 @@
|
||||
<groupId>de.craftinc</groupId>
|
||||
<artifactId>CraftIncGates</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.1.1</version>
|
||||
<version>2.1.2</version>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>src</sourceDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}/lib</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<version>1.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>Run Test Bukkit Server</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<executable>${basedir}/scripts/test-deployment.sh</executable>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>RELEASE</version>
|
||||
<version>1.5.2-R0.1</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
<version>1.5.2-R0.1</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.milkbowl.vault</groupId>
|
||||
<artifactId>Vault</artifactId>
|
||||
<version>1.2.23-SNAPSHOT</version>
|
||||
<version>1.2.26-SNAPSHOT</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<directory>target</directory>
|
||||
<outputDirectory>target/classes</outputDirectory>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
<sourceDirectory>src</sourceDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>resources</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>bukkit-repo</id>
|
||||
|
@ -177,7 +177,7 @@ public abstract class BaseGate
|
||||
throw new Exception("Gate got closed. It has no exit.");
|
||||
}
|
||||
|
||||
if (gateBlockLocations.size() == 0) {
|
||||
if (gateBlockLocations == null || gateBlockLocations.size() == 0) {
|
||||
setOpen(false);
|
||||
throw new Exception("Gate got closed. The frame is missing or broken.");
|
||||
}
|
||||
|
@ -142,8 +142,10 @@ public class Gate extends BaseGate implements ConfigurationSerializable
|
||||
retVal.put(exitYawKey, exit.getYaw());
|
||||
}
|
||||
|
||||
retVal.put(locationPitchKey, location.getPitch());
|
||||
retVal.put(locationYawKey, location.getYaw());
|
||||
if (location != null) {
|
||||
retVal.put(locationPitchKey, location.getPitch());
|
||||
retVal.put(locationYawKey, location.getYaw());
|
||||
}
|
||||
|
||||
List<Map<String, Object>> serializedGateBlocks = new ArrayList<Map<String, Object>>();
|
||||
|
||||
|
@ -142,7 +142,7 @@ public abstract class BaseCommand
|
||||
*/
|
||||
protected boolean hasPermission()
|
||||
{
|
||||
if (Plugin.permission == null) // fallback <20> use the standard bukkit permission system
|
||||
if (Plugin.permission == null) // fallback <20> use the standard bukkit permission system
|
||||
{
|
||||
return this.sender.hasPermission(this.requiredPermission);
|
||||
}
|
||||
@ -156,7 +156,7 @@ public abstract class BaseCommand
|
||||
}
|
||||
else
|
||||
{
|
||||
// sender is no player <20> there is no information about the senders locations
|
||||
// sender is no player <20> there is no information about the senders locations
|
||||
return Plugin.permission.has(this.sender, this.requiredPermission);
|
||||
}
|
||||
|
||||
@ -205,17 +205,23 @@ public abstract class BaseCommand
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean permAtLocation = Plugin.permission.has(this.gate.getLocation().getWorld(), p.getName(), this.requiredPermission);
|
||||
|
||||
boolean permAtLocation;
|
||||
|
||||
if (this.gate.getLocation() == null) {
|
||||
permAtLocation = true;
|
||||
}
|
||||
else {
|
||||
permAtLocation = Plugin.permission.has(this.gate.getLocation().getWorld(), p.getName(), this.requiredPermission);
|
||||
}
|
||||
|
||||
|
||||
boolean permAtExit;
|
||||
|
||||
if (this.gate.getExit() == null)
|
||||
{
|
||||
if (this.gate.getExit() == null) {
|
||||
permAtExit = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
permAtExit = Plugin.permission.has(this.gate.getExit().getWorld(), p.getName(), this.requiredPermission);
|
||||
}
|
||||
|
||||
|
@ -42,12 +42,14 @@ public class CommandCreate extends BaseLocationCommand
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
sendMessage(ChatColor.RED + "Creating the gate failed!" + e.getMessage() + "See server log for more information");
|
||||
sendMessage(ChatColor.RED + "Creating the gate failed!" + e.getMessage() + " See server log for more information");
|
||||
return;
|
||||
}
|
||||
|
||||
Location playerLocation = getValidPlayerLocation();
|
||||
|
||||
Plugin.log("player location:" + playerLocation);
|
||||
|
||||
if (playerLocation != null)
|
||||
{
|
||||
try
|
||||
@ -62,8 +64,7 @@ public class CommandCreate extends BaseLocationCommand
|
||||
}
|
||||
else
|
||||
{
|
||||
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 execute:");
|
||||
sendMessage(new CommandSetLocation().getUsageTemplate(true, true));
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ public class CommandInfo extends BaseCommand
|
||||
|
||||
requiredParameters.add("id");
|
||||
|
||||
helpDescription = "Prints detailed informations about a certain gate.";
|
||||
helpDescription = "Print detailed informations about a certain gate.";
|
||||
|
||||
requiredPermission = Plugin.permissionInfo;
|
||||
|
||||
@ -49,12 +49,12 @@ public class CommandInfo extends BaseCommand
|
||||
if (gate.getLocation() != null)
|
||||
sendMessage(ChatColor.DARK_AQUA + "from: " + ChatColor.AQUA + "( " + gate.getLocation().getBlockX() + " | " + gate.getLocation().getBlockY() + " | " + gate.getLocation().getBlockZ() + " ) in " + gate.getLocation().getWorld().getName());
|
||||
else
|
||||
sendMessage(ChatColor.DARK_AQUA + "NOTE: this gate has no 'from' location");
|
||||
sendMessage(ChatColor.DARK_AQUA + "NOTE: this gate has no location");
|
||||
|
||||
if (gate.getExit() != null)
|
||||
sendMessage(ChatColor.DARK_AQUA + "to: " + ChatColor.AQUA + "( " + gate.getExit().getBlockX() + " | " + gate.getExit().getBlockY() + " | " + gate.getExit().getBlockZ() + " ) in " + gate.getExit().getWorld().getName());
|
||||
else
|
||||
sendMessage(ChatColor.DARK_AQUA + "NOTE: this gate has no 'to' location");
|
||||
sendMessage(ChatColor.DARK_AQUA + "NOTE: this gate has no exit");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,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");
|
||||
@ -32,42 +41,123 @@ public class CommandList extends BaseCommand
|
||||
}
|
||||
|
||||
|
||||
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.DARK_AQUA + "" + (char)(i+65) + ":";
|
||||
retVal += (char)(i+65);
|
||||
}
|
||||
else if ( i == 26 ) {
|
||||
return ChatColor.DARK_AQUA + "0 - 9:";
|
||||
retVal += "0-9";
|
||||
}
|
||||
else {
|
||||
return ChatColor.DARK_AQUA + "!@#$:";
|
||||
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";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Method for returning a collection of gates the player is allowed to see.
|
||||
* Method for getting 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)
|
||||
{
|
||||
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!
|
||||
|
||||
// create a copy since we cannot iterate over a collection while modifying it!
|
||||
Collection<Gate> gatesCopy = new ArrayList<Gate>(gates);
|
||||
|
||||
for (Gate gate : gatesCopy) {
|
||||
|
||||
if (!Plugin.permission.has(gate.getLocation().getWorld(), p.getName(), this.requiredPermission))
|
||||
{
|
||||
gates.remove(gate);
|
||||
if (gate.getLocation() != null) {
|
||||
boolean permissionAtGateLocation = Plugin.permission.has(gate.getLocation().getWorld(), p.getName(), this.requiredPermission);
|
||||
if (!permissionAtGateLocation) {
|
||||
gates.remove(gate);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (gate.getExit() != null && !Plugin.permission.has(gate.getExit().getWorld(), p.getName(), this.requiredPermission))
|
||||
{
|
||||
gates.remove(gate);
|
||||
|
||||
if (gate.getExit() != null) {
|
||||
|
||||
boolean permissionAtGateExit = Plugin.permission.has(gate.getExit().getWorld(), p.getName(), this.requiredPermission);
|
||||
if (!permissionAtGateExit) {
|
||||
gates.remove(gate);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -76,30 +166,24 @@ public class CommandList extends BaseCommand
|
||||
}
|
||||
|
||||
|
||||
|
||||
// pages start at 1
|
||||
// will return null if requested page not availible
|
||||
protected List<String> message(int page)
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
Collection<Gate> gates = this.getAllGates();
|
||||
|
||||
if (gates.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* 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
|
||||
*/
|
||||
// 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);
|
||||
|
||||
@ -119,92 +203,103 @@ 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(ChatColor.AQUA + 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(ChatColor.AQUA + 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(TextUtil.titleize("List of all gates (" + page + "/" + --currentPage + ")"));
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@ -224,26 +319,23 @@ public class CommandList extends BaseCommand
|
||||
public void perform()
|
||||
{
|
||||
int page = this.getPageParameter();
|
||||
|
||||
List<String> messages = message(page);
|
||||
|
||||
if (messages == null)
|
||||
{
|
||||
if (page == 1) // no gates exist
|
||||
{
|
||||
sendMessage(ChatColor.RED + "There are no gates yet. " + ChatColor.RESET +
|
||||
"(Note that you might not be allowed to get information about certain gates)");
|
||||
}
|
||||
else // the requested page does not exist
|
||||
{
|
||||
sendMessage(ChatColor.RED + "The requested page is not availible");
|
||||
}
|
||||
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;
|
||||
}
|
||||
else
|
||||
{
|
||||
sendMessage(messages);
|
||||
|
||||
if (page > allPages.size() || page < 1) {
|
||||
sendMessage(ChatColor.RED + "The requested page is not availible");
|
||||
return;
|
||||
}
|
||||
|
||||
String message = TextUtil.titleize("List of all gates (" + page + "/" + allPages.size() + ")") + "\n";
|
||||
message += allPages.get(page-1);
|
||||
|
||||
sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,12 +31,8 @@ public class CommandSetExit extends BaseCommand
|
||||
{
|
||||
try
|
||||
{
|
||||
System.out.println(gate.getExit());
|
||||
|
||||
gate.setExit(player.getLocation());
|
||||
sendMessage(ChatColor.GREEN + "The exit of gate '" + gate.getId() + "' is now where you stand.");
|
||||
|
||||
System.out.println(gate.getExit());
|
||||
}
|
||||
catch (Exception e) {
|
||||
sendMessage(ChatColor.RED + "Setting the exit for the gate failed! See server log for more information");
|
||||
|
@ -1,5 +1,7 @@
|
||||
package de.craftinc.gates.listeners;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
@ -20,6 +22,8 @@ import de.craftinc.gates.util.GateUtil;
|
||||
|
||||
public class PluginPlayerListener implements Listener
|
||||
{
|
||||
protected HashMap<String, Long> lastBorderMessage = new HashMap<String, Long>();
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPlayerMove(PlayerMoveEvent event)
|
||||
{
|
||||
@ -38,7 +42,22 @@ public class PluginPlayerListener implements Listener
|
||||
|
||||
// Check for permission
|
||||
if (!hasPermission(event.getPlayer(), gateAtLocation)) {
|
||||
event.getPlayer().sendMessage(ChatColor.RED + "Sorry, you are not allowed to use this gate!");
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -80,7 +99,7 @@ public class PluginPlayerListener implements Listener
|
||||
|
||||
protected boolean hasPermission(Player player, Gate gate)
|
||||
{
|
||||
if (Plugin.permission == null) // fallback <20> use the standard bukkit permission system
|
||||
if (Plugin.permission == null) // fallback: use the standard bukkit permission system
|
||||
{
|
||||
return player.hasPermission(Plugin.permissionUse);
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ import org.bukkit.event.entity.EntityPortalEnterEvent;
|
||||
import org.bukkit.event.player.PlayerPortalEvent;
|
||||
|
||||
import de.craftinc.gates.Gate;
|
||||
import de.craftinc.gates.Plugin;
|
||||
import de.craftinc.gates.util.GateUtil;
|
||||
|
||||
|
||||
@ -76,10 +75,7 @@ public class PluginPortalListener implements Listener
|
||||
eventLocation.setY(closestGate.getLocation().getY());
|
||||
|
||||
double distToClosestGate = closestGate.getLocation().distance(eventLocation);
|
||||
|
||||
Plugin.log("closest gate: " + closestGate.getId());
|
||||
Plugin.log("distance: " + distToClosestGate);
|
||||
|
||||
|
||||
if (distToClosestGate < 2.0) {
|
||||
this.currentGateAtEvent.put(player, closestGate);
|
||||
return;
|
||||
|
@ -51,10 +51,13 @@ public class GateUtil
|
||||
}
|
||||
|
||||
// Check if the gate is open and useable
|
||||
if (g.getLocation() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
World gateWorld = g.getLocation().getWorld();
|
||||
|
||||
if (!g.isOpen() || !gateWorld.equals(playerWorld))
|
||||
{
|
||||
if (!g.isOpen() || !gateWorld.equals(playerWorld)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@ package de.craftinc.gates.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
@ -90,13 +89,13 @@ public class LocationUtil
|
||||
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()) {
|
||||
if (l1.getBlockX() != l2.getBlockX()) {
|
||||
return false;
|
||||
}
|
||||
if (new Double(l1.getY()).longValue() != new Double(l2.getY()).longValue()) {
|
||||
if (l1.getBlockY() != l2.getBlockY()) {
|
||||
return false;
|
||||
}
|
||||
if (new Double(l1.getZ()).longValue() != new Double(l2.getZ()).longValue()) {
|
||||
if (l1.getBlockZ() != l2.getBlockZ()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user