commit 7bdaafed48605a3e33d469697a6e758c311d3770 Author: Kalle Struik Date: Sat Apr 8 23:31:06 2023 +0200 Finally put this on git diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..76483db --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.idea/ +.gradle/ +build/ + +*.iml + diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..97b743b --- /dev/null +++ b/build.gradle @@ -0,0 +1,51 @@ +plugins { + id "com.github.johnrengelman.shadow" version "2.0.4" + id "java" + id "maven" + id "net.ltgt.apt" version "0.10" + id "io.franzbecker.gradle-lombok" version "1.14" +} + +group = pluginGroup +version = pluginVersion + +sourceCompatibility = 1.8 +targetCompatibility = 1.8 + +lombok { + version = '1.18.2' + sha256 = "" +} + +repositories { + mavenCentral() + mavenLocal() + maven { + name = 'spigotmc-repo' + url = 'https://hub.spigotmc.org/nexus/content/groups/public/' + } + + maven { + name = 'sonatype' + url = 'https://oss.sonatype.org/content/groups/public/' + } + + maven { + name = 'nexus-hc' + url = 'http://nexus.hc.to/content/repositories/pub_releases/' + } +} + +dependencies { + compile 'org.spigotmc:spigot:1.8.8-R0.1-SNAPSHOT' + compile 'org.bukkit:bukkit:1.8.8-R0.1-SNAPSHOT' + apt 'org.projectlombok:lombok:1.14.8' +} + +import org.apache.tools.ant.filters.ReplaceTokens + +processResources { + from(sourceSets.main.resources.srcDirs) { + filter ReplaceTokens, tokens: [version: version] + } +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..32f3c88 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,2 @@ +pluginGroup=nl.dragontamerfred +pluginVersion=1.0 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..c821d9e Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..9ecd82d --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Sun Sep 23 09:18:26 CEST 2018 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..4453cce --- /dev/null +++ b/gradlew @@ -0,0 +1,172 @@ +#!/usr/bin/env sh + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# 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\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +# 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 +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +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" -a "$nonstop" = "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"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # 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 + +# Escape application args +save ( ) { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..e95643d --- /dev/null +++ b/gradlew.bat @@ -0,0 +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= + +@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 diff --git a/src/main/java/nl/dragontamerfred/combattag/CombatManager.java b/src/main/java/nl/dragontamerfred/combattag/CombatManager.java new file mode 100644 index 0000000..a7a0459 --- /dev/null +++ b/src/main/java/nl/dragontamerfred/combattag/CombatManager.java @@ -0,0 +1,103 @@ +package nl.dragontamerfred.combattag; + +import org.bukkit.Bukkit; + +import java.util.HashMap; +import java.util.UUID; + +public class CombatManager { + + /** + * The HashMap containing the players currently in combat. + */ + private static HashMap combatPlayers = new HashMap<>(); + + /** + * Freeze the combat time of a player making it not decrease anymore until unfrozen. + * @param uuid The {@link UUID} of the player. + */ + public static void freezeCombatTime(UUID uuid) { + if (combatPlayers.containsKey(uuid)) { + combatPlayers.get(uuid).setIsFrozen(true); + } + } + + /** + * Unfreeze the combat time of a player making it decrease normally again. + * @param uuid The {@link UUID} of the player. + */ + public static void unfreezeCombatTime(UUID uuid) { + if (combatPlayers.containsKey(uuid)) { + combatPlayers.get(uuid).setIsFrozen(false); + } + } + + /** + * Get if the player's combat time is frozen. + * @param uuid The {@link UUID} of the player to check. + * @return true if frozen, false otherwise. + */ + public static boolean getFrozen(UUID uuid) { + if (combatPlayers.containsKey(uuid)) { + return combatPlayers.get(uuid).getIsFrozen(); + } + return false; + } + + /** + * Set the combat time for a player. + * @param uuid The {@link UUID} of the player to set. + * @param amount The amount ot set it to. + */ + public static void setCombatTime(UUID uuid, Integer amount) { + if (combatPlayers.containsKey(uuid)) + combatPlayers.get(uuid).setCombatTime(amount); + else + combatPlayers.put(uuid, new CombatPlayer(Bukkit.getPlayer(uuid), amount)); + } + + /** + * Increase the combat time of a player. + * @param uuid The {@link UUID} of the player to increase. + * @param amount The amount of time to increase it by. + * @param reason The reason the time is getting increased. + */ + public static void increaseCombatTime(UUID uuid, Integer amount, String reason) { + if (combatPlayers.containsKey(uuid)) + combatPlayers.get(uuid).increaseCombatTime(amount, reason); + } + + /** + * Decrease the combat time of a player. + * @param uuid The {@link UUID} of the player to decrease. + * @param amount The amount of time to decrease it by. + * @param reason The reason the time is getting decreased. + */ + public static void decreaseCombatTime(UUID uuid, Integer amount, String reason) { + if (combatPlayers.containsKey(uuid)) + combatPlayers.get(uuid).increaseCombatTime(amount, reason); + } + + /** + * Get the remaining combat time of a player. + * @param uuid The {@link UUID} of the player to check. + * @return The amount of combat time left. + */ + public static int getCombatTime(UUID uuid) { + if (combatPlayers.containsKey(uuid)) + return combatPlayers.get(uuid).getCombatTime(); + else + return 0; + } + + /** + * Remove a player from the combatPlayers HashMap so they can go into combat again. + * @param uuid + */ + public static void cleanup(UUID uuid) { + if (combatPlayers.containsKey(uuid)) + combatPlayers.get(uuid).cleanup(); + combatPlayers.remove(uuid); + } + +} diff --git a/src/main/java/nl/dragontamerfred/combattag/CombatPlayer.java b/src/main/java/nl/dragontamerfred/combattag/CombatPlayer.java new file mode 100644 index 0000000..5487eac --- /dev/null +++ b/src/main/java/nl/dragontamerfred/combattag/CombatPlayer.java @@ -0,0 +1,98 @@ +package nl.dragontamerfred.combattag; + +import lombok.Getter; +import lombok.Setter; +import net.minecraft.server.v1_8_R3.IChatBaseComponent; +import net.minecraft.server.v1_8_R3.PacketPlayOutChat; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; +import org.bukkit.entity.Player; + +public class CombatPlayer { + + @Getter + private Player player; + @Getter + @Setter + private Integer combatTime; + @Getter + @Setter + private Boolean isFrozen = false; + private String reason; + private Integer change; + private ChatColor changeColor; + private final int[] taskNumber = new int[1]; + + public CombatPlayer(Player player, Integer combatTime) { + this.player = player; + this.combatTime = combatTime; + startTimer(); + } + + private void startTimer() { + taskNumber[0] = Bukkit.getScheduler().scheduleAsyncRepeatingTask(CombatTag.plugin, () -> { + if (combatTime <= 0) { + Bukkit.getScheduler().cancelTask(taskNumber[0]); + CombatManager.cleanup(player.getUniqueId()); + } + String message; + String combatTimeString; + if (isFrozen) { + combatTimeString = ChatColor.BLUE + "Frozen"; + } else { + combatTimeString = combatTime.toString(); + } + if (reason != null && !reason.equals("")) { + String changeString; + if (change > 0) + changeString = "+" + change.toString(); + else + changeString = change.toString(); + + message = Messages.COMBAT_TAG_INFO_CHANGE_FORMAT + .replaceAll("", combatTimeString) + .replaceAll("", changeColor.toString()) + .replaceAll("", changeString) + .replaceAll("", reason); + } else { + message = Messages.COMBAT_TAG_INFO_FORMAT + .replaceAll("", combatTimeString); + } + CraftPlayer craftPlayer = (CraftPlayer) player; + IChatBaseComponent cbc = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + message + "\"}"); + PacketPlayOutChat ppoc = new PacketPlayOutChat(cbc, (byte)2); + craftPlayer.getHandle().playerConnection.sendPacket(ppoc); + if (!isFrozen) + combatTime--; + },0,20); + } + + public void cleanup() { + Bukkit.getScheduler().cancelTask(taskNumber[0]); + } + + public void increaseCombatTime(Integer amount, String reason) { + change = amount; + changeColor = ChatColor.RED; + this.reason = reason; + combatTime = combatTime+amount; + Bukkit.getScheduler().scheduleSyncDelayedTask(CombatTag.plugin, () -> { + this.reason = ""; + this.change = 0; + this.changeColor = ChatColor.RESET; + }, 40); + } + + public void decreaseCombatTime(Integer amount, String reason) { + change = amount * -1; + changeColor = ChatColor.GREEN; + this.reason = reason; + combatTime = combatTime-amount; + Bukkit.getScheduler().scheduleSyncDelayedTask(CombatTag.plugin, () -> { + this.reason = ""; + this.change = 0; + this.changeColor = ChatColor.RESET; + }, 40); + } +} diff --git a/src/main/java/nl/dragontamerfred/combattag/CombatTag.java b/src/main/java/nl/dragontamerfred/combattag/CombatTag.java new file mode 100644 index 0000000..2417543 --- /dev/null +++ b/src/main/java/nl/dragontamerfred/combattag/CombatTag.java @@ -0,0 +1,48 @@ +package nl.dragontamerfred.combattag; + +import nl.dragontamerfred.combattag.Handlers.CombatHandler; +import org.bukkit.ChatColor; +import org.bukkit.plugin.java.JavaPlugin; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.OutputStream; + +public final class CombatTag extends JavaPlugin { + + public static CombatTag plugin; + + @Override + public void onEnable() { + plugin = this; + getServer().getPluginManager().registerEvents(new CombatHandler(), this); + Config.load(new File(getDataFolder(), "config.yml")); + Messages.load(new File(getDataFolder(), "messages.yml")); + } + + @Override + public void onDisable() { + // Plugin shutdown logic + } + + public static void ExportResource(String resourceName, File output) { + try (InputStream stream = CombatTag.class.getResourceAsStream(resourceName); OutputStream resStreamOut = new FileOutputStream(output)) { + if (stream == null) { + throw new Exception("Cannot get resource \"" + resourceName + "\" from Jar file."); + } + + int readBytes; + byte[] buffer = new byte[4096]; + while ((readBytes = stream.read(buffer)) > 0) { + resStreamOut.write(buffer, 0, readBytes); + } + } catch (Exception ex) { + //Fail silently + } + } + + public static String colorCodes(String string) { + return ChatColor.translateAlternateColorCodes('&', string); + } +} diff --git a/src/main/java/nl/dragontamerfred/combattag/Config.java b/src/main/java/nl/dragontamerfred/combattag/Config.java new file mode 100644 index 0000000..e87ee0d --- /dev/null +++ b/src/main/java/nl/dragontamerfred/combattag/Config.java @@ -0,0 +1,31 @@ +package nl.dragontamerfred.combattag; + +import org.bukkit.configuration.file.YamlConfiguration; + +import java.io.File; +import java.util.List; + +public class Config { + + public static Integer COMBAT_TIME; + public static Integer EPEARL_PENALTY; + public static List BANNED_COMMANDS; + + public static void load(File file) { + try { + if (!file.getParentFile().exists()) + file.getParentFile().mkdirs(); + if (!file.exists()) + CombatTag.ExportResource("/config.yml", file); + YamlConfiguration config = new YamlConfiguration(); + config.load(file); + + COMBAT_TIME = config.getInt("combat-time"); + EPEARL_PENALTY = config.getInt("enderpearl-penalty"); + BANNED_COMMANDS = config.getStringList("banned-commands"); + + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/nl/dragontamerfred/combattag/Handlers/CombatHandler.java b/src/main/java/nl/dragontamerfred/combattag/Handlers/CombatHandler.java new file mode 100644 index 0000000..8e7d8c8 --- /dev/null +++ b/src/main/java/nl/dragontamerfred/combattag/Handlers/CombatHandler.java @@ -0,0 +1,89 @@ +package nl.dragontamerfred.combattag.Handlers; + +import nl.dragontamerfred.combattag.CombatManager; +import nl.dragontamerfred.combattag.Config; +import nl.dragontamerfred.combattag.Messages; +import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.player.*; + +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + +public class CombatHandler implements Listener { + + private static Set kickedPlayers = new HashSet<>(); + + @EventHandler + public void on(PlayerMoveEvent event) { + Player player = event.getPlayer(); + if (player.isSprinting()) { + CombatManager.freezeCombatTime(player.getUniqueId()); + } else { + CombatManager.unfreezeCombatTime(player.getUniqueId()); + } + } + + @EventHandler + public void on(EntityDamageByEntityEvent event) { + if (event.getEntity() instanceof Player) { + Player damaged = ((Player) event.getEntity()); + if (event.getCause() == EntityDamageEvent.DamageCause.ENTITY_ATTACK) { + if (event.getDamager() instanceof Player) { + Player damager = ((Player) event.getDamager()); + if (damager.getUniqueId() != damaged.getUniqueId()) { + CombatManager.setCombatTime(damager.getUniqueId(), Config.COMBAT_TIME); + CombatManager.setCombatTime(damaged.getUniqueId(), Config.COMBAT_TIME); + } + } + } else if (event.getCause() == EntityDamageEvent.DamageCause.PROJECTILE) { + if (event.getDamager() instanceof Projectile) { + Projectile projectile = ((Projectile) event.getDamager()); + if (projectile.getShooter() instanceof Player) { + Player damager = ((Player) projectile.getShooter()); + if (damager.getUniqueId() != damaged.getUniqueId()) { + CombatManager.setCombatTime(damager.getUniqueId(), Config.COMBAT_TIME); + CombatManager.setCombatTime(damaged.getUniqueId(), Config.COMBAT_TIME); + } + } + } + } + } + } + + @EventHandler + public void on(PlayerTeleportEvent event) { + if (event.getCause() == PlayerTeleportEvent.TeleportCause.ENDER_PEARL) { + CombatManager.increaseCombatTime(event.getPlayer().getUniqueId(), Config.EPEARL_PENALTY, Messages.EPEARL_REASON); + } + } + + @EventHandler + public void on(PlayerCommandPreprocessEvent event) { + String command = event.getMessage().split(" ")[0].replaceAll("/", ""); + if (Config.BANNED_COMMANDS.contains(command.toLowerCase())) { + event.setCancelled(true); + event.getPlayer().sendMessage(Messages.COMMAND_DISABLED_IN_COMBAT + .replaceAll("", command)); + } + } + + @EventHandler + public void on(PlayerKickEvent event) { + kickedPlayers.add(event.getPlayer().getUniqueId()); + } + + @EventHandler + public void on(PlayerQuitEvent event) { + if (!kickedPlayers.contains(event.getPlayer().getUniqueId())) { + if (CombatManager.getCombatTime(event.getPlayer().getUniqueId()) > 0) + event.getPlayer().setHealth(0); + } else + kickedPlayers.remove(event.getPlayer().getUniqueId()); + } +} diff --git a/src/main/java/nl/dragontamerfred/combattag/Messages.java b/src/main/java/nl/dragontamerfred/combattag/Messages.java new file mode 100644 index 0000000..27b7186 --- /dev/null +++ b/src/main/java/nl/dragontamerfred/combattag/Messages.java @@ -0,0 +1,35 @@ +package nl.dragontamerfred.combattag; + +import org.bukkit.configuration.file.YamlConfiguration; + +import java.io.File; + +import static nl.dragontamerfred.combattag.CombatTag.colorCodes; + +public class Messages { + + public static String COMBAT_TAG_INFO_FORMAT; + public static String COMBAT_TAG_INFO_CHANGE_FORMAT; + + public static String EPEARL_REASON; + public static String COMMAND_DISABLED_IN_COMBAT; + + public static void load(File file) { + try { + if (!file.getParentFile().exists()) + file.getParentFile().mkdirs(); + if (!file.exists()) + CombatTag.ExportResource("/messages.yml", file); + YamlConfiguration config = new YamlConfiguration(); + config.load(file); + + COMBAT_TAG_INFO_FORMAT = colorCodes(config.getString("combat-tag-info-format")); + COMBAT_TAG_INFO_CHANGE_FORMAT = colorCodes(config.getString("combat-tag-info-change-format")); + + EPEARL_REASON = colorCodes(config.getString("epearl-reason")); + COMMAND_DISABLED_IN_COMBAT = colorCodes(config.getString("command-disabled-in-combat")); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..355476c --- /dev/null +++ b/src/main/resources/config.yml @@ -0,0 +1,18 @@ +# The combat time to set when entering combat. +combat-time: 15 +# The penalty to give to the combat time when someone enderpearls successfully. +enderpearl-penalty: 10 +# The list of banned commands. These should be lower case. +banned-commands: +- 'spawn' +- 'espawn' +- 'essentials:spawn' +- 'essentials:espawn' +- 'tpa' +- 'etpa' +- 'essentials:tpa' +- 'essentials:etpa' +- 'tpask' +- 'etpask' +- 'essentials:tpask' +- 'essentials:etpask' \ No newline at end of file diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml new file mode 100644 index 0000000..a542bde --- /dev/null +++ b/src/main/resources/messages.yml @@ -0,0 +1,8 @@ +# The message displayed above someones hotbar when they are in combat. Accepted placeholders: . +combat-tag-info-format: "&7Combat:&f " +# The message displayed above someones hotbar when they are in combat and their combat tiem gets modified. Accepted placeholders: . , and . +combat-tag-info-change-format: "&7Combat:&f &f[&5&f]" +# The reason displayed when combat time gets increased because of ender pearling. +epearl-reason: "Enderpearled" +# The message displayed to the player when they try to use a banned command in combat. Accepted placeholders: . +command-disabled-in-combat: "&8[&c&lPatron&7Tag&8] &7&c can not be used while in combat." \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..2a5c2a7 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,3 @@ +name: CombatTag +version: @version@ +main: nl.dragontamerfred.combattag.CombatTag