Skip to content
Permalink
Browse files

Update for vector refactor

  • Loading branch information...
me4502 committed Nov 4, 2018
1 parent 3ef008a commit 682c8355fcbfaa1dbc36b222379ad2ac7fa070fd
Showing with 161 additions and 158 deletions.
  1. +1 −0 build.gradle
  2. +14 −16 src/main/java/com/sk89q/craftbook/bukkit/util/CraftBookBukkitUtil.java
  3. +15 −8 src/main/java/com/sk89q/craftbook/mechanics/XPStorer.java
  4. +4 −4 src/main/java/com/sk89q/craftbook/mechanics/area/AreaCommands.java
  5. +3 −3 src/main/java/com/sk89q/craftbook/mechanics/area/simple/Bridge.java
  6. +3 −3 src/main/java/com/sk89q/craftbook/mechanics/area/simple/CuboidToggleMechanic.java
  7. +3 −3 src/main/java/com/sk89q/craftbook/mechanics/area/simple/Door.java
  8. +5 −5 src/main/java/com/sk89q/craftbook/mechanics/area/simple/Gate.java
  9. +2 −2 src/main/java/com/sk89q/craftbook/mechanics/ic/gates/world/blocks/BlockBreaker.java
  10. +2 −2 src/main/java/com/sk89q/craftbook/mechanics/ic/gates/world/blocks/CombineHarvester.java
  11. +2 −2 src/main/java/com/sk89q/craftbook/mechanics/ic/gates/world/blocks/Driller.java
  12. +3 −3 src/main/java/com/sk89q/craftbook/mechanics/ic/gates/world/blocks/LiquidFlood.java
  13. +12 −13 src/main/java/com/sk89q/craftbook/mechanics/ic/gates/world/blocks/Spigot.java
  14. +5 −5 src/main/java/com/sk89q/craftbook/mechanics/ic/gates/world/items/RangedCollector.java
  15. +9 −10 src/main/java/com/sk89q/craftbook/mechanics/ic/gates/world/miscellaneous/LightningSummon.java
  16. +13 −14 src/main/java/com/sk89q/craftbook/mechanics/ic/gates/world/miscellaneous/SentryGun.java
  17. +11 −12 src/main/java/com/sk89q/craftbook/mechanics/ic/gates/world/sensors/MovementSensor.java
  18. +3 −4 src/main/java/com/sk89q/craftbook/util/DistanceComparator.java
  19. +18 −21 src/main/java/com/sk89q/craftbook/util/ICUtil.java
  20. +10 −12 src/main/java/com/sk89q/craftbook/util/LocationUtil.java
  21. +23 −16 src/main/java/com/sk89q/craftbook/util/SearchArea.java
@@ -96,6 +96,7 @@ allprojects {
compile 'com.destroystokyo.paper:paper-api:1.13.1-R0.1-SNAPSHOT'
compile 'com.sk89q.worldedit:worldedit-core:7.0.0-SNAPSHOT'
compile 'com.sk89q.worldedit:worldedit-bukkit:7.0.0-SNAPSHOT'
compile 'com.sk89q.worldguard:worldguard-core:7.0.0-SNAPSHOT'
compile 'com.sk89q.worldguard:worldguard-legacy:7.0.0-SNAPSHOT'
compile 'com.sk89q:squirrelid:0.1.0'
compile 'net.milkbowl.vault:VaultAPI:1.6'
@@ -3,8 +3,9 @@
import com.sk89q.craftbook.ChangedSign;
import com.sk89q.craftbook.CraftBookPlayer;
import com.sk89q.craftbook.bukkit.CraftBookPlugin;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.util.Location;
import org.bukkit.Material;
import org.bukkit.Tag;
@@ -13,6 +14,7 @@
import org.bukkit.block.BlockFace;
import org.bukkit.block.Sign;

import java.util.EnumSet;
import java.util.HashSet;
import java.util.Set;

@@ -63,28 +65,23 @@ public static Sign toSign(ChangedSign sign) {
}
}

