parent
df9da1a0cd
commit
2824bd67e0
|
@ -24,7 +24,7 @@
|
|||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</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>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
|
|
|
@ -1,2 +1,8 @@
|
|||
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.reportPreviewFeatures=ignore
|
||||
org.eclipse.jdt.core.compiler.release=enabled
|
||||
org.eclipse.jdt.core.compiler.source=17
|
||||
|
|
47
pom.xml
47
pom.xml
|
@ -12,6 +12,20 @@
|
|||
<url>https://repo.purpurmc.org/snapshots</url>
|
||||
</repository>
|
||||
</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>
|
||||
<!--This adds the Purpur API artifact to the build -->
|
||||
<dependency>
|
||||
|
@ -21,4 +35,37 @@
|
|||
</dependency>
|
||||
|
||||
</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>
|
|
@ -2,6 +2,7 @@ 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;
|
||||
|
@ -10,31 +11,30 @@ public class CountdownTimer extends BukkitRunnable {
|
|||
private int elapsedSeconds;
|
||||
private int seconds;
|
||||
private Player player;
|
||||
//private JavaPlugin pl;
|
||||
private PlayerTookDamage runner;
|
||||
|
||||
public CountdownTimer(int seconds, Player p) {
|
||||
//this.man = Bukkit.getScoreboardManager();
|
||||
//this.pl = pl;
|
||||
public CountdownTimer(int seconds, Player p, PlayerTookDamage runner) {
|
||||
this.elapsedSeconds = 0;
|
||||
this.player = p;
|
||||
this.seconds = seconds;
|
||||
this.runner = runner;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
@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"))
|
||||
if (this.elapsedSeconds <= this.seconds) {
|
||||
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(comp);
|
||||
this.elapsedSeconds++;
|
||||
} else {
|
||||
this.player.sendActionBar(Component.text(""));
|
||||
this.runner.removeMe(this);
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package ca.thetechrobo.fbl;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
@ -16,24 +17,31 @@ 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;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
|
||||
public class PlayerTookDamage implements Listener {
|
||||
private JavaPlugin pl;
|
||||
private HashMap<Player, CountdownTimer> map;
|
||||
|
||||
public PlayerTookDamage(JavaPlugin pl) {
|
||||
this.pl = pl;
|
||||
this.map = new HashMap<Player, CountdownTimer>();
|
||||
}
|
||||
|
||||
private long load_internal_long(Player p, NamespacedKey key, long def) {
|
||||
PersistentDataContainer c = p.getPersistentDataContainer();
|
||||
if (c.has(key, PersistentDataType.LONG)) {
|
||||
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)) {
|
||||
if (c.has(key, PersistentDataType.STRING)) {
|
||||
String i = c.get(key, PersistentDataType.STRING);
|
||||
return i;
|
||||
}
|
||||
|
@ -42,11 +50,19 @@ public class PlayerTookDamage implements Listener {
|
|||
|
||||
@EventHandler
|
||||
public void playerTookDamage(EntityDamageByEntityEvent e) {
|
||||
if (!(e.getEntity().getType() == EntityType.PLAYER)) return;
|
||||
if (!(e.getEntity().getType() == EntityType.PLAYER))
|
||||
return;
|
||||
Entity damager = e.getDamager();
|
||||
if (!(damager.getType() == EntityType.PLAYER)) return;
|
||||
if (!(damager.getType() == EntityType.PLAYER))
|
||||
return;
|
||||
Player p2 = (Player) damager;
|
||||
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();
|
||||
NamespacedKey key = new NamespacedKey(this.pl, "AntiBL_LastHit");
|
||||
NamespacedKey key2 = new NamespacedKey(this.pl, "AntiBL_HitOn");
|
||||
|
@ -54,11 +70,16 @@ public class PlayerTookDamage implements Listener {
|
|||
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);
|
||||
CountdownTimer timerP = new CountdownTimer(11, p, this);
|
||||
CountdownTimer timerP2 = new CountdownTimer(11, p2, this);
|
||||
timerP.runTaskTimer(this.pl, 0, 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
|
||||
public void playerLeftGame(PlayerQuitEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
|
@ -67,21 +88,26 @@ public class PlayerTookDamage implements Listener {
|
|||
long unixTimestamp = Instant.now().getEpochSecond();
|
||||
long difference = unixTimestamp - lastOldHit;
|
||||
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 p2d = "someone";
|
||||
Component p2d = Component.text("someone");
|
||||
if (uu == null) {
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
UUID p2u = UUID.fromString(uu);
|
||||
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("."));
|
||||
Bukkit.broadcast(message);
|
||||
p.damage(unixTimestamp); // THAT'S A LOTTA DAMAGE!
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,14 +6,15 @@ import org.bukkit.persistence.PersistentDataType;
|
|||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class NoMoreSayingYouBattleLogged extends BukkitRunnable {
|
||||
public class WriteLastHit extends BukkitRunnable {
|
||||
private Player p;
|
||||
private JavaPlugin pl;
|
||||
|
||||
public NoMoreSayingYouBattleLogged(Player p, JavaPlugin pl) {
|
||||
public WriteLastHit(Player p, JavaPlugin pl) {
|
||||
this.p = p;
|
||||
this.pl = pl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
NamespacedKey key = new NamespacedKey(this.pl, "AntiBL_LastHit");
|
Loading…
Reference in New Issue