Skip to content

Commit

Permalink
Add configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
Torm committed Mar 30, 2020
1 parent 9983bcc commit 58e381e
Show file tree
Hide file tree
Showing 16 changed files with 1,728 additions and 1,413 deletions.
46 changes: 23 additions & 23 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
1,348 changes: 674 additions & 674 deletions LICENSE

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# FarmingUpgrade
Upgraded farming mechanics.
### Compatibility
Tested for Spigot 1.15.2.
### Features
- Harvesting a grown crop with a hoe automatically replants the crop.
- Hoes do not break crops that are not fully grown.
- Hoes harvest grown crops within a range. Wood and stone have a range of 0, iron and gold a range of 1 and diamond a range of 2.
- Hoes with higher enchantment levels of Unbreaking have a lower chance to take damage when harvesting crops.
- Higher levels of Efficiency increases the range of the hoe. For every 2 levels of Efficiency, the hoe gains 1 range.
- Farmland is no longer trampled. Instead, the crop that is planted on it is reset to its first growth stage.
- Water can be placed up to 2 blocks underneath Farmland to hydrate it.
### Installation
Place the FarmingUpgrade jar file in the Bukkit server's plugins directory.
# FarmingUpgrade
Upgraded farming mechanics.
### Compatibility
Tested for Spigot 1.15.2.
### Features
- Harvesting a grown crop with a hoe automatically replants the crop.
- Hoes do not break crops that are not fully grown.
- Hoes harvest grown crops within a range. Wood and stone have a range of 0, iron and gold a range of 1 and diamond a range of 2.
- Hoes with higher enchantment levels of Unbreaking have a lower chance to take damage when harvesting crops.
- Higher levels of Efficiency increases the range of the hoe. For every 2 levels of Efficiency, the hoe gains 1 range.
- Farmland is no longer trampled. Instead, the crop that is planted on it is reset to its first growth stage.
- Water can be placed up to 2 blocks underneath Farmland to hydrate it.
### Installation
Place the FarmingUpgrade jar file in the Bukkit server's plugins directory.
36 changes: 18 additions & 18 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
plugins {
id 'java'
}

group 'no.hyp'
version '1.0.0'

sourceCompatibility = 1.8

repositories {
mavenLocal()
mavenCentral()
}

dependencies {
compileOnly 'org.spigotmc:spigot-api:1.15.1-R0.1-SNAPSHOT'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
plugins {
id 'java'
}

group 'no.hyp'
version '1.1.0'

sourceCompatibility = 1.8

repositories {
mavenLocal()
mavenCentral()
}

dependencies {
compileOnly 'org.spigotmc:spigot-api:1.15.2-R0.1-SNAPSHOT'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
12 changes: 6 additions & 6 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Mar 24 00:37:42 CET 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
#Tue Mar 24 00:37:42 CET 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
168 changes: 84 additions & 84 deletions gradlew.bat
Original file line number Diff line number Diff line change
@@ -1,84 +1,84 @@
@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

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@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="-Xmx64m"

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

if not "%OS%" == "Windows_NT" goto win9xME_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=%*

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

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@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="-Xmx64m"

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

if not "%OS%" == "Windows_NT" goto win9xME_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=%*

: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
4 changes: 2 additions & 2 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
rootProject.name = 'FarmingUpgrade'

rootProject.name = 'FarmingUpgrade'

86 changes: 86 additions & 0 deletions src/main/java/no/hyp/farmingupgrade/ConfigurationWatcher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package no.hyp.farmingupgrade;

import org.bukkit.Bukkit;

import java.io.IOException;
import java.nio.file.*;

import static java.nio.file.StandardWatchEventKinds.*;

/**
* This runnable watches for changes to the configuration file. When the configuration is modified,
* the plugin reads the configuration again. This allows a user to edit the configuration and see
* the changes in game without reloading the server.
*/
class ConfigurationWatcher implements Runnable {

private final FarmingUpgrade plugin;

private final Path path;

public ConfigurationWatcher(FarmingUpgrade plugin, Path path) {
this.plugin = plugin;
this.path = path;
}

@Override
public void run() {
// Create a WatchService that watches for changes to the configuration file.
WatchService configurationWatcher;
try {
configurationWatcher = FileSystems.getDefault().newWatchService();
path.register(configurationWatcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
} catch (IOException e) {
e.printStackTrace();
return;
}
// Keep polling the WatchService for changes.
while (true) {
WatchKey key;
try {
key = configurationWatcher.take();
// Sleep a short time to collect duplicate events.
Thread.sleep(50);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
break;
}
for (WatchEvent event : key.pollEvents()) {
if (event.context() instanceof Path) {
WatchEvent<Path> pathEvent = (WatchEvent<Path>) event;
if (pathEvent.context().toString().equals("config.yml")) {
// If the configuration is created, read it.
if (event.kind() == ENTRY_CREATE) {
Bukkit.getScheduler().runTask(plugin, (() -> {
plugin.getLogger().info("Configuration was created.");
plugin.reloadConfig();
}));
// If the configuration is deleted, the user is probably replacing it. Do nothing in the meanwhile.
} else if (event.kind() == ENTRY_DELETE) {
Bukkit.getScheduler().runTask(plugin, (() -> {
plugin.getLogger().info("Configuration was deleted.");
}));
// If the configuration is modified, reload it.
} else if (event.kind() == ENTRY_MODIFY) {
Bukkit.getScheduler().runTask(plugin, (() -> {
plugin.getLogger().info("Configuration was modified.");
plugin.reloadConfig();
}));
}
}
}
}
key.reset();
}
// Finish by closing the WatchService.
try {
configurationWatcher.close();
} catch (IOException e) {
e.printStackTrace();
Bukkit.getScheduler().runTask(plugin, () -> {
plugin.getLogger().severe("Error closing configuration watcher.");
});
}
}

}
Loading

0 comments on commit 58e381e

Please sign in to comment.