diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 8e6d36c..0000000 --- a/build.gradle +++ /dev/null @@ -1,52 +0,0 @@ -plugins { - id 'java' - id 'com.github.johnrengelman.shadow' version '7.1.0' -} - -group = 'me.bloodyhan' -version = '5.0.0' - -repositories { - mavenCentral() - maven { - name = 'spigotmc-repo' - url = 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/' - } - maven { - name = 'sonatype' - url = 'https://oss.sonatype.org/content/groups/public/' - } - maven { - url = 'https://repo.extendedclip.com/content/repositories/placeholderapi/' - } -} - -dependencies { - compileOnly 'org.spigotmc:spigot-api:1.8.8-R0.1-SNAPSHOT' - implementation 'com.zaxxer:HikariCP:3.4.5' - compileOnly 'org.projectlombok:lombok:1.18.22' - compileOnly 'me.clip:placeholderapi:2.10.10' - - annotationProcessor 'org.projectlombok:lombok:1.18.22' - testCompileOnly 'org.projectlombok:lombok:1.18.22' - testAnnotationProcessor 'org.projectlombok:lombok:1.18.22' -} - -processResources { - def props = [version: version] - inputs.properties props - filteringCharset 'UTF-8' - filesMatching('plugin.yml') { - expand props - } -} - -tasks.withType(JavaCompile){ - options.encoding = "UTF-8"; -} - -shadowJar { - baseName = 'BridgeLeveling' - classifier = null - relocate 'com.zaxxer.hikari', 'me.bloodyhan.lib.hikari' -} diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..67aee15 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,61 @@ +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar + +plugins { + java + id("com.github.johnrengelman.shadow") version "7.1.0" +} + +group = "me.bloodyhan" +version = "5.0.1" + +repositories { + mavenCentral() + maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") + maven("https://oss.sonatype.org/content/groups/public/") + maven("https://repo.extendedclip.com/content/repositories/placeholderapi/") +} + +dependencies { + compileOnly("org.spigotmc:spigot-api:1.8.8-R0.1-SNAPSHOT") + implementation("com.zaxxer:HikariCP:4.0.3") + compileOnly("org.projectlombok:lombok:1.18.22") + compileOnly("me.clip:placeholderapi:2.10.10") + + annotationProcessor("org.projectlombok:lombok:1.18.22") + testCompileOnly("org.projectlombok:lombok:1.18.22") + testAnnotationProcessor("org.projectlombok:lombok:1.18.22") +} + +tasks { + + withType { + options.encoding = "UTF-8" + } + + val fatJar by named("shadowJar", ShadowJar::class) { + archiveFileName.set("${project.name}-${project.version}.jar") + + dependencies { + exclude(dependency("org.slf4j:.*")) + } + + relocate("com.zaxxer", "me.bloodyhan.libs.com.zaxxer") + minimize() + } + + artifacts { + add("archives", fatJar) + } + + processResources { + inputs.property("version", project.version) + filesMatching("plugin.yml") { + expand("version" to project.version) + } + } + + build { + dependsOn(shadowJar) + } + +} \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 05679dc..ffed3a2 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index c092a3f..0000000 --- a/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -rootProject.name = 'BridgeLeveling' diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..fff105b --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1 @@ +rootProject.name = "BridgeLeveling" \ No newline at end of file diff --git a/src/main/java/me/bloodyhan/bridgeleveling/Main.java b/src/main/java/me/bloodyhan/bridgeleveling/Main.java index 1c6ca43..837b9f2 100644 --- a/src/main/java/me/bloodyhan/bridgeleveling/Main.java +++ b/src/main/java/me/bloodyhan/bridgeleveling/Main.java @@ -19,7 +19,6 @@ import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.scheduler.BukkitTask; /** * @author Bloody_Han diff --git a/src/main/java/me/bloodyhan/bridgeleveling/api/PlayerData.java b/src/main/java/me/bloodyhan/bridgeleveling/api/PlayerData.java index d9f7711..e7d8ac9 100644 --- a/src/main/java/me/bloodyhan/bridgeleveling/api/PlayerData.java +++ b/src/main/java/me/bloodyhan/bridgeleveling/api/PlayerData.java @@ -14,7 +14,6 @@ import me.bloodyhan.bridgeleveling.database.SqlValue; import me.bloodyhan.bridgeleveling.database.Value; import me.bloodyhan.bridgeleveling.database.ValueType; -import me.bloodyhan.bridgeleveling.task.BridgeTask; import me.bloodyhan.bridgeleveling.util.Method; import me.clip.placeholderapi.PlaceholderAPI; import org.bukkit.Bukkit; @@ -22,7 +21,10 @@ import org.bukkit.Sound; import org.bukkit.entity.Player; -import java.util.*; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.UUID; /** * @author Bloody_Han @@ -40,9 +42,7 @@ public class PlayerData { private int levelUpCost; private int killStreak = 0; private int blockPlace = 0; - private Player lastDamager = null; private Rank rank = null; - private BridgeTask task; private static HashMap dataMap = Maps.newHashMap(); public PlayerData(@NonNull UUID uuid){ diff --git a/src/main/java/me/bloodyhan/bridgeleveling/api/PlayerKillEvent.java b/src/main/java/me/bloodyhan/bridgeleveling/api/PlayerKillEvent.java index 8f34b9d..7e8fcba 100644 --- a/src/main/java/me/bloodyhan/bridgeleveling/api/PlayerKillEvent.java +++ b/src/main/java/me/bloodyhan/bridgeleveling/api/PlayerKillEvent.java @@ -22,8 +22,8 @@ public PlayerKillEvent(Player player, Player killer) { @Override public HandlerList getHandlers() { - return handlers; - } + return handlers; + } public static HandlerList getHandlerList() { return handlers; diff --git a/src/main/java/me/bloodyhan/bridgeleveling/api/Rank.java b/src/main/java/me/bloodyhan/bridgeleveling/api/Rank.java index ba6b461..0d5865d 100644 --- a/src/main/java/me/bloodyhan/bridgeleveling/api/Rank.java +++ b/src/main/java/me/bloodyhan/bridgeleveling/api/Rank.java @@ -1,6 +1,5 @@ package me.bloodyhan.bridgeleveling.api; -import lombok.AccessLevel; import lombok.Getter; /** diff --git a/src/main/java/me/bloodyhan/bridgeleveling/command/BridgeCommand.java b/src/main/java/me/bloodyhan/bridgeleveling/command/BridgeCommand.java index c39707b..3ac9281 100644 --- a/src/main/java/me/bloodyhan/bridgeleveling/command/BridgeCommand.java +++ b/src/main/java/me/bloodyhan/bridgeleveling/command/BridgeCommand.java @@ -2,7 +2,6 @@ import me.bloodyhan.bridgeleveling.Main; import me.bloodyhan.bridgeleveling.api.PlayerData; -import me.bloodyhan.bridgeleveling.config.MainConfig; import me.bloodyhan.bridgeleveling.config.MessageConfig; import me.bloodyhan.bridgeleveling.util.Method; import me.clip.placeholderapi.PlaceholderAPI; diff --git a/src/main/java/me/bloodyhan/bridgeleveling/command/CommandManager.java b/src/main/java/me/bloodyhan/bridgeleveling/command/CommandManager.java index e4dac59..6631e86 100644 --- a/src/main/java/me/bloodyhan/bridgeleveling/command/CommandManager.java +++ b/src/main/java/me/bloodyhan/bridgeleveling/command/CommandManager.java @@ -14,12 +14,15 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.math.BigDecimal; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; /** * @author Bongle (Boougouh) - * @createDate 2020/04/05 * @version 2.1 + * @createDate 2020/04/05 */ public class CommandManager extends BukkitCommand { @@ -284,4 +287,4 @@ public enum CommandOnly{ } -} +} \ No newline at end of file diff --git a/src/main/java/me/bloodyhan/bridgeleveling/config/ConfigManager.java b/src/main/java/me/bloodyhan/bridgeleveling/config/ConfigManager.java index bfad6c2..93fc276 100644 --- a/src/main/java/me/bloodyhan/bridgeleveling/config/ConfigManager.java +++ b/src/main/java/me/bloodyhan/bridgeleveling/config/ConfigManager.java @@ -1,7 +1,6 @@ package me.bloodyhan.bridgeleveling.config; import me.bloodyhan.bridgeleveling.Main; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.configuration.file.YamlConfiguration; diff --git a/src/main/java/me/bloodyhan/bridgeleveling/config/SoundConfig.java b/src/main/java/me/bloodyhan/bridgeleveling/config/SoundConfig.java index b09424e..16b7888 100644 --- a/src/main/java/me/bloodyhan/bridgeleveling/config/SoundConfig.java +++ b/src/main/java/me/bloodyhan/bridgeleveling/config/SoundConfig.java @@ -1,8 +1,5 @@ package me.bloodyhan.bridgeleveling.config; -import org.bukkit.Bukkit; -import org.bukkit.Sound; - /** * @author Bloody_Han */ diff --git a/src/main/java/me/bloodyhan/bridgeleveling/database/MySQL.java b/src/main/java/me/bloodyhan/bridgeleveling/database/MySQL.java index 3aa2fa2..a2c5226 100644 --- a/src/main/java/me/bloodyhan/bridgeleveling/database/MySQL.java +++ b/src/main/java/me/bloodyhan/bridgeleveling/database/MySQL.java @@ -1,16 +1,12 @@ package me.bloodyhan.bridgeleveling.database; -import com.google.common.base.Joiner; import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; import me.bloodyhan.bridgeleveling.Main; import me.bloodyhan.bridgeleveling.config.MainConfig; import java.sql.Connection; -import java.sql.PreparedStatement; import java.sql.SQLException; -import java.util.Arrays; -import java.util.stream.Collectors; /** * @author Bloody_Han diff --git a/src/main/java/me/bloodyhan/bridgeleveling/database/SQLite.java b/src/main/java/me/bloodyhan/bridgeleveling/database/SQLite.java index 5c1b325..e69d829 100644 --- a/src/main/java/me/bloodyhan/bridgeleveling/database/SQLite.java +++ b/src/main/java/me/bloodyhan/bridgeleveling/database/SQLite.java @@ -2,13 +2,10 @@ import com.google.common.base.Joiner; import com.google.common.collect.Lists; -import com.zaxxer.hikari.HikariConfig; -import com.zaxxer.hikari.HikariDataSource; import me.bloodyhan.bridgeleveling.Main; import org.bukkit.Bukkit; import java.io.File; -import java.io.IOException; import java.sql.*; import java.util.Arrays; import java.util.List; diff --git a/src/main/java/me/bloodyhan/bridgeleveling/listener/KillListener.java b/src/main/java/me/bloodyhan/bridgeleveling/listener/KillListener.java index 5077e34..537380f 100644 --- a/src/main/java/me/bloodyhan/bridgeleveling/listener/KillListener.java +++ b/src/main/java/me/bloodyhan/bridgeleveling/listener/KillListener.java @@ -1,12 +1,14 @@ package me.bloodyhan.bridgeleveling.listener; +import com.google.common.collect.Maps; +import lombok.AllArgsConstructor; +import lombok.Data; import me.bloodyhan.bridgeleveling.Main; import me.bloodyhan.bridgeleveling.api.PlayerData; import me.bloodyhan.bridgeleveling.api.PlayerKillEvent; import me.bloodyhan.bridgeleveling.config.MainConfig; import me.bloodyhan.bridgeleveling.config.MessageConfig; import me.bloodyhan.bridgeleveling.config.SoundConfig; -import me.bloodyhan.bridgeleveling.task.TargetResetTask; import me.bloodyhan.bridgeleveling.util.Method; import me.clip.placeholderapi.PlaceholderAPI; import org.bukkit.Bukkit; @@ -20,55 +22,53 @@ import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.PlayerMoveEvent; +import java.util.Map; +import java.util.UUID; + /** * @author Bloody_Han * @date 2019/02/20 */ public class KillListener implements Listener { - public KillListener(){ - Bukkit.getPluginManager().registerEvents(this, Main.getInstance()); - } + private Map> targetMap = Maps.newHashMap(); @EventHandler - public void onHit(EntityDamageByEntityEvent e){ - if(!(e.getEntity() instanceof Player) && PlayerData.getData(e.getEntity().getUniqueId()) == null){ + public void onHit(EntityDamageByEntityEvent e) { + if (e.isCancelled() || !(e.getEntity() instanceof Player)) { return; } Player p = (Player) e.getEntity(); - if (e.getDamager() instanceof Player && !e.isCancelled() && e.getDamager() != e.getEntity()) { - PlayerData data = PlayerData.getData(p.getUniqueId()); - Player damager = (Player) e.getDamager(); - data.setLastDamager(damager); - if(data.getTask() != null){ - data.getTask().cancel(); - } - data.setTask(new TargetResetTask(p)); - } - else if (e.getDamager() instanceof Projectile && !e.isCancelled() && ((Projectile) e.getDamager()).getShooter() != e.getEntity()) { - PlayerData data = PlayerData.getData(p.getUniqueId()); - Player shooter = (Player) ((Projectile) e.getDamager()).getShooter(); - data.setLastDamager(shooter); - if(data.getTask() != null){ - data.getTask().cancel(); - } - data.setTask(new TargetResetTask(p)); + Player attacker = e.getDamager() instanceof Player + ? (Player) e.getDamager() + : e.getDamager() instanceof Projectile && ((Projectile) e.getDamager()).getShooter() != e.getEntity() + ? (Player) ((Projectile) e.getDamager()).getShooter() + : null; + if (attacker == null) { + return; } - else{ - e.setCancelled(true); + PlayerData data = PlayerData.getData(attacker.getUniqueId()); + if (data == null) { + return; } + targetMap.put(p.getUniqueId(), new Pair<>(data.getUniqueId(), System.currentTimeMillis() + 10000L)); + } + + public KillListener() { + Bukkit.getPluginManager().registerEvents(this, Main.getInstance()); } @EventHandler - public void onDeath(PlayerDeathEvent e){ - if(e.getEntity() == null){ + public void onDeath(PlayerDeathEvent e) { + if (e.getEntity() == null) { return; } Player p = e.getEntity(); PlayerData data = PlayerData.getData(p.getUniqueId()); data.setKillStreak(0); - if (data.getLastDamager() != null) { - this.killPlayer(p, data.getLastDamager()); + Pair damageData = targetMap.getOrDefault(data.getUniqueId(), new Pair<>(null, -1L)); + if (damageData.first != null && System.currentTimeMillis() < damageData.second) { + this.killPlayer(p, Bukkit.getPlayer(damageData.first)); } } @@ -78,8 +78,9 @@ public void onMove(PlayerMoveEvent e) { if (e.getTo().getY() < 0.1) { PlayerData data = PlayerData.getData(p.getUniqueId()); data.setKillStreak(0); - if (data.getLastDamager() != null) { - this.killPlayer(p, data.getLastDamager()); + Pair damageData = targetMap.getOrDefault(p.getUniqueId(), new Pair<>(null, -1L)); + if (damageData.first != null && System.currentTimeMillis() < damageData.second) { + this.killPlayer(p, Bukkit.getPlayer(damageData.first)); } } } @@ -144,7 +145,7 @@ public void killPlayer(Player victim, Player damager){ } data.checkRankUp(); Bukkit.getPluginManager().callEvent(new PlayerKillEvent(victim, damager)); - PlayerData.getData(victim.getUniqueId()).setLastDamager(null); + this.targetMap.remove(victim.getUniqueId()); for (String cmd : MainConfig.TRIGGER_DEATH_COMMAND) { Bukkit.dispatchCommand(Bukkit.getConsoleSender(), PlaceholderAPI.setPlaceholders(victim, cmd .replace("{damager}", damager.getName()) @@ -152,11 +153,20 @@ public void killPlayer(Player victim, Player damager){ } } + @Data + @AllArgsConstructor + class Pair { + + private A first; + private B second; + + } + private int killAddXp(Player p) { PlayerData data = PlayerData.getData(p.getUniqueId()); - int killXp = ( MainConfig.XP_GIVE_KILL_STREAK_BONUS - 1 ) * MainConfig.XP_GIVE_KILL_STREAK_BONUS + MainConfig.XP_GIVE_KILL; - if(MainConfig.XP_GIVE_KILL_STREAK_BONUS >= data.getKillStreak()) { - killXp = ( data.getKillStreak() - 1 ) * MainConfig.XP_GIVE_KILL_STREAK_BONUS + MainConfig.XP_GIVE_KILL; + int killXp = (MainConfig.XP_GIVE_KILL_STREAK_BONUS - 1) * MainConfig.XP_GIVE_KILL_STREAK_BONUS + MainConfig.XP_GIVE_KILL; + if (MainConfig.XP_GIVE_KILL_STREAK_BONUS >= data.getKillStreak()) { + killXp = (data.getKillStreak() - 1) * MainConfig.XP_GIVE_KILL_STREAK_BONUS + MainConfig.XP_GIVE_KILL; } return (int) (killXp * data.getBoost()); } diff --git a/src/main/java/me/bloodyhan/bridgeleveling/listener/LevelListener.java b/src/main/java/me/bloodyhan/bridgeleveling/listener/LevelListener.java index d8736f7..9a2c8ed 100644 --- a/src/main/java/me/bloodyhan/bridgeleveling/listener/LevelListener.java +++ b/src/main/java/me/bloodyhan/bridgeleveling/listener/LevelListener.java @@ -1,23 +1,14 @@ package me.bloodyhan.bridgeleveling.listener; -import com.google.common.collect.Lists; import me.bloodyhan.bridgeleveling.Main; import me.bloodyhan.bridgeleveling.api.PlayerData; -import me.bloodyhan.bridgeleveling.api.PlayerLevelUpEvent; -import me.bloodyhan.bridgeleveling.api.PlayerRankUpEvent; -import me.bloodyhan.bridgeleveling.config.MainConfig; -import me.bloodyhan.bridgeleveling.config.MessageConfig; -import me.bloodyhan.bridgeleveling.config.SoundConfig; import org.bukkit.Bukkit; -import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; -import java.util.List; - /** * @author Bloody_Han */ diff --git a/src/main/java/me/bloodyhan/bridgeleveling/task/TargetResetTask.java b/src/main/java/me/bloodyhan/bridgeleveling/task/TargetResetTask.java deleted file mode 100644 index eadc142..0000000 --- a/src/main/java/me/bloodyhan/bridgeleveling/task/TargetResetTask.java +++ /dev/null @@ -1,36 +0,0 @@ -package me.bloodyhan.bridgeleveling.task; - -import me.bloodyhan.bridgeleveling.Main; -import me.bloodyhan.bridgeleveling.api.PlayerData; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitTask; - -/** - * @author Bloody_Han - */ -public class TargetResetTask implements BridgeTask{ - - private Player p; - private BukkitTask task; - - public TargetResetTask(Player p){ - this.p = p; - this.task = Bukkit.getScheduler().runTaskTimerAsynchronously(Main.getInstance(), () -> { - PlayerData data = PlayerData.getData(p.getUniqueId()); - if(data.getLastDamager() != null) { - data.setLastDamager(null); - } - cancel(); - },10 * 20L, 10 * 20L); - } - - @Override - public void cancel(){ - if(this.task != null) { - this.task.cancel(); - this.task = null; - } - } - -} diff --git a/src/main/java/me/bloodyhan/bridgeleveling/util/Method.java b/src/main/java/me/bloodyhan/bridgeleveling/util/Method.java index 5a0f23f..be81688 100644 --- a/src/main/java/me/bloodyhan/bridgeleveling/util/Method.java +++ b/src/main/java/me/bloodyhan/bridgeleveling/util/Method.java @@ -2,7 +2,6 @@ import net.md_5.bungee.api.ChatColor; -import java.math.BigDecimal; import java.math.RoundingMode; import java.text.DecimalFormat; diff --git a/src/main/java/me/bloodyhan/bridgeleveling/util/PlaceholderHook.java b/src/main/java/me/bloodyhan/bridgeleveling/util/PlaceholderHook.java index ee12871..611b6be 100644 --- a/src/main/java/me/bloodyhan/bridgeleveling/util/PlaceholderHook.java +++ b/src/main/java/me/bloodyhan/bridgeleveling/util/PlaceholderHook.java @@ -5,7 +5,6 @@ import me.bloodyhan.bridgeleveling.config.MainConfig; import me.clip.placeholderapi.expansion.PlaceholderExpansion; import org.bukkit.OfflinePlayer; -import org.bukkit.entity.Player; public class PlaceholderHook extends PlaceholderExpansion { diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 03adf44..2201e12 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: BridgeLeveling -version: '${version}' +version: '$version' main: me.bloodyhan.bridgeleveling.Main softdepend: [ PlaceholderAPI ] -authors: [ Bloody_Han ] +authors: [ Bongle ] description: Leveling for your bridge server