quick fix
This commit is contained in:
5
.idea/jarRepositories.xml
generated
5
.idea/jarRepositories.xml
generated
@@ -1,6 +1,11 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="RemoteRepositoriesConfiguration">
|
<component name="RemoteRepositoriesConfiguration">
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="enginehub-repo" />
|
||||||
|
<option name="name" value="enginehub-repo" />
|
||||||
|
<option name="url" value="https://maven.enginehub.org/repo/" />
|
||||||
|
</remote-repository>
|
||||||
<remote-repository>
|
<remote-repository>
|
||||||
<option name="id" value="central" />
|
<option name="id" value="central" />
|
||||||
<option name="name" value="Central Repository" />
|
<option name="name" value="Central Repository" />
|
||||||
|
|||||||
18
pom.xml
18
pom.xml
@@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>21</java.version>
|
<java.version>21</java.version>
|
||||||
|
<fawe.version>2.13.0</fawe.version>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
@@ -59,6 +60,16 @@
|
|||||||
<id>sonatype</id>
|
<id>sonatype</id>
|
||||||
<url>https://oss.sonatype.org/content/groups/public/</url>
|
<url>https://oss.sonatype.org/content/groups/public/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>enginehub-repo</id>
|
||||||
|
<url>https://maven.enginehub.org/repo/</url>
|
||||||
|
<releases>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</releases>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@@ -68,5 +79,12 @@
|
|||||||
<version>1.21.1-R0.1-SNAPSHOT</version>
|
<version>1.21.1-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.sk89q.worldedit</groupId>
|
||||||
|
<artifactId>worldedit-bukkit</artifactId>
|
||||||
|
<version>7.3.9</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -3,24 +3,37 @@ package hu.jgj52.wolfFFA;
|
|||||||
import hu.jgj52.wolfFFA.Commands.EditKitCommand;
|
import hu.jgj52.wolfFFA.Commands.EditKitCommand;
|
||||||
import hu.jgj52.wolfFFA.Commands.TpToFfaCommand;
|
import hu.jgj52.wolfFFA.Commands.TpToFfaCommand;
|
||||||
import hu.jgj52.wolfFFA.Listeners.KitListener;
|
import hu.jgj52.wolfFFA.Listeners.KitListener;
|
||||||
|
import hu.jgj52.wolfFFA.Utils.MapReset;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
public final class Main extends JavaPlugin {
|
public final class Main extends JavaPlugin {
|
||||||
|
|
||||||
|
private MapReset mapReset;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
// Plugin startup logic
|
// Plugin startup logic
|
||||||
getConfig().options().copyDefaults(true);
|
getConfig().options().copyDefaults(true);
|
||||||
|
saveConfig();
|
||||||
|
|
||||||
getCommand("tptoffa").setExecutor(new TpToFfaCommand(this));
|
getCommand("tptoffa").setExecutor(new TpToFfaCommand(this));
|
||||||
getCommand("editkit").setExecutor(new EditKitCommand(this));
|
getCommand("editkit").setExecutor(new EditKitCommand(this));
|
||||||
|
|
||||||
getServer().getPluginManager().registerEvents(new KitListener(this), this);
|
getServer().getPluginManager().registerEvents(new KitListener(this), this);
|
||||||
|
|
||||||
|
this.mapReset = new MapReset(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
// Plugin shutdown logic
|
// Plugin shutdown logic
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Main getInstance() {
|
||||||
|
return getPlugin(Main.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MapReset getMapResetManager() {
|
||||||
|
return this.mapReset;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
194
src/main/java/hu/jgj52/wolfFFA/Utils/MapReset.java
Normal file
194
src/main/java/hu/jgj52/wolfFFA/Utils/MapReset.java
Normal file
@@ -0,0 +1,194 @@
|
|||||||
|
package hu.jgj52.wolfFFA.Utils;
|
||||||
|
|
||||||
|
import com.fastasyncworldedit.core.FaweAPI;
|
||||||
|
import com.fastasyncworldedit.core.extent.clipboard.io.ClipboardFormat;
|
||||||
|
import com.fastasyncworldedit.core.extent.clipboard.io.ClipboardFormats;
|
||||||
|
import com.fastasyncworldedit.core.extent.clipboard.io.ClipboardReader;
|
||||||
|
import com.fastasyncworldedit.core.function.operation.Operation;
|
||||||
|
import com.fastasyncworldedit.core.function.operation.Operations;
|
||||||
|
import com.fastasyncworldedit.core.worldedit.EditSession;
|
||||||
|
import com.fastasyncworldedit.core.worldedit.session.ClipboardHolder;
|
||||||
|
import com.fastasyncworldedit.core.worldedit.math.BlockVector3;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class MapReset {
|
||||||
|
private final JavaPlugin plugin;
|
||||||
|
private BukkitTask resetTask;
|
||||||
|
|
||||||
|
public MapReset(JavaPlugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
mapResetRunnable();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean placeSchematic(World world, int x, int y, int z, String schematicName) {
|
||||||
|
File schematicFile = new File(plugin.getDataFolder() + File.separator + "schematics", schematicName + ".schem");
|
||||||
|
|
||||||
|
if (!schematicFile.exists()) {
|
||||||
|
plugin.getLogger().warning("Schematic file not found: " + schematicFile.getAbsolutePath());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ClipboardFormat format = ClipboardFormats.findByFile(schematicFile);
|
||||||
|
if (format == null) {
|
||||||
|
plugin.getLogger().warning("Unknown schematic format for file: " + schematicFile.getAbsolutePath());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try (ClipboardReader reader = format.getReader(new FileInputStream(schematicFile))) {
|
||||||
|
ClipboardHolder clipboard = new ClipboardHolder(reader.read());
|
||||||
|
|
||||||
|
EditSession editSession = FaweAPI.getWorld(world.getName()).getEditSession();
|
||||||
|
editSession.setFastMode(true); // Optimize for FAWE
|
||||||
|
|
||||||
|
Operation operation = clipboard
|
||||||
|
.createPaste(editSession)
|
||||||
|
.to(BlockVector3.at(x, y, z))
|
||||||
|
.ignoreAirBlocks(false)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Operations.complete(operation);
|
||||||
|
editSession.flushSession();
|
||||||
|
return true;
|
||||||
|
} catch (IOException e) {
|
||||||
|
plugin.getLogger().severe("Error reading schematic file: " + e.getMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
} catch (Exception e) {
|
||||||
|
plugin.getLogger().severe("Error placing schematic: " + e.getMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean placeSchematic(Location location, String schematicName) {
|
||||||
|
return placeSchematic(
|
||||||
|
location.getWorld(),
|
||||||
|
location.getBlockX(),
|
||||||
|
location.getBlockY(),
|
||||||
|
location.getBlockZ(),
|
||||||
|
schematicName
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void placeSchematicsSequentially() {
|
||||||
|
class SchematicPlacement {
|
||||||
|
final World world;
|
||||||
|
final int x, y, z;
|
||||||
|
final String name;
|
||||||
|
|
||||||
|
SchematicPlacement(World world, int x, int y, int z, String name) {
|
||||||
|
this.world = world;
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.z = z;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<SchematicPlacement> schematics = new ArrayList<>();
|
||||||
|
schematics.add(new SchematicPlacement(Bukkit.getWorld("world"), -76, 91, -1076, "uhc"));
|
||||||
|
schematics.add(new SchematicPlacement(Bukkit.getWorld("world"), -1078, 87, 1076, "boxcart"));
|
||||||
|
|
||||||
|
new BukkitRunnable() {
|
||||||
|
int index = 0;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (index < schematics.size()) {
|
||||||
|
SchematicPlacement placement = schematics.get(index);
|
||||||
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
|
player.sendMessage("§ePlacing schematic " + placement.name + "...");
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean success = placeSchematic(
|
||||||
|
placement.world,
|
||||||
|
placement.x,
|
||||||
|
placement.y,
|
||||||
|
placement.z,
|
||||||
|
placement.name
|
||||||
|
);
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
|
player.sendMessage("§aSchematic " + placement.name + " placed successfully!");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
|
player.sendMessage("§cFailed to place schematic " + placement.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
index++;
|
||||||
|
} else {
|
||||||
|
removeEntities();
|
||||||
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
|
player.sendMessage("§cA mapok resetelve lettek!");
|
||||||
|
}
|
||||||
|
this.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.runTaskTimer(plugin, 0L, 20L);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeEntities() {
|
||||||
|
for (World world : Bukkit.getWorlds()) {
|
||||||
|
for (Entity entity : world.getEntities()) {
|
||||||
|
if (entity.getType() == EntityType.TNT_MINECART ||
|
||||||
|
entity.getType() == EntityType.END_CRYSTAL) {
|
||||||
|
entity.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mapResetRunnable() {
|
||||||
|
if (resetTask != null && !resetTask.isCancelled()) {
|
||||||
|
resetTask.cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
resetTask = new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
new BukkitRunnable() {
|
||||||
|
int countdown = 5;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (countdown > 0) {
|
||||||
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
|
player.sendMessage("§cA mapok resetelődnek " + countdown + " másodperc múlva!");
|
||||||
|
}
|
||||||
|
countdown--;
|
||||||
|
} else {
|
||||||
|
// Start sequential schematic placement
|
||||||
|
placeSchematicsSequentially();
|
||||||
|
this.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.runTaskTimer(plugin, 0L, 20L);
|
||||||
|
}
|
||||||
|
}.runTaskTimer(plugin, 0L, 12000L);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Method to stop the scheduler (call this in onDisable)
|
||||||
|
public void stopScheduler() {
|
||||||
|
if (resetTask != null && !resetTask.isCancelled()) {
|
||||||
|
resetTask.cancel();
|
||||||
|
resetTask = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user