use of net.countercraft.movecraft.events.SignTranslateEvent 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.events.SignTranslateEvent 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);
}
}
}
Aggregations