8 Commits
1.1 ... 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
10 changed files with 268 additions and 9 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@ lib/
target/ target/
*.iml *.iml
.idea/ .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/BorderManager.java
* src/main/java/de/craftinc/borderprotection/Commands.java * src/main/java/de/craftinc/borderprotection/Commands.java
* src/main/java/de/craftinc/borderprotection/Messages.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/PlayerMoveListener.java
* src/main/java/de/craftinc/borderprotection/PlayerTeleportListener.java * src/main/java/de/craftinc/borderprotection/PlayerTeleportListener.java
* src/main/java/de/craftinc/borderprotection/Plugin.java * src/main/java/de/craftinc/borderprotection/Plugin.java
* src/main/java/de/craftinc/borderprotection/UpdateHelper.java
* src/main/resources/plugin.yml * src/main/resources/plugin.yml
full text of GPLv3 can be found in the file "GPLv3" full text of GPLv3 can be found in the file "GPLv3"

44
pom.xml
View File

@ -5,7 +5,7 @@
<groupId>de.craftinc</groupId> <groupId>de.craftinc</groupId>
<artifactId>CraftincBorderProtection</artifactId> <artifactId>CraftincBorderProtection</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<version>1.1</version> <version>1.1.1</version>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@ -18,13 +18,53 @@
<filtering>true</filtering> <filtering>true</filtering>
</resource> </resource>
</resources> </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> </build>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.bukkit</groupId> <groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId> <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> <type>jar</type>
<scope>compile</scope> <scope>compile</scope>
</dependency> </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; 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 // set
if ( ( args.length == 2 || args.length == 3 ) && args[0].equalsIgnoreCase("set") ) if ( ( args.length == 2 || args.length == 3 ) && args[0].equalsIgnoreCase("set") )
{ {

View File

@ -22,6 +22,8 @@ public class Messages
{ {
private static final String NEWLINE = "\n"; 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 ) private static String makeCmd( String command, String explanation, String... args )
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
@ -66,13 +68,14 @@ public class Messages
makeCmd("/cibp get", "shows the borders of the current world"); makeCmd("/cibp get", "shows the borders of the current world");
public static String helpGeneral = public static String helpGeneral =
ChatColor.GREEN + "CraftInc BorderProtection - Usage:" + NEWLINE + ChatColor.GREEN + pluginName + " - Usage:" + NEWLINE +
makeCmd("help", "shows this help") + makeCmd("help", "shows this help") +
makeCmd("get | info", "shows the border 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("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 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", 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 public static String borderCreationSuccessful
= ChatColor.YELLOW + "New border was set " + = ChatColor.YELLOW + "New border was set " +
@ -80,7 +83,7 @@ public class Messages
ChatColor.YELLOW + "!"; ChatColor.YELLOW + "!";
public static String commandIssuedByNonPlayer 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, Boolean isBorderEnabled ) public static String borderInfo( String worldName, String borderDef, Boolean isBorderEnabled )
{ {
@ -105,6 +108,9 @@ public class Messages
public static String noPermissionSet = public static String noPermissionSet =
ChatColor.RED + "Sorry, you don't have permission to change 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 = public static String borderEnabled =
ChatColor.YELLOW + "Border enabled."; ChatColor.YELLOW + "Border enabled.";
@ -117,13 +123,16 @@ public class Messages
public static String borderEnableDisableException = public static String borderEnableDisableException =
ChatColor.RED + "Error: Could not save border state on server. After the next reload this border state will be lost!"; 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 ) public static String updateMessage( String newVersion, String curVersion )
{ {
return ChatColor.RED + "Craft Inc. BorderProtection: New version available!" + NEWLINE + return ChatColor.RED + pluginName + ": New version available!" + NEWLINE +
ChatColor.YELLOW + "Current version: " + ChatColor.WHITE + curVersion + NEWLINE + ChatColor.YELLOW + "Current version: " + ChatColor.WHITE + curVersion + NEWLINE +
ChatColor.YELLOW + "New version: " + ChatColor.WHITE + newVersion + NEWLINE + ChatColor.YELLOW + "New version: " + ChatColor.WHITE + newVersion + NEWLINE +
ChatColor.YELLOW + "Please visit:" + NEWLINE + ChatColor.YELLOW + "Please visit:" + NEWLINE +
ChatColor.AQUA + "http://dev.bukkit.org/server-mods/craftinc-borderprotection" + NEWLINE + ChatColor.AQUA + "http://dev.bukkit.org/server-mods/craftinc-borderprotection" + NEWLINE +
ChatColor.YELLOW + "to get the latest version!"; ChatColor.YELLOW + "to get the latest version!";
} }
public static String noUpdateAvailable =
ChatColor.YELLOW + "No updates available.";
} }

View File

@ -25,6 +25,7 @@ import org.bukkit.event.player.PlayerLoginEvent;
public class PlayerLoginListener implements Listener public class PlayerLoginListener implements Listener
{ {
@SuppressWarnings("unused")
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
public void onPlayerLogin( PlayerLoginEvent e ) public void onPlayerLogin( PlayerLoginEvent e )
{ {
@ -40,7 +41,7 @@ public class PlayerLoginListener implements Listener
@Override @Override
public void run() public void run()
{ {
player.sendMessage(Messages.UpdateMessage(UpdateHelper.cachedLatestVersion, player.sendMessage(Messages.updateMessage(UpdateHelper.cachedLatestVersion,
UpdateHelper.getCurrentVersion())); UpdateHelper.getCurrentVersion()));
} }
}, 20L); }, 20L);

View File

@ -46,6 +46,8 @@ public class Plugin extends JavaPlugin
Plugin.cibpPlugin = this; Plugin.cibpPlugin = this;
BorderManager borderManager = new BorderManager(); BorderManager borderManager = new BorderManager();
// create listeners
PlayerMoveListener playerMoveListener = new PlayerMoveListener(borderManager); PlayerMoveListener playerMoveListener = new PlayerMoveListener(borderManager);
PlayerTeleportListener playerTeleportListener = new PlayerTeleportListener(borderManager); PlayerTeleportListener playerTeleportListener = new PlayerTeleportListener(borderManager);
PlayerLoginListener playerLoginListener = new PlayerLoginListener(); PlayerLoginListener playerLoginListener = new PlayerLoginListener();
@ -54,7 +56,7 @@ public class Plugin extends JavaPlugin
Commands commandExecutor = new Commands(borderManager); Commands commandExecutor = new Commands(borderManager);
getCommand("cibp").setExecutor(commandExecutor); getCommand("cibp").setExecutor(commandExecutor);
// listeners // register listeners
PluginManager pm = this.getServer().getPluginManager(); PluginManager pm = this.getServer().getPluginManager();
pm.registerEvents(playerMoveListener, this); pm.registerEvents(playerMoveListener, this);
pm.registerEvents(playerTeleportListener, this); pm.registerEvents(playerTeleportListener, this);