Skip to content

Commit

Permalink
Merge branch 'APDevTeam:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
goodroach authored Aug 14, 2024
2 parents 5577a66 + e02019a commit 7018aa2
Show file tree
Hide file tree
Showing 31 changed files with 518 additions and 190 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
run: ./gradlew clean shadowJar --parallel

- name: Publish to GitHub Packages
if: ${{ github.event_name == 'release' }}
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
run: ./gradlew publish --parallel
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion Movecraft/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ hangarPublish {
platforms {
register(io.papermc.hangarpublishplugin.model.Platforms.PAPER) {
jar.set(tasks.shadowJar.flatMap { it.archiveFile })
platformVersions.set(listOf("1.18.2", "1.20.6", "1.21"))
platformVersions.set(listOf("1.18.2", "1.20.6", "1.21.1"))
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions Movecraft/src/main/java/net/countercraft/movecraft/Movecraft.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
import net.countercraft.movecraft.config.Settings;
import net.countercraft.movecraft.craft.ChunkManager;
import net.countercraft.movecraft.craft.CraftManager;
import net.countercraft.movecraft.craft.datatag.CraftDataTagRegistry;
import net.countercraft.movecraft.features.contacts.ContactsCommand;
import net.countercraft.movecraft.features.contacts.ContactsManager;
import net.countercraft.movecraft.features.contacts.ContactsSign;
import net.countercraft.movecraft.features.fading.WreckManager;
import net.countercraft.movecraft.features.status.StatusManager;
import net.countercraft.movecraft.features.status.StatusSign;
import net.countercraft.movecraft.listener.*;
Expand All @@ -38,6 +40,7 @@
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.io.FileOutputStream;
Expand All @@ -55,6 +58,7 @@ public class Movecraft extends JavaPlugin {
private WorldHandler worldHandler;
private SmoothTeleport smoothTeleport;
private AsyncManager asyncManager;
private WreckManager wreckManager;

public static synchronized Movecraft getInstance() {
return instance;
Expand All @@ -73,6 +77,7 @@ public void onEnable() {
Settings.DisableNMSCompatibilityCheck = getConfig().getBoolean("IReallyKnowWhatIAmDoing", false);
Settings.DisableSpillProtection = getConfig().getBoolean("DisableSpillProtection", false);
Settings.DisableIceForm = getConfig().getBoolean("DisableIceForm", true);
Settings.ReleaseOnDeath = getConfig().getBoolean("ReleaseOnDeath", false);

String[] localisations = {"en", "cz", "nl", "fr"};
for (String s : localisations) {
Expand Down Expand Up @@ -186,8 +191,10 @@ public void onEnable() {
asyncManager.runTaskTimer(this, 0, 1);
MapUpdateManager.getInstance().runTaskTimer(this, 0, 1);


CraftManager.initialize(datapackInitialized);
Bukkit.getScheduler().runTaskTimer(this, WorldManager.INSTANCE::run, 0,1);
wreckManager = new WreckManager(WorldManager.INSTANCE);

getServer().getPluginManager().registerEvents(new InteractListener(), this);

Expand Down Expand Up @@ -329,4 +336,8 @@ public SmoothTeleport getSmoothTeleport() {
public AsyncManager getAsyncManager() {
return asyncManager;
}

public @NotNull WreckManager getWreckManager(){
return wreckManager;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,26 @@
import net.countercraft.movecraft.MovecraftLocation;
import net.countercraft.movecraft.async.rotation.RotationTask;
import net.countercraft.movecraft.async.translation.TranslationTask;
import net.countercraft.movecraft.config.Settings;
import net.countercraft.movecraft.craft.*;
import net.countercraft.movecraft.craft.Craft;
import net.countercraft.movecraft.craft.CraftManager;
import net.countercraft.movecraft.craft.PilotedCraft;
import net.countercraft.movecraft.craft.PlayerCraft;
import net.countercraft.movecraft.craft.SinkingCraft;
import net.countercraft.movecraft.craft.type.CraftType;
import net.countercraft.movecraft.events.CraftReleaseEvent;
import net.countercraft.movecraft.mapUpdater.MapUpdateManager;
import net.countercraft.movecraft.mapUpdater.update.BlockCreateCommand;
import net.countercraft.movecraft.mapUpdater.update.UpdateCommand;
import net.countercraft.movecraft.util.hitboxes.HitBox;
import net.kyori.adventure.text.Component;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.jetbrains.annotations.NotNull;

import java.util.*;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

Expand All @@ -49,14 +51,8 @@ public class AsyncManager extends BukkitRunnable {
private final Map<AsyncTask, Craft> ownershipMap = new HashMap<>();
private final BlockingQueue<AsyncTask> finishedAlgorithms = new LinkedBlockingQueue<>();
private final Set<Craft> clearanceSet = new HashSet<>();
private final Map<HitBox, Long> wrecks = new HashMap<>();
private final Map<HitBox, World> wreckWorlds = new HashMap<>();
private final Map<HitBox, Map<Location, BlockData>> wreckPhases = new HashMap<>();
private final Map<World, Set<MovecraftLocation>> processedFadeLocs = new HashMap<>();
private final Map<Craft, Integer> cooldownCache = new WeakHashMap<>();

private long lastFadeCheck = 0;

public AsyncManager() {}

public void submitTask(AsyncTask task, Craft c) {
Expand All @@ -71,15 +67,6 @@ public void submitCompletedTask(AsyncTask task) {
finishedAlgorithms.add(task);
}

public void addWreck(Craft craft){
if(craft.getCollapsedHitBox().isEmpty() || Settings.FadeWrecksAfter == 0){
return;
}
wrecks.put(craft.getCollapsedHitBox(), System.currentTimeMillis());
wreckWorlds.put(craft.getCollapsedHitBox(), craft.getWorld());
wreckPhases.put(craft.getCollapsedHitBox(), craft.getPhaseBlocks());
}

private void processAlgorithmQueue() {
int runLength = 10;
int queueLength = finishedAlgorithms.size();
Expand Down Expand Up @@ -325,68 +312,11 @@ private void processSinking() {
}
}

private void processFadingBlocks() {
if (Settings.FadeWrecksAfter == 0)
return;
long ticksElapsed = (System.currentTimeMillis() - lastFadeCheck) / 50;
if (ticksElapsed <= Settings.FadeTickCooldown)
return;

List<HitBox> processed = new ArrayList<>();
for(Map.Entry<HitBox, Long> entry : wrecks.entrySet()){
if (Settings.FadeWrecksAfter * 1000L > System.currentTimeMillis() - entry.getValue())
continue;

final HitBox hitBox = entry.getKey();
final Map<Location, BlockData> phaseBlocks = wreckPhases.get(hitBox);
final World world = wreckWorlds.get(hitBox);
List<UpdateCommand> commands = new ArrayList<>();
int fadedBlocks = 0;
if (!processedFadeLocs.containsKey(world))
processedFadeLocs.put(world, new HashSet<>());

int maxFadeBlocks = (int) (hitBox.size() * (Settings.FadePercentageOfWreckPerCycle / 100.0));
//Iterate hitbox as a set to get more random locations
for (MovecraftLocation location : hitBox.asSet()){
if (processedFadeLocs.get(world).contains(location))
continue;

if (fadedBlocks >= maxFadeBlocks)
break;

final Location bLoc = location.toBukkit(world);
if ((Settings.FadeWrecksAfter
+ Settings.ExtraFadeTimePerBlock.getOrDefault(bLoc.getBlock().getType(), 0))
* 1000L > System.currentTimeMillis() - entry.getValue())
continue;

fadedBlocks++;
processedFadeLocs.get(world).add(location);
BlockData phaseBlock = phaseBlocks.getOrDefault(bLoc, Material.AIR.createBlockData());
commands.add(new BlockCreateCommand(world, location, phaseBlock));
}
MapUpdateManager.getInstance().scheduleUpdates(commands);
if (!processedFadeLocs.get(world).containsAll(hitBox.asSet()))
continue;

processed.add(hitBox);
processedFadeLocs.get(world).removeAll(hitBox.asSet());
}
for(HitBox hitBox : processed) {
wrecks.remove(hitBox);
wreckPhases.remove(hitBox);
wreckWorlds.remove(hitBox);
}

lastFadeCheck = System.currentTimeMillis();
}

public void run() {
clearAll();

processCruise();
processSinking();
processFadingBlocks();
processAlgorithmQueue();

// now cleanup craft that are bugged and have not moved in the past 60 seconds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,14 +334,17 @@ else if (world.equals(craft.getWorld())
}
newHitBox.removeAll(air);
for (MovecraftLocation location : collisionBox) {
if (craft.getType().getFloatProperty(CraftType.EXPLODE_ON_CRASH) > 0F) {
CraftType type = craft.getType();

if (type.getFloatProperty(CraftType.EXPLODE_ON_CRASH) > 0F) {
if (System.currentTimeMillis() - craft.getOrigPilotTime() <= 1000) {
continue;
}
Location loc = location.toBukkit(craft.getWorld());
if (!loc.getBlock().getType().isAir() && ThreadLocalRandom.current().nextDouble(1) < .05) {
updates.add(new ExplosionUpdateCommand(loc,
craft.getType().getFloatProperty(CraftType.EXPLODE_ON_CRASH)));
type.getFloatProperty(CraftType.EXPLODE_ON_CRASH),
type.getBoolProperty(CraftType.INCENDIARY_ON_CRASH)));
collisionExplosion = true;
}
}
Expand All @@ -358,6 +361,7 @@ else if (world.equals(craft.getWorld())
&& System.currentTimeMillis() - craft.getOrigPilotTime() > craft.getType().getIntProperty(CraftType.EXPLOSION_ARMING_TIME)) {
for (MovecraftLocation location : collisionBox) {
float explosionForce = craft.getType().getFloatProperty(CraftType.COLLISION_EXPLOSION);
boolean incendiary = craft.getType().getBoolProperty(CraftType.INCENDIARY_ON_CRASH);
if (craft.getType().getBoolProperty(CraftType.FOCUSED_EXPLOSION)) {
explosionForce *= Math.min(oldHitBox.size(), craft.getType().getIntProperty(CraftType.MAX_SIZE));
}
Expand All @@ -372,7 +376,7 @@ else if (world.equals(craft.getWorld())
newLocation, craft.getWorld());
Bukkit.getServer().getPluginManager().callEvent(e);
if (!e.isCancelled()) {
updates.add(new ExplosionUpdateCommand(newLocation, explosionForce));
updates.add(new ExplosionUpdateCommand(newLocation, explosionForce, incendiary));
collisionExplosion = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import net.countercraft.movecraft.async.translation.TranslationTask;
import net.countercraft.movecraft.config.Settings;
import net.countercraft.movecraft.craft.datatag.CraftDataTagContainer;
import net.countercraft.movecraft.craft.datatag.CraftDataTagKey;
import net.countercraft.movecraft.craft.datatag.CraftDataTagRegistry;
import net.countercraft.movecraft.craft.type.CraftType;
import net.countercraft.movecraft.localisation.I18nSupport;
import net.countercraft.movecraft.processing.CachedMovecraftWorld;
Expand All @@ -22,13 +24,23 @@
import net.countercraft.movecraft.util.hitboxes.SetHitBox;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import org.bukkit.*;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.block.data.BlockData;
import org.jetbrains.annotations.NotNull;

import java.util.*;
import java.util.Collection;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;

Expand Down Expand Up @@ -69,7 +81,8 @@ public abstract class BaseCraft implements Craft {
private MovecraftLocation lastTranslation = new MovecraftLocation(0, 0, 0);
private Map<NamespacedKey, Set<TrackedLocation>> trackedLocations = new HashMap<>();

private final CraftDataTagContainer dataTagContainer = new CraftDataTagContainer();
@NotNull
private final CraftDataTagContainer dataTagContainer;

private final UUID uuid = UUID.randomUUID();

Expand All @@ -85,6 +98,7 @@ public BaseCraft(@NotNull CraftType type, @NotNull World world) {
disabled = false;
origPilotTime = System.currentTimeMillis();
audience = Audience.empty();
dataTagContainer = new CraftDataTagContainer();
}


Expand Down Expand Up @@ -536,11 +550,17 @@ public void setAudience(@NotNull Audience audience) {
}

@Override
public CraftDataTagContainer getDataTagContainer() {
return dataTagContainer;
public <T> void setDataTag(final @NotNull CraftDataTagKey<T> tagKey, final T data) {
dataTagContainer.set(tagKey, data);
}

public UUID getUuid() {
@Override
public <T> T getDataTag(final @NotNull CraftDataTagKey<T> tagKey) {
return dataTagContainer.get(this, tagKey);
}

@Override
public UUID getUUID() {
return this.uuid;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public void release(@NotNull Craft craft, @NotNull CraftReleaseEvent.Reason reas
craft.getHitBox().getMinZ())
);
}
Movecraft.getInstance().getAsyncManager().addWreck(craft);
Movecraft.getInstance().getWreckManager().queueWreck(craft);
}

//region Craft management
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.countercraft.movecraft.craft.*;
import net.countercraft.movecraft.craft.datatag.CraftDataTagContainer;
import net.countercraft.movecraft.craft.datatag.CraftDataTagKey;
import net.countercraft.movecraft.craft.datatag.CraftDataTagRegistry;
import net.countercraft.movecraft.craft.type.CraftType;
import net.countercraft.movecraft.events.*;
import net.countercraft.movecraft.exception.EmptyHitBoxException;
Expand All @@ -27,7 +28,7 @@
import java.util.*;

public class ContactsManager extends BukkitRunnable implements Listener {
private static final CraftDataTagKey<Map<Craft, Long>> RECENT_CONTACTS = CraftDataTagContainer.tryRegisterTagKey(new NamespacedKey("movecraft", "recent-contacts"), craft -> new WeakHashMap<>());
private static final CraftDataTagKey<Map<Craft, Long>> RECENT_CONTACTS = CraftDataTagRegistry.INSTANCE.registerTagKey(new NamespacedKey("movecraft", "recent-contacts"), craft -> new WeakHashMap<>());

@Override
public void run() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package net.countercraft.movecraft.features.fading;

import net.countercraft.movecraft.MovecraftLocation;
import net.countercraft.movecraft.processing.MovecraftWorld;
import net.countercraft.movecraft.processing.WorldManager;
import net.countercraft.movecraft.processing.effects.Effect;
import net.countercraft.movecraft.processing.effects.SetBlockEffect;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.block.data.BlockData;
import org.jetbrains.annotations.NotNull;

import java.util.Objects;
import java.util.function.Supplier;

/**
* Fades a block if the data for the intended block has not been mutated since creation.
*/
public class FadeTask implements Supplier<Effect> {
private final @NotNull BlockData compareData;
private final @NotNull BlockData setData;
private final @NotNull MovecraftWorld world;
private final @NotNull MovecraftLocation location;

public FadeTask(@NotNull BlockData compareData, @NotNull BlockData setData, @NotNull MovecraftWorld world, @NotNull MovecraftLocation location){
this.compareData = compareData;
this.setData = setData;
this.world = world;
this.location = location;
}

@Override
public Effect get() {
var testData = world.getData(location);

return () -> Objects.requireNonNull(Bukkit.getWorld(world.getWorldUUID()))
.getChunkAtAsync(location.toBukkit(null))
.thenRunAsync(() -> WorldManager.INSTANCE.submit(() -> testData.equals(compareData)
? new SetBlockEffect(world, location, setData)
: null));
}
}
Loading

0 comments on commit 7018aa2

Please sign in to comment.