diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..07f4e87 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +bin/ +dist/ +.gradle/ +*~ +build/ +*.iml +.idea/ diff --git a/README.md b/README.md index 49826cb..fbad78d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,13 @@ -bukkit-plugin-showcase -====================== +coderdojo-minecraft-bukkit-plugins +================== -A Minecraft server Plugin. It's a showcase created to study the Bukkit API +Empty plugin for Minecraft server built on Bukkit API. +Compiled on [Bukkit api 1.7.9-R0.2](https://github.com/Bukkit/Bukkit/tree/1.7.9-R0.2) + + +Building and Running +-------------------- +Copy compiled plugins (via [Gradle](http://gradle.org)) in the dedicated folder on your Bukkit Server. + +Partially supported on [Glowstone](https://github.com/GlowstoneMC/Glowstone) +Best supported on CraftBukkit 1.7.9-R0.2-24-g07d4558-b3116jnks (MC: 1.7.10) (Implementing API version 1.7.10-R0.1-SNAPSHOT) diff --git a/build-and-deploy-plugins.sh b/build-and-deploy-plugins.sh new file mode 100755 index 0000000..4b6cfd3 --- /dev/null +++ b/build-and-deploy-plugins.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +set -e + +# Check if there are one argument +if [ $# -eq 1 ]; then + # Check if the input file actually exists. + if [ ! -d "$1" ]; then + echo "The server folder $1 does not exist... check them" + exit 1 + fi +else + echo "Usage: $0 [server folder]" + exit 1 +fi + + +PLUGIN_FOLDER="$1/plugins" +LOCATION=$(dirname "$(readlink -fn "$0")") + +mkdir -p $PLUGIN_FOLDER + +find $LOCATION -type d -name "*-plugin" -exec sh -c "cd \"{}\" && pwd && ./gradlew" \; + + +find $LOCATION -type f -name "*-bukkit-plugin*.jar" -exec sh -c "cp \"{}\" $PLUGIN_FOLDER" \; diff --git a/craftbukkit b/craftbukkit new file mode 100755 index 0000000..e7c758a --- /dev/null +++ b/craftbukkit @@ -0,0 +1,68 @@ +#!/bin/sh + +#LOCATION=$(dirname "$(readlink -fn "$0")") +#LOCATION=$(dirname "$0") +#LOCATION=$HOME/crafbukkit +LOCATION=/etc/craftbukkit + +cd "$LOCATION" + +mkdir -p logs + +MINECRAFT=`find . -maxdepth 1 -type f -name "*.jar"` + +JAVA="java" + +JAVAOPTS="-server -jar" + +RUNNING=`screen -ls | grep minecraft` + +case "$1" in +'start') + cd $LOCATION + RUNNING=`screen -ls | grep minecraft` + if [ "$RUNNING" = "" ] + then + screen -dmS minecraft $JAVA $JAVAOPTS $MINECRAFT nogui + fi + ;; +'stop') + screen -x minecraft -X stuff "`printf "kickall Restarting server! Try again in 60 seconds!\r"`" + sleep 2 + screen -x minecraft -X stuff `printf "stop\r"` + ;; + +'restart') + screen -x minecraft -X stuff "`printf "kickall Restarting server! Try again in 60 seconds!\r"`" + sleep 2 + screen -x minecraft -X stuff `printf "stop\r"` + RUNNING=`screen -ls | grep minecraft` + cd $LOCATION + until [ "$RUNNING" = "" ] + do + RUNNING=`screen -ls | grep minecraft` + done + screen -dmS minecraft $JAVA $JAVAOPTS $MINECRAFT nogui + sleep 1 + screen -x minecraft + ;; +'view') + screen -x minecraft + ;; + +'sv') + cd $LOCATION + if [ "$RUNNING" = "" ] + then + screen -dmS minecraft $JAVA $JAVAOPTS $MINECRAFT nogui + fi + sleep 1 + screen -x minecraft + ;; + +*) + echo "Usage: $0 { start | stop | restart | view | sv (start & view) }" + ;; +esac +exit 0 + diff --git a/enzo-plugin/build.gradle b/enzo-plugin/build.gradle new file mode 100644 index 0000000..8481be2 --- /dev/null +++ b/enzo-plugin/build.gradle @@ -0,0 +1,42 @@ +defaultTasks 'clean', 'build', 'fatJar' + +//prova windows + +apply plugin: 'java' +apply plugin: 'project-report' + +group = 'it.enzo.bukkit-hello-world' +version = '0.0.1-SNAPSHOT' +description = "Enzo CoderDojo plugin" + +sourceCompatibility = '1.7' +targetCompatibility = '1.7' + +compileJava { + options.encoding = 'UTF-8' +} + +repositories { + mavenLocal() + mavenCentral() + maven { url "http://repo.bukkit.org/content/groups/public/" } + maven { url "https://oss.sonatype.org/content/repositories/public/" } +} + +// This server is running CraftBukkit version git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks (MC: 1.7.10) (Implementing API version 1.7.10-R0.1-SNAPSHOT) +dependencies { + compile 'org.bukkit:bukkit:1.7.9-R0.2' + compile 'org.projectlombok:lombok:1.14.8' + compile 'org.slf4j:slf4j-api:1.7.7' + compile 'ch.qos.logback:logback-classic:1.1.2' + compile 'com.google.guava:guava:18.0' + compile 'com.google.inject:guice:3.0' + compile 'org.glassfish.jersey.core:jersey-client:2.13' +} + +task fatJar(type: Jar) { + exclude 'org/bukkit/**' + baseName = project.name + '-bukkit-plugin' + from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } + with jar +} diff --git a/enzo-plugin/gradle/wrapper/gradle-wrapper.jar b/enzo-plugin/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..5838598 Binary files /dev/null and b/enzo-plugin/gradle/wrapper/gradle-wrapper.jar differ diff --git a/enzo-plugin/gradle/wrapper/gradle-wrapper.properties b/enzo-plugin/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..7e87d75 --- /dev/null +++ b/enzo-plugin/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Thu Nov 06 23:37:22 CET 2014 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=http\://services.gradle.org/distributions/gradle-2.1-all.zip diff --git a/enzo-plugin/gradlew b/enzo-plugin/gradlew new file mode 100755 index 0000000..91a7e26 --- /dev/null +++ b/enzo-plugin/gradlew @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# For Cygwin, ensure paths are in UNIX format before anything is touched. +if $cygwin ; then + [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` +fi + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >&- +APP_HOME="`pwd -P`" +cd "$SAVED" >&- + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/enzo-plugin/gradlew.bat b/enzo-plugin/gradlew.bat new file mode 100644 index 0000000..8a0b282 --- /dev/null +++ b/enzo-plugin/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/enzo-plugin/src/main/java/it/enzo/minecraft/plugin/CoderDojoPlugin.java b/enzo-plugin/src/main/java/it/enzo/minecraft/plugin/CoderDojoPlugin.java new file mode 100644 index 0000000..7b797c8 --- /dev/null +++ b/enzo-plugin/src/main/java/it/enzo/minecraft/plugin/CoderDojoPlugin.java @@ -0,0 +1,92 @@ +package it.enzo.minecraft.plugin; + + +import com.google.common.base.CaseFormat; +import com.google.common.base.Optional; +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.Injector; +import com.google.inject.name.Names; +import it.enzo.minecraft.plugin.command.CommandExecution; +import it.enzo.minecraft.plugin.tabComplete.OnTabComplete; +import lombok.extern.slf4j.Slf4j; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.Arrays; +import java.util.List; + +@Slf4j +public class CoderDojoPlugin extends JavaPlugin { + + private Injector injector; + + public void onLoad() { + + log.info("[ShowCase] LOAD "); + + injector = Guice.createInjector(new AbstractModule() { + @Override + protected void configure() { + bind(String.class).annotatedWith(Names.named("aString")).toInstance("AAAAAA"); + } + }); + } + + public void onEnable() { + } + + public void onDisable() { + log.info("[ShowCase] DISABLE "); + } + + public boolean onCommand( + CommandSender sender, + Command command, + String commandLabel, + String[] args + ) { + log.debug("sender {}", sender); //GlowPlayer vs net.glowstone.ConsoleManager$ColoredCommandSender + log.debug("command {}", command); //org.bukkit.command.PluginCommand + + final Optional commandExecutionOpt = instanceFromCommandLabel(commandLabel, CommandExecution.class.getPackage()); + + if (commandExecutionOpt.isPresent()) { + return commandExecutionOpt.get().go(sender, command, Arrays.asList(args)); + } else { + return false; + } + } + + @Override + public List onTabComplete( + CommandSender sender, + Command command, + String alias, + String[] args) { + + final Optional onTabCompleteOptional = instanceFromCommandLabel(alias, OnTabComplete.class.getPackage()); + + if (onTabCompleteOptional.isPresent()) { + return onTabCompleteOptional.get().go(sender, command, Arrays.asList(args)); + } else { + return super.onTabComplete(sender ,command, alias, args); + } + + } + + private Optional instanceFromCommandLabel(String commandLabel, Package p) { + String className = p.getName() + "." + CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, commandLabel); + T commandInstance = null; + + try { + commandInstance = (T) injector.getInstance(Class.forName(className)); + } catch (Exception e) { + log.error("can't build command execution class ",e); + } + + return Optional.fromNullable(commandInstance); + } +} + diff --git a/enzo-plugin/src/main/java/it/enzo/minecraft/plugin/command/CommandExecution.java b/enzo-plugin/src/main/java/it/enzo/minecraft/plugin/command/CommandExecution.java new file mode 100644 index 0000000..7f1e484 --- /dev/null +++ b/enzo-plugin/src/main/java/it/enzo/minecraft/plugin/command/CommandExecution.java @@ -0,0 +1,12 @@ +package it.enzo.minecraft.plugin.command; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; + +/** + * Created by toto on 05/11/14. + */ +public interface CommandExecution { + + boolean go(CommandSender sender, Command command, Iterable args); +} diff --git a/enzo-plugin/src/main/java/it/enzo/minecraft/plugin/command/EnzoWhoAmI.java b/enzo-plugin/src/main/java/it/enzo/minecraft/plugin/command/EnzoWhoAmI.java new file mode 100644 index 0000000..b58743d --- /dev/null +++ b/enzo-plugin/src/main/java/it/enzo/minecraft/plugin/command/EnzoWhoAmI.java @@ -0,0 +1,41 @@ +package it.enzo.minecraft.plugin.command; + +import lombok.extern.slf4j.Slf4j; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; + +/** + * Created by toto on 65/11/14. + */ +@Slf4j +public class EnzoWhoAmI implements CommandExecution { + + + @Override + public boolean go(CommandSender sender, Command command, Iterable args) { + if (sender instanceof Player) { + Player me = (Player)sender; + me.sendMessage(String.format("Your list name is %s", me.getPlayerListName())); + me.sendMessage(String.format("Your location is %s", me.getLocation())); + + me.getLocation(); + + float exp = me.getExp(); + int food = me.getFoodLevel(); + boolean grounded = ((Entity)me).isOnGround(); + String groundMsg = ""; + if (!grounded) { + groundMsg = "not "; //(1) + } + me.sendMessage("PROVA 4 !!! Your experience points are " + exp + + ", food is " + food + + "\nwater falls from the sky " + + "and you are " + groundMsg + "on the ground." + ); + } + return true; + } + +} diff --git a/enzo-plugin/src/main/java/it/enzo/minecraft/plugin/tabComplete/OnTabComplete.java b/enzo-plugin/src/main/java/it/enzo/minecraft/plugin/tabComplete/OnTabComplete.java new file mode 100644 index 0000000..64df682 --- /dev/null +++ b/enzo-plugin/src/main/java/it/enzo/minecraft/plugin/tabComplete/OnTabComplete.java @@ -0,0 +1,14 @@ +package it.enzo.minecraft.plugin.tabComplete; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; + +import java.util.List; + +/** + * Created by toto on 06/11/14. + */ +public interface OnTabComplete { + + List go(CommandSender sender, Command command, Iterable args); +} diff --git a/enzo-plugin/src/main/java/it/enzo/minecraft/plugin/tabComplete/PlayASound.java b/enzo-plugin/src/main/java/it/enzo/minecraft/plugin/tabComplete/PlayASound.java new file mode 100644 index 0000000..9f5cfa7 --- /dev/null +++ b/enzo-plugin/src/main/java/it/enzo/minecraft/plugin/tabComplete/PlayASound.java @@ -0,0 +1,30 @@ +package it.enzo.minecraft.plugin.tabComplete; + +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; +import org.apache.commons.lang.StringUtils; +import org.bukkit.Sound; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; + +import java.util.List; + +/** + * Created by toto on 06/11/14. + */ +public class PlayASound implements OnTabComplete { + + @Override + public List go(CommandSender sender, Command command, Iterable args) { + List result = Lists.newArrayList(); + final String containsIgnoreCase = Iterables.getFirst(args, StringUtils.EMPTY); + Sound[] sounds = Sound.values(); + for (Sound sound : sounds) { + if (StringUtils.containsIgnoreCase(sound.name(), containsIgnoreCase)) { + result.add(sound.name()); + } + } + + return result; + } +} diff --git a/enzo-plugin/src/main/resources/logback.xml b/enzo-plugin/src/main/resources/logback.xml new file mode 100644 index 0000000..ca2a279 --- /dev/null +++ b/enzo-plugin/src/main/resources/logback.xml @@ -0,0 +1,24 @@ + + + + + ${user.home}/toto.log + true + + %-4relative [%thread] %-5level %logger{35} - %msg%n + + + + + + %d %-5level [%t %X{uniq}] %logger{36} - %msg%n + + + + + + + + + + \ No newline at end of file diff --git a/enzo-plugin/src/main/resources/plugin.yml b/enzo-plugin/src/main/resources/plugin.yml new file mode 100644 index 0000000..ce49969 --- /dev/null +++ b/enzo-plugin/src/main/resources/plugin.yml @@ -0,0 +1,12 @@ +name: enzo + +author: Enzo +website: https://github.com/toto-castaldi +main: it.enzo.minecraft.plugin.CoderDojoPlugin + +commands: + who-am-i: + description: Player info + usage: /enzo-who-am-i + +version: 0.1 diff --git a/federico-plugin/build.gradle b/federico-plugin/build.gradle new file mode 100644 index 0000000..007a139 --- /dev/null +++ b/federico-plugin/build.gradle @@ -0,0 +1,38 @@ +defaultTasks 'clean', 'build', 'fatJar' + +apply plugin: 'java' +apply plugin: 'project-report' + +group = 'it.federico.bukkit-hello-world' +version = '0.0.1-SNAPSHOT' +description = "Federico CoderDojo plugin" + +sourceCompatibility = '1.7' +targetCompatibility = '1.7' + +compileJava { + options.encoding = 'UTF-8' +} + +repositories { + mavenLocal() + mavenCentral() + maven { url "http://repo.bukkit.org/content/groups/public/" } + maven { url "https://oss.sonatype.org/content/repositories/public/" } +} + +// This server is running CraftBukkit version git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks (MC: 1.7.10) (Implementing API version 1.7.10-R0.1-SNAPSHOT) +dependencies { + compile 'org.bukkit:bukkit:1.7.9-R0.2' + compile 'org.projectlombok:lombok:1.14.8' + compile 'org.slf4j:slf4j-api:1.7.7' + compile 'com.google.guava:guava:18.0' + compile 'com.google.inject:guice:3.0' +} + +task fatJar(type: Jar) { + exclude 'org/bukkit/**' + baseName = project.name + '-bukkit-plugin' + from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } + with jar +} diff --git a/federico-plugin/gradle/wrapper/gradle-wrapper.jar b/federico-plugin/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..5838598 Binary files /dev/null and b/federico-plugin/gradle/wrapper/gradle-wrapper.jar differ diff --git a/federico-plugin/gradle/wrapper/gradle-wrapper.properties b/federico-plugin/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..7e87d75 --- /dev/null +++ b/federico-plugin/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Thu Nov 06 23:37:22 CET 2014 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=http\://services.gradle.org/distributions/gradle-2.1-all.zip diff --git a/federico-plugin/gradlew b/federico-plugin/gradlew new file mode 100755 index 0000000..91a7e26 --- /dev/null +++ b/federico-plugin/gradlew @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# For Cygwin, ensure paths are in UNIX format before anything is touched. +if $cygwin ; then + [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` +fi + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >&- +APP_HOME="`pwd -P`" +cd "$SAVED" >&- + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/federico-plugin/gradlew.bat b/federico-plugin/gradlew.bat new file mode 100644 index 0000000..8a0b282 --- /dev/null +++ b/federico-plugin/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/federico-plugin/src/main/java/it/federico/minecraft/plugin/CoderDojoPlugin.java b/federico-plugin/src/main/java/it/federico/minecraft/plugin/CoderDojoPlugin.java new file mode 100644 index 0000000..ffd35f4 --- /dev/null +++ b/federico-plugin/src/main/java/it/federico/minecraft/plugin/CoderDojoPlugin.java @@ -0,0 +1,96 @@ +package it.federico.minecraft.plugin; + + +import com.google.common.base.CaseFormat; +import com.google.common.base.Optional; +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.Injector; +import it.federico.minecraft.plugin.command.CommandExecution; +import it.federico.minecraft.plugin.tabComplete.OnTabComplete; +import it.federico.minecraft.plugin.util.DebugLog; +import lombok.extern.slf4j.Slf4j; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.Arrays; +import java.util.List; + +@Slf4j +public class CoderDojoPlugin extends JavaPlugin { + + private Injector injector; + private DebugLog debugLog; + + public void onLoad() { + + log.info("[ShowCase] LOAD "); + + injector = Guice.createInjector(new AbstractModule() { + @Override + protected void configure() { + } + }); + + debugLog = DebugLog.of(log); + } + + public void onEnable() { + + log.info("[ShowCase] ENABLE "); + } + + public void onDisable() { + log.info("[ShowCase] DISABLE "); + } + + public boolean onCommand( + CommandSender sender, + Command command, + String commandLabel, + String[] args + ) { + debugLog.debug("sender {}", sender); //GlowPlayer vs net.glowstone.ConsoleManager$ColoredCommandSender + debugLog.debug("command {}", command); //org.bukkit.command.PluginCommand + + final Optional commandExecutionOpt = instanceFromCommandLabel(commandLabel, CommandExecution.class.getPackage()); + + if (commandExecutionOpt.isPresent()) { + return commandExecutionOpt.get().go(sender, command, Arrays.asList(args)); + } else { + return false; + } + } + + @Override + public List onTabComplete( + CommandSender sender, + Command command, + String alias, + String[] args) { + + final Optional onTabCompleteOptional = instanceFromCommandLabel(alias, OnTabComplete.class.getPackage()); + + if (onTabCompleteOptional.isPresent()) { + return onTabCompleteOptional.get().go(sender, command, Arrays.asList(args)); + } else { + return super.onTabComplete(sender ,command, alias, args); + } + + } + + private Optional instanceFromCommandLabel(String commandLabel, Package p) { + String className = p.getName() + "." + CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, commandLabel); + T commandInstance = null; + + try { + commandInstance = (T) injector.getInstance(Class.forName(className)); + } catch (Exception e) { + log.error("can't build command execution class ",e); + } + + return Optional.fromNullable(commandInstance); + } +} + diff --git a/federico-plugin/src/main/java/it/federico/minecraft/plugin/command/CommandExecution.java b/federico-plugin/src/main/java/it/federico/minecraft/plugin/command/CommandExecution.java new file mode 100644 index 0000000..75882a3 --- /dev/null +++ b/federico-plugin/src/main/java/it/federico/minecraft/plugin/command/CommandExecution.java @@ -0,0 +1,12 @@ +package it.federico.minecraft.plugin.command; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; + +/** + * Created by giampiero on 05/11/14. + */ +public interface CommandExecution { + + boolean go(CommandSender sender, Command command, Iterable args); +} diff --git a/federico-plugin/src/main/java/it/federico/minecraft/plugin/command/FedericoHelloWorld.java b/federico-plugin/src/main/java/it/federico/minecraft/plugin/command/FedericoHelloWorld.java new file mode 100644 index 0000000..63cca3f --- /dev/null +++ b/federico-plugin/src/main/java/it/federico/minecraft/plugin/command/FedericoHelloWorld.java @@ -0,0 +1,25 @@ +package it.federico.minecraft.plugin.command; + +import com.google.inject.Inject; +import lombok.extern.slf4j.Slf4j; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +@Slf4j +public class FedericoHelloWorld implements CommandExecution { + + @Inject + public FedericoHelloWorld() { + } + + @Override + public boolean go(CommandSender sender, Command command, Iterable args) { + if (sender instanceof Player) { + Player me = (Player)sender; + me.sendMessage("CIAO !!! Da Federico"); + } + return true; + } + +} diff --git a/federico-plugin/src/main/java/it/federico/minecraft/plugin/tabComplete/OnTabComplete.java b/federico-plugin/src/main/java/it/federico/minecraft/plugin/tabComplete/OnTabComplete.java new file mode 100644 index 0000000..8530af5 --- /dev/null +++ b/federico-plugin/src/main/java/it/federico/minecraft/plugin/tabComplete/OnTabComplete.java @@ -0,0 +1,14 @@ +package it.federico.minecraft.plugin.tabComplete; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; + +import java.util.List; + +/** + * Created by giampiero on 06/11/14. + */ +public interface OnTabComplete { + + List go(CommandSender sender, Command command, Iterable args); +} diff --git a/federico-plugin/src/main/java/it/federico/minecraft/plugin/util/DebugLog.java b/federico-plugin/src/main/java/it/federico/minecraft/plugin/util/DebugLog.java new file mode 100644 index 0000000..1254fbb --- /dev/null +++ b/federico-plugin/src/main/java/it/federico/minecraft/plugin/util/DebugLog.java @@ -0,0 +1,19 @@ +package it.federico.minecraft.plugin.util; + +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import org.slf4j.Logger; + +/** + * Created by giampiero on 04/11/14. + */ +@RequiredArgsConstructor (staticName = "of") +public class DebugLog { + + @NonNull + private Logger log; + + public void debug(String s, Object... arguments) { + log.info("DEBUG " + s, arguments); + } +} diff --git a/federico-plugin/src/main/resources/plugin.yml b/federico-plugin/src/main/resources/plugin.yml new file mode 100644 index 0000000..1df9288 --- /dev/null +++ b/federico-plugin/src/main/resources/plugin.yml @@ -0,0 +1,11 @@ +name: federico + +author: Federico +website: +main: it.federico.minecraft.plugin.CoderDojoPlugin + +commands: + federico-hello-world: + description: Say HELLO ! + usage: /federico-hello-world +version: 0.1 diff --git a/gerard-plugin/build.gradle b/gerard-plugin/build.gradle new file mode 100644 index 0000000..cbafa91 --- /dev/null +++ b/gerard-plugin/build.gradle @@ -0,0 +1,40 @@ +defaultTasks 'clean', 'build', 'fatJar' + +//prova windows Gerard + +apply plugin: 'java' +apply plugin: 'project-report' + +group = 'it.gerard.bukkit-hello-world' +version = '0.0.1-SNAPSHOT' +description = "Gerard CoderDojo plugin" + +sourceCompatibility = '1.7' +targetCompatibility = '1.7' + +compileJava { + options.encoding = 'UTF-8' +} + +repositories { + mavenLocal() + mavenCentral() + maven { url "http://repo.bukkit.org/content/groups/public/" } + maven { url "https://oss.sonatype.org/content/repositories/public/" } +} + +// This server is running CraftBukkit version git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks (MC: 1.7.10) (Implementing API version 1.7.10-R0.1-SNAPSHOT) +dependencies { + compile 'org.bukkit:bukkit:1.7.9-R0.2' + compile 'org.projectlombok:lombok:1.14.8' + compile 'org.slf4j:slf4j-api:1.7.7' + compile 'com.google.guava:guava:18.0' + compile 'com.google.inject:guice:3.0' +} + +task fatJar(type: Jar) { + exclude 'org/bukkit/**' + baseName = project.name + '-bukkit-plugin' + from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } + with jar +} diff --git a/gerard-plugin/gradle/wrapper/gradle-wrapper.jar b/gerard-plugin/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..5838598 Binary files /dev/null and b/gerard-plugin/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gerard-plugin/gradle/wrapper/gradle-wrapper.properties b/gerard-plugin/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..7e87d75 --- /dev/null +++ b/gerard-plugin/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Thu Nov 06 23:37:22 CET 2014 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=http\://services.gradle.org/distributions/gradle-2.1-all.zip diff --git a/gerard-plugin/gradlew b/gerard-plugin/gradlew new file mode 100755 index 0000000..91a7e26 --- /dev/null +++ b/gerard-plugin/gradlew @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# For Cygwin, ensure paths are in UNIX format before anything is touched. +if $cygwin ; then + [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` +fi + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >&- +APP_HOME="`pwd -P`" +cd "$SAVED" >&- + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/gerard-plugin/gradlew.bat b/gerard-plugin/gradlew.bat new file mode 100644 index 0000000..8a0b282 --- /dev/null +++ b/gerard-plugin/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/gerard-plugin/src/main/java/it/gerard/minecraft/plugin/CoderDojoPlugin.java b/gerard-plugin/src/main/java/it/gerard/minecraft/plugin/CoderDojoPlugin.java new file mode 100644 index 0000000..6c90998 --- /dev/null +++ b/gerard-plugin/src/main/java/it/gerard/minecraft/plugin/CoderDojoPlugin.java @@ -0,0 +1,96 @@ +package it.gerard.minecraft.plugin; + + +import com.google.common.base.CaseFormat; +import com.google.common.base.Optional; +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.Injector; +import it.gerard.minecraft.plugin.command.CommandExecution; +import it.gerard.minecraft.plugin.util.DebugLog; +import it.gerard.minecraft.plugin.tabComplete.OnTabComplete; +import lombok.extern.slf4j.Slf4j; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.Arrays; +import java.util.List; + +@Slf4j +public class CoderDojoPlugin extends JavaPlugin { + + private Injector injector; + private DebugLog debugLog; + + public void onLoad() { + + log.info("[ShowCase] LOAD "); + + injector = Guice.createInjector(new AbstractModule() { + @Override + protected void configure() { + } + }); + + debugLog = DebugLog.of(log); + } + + public void onEnable() { + + log.info("[ShowCase] ENABLE "); + } + + public void onDisable() { + log.info("[ShowCase] DISABLE "); + } + + public boolean onCommand( + CommandSender sender, + Command command, + String commandLabel, + String[] args + ) { + debugLog.debug("sender {}", sender); //GlowPlayer vs net.glowstone.ConsoleManager$ColoredCommandSender + debugLog.debug("command {}", command); //org.bukkit.command.PluginCommand + + final Optional commandExecutionOpt = instanceFromCommandLabel(commandLabel, CommandExecution.class.getPackage()); + + if (commandExecutionOpt.isPresent()) { + return commandExecutionOpt.get().go(sender, command, Arrays.asList(args)); + } else { + return false; + } + } + + @Override + public List onTabComplete( + CommandSender sender, + Command command, + String alias, + String[] args) { + + final Optional onTabCompleteOptional = instanceFromCommandLabel(alias, OnTabComplete.class.getPackage()); + + if (onTabCompleteOptional.isPresent()) { + return onTabCompleteOptional.get().go(sender, command, Arrays.asList(args)); + } else { + return super.onTabComplete(sender ,command, alias, args); + } + + } + + private Optional instanceFromCommandLabel(String commandLabel, Package p) { + String className = p.getName() + "." + CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, commandLabel); + T commandInstance = null; + + try { + commandInstance = (T) injector.getInstance(Class.forName(className)); + } catch (Exception e) { + log.error("can't build command execution class ",e); + } + + return Optional.fromNullable(commandInstance); + } +} + diff --git a/gerard-plugin/src/main/java/it/gerard/minecraft/plugin/command/BuildAHouse.java b/gerard-plugin/src/main/java/it/gerard/minecraft/plugin/command/BuildAHouse.java new file mode 100644 index 0000000..0251b1c --- /dev/null +++ b/gerard-plugin/src/main/java/it/gerard/minecraft/plugin/command/BuildAHouse.java @@ -0,0 +1,128 @@ +/*** + * Excerpted from "Learn to Program with Minecraft Plugins", + * published by The Pragmatic Bookshelf. + * Copyrights apply to this code. It may not be used to create training material, + * courses, books, articles, and the like. Contact us if you are in doubt. + * We make no guarantees that this code is fit for any purpose. + * Visit http://www.pragmaticprogrammer.com/titles/ahmine for more book information. +***/ +package it.gerard.minecraft.plugin.command; + +import java.util.logging.Logger; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; + +// +// This is a bit convoluted, but it will let you call the "buildMyHouse" +// function without having to see or read this code. +// You might want to pull out the "makeCube" function to use +// in another plugin; it's a triple-nested for-loop +// to make a 3D block. +// + +public class BuildAHouse implements CommandExecution { + public static Logger log = Logger.getLogger("Minecraft"); + public void onEnable() { + log.info("[BuildAHouse] Start up."); + } + public void onReload() { + log.info("[BuildAHouse] Server reloaded."); + } + public void onDisable() { + log.info("[BuildAHouse] Server stopping."); + } + + public static Location origin = null; + public static boolean firstHouse = true; + + // Create a 3D cube, offset from the saved "origin" + private static void makeCube(int offsetX, int offsetY, int offsetZ, + int width, int height, Material what) { + int i, j, k; + Location loc = new Location(origin.getWorld(), 0,0,0); + + // Base is i X j, k goes up for height + for (i=0; i< width; i++) { + for (j=0; j args) { + if (sender instanceof Player) { + Player me = (Player)sender; + // Put your code after this line: + origin = me.getLocation(); + firstHouse = true; + MyHouse.build_me(); + // ...and finish your code before this line. + return true; + } else { + return false; + } + } +} diff --git a/gerard-plugin/src/main/java/it/gerard/minecraft/plugin/command/CommandExecution.java b/gerard-plugin/src/main/java/it/gerard/minecraft/plugin/command/CommandExecution.java new file mode 100644 index 0000000..387738a --- /dev/null +++ b/gerard-plugin/src/main/java/it/gerard/minecraft/plugin/command/CommandExecution.java @@ -0,0 +1,12 @@ +package it.gerard.minecraft.plugin.command; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; + +/** + * Created by giacomo on 05/11/14. + */ +public interface CommandExecution { + + boolean go(CommandSender sender, Command command, Iterable args); +} diff --git a/gerard-plugin/src/main/java/it/gerard/minecraft/plugin/command/GerardHelloWorld.java b/gerard-plugin/src/main/java/it/gerard/minecraft/plugin/command/GerardHelloWorld.java new file mode 100644 index 0000000..c3065bc --- /dev/null +++ b/gerard-plugin/src/main/java/it/gerard/minecraft/plugin/command/GerardHelloWorld.java @@ -0,0 +1,28 @@ +package it.gerard.minecraft.plugin.command; + +import com.google.inject.Inject; +import lombok.extern.slf4j.Slf4j; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +/** + * Created by giacomo on 65/11/14. + */ +@Slf4j +public class GerardHelloWorld implements CommandExecution { + + @Inject + public GerardHelloWorld() { + } + + @Override + public boolean go(CommandSender sender, Command command, Iterable args) { + if (sender instanceof Player) { + Player me = (Player)sender; + me.sendMessage("CIAO !!! Da Gerard"); + } + return true; + } + +} diff --git a/gerard-plugin/src/main/java/it/gerard/minecraft/plugin/command/MyHouse.java b/gerard-plugin/src/main/java/it/gerard/minecraft/plugin/command/MyHouse.java new file mode 100644 index 0000000..e7ce9e6 --- /dev/null +++ b/gerard-plugin/src/main/java/it/gerard/minecraft/plugin/command/MyHouse.java @@ -0,0 +1,19 @@ +/*** + * Excerpted from "Learn to Program with Minecraft Plugins", + * published by The Pragmatic Bookshelf. + * Copyrights apply to this code. It may not be used to create training material, + * courses, books, articles, and the like. Contact us if you are in doubt. + * We make no guarantees that this code is fit for any purpose. + * Visit http://www.pragmaticprogrammer.com/titles/ahmine for more book information. +***/ +package buildahouse; +public class MyHouse { + public static void build_me() { + int width; + width = 3; + int height; + height = 50; + for (int build=0; build < 20; build++) { + BuildAHouse.buildMyHouse(width, height);} + } +} diff --git a/gerard-plugin/src/main/java/it/gerard/minecraft/plugin/command/NameHorse.java b/gerard-plugin/src/main/java/it/gerard/minecraft/plugin/command/NameHorse.java new file mode 100644 index 0000000..1bb2eac --- /dev/null +++ b/gerard-plugin/src/main/java/it/gerard/minecraft/plugin/command/NameHorse.java @@ -0,0 +1,32 @@ +package it.gerard.minecraft.plugin.command; + +import com.google.common.collect.Iterables; +import lombok.extern.slf4j.Slf4j; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Horse; +import org.bukkit.entity.Player; + +/** + * Created by gerard on 08/12/14. + */ +@Slf4j +public class NameHorse implements CommandExecution { + + + @Override + public boolean go(CommandSender sender, Command command, Iterable args) { + if (sender instanceof Player) { + Player me = (Player)sender; + Horse horse = me.getWorld().spawn(me.getLocation(), Horse.class); + horse.setCustomName(Iterables.getFirst(args, "Horse")); + horse.setCustomNameVisible(true); + return true; + } else { + log.warn("command is avaliable on players"); + return false; + } + + } + +} diff --git a/gerard-plugin/src/main/java/it/gerard/minecraft/plugin/command/NamePig.java b/gerard-plugin/src/main/java/it/gerard/minecraft/plugin/command/NamePig.java new file mode 100644 index 0000000..7e54058 --- /dev/null +++ b/gerard-plugin/src/main/java/it/gerard/minecraft/plugin/command/NamePig.java @@ -0,0 +1,32 @@ +package it.gerard.minecraft.plugin.command; + +import com.google.common.collect.Iterables; +import lombok.extern.slf4j.Slf4j; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Pig; +import org.bukkit.entity.Player; + +/** + * Created by gerard on 08/12/14. + */ +@Slf4j +public class NamePig implements CommandExecution { + + + @Override + public boolean go(CommandSender sender, Command command, Iterable args) { + if (sender instanceof Player) { + Player me = (Player)sender; + Pig pig = me.getWorld().spawn(me.getLocation(), Pig.class); + pig.setCustomName(Iterables.getFirst(args, "Pig")); + pig.setCustomNameVisible(true); + return true; + } else { + log.warn("command is avaliable on players"); + return false; + } + + } + +} diff --git a/gerard-plugin/src/main/java/it/gerard/minecraft/plugin/command/NameSheep.java b/gerard-plugin/src/main/java/it/gerard/minecraft/plugin/command/NameSheep.java new file mode 100644 index 0000000..d2cc14c --- /dev/null +++ b/gerard-plugin/src/main/java/it/gerard/minecraft/plugin/command/NameSheep.java @@ -0,0 +1,32 @@ +package it.gerard.minecraft.plugin.command; + +import com.google.common.collect.Iterables; +import lombok.extern.slf4j.Slf4j; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Sheep; +import org.bukkit.entity.Player; + +/** + * Created by gerard on 12/12/14. + */ +@Slf4j +public class NameSheep implements CommandExecution { + + + @Override + public boolean go(CommandSender sender, Command command, Iterable args) { + if (sender instanceof Player) { + Player me = (Player)sender; + Sheep sheep = me.getWorld().spawn(me.getLocation(), Sheep.class); + sheep.setCustomName(Iterables.getFirst(args, "Sheep")); + sheep.setCustomNameVisible(true); + return true; + } else { + log.warn("command is avaliable on players"); + return false; + } + + } + +} diff --git a/gerard-plugin/src/main/java/it/gerard/minecraft/plugin/command/NameSpider.java b/gerard-plugin/src/main/java/it/gerard/minecraft/plugin/command/NameSpider.java new file mode 100644 index 0000000..bd55c3a --- /dev/null +++ b/gerard-plugin/src/main/java/it/gerard/minecraft/plugin/command/NameSpider.java @@ -0,0 +1,32 @@ +package it.gerard.minecraft.plugin.command; + +import com.google.common.collect.Iterables; +import lombok.extern.slf4j.Slf4j; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Spider; +import org.bukkit.entity.Player; + +/** + * Created by gerard on 08/12/14. + */ +@Slf4j +public class NameSpider implements CommandExecution { + + + @Override + public boolean go(CommandSender sender, Command command, Iterable args) { + if (sender instanceof Player) { + Player me = (Player)sender; + Spider spider = me.getWorld().spawn(me.getLocation(), Spider.class); + spider.setCustomName(Iterables.getFirst(args, "Spider")); + spider.setCustomNameVisible(true); + return true; + } else { + log.warn("command is avaliable on players"); + return false; + } + + } + +} diff --git a/gerard-plugin/src/main/java/it/gerard/minecraft/plugin/command/NameWolf.java b/gerard-plugin/src/main/java/it/gerard/minecraft/plugin/command/NameWolf.java new file mode 100644 index 0000000..4de1b9c --- /dev/null +++ b/gerard-plugin/src/main/java/it/gerard/minecraft/plugin/command/NameWolf.java @@ -0,0 +1,32 @@ +package it.gerard.minecraft.plugin.command; + +import com.google.common.collect.Iterables; +import lombok.extern.slf4j.Slf4j; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Wolf; +import org.bukkit.entity.Player; + +/** + * Created by gerard on 08/12/14. + */ +@Slf4j +public class NameWolf implements CommandExecution { + + + @Override + public boolean go(CommandSender sender, Command command, Iterable args) { + if (sender instanceof Player) { + Player me = (Player)sender; + Wolf wolf = me.getWorld().spawn(me.getLocation(), Wolf.class); + wolf.setCustomName(Iterables.getFirst(args, "Wolf")); + wolf.setCustomNameVisible(true); + return true; + } else { + log.warn("command is avaliable on players"); + return false; + } + + } + +} diff --git a/gerard-plugin/src/main/java/it/gerard/minecraft/plugin/tabComplete/OnTabComplete.java b/gerard-plugin/src/main/java/it/gerard/minecraft/plugin/tabComplete/OnTabComplete.java new file mode 100644 index 0000000..26bbbac --- /dev/null +++ b/gerard-plugin/src/main/java/it/gerard/minecraft/plugin/tabComplete/OnTabComplete.java @@ -0,0 +1,14 @@ +package it.gerard.minecraft.plugin.tabComplete; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; + +import java.util.List; + +/** + * Created by giacomo on 06/11/14. + */ +public interface OnTabComplete { + + List go(CommandSender sender, Command command, Iterable args); +} diff --git a/gerard-plugin/src/main/java/it/gerard/minecraft/plugin/util/DebugLog.java b/gerard-plugin/src/main/java/it/gerard/minecraft/plugin/util/DebugLog.java new file mode 100644 index 0000000..8184f1f --- /dev/null +++ b/gerard-plugin/src/main/java/it/gerard/minecraft/plugin/util/DebugLog.java @@ -0,0 +1,19 @@ +package it.gerard.minecraft.plugin.util; + +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import org.slf4j.Logger; + +/** + * Created by giacomo on 04/11/14. + */ +@RequiredArgsConstructor (staticName = "of") +public class DebugLog { + + @NonNull + private Logger log; + + public void debug(String s, Object... arguments) { + log.info("DEBUG " + s, arguments); + } +} diff --git a/gerard-plugin/src/main/resources/plugin.yml b/gerard-plugin/src/main/resources/plugin.yml new file mode 100644 index 0000000..892ac7c --- /dev/null +++ b/gerard-plugin/src/main/resources/plugin.yml @@ -0,0 +1,28 @@ +name: gerard + +author: Gerard +website: +main: it.gerard.minecraft.plugin.CoderDojoPlugin + +commands: + gerard-hello-world: + description: Say HELLO ! + usage: /gerard-hello-world + name-pig: + description: Creates a Pig and Give it a name + usage: /name-pig name + name-spider: + description: Creates a Spider and Give it a name + usage: /name-spider name + name-wolf: + description: Creates a Wolf and Give it a name + usage: /name-wolf name + name-sheep: + description: Creates a Sheep and Give it a name + usage: /name-sheep name + build-a-house: + description: Creates a 10x5 glass house + usage: /build-a-house + + +version: 0.1 diff --git a/giacomo-plugin/build.gradle b/giacomo-plugin/build.gradle new file mode 100644 index 0000000..1b312ca --- /dev/null +++ b/giacomo-plugin/build.gradle @@ -0,0 +1,38 @@ +defaultTasks 'clean', 'build', 'fatJar' + +apply plugin: 'java' +apply plugin: 'project-report' + +group = 'it.giacomo.bukkit-hello-world' +version = '0.0.1-SNAPSHOT' +description = "Giacomo CoderDojo plugin" + +sourceCompatibility = '1.7' +targetCompatibility = '1.7' + +compileJava { + options.encoding = 'UTF-8' +} + +repositories { + mavenLocal() + mavenCentral() + maven { url "http://repo.bukkit.org/content/groups/public/" } + maven { url "https://oss.sonatype.org/content/repositories/public/" } +} + +// This server is running CraftBukkit version git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks (MC: 1.7.10) (Implementing API version 1.7.10-R0.1-SNAPSHOT) +dependencies { + compile 'org.bukkit:bukkit:1.7.9-R0.2' + compile 'org.projectlombok:lombok:1.14.8' + compile 'org.slf4j:slf4j-api:1.7.7' + compile 'com.google.guava:guava:18.0' + compile 'com.google.inject:guice:3.0' +} + +task fatJar(type: Jar) { + exclude 'org/bukkit/**' + baseName = project.name + '-bukkit-plugin' + from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } + with jar +} diff --git a/giacomo-plugin/gradle/wrapper/gradle-wrapper.jar b/giacomo-plugin/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..5838598 Binary files /dev/null and b/giacomo-plugin/gradle/wrapper/gradle-wrapper.jar differ diff --git a/giacomo-plugin/gradle/wrapper/gradle-wrapper.properties b/giacomo-plugin/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..7e87d75 --- /dev/null +++ b/giacomo-plugin/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Thu Nov 06 23:37:22 CET 2014 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=http\://services.gradle.org/distributions/gradle-2.1-all.zip diff --git a/giacomo-plugin/gradlew b/giacomo-plugin/gradlew new file mode 100755 index 0000000..91a7e26 --- /dev/null +++ b/giacomo-plugin/gradlew @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# For Cygwin, ensure paths are in UNIX format before anything is touched. +if $cygwin ; then + [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` +fi + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >&- +APP_HOME="`pwd -P`" +cd "$SAVED" >&- + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/giacomo-plugin/gradlew.bat b/giacomo-plugin/gradlew.bat new file mode 100644 index 0000000..8a0b282 --- /dev/null +++ b/giacomo-plugin/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/giacomo-plugin/src/main/java/it/giacomo/minecraft/plugin/CoderDojoPlugin.java b/giacomo-plugin/src/main/java/it/giacomo/minecraft/plugin/CoderDojoPlugin.java new file mode 100644 index 0000000..6533b91 --- /dev/null +++ b/giacomo-plugin/src/main/java/it/giacomo/minecraft/plugin/CoderDojoPlugin.java @@ -0,0 +1,96 @@ +package it.giacomo.minecraft.plugin; + + +import com.google.common.base.CaseFormat; +import com.google.common.base.Optional; +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.Injector; +import it.giacomo.minecraft.plugin.command.CommandExecution; +import it.giacomo.minecraft.plugin.tabComplete.OnTabComplete; +import it.giacomo.minecraft.plugin.util.DebugLog; +import lombok.extern.slf4j.Slf4j; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.Arrays; +import java.util.List; + +@Slf4j +public class CoderDojoPlugin extends JavaPlugin { + + private Injector injector; + private DebugLog debugLog; + + public void onLoad() { + + log.info("[ShowCase] LOAD "); + + injector = Guice.createInjector(new AbstractModule() { + @Override + protected void configure() { + } + }); + + debugLog = DebugLog.of(log); + } + + public void onEnable() { + + log.info("[ShowCase] ENABLE "); + } + + public void onDisable() { + log.info("[ShowCase] DISABLE "); + } + + public boolean onCommand( + CommandSender sender, + Command command, + String commandLabel, + String[] args + ) { + debugLog.debug("sender {}", sender); //GlowPlayer vs net.glowstone.ConsoleManager$ColoredCommandSender + debugLog.debug("command {}", command); //org.bukkit.command.PluginCommand + + final Optional commandExecutionOpt = instanceFromCommandLabel(commandLabel, CommandExecution.class.getPackage()); + + if (commandExecutionOpt.isPresent()) { + return commandExecutionOpt.get().go(sender, command, Arrays.asList(args)); + } else { + return false; + } + } + + @Override + public List onTabComplete( + CommandSender sender, + Command command, + String alias, + String[] args) { + + final Optional onTabCompleteOptional = instanceFromCommandLabel(alias, OnTabComplete.class.getPackage()); + + if (onTabCompleteOptional.isPresent()) { + return onTabCompleteOptional.get().go(sender, command, Arrays.asList(args)); + } else { + return super.onTabComplete(sender ,command, alias, args); + } + + } + + private Optional instanceFromCommandLabel(String commandLabel, Package p) { + String className = p.getName() + "." + CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, commandLabel); + T commandInstance = null; + + try { + commandInstance = (T) injector.getInstance(Class.forName(className)); + } catch (Exception e) { + log.error("can't build command execution class ",e); + } + + return Optional.fromNullable(commandInstance); + } +} + diff --git a/giacomo-plugin/src/main/java/it/giacomo/minecraft/plugin/command/CommandExecution.java b/giacomo-plugin/src/main/java/it/giacomo/minecraft/plugin/command/CommandExecution.java new file mode 100644 index 0000000..bfd8f7c --- /dev/null +++ b/giacomo-plugin/src/main/java/it/giacomo/minecraft/plugin/command/CommandExecution.java @@ -0,0 +1,12 @@ +package it.giacomo.minecraft.plugin.command; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; + +/** + * Created by giampiero on 05/11/14. + */ +public interface CommandExecution { + + boolean go(CommandSender sender, Command command, Iterable args); +} diff --git a/giacomo-plugin/src/main/java/it/giacomo/minecraft/plugin/command/GiacomoHelloWorld.java b/giacomo-plugin/src/main/java/it/giacomo/minecraft/plugin/command/GiacomoHelloWorld.java new file mode 100644 index 0000000..f7c88f1 --- /dev/null +++ b/giacomo-plugin/src/main/java/it/giacomo/minecraft/plugin/command/GiacomoHelloWorld.java @@ -0,0 +1,28 @@ +package it.giacomo.minecraft.plugin.command; + +import com.google.inject.Inject; +import lombok.extern.slf4j.Slf4j; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +/** + * Created by giampiero on 65/11/14. + */ +@Slf4j +public class GiacomoHelloWorld implements CommandExecution { + + @Inject + public GiacomoHelloWorld() { + } + + @Override + public boolean go(CommandSender sender, Command command, Iterable args) { + if (sender instanceof Player) { + Player me = (Player)sender; + me.sendMessage("CIAO !!! Da Giacomo"); + } + return true; + } + +} diff --git a/giacomo-plugin/src/main/java/it/giacomo/minecraft/plugin/tabComplete/OnTabComplete.java b/giacomo-plugin/src/main/java/it/giacomo/minecraft/plugin/tabComplete/OnTabComplete.java new file mode 100644 index 0000000..914e028 --- /dev/null +++ b/giacomo-plugin/src/main/java/it/giacomo/minecraft/plugin/tabComplete/OnTabComplete.java @@ -0,0 +1,14 @@ +package it.giacomo.minecraft.plugin.tabComplete; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; + +import java.util.List; + +/** + * Created by giampiero on 06/11/14. + */ +public interface OnTabComplete { + + List go(CommandSender sender, Command command, Iterable args); +} diff --git a/giacomo-plugin/src/main/java/it/giacomo/minecraft/plugin/util/DebugLog.java b/giacomo-plugin/src/main/java/it/giacomo/minecraft/plugin/util/DebugLog.java new file mode 100644 index 0000000..c45eb97 --- /dev/null +++ b/giacomo-plugin/src/main/java/it/giacomo/minecraft/plugin/util/DebugLog.java @@ -0,0 +1,19 @@ +package it.giacomo.minecraft.plugin.util; + +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import org.slf4j.Logger; + +/** + * Created by giampiero on 04/11/14. + */ +@RequiredArgsConstructor (staticName = "of") +public class DebugLog { + + @NonNull + private Logger log; + + public void debug(String s, Object... arguments) { + log.info("DEBUG " + s, arguments); + } +} diff --git a/giacomo-plugin/src/main/resources/plugin.yml b/giacomo-plugin/src/main/resources/plugin.yml new file mode 100644 index 0000000..3ab2590 --- /dev/null +++ b/giacomo-plugin/src/main/resources/plugin.yml @@ -0,0 +1,11 @@ +name: giacomo + +author: Toto Castaldi +website: https://github.com/giacomo-castaldi +main: it.giacomo.minecraft.plugin.CoderDojoPlugin + +commands: + giacomo-hello-world: + description: Say HELLO ! + usage: /giacomo-hello-world +version: 0.1 diff --git a/giampiero-plugin/build.gradle b/giampiero-plugin/build.gradle new file mode 100644 index 0000000..0ad9472 --- /dev/null +++ b/giampiero-plugin/build.gradle @@ -0,0 +1,38 @@ +defaultTasks 'clean', 'build', 'fatJar' + +apply plugin: 'java' +apply plugin: 'project-report' + +group = 'it.giampiero.bukkit-hello-world' +version = '0.0.1-SNAPSHOT' +description = "Giampiero CoderDojo plugin" + +sourceCompatibility = '1.7' +targetCompatibility = '1.7' + +compileJava { + options.encoding = 'UTF-8' +} + +repositories { + mavenLocal() + mavenCentral() + maven { url "http://repo.bukkit.org/content/groups/public/" } + maven { url "https://oss.sonatype.org/content/repositories/public/" } +} + +// This server is running CraftBukkit version git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks (MC: 1.7.10) (Implementing API version 1.7.10-R0.1-SNAPSHOT) +dependencies { + compile 'org.bukkit:bukkit:1.7.9-R0.2' + compile 'org.projectlombok:lombok:1.14.8' + compile 'org.slf4j:slf4j-api:1.7.7' + compile 'com.google.guava:guava:18.0' + compile 'com.google.inject:guice:3.0' +} + +task fatJar(type: Jar) { + exclude 'org/bukkit/**' + baseName = project.name + '-bukkit-plugin' + from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } + with jar +} diff --git a/giampiero-plugin/gradle/wrapper/gradle-wrapper.jar b/giampiero-plugin/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..5838598 Binary files /dev/null and b/giampiero-plugin/gradle/wrapper/gradle-wrapper.jar differ diff --git a/giampiero-plugin/gradle/wrapper/gradle-wrapper.properties b/giampiero-plugin/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..7e87d75 --- /dev/null +++ b/giampiero-plugin/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Thu Nov 06 23:37:22 CET 2014 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=http\://services.gradle.org/distributions/gradle-2.1-all.zip diff --git a/giampiero-plugin/gradlew b/giampiero-plugin/gradlew new file mode 100755 index 0000000..91a7e26 --- /dev/null +++ b/giampiero-plugin/gradlew @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# For Cygwin, ensure paths are in UNIX format before anything is touched. +if $cygwin ; then + [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` +fi + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >&- +APP_HOME="`pwd -P`" +cd "$SAVED" >&- + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/giampiero-plugin/gradlew.bat b/giampiero-plugin/gradlew.bat new file mode 100644 index 0000000..8a0b282 --- /dev/null +++ b/giampiero-plugin/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/giampiero-plugin/src/main/java/it/giampiero/minecraft/plugin/CoderDojoPlugin.java b/giampiero-plugin/src/main/java/it/giampiero/minecraft/plugin/CoderDojoPlugin.java new file mode 100644 index 0000000..e418b46 --- /dev/null +++ b/giampiero-plugin/src/main/java/it/giampiero/minecraft/plugin/CoderDojoPlugin.java @@ -0,0 +1,32 @@ +package it.giampiero.minecraft.plugin; + + +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.plugin.java.JavaPlugin; + +public class CoderDojoPlugin extends JavaPlugin { + + + public void onLoad() { + + } + + public void onEnable() { + + } + + public void onDisable() { + } + + public boolean onCommand( + CommandSender sender, + Command command, + String commandLabel, + String[] args + ) { + return true; + } + +} + diff --git a/giampiero-plugin/src/main/resources/plugin.yml b/giampiero-plugin/src/main/resources/plugin.yml new file mode 100644 index 0000000..e945c1b --- /dev/null +++ b/giampiero-plugin/src/main/resources/plugin.yml @@ -0,0 +1,8 @@ +name: giampiero + +author: Giampiero +website: +main: it.giampiero.minecraft.plugin.CoderDojoPlugin + +commands: +version: 0.1 diff --git a/ludovico-plugin/build.gradle b/ludovico-plugin/build.gradle new file mode 100644 index 0000000..80a0717 --- /dev/null +++ b/ludovico-plugin/build.gradle @@ -0,0 +1,38 @@ +defaultTasks 'clean', 'build', 'fatJar' + +apply plugin: 'java' +apply plugin: 'project-report' + +group = 'it.ludovico.bukkit-hello-world' +version = '0.0.1-SNAPSHOT' +description = "Ludovico CoderDojo plugin" + +sourceCompatibility = '1.7' +targetCompatibility = '1.7' + +compileJava { + options.encoding = 'UTF-8' +} + +repositories { + mavenLocal() + mavenCentral() + maven { url "http://repo.bukkit.org/content/groups/public/" } + maven { url "https://oss.sonatype.org/content/repositories/public/" } +} + +// This server is running CraftBukkit version git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks (MC: 1.7.10) (Implementing API version 1.7.10-R0.1-SNAPSHOT) +dependencies { + compile 'org.bukkit:bukkit:1.7.9-R0.2' + compile 'org.projectlombok:lombok:1.14.8' + compile 'org.slf4j:slf4j-api:1.7.7' + compile 'com.google.guava:guava:18.0' + compile 'com.google.inject:guice:3.0' +} + +task fatJar(type: Jar) { + exclude 'org/bukkit/**' + baseName = project.name + '-bukkit-plugin' + from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } + with jar +} diff --git a/ludovico-plugin/gradle/wrapper/gradle-wrapper.jar b/ludovico-plugin/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..5838598 Binary files /dev/null and b/ludovico-plugin/gradle/wrapper/gradle-wrapper.jar differ diff --git a/ludovico-plugin/gradle/wrapper/gradle-wrapper.properties b/ludovico-plugin/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..7e87d75 --- /dev/null +++ b/ludovico-plugin/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Thu Nov 06 23:37:22 CET 2014 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=http\://services.gradle.org/distributions/gradle-2.1-all.zip diff --git a/ludovico-plugin/gradlew b/ludovico-plugin/gradlew new file mode 100755 index 0000000..91a7e26 --- /dev/null +++ b/ludovico-plugin/gradlew @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# For Cygwin, ensure paths are in UNIX format before anything is touched. +if $cygwin ; then + [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` +fi + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >&- +APP_HOME="`pwd -P`" +cd "$SAVED" >&- + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/ludovico-plugin/gradlew.bat b/ludovico-plugin/gradlew.bat new file mode 100644 index 0000000..8a0b282 --- /dev/null +++ b/ludovico-plugin/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/ludovico-plugin/src/main/java/it/ludovico/minecraft/plugin/CoderDojoPlugin.java b/ludovico-plugin/src/main/java/it/ludovico/minecraft/plugin/CoderDojoPlugin.java new file mode 100644 index 0000000..7ca6dd1 --- /dev/null +++ b/ludovico-plugin/src/main/java/it/ludovico/minecraft/plugin/CoderDojoPlugin.java @@ -0,0 +1,96 @@ +package it.ludovico.minecraft.plugin; + + +import com.google.common.base.CaseFormat; +import com.google.common.base.Optional; +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.Injector; +import it.ludovico.minecraft.plugin.command.CommandExecution; +import it.ludovico.minecraft.plugin.tabComplete.OnTabComplete; +import it.ludovico.minecraft.plugin.util.DebugLog; +import lombok.extern.slf4j.Slf4j; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.Arrays; +import java.util.List; + +@Slf4j +public class CoderDojoPlugin extends JavaPlugin { + + private Injector injector; + private DebugLog debugLog; + + public void onLoad() { + + log.info("[ShowCase] LOAD "); + + injector = Guice.createInjector(new AbstractModule() { + @Override + protected void configure() { + } + }); + + debugLog = DebugLog.of(log); + } + + public void onEnable() { + + log.info("[ShowCase] ENABLE "); + } + + public void onDisable() { + log.info("[ShowCase] DISABLE "); + } + + public boolean onCommand( + CommandSender sender, + Command command, + String commandLabel, + String[] args + ) { + debugLog.debug("sender {}", sender); //GlowPlayer vs net.glowstone.ConsoleManager$ColoredCommandSender + debugLog.debug("command {}", command); //org.bukkit.command.PluginCommand + + final Optional commandExecutionOpt = instanceFromCommandLabel(commandLabel, CommandExecution.class.getPackage()); + + if (commandExecutionOpt.isPresent()) { + return commandExecutionOpt.get().go(sender, command, Arrays.asList(args)); + } else { + return false; + } + } + + @Override + public List onTabComplete( + CommandSender sender, + Command command, + String alias, + String[] args) { + + final Optional onTabCompleteOptional = instanceFromCommandLabel(alias, OnTabComplete.class.getPackage()); + + if (onTabCompleteOptional.isPresent()) { + return onTabCompleteOptional.get().go(sender, command, Arrays.asList(args)); + } else { + return super.onTabComplete(sender ,command, alias, args); + } + + } + + private Optional instanceFromCommandLabel(String commandLabel, Package p) { + String className = p.getName() + "." + CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, commandLabel); + T commandInstance = null; + + try { + commandInstance = (T) injector.getInstance(Class.forName(className)); + } catch (Exception e) { + log.error("can't build command execution class ",e); + } + + return Optional.fromNullable(commandInstance); + } +} + diff --git a/ludovico-plugin/src/main/java/it/ludovico/minecraft/plugin/command/CommandExecution.java b/ludovico-plugin/src/main/java/it/ludovico/minecraft/plugin/command/CommandExecution.java new file mode 100644 index 0000000..fe7cfc8 --- /dev/null +++ b/ludovico-plugin/src/main/java/it/ludovico/minecraft/plugin/command/CommandExecution.java @@ -0,0 +1,12 @@ +package it.ludovico.minecraft.plugin.command; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; + +/** + * Created by giampiero on 05/11/14. + */ +public interface CommandExecution { + + boolean go(CommandSender sender, Command command, Iterable args); +} diff --git a/ludovico-plugin/src/main/java/it/ludovico/minecraft/plugin/command/LudovicoHelloWorld.java b/ludovico-plugin/src/main/java/it/ludovico/minecraft/plugin/command/LudovicoHelloWorld.java new file mode 100644 index 0000000..7a17c77 --- /dev/null +++ b/ludovico-plugin/src/main/java/it/ludovico/minecraft/plugin/command/LudovicoHelloWorld.java @@ -0,0 +1,26 @@ +package it.ludovico.minecraft.plugin.command; + +import com.google.inject.Inject; +import lombok.extern.slf4j.Slf4j; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +/** + * Created by giampiero on 65/11/14. + */ +@Slf4j +public class LudovicoHelloWorld implements CommandExecution { + + @Inject + public LudovicoHelloWorld() { + } + + @Override + public boolean go(CommandSender sender, Command command, Iterable args) { + Player me = (Player)sender; + me.sendMessage("CIAO !!! Da Ludovico"); + return true; + } + +} diff --git a/ludovico-plugin/src/main/java/it/ludovico/minecraft/plugin/tabComplete/OnTabComplete.java b/ludovico-plugin/src/main/java/it/ludovico/minecraft/plugin/tabComplete/OnTabComplete.java new file mode 100644 index 0000000..c1c6fab --- /dev/null +++ b/ludovico-plugin/src/main/java/it/ludovico/minecraft/plugin/tabComplete/OnTabComplete.java @@ -0,0 +1,14 @@ +package it.ludovico.minecraft.plugin.tabComplete; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; + +import java.util.List; + +/** + * Created by giampiero on 06/11/14. + */ +public interface OnTabComplete { + + List go(CommandSender sender, Command command, Iterable args); +} diff --git a/ludovico-plugin/src/main/java/it/ludovico/minecraft/plugin/util/DebugLog.java b/ludovico-plugin/src/main/java/it/ludovico/minecraft/plugin/util/DebugLog.java new file mode 100644 index 0000000..84fccdb --- /dev/null +++ b/ludovico-plugin/src/main/java/it/ludovico/minecraft/plugin/util/DebugLog.java @@ -0,0 +1,19 @@ +package it.ludovico.minecraft.plugin.util; + +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import org.slf4j.Logger; + +/** + * Created by giampiero on 04/11/14. + */ +@RequiredArgsConstructor (staticName = "of") +public class DebugLog { + + @NonNull + private Logger log; + + public void debug(String s, Object... arguments) { + log.info("DEBUG " + s, arguments); + } +} diff --git a/ludovico-plugin/src/main/resources/plugin.yml b/ludovico-plugin/src/main/resources/plugin.yml new file mode 100644 index 0000000..d3b96b0 --- /dev/null +++ b/ludovico-plugin/src/main/resources/plugin.yml @@ -0,0 +1,11 @@ +name: ludovico + +author: Ludovico Castaldi +website: https://github.com/giacomo-castaldi +main: it.giacomo.minecraft.plugin.CoderDojoPlugin + +commands: + giacomo-hello-world: + description: Say HELLO ! + usage: /ludovico-hello-world +version: 0.1 diff --git a/redeploy.sh b/redeploy.sh new file mode 100755 index 0000000..c1ad519 --- /dev/null +++ b/redeploy.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +set -e + +export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64 +cd /root/coderdojo-minecraft-bukkit-plugins +git pull +/etc/init.d/craftbukkit stop +./build-and-deploy-plugins.sh /etc/craftbukkit +/etc/init.d/craftbukkit start diff --git a/toto-plugin/build.gradle b/toto-plugin/build.gradle new file mode 100644 index 0000000..4a44c31 --- /dev/null +++ b/toto-plugin/build.gradle @@ -0,0 +1,42 @@ +defaultTasks 'clean', 'build', 'fatJar' + +//prova windows + +apply plugin: 'java' +apply plugin: 'project-report' + +group = 'it.toto.bukkit-hello-world' +version = '0.0.1-SNAPSHOT' +description = "Toto CoderDojo plugin" + +sourceCompatibility = '1.7' +targetCompatibility = '1.7' + +compileJava { + options.encoding = 'UTF-8' +} + +repositories { + mavenLocal() + mavenCentral() + maven { url "http://repo.bukkit.org/content/groups/public/" } + maven { url "https://oss.sonatype.org/content/repositories/public/" } +} + +// This server is running CraftBukkit version git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks (MC: 1.7.10) (Implementing API version 1.7.10-R0.1-SNAPSHOT) +dependencies { + compile 'org.bukkit:bukkit:1.7.9-R0.2' + compile 'org.projectlombok:lombok:1.14.8' + compile 'org.slf4j:slf4j-api:1.7.7' + compile 'ch.qos.logback:logback-classic:1.1.2' + compile 'com.google.guava:guava:18.0' + compile 'com.google.inject:guice:3.0' + compile 'org.glassfish.jersey.core:jersey-client:2.13' +} + +task fatJar(type: Jar) { + exclude 'org/bukkit/**' + baseName = project.name + '-bukkit-plugin' + from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } + with jar +} diff --git a/toto-plugin/gradle/wrapper/gradle-wrapper.jar b/toto-plugin/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..5838598 Binary files /dev/null and b/toto-plugin/gradle/wrapper/gradle-wrapper.jar differ diff --git a/toto-plugin/gradle/wrapper/gradle-wrapper.properties b/toto-plugin/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..7e87d75 --- /dev/null +++ b/toto-plugin/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Thu Nov 06 23:37:22 CET 2014 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=http\://services.gradle.org/distributions/gradle-2.1-all.zip diff --git a/toto-plugin/gradlew b/toto-plugin/gradlew new file mode 100755 index 0000000..91a7e26 --- /dev/null +++ b/toto-plugin/gradlew @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# For Cygwin, ensure paths are in UNIX format before anything is touched. +if $cygwin ; then + [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` +fi + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >&- +APP_HOME="`pwd -P`" +cd "$SAVED" >&- + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/toto-plugin/gradlew.bat b/toto-plugin/gradlew.bat new file mode 100644 index 0000000..8a0b282 --- /dev/null +++ b/toto-plugin/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/toto-plugin/src/main/java/it/toto/minecraft/plugin/AwsJenkinsPush.java b/toto-plugin/src/main/java/it/toto/minecraft/plugin/AwsJenkinsPush.java new file mode 100644 index 0000000..12d1354 --- /dev/null +++ b/toto-plugin/src/main/java/it/toto/minecraft/plugin/AwsJenkinsPush.java @@ -0,0 +1,67 @@ +package it.toto.minecraft.plugin; + +import com.google.inject.Inject; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang.StringUtils; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.util.FileUtil; +import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; + +/** + * Created by toto on 14/12/14. + */ +@Slf4j +public class AwsJenkinsPush extends BukkitRunnable { + + private final PlayerRepository playerRepository; + + @Inject + public AwsJenkinsPush( + PlayerRepository playerRepository + ) { + this.playerRepository = playerRepository; + } + + @Override + public void run() { + if (playerRepository.isNotEmpty()) { + log.info("push {}", playerRepository.info()); + + String auth = StringUtils.EMPTY; + try { + FileReader fileReader = new FileReader("/home/ubuntu/auth.properties"); + BufferedReader bufferedReader = new BufferedReader(fileReader); + auth = bufferedReader.readLine(); + } catch (FileNotFoundException e) { + log.error(null, e); + } catch (IOException e) { + log.error(null,e); + } + + if (StringUtils.isNotBlank(auth)) { + final Response post = ClientBuilder.newClient() + .target("http://api.awsjenkins.skillbill.net") + .path("alives-servers") + .request(MediaType.APPLICATION_JSON) + .header("Authorization", auth) + .post(Entity.json(null)); + log.debug("ping response {}", post); + } else { + log.warn("no authorization config"); + } + } else { + log.info("skip push... no players"); + } + } +} diff --git a/toto-plugin/src/main/java/it/toto/minecraft/plugin/CoderDojoPlugin.java b/toto-plugin/src/main/java/it/toto/minecraft/plugin/CoderDojoPlugin.java new file mode 100644 index 0000000..3a39de7 --- /dev/null +++ b/toto-plugin/src/main/java/it/toto/minecraft/plugin/CoderDojoPlugin.java @@ -0,0 +1,99 @@ +package it.toto.minecraft.plugin; + + +import com.google.common.base.CaseFormat; +import com.google.common.base.Optional; +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.Injector; +import com.google.inject.name.Names; +import it.toto.minecraft.plugin.command.CommandExecution; +import it.toto.minecraft.plugin.listener.AwsJenkinsClient; +import it.toto.minecraft.plugin.listener.BlockPlaceMiniGame; +import it.toto.minecraft.plugin.tabComplete.OnTabComplete; +import lombok.extern.slf4j.Slf4j; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.Arrays; +import java.util.List; + +@Slf4j +public class CoderDojoPlugin extends JavaPlugin { + + private Injector injector; + + public void onLoad() { + + log.info("[ShowCase] LOAD "); + + injector = Guice.createInjector(new AbstractModule() { + @Override + protected void configure() { + bind(String.class).annotatedWith(Names.named("aString")).toInstance("AAAAAA"); + } + }); + } + + public void onEnable() { + getServer().getPluginManager().registerEvents(injector.getInstance(BlockPlaceMiniGame.class), this); + getServer().getPluginManager().registerEvents(injector.getInstance(AwsJenkinsClient.class), this); + + final AwsJenkinsPush awsJenkinsPush = injector.getInstance(AwsJenkinsPush.class); + awsJenkinsPush.runTaskTimerAsynchronously(this, 20, 1200); //1 secondo, 1 minuto + } + + public void onDisable() { + log.info("[ShowCase] DISABLE "); + } + + public boolean onCommand( + CommandSender sender, + Command command, + String commandLabel, + String[] args + ) { + log.debug("sender {}", sender); //GlowPlayer vs net.glowstone.ConsoleManager$ColoredCommandSender + log.debug("command {}", command); //org.bukkit.command.PluginCommand + + final Optional commandExecutionOpt = instanceFromCommandLabel(commandLabel, CommandExecution.class.getPackage()); + + if (commandExecutionOpt.isPresent()) { + return commandExecutionOpt.get().go(sender, command, Arrays.asList(args)); + } else { + return false; + } + } + + @Override + public List onTabComplete( + CommandSender sender, + Command command, + String alias, + String[] args) { + + final Optional onTabCompleteOptional = instanceFromCommandLabel(alias, OnTabComplete.class.getPackage()); + + if (onTabCompleteOptional.isPresent()) { + return onTabCompleteOptional.get().go(sender, command, Arrays.asList(args)); + } else { + return super.onTabComplete(sender ,command, alias, args); + } + + } + + private Optional instanceFromCommandLabel(String commandLabel, Package p) { + String className = p.getName() + "." + CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, commandLabel); + T commandInstance = null; + + try { + commandInstance = (T) injector.getInstance(Class.forName(className)); + } catch (Exception e) { + log.error("can't build command execution class ",e); + } + + return Optional.fromNullable(commandInstance); + } +} + diff --git a/toto-plugin/src/main/java/it/toto/minecraft/plugin/PlayerRepository.java b/toto-plugin/src/main/java/it/toto/minecraft/plugin/PlayerRepository.java new file mode 100644 index 0000000..734ab5f --- /dev/null +++ b/toto-plugin/src/main/java/it/toto/minecraft/plugin/PlayerRepository.java @@ -0,0 +1,41 @@ +package it.toto.minecraft.plugin; + +import com.google.common.collect.Maps; +import com.google.inject.Singleton; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang.StringUtils; +import org.bukkit.entity.Player; + +import java.util.Map; + +/** + * Created by toto on 14/12/14. + */ +@Singleton +@Slf4j +public class PlayerRepository { + + private Map players = Maps.newConcurrentMap(); + + public void quit(Player player) { + players.remove(player.getDisplayName()); + } + + public void join(Player player) { + final String displayName = player.getDisplayName(); + players.put(player.getDisplayName(), player); + log.debug("join {}, {}", displayName, info()); + } + + public String info() { + String info = StringUtils.EMPTY; + for (String s : players.keySet()) { + info = info + s; + } + return info; + } + + public boolean isNotEmpty() { + return !players.isEmpty(); + } +} diff --git a/toto-plugin/src/main/java/it/toto/minecraft/plugin/command/BuildACube.java b/toto-plugin/src/main/java/it/toto/minecraft/plugin/command/BuildACube.java new file mode 100644 index 0000000..7b0e4b4 --- /dev/null +++ b/toto-plugin/src/main/java/it/toto/minecraft/plugin/command/BuildACube.java @@ -0,0 +1,100 @@ +package it.toto.minecraft.plugin.command; + +import com.google.common.collect.Iterables; +import com.google.inject.Inject; +import com.google.inject.name.Named; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang.math.NumberUtils; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +/** + * Created by toto on 05/11/14. + */ +@Slf4j +public class BuildACube implements CommandExecution { + + + Location origin = null; + + @Inject + public BuildACube(@Named("aString") String aString) { + log.debug("aString {}", aString); + } + + // Create a 3D cube, offset from the saved "origin" + void makeCube(int offsetX, int offsetY, int offsetZ, int width, int height, Material what) { + int i, j, k; + Location loc = new Location(origin.getWorld(), 0,0,0); + + // Base is i X j, k goes up for height + for (i=0; i< width; i++) { + for (j=0; j args) { + if (sender instanceof Player) { + Player me = (Player) sender; + // Put your code after this line: + origin = me.getLocation(); + + int width = 6; + int height = 6; + + if ( Iterables.size(args) > 1 && + NumberUtils.isDigits(Iterables.get(args, 0)) && + NumberUtils.isDigits(Iterables.get(args, 1)) + ) { + width = Integer.valueOf(Iterables.get(args, 0)); + height = Integer.valueOf(Iterables.get(args, 1)); + } + + buildMyHouse(width, height); + return true; + } else { + log.warn("command is avaliable on players"); + return false; + } + + } + +} diff --git a/toto-plugin/src/main/java/it/toto/minecraft/plugin/command/CommandExecution.java b/toto-plugin/src/main/java/it/toto/minecraft/plugin/command/CommandExecution.java new file mode 100644 index 0000000..b0da4d1 --- /dev/null +++ b/toto-plugin/src/main/java/it/toto/minecraft/plugin/command/CommandExecution.java @@ -0,0 +1,12 @@ +package it.toto.minecraft.plugin.command; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; + +/** + * Created by toto on 05/11/14. + */ +public interface CommandExecution { + + boolean go(CommandSender sender, Command command, Iterable args); +} diff --git a/toto-plugin/src/main/java/it/toto/minecraft/plugin/command/FlyingCreeper.java b/toto-plugin/src/main/java/it/toto/minecraft/plugin/command/FlyingCreeper.java new file mode 100644 index 0000000..267956d --- /dev/null +++ b/toto-plugin/src/main/java/it/toto/minecraft/plugin/command/FlyingCreeper.java @@ -0,0 +1,50 @@ +package it.toto.minecraft.plugin.command; + +import lombok.extern.slf4j.Slf4j; +import org.bukkit.Location; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Bat; +import org.bukkit.entity.Creeper; +import org.bukkit.entity.Player; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +/** + * Created by toto on 05/11/14. + */ +@Slf4j +public class FlyingCreeper implements CommandExecution { + + + @Override + public boolean go(CommandSender sender, Command command, Iterable args) { + if (sender instanceof Player) { + //il giocatore che ha lanciato il comando + Player player = (Player) sender; + //la posizione del giocatore + Location loc = player.getLocation(); + //sopra la testa del giocatore di 5 blocchi + loc.setY(loc.getY() + 5); + //spawn di un pipistrello + Bat bat = player.getWorld().spawn(loc, Bat.class); + //spawn di un creeper + Creeper creeper = player.getWorld().spawn(loc, Creeper.class); + //il creepar è "passeggero" del pipistrello + bat.setPassenger(creeper); + //efftto pozione di invisibilità massima (con valore 1) + PotionEffect potion = new PotionEffect( + PotionEffectType.INVISIBILITY, + Integer.MAX_VALUE, + 1); + //pozione al pipistrello + bat.addPotionEffect(potion); + return true; + } else { + log.warn("command is avaliable on players"); + return false; + } + + } + +} diff --git a/toto-plugin/src/main/java/it/toto/minecraft/plugin/command/GiveItem.java b/toto-plugin/src/main/java/it/toto/minecraft/plugin/command/GiveItem.java new file mode 100644 index 0000000..ab8d567 --- /dev/null +++ b/toto-plugin/src/main/java/it/toto/minecraft/plugin/command/GiveItem.java @@ -0,0 +1,30 @@ +package it.toto.minecraft.plugin.command; + +import com.google.common.collect.Iterables; +import org.bukkit.Material; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; + +/** + * Created by toto on 14/02/15. + */ +public class GiveItem implements CommandExecution { + + @Override + public boolean go(CommandSender sender, Command command, Iterable args) { + + Player player = (Player) sender; + + PlayerInventory inventory = player.getInventory(); + + Integer times = Integer.valueOf(Iterables.get(args, 1)); + + for (int i=times;i!=0;i--) { + inventory.addItem(new ItemStack(Material.valueOf(Iterables.getFirst(args, "DIRT")))); + } + return true; + } +} diff --git a/toto-plugin/src/main/java/it/toto/minecraft/plugin/command/HelloToto.java b/toto-plugin/src/main/java/it/toto/minecraft/plugin/command/HelloToto.java new file mode 100644 index 0000000..e27e189 --- /dev/null +++ b/toto-plugin/src/main/java/it/toto/minecraft/plugin/command/HelloToto.java @@ -0,0 +1,60 @@ +package it.toto.minecraft.plugin.command; + +import com.google.common.collect.Iterables; +import org.apache.commons.lang.StringUtils; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Cow; +import org.bukkit.entity.Player; + +public class HelloToto implements CommandExecution { + + private static Integer conto = 0; + + public boolean go(CommandSender sender, Command command, Iterable args) { + Player me = (Player)sender; + + conto = conto + 1; + + if (StringUtils.containsIgnoreCase(me.getDisplayName(), "toto")) { + Location miaLocation = me.getLocation(); + + Location oggettoLocation = new Location(me.getWorld(), 0,0,0); + + oggettoLocation.setX(miaLocation.getX() + 5); + oggettoLocation.setZ(miaLocation.getZ() + 5); + oggettoLocation.setY(miaLocation.getY() + 2); + me.getWorld().getBlockAt(oggettoLocation).setType(Material.WOOD); + + } + + if (conto == 10) { + me.sendMessage("BRAVO ECCO LA TUA MUCCA !!!"); + + Cow cow = me.getWorld().spawn(me.getLocation(), Cow.class); + cow.setCustomName(me.getDisplayName()); + cow.setCustomNameVisible(true); + + } else if (conto == 20) { + conto = 1; + + me.sendMessage("TRASFORMAZIONE !!!!"); + + Location miaLocation = me.getLocation(); + + Location oggettoLocation = new Location(me.getWorld(), 0,0,0); + + oggettoLocation.setX(miaLocation.getX() + 5); + oggettoLocation.setZ(miaLocation.getZ() + 5); + oggettoLocation.setY(miaLocation.getY() + 2); + me.getWorld().getBlockAt(oggettoLocation).setType(Material.WOOD); + + } else { + me.sendMessage("CIAO MONDO !!!!!! Sei Arrivato a " + conto); + } + return true; + } + +} diff --git a/toto-plugin/src/main/java/it/toto/minecraft/plugin/command/LavaVision.java b/toto-plugin/src/main/java/it/toto/minecraft/plugin/command/LavaVision.java new file mode 100644 index 0000000..d9f6707 --- /dev/null +++ b/toto-plugin/src/main/java/it/toto/minecraft/plugin/command/LavaVision.java @@ -0,0 +1,42 @@ +package it.toto.minecraft.plugin.command; + +import lombok.extern.slf4j.Slf4j; +import org.bukkit.Effect; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.block.Block; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.util.BlockIterator; + +/** + * Created by toto on 05/11/14. + */ +@Slf4j +public class LavaVision implements CommandExecution { + + @Override + public boolean go(CommandSender sender, Command command, Iterable args) { + if (sender instanceof Player) { + Player me = (Player)sender; + BlockIterator sightItr = new BlockIterator (me, 100); + boolean found = false; + while (sightItr.hasNext() && !found) { + Block b = sightItr.next(); + me.playEffect(b.getLocation(), Effect.MOBSPAWNER_FLAMES, null); + if (b.getType() != Material.AIR) { + b.setType(Material.LAVA); + me.playSound(b.getLocation(), Sound.EXPLODE, 1.0f, 0.5f); + found = true; + } + } + return true; + } else { + log.warn("command is avaliable on players"); + return false; + } + + } + +} diff --git a/toto-plugin/src/main/java/it/toto/minecraft/plugin/command/NameCow.java b/toto-plugin/src/main/java/it/toto/minecraft/plugin/command/NameCow.java new file mode 100644 index 0000000..e459e2b --- /dev/null +++ b/toto-plugin/src/main/java/it/toto/minecraft/plugin/command/NameCow.java @@ -0,0 +1,32 @@ +package it.toto.minecraft.plugin.command; + +import com.google.common.collect.Iterables; +import lombok.extern.slf4j.Slf4j; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Cow; +import org.bukkit.entity.Player; + +/** + * Created by toto on 65/11/14. + */ +@Slf4j +public class NameCow implements CommandExecution { + + + @Override + public boolean go(CommandSender sender, Command command, Iterable args) { + if (sender instanceof Player) { + Player me = (Player)sender; + Cow cow = me.getWorld().spawn(me.getLocation(), Cow.class); + cow.setCustomName(Iterables.getFirst(args, "Cow")); + cow.setCustomNameVisible(true); + return true; + } else { + log.warn("command is avaliable on players"); + return false; + } + + } + +} diff --git a/toto-plugin/src/main/java/it/toto/minecraft/plugin/command/PlayASound.java b/toto-plugin/src/main/java/it/toto/minecraft/plugin/command/PlayASound.java new file mode 100644 index 0000000..10be730 --- /dev/null +++ b/toto-plugin/src/main/java/it/toto/minecraft/plugin/command/PlayASound.java @@ -0,0 +1,33 @@ +package it.toto.minecraft.plugin.command; + +import com.google.common.collect.Iterables; +import lombok.extern.slf4j.Slf4j; +import org.bukkit.Sound; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +/** + * Created by toto on 65/11/14. + */ +@Slf4j +public class PlayASound implements CommandExecution { + + private float volume = 0.1f; + private float pitch = 1.0f; + + @Override + public boolean go(CommandSender sender, Command command, Iterable args) { + String soundName = Iterables.getFirst(args, Sound.GHAST_SCREAM.name()); + if (sender instanceof Player) { + Player me = (Player) sender; + me.playSound(me.getLocation(), Sound.valueOf(soundName), volume, pitch); + return true; + } else { + log.warn("command is avaliable on players"); + return false; + } + + } + +} diff --git a/toto-plugin/src/main/java/it/toto/minecraft/plugin/command/SkyCmd.java b/toto-plugin/src/main/java/it/toto/minecraft/plugin/command/SkyCmd.java new file mode 100644 index 0000000..250fde3 --- /dev/null +++ b/toto-plugin/src/main/java/it/toto/minecraft/plugin/command/SkyCmd.java @@ -0,0 +1,37 @@ +package it.toto.minecraft.plugin.command; + +import java.util.logging.Logger; +import org.bukkit.Location; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.entity.Entity; +import java.util.List; + +/** + * Created by toto on 05/11/14. + */ +public class SkyCmd implements CommandExecution { + + public boolean go(CommandSender sender, Command command, Iterable args) { + if (sender instanceof Player) { //(2) + Player me = (Player)sender; //(3) + List list = me.getNearbyEntities(50,50,50); + for (Entity target : list) { + Location loc = target.getLocation(); + double y = loc.getY(); + double z = loc.getZ(); + double x = loc.getX(); + Location melocation = me.getLocation(); + loc.setY(melocation.getY()); + loc.setZ(melocation.getZ()); + loc.setX(melocation.getY()+5); + target.teleport(loc); + } + } + return true; + } + +} diff --git a/toto-plugin/src/main/java/it/toto/minecraft/plugin/command/WhoAmI.java b/toto-plugin/src/main/java/it/toto/minecraft/plugin/command/WhoAmI.java new file mode 100644 index 0000000..363e6fa --- /dev/null +++ b/toto-plugin/src/main/java/it/toto/minecraft/plugin/command/WhoAmI.java @@ -0,0 +1,41 @@ +package it.toto.minecraft.plugin.command; + +import lombok.extern.slf4j.Slf4j; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; + +/** + * Created by toto on 65/11/14. + */ +@Slf4j +public class WhoAmI implements CommandExecution { + + + @Override + public boolean go(CommandSender sender, Command command, Iterable args) { + if (sender instanceof Player) { + Player me = (Player)sender; + me.sendMessage(String.format("Your list name is %s", me.getPlayerListName())); + me.sendMessage(String.format("Your location is %s", me.getLocation())); + + me.getLocation(); + + float exp = me.getExp(); + int food = me.getFoodLevel(); + boolean grounded = ((Entity)me).isOnGround(); + String groundMsg = ""; + if (!grounded) { + groundMsg = "not "; //(1) + } + me.sendMessage("PROVA 4 !!! Your experience points are " + exp + + ", food is " + food + + "\nwater falls from the sky " + + "and you are " + groundMsg + "on the ground." + ); + } + return true; + } + +} diff --git a/toto-plugin/src/main/java/it/toto/minecraft/plugin/listener/AwsJenkinsClient.java b/toto-plugin/src/main/java/it/toto/minecraft/plugin/listener/AwsJenkinsClient.java new file mode 100644 index 0000000..db61220 --- /dev/null +++ b/toto-plugin/src/main/java/it/toto/minecraft/plugin/listener/AwsJenkinsClient.java @@ -0,0 +1,37 @@ +package it.toto.minecraft.plugin.listener; + +import com.google.inject.Inject; +import it.toto.minecraft.plugin.PlayerRepository; +import lombok.extern.slf4j.Slf4j; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +/** + * Created by toto on 14/12/14. + */ +@Slf4j +public class AwsJenkinsClient implements Listener { + + private PlayerRepository playerRepository; + + @Inject + public void AwsJenkinsClient( + PlayerRepository playerRepository + ) { + this.playerRepository = playerRepository; + } + + @EventHandler + public void onPlayerJoinEvent(PlayerJoinEvent playerJoinEvent) { + log.info("PlayerJoinEvent {}", playerJoinEvent.getPlayer()); + playerRepository.join(playerJoinEvent.getPlayer()); + } + + @EventHandler + public void onPlayerQuitEvent(PlayerQuitEvent playerQuitEvent) { + log.info("PlayerQuitEvent {}", playerQuitEvent.getPlayer()); + playerRepository.quit(playerQuitEvent.getPlayer()); + } +} diff --git a/toto-plugin/src/main/java/it/toto/minecraft/plugin/listener/BlockPlaceMiniGame.java b/toto-plugin/src/main/java/it/toto/minecraft/plugin/listener/BlockPlaceMiniGame.java new file mode 100644 index 0000000..3964933 --- /dev/null +++ b/toto-plugin/src/main/java/it/toto/minecraft/plugin/listener/BlockPlaceMiniGame.java @@ -0,0 +1,103 @@ +package it.toto.minecraft.plugin.listener; + +import com.google.common.base.Optional; +import com.google.common.collect.Lists; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang.builder.ReflectionToStringBuilder; +import org.bukkit.Effect; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockPlaceEvent; + +import java.util.List; + + +/** + * Created by toto on 28/11/14. + */ +@Slf4j +public class BlockPlaceMiniGame implements Listener { + + private final BlockFace[] directions = new BlockFace[]{ + BlockFace.NORTH, + BlockFace.EAST, + BlockFace.SOUTH, + BlockFace.WEST, + }; + + private final Material[] sequence = new Material[]{ + Material.SAND, + Material.DIRT, + Material.WOOD + }; + + @EventHandler + public void onBlockPlace(BlockPlaceEvent blockPlaceEvent) { + //log.debug("onBlockPlace {}", ReflectionToStringBuilder.toString(blockPlaceEvent)); + final Block blockPlaced = blockPlaceEvent.getBlockPlaced(); + if (blockPlaced != null) { + log.info("BlockPlaced {}", blockPlaced); + + final Material blockPlacedType = blockPlaced.getType(); + if (blockPlacedType == sequence[0]) { + Optional nearestGravelOptional = findNearest(blockPlaced, sequence[1]); + + if (nearestGravelOptional.isPresent()) { + + final BlockFace blockFace = nearestGravelOptional.get(); + + int index = 0; + + Block block = blockPlaced; + + List blocks = Lists.newArrayList(); + + boolean found = true; + + while (index < sequence.length && found) { + log.info("relative of {} index {} blockface {}", block, index, blockFace); + if (block.getType() != sequence[index]) { + found = false; + } else { + blocks.add(block); + } + index ++; + block = block.getRelative(blockFace, 1); + } + + if (found) { + log.info("sequence ok !!!!"); + + final Player player = blockPlaceEvent.getPlayer(); + + for (Block b : blocks) { + player.playEffect(b.getLocation(), Effect.MOBSPAWNER_FLAMES, null); + b.setType(Material.AIR); + } + + player.getServer().broadcastMessage(player.getDisplayName() + " ha completato la sequenza !"); + + } else { + log.info("wong sequence of {} index {} blockface {}", block, index, blockFace); + } + + } + } + } + } + + private Optional findNearest(Block block, Material material) { + for (BlockFace direction : directions) { + if (block.getRelative(direction,1).getType() == material) { + return Optional.of(direction); + } + } + return Optional.absent(); + } + +} diff --git a/toto-plugin/src/main/java/it/toto/minecraft/plugin/tabComplete/OnTabComplete.java b/toto-plugin/src/main/java/it/toto/minecraft/plugin/tabComplete/OnTabComplete.java new file mode 100644 index 0000000..2b755b8 --- /dev/null +++ b/toto-plugin/src/main/java/it/toto/minecraft/plugin/tabComplete/OnTabComplete.java @@ -0,0 +1,14 @@ +package it.toto.minecraft.plugin.tabComplete; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; + +import java.util.List; + +/** + * Created by toto on 06/11/14. + */ +public interface OnTabComplete { + + List go(CommandSender sender, Command command, Iterable args); +} diff --git a/toto-plugin/src/main/java/it/toto/minecraft/plugin/tabComplete/PlayASound.java b/toto-plugin/src/main/java/it/toto/minecraft/plugin/tabComplete/PlayASound.java new file mode 100644 index 0000000..4dc52a9 --- /dev/null +++ b/toto-plugin/src/main/java/it/toto/minecraft/plugin/tabComplete/PlayASound.java @@ -0,0 +1,30 @@ +package it.toto.minecraft.plugin.tabComplete; + +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; +import org.apache.commons.lang.StringUtils; +import org.bukkit.Sound; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; + +import java.util.List; + +/** + * Created by toto on 06/11/14. + */ +public class PlayASound implements OnTabComplete { + + @Override + public List go(CommandSender sender, Command command, Iterable args) { + List result = Lists.newArrayList(); + final String containsIgnoreCase = Iterables.getFirst(args, StringUtils.EMPTY); + Sound[] sounds = Sound.values(); + for (Sound sound : sounds) { + if (StringUtils.containsIgnoreCase(sound.name(), containsIgnoreCase)) { + result.add(sound.name()); + } + } + + return result; + } +} diff --git a/toto-plugin/src/main/resources/logback.xml b/toto-plugin/src/main/resources/logback.xml new file mode 100644 index 0000000..ca2a279 --- /dev/null +++ b/toto-plugin/src/main/resources/logback.xml @@ -0,0 +1,24 @@ + + + + + ${user.home}/toto.log + true + + %-4relative [%thread] %-5level %logger{35} - %msg%n + + + + + + %d %-5level [%t %X{uniq}] %logger{36} - %msg%n + + + + + + + + + + \ No newline at end of file diff --git a/toto-plugin/src/main/resources/plugin.yml b/toto-plugin/src/main/resources/plugin.yml new file mode 100644 index 0000000..6637ef5 --- /dev/null +++ b/toto-plugin/src/main/resources/plugin.yml @@ -0,0 +1,36 @@ +name: toto + +author: Toto Castaldi +website: https://github.com/toto-castaldi +main: it.toto.minecraft.plugin.CoderDojoPlugin + +commands: + build-a-cube: + description: Build a Cube + usage: /build-a-cube width height + play-a-sound: + description: Play a Sound + usage: /play-a-sound soundName + #NOT SUPPORTED IN GLOWSTONE 1.8 + name-cow: + description: Creates a Cow and Give it a name + usage: /name-cow name + who-am-i: + description: Player info + usage: /who-am-i + lava-vision: + description: Turn block near me into LAVA + usage: /lava-vision + flying-creeper: + description: Spawn a Flying Creeper + usage: /flying-creeper + give-item: + description: Give an Item to the Player + usage: /give-item + hello-toto: + description: Ciao + usage: /hello-toto + sky-cmd: + description: Ciao + usage: /sky-cmd +version: 0.1