public static Vector toVector(Block block) {

return new Vector(block.getX(), block.getY(), block.getZ());
public static BlockVector3 toVector(Block block) {
return BlockVector3.at(block.getX(), block.getY(), block.getZ());
}

public static Vector toVector(BlockFace face) {

return new Vector(face.getModX(), face.getModY(), face.getModZ());
public static BlockVector3 toVector(BlockFace face) {
return BlockVector3.at(face.getModX(), face.getModY(), face.getModZ());
}

public static Vector toVector(org.bukkit.Location loc) {

return new Vector(loc.getX(), loc.getY(), loc.getZ());
public static Vector3 toVector(org.bukkit.Location loc) {
return Vector3.at(loc.getX(), loc.getY(), loc.getZ());
}

public static Vector toVector(org.bukkit.util.Vector vector) {

return new Vector(vector.getX(), vector.getY(), vector.getZ());
public static Vector3 toVector(org.bukkit.util.Vector vector) {
return Vector3.at(vector.getX(), vector.getY(), vector.getZ());
}

public static org.bukkit.Location toLocation(World world, Vector pt) {

public static org.bukkit.Location toLocation(World world, Vector3 pt) {
return new org.bukkit.Location(world, pt.getX(), pt.getY(), pt.getZ());
}

@@ -121,7 +118,7 @@ public static World toWorld(final com.sk89q.worldedit.world.World world) {
return ((BukkitWorld) world).getWorld();
}

private static final Set<Material> isRedstoneBlock = new HashSet<>();
private static Set<Material> isRedstoneBlock = new HashSet<>();
static {
isRedstoneBlock.add(Material.POWERED_RAIL);
isRedstoneBlock.add(Material.DETECTOR_RAIL);
@@ -150,6 +147,7 @@ public static World toWorld(final com.sk89q.worldedit.world.World world) {
isRedstoneBlock.add(Material.ACTIVATOR_RAIL);
isRedstoneBlock.add(Material.DROPPER);
isRedstoneBlock.add(Material.DAYLIGHT_DETECTOR);
isRedstoneBlock = EnumSet.copyOf(isRedstoneBlock);
}

/**
@@ -1,20 +1,31 @@
package com.sk89q.craftbook.mechanics;

import com.sk89q.craftbook.AbstractCraftBookMechanic;
import com.sk89q.craftbook.ChangedSign;
import com.sk89q.craftbook.CraftBookPlayer;
import com.sk89q.craftbook.bukkit.CraftBookPlugin;
import com.sk89q.craftbook.bukkit.util.CraftBookBukkitUtil;
import com.sk89q.craftbook.util.*;
import com.sk89q.craftbook.util.BlockSyntax;
import com.sk89q.craftbook.util.EventUtil;
import com.sk89q.craftbook.util.InventoryUtil;
import com.sk89q.craftbook.util.ItemUtil;
import com.sk89q.craftbook.util.LocationUtil;
import com.sk89q.craftbook.util.ProtectionUtil;
import com.sk89q.craftbook.util.SignUtil;
import com.sk89q.craftbook.util.TernaryState;
import com.sk89q.craftbook.util.events.SelfTriggerPingEvent;
import com.sk89q.craftbook.util.events.SelfTriggerThinkEvent;
import com.sk89q.worldedit.Vector;
import com.sk89q.util.yaml.YAMLProcessor;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.item.ItemTypes;
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.*;
import org.bukkit.entity.Entity;
import org.bukkit.entity.ExperienceOrb;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.Action;
@@ -25,10 +36,6 @@
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;

import com.sk89q.craftbook.AbstractCraftBookMechanic;
import com.sk89q.craftbook.bukkit.CraftBookPlugin;
import com.sk89q.util.yaml.YAMLProcessor;

import java.util.ArrayList;
import java.util.List;

@@ -217,7 +224,7 @@ public void onThink(SelfTriggerThinkEvent event) {

List<ExperienceOrb> orbs = new ArrayList<>();

for (Entity entity : LocationUtil.getNearbyEntities(SignUtil.getBackBlock(event.getBlock()).getLocation(), new Vector(signRadius,signRadius,signRadius))) {
for (Entity entity : LocationUtil.getNearbyEntities(SignUtil.getBackBlock(event.getBlock()).getLocation(), Vector3.at(signRadius, signRadius, signRadius))) {
if (entity instanceof ExperienceOrb && entity.getTicksLived() > 20) {
xp += ((ExperienceOrb) entity).getExperience();
orbs.add((ExperienceOrb) entity);
@@ -11,11 +11,11 @@
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.minecraft.util.commands.CommandPermissionsException;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@@ -82,9 +82,9 @@ public void saveArea(CommandContext context, CommandSender sender) throws Comman
sender.sendMessage(ChatColor.RED + "You have not made a selection!");
return;
}
Vector min = sel.getMinimumPoint();
Vector max = sel.getMaximumPoint();
Vector size = max.subtract(min).add(1, 1, 1);
BlockVector3 min = sel.getMinimumPoint();
BlockVector3 max = sel.getMaximumPoint();
BlockVector3 size = max.subtract(min).add(1, 1, 1);

// Check maximum size
if (Area.instance.maxAreaSize != -1 && size.getBlockX() * size.getBlockY() * size.getBlockZ()
@@ -29,8 +29,8 @@
import com.sk89q.craftbook.util.events.SourcedBlockRedstoneEvent;
import com.sk89q.craftbook.util.exceptions.InvalidMechanismException;
import com.sk89q.util.yaml.YAMLProcessor;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.world.block.BlockCategories;
import com.sk89q.worldedit.world.block.BlockStateHolder;
@@ -237,14 +237,14 @@ public CuboidRegion getCuboidArea(Block trigger, Block proximalBaseCenter, Block
for (int i = 0; i < left; i++) {
if(!BlockUtil.areBlocksIdentical(distalBaseCenter.getRelative(SignUtil.getLeft(trigger), i), proximalBaseCenter.getRelative(SignUtil.getLeft(trigger), i)))
throw new InvalidMechanismException("mech.bridge.material");
toggle.expand(CraftBookBukkitUtil.toVector(SignUtil.getLeft(trigger)), new Vector(0, 0, 0));
toggle.expand(CraftBookBukkitUtil.toVector(SignUtil.getLeft(trigger)), BlockVector3.ZERO);
}

// Expand Right
for (int i = 0; i < right; i++) {
if(!BlockUtil.areBlocksIdentical(distalBaseCenter.getRelative(SignUtil.getRight(trigger), i), proximalBaseCenter.getRelative(SignUtil.getRight(trigger), i)))
throw new InvalidMechanismException("mech.bridge.material");
toggle.expand(CraftBookBukkitUtil.toVector(SignUtil.getRight(trigger)), new Vector(0, 0, 0));
toggle.expand(CraftBookBukkitUtil.toVector(SignUtil.getRight(trigger)), BlockVector3.ZERO);
}

// Don't toggle the end points
@@ -14,8 +14,8 @@
import com.sk89q.craftbook.util.SignUtil;
import com.sk89q.craftbook.util.exceptions.InvalidMechanismException;
import com.sk89q.util.yaml.YAMLProcessor;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion;
import org.bukkit.Material;
import org.bukkit.block.Block;
@@ -45,7 +45,7 @@ public static boolean open(Block sign, Block farSide, BlockData type, CuboidRegi

ChangedSign s = CraftBookBukkitUtil.toChangedSign(sign);
ChangedSign other = CraftBookBukkitUtil.toChangedSign(farSide);
for (Vector bv : toggle) {
for (BlockVector3 bv : toggle) {
Block b = sign.getWorld().getBlockAt(bv.getBlockX(), bv.getBlockY(), bv.getBlockZ());
if (b.getType() == type.getMaterial() || BlockUtil.isBlockReplacable(b.getType())) {
if (CraftBookPlugin.inst().getConfiguration().safeDestruction && (b.getType() == type.getMaterial()))
@@ -61,7 +61,7 @@ public static boolean close(Block sign, Block farSide, BlockData data, CuboidReg

ChangedSign s = CraftBookBukkitUtil.toChangedSign(sign);
ChangedSign other = CraftBookBukkitUtil.toChangedSign(farSide);
for (Vector bv : toggle) {
for (BlockVector3 bv : toggle) {
Block b = sign.getWorld().getBlockAt(bv.getBlockX(), bv.getBlockY(), bv.getBlockZ());
if (BlockUtil.isBlockReplacable(b.getType())) {
if (CraftBookPlugin.inst().getConfiguration().safeDestruction) {
@@ -29,8 +29,8 @@
import com.sk89q.craftbook.util.events.SourcedBlockRedstoneEvent;
import com.sk89q.craftbook.util.exceptions.InvalidMechanismException;
import com.sk89q.util.yaml.YAMLProcessor;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.world.block.BlockCategories;
import com.sk89q.worldedit.world.block.BlockStateHolder;
@@ -305,14 +305,14 @@ public CuboidRegion getCuboidArea(Block trigger, Block proximalBaseCenter, Block
for (int i = 0; i < left; i++) {
if(distalBaseCenter.getRelative(SignUtil.getLeft(trigger), i).getType() != proximalBaseCenter.getRelative(SignUtil.getLeft(trigger), i).getType())
throw new InvalidMechanismException("mech.door.material");
toggle.expand(CraftBookBukkitUtil.toVector(SignUtil.getLeft(trigger)), new Vector(0, 0, 0));
toggle.expand(CraftBookBukkitUtil.toVector(SignUtil.getLeft(trigger)), BlockVector3.ZERO);
}

// Expand Right
for (int i = 0; i < right; i++) {
if(distalBaseCenter.getRelative(SignUtil.getRight(trigger), i).getType() != proximalBaseCenter.getRelative(SignUtil.getRight(trigger), i).getType())
throw new InvalidMechanismException("mech.door.material");
toggle.expand(CraftBookBukkitUtil.toVector(SignUtil.getRight(trigger)), new Vector(0, 0, 0));
toggle.expand(CraftBookBukkitUtil.toVector(SignUtil.getRight(trigger)), BlockVector3.ZERO);
}

// Don't toggle the end points
@@ -29,9 +29,9 @@
import com.sk89q.craftbook.util.events.SignClickEvent;
import com.sk89q.craftbook.util.events.SourcedBlockRedstoneEvent;
import com.sk89q.util.yaml.YAMLProcessor;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.Blocks;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.world.block.BlockState;
@@ -181,8 +181,8 @@ private boolean toggleColumn(CraftBookPlayer player, ChangedSign sign, Block blo

CraftBookPlugin.logDebugMessage("Setting column at " + block.getX() + ':' + block.getY() + ':' + block.getZ() + " to " + item.toString(), "gates.search");

for (Vector bl : column.getRegion()) {
Block blo = CraftBookBukkitUtil.toLocation(block.getWorld(), bl).getBlock();
for (BlockVector3 bl : column.getRegion()) {
Block blo = CraftBookBukkitUtil.toLocation(block.getWorld(), bl.toVector3()).getBlock();

//sign = CraftBookBukkitUtil.toChangedSign(sign.getSign().getBlock());

@@ -655,8 +655,8 @@ public int getZ() {

public CuboidRegion getRegion() {
return new CuboidRegion(
BukkitAdapter.adapt(getStartingPoint().getRelative(0, -1, 0).getLocation()).toVector(),
BukkitAdapter.adapt(getEndingPoint().getLocation()).toVector()
BukkitAdapter.adapt(getStartingPoint().getRelative(0, -1, 0).getLocation()).toVector().toBlockPoint(),
BukkitAdapter.adapt(getEndingPoint().getLocation()).toVector().toBlockPoint()
);
}

@@ -14,9 +14,9 @@
import com.sk89q.craftbook.util.BlockUtil;
import com.sk89q.craftbook.util.ICUtil;
import com.sk89q.util.yaml.YAMLProcessor;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.Blocks;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypes;
import org.bukkit.Material;
@@ -86,7 +86,7 @@ public boolean breakBlock() {

if (!item.equalsFuzzy(BukkitAdapter.adapt(broken.getBlockData())))

ICUtil.collectItem(this, new Vector(0, 1, 0), BlockUtil.getBlockDrops(broken, null));
ICUtil.collectItem(this, BlockVector3.at(0, 1, 0), BlockUtil.getBlockDrops(broken, null));
broken.setType(Material.AIR);

return true;
@@ -11,7 +11,7 @@
import com.sk89q.craftbook.util.BlockUtil;
import com.sk89q.craftbook.util.ICUtil;
import com.sk89q.craftbook.util.SearchArea;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.math.BlockVector3;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.Tag;
@@ -67,7 +67,7 @@ public boolean harvest() {
if(b == null) return false;

if (harvestable(b)) {
ICUtil.collectItem(this, new Vector(0, 1, 0), BlockUtil.getBlockDrops(b, null));
ICUtil.collectItem(this, BlockVector3.at(0, 1, 0), BlockUtil.getBlockDrops(b, null));
b.setType(Material.AIR);
return true;
}
@@ -14,7 +14,7 @@
import com.sk89q.craftbook.util.ICUtil;
import com.sk89q.craftbook.util.InventoryUtil;
import com.sk89q.util.yaml.YAMLProcessor;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.math.BlockVector3;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.block.Block;
@@ -99,7 +99,7 @@ public boolean drillLine(ItemStack tool, Block blockToBreak) {
if (brokenType == Material.BEDROCK) return false;
}

ICUtil.collectItem(this, new Vector(0, 1, 0), BlockUtil.getBlockDrops(blockToBreak, tool));
ICUtil.collectItem(this, BlockVector3.at(0, 1, 0), BlockUtil.getBlockDrops(blockToBreak, tool));

brokenType = blockToBreak.getType();
blockToBreak.setType(Material.AIR);
@@ -9,15 +9,15 @@
import com.sk89q.craftbook.mechanics.ic.ICFactory;
import com.sk89q.craftbook.mechanics.ic.RestrictedIC;
import com.sk89q.craftbook.util.ICUtil;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.math.BlockVector3;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.block.Block;

public class LiquidFlood extends AbstractSelfTriggeredIC {

Vector radius;
BlockVector3 radius;
String liquid;
Location centre;

@@ -42,7 +42,7 @@ public String getSignTitle() {
public void load() {

centre = ICUtil.parseBlockLocation(getSign()).getLocation();
radius = ICUtil.parseRadius(getSign());
radius = ICUtil.parseRadius(getSign()).toBlockPoint();

liquid = getSign().getLine(2).equalsIgnoreCase("lava") ? "lava" : "water";
}

0 comments on commit 682c835

Please sign in to comment.
You can’t perform that action at this time.