Skip to content

Commit

Permalink
Some fixes
Browse files Browse the repository at this point in the history
Are they good fixes or bad ones?
They fix stuff okay >.>
  • Loading branch information
Pulverizer committed Jul 12, 2019
1 parent 8590b6d commit 40fdce3
Show file tree
Hide file tree
Showing 110 changed files with 506 additions and 371 deletions.
Binary file modified .gradle/4.4/fileContent/fileContent.lock
Binary file not shown.
Binary file modified .gradle/4.4/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/4.4/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/4.4/taskHistory/taskHistory.bin
Binary file not shown.
Binary file modified .gradle/4.4/taskHistory/taskHistory.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
459 changes: 222 additions & 237 deletions .idea/workspace.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ <h2 title="Class PilotSign" class="title">Class PilotSign</h2>
<li>java.lang.Object</li>
<li>
<ul class="inheritance">
<li>io.github.pulverizer.movecraft.sign.PilotSign</li>
<li>io.github.pulverizer.movecraft.sign.CommanderSign</li>
</ul>
</li>
</ul>
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed build/libs/movecraft-0.0.1.jar
Binary file not shown.
Binary file added build/libs/movecraft-0.1.0.jar
Binary file not shown.
23 changes: 4 additions & 19 deletions src/main/java/io/github/pulverizer/movecraft/Movecraft.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.reflect.TypeToken;
import com.google.inject.Inject;
import io.github.pulverizer.movecraft.sign.*;
import ninja.leaping.configurate.ConfigurationNode;
import ninja.leaping.configurate.ConfigurationOptions;
import ninja.leaping.configurate.loader.ConfigurationLoader;
Expand All @@ -25,24 +26,7 @@
import io.github.pulverizer.movecraft.listener.InteractListener;
import io.github.pulverizer.movecraft.listener.PlayerListener;
import io.github.pulverizer.movecraft.mapUpdater.MapUpdateManager;
import io.github.pulverizer.movecraft.sign.AntiAircraftDirectorSign;
import io.github.pulverizer.movecraft.sign.AscendSign;
import io.github.pulverizer.movecraft.sign.CannonDirectorSign;
import io.github.pulverizer.movecraft.sign.ContactsSign;
import io.github.pulverizer.movecraft.sign.CraftSign;
import io.github.pulverizer.movecraft.sign.CrewSign;
import io.github.pulverizer.movecraft.sign.CruiseSign;
import io.github.pulverizer.movecraft.sign.DescendSign;
import io.github.pulverizer.movecraft.sign.HelmSign;
import io.github.pulverizer.movecraft.sign.MoveSign;
import io.github.pulverizer.movecraft.sign.PilotSign;
import io.github.pulverizer.movecraft.sign.RelativeMoveSign;
import io.github.pulverizer.movecraft.sign.ReleaseSign;
import io.github.pulverizer.movecraft.sign.RemoteSign;
import io.github.pulverizer.movecraft.sign.SpeedSign;
import io.github.pulverizer.movecraft.sign.StatusSign;
import io.github.pulverizer.movecraft.sign.SubcraftRotateSign;
import io.github.pulverizer.movecraft.sign.TeleportSign;
import io.github.pulverizer.movecraft.sign.CommanderSign;
import org.spongepowered.api.scheduler.Task;

import java.io.IOException;
Expand Down Expand Up @@ -244,14 +228,15 @@ public void onLoad(GamePreInitializationEvent event) {
Sponge.getEventManager().registerListeners(this, new DescendSign());
Sponge.getEventManager().registerListeners(this, new HelmSign());
Sponge.getEventManager().registerListeners(this, new MoveSign());
Sponge.getEventManager().registerListeners(this, new PilotSign());
Sponge.getEventManager().registerListeners(this, new CommanderSign());
Sponge.getEventManager().registerListeners(this, new RelativeMoveSign());
Sponge.getEventManager().registerListeners(this, new ReleaseSign());
Sponge.getEventManager().registerListeners(this, new RemoteSign());
Sponge.getEventManager().registerListeners(this, new SpeedSign());
Sponge.getEventManager().registerListeners(this, new StatusSign());
Sponge.getEventManager().registerListeners(this, new SubcraftRotateSign());
Sponge.getEventManager().registerListeners(this, new TeleportSign());
Sponge.getEventManager().registerListeners(this, new PilotSign());

logger.info("Movecraft Enabled.");
}
Expand Down
25 changes: 17 additions & 8 deletions src/main/java/io/github/pulverizer/movecraft/WorldHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import io.github.pulverizer.movecraft.config.Settings;
import io.github.pulverizer.movecraft.craft.Craft;
import io.github.pulverizer.movecraft.utils.HashHitBox;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.block.BlockSnapshot;
import org.spongepowered.api.block.BlockTypes;
import org.spongepowered.api.block.ScheduledBlockUpdate;
import org.spongepowered.api.data.key.Keys;
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.scheduler.Task;
import org.spongepowered.api.util.Direction;
import org.spongepowered.api.world.*;
import io.github.pulverizer.movecraft.utils.MathUtils;
Expand Down Expand Up @@ -104,31 +106,38 @@ public void translateCraft(Craft craft, Vector3i translateBlockVector, HashHitBo

//get the old blocks
List<BlockSnapshot> blocks = new ArrayList<>();
List<Collection<ScheduledBlockUpdate>> updates = new ArrayList<>();
//List<Collection<ScheduledBlockUpdate>> updates = new ArrayList<>();
for(Vector3i blockPosition : blockPositions){
blocks.add(nativeWorld.createSnapshot(blockPosition));
updates.add(nativeWorld.getLocation(blockPosition).getScheduledUpdates());
//updates.add(nativeWorld.getLocation(blockPosition).getScheduledUpdates());
}

//translate the blockPositions
List<Vector3i> newBlockPositions = new ArrayList<>();
for(Vector3i blockPosition : blockPositions){
newBlockPositions.add(blockPosition.add(translateBlockVector));
}

//remove the old blocks from the world
blockPositions.forEach(blockPosition -> {
nativeWorld.getLocation(blockPosition).getScheduledUpdates().forEach(update -> nativeWorld.getLocation(blockPosition).removeScheduledUpdate(update));
setBlock(nativeWorld, blockPosition, BlockSnapshot.builder().blockState(BlockTypes.AIR.getDefaultState()).world(nativeWorld.getProperties()).position(blockPosition).build());
});
//for (Vector3i blockPosition : blockPositions) {
//nativeWorld.getLocation(blockPosition).getScheduledUpdates().forEach(update -> nativeWorld.getLocation(blockPosition).removeScheduledUpdate(update));
//setBlock(nativeWorld, blockPosition, BlockSnapshot.builder().blockState(BlockTypes.AIR.getDefaultState()).world(nativeWorld.getProperties()).position(blockPosition).build());
//}

//create the new blocks
for(int i = 0; i < newBlockPositions.size(); i++) {
setBlock(nativeWorld, newBlockPositions.get(i), blocks.get(i));
int finalI = i;
updates.get(i).forEach(update -> nativeWorld.getLocation(newBlockPositions.get(finalI)).addScheduledUpdate(update.getPriority(), update.getTicks()));
//int finalI = i;
//updates.get(i).forEach(update -> nativeWorld.getLocation(newBlockPositions.get(finalI)).addScheduledUpdate(update.getPriority(), update.getTicks()));
}

blockPositions.removeAll(newBlockPositions);
blockPositions.forEach(blockPosition -> {
setBlock(nativeWorld, blockPosition, BlockSnapshot.builder().blockState(BlockTypes.AIR.getDefaultState()).world(nativeWorld.getProperties()).position(blockPosition).build());
});

craft.setHitBox(newHitBox);

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,53 +128,54 @@ private void processAlgorithmQueue() {
DetectionTask task = (DetectionTask) poll;
DetectionTaskData data = task.getData();

Player p = Sponge.getServer().getPlayer(data.getPlayer()).orElse(null);
Player notifyP = Sponge.getServer().getPlayer(data.getNotificationPlayer()).orElse(null);
Craft pCraft = CraftManager.getInstance().getCraftByPlayer(data.getPlayer());
Player player = Sponge.getServer().getPlayer(data.getPlayer()).orElse(null);

if (pCraft != null && p != null) {
// Player is already controlling a craft
notifyP.sendMessage(Text.of("Detection Failed! You are already commanding a craft."));
} else {
if (data.failed()) {
if (notifyP != null)
notifyP.sendMessage(Text.of(data.getFailMessage()));
if (player != null)
player.sendMessage(Text.of(data.getFailMessage()));
else
Movecraft.getInstance().getLogger().info("NULL Player Craft Detection failed:" + data.getFailMessage());

} else {
Set<Craft> craftsInWorld = CraftManager.getInstance().getCraftsInWorld(c.getWorld());
boolean failed = false;
boolean isSubcraft = false;
Craft parentCraft = null;

for (Craft craft : craftsInWorld) {
if(craft.getHitBox().intersects(data.getBlockList())){
for (Craft pCraft : craftsInWorld) {
if (pCraft.getHitBox().intersects(data.getBlockList())) {
isSubcraft = true;
if (c.getType().getCruiseOnPilot() || p != null) {
if (craft.getType() == c.getType() || craft.getHitBox().size() <= data.getBlockList().size()) {
notifyP.sendMessage(Text.of("Detection Failed. Craft is already being controlled by another player."));
parentCraft = pCraft;
break;
}
}
if (player != null && CraftManager.getInstance().getCraftByPlayer(player.getUniqueId()) != null && (!c.getType().getCruiseOnPilot() || isSubcraft)) {
// Player is already controlling a craft
player.sendMessage(Text.of("Detection Failed! You are already in the crew of another craft."));
} else {

if (isSubcraft && (c.getType().getCruiseOnPilot() || player != null)) {

if (parentCraft.getType() == c.getType() || parentCraft.getHitBox().size() <= data.getBlockList().size()) {
player.sendMessage(Text.of("Detection Failed. Craft is already being controlled by another player."));
failed = true;

} else {

// if this is a different type than the overlapping craft, and is smaller, this must be a child craft, like a fighter on a carrier
if (!parentCraft.isNotProcessing()) {
failed = true;
} else {
// if this is a different type than
// the overlapping craft, and is
// smaller, this must be a child
// craft, like a fighter on a
// carrier
if (!craft.isNotProcessing()) {
failed = true;
notifyP.sendMessage(Text.of("Parent Craft is busy."));
}
craft.setHitBox(new HashHitBox(CollectionUtils.filter(craft.getHitBox(),data.getBlockList())));
craft.setInitialSize(craft.getInitialSize() - data.getBlockList().size());
player.sendMessage(Text.of("Parent Craft is busy."));
}
parentCraft.setHitBox(new HashHitBox(CollectionUtils.filter(parentCraft.getHitBox(), data.getBlockList())));
parentCraft.setInitialSize(parentCraft.getInitialSize() - data.getBlockList().size());
}
}


}

if (c.getType().getMustBeSubcraft() && !isSubcraft) {
failed = true;
notifyP.sendMessage(Text.of("Craft must be part of another craft!"));
player.sendMessage(Text.of("Craft must be part of another craft!"));
}
if (!failed) {
c.setInitialSize(task.getData().getBlockList().size());
Expand All @@ -188,19 +189,25 @@ private void processAlgorithmQueue() {
}
}

if (notifyP != null) {
notifyP.sendMessage(Text.of("Successfully piloted " + c.getType().getCraftName() + " Size: " + c.getHitBox().size()));
Movecraft.getInstance().getLogger().info("New Craft Detected! Pilot: " + notifyP.getName() + " CraftType: " + c.getType().getCraftName() + " Size: " + c.getHitBox().size() + " Location: " + c.getHitBox().getMinX() + ", " + c.getHitBox().getMinY() + ", " + c.getHitBox().getMinZ());
if (c.getHitBox() != null) {

if (player != null) {
player.sendMessage(Text.of("Successfully piloted " + c.getType().getCraftName() + " Size: " + c.getHitBox().size()));
Movecraft.getInstance().getLogger().info("New Craft Detected! Pilot: " + player.getName() + " CraftType: " + c.getType().getCraftName() + " Size: " + c.getHitBox().size() + " Location: " + c.getHitBox().getMinX() + ", " + c.getHitBox().getMinY() + ", " + c.getHitBox().getMinZ());
} else {
Movecraft.getInstance().getLogger().info("New Craft Detected! Pilot: " + "NULL PLAYER" + " CraftType: " + c.getType().getCraftName() + " Size: " + c.getHitBox().size() + " Location: " + c.getHitBox().getMinX() + ", " + c.getHitBox().getMinY() + ", " + c.getHitBox().getMinZ());
}
CraftManager.getInstance().addCraft(c);
} else {
Movecraft.getInstance().getLogger().info("New Craft Detected! Pilot: " + "NULL PLAYER" + " CraftType: " + c.getType().getCraftName() + " Size: " + c.getHitBox().size() + " Location: " + c.getHitBox().getMinX() + ", " + c.getHitBox().getMinY() + ", " + c.getHitBox().getMinZ());
Movecraft.getInstance().getLogger().info("Detection Failed - NULL Hitbox!");
}
CraftManager.getInstance().addCraft(c);
}
}
if(c != null && c.getHitBox() != null){
CraftDetectEvent event = new CraftDetectEvent(c);
Sponge.getEventManager().post(event);
}
if(c!=null){
Sponge.getEventManager().post(new CraftDetectEvent(c));
}


} else if (poll instanceof TranslationTask) {
// Process translation task
Expand Down Expand Up @@ -233,6 +240,7 @@ private void processAlgorithmQueue() {
}

} else if (poll instanceof RotationTask) {

// Process rotation task
RotationTask task = (RotationTask) poll;
Player notifyP = Sponge.getServer().getPlayer(c.getPilot()).orElse(null);
Expand All @@ -241,13 +249,15 @@ private void processAlgorithmQueue() {
if (notifyP != null || task.getIsSubCraft()) {

if (task.isFailed()) {

// The craft translation failed, don't try to notify
// them if there is no pilot
if (notifyP != null)
notifyP.sendMessage(Text.of(task.getFailMessage()));
else
Movecraft.getInstance().getLogger().info("NULL Player Rotation Failed: " + task.getFailMessage());
} else {

if (c.getPilot() != null) {
// convert blocklist to location list
List<Location> shipLocations = new ArrayList<>();
Expand All @@ -256,8 +266,9 @@ private void processAlgorithmQueue() {
}
}

MapUpdateManager.getInstance().scheduleUpdates(task.getUpdates());
Movecraft.getInstance().getLogger().info("Number of updates in Rotation Task: " + task.getUpdates().size());

MapUpdateManager.getInstance().scheduleUpdates(task.getUpdates());

sentMapUpdate = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public DetectionTask(Craft c, Location<World> startLocation, UUID player) {
this.minSize = craft.getType().getMinSize();
this.maxSize = craft.getType().getMaxSize();
this.world = craft.getWorld();
data = new DetectionTaskData(craft.getWorld(), player, craft.getPilot(), craft.getType().getAllowedBlocks(), craft.getType().getForbiddenBlocks(),
data = new DetectionTaskData(craft.getWorld(), player, craft.getType().getAllowedBlocks(), craft.getType().getForbiddenBlocks(),
craft.getType().getForbiddenSignStrings());
}

Expand Down Expand Up @@ -98,15 +98,15 @@ private void detectBlock(Location<World> workingLocation) {
if(snapshot.getLocation().isPresent() && snapshot.getLocation().get().getTileEntity().isPresent()) {

Sign s = (Sign) snapshot.getLocation().get().getTileEntity().get();
if (s.lines().get(0).toString().equalsIgnoreCase("Pilot:") && data.getPlayer() != null) {
if (s.lines().get(0).toString().equalsIgnoreCase("Commander:") && data.getPlayer() != null) {
String playerName = Sponge.getServer().getPlayer(data.getPlayer()).get().getName();
boolean foundPilot = false;
if (s.lines().get(1).toString().equalsIgnoreCase(playerName) || s.lines().get(2).toString().equalsIgnoreCase(playerName)
|| s.lines().get(3).toString().equalsIgnoreCase(playerName)) {
foundPilot = true;
}
if (!foundPilot && (!Sponge.getServer().getPlayer(data.getPlayer()).get().hasPermission("movecraft.bypasslock"))) {
fail("Not one of the registered pilots on this craft.");
fail("Not one of the registered commanders for this craft.");
}
}
for (int i = 0; i < 4; i++) {
Expand All @@ -120,12 +120,7 @@ private void detectBlock(Location<World> workingLocation) {
fail("Detection Failed- Forbidden block found.");
} else if (isAllowedBlock(testID)) {

UUID player;
if (data.getPlayer() == null) {
player = data.getNotificationPlayer();
} else {
player = data.getPlayer();
}
UUID player = data.getPlayer();
if (player != null) {

addToBlockList(workingLocation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ public class DetectionTaskData {
private String failMessage;
private HashHitBox hitBox;
private UUID player;
private UUID notificationPlayer;
private int minX, minZ;
private BlockType[] allowedBlocks, forbiddenBlocks;
private String[] forbiddenSignStrings;

public DetectionTaskData(World w, UUID player, UUID notificationPlayer, BlockType[] allowedBlocks, BlockType[] forbiddenBlocks, String[] forbiddenSignStrings) {
public DetectionTaskData(World w, UUID player, BlockType[] allowedBlocks, BlockType[] forbiddenBlocks, String[] forbiddenSignStrings) {
this.w = w;
this.player = player;
this.notificationPlayer = notificationPlayer;
this.allowedBlocks = allowedBlocks;
this.forbiddenBlocks = forbiddenBlocks;
this.forbiddenSignStrings = forbiddenSignStrings;
Expand Down Expand Up @@ -92,14 +90,6 @@ void setPlayer(UUID player) {
this.player = player;
}

public UUID getNotificationPlayer() {
return notificationPlayer;
}

void setNotificationPlayer(UUID notificationPlayer) {
this.notificationPlayer = notificationPlayer;
}

public HitBox getHitBox() {
return hitBox;
}
Expand Down
Loading

0 comments on commit 40fdce3

Please sign in to comment.