16 Commits
1.0.0 ... 1.1.1

Author SHA1 Message Date
e20a2c9084 version 1.1.1 2013-03-16 23:40:56 +01:00
bb32466902 bump to version 1.1.1 2013-03-16 23:27:38 +01:00
bbbe256718 Bukkit 1.5R0.1 compatible 2013-03-16 23:26:34 +01:00
53c29aa9a8 always make ddidderr, mice_on_drugs and Mochaccino ops on testserver 2013-03-16 23:25:51 +01:00
094b2f6dca automatic testserver deployment beta 2013-03-08 14:09:52 +01:00
62e7d558e6 maven dependencies (mainly bukkit) will now be copied to target/lib 2013-02-24 10:44:35 +01:00
8fd26b513a checkversion command 2013-02-24 10:29:26 +01:00
a83c0fbab0 LICENSE updated
minor code style improvements
2013-02-24 10:16:56 +01:00
6a218f97f0 Version 1.1
First version of basic update checker included
Event priorities for Move and Teleport listeners now HIGHEST
2013-02-23 22:16:44 +01:00
46d19fa35e border info message now shows if border is enabled or disabled 2013-02-20 16:32:12 +01:00
785dc10644 Version 1.0.3-1 2013-02-20 16:11:04 +01:00
c671f04f65 Security Fix: added missing permission check for enable/disable border 2013-02-20 15:59:58 +01:00
0176ec3a3a version 1.0.3
softdepend Multiverse-Core added (should resolve issue #7)
removed a system.out.println
fixed: now checks if border is null before trying to on|off
2013-02-20 11:59:28 +01:00
5bc660d392 Version 1.0.2
License information updated in all files.
version number in plugin.yml now comes from maven.
2013-02-16 17:59:05 +01:00
df37830bef Version 1.0.1 2013-02-10 02:30:58 +01:00
e11469618d better output on border creation 2013-02-10 02:28:56 +01:00
20 changed files with 808 additions and 110 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@ lib/
target/
*.iml
.idea/
bukkit-testserver/

Binary file not shown.

View File

165
LGPLv3 Normal file
View File

@ -0,0 +1,165 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.

19
LICENSE.md Normal file
View File

@ -0,0 +1,19 @@
# GPLv3
* src/main/java/de/craftinc/borderprotection/Border.java
* src/main/java/de/craftinc/borderprotection/BorderManager.java
* src/main/java/de/craftinc/borderprotection/Commands.java
* src/main/java/de/craftinc/borderprotection/Messages.java
* src/main/java/de/craftinc/borderprotection/PlayerLoginListener.java
* src/main/java/de/craftinc/borderprotection/PlayerMoveListener.java
* src/main/java/de/craftinc/borderprotection/PlayerTeleportListener.java
* src/main/java/de/craftinc/borderprotection/Plugin.java
* src/main/java/de/craftinc/borderprotection/UpdateHelper.java
* src/main/resources/plugin.yml
full text of GPLv3 can be found in the file "GPLv3"
# LGPLv3
* src/main/java/de/craftinc/borderprotection/LocationSerializer.java
full text of LGPLv3 can be found in the file "LGPLv3"

View File

@ -1,8 +1,9 @@
craftinc-borderprotection
=========================
# Craft Inc. BorderProtection
A border protection plugin for bukkit. All players (except those with ignoreborders permission) cannot go beyond the border.
Full user guide can be found here: http://www.craftinc.de/border-protection/
Read the [full user guide](http://www.craftinc.de/border-protection/) for more information.
This project is licensed under the GPLv3, see LICENSE
## License
This project is licensed under GPLv3 and some files are LGPLv3. For exact information see LICENSE.

53
pom.xml
View File

@ -5,17 +5,66 @@
<groupId>de.craftinc</groupId>
<artifactId>CraftincBorderProtection</artifactId>
<packaging>jar</packaging>
<version>1.0.0</version>
<version>1.1.1</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<resources>
<resource>
<directory>src/main/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-R0.1-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.5-R0.1-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>

160
scripts/minecraft.sh Executable file
View File

@ -0,0 +1,160 @@
#!/bin/bash
SCRIPT_DIR=$(readlink -f $(dirname "$0"))
SERVICE='craftbukkit*.jar'
#USERNAME="minecraft"
CPU_COUNT=2
BUKKIT="$SCRIPT_DIR/../target/lib/$SERVICE"
INVOCATION="java -Xmx1000M -Xms300M -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalPacing -XX:ParallelGCThreads=$CPU_COUNT -XX:+AggressiveOpts -jar $BUKKIT nogui"
MCPATH="$SCRIPT_DIR/../bukkit-testserver"
if [ ! -d "$MCPATH" ]; then
mkdir -p "$MCPATH"
fi
ME=$(whoami)
as_user() {
#if [ $ME == $USERNAME ] ; then
bash -c "$1"
#else
#su - $USERNAME -c "$1"
#fi
}
mc_start() {
if ps ax | grep -v grep | grep -v -i SCREEN | grep "craftbukkit" > /dev/null
then
echo "Tried to start but $SERVICE was already running!"
else
echo "$SERVICE was not running... starting."
cd "$MCPATH"
as_user "cd "$MCPATH" && screen -dmS minecraft $INVOCATION"
sleep 7
if ps ax | grep -v grep | grep -v -i SCREEN | grep "craftbukkit" > /dev/null
then
echo "$SERVICE is now running."
else
echo "Could not start $SERVICE."
fi
fi
}
mc_stop() {
if ps ax | grep -v grep | grep -v -i SCREEN | grep "craftbukkit" > /dev/null
then
echo "$SERVICE is running... stopping."
as_user "screen -p 0 -S minecraft -X eval 'stuff \"save-all\"\015'"
sleep 2
as_user "screen -p 0 -S minecraft -X eval 'stuff \"stop\"\015'"
sleep 6
else
echo "$SERVICE was not running."
fi
if ps ax | grep -v grep | grep -v -i SCREEN | grep "craftbukkit" > /dev/null
then
echo "$SERVICE could not be shut down... still running."
else
echo "$SERVICE is shut down."
fi
}
mc_save() {
if ps ax | grep -v grep | grep -v -i SCREEN | grep "craftbukkit" > /dev/null
then
echo "$SERVICE is running... saving."
as_user "screen -p 0 -S minecraft -X eval 'stuff \"save-all\"\015'"
else
echo "$SERVICE was not running."
fi
}
mc_reload() {
if ps ax | grep -v grep | grep -v -i SCREEN | grep "craftbukkit" > /dev/null
then
echo "$SERVICE is running... reloading."
as_user "screen -p 0 -S minecraft -X eval 'stuff \"reload\"\015'"
else
echo "$SERVICE was not running."
fi
}
mc_reload_or_start() {
if ps ax | grep -v grep | grep -v -i SCREEN | grep "craftbukkit" > /dev/null
then
echo "$SERVICE was already running! Doing a reload now!"
mc_reload
else
echo "$SERVICE was not running... starting."
cd "$MCPATH"
as_user "cd \"$MCPATH\" && screen -dmS minecraft $INVOCATION"
sleep 7
if ps ax | grep -v grep | grep -v -i SCREEN | grep "craftbukkit" > /dev/null
then
echo "$SERVICE is now running."
else
echo "Could not start $SERVICE."
fi
fi
}
mc_ddidderr_admin() {
if ps ax | grep -v grep | grep -v -i SCREEN | grep "craftbukkit" > /dev/null
then
echo "$SERVICE is running... making ddidder to admin and reloading permissions."
as_user "screen -p 0 -S minecraft -X eval 'stuff \"pex user ddidderr group set admin\"\015'"
as_user "screen -p 0 -S minecraft -X eval 'stuff \"pex reload\"\015'"
else
echo "$SERVICE was not running."
fi
}
case "$1" in
start)
echo "Starting Minecraft..."
mc_start
echo "DONE"
;;
stop)
echo "Stopping Minecraft..."
as_user "screen -p 0 -S minecraft -X eval 'stuff \"say SERVER SHUTTING DOWN!\"\015'"
mc_stop
echo "DONE"
;;
restart)
as_user "screen -p 0 -S minecraft -X eval 'stuff \"say SERVER REBOOT IN 10 SECONDS.\"\015'"
$0 stop
sleep 1
$0 start
;;
reload)
mc_reload
;;
reload_or_start)
echo "Starting or reloading Minecraft..."
mc_reload_or_start
echo "DONE"
;;
ddidderr_admin)
mc_ddidderr_admin
;;
connected)
as_user "screen -p 0 -S minecraft -X eval 'stuff \"who\"\015'"
sleep 2s
tac "$MCPATH"/server.log | grep -m 1 "Connected"
;;
status)
if ps ax | grep -v grep | grep -v -i SCREEN | grep "craftbukkit" > /dev/null
then
echo "$SERVICE is running."
else
echo "$SERVICE is not running."
fi
;;
save)
mc_save
;;
*)
echo "Usage: /etc/init.d/minecraft {start|stop|restart|connected|status}"
exit 1
;;
esac

21
scripts/test-deployment.sh Executable file
View File

@ -0,0 +1,21 @@
#!/bin/bash
SCRIPT_DIR=$(readlink -f $(dirname "$0"))
BUKKIT_DIR="$SCRIPT_DIR/../bukkit-testserver"
PLUGIN_DIR="$SCRIPT_DIR/../bukkit-testserver/plugins"
# TODO: This is a bad solution! Maven should write necessary information into an extra file.
ARTIFACT_ID="$(grep -C3 '<groupId>de.craftinc' "$SCRIPT_DIR/../pom.xml" | grep '<artifactId>' | sed 's/\s*<artifactId>//g' | sed 's/<\/artifactId>\s*//g')"
# TODO: This is a bad solution! Maven should write necessary information into an extra file.
VERSION="$(grep -C3 '<groupId>de.craftinc' "$SCRIPT_DIR/../pom.xml" | grep '<version>' | sed 's/\s*<version>//g' | sed 's/<\/version>\s*//g')"
mkdir -p "$PLUGIN_DIR"
cp "$SCRIPT_DIR/../target/$ARTIFACT_ID-$VERSION".jar "$PLUGIN_DIR/$ARTIFACT_ID".jar
echo -e "ddidderr\nmice_on_drugs\nMochaccino" > "$BUKKIT_DIR/ops.txt"
"$SCRIPT_DIR/minecraft.sh" reload_or_start

View File

@ -1,3 +1,19 @@
/* Craft Inc. BorderProtection
Copyright (C) 2013 Paul Schulze, Tobias Ottenweller
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.craftinc.borderprotection;
import org.bukkit.Location;
@ -106,8 +122,6 @@ public class Border implements ConfigurationSerializable
map.put(rectPoint2Name, LocationSerializer.serializeLocation(rectPoint2));
map.put(isActiveKey, isActive);
System.out.println(map);
return map;
}

View File

@ -1,5 +1,5 @@
/* CraftInc BorderProtection
Copyright (C) 2012 Paul Schulze
/* Craft Inc. BorderProtection
Copyright (C) 2013 Paul Schulze, Tobias Ottenweller
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,5 +1,5 @@
/* CraftInc BorderProtection
Copyright (C) 2012 Paul Schulze
/* Craft Inc. BorderProtection
Copyright (C) 2013 Paul Schulze, Tobias Ottenweller
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -53,6 +53,29 @@ public class Commands implements CommandExecutor
return true;
}
// checkversion
if ( args.length > 0 && args[0].equalsIgnoreCase("checkversion") )
{
if ( !sender.hasPermission("craftinc.borderprotection.update") )
{
sender.sendMessage(Messages.noPermissionCheckversion);
return false;
}
if ( UpdateHelper.newVersionAvailable() )
{
sender.sendMessage(
Messages.updateMessage(UpdateHelper.cachedLatestVersion, UpdateHelper.getCurrentVersion()));
return true;
}
else
{
sender.sendMessage(Messages.noUpdateAvailable);
return true;
}
}
// set
if ( ( args.length == 2 || args.length == 3 ) && args[0].equalsIgnoreCase("set") )
{
@ -61,13 +84,17 @@ public class Commands implements CommandExecutor
sender.sendMessage(Messages.noPermissionSet);
return false;
}
World world = ( (Player) sender ).getWorld();
// set <distance>
if ( args.length == 2 )
{
try
{
borderManager.setBorder(( (Player) sender ).getWorld(), Double.parseDouble(args[1]));
Border border = Border.getBorders().get(world);
sender.sendMessage(Messages.borderCreationSuccessful);
sender.sendMessage(Messages.borderInfo(world.getName(), border.toString(), border.isActive()));
}
catch ( Exception e )
{
@ -80,6 +107,9 @@ public class Commands implements CommandExecutor
try
{
borderManager.setBorder(( (Player) sender ).getWorld(), args[1], args[2]);
Border border = Border.getBorders().get(world);
sender.sendMessage(Messages.borderCreationSuccessful);
sender.sendMessage(Messages.borderInfo(world.getName(), border.toString(), border.isActive()));
}
catch ( Exception e )
{
@ -113,20 +143,38 @@ public class Commands implements CommandExecutor
Border border = Border.getBorders().get(world);
sender.sendMessage(Messages.borderInfo(world.getName(), border.toString()));
sender.sendMessage(Messages.borderInfo(world.getName(), border.toString(), border.isActive()));
return true;
}
// on
if ( args.length == 1 && ( args[0].equalsIgnoreCase("on") || args[0].equalsIgnoreCase("off") ) )
{
if ( !sender.hasPermission("craftinc.borderprotection.set") )
{
sender.sendMessage(Messages.noPermissionSet);
return false;
}
World world = ( (Player) sender ).getWorld();
if (args[0].equalsIgnoreCase("on")) {
Border.getBorders().get(world).enable();
sender.sendMessage(Messages.borderEnabled);
} else {
Border.getBorders().get(world).disable();
sender.sendMessage(Messages.borderDisabled);
Border border = Border.getBorders().get(world);
if ( border != null )
{
if ( args[0].equalsIgnoreCase("on") )
{
border.enable();
sender.sendMessage(Messages.borderEnabled);
}
else
{
border.disable();
sender.sendMessage(Messages.borderDisabled);
}
}
else
{
sender.sendMessage(Messages.borderInfoNoBorderSet);
}
// save the new border

View File

@ -1,3 +1,19 @@
/* Craft Inc. BorderProtection
Copyright (C) 2013 Tobias Ottenweller
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program (LGPLv3). If not, see <http://www.gnu.org/licenses/>.
*/
package de.craftinc.borderprotection;
import org.bukkit.Location;
@ -12,73 +28,76 @@ import java.util.Map;
*/
public class LocationSerializer
{
protected static String worldKey = "world";
protected static String xKey = "x";
protected static String yKey = "y";
protected static String zKey = "z";
protected static String worldKey = "world";
protected static String xKey = "x";
protected static String yKey = "y";
protected static String zKey = "z";
protected static World getWorld(String name) throws Exception
{
World world = Plugin.getPlugin().getServer().getWorld(name);
protected static World getWorld( String name ) throws Exception
{
World world = Plugin.getPlugin().getServer().getWorld(name);
if (world == null) {
throw new Exception("World '" + name + "' does not exists anymore! Cannot get instance!");
}
if ( world == null )
{
throw new Exception("World '" + name + "' does not exists anymore! Cannot get instance!");
}
return world;
}
return world;
}
public static Map<String, Object> serializeLocation(Location l)
{
if (l == null) {
return null;
}
public static Map<String, Object> serializeLocation( Location l )
{
if ( l == null )
{
return null;
}
Map<String, Object> serializedLocation = new HashMap<String, Object>();
Map<String, Object> serializedLocation = new HashMap<String, Object>();
serializedLocation.put(worldKey, l.getWorld().getName());
serializedLocation.put(xKey, l.getX());
serializedLocation.put(yKey, l.getY());
serializedLocation.put(zKey, l.getZ());
serializedLocation.put(worldKey, l.getWorld().getName());
serializedLocation.put(xKey, l.getX());
serializedLocation.put(yKey, l.getY());
serializedLocation.put(zKey, l.getZ());
return serializedLocation;
}
return serializedLocation;
}
public static Location deserializeLocation(Map<String, Object> map) throws Exception
{
if (map == null) {
return null;
}
public static Location deserializeLocation( Map<String, Object> map ) throws Exception
{
if ( map == null )
{
return null;
}
World w = getWorld((String)map.get(worldKey));
World w = getWorld((String) map.get(worldKey));
// verbose loading of coordinates (they might be Double or Integer)
Object objX = map.get(xKey);
Object objY = map.get(yKey);
Object objZ = map.get(zKey);
// verbose loading of coordinates (they might be Double or Integer)
Object objX = map.get(xKey);
Object objY = map.get(yKey);
Object objZ = map.get(zKey);
double x,y,z;
double x, y, z;
if (objX instanceof Integer)
x = (double)(Integer)objX;
else
x = (Double)objX;
if ( objX instanceof Integer )
x = (double) (Integer) objX;
else
x = (Double) objX;
if (objY instanceof Integer)
y = (double)(Integer)objY;
else
y = (Double)objY;
if ( objY instanceof Integer )
y = (double) (Integer) objY;
else
y = (Double) objY;
if (objZ instanceof Integer)
z = (double)(Integer)objZ;
else
z = (Double)objZ;
if ( objZ instanceof Integer )
z = (double) (Integer) objZ;
else
z = (Double) objZ;
return new Location(w, x, y, z);
}
return new Location(w, x, y, z);
}
}

View File

@ -1,5 +1,5 @@
/* CraftInc BorderProtection
Copyright (C) 2012 Paul Schulze
/* Craft Inc. BorderProtection
Copyright (C) 2013 Paul Schulze, Tobias Ottenweller
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -22,6 +22,8 @@ public class Messages
{
private static final String NEWLINE = "\n";
private static final String pluginName = Plugin.getPlugin().getDescription().getName();
private static String makeCmd( String command, String explanation, String... args )
{
StringBuilder sb = new StringBuilder();
@ -66,12 +68,14 @@ public class Messages
makeCmd("/cibp get", "shows the borders of the current world");
public static String helpGeneral =
ChatColor.GREEN + "CraftInc BorderProtection - Usage:" + NEWLINE +
ChatColor.GREEN + pluginName + " - Usage:" + NEWLINE +
makeCmd("help", "shows this help") +
makeCmd("get | info", "shows the borders of the current world") +
makeCmd("get | info", "shows the border of the current world") +
makeCmd("on | off", "enables/disables the border of the current world") +
makeCmd("set", "Border rectangle edges will be this far away from point of origin.", "<integer>") +
makeCmd("set", "Border rectangle is defined by the two points. A point is specified as: x,z",
"<point1>", "<point2>");
"<point1>", "<point2>") +
makeCmd("checkversion", "Checks for a newer version.");
public static String borderCreationSuccessful
= ChatColor.YELLOW + "New border was set " +
@ -79,22 +83,33 @@ public class Messages
ChatColor.YELLOW + "!";
public static String commandIssuedByNonPlayer
= ChatColor.RED + "Only a player can use CraftInc BorderProtection commands!";
= ChatColor.RED + "Only a player can use " + pluginName + " commands!";
public static String borderInfo( String worldName, String borderDef )
public static String borderInfo( String worldName, String borderDef, Boolean isBorderEnabled )
{
String borderEnabled;
if (isBorderEnabled)
{
borderEnabled = ChatColor.GREEN + "enabled";
} else {
borderEnabled = ChatColor.RED + "disabled";
}
return ChatColor.WHITE + "Borders of world " +
ChatColor.YELLOW + worldName +
ChatColor.WHITE + ": " +
ChatColor.YELLOW + borderDef;
ChatColor.YELLOW + borderDef + ChatColor.WHITE + "." + NEWLINE +
ChatColor.WHITE + "Border is " + borderEnabled + ChatColor.WHITE + ".";
}
public static String borderInfoNoBorderSet =
ChatColor.YELLOW + "No border here.";
ChatColor.YELLOW + "No border in this world.";
public static String noPermissionSet =
ChatColor.RED + "Sorry, you don't have permission to set the border.";
ChatColor.RED + "Sorry, you don't have permission to change the border.";
public static String noPermissionCheckversion =
ChatColor.RED + "Sorry, you don't have permission to check for new versions.";
public static String borderEnabled =
ChatColor.YELLOW + "Border enabled.";
@ -107,4 +122,17 @@ public class Messages
public static String borderEnableDisableException =
ChatColor.RED + "Error: Could not save border state on server. After the next reload this border state will be lost!";
public static String updateMessage( String newVersion, String curVersion )
{
return ChatColor.RED + pluginName + ": New version available!" + NEWLINE +
ChatColor.YELLOW + "Current version: " + ChatColor.WHITE + curVersion + NEWLINE +
ChatColor.YELLOW + "New version: " + ChatColor.WHITE + newVersion + NEWLINE +
ChatColor.YELLOW + "Please visit:" + NEWLINE +
ChatColor.AQUA + "http://dev.bukkit.org/server-mods/craftinc-borderprotection" + NEWLINE +
ChatColor.YELLOW + "to get the latest version!";
}
public static String noUpdateAvailable =
ChatColor.YELLOW + "No updates available.";
}

View File

@ -0,0 +1,51 @@
/* Craft Inc. BorderProtection
Copyright (C) 2013 Paul Schulze
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.craftinc.borderprotection;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerLoginEvent;
public class PlayerLoginListener implements Listener
{
@SuppressWarnings("unused")
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerLogin( PlayerLoginEvent e )
{
final Player player = e.getPlayer();
if ( e.getPlayer().hasPermission("craftinc.borderprotection.update") )
{
if ( UpdateHelper.newVersionAvailable() )
{
// Schedule a task which delays 20 ticks (1 second) and then sends a message to the player
Bukkit.getScheduler().scheduleSyncDelayedTask(Plugin.getPlugin(), new Runnable()
{
@Override
public void run()
{
player.sendMessage(Messages.updateMessage(UpdateHelper.cachedLatestVersion,
UpdateHelper.getCurrentVersion()));
}
}, 20L);
}
}
}
}

View File

@ -1,5 +1,5 @@
/* CraftInc BorderProtection
Copyright (C) 2012 Paul Schulze
/* Craft Inc. BorderProtection
Copyright (C) 2013 Paul Schulze, Tobias Ottenweller
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -55,9 +55,16 @@ public class PlayerMoveListener implements Listener
return (double) footBlock.getY();
}
@EventHandler(priority = EventPriority.NORMAL)
@SuppressWarnings("unused")
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerMove( PlayerMoveEvent e )
{
// do nothing if the event is already cancelled
if (e.isCancelled())
{
return;
}
// do nothing if player has the ignoreborders permission
if ( e.getPlayer().hasPermission("craftinc.borderprotection.ignoreborders") )
{
@ -85,6 +92,7 @@ public class PlayerMoveListener implements Listener
return;
}
// do nothing if border is disabled
if ( !border.isActive() )
{
return;

View File

@ -1,5 +1,5 @@
/* CraftInc BorderProtection
Copyright (C) 2012 Paul Schulze
/* Craft Inc. BorderProtection
Copyright (C) 2013 Paul Schulze, Tobias Ottenweller
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -32,9 +32,16 @@ public class PlayerTeleportListener implements Listener
this.borderManager = borderManager;
}
@EventHandler(priority = EventPriority.LOWEST)
@SuppressWarnings("unused")
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerMove( PlayerTeleportEvent e )
{
// do nothing if the event is already cancelled
if (e.isCancelled())
{
return;
}
// do nothing if player has the ignoreborders permission
if ( e.getPlayer().hasPermission("craftinc.borderprotection.ignoreborders") )
{
@ -62,6 +69,7 @@ public class PlayerTeleportListener implements Listener
return;
}
// do nothing if border is disabled
if ( !border.isActive() )
{
return;

View File

@ -1,5 +1,5 @@
/* CraftInc BorderProtection
Copyright (C) 2012 Paul Schulze
/* Craft Inc. BorderProtection
Copyright (C) 2013 Paul Schulze, Tobias Ottenweller
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -46,16 +46,20 @@ public class Plugin extends JavaPlugin
Plugin.cibpPlugin = this;
BorderManager borderManager = new BorderManager();
// create listeners
PlayerMoveListener playerMoveListener = new PlayerMoveListener(borderManager);
PlayerTeleportListener playerTeleportListener = new PlayerTeleportListener(borderManager);
PlayerLoginListener playerLoginListener = new PlayerLoginListener();
// commands
Commands commandExecutor = new Commands(borderManager);
getCommand("cibp").setExecutor(commandExecutor);
// listeners
// register listeners
PluginManager pm = this.getServer().getPluginManager();
pm.registerEvents(playerMoveListener, this);
pm.registerEvents(playerTeleportListener, this);
pm.registerEvents(playerLoginListener, this);
}
}

View File

@ -0,0 +1,98 @@
/* Craft Inc. BorderProtection
Copyright (C) 2013 Paul Schulze
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.craftinc.borderprotection;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
public class UpdateHelper
{
/**
* The URL from which the Plugin tries to get the latest version.
*/
@SuppressWarnings("FieldCanBeLocal")
private static final String updateUrl = "http://www.craftinc.de/plugins/update/craftinc-borderprotection";
/**
* The latest version which was seen on last check.
*/
public static String cachedLatestVersion = null;
/**
* Gets the latest version from the updateURL and returns it as <code>String</code>.
*
* @return latest version as <code>String</code>.
*/
@SuppressWarnings("StringBufferMayBeStringBuilder")
public static String getLatestVersion()
{
// StringBuffer is thread-safe. Don't know if this is really important here, but safe is safe :).
StringBuffer s = new StringBuffer();
try
{
URLConnection c = new URL(updateUrl).openConnection();
BufferedReader br = new BufferedReader(new InputStreamReader(c.getInputStream()));
String inputLine;
while ( ( inputLine = br.readLine() ) != null )
{
s.append(inputLine);
}
br.close();
}
catch ( MalformedURLException e )
{
Plugin.getPlugin().getLogger().warning("Could not check for latest version. Update URL is malformed.");
}
catch ( IOException e )
{
Plugin.getPlugin().getLogger().warning("Could not check for latest version. Update URL was not readable.");
}
// update cached latest version
cachedLatestVersion = s.toString();
return s.toString();
}
/**
* Gets the current version of this plugin directly from the plugin.yml version entry.
*
* @return current version as <code>String</code>.
*/
public static String getCurrentVersion()
{
return Plugin.getPlugin().getDescription().getVersion();
}
/**
* Checks if a newer version is available.
*
* @return Boolean
*/
public static Boolean newVersionAvailable()
{
return !getCurrentVersion().equals(getLatestVersion());
}
}

View File

@ -1,5 +1,5 @@
# CraftInc BorderProtection
# Copyright (C) 2012 Paul Schulze
# Craft Inc. BorderProtection
# Copyright (C) 2013 Paul Schulze, Tobias Ottenweller
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -16,14 +16,15 @@
name: Craft Inc. BorderProtection
main: de.craftinc.borderprotection.Plugin
version: 1.0.0
author: ddidderr
version: ${project.version}
softdepend: [Multiverse-Core]
authors: [ddidderr, mice_on_drugs]
website: http://www.craftinc.de/plugins/borderprotection
commands:
cibp:
description: Shows help for CraftInc BorderProtection
description: Shows help for Craft Inc. BorderProtection
permissions:
craftinc.borderprotection.set:
@ -32,3 +33,6 @@ permissions:
craftinc.borderprotection.ignoreborders:
default: op
description: Allows to be everywhere on the map (ignoring the borders).
craftinc.borderprotection.update:
default: op
description: Allows to get notified on login, when a new update is available.