Init
This commit is contained in:
commit
687c4ed0c7
|
@ -0,0 +1,38 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="test" value="true"/>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="test" value="true"/>
|
||||||
|
<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">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="output" path="target/classes"/>
|
||||||
|
</classpath>
|
|
@ -0,0 +1,3 @@
|
||||||
|
*.class
|
||||||
|
/target
|
||||||
|
*.[wj]ar
|
|
@ -0,0 +1,23 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>antibattlelogging</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
|
@ -0,0 +1,2 @@
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
|
@ -0,0 +1,4 @@
|
||||||
|
activeProfiles=
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
resolveWorkspaceProjects=true
|
||||||
|
version=1
|
|
@ -0,0 +1,4 @@
|
||||||
|
name: FBl
|
||||||
|
main: ca.thetechrobo.fbl.AntiBattlelogPlugin
|
||||||
|
version: 1.0
|
||||||
|
api-version: 1.19
|
|
@ -0,0 +1,24 @@
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>ca.thetechrobo.antibattlelog</groupId>
|
||||||
|
<artifactId>antibattlelogging</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<name>FBl</name>
|
||||||
|
<description>because battle-logging is trash</description>
|
||||||
|
<repositories>
|
||||||
|
<!-- This adds the Spigot Maven repository to the build -->
|
||||||
|
<repository>
|
||||||
|
<id>purpur-repo</id>
|
||||||
|
<url>https://repo.purpurmc.org/snapshots</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
<dependencies>
|
||||||
|
<!--This adds the Purpur API artifact to the build -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.purpurmc.purpur</groupId>
|
||||||
|
<artifactId>purpur-api</artifactId>
|
||||||
|
<version>1.19-R0.1-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
|
@ -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() {
|
||||||
|
}
|
||||||
|
}
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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!"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue