Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
e20a2c9084 | |||
bb32466902 | |||
bbbe256718 | |||
53c29aa9a8 | |||
094b2f6dca | |||
62e7d558e6 | |||
8fd26b513a | |||
a83c0fbab0 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@ lib/
|
||||
target/
|
||||
*.iml
|
||||
.idea/
|
||||
bukkit-testserver/
|
||||
|
Binary file not shown.
@ -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
44
pom.xml
@ -5,7 +5,7 @@
|
||||
<groupId>de.craftinc</groupId>
|
||||
<artifactId>CraftincBorderProtection</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.1</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
160
scripts/minecraft.sh
Executable 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
21
scripts/test-deployment.sh
Executable 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
|
@ -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") )
|
||||
{
|
||||
|
@ -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,7 +83,7 @@ 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, Boolean isBorderEnabled )
|
||||
{
|
||||
@ -105,6 +108,9 @@ public class Messages
|
||||
public static String noPermissionSet =
|
||||
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.";
|
||||
|
||||
@ -117,13 +123,16 @@ 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 )
|
||||
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 + "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.";
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ import org.bukkit.event.player.PlayerLoginEvent;
|
||||
|
||||
public class PlayerLoginListener implements Listener
|
||||
{
|
||||
@SuppressWarnings("unused")
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerLogin( PlayerLoginEvent e )
|
||||
{
|
||||
@ -40,7 +41,7 @@ public class PlayerLoginListener implements Listener
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
player.sendMessage(Messages.UpdateMessage(UpdateHelper.cachedLatestVersion,
|
||||
player.sendMessage(Messages.updateMessage(UpdateHelper.cachedLatestVersion,
|
||||
UpdateHelper.getCurrentVersion()));
|
||||
}
|
||||
}, 20L);
|
||||
|
@ -46,6 +46,8 @@ 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();
|
||||
@ -54,7 +56,7 @@ public class Plugin extends JavaPlugin
|
||||
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);
|
||||
|
Reference in New Issue
Block a user