Skip to content

Commit

Permalink
Added Arena copy task
Browse files Browse the repository at this point in the history
  • Loading branch information
Devlrxxh committed Sep 22, 2024
1 parent 62e9e5d commit 8a191ba
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Plugin/src/main/java/dev/lrxh/neptune/Neptune.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ private void loadManager() {
new PlaceholderImpl(this).register();
}

this.workloadManager = new WorkloadManager();
this.taskScheduler = new TaskScheduler(this);
this.configManager = new ConfigManager();
this.configManager.load();
this.queueManager = new QueueManager();
Expand All @@ -149,7 +151,6 @@ private void loadManager() {
this.generationManager = new GenerationManager(versionHandler);
this.assemble = new Assemble(new ScoreboardAdapter());
this.api = new API(this);
this.workloadManager = new WorkloadManager();

registerListeners();
loadCommandManager();
Expand Down Expand Up @@ -202,7 +203,6 @@ private void loadWorlds() {
}

private void loadTasks() {
taskScheduler = new TaskScheduler(this);
new QueueCheckTask(this).start(SettingsLocale.QUEUE_UPDATE_TIME.getInt(), this);
new LeaderboardTask(this).start(SettingsLocale.LEADERBOARD_UPDATE_TIME.getInt(), this);
new WorkloadTask(workloadManager).start(1,this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import dev.lrxh.neptune.Neptune;
import dev.lrxh.neptune.arena.Arena;
import dev.lrxh.neptune.arena.impl.tasks.ArenaCaptureTask;
import dev.lrxh.neptune.arena.impl.tasks.ArenaCopyTask;
import dev.lrxh.neptune.arena.impl.tasks.ArenaResetTask;
import dev.lrxh.neptune.configs.impl.SettingsLocale;
import dev.lrxh.neptune.kit.Kit;
Expand Down Expand Up @@ -88,9 +89,9 @@ public boolean isSetup() {
public void createCopy() {
int offset = SettingsLocale.ARENA_COPY_DISTANCE.getInt() * (copies.size() + 1);

plugin.getGenerationManager().pasteRegion(this, min, max, offset);
new ArenaCopyTask(this, offset).start(plugin);

StandAloneArena copy = getArenaCopy(this, LocationUtil.addOffsetToLocation(min, offset), LocationUtil.addOffsetToLocation(max, offset));
StandAloneArena copy = getArenaCopy(this, offset);

copies.add(copy);

Expand All @@ -112,9 +113,11 @@ public void removeCopy(StandAloneArena copy) {
plugin.getKitManager().saveKits();
}

private StandAloneArena getArenaCopy(StandAloneArena arena, Location min, Location max) {
Location redSpawn = new Location(min.getWorld(), arena.getRedSpawn().getX() - arena.getMin().getX() + min.getX(), arena.getRedSpawn().getY(), arena.getRedSpawn().getZ() - arena.getMin().getZ() + min.getZ(), arena.getRedSpawn().getYaw(), arena.getRedSpawn().getPitch());
Location blueSpawn = new Location(max.getWorld(), arena.getBlueSpawn().getX() - arena.getMin().getX() + min.getX(), arena.getBlueSpawn().getY(), arena.getBlueSpawn().getZ() - arena.getMin().getZ() + min.getZ(), arena.getBlueSpawn().getYaw(), arena.getBlueSpawn().getPitch());
private StandAloneArena getArenaCopy(StandAloneArena arena, int offset) {
Location redSpawn = getRedSpawn().add(0, 0, offset);
Location blueSpawn = getBlueSpawn().add(0, 0,offset);
Location min = getMin().add(0, 0, offset);
Location max = getMax().add(0, 0,offset);

return new StandAloneArena(
arena.getName() + "#" + (arena.getCopies().size() + 1),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package dev.lrxh.neptune.arena.impl.tasks;

import dev.lrxh.neptune.Neptune;
import dev.lrxh.neptune.arena.impl.StandAloneArena;
import dev.lrxh.neptune.providers.tasks.Workload;
import org.bukkit.Location;
import org.bukkit.Material;

import java.util.Map;

public class ArenaCopyTask implements Workload {

private final StandAloneArena arena;
private final Neptune plugin;
private final int offset;

public ArenaCopyTask(StandAloneArena arena, int offset) {
this.arena = arena;
this.plugin = arena.getPlugin();
this.offset = offset;
}

@Override
public void compute() {
for (Map.Entry<Location, Material> stuff : arena.getBlockMap().entrySet()) {
plugin.getVersionHandler().getReflection().setBlock(plugin.getPlugin(), stuff.getKey().add(0, 0, offset), stuff.getValue(), false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public String serialize(Location location) {
}

public Location addOffsetToLocation(Location oldLoc, int offset) {
return new Location(oldLoc.getWorld(), oldLoc.getX() + offset, oldLoc.getY(), oldLoc.getZ() + offset, oldLoc.getYaw(), oldLoc.getPitch());
return oldLoc.add(0, 0, offset);
}

public Location deserialize(String source) {
Expand Down

0 comments on commit 8a191ba

Please sign in to comment.