diff --git a/pom.xml b/pom.xml index fa6f9bf..21c920f 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.alttd AltitudeTag - 1.0.2 + 1.0.3 UTF-8 diff --git a/src/main/java/com/alttd/altitudetag/AltitudeTag.java b/src/main/java/com/alttd/altitudetag/AltitudeTag.java index 4e4dbb7..d18a1e7 100644 --- a/src/main/java/com/alttd/altitudetag/AltitudeTag.java +++ b/src/main/java/com/alttd/altitudetag/AltitudeTag.java @@ -21,6 +21,7 @@ public class AltitudeTag extends JavaPlugin private static AltitudeTag instance; private UUID tagger; + private UUID prevTagger; private BossBar bossBar; @@ -124,10 +125,21 @@ public class AltitudeTag extends JavaPlugin Bukkit.getPlayer(tagger).getName(), cause); } - + + instance.prevTagger = instance.tagger; instance.tagger = tagger; } + /** + * Returns the previous tagger. + * + * @return the previous tagger. + */ + public static UUID getPreviousTagger() + { + return instance.prevTagger; + } + /** * Adds a tag for the given player. * diff --git a/src/main/java/com/alttd/altitudetag/Leaderboard.java b/src/main/java/com/alttd/altitudetag/Leaderboard.java index 460fd79..00f2eea 100644 --- a/src/main/java/com/alttd/altitudetag/Leaderboard.java +++ b/src/main/java/com/alttd/altitudetag/Leaderboard.java @@ -164,7 +164,7 @@ public class Leaderboard { return; } - + Objects.requireNonNull(hologram); Bukkit.getScheduler().runTaskAsynchronously(AltitudeTag.getInstance(), () -> diff --git a/src/main/java/com/alttd/altitudetag/configuration/Config.java b/src/main/java/com/alttd/altitudetag/configuration/Config.java index 9f7c5d9..f4cd3d2 100644 --- a/src/main/java/com/alttd/altitudetag/configuration/Config.java +++ b/src/main/java/com/alttd/altitudetag/configuration/Config.java @@ -86,6 +86,12 @@ public final class Config 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 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_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'!"); /** * Update the values from the config file. diff --git a/src/main/java/com/alttd/altitudetag/listeners/InteractListener.java b/src/main/java/com/alttd/altitudetag/listeners/InteractListener.java index a4cf5f8..2cf7f5f 100644 --- a/src/main/java/com/alttd/altitudetag/listeners/InteractListener.java +++ b/src/main/java/com/alttd/altitudetag/listeners/InteractListener.java @@ -3,6 +3,8 @@ package com.alttd.altitudetag.listeners; import com.alttd.altitudetag.AltitudeTag; import com.alttd.altitudetag.NotificationHandler; import com.alttd.altitudetag.TagCause; +import com.alttd.altitudetag.configuration.Config; +import com.alttd.altitudetag.configuration.Lang; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -10,6 +12,8 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent; public class InteractListener implements Listener { + private static long lastTagTime = -1; + @EventHandler public void onHit(EntityDamageByEntityEvent event) { @@ -26,17 +30,32 @@ public class InteractListener implements Listener final Player tagged = (Player) event.getEntity(); - // add the new tag - AltitudeTag.addTag(tagger.getUniqueId(), () -> - { - // if they left, we can stop - if (!tagger.isOnline()) - { - return; - } - NotificationHandler.sendTaggerNotifications(tagger, tagged.getName()); - }); + // check for time since last tag + if (lastTagTime != -1 && Config.TAG_DELAY_ENABLED.getValue() && (System.currentTimeMillis() - lastTagTime) / 50 < Config.TAG_DELAY_DURATION.getValue()) + { + tagger.sendMessage(Lang.renderString(Config.TAG_DELAY_MESSAGE.getValue())); + return; + } + + // add the new tag + if (!Config.TAG_BACKS_TRACK_LEADERBOARD.getValue() && AltitudeTag.getPreviousTagger().equals(tagged.getUniqueId())) + { + tagger.sendMessage(Lang.renderString(Config.TAG_BACKS_MESSAGE.getValue())); + } + else + { + AltitudeTag.addTag(tagger.getUniqueId(), () -> + { + // if they left, we can stop + if (!tagger.isOnline()) + { + return; + } + + NotificationHandler.sendTaggerNotifications(tagger, tagged.getName()); + }); + } AltitudeTag.setTagger(tagged.getUniqueId(), TagCause.NORMAL); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 95afcb4..d8a96de 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -50,4 +50,11 @@ notification: color: YELLOW # 0-100 percent: 0 - message: "&e{player} is 'it'! Don't let them tag you!" \ No newline at end of file + message: "&e{player} is 'it'! Don't let them tag you!" +tag-backs: + track-leaderboard: false + message: "&e* Have fun, but tag-backs aren't regarded toward the leaderboard." +tag-delay: + enabled: true + duration: 60 + message: "&e* Can't tag anyone within 5 seconds of becoming 'it'!" \ No newline at end of file