use of net.countercraft.movecraft.MovecraftLocation in project Movecraft by APDevTeam.
the class CraftRotateCommand method sendSignEvents.
private void sendSignEvents() {
Object2ObjectMap<String[], List<MovecraftLocation>> signs = new Object2ObjectOpenCustomHashMap<>(new Hash.Strategy<String[]>() {
@Override
public int hashCode(String[] strings) {
return Arrays.hashCode(strings);
}
@Override
public boolean equals(String[] a, String[] b) {
return Arrays.equals(a, b);
}
});
Map<MovecraftLocation, Sign> signStates = new HashMap<>();
for (MovecraftLocation location : craft.getHitBox()) {
Block block = location.toBukkit(craft.getWorld()).getBlock();
BlockState state = block.getState();
if (state instanceof Sign) {
Sign sign = (Sign) block.getState();
if (!signs.containsKey(sign.getLines()))
signs.put(sign.getLines(), new ArrayList<>());
signs.get(sign.getLines()).add(location);
signStates.put(location, sign);
}
}
for (Map.Entry<String[], List<MovecraftLocation>> entry : signs.entrySet()) {
SignTranslateEvent event = new SignTranslateEvent(craft, entry.getKey(), entry.getValue());
Bukkit.getServer().getPluginManager().callEvent(event);
if (!event.isUpdated()) {
continue;
}
for (MovecraftLocation location : entry.getValue()) {
Block block = location.toBukkit(craft.getWorld()).getBlock();
BlockState state = block.getState();
BlockData data = block.getBlockData();
if (!(state instanceof Sign)) {
continue;
}
Sign sign = signStates.get(location);
for (int i = 0; i < 4; i++) {
sign.setLine(i, entry.getKey()[i]);
}
sign.update(false, false);
block.setBlockData(data);
}
}
}
use of net.countercraft.movecraft.MovecraftLocation in project Movecraft by APDevTeam.
the class CraftTranslateCommand method sendSignEvents.
private void sendSignEvents() {
Object2ObjectMap<String[], List<MovecraftLocation>> signs = new Object2ObjectOpenCustomHashMap<>(new Hash.Strategy<String[]>() {
@Override
public int hashCode(String[] strings) {
return Arrays.hashCode(strings);
}
@Override
public boolean equals(String[] a, String[] b) {
return Arrays.equals(a, b);
}
});
Map<MovecraftLocation, Sign> signStates = new HashMap<>();
for (MovecraftLocation location : craft.getHitBox()) {
Block block = location.toBukkit(craft.getWorld()).getBlock();
if (!Tag.SIGNS.isTagged(block.getType())) {
continue;
}
BlockState state = block.getState();
if (state instanceof Sign) {
Sign sign = (Sign) state;
if (!signs.containsKey(sign.getLines()))
signs.put(sign.getLines(), new ArrayList<>());
signs.get(sign.getLines()).add(location);
signStates.put(location, sign);
}
}
for (Map.Entry<String[], List<MovecraftLocation>> entry : signs.entrySet()) {
SignTranslateEvent event = new SignTranslateEvent(craft, entry.getKey(), entry.getValue());
Bukkit.getServer().getPluginManager().callEvent(event);
if (!event.isUpdated()) {
continue;
}
for (MovecraftLocation location : entry.getValue()) {
Block block = location.toBukkit(craft.getWorld()).getBlock();
BlockState state = block.getState();
if (!(state instanceof Sign)) {
continue;
}
Sign sign = signStates.get(location);
for (int i = 0; i < 4; i++) {
sign.setLine(i, entry.getKey()[i]);
}
sign.update(false, false);
}
}
}
use of net.countercraft.movecraft.MovecraftLocation in project Movecraft by APDevTeam.
the class HoverValidator method validate.
@Override
@Contract(pure = true)
@NotNull
public Result validate(@NotNull MovecraftLocation translation, @NotNull MovecraftWorld world, @NotNull HitBox hitBox, @NotNull CraftType type) {
if (type.getMaterialSetProperty(CraftType.FORBIDDEN_HOVER_OVER_BLOCKS).size() > 0) {
MovecraftLocation test = new MovecraftLocation(hitBox.getMidPoint().getX(), hitBox.getMinY(), hitBox.getMidPoint().getZ());
test = test.translate(0, -1, 0);
while (world.getMaterial(test).isAir()) {
test = test.translate(0, -1, 0);
}
Material testType = world.getMaterial(test);
if (type.getMaterialSetProperty(CraftType.FORBIDDEN_HOVER_OVER_BLOCKS).contains(testType)) {
return Result.failWithMessage(String.format(I18nSupport.getInternationalisedString("Translation - Failed Craft over block"), testType.name().toLowerCase().replace("_", " ")));
}
}
return Result.succeed();
}
use of net.countercraft.movecraft.MovecraftLocation in project Movecraft by APDevTeam.
the class AscendSign method onCraftDetect.
@EventHandler
public void onCraftDetect(CraftDetectEvent event) {
World world = event.getCraft().getWorld();
for (MovecraftLocation location : event.getCraft().getHitBox()) {
var block = location.toBukkit(world).getBlock();
if (!Tag.SIGNS.isTagged(block.getType())) {
continue;
}
BlockState state = block.getState();
if (block.getState() instanceof Sign) {
Sign sign = (Sign) block.getState();
if (ChatColor.stripColor(sign.getLine(0)).equalsIgnoreCase("Ascend: ON")) {
sign.setLine(0, "Ascend: OFF");
sign.update();
}
}
}
}
use of net.countercraft.movecraft.MovecraftLocation in project Movecraft by APDevTeam.
the class ContactsSign method onSignTranslateEvent.
@EventHandler
public final void onSignTranslateEvent(SignTranslateEvent event) {
String[] lines = event.getLines();
Craft craft = event.getCraft();
if (!ChatColor.stripColor(lines[0]).equalsIgnoreCase("Contacts:")) {
return;
}
int signLine = 1;
for (Craft tcraft : craft.getContacts()) {
MovecraftLocation center = craft.getHitBox().getMidPoint();
MovecraftLocation tcenter = tcraft.getHitBox().getMidPoint();
int distsquared = center.distanceSquared(tcenter);
// craft has been detected
String notification = ChatColor.BLUE + tcraft.getType().getStringProperty(CraftType.NAME);
if (notification.length() > 9) {
notification = notification.substring(0, 7);
}
notification += " " + (int) Math.sqrt(distsquared);
int diffx = center.getX() - tcenter.getX();
int diffz = center.getZ() - tcenter.getZ();
if (Math.abs(diffx) > Math.abs(diffz)) {
if (diffx < 0) {
notification += " E";
} else {
notification += " W";
}
} else {
if (diffz < 0) {
notification += " S";
} else {
notification += " N";
}
}
lines[signLine++] = notification;
if (signLine >= 4) {
break;
}
}
if (signLine < 4) {
for (int i = signLine; i < 4; i++) {
lines[signLine] = "";
}
}
}
Aggregations