Skip to content

Commit

Permalink
Bug fix with clear command
Browse files Browse the repository at this point in the history
  • Loading branch information
Sorax5 committed Sep 11, 2024
1 parent a7f95ee commit 8268eb9
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = 'fr.phylisiumstudio'
version = '1.1-BETA'
version = '1.1.1-BETA'

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public void removeBlock(RigidBlock block) {
*/
@Override
public void clear() {
synchronized (blocks) {
synchronized (PhysicsManager.lock) {
for (RigidBlock block : blocks) {
bulletWorld.removeRigidBody(block.getRigidBody());
block.getBlockDisplay().remove();
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/fr/phylisiumstudio/logic/WorldPhysics.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,12 @@ public abstract class WorldPhysics {
* @return if the world can run
*/
public abstract boolean isRunning();

/**
* Link two rigid blocks
* @param rigidBlock the first block
* @param rigidBlock1 the second block
*/
public void linkRigidBlock(RigidBlock rigidBlock, RigidBlock rigidBlock1) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,34 @@
import co.aikar.commands.BaseCommand;
import co.aikar.commands.CommandHelp;
import co.aikar.commands.annotation.*;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.session.SessionManager;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BlockState;
import fr.phylisiumstudio.logic.WorldPhysics;
import fr.phylisiumstudio.soraxPhysic.PhysicsManager;
import fr.phylisiumstudio.soraxPhysic.models.RigidBlock;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import javax.vecmath.Vector3f;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.vecmath.Vector3f;

@CommandAlias("physics")
Expand Down Expand Up @@ -42,7 +63,7 @@ public void createSphere(Player sender, Material block, float mass, float radius
sender.sendMessage("Sphere created");
}

/*@Subcommand("convert")
@Subcommand("convert")
@Description("Convert the WorldEdit selection to physics shapes (beta feature do not use if you don't know what you are doing)")
@CommandPermission("physics.create.convert")
public void convertSelection(Player player, float impulse, float damping, float tau){
Expand All @@ -52,6 +73,7 @@ public void convertSelection(Player player, float impulse, float damping, float
Region region;
World world = session.getSelectionWorld();
org.bukkit.World bukkitWorld = BukkitAdapter.adapt(world);
WorldPhysics worldPhysics = physicsManager.getWorldPhysics(bukkitWorld.getUID());

try {
if (world == null) {
Expand All @@ -63,7 +85,7 @@ public void convertSelection(Player player, float impulse, float damping, float
throw new IllegalArgumentException("Please make a WorldEdit selection first");
}

Map<Block,RigidBody> bodies = new HashMap<>();
Map<Block, RigidBlock> bodies = new HashMap<>();

// get block in the region
for (BlockVector3 blockVector3 : region) {
Expand All @@ -73,7 +95,7 @@ public void convertSelection(Player player, float impulse, float damping, float
continue;
}

RigidBody body = physicsManager.createBoxShape(block.getLocation(), block.getType(), 1, 1, 1, 1);
RigidBlock body = worldPhysics.createBox(block.getLocation(), block.getBlockData(), 1, 1, 1, 1);
bodies.put(block, body);
}

Expand All @@ -92,7 +114,7 @@ public void convertSelection(Player player, float impulse, float damping, float
BlockFace oppositeFace = blockFace.getOppositeFace();
assert oppositeFace != null;

physicsManager.linkRigidBody(body, bodies.get(block1), blockFace, oppositeFace);
worldPhysics.linkRigidBlock(bodies.get(block), bodies.get(block1));
}
}
});
Expand All @@ -105,7 +127,7 @@ public void convertSelection(Player player, float impulse, float damping, float
}

player.sendMessage("Selection converted");
}*/
}
}

@Subcommand("clear")
Expand Down

0 comments on commit 8268eb9

Please sign in to comment.