Several fixes, add licence to pom.xml, clean up code...

Fixes #2
This commit is contained in:
TheTechRobo 2022-11-04 11:26:32 -04:00
parent df9da1a0cd
commit 2824bd67e0
6 changed files with 113 additions and 33 deletions

View File

@ -24,7 +24,7 @@
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>

View File

@ -1,2 +1,8 @@
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=17

47
pom.xml
View File

@ -12,6 +12,20 @@
<url>https://repo.purpurmc.org/snapshots</url> <url>https://repo.purpurmc.org/snapshots</url>
</repository> </repository>
</repositories> </repositories>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>
<developers>
<developer>
<name>TheTechRobo</name>
<email>thetechrobo@protonmail.ch</email>
<organization>what! the tech</organization>
<organizationUrl>https://thetechrobo.ca</organizationUrl>
</developer>
</developers>
<dependencies> <dependencies>
<!--This adds the Purpur API artifact to the build --> <!--This adds the Purpur API artifact to the build -->
<dependency> <dependency>
@ -21,4 +35,37 @@
</dependency> </dependency>
</dependencies> </dependencies>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>17</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<id>attach-source</id>
<phase>compile</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project> </project>

View File

@ -2,6 +2,7 @@ package ca.thetechrobo.fbl;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.TextColor; import net.kyori.adventure.text.format.TextColor;
@ -10,31 +11,30 @@ public class CountdownTimer extends BukkitRunnable {
private int elapsedSeconds; private int elapsedSeconds;
private int seconds; private int seconds;
private Player player; private Player player;
//private JavaPlugin pl; private PlayerTookDamage runner;
public CountdownTimer(int seconds, Player p) { public CountdownTimer(int seconds, Player p, PlayerTookDamage runner) {
//this.man = Bukkit.getScoreboardManager();
//this.pl = pl;
this.elapsedSeconds = 0; this.elapsedSeconds = 0;
this.player = p; this.player = p;
this.seconds = seconds; this.seconds = seconds;
this.runner = runner;
} }
public Player getPlayer() {
return this.player;
}
@Override @Override
public void run() { public void run() {
if (this.elapsedSeconds <= this.seconds ) { if (this.elapsedSeconds <= this.seconds) {
/*Scoreboard board = this.man.getNewScoreboard(); TextComponent comp = Component
Objective objective = board.registerNewObjective( .text("Battle Log Protection: " + (this.seconds - this.elapsedSeconds + "s remaining"))
"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)); .color(TextColor.color(155, 105, 165));
this.player.sendActionBar(comp); this.player.sendActionBar(comp);
this.elapsedSeconds++; this.elapsedSeconds++;
} } else {
else {
this.player.sendActionBar(Component.text("")); this.player.sendActionBar(Component.text(""));
this.runner.removeMe(this);
this.cancel(); this.cancel();
} }
} }

View File

@ -1,6 +1,7 @@
package ca.thetechrobo.fbl; package ca.thetechrobo.fbl;
import java.time.Instant; import java.time.Instant;
import java.util.HashMap;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -16,24 +17,31 @@ import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType; import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextColor;
public class PlayerTookDamage implements Listener { public class PlayerTookDamage implements Listener {
private JavaPlugin pl; private JavaPlugin pl;
private HashMap<Player, CountdownTimer> map;
public PlayerTookDamage(JavaPlugin pl) { public PlayerTookDamage(JavaPlugin pl) {
this.pl = pl; this.pl = pl;
this.map = new HashMap<Player, CountdownTimer>();
} }
private long load_internal_long(Player p, NamespacedKey key, long def) { private long load_internal_long(Player p, NamespacedKey key, long def) {
PersistentDataContainer c = p.getPersistentDataContainer(); PersistentDataContainer c = p.getPersistentDataContainer();
if (c.has(key, PersistentDataType.LONG)) { if (c.has(key, PersistentDataType.LONG)) {
long i = c.get(key, PersistentDataType.LONG); long i = c.get(key, PersistentDataType.LONG);
return i; return i;
} }
return def; return def;
} }
private String load_internal_str(Player p, NamespacedKey key) { private String load_internal_str(Player p, NamespacedKey key) {
PersistentDataContainer c = p.getPersistentDataContainer(); PersistentDataContainer c = p.getPersistentDataContainer();
if (c.has(key, PersistentDataType.STRING)) { if (c.has(key, PersistentDataType.STRING)) {
String i = c.get(key, PersistentDataType.STRING); String i = c.get(key, PersistentDataType.STRING);
return i; return i;
} }
@ -42,11 +50,19 @@ public class PlayerTookDamage implements Listener {
@EventHandler @EventHandler
public void playerTookDamage(EntityDamageByEntityEvent e) { public void playerTookDamage(EntityDamageByEntityEvent e) {
if (!(e.getEntity().getType() == EntityType.PLAYER)) return; if (!(e.getEntity().getType() == EntityType.PLAYER))
return;
Entity damager = e.getDamager(); Entity damager = e.getDamager();
if (!(damager.getType() == EntityType.PLAYER)) return; if (!(damager.getType() == EntityType.PLAYER))
return;
Player p2 = (Player) damager; Player p2 = (Player) damager;
Player p = (Player) e.getEntity(); Player p = (Player) e.getEntity();
if (this.map.containsKey(p)) {
this.map.get(p).cancel();
}
if (this.map.containsKey(p2)) {
this.map.get(p2).cancel();
}
long unixTimestamp = Instant.now().getEpochSecond(); long unixTimestamp = Instant.now().getEpochSecond();
NamespacedKey key = new NamespacedKey(this.pl, "AntiBL_LastHit"); NamespacedKey key = new NamespacedKey(this.pl, "AntiBL_LastHit");
NamespacedKey key2 = new NamespacedKey(this.pl, "AntiBL_HitOn"); NamespacedKey key2 = new NamespacedKey(this.pl, "AntiBL_HitOn");
@ -54,11 +70,16 @@ public class PlayerTookDamage implements Listener {
p2.getPersistentDataContainer().set(key, PersistentDataType.LONG, unixTimestamp); p2.getPersistentDataContainer().set(key, PersistentDataType.LONG, unixTimestamp);
p.getPersistentDataContainer().set(key2, PersistentDataType.STRING, p2.getUniqueId().toString()); p.getPersistentDataContainer().set(key2, PersistentDataType.STRING, p2.getUniqueId().toString());
p2.getPersistentDataContainer().set(key2, PersistentDataType.STRING, p.getUniqueId().toString()); p2.getPersistentDataContainer().set(key2, PersistentDataType.STRING, p.getUniqueId().toString());
new CountdownTimer(11, p).runTaskTimer(this.pl, 0, 20); CountdownTimer timerP = new CountdownTimer(11, p, this);
new CountdownTimer(11, p2).runTaskTimer(this.pl, 0, 20); CountdownTimer timerP2 = new CountdownTimer(11, p2, this);
new NoMoreSayingYouBattleLogged(p, this.pl).runTaskLater(pl, 11*20); timerP.runTaskTimer(this.pl, 0, 20);
new NoMoreSayingYouBattleLogged(p2, this.pl).runTaskLater(pl, 11*20); timerP2.runTaskTimer(this.pl, 0, 20);
this.map.put(p, timerP);
this.map.put(p2, timerP2);
new WriteLastHit(p, this.pl).runTaskLater(pl, 11 * 20);
new WriteLastHit(p2, this.pl).runTaskLater(pl, 11 * 20);
} }
@EventHandler @EventHandler
public void playerLeftGame(PlayerQuitEvent e) { public void playerLeftGame(PlayerQuitEvent e) {
Player p = e.getPlayer(); Player p = e.getPlayer();
@ -67,21 +88,26 @@ public class PlayerTookDamage implements Listener {
long unixTimestamp = Instant.now().getEpochSecond(); long unixTimestamp = Instant.now().getEpochSecond();
long difference = unixTimestamp - lastOldHit; long difference = unixTimestamp - lastOldHit;
if (difference < 11) { if (difference < 11) {
Component pDisplayName = p.displayName(); Component pDisplayName = p.displayName().color(TextColor.color(100, 100, 255));
String uu = load_internal_str(p, new NamespacedKey(this.pl, "AntiBL_HitOn")); String uu = load_internal_str(p, new NamespacedKey(this.pl, "AntiBL_HitOn"));
String p2d = "someone"; Component p2d = Component.text("someone");
if (uu == null) { if (uu == null) {
} } else {
else {
UUID p2u = UUID.fromString(uu); UUID p2u = UUID.fromString(uu);
OfflinePlayer p2 = Bukkit.getOfflinePlayer(p2u); OfflinePlayer p2 = Bukkit.getOfflinePlayer(p2u);
p2d = p2.getName(); p2d = Component.text(p2.getName()).color(TextColor.color(200, 100, 150));
} }
Component message = pDisplayName.append(Component.text(" quit during battle with " + p2d)) Component message = pDisplayName.append(Component.text(" quit during battle with ").append(p2d))
.append(Component.text(".")); .append(Component.text("."));
Bukkit.broadcast(message); Bukkit.broadcast(message);
p.damage(unixTimestamp); // THAT'S A LOTTA DAMAGE! p.damage(unixTimestamp); // THAT'S A LOTTA DAMAGE!
p.kick(Component.text("You logged out during PvP and died!")); p.kick(Component.text("You logged out during PvP and died!"));
} }
this.map.remove(p);
}
public void removeMe(CountdownTimer timer) {
Player p = timer.getPlayer();
this.map.remove(p, timer);
} }
} }

View File

@ -6,14 +6,15 @@ import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
public class NoMoreSayingYouBattleLogged extends BukkitRunnable { public class WriteLastHit extends BukkitRunnable {
private Player p; private Player p;
private JavaPlugin pl; private JavaPlugin pl;
public NoMoreSayingYouBattleLogged(Player p, JavaPlugin pl) { public WriteLastHit(Player p, JavaPlugin pl) {
this.p = p; this.p = p;
this.pl = pl; this.pl = pl;
} }
@Override @Override
public void run() { public void run() {
NamespacedKey key = new NamespacedKey(this.pl, "AntiBL_LastHit"); NamespacedKey key = new NamespacedKey(this.pl, "AntiBL_LastHit");