Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

142 changes: 73 additions & 69 deletions dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
@@ -1,69 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>rebelmythik</groupId>
<artifactId>antivillagerlag</artifactId>
<name>antivillagerlag</name>
<version>3.0.6</version>
<build>
<defaultGoal>clean package</defaultGoal>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<relocations>
<relocation>
<pattern>org.bstats</pattern>
<shadedPattern>rebelmythik.antivillagerlag.utils</shadedPattern>
</relocation>
</relocations>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.20.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
<properties>
<java.version>17</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>rebelmythik</groupId>
<artifactId>antivillagerlag</artifactId>
<name>antivillagerlag</name>
<version>3.1.0-FOLIA</version>
<build>
<defaultGoal>clean package</defaultGoal>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<relocations>
<relocation>
<pattern>org.bstats</pattern>
<shadedPattern>rebelmythik.antivillagerlag.utils</shadedPattern>
</relocation>
</relocations>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
<repository>
<id>papermc</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>dev.folia</groupId>
<artifactId>folia-api</artifactId>
<version>1.20.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>17</java.version>
</properties>
</project>
21 changes: 13 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,24 @@
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
<repository>
<id>papermc</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<groupId>dev.folia</groupId>
<artifactId>folia-api</artifactId>
<version>1.20.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency><dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>3.0.0</version>
<scope>compile</scope>
</dependency>
</dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>3.0.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import rebelmythik.antiVillagerLag.events.NameTagAI;
import rebelmythik.antiVillagerLag.events.WorkblockAI;
import rebelmythik.antiVillagerLag.utils.ColorCode;
import rebelmythik.antiVillagerLag.utils.SchedulerUtils;
import rebelmythik.antiVillagerLag.utils.VillagerUtilities;

