diff --git a/pom.xml b/pom.xml index 280b96d..51aad2e 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.alttd AltitudeTag - 1.0.5 + 1.0.6 UTF-8 @@ -48,6 +48,11 @@ holographicdisplays-api 2.3.2 + + org.jetbrains + annotations + 16.0.2 + diff --git a/src/main/java/com/alttd/altitudetag/AltitudeTag.java b/src/main/java/com/alttd/altitudetag/AltitudeTag.java index 840b8a7..6a6c6f7 100644 --- a/src/main/java/com/alttd/altitudetag/AltitudeTag.java +++ b/src/main/java/com/alttd/altitudetag/AltitudeTag.java @@ -17,6 +17,8 @@ import org.bukkit.boss.BossBar; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitTask; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class AltitudeTag extends JavaPlugin { @@ -146,6 +148,7 @@ public class AltitudeTag extends JavaPlugin * * @return the previous tagger. */ + @Nullable public static UUID getPreviousTagger() { return instance.prevTagger; @@ -156,7 +159,7 @@ public class AltitudeTag extends JavaPlugin * * @param uuid the player to add a tag for. */ - public static void addTag(UUID uuid, Runnable runnable) + public static void addTag(@NotNull UUID uuid, @NotNull Runnable runnable) { Leaderboard.addTag(uuid, runnable); } @@ -166,12 +169,13 @@ public class AltitudeTag extends JavaPlugin Leaderboard.getTags(uuid, consumer); } - public static Player randomTagger(TagCause cause, Player filtered) + public static Player randomTagger(@NotNull TagCause cause, @NotNull Player filtered) { Optional optional = Bukkit.getOnlinePlayers().stream().filter(p -> p != filtered).findAny(); if (!optional.isPresent()) { - throw new IllegalStateException("Filtering failed. All players: " + filtered.getUniqueId()); + AltitudeTag.setTagger(null, cause); + return null; } Player player = optional.get(); AltitudeTag.setTagger(player.getUniqueId(), cause); diff --git a/src/main/java/com/alttd/altitudetag/configuration/Config.java b/src/main/java/com/alttd/altitudetag/configuration/Config.java index 7e68e42..e79f37f 100644 --- a/src/main/java/com/alttd/altitudetag/configuration/Config.java +++ b/src/main/java/com/alttd/altitudetag/configuration/Config.java @@ -51,8 +51,9 @@ public final class Config public static final MutableValue LEADERBOARD_ENABLED = new MutableValue<>(true); public static final MutableValue LEADERBOARD_TITLE = new MutableValue<>("&b&lAltitude Tag Leaderboard"); - public static final MutableValue LEADERBOARD_FORMAT = new MutableValue<>("&6{rank}. &e{player} &7- &e{tags}"); public static final MutableValue LEADERBOARD_TOP = new MutableValue<>(10); + public static final MutableValue LEADERBOARD_FORMAT = new MutableValue<>( + "&6{rank}. &e{player} &7- &e{tags}"); public static final MutableValue LEADERBOARD_LOCATION_WORLD = new MutableValue<>("world"); public static final MutableValue LEADERBOARD_LOCATION_X = new MutableValue<>(10.0); @@ -66,32 +67,39 @@ public final class Config public static final MutableValue NOTIFICATION_VICTIM_TITLE_FADE_OUT = new MutableValue<>(0); public static final MutableValue NOTIFICATION_VICTIM_TITLE_SUB_TITLE_ENABLED = new MutableValue<>(true); - public static final MutableValue NOTIFICATION_VICTIM_TITLE_SUB_TITLE_MESSAGE = new MutableValue<>("&eYou're it!"); + public static final MutableValue NOTIFICATION_VICTIM_TITLE_SUB_TITLE_MESSAGE = new MutableValue<>( + "&eYou're it!"); public static final MutableValue NOTIFICATION_VICTIM_TITLE_JOIN_DELAY_ENABLED = new MutableValue<>(true); public static final MutableValue NOTIFICATION_VICTIM_TITLE_JOIN_DELAY_LENGTH = new MutableValue<>(60); public static final MutableValue NOTIFICATION_ATTACKER_CHAT_ENABLED = new MutableValue<>(true); - public static final MutableValue NOTIFICATION_ATTACKER_CHAT_MESSAGE = new MutableValue<>("&7You just tagged &e{target}&7! You have &e{amount}&7 total tags."); + public static final MutableValue NOTIFICATION_ATTACKER_CHAT_MESSAGE = new MutableValue<>( + "&7You just tagged &e{target}&7! You have &e{amount}&7 total tags."); public static final MutableValue NOTIFICATION_GLOBAL_CHAT_AFTER_TAG_ENABLED = new MutableValue<>(true); - public static final MutableValue NOTIFICATION_GLOBAL_CHAT_AFTER_TAG_MESSAGE = new MutableValue<>("&e* {attacker} tagged {target}, run!"); + public static final MutableValue NOTIFICATION_GLOBAL_CHAT_AFTER_TAG_MESSAGE = new MutableValue<>( + "&e* {attacker} tagged {target}, run!"); public static final MutableValue NOTIFICATION_GLOBAL_CHAT_OTHER_REASON_ENABLED = new MutableValue<>(true); - public static final MutableValue NOTIFICATION_GLOBAL_CHAT_OTHER_REASON_MESSAGE = new MutableValue<>("&e*{target} is it now, run!"); + public static final MutableValue NOTIFICATION_GLOBAL_CHAT_OTHER_REASON_MESSAGE = new MutableValue<>( + "&e*{target} is it now, run!"); public static final MutableValue NOTIFICATION_GLOBAL_BOSS_BAR_ENABLED = new MutableValue<>(true); public static final MutableValue NOTIFICATION_GLOBAL_BOSS_BAR_SEGMENTS = new MutableValue<>(0); public static final MutableValue NOTIFICATION_GLOBAL_BOSS_BAR_COLOR = new MutableValue<>("YELLOW"); public static final MutableValue NOTIFICATION_GLOBAL_BOSS_BAR_PERCENT = new MutableValue<>(0); - public static final MutableValue NOTIFICATION_GLOBAL_BOSS_BAR_MESSAGE = new MutableValue<>("&e{player} is 'it'! Don't let them tag you!"); + public static final MutableValue NOTIFICATION_GLOBAL_BOSS_BAR_MESSAGE = new MutableValue<>( + "&e{player} is 'it'! Don't let them tag you!"); public static final MutableValue TAG_BACKS_TRACK_LEADERBOARD = new MutableValue<>(false); - public static final MutableValue TAG_BACKS_MESSAGE = new MutableValue<>("&e* Have fun, but tag-backs aren't regarded toward the leaderboard."); + public static final MutableValue TAG_BACKS_MESSAGE = new MutableValue<>( + "&e* Have fun, but tag-backs aren't regarded toward the leaderboard."); public static final MutableValue TAG_DELAY_ENABLED = new MutableValue<>(true); public static final MutableValue TAG_DELAY_DURATION = new MutableValue<>(60); - public static final MutableValue TAG_DELAY_MESSAGE = new MutableValue<>("&e* Can't tag anyone within 5 seconds of becoming 'it'!"); + public static final MutableValue TAG_DELAY_MESSAGE = new MutableValue<>( + "&e* Can't tag anyone within 5 seconds of becoming 'it'!"); public static final MutableValue TIME_LIMIT_ENABLED = new MutableValue<>(true); public static final MutableValue TIME_LIMIT_DURATION = new MutableValue<>(1200); @@ -135,25 +143,33 @@ public final class Config updateValue(config, save, "notification.victim.title.duration", NOTIFICATION_VICTIM_TITLE_DURATION); updateValue(config, save, "notification.victim.title.fade-in", NOTIFICATION_VICTIM_TITLE_FADE_IN); updateValue(config, save, "notification.victim.title.fade-out", NOTIFICATION_VICTIM_TITLE_FADE_OUT); - updateValue(config, save, "notification.victim.title.sub-title.enabled", NOTIFICATION_VICTIM_TITLE_SUB_TITLE_ENABLED); - updateValue(config, save, "notification.victim.title.sub-title.message", NOTIFICATION_VICTIM_TITLE_SUB_TITLE_MESSAGE); - updateValue(config, save, "notification.victim.title.join-delay.enabled", NOTIFICATION_VICTIM_TITLE_JOIN_DELAY_ENABLED); - updateValue(config, save, "notification.victim.title.join-delay.length", NOTIFICATION_VICTIM_TITLE_JOIN_DELAY_LENGTH); + updateValue(config, save, "notification.victim.title.sub-title.enabled", + NOTIFICATION_VICTIM_TITLE_SUB_TITLE_ENABLED); + updateValue(config, save, "notification.victim.title.sub-title.message", + NOTIFICATION_VICTIM_TITLE_SUB_TITLE_MESSAGE); + updateValue(config, save, "notification.victim.title.join-delay.enabled", + NOTIFICATION_VICTIM_TITLE_JOIN_DELAY_ENABLED); + updateValue(config, save, "notification.victim.title.join-delay.length", + NOTIFICATION_VICTIM_TITLE_JOIN_DELAY_LENGTH); updateValue(config, save, "notification.attacker.chat.enabled", NOTIFICATION_ATTACKER_CHAT_ENABLED); updateValue(config, save, "notification.attacker.chat.message", NOTIFICATION_ATTACKER_CHAT_MESSAGE); - updateValue(config, save, "notification.global.chat.after-tag.enabled", NOTIFICATION_GLOBAL_CHAT_AFTER_TAG_ENABLED); - updateValue(config, save, "notification.global.chat.after-tag.message", NOTIFICATION_GLOBAL_CHAT_AFTER_TAG_MESSAGE); - updateValue(config, save, "notification.global.chat.other-reason.enabled", NOTIFICATION_GLOBAL_CHAT_OTHER_REASON_ENABLED); - updateValue(config, save, "notification.global.chat.other-reason.message", NOTIFICATION_GLOBAL_CHAT_OTHER_REASON_MESSAGE); + updateValue(config, save, "notification.global.chat.after-tag.enabled", + NOTIFICATION_GLOBAL_CHAT_AFTER_TAG_ENABLED); + updateValue(config, save, "notification.global.chat.after-tag.message", + NOTIFICATION_GLOBAL_CHAT_AFTER_TAG_MESSAGE); + updateValue(config, save, "notification.global.chat.other-reason.enabled", + NOTIFICATION_GLOBAL_CHAT_OTHER_REASON_ENABLED); + updateValue(config, save, "notification.global.chat.other-reason.message", + NOTIFICATION_GLOBAL_CHAT_OTHER_REASON_MESSAGE); updateValue(config, save, "notification.global.boss-bar.enabled", NOTIFICATION_GLOBAL_BOSS_BAR_ENABLED); updateValue(config, save, "notification.global.boss-bar.segments", NOTIFICATION_GLOBAL_BOSS_BAR_SEGMENTS); updateValue(config, save, "notification.global.boss-bar.color", NOTIFICATION_GLOBAL_BOSS_BAR_COLOR); updateValue(config, save, "notification.global.boss-bar.percent", NOTIFICATION_GLOBAL_BOSS_BAR_PERCENT); updateValue(config, save, "notification.global.boss-bar.message", NOTIFICATION_GLOBAL_BOSS_BAR_MESSAGE); - + updateValue(config, save, "tag-backs.track-leaderboard", TAG_BACKS_TRACK_LEADERBOARD); updateValue(config, save, "tag-backs.message", TAG_BACKS_MESSAGE); - + updateValue(config, save, "tag-delay.enabled", TAG_DELAY_ENABLED); updateValue(config, save, "tag-delay.duration", TAG_DELAY_DURATION); updateValue(config, save, "tag-delay.message", TAG_DELAY_MESSAGE); @@ -176,9 +192,11 @@ public final class Config * @param location the location in the config. * @param mutable the mutable value to update. */ - private static void updateValue(FileConfiguration config, MutableValue save, String location, MutableValue mutable) + private static void updateValue(FileConfiguration config, MutableValue save, String location, + MutableValue mutable) { - if (!config.isSet(location) || !successful(() -> mutable.setValue(loadValue(config, mutable.getType(), location)))) + if (!config.isSet(location) || + !successful(() -> mutable.setValue(loadValue(config, mutable.getType(), location)))) { error(location); config.set(location, mutable.getValue().toString()); @@ -218,7 +236,9 @@ public final class Config */ private static void error(String location) { - AltitudeTag.getInstance().getLogger().severe("Error loading the config value '" + location + "'. Reverted it to default."); + AltitudeTag.getInstance() + .getLogger() + .severe("Error loading the config value '" + location + "'. Reverted it to default."); } @SuppressWarnings("unchecked") diff --git a/src/main/java/com/alttd/altitudetag/listeners/InteractListener.java b/src/main/java/com/alttd/altitudetag/listeners/InteractListener.java index 5681b42..08c790f 100644 --- a/src/main/java/com/alttd/altitudetag/listeners/InteractListener.java +++ b/src/main/java/com/alttd/altitudetag/listeners/InteractListener.java @@ -39,7 +39,7 @@ public class InteractListener implements Listener } // add the new tag - if (!Config.TAG_BACKS_TRACK_LEADERBOARD.getValue() && AltitudeTag.getPreviousTagger().equals(tagged.getUniqueId())) + if (!Config.TAG_BACKS_TRACK_LEADERBOARD.getValue() && tagged.getUniqueId().equals(AltitudeTag.getPreviousTagger())) { tagger.sendMessage(Lang.renderString(Config.TAG_BACKS_MESSAGE.getValue())); }