12 Commits
1.0.3 ... 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
14 changed files with 468 additions and 17 deletions

1
.gitignore vendored
View File

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

Binary file not shown.

View File

@ -3,9 +3,11 @@
* 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"

44
pom.xml
View File

@ -5,7 +5,7 @@
<groupId>de.craftinc</groupId>
<artifactId>CraftincBorderProtection</artifactId>
<packaging>jar</packaging>
<version>1.0.3</version>
<version>1.1.1</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@ -18,13 +18,53 @@
<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

@ -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") )
{
@ -71,7 +94,7 @@ public class Commands implements CommandExecutor
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()));
sender.sendMessage(Messages.borderInfo(world.getName(), border.toString(), border.isActive()));
}
catch ( Exception e )
{
@ -86,7 +109,7 @@ public class Commands implements CommandExecutor
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()));
sender.sendMessage(Messages.borderInfo(world.getName(), border.toString(), border.isActive()));
}
catch ( Exception e )
{
@ -120,22 +143,31 @@ 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();
Border border = Border.getBorders().get(world);
if (border != null)
if ( border != null )
{
if (args[0].equalsIgnoreCase("on")) {
if ( args[0].equalsIgnoreCase("on") )
{
border.enable();
sender.sendMessage(Messages.borderEnabled);
} else {
}
else
{
border.disable();
sender.sendMessage(Messages.borderDisabled);
}

View File

@ -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,13 +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 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 " +
@ -80,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 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.";
@ -108,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

@ -56,9 +56,15 @@ public class PlayerMoveListener implements Listener
}
@SuppressWarnings("unused")
@EventHandler(priority = EventPriority.NORMAL)
@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") )
{

View File

@ -33,9 +33,15 @@ public class PlayerTeleportListener implements Listener
}
@SuppressWarnings("unused")
@EventHandler(priority = EventPriority.LOWEST)
@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") )
{

View File

@ -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

@ -33,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.