public class OptimizeCommand implements CommandExecutor {
Expand Down Expand Up @@ -54,19 +55,20 @@ public boolean onCommand(CommandSender commandSender, Command command, String s,
player.getNearbyEntities(radius, radius, radius).forEach(entity -> {
if (entity instanceof Villager) {
Villager villager = (Villager) entity;
// Setup new Villagers
if (!VillagerUtilities.hasMarker(villager, plugin)) {
VillagerUtilities.setAiCooldown(villager, plugin, 0);
VillagerUtilities.setLevelCooldown(villager, plugin, 0);
VillagerUtilities.setLastRestock(villager, plugin);
VillagerUtilities.setMarker(villager, plugin, true);
}
// Rename villager
villager.setCustomName(VillagerUtilities.disabling_names.getFirst());
// Update the marker and AI
VillagerUtilities.setMarker(villager, plugin, false);
villager.setAware(false);

SchedulerUtils.runAtEntity(villager, plugin, () -> {
// Setup new Villagers
if (!VillagerUtilities.hasMarker(villager, plugin)) {
VillagerUtilities.setAiCooldown(villager, plugin, 0);
VillagerUtilities.setLevelCooldown(villager, plugin, 0);
VillagerUtilities.setLastRestock(villager, plugin);
VillagerUtilities.setMarker(villager, plugin, true);
}
// Rename villager
villager.setCustomName(VillagerUtilities.disabling_names.getFirst());
// Update the marker and AI
VillagerUtilities.setMarker(villager, plugin, false);
villager.setAware(false);
});
}
});
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.bukkit.entity.Villager;
import rebelmythik.antiVillagerLag.AntiVillagerLag;
import rebelmythik.antiVillagerLag.utils.ColorCode;
import rebelmythik.antiVillagerLag.utils.SchedulerUtils;
import rebelmythik.antiVillagerLag.utils.VillagerUtilities;

public class RemoveChangesCommand implements CommandExecutor {
Expand Down Expand Up @@ -73,7 +74,9 @@ private void removeVillagerChanges() {
for (Entity entity : world.getLivingEntities()) {
if (entity.getType() == EntityType.VILLAGER) {
Villager vil = (Villager) entity;
VillagerUtilities.CleanseTheVillagers(vil, plugin);
SchedulerUtils.runAtEntity(vil, plugin, () -> {
VillagerUtilities.CleanseTheVillagers(vil, plugin);
});
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.bukkit.entity.Player;
import org.bukkit.entity.Villager;
import rebelmythik.antiVillagerLag.AntiVillagerLag;
import rebelmythik.antiVillagerLag.utils.SchedulerUtils;
import rebelmythik.antiVillagerLag.utils.VillagerUtilities;

public class UnoptimizeCommand implements CommandExecutor {
Expand Down Expand Up @@ -48,18 +49,20 @@ public boolean onCommand(CommandSender commandSender, Command command, String s,
player.getNearbyEntities(radius, radius, radius).forEach(entity -> {
if (entity instanceof Villager) {
Villager villager = (Villager) entity;
// Setup new Villagers
if (!VillagerUtilities.hasMarker(villager, plugin)) {
VillagerUtilities.setAiCooldown(villager, plugin, 0);
VillagerUtilities.setLevelCooldown(villager, plugin, 0);
VillagerUtilities.setLastRestock(villager, plugin);
SchedulerUtils.runAtEntity(villager, plugin, () -> {
// Setup new Villagers
if (!VillagerUtilities.hasMarker(villager, plugin)) {
VillagerUtilities.setAiCooldown(villager, plugin, 0);
VillagerUtilities.setLevelCooldown(villager, plugin, 0);
VillagerUtilities.setLastRestock(villager, plugin);
VillagerUtilities.setMarker(villager, plugin, true);
}
// Rename villager
villager.setCustomName("");
// Update the marker and AI
VillagerUtilities.setMarker(villager, plugin, true);
}
// Rename villager
villager.setCustomName("");
// Update the marker and AI
VillagerUtilities.setMarker(villager, plugin, true);
villager.setAware(true);
villager.setAware(true);
});
}
});
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package rebelmythik.antiVillagerLag.utils;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.concurrent.TimeUnit;

public class SchedulerUtils {

private static boolean isFolia;

static {
try {
Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
isFolia = true;
} catch (ClassNotFoundException e) {
isFolia = false;
}
}

public static boolean isFolia() {
return isFolia;
}

public static void runAsync(JavaPlugin plugin, Runnable runnable) {
if (isFolia) {
Bukkit.getAsyncScheduler().runNow(plugin, task -> runnable.run());
} else {
Bukkit.getScheduler().runTaskAsynchronously(plugin, runnable);
}
}

public static void runSync(JavaPlugin plugin, Runnable runnable) {
if (isFolia) {
Bukkit.getGlobalRegionScheduler().run(plugin, task -> runnable.run());
} else {
Bukkit.getScheduler().runTask(plugin, runnable);
}
}

public static void runAtEntity(Entity entity, JavaPlugin plugin, Runnable runnable) {
if (isFolia) {
entity.getScheduler().run(plugin, task -> runnable.run(), null);
} else {
Bukkit.getScheduler().runTask(plugin, runnable);
}
}

public static void runAtLocation(Location location, JavaPlugin plugin, Runnable runnable) {
if (isFolia) {
Bukkit.getRegionScheduler().run(plugin, location, task -> runnable.run());
} else {
Bukkit.getScheduler().runTask(plugin, runnable);
}
}

public static void runAtEntityLater(Entity entity, JavaPlugin plugin, Runnable runnable, long delay) {
if (isFolia) {
entity.getScheduler().runDelayed(plugin, task -> runnable.run(), null, delay);
} else {
Bukkit.getScheduler().runTaskLater(plugin, runnable, delay);
}
}

public static void runAtLocationLater(Location location, JavaPlugin plugin, Runnable runnable, long delay) {
if (isFolia) {
Bukkit.getRegionScheduler().runDelayed(plugin, location, task -> runnable.run(), delay);
} else {
Bukkit.getScheduler().runTaskLater(plugin, runnable, delay);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public UpdateChecker(JavaPlugin plugin, int resourceId) {
}

public void getVersion(final Consumer<String> consumer) {
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
SchedulerUtils.runAsync(this.plugin, () -> {
try (InputStream is = new URL("https://api.spigotmc.org/legacy/update.php?resource=" + this.resourceId + "/~").openStream(); Scanner scann = new Scanner(is)) {
if (scann.hasNext()) {
consumer.accept(scann.next());
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: AntiVillagerLag
version: '${project.version}'
main: rebelmythik.antiVillagerLag.AntiVillagerLag
api-version: '1.20'
folia-supported: true
authors: [ RebelMythik, CaveRaider ]
description: Bonk Villagers

Expand Down