commit 687c4ed0c7ff8e81b103f901136beb89147576cb Author: TheTechRobo <52163910+TheTechRobo@users.noreply.github.com> Date: Fri Aug 26 22:41:46 2022 -0400 Init diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..a3508c6 --- /dev/null +++ b/.classpath @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d411aca --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.class +/target +*.[wj]ar diff --git a/.project b/.project new file mode 100644 index 0000000..4fe74aa --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + antibattlelogging + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..4ede96d --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/plugin.yml b/plugin.yml new file mode 100644 index 0000000..cebfada --- /dev/null +++ b/plugin.yml @@ -0,0 +1,4 @@ +name: FBl +main: ca.thetechrobo.fbl.AntiBattlelogPlugin +version: 1.0 +api-version: 1.19 \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..2735222 --- /dev/null +++ b/pom.xml @@ -0,0 +1,24 @@ + + 4.0.0 + ca.thetechrobo.antibattlelog + antibattlelogging + 0.0.1-SNAPSHOT + FBl + because battle-logging is trash + + + + purpur-repo + https://repo.purpurmc.org/snapshots + + + + + + org.purpurmc.purpur + purpur-api + 1.19-R0.1-SNAPSHOT + + + + \ No newline at end of file diff --git a/src/main/java/ca/thetechrobo/fbl/AntiBattlelogPlugin.java b/src/main/java/ca/thetechrobo/fbl/AntiBattlelogPlugin.java new file mode 100644 index 0000000..c07f93d --- /dev/null +++ b/src/main/java/ca/thetechrobo/fbl/AntiBattlelogPlugin.java @@ -0,0 +1,14 @@ +package ca.thetechrobo.fbl; + +import org.bukkit.plugin.java.JavaPlugin; + +public class AntiBattlelogPlugin extends JavaPlugin { + @Override + public void onEnable() { + PlayerTookDamage eventHandler = new PlayerTookDamage(this); + getServer().getPluginManager().registerEvents(eventHandler, this); + } + @Override + public void onDisable() { + } +} diff --git a/src/main/java/ca/thetechrobo/fbl/CountdownTimer.java b/src/main/java/ca/thetechrobo/fbl/CountdownTimer.java new file mode 100644 index 0000000..ae20345 --- /dev/null +++ b/src/main/java/ca/thetechrobo/fbl/CountdownTimer.java @@ -0,0 +1,41 @@ +package ca.thetechrobo.fbl; + +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; +import net.kyori.adventure.text.format.TextColor; + +public class CountdownTimer extends BukkitRunnable { + private int elapsedSeconds; + private int seconds; + private Player player; + //private JavaPlugin pl; + + public CountdownTimer(int seconds, Player p) { + //this.man = Bukkit.getScoreboardManager(); + //this.pl = pl; + this.elapsedSeconds = 0; + this.player = p; + this.seconds = seconds; + } + @Override + public void run() { + if (this.elapsedSeconds <= this.seconds ) { + /*Scoreboard board = this.man.getNewScoreboard(); + Objective objective = board.registerNewObjective( + "antibattlelog", "dummy", + Component.text("Anti-Combat-Log Protection")); + objective.setDisplaySlot(DisplaySlot.); + Score score = objective.getScore(player);*/ + TextComponent comp = Component.text("Battle Log Protection - " + (this.seconds - this.elapsedSeconds + "s remaining")) + .color(TextColor.color(155, 105, 165)); + this.player.sendActionBar(comp); + this.elapsedSeconds++; + } + else { + this.player.sendActionBar(Component.text("")); + this.cancel(); + } + } +} diff --git a/src/main/java/ca/thetechrobo/fbl/NoMoreSayingYouBattleLogged.java b/src/main/java/ca/thetechrobo/fbl/NoMoreSayingYouBattleLogged.java new file mode 100644 index 0000000..eea786a --- /dev/null +++ b/src/main/java/ca/thetechrobo/fbl/NoMoreSayingYouBattleLogged.java @@ -0,0 +1,22 @@ +package ca.thetechrobo.fbl; + +import org.bukkit.NamespacedKey; +import org.bukkit.entity.Player; +import org.bukkit.persistence.PersistentDataType; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitRunnable; + +public class NoMoreSayingYouBattleLogged extends BukkitRunnable { + private Player p; + private JavaPlugin pl; + + public NoMoreSayingYouBattleLogged(Player p, JavaPlugin pl) { + this.p = p; + this.pl = pl; + } + @Override + public void run() { + NamespacedKey key = new NamespacedKey(this.pl, "AntiBL_LastHit"); + p.getPersistentDataContainer().set(key, PersistentDataType.LONG, (long) 0); + } +} diff --git a/src/main/java/ca/thetechrobo/fbl/PlayerTookDamage.java b/src/main/java/ca/thetechrobo/fbl/PlayerTookDamage.java new file mode 100644 index 0000000..3332943 --- /dev/null +++ b/src/main/java/ca/thetechrobo/fbl/PlayerTookDamage.java @@ -0,0 +1,87 @@ +package ca.thetechrobo.fbl; + +import java.time.Instant; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.NamespacedKey; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.persistence.PersistentDataContainer; +import org.bukkit.persistence.PersistentDataType; +import org.bukkit.plugin.java.JavaPlugin; +import net.kyori.adventure.text.Component; + +public class PlayerTookDamage implements Listener { + private JavaPlugin pl; + public PlayerTookDamage(JavaPlugin pl) { + this.pl = pl; + } + private long load_internal_long(Player p, NamespacedKey key, long def) { + PersistentDataContainer c = p.getPersistentDataContainer(); + if (c.has(key, PersistentDataType.LONG)) { + long i = c.get(key, PersistentDataType.LONG); + return i; + } + return def; + } + private String load_internal_str(Player p, NamespacedKey key) { + PersistentDataContainer c = p.getPersistentDataContainer(); + if (c.has(key, PersistentDataType.STRING)) { + String i = c.get(key, PersistentDataType.STRING); + return i; + } + return null; + } + + @EventHandler + public void playerTookDamage(EntityDamageByEntityEvent e) { + if (!(e.getEntity().getType() == EntityType.PLAYER)) return; + Entity damager = e.getDamager(); + if (!(damager.getType() == EntityType.PLAYER)) return; + Player p2 = (Player) damager; + Player p = (Player) e.getEntity(); + long unixTimestamp = Instant.now().getEpochSecond(); + NamespacedKey key = new NamespacedKey(this.pl, "AntiBL_LastHit"); + NamespacedKey key2 = new NamespacedKey(this.pl, "AntiBL_HitOn"); + p.getPersistentDataContainer().set(key, PersistentDataType.LONG, unixTimestamp); + p2.getPersistentDataContainer().set(key, PersistentDataType.LONG, unixTimestamp); + p.getPersistentDataContainer().set(key2, PersistentDataType.STRING, p2.getUniqueId().toString()); + p2.getPersistentDataContainer().set(key2, PersistentDataType.STRING, p.getUniqueId().toString()); + new CountdownTimer(11, p).runTaskTimer(this.pl, 0, 20); + new CountdownTimer(11, p2).runTaskTimer(this.pl, 0, 20); + new NoMoreSayingYouBattleLogged(p, this.pl).runTaskLater(pl, 11*20); + new NoMoreSayingYouBattleLogged(p2, this.pl).runTaskLater(pl, 11*20); + } + @EventHandler + public void playerLeftGame(PlayerQuitEvent e) { + Player p = e.getPlayer(); + NamespacedKey key = new NamespacedKey(this.pl, "AntiBL_LastHit"); + long lastOldHit = load_internal_long(p, key, 0); + long unixTimestamp = Instant.now().getEpochSecond(); + long difference = unixTimestamp - lastOldHit; + if (difference < 11) { + Component pDisplayName = p.displayName(); + String uu = load_internal_str(p, new NamespacedKey(this.pl, "AntiBL_HitOn")); + String p2d = "someone"; + if (uu == null) { + } + else { + UUID p2u = UUID.fromString(uu); + OfflinePlayer p2 = Bukkit.getOfflinePlayer(p2u); + p2d = p2.getName(); + } + Component message = pDisplayName.append(Component.text(" quit during battle with " + p2d)) + .append(Component.text(".")); + Bukkit.broadcast(message); + p.damage(unixTimestamp); // THAT'S A LOTTA DAMAGE! + p.kick(Component.text("You logged out during PvP and died!")); + } + } +}