use of io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler in project MissileWarfare by koiboi-dev.
the class AntiMissileLauncher method preRegister.
@Override
public void preRegister() {
// cancel thing on place
BlockPlaceHandler blockPlaceHandler = new BlockPlaceHandler(false) {
@Override
public void onPlayerPlace(BlockPlaceEvent event) {
BlockData data = event.getBlockPlaced().getBlockData();
((Directional) data).setFacing(BlockFace.UP);
event.getBlockPlaced().setBlockData(data);
Block block = event.getBlockPlaced();
// Block bottom = world.getBlockAt(event.getBlock().getLocation().subtract(new Vector(0, 2, 0)));
if (correctlyBuilt(block)) {
event.getPlayer().sendMessage(Translations.get("messages.launchers.createantiair.success"));
} else {
event.getPlayer().sendMessage(Translations.get("messages.launchers.createantiair.failure"));
}
}
};
addItemHandler(blockPlaceHandler);
BlockDispenseHandler blockDispenseHandler = this::blockDispense;
addItemHandler(blockDispenseHandler);
addItemHandler(new BlockTicker() {
@Override
public boolean isSynchronized() {
return true;
}
@Override
public void tick(Block block, SlimefunItem slimefunItem, Config config) {
TileState state = (TileState) block.getState();
PersistentDataContainer cont = state.getPersistentDataContainer();
if (!block.isBlockPowered()) {
List<MissileController> missiles = MissileWarfare.activemissiles;
MissileController locked = null;
if (!missiles.isEmpty()) {
for (MissileController missile : missiles) {
if (block.getLocation().distanceSquared(missile.pos.toLocation(missile.world)) < range && missile.isgroundmissile) {
locked = missile;
break;
}
}
}
state.update();
try {
if (locked != null && cont.get(new NamespacedKey(MissileWarfare.getInstance(), "timesincelastshot"), PersistentDataType.INTEGER) <= System.currentTimeMillis()) {
cont.set(new NamespacedKey(MissileWarfare.getInstance(), "timesincelastshot"), PersistentDataType.INTEGER, (int) System.currentTimeMillis() + 1000);
fireMissile((Dispenser) block.getState(), locked);
}
} catch (NullPointerException e) {
cont.set(new NamespacedKey(MissileWarfare.getInstance(), "timesincelastshot"), PersistentDataType.INTEGER, Integer.MIN_VALUE);
state.update();
}
}
}
});
}
use of io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler in project MissileWarfare by koiboi-dev.
the class GroundMissileLauncher method preRegister.
@Override
public void preRegister() {
// cancel thing on place
BlockPlaceHandler blockPlaceHandler = new BlockPlaceHandler(false) {
@Override
public void onPlayerPlace(BlockPlaceEvent event) {
World world = event.getBlock().getWorld();
Block below = world.getBlockAt(event.getBlock().getLocation().subtract(new Vector(0, 1, 0)));
BlockData data = event.getBlockPlaced().getBlockData();
((Directional) data).setFacing(BlockFace.UP);
event.getBlockPlaced().setBlockData(data);
// Block bottom = world.getBlockAt(event.getBlock().getLocation().subtract(new Vector(0, 2, 0)));
if (below.getType() == Material.GREEN_CONCRETE) {
event.getPlayer().sendMessage(Translations.get("messages.launchers.ground.create.success"));
TileState state = (TileState) event.getBlockPlaced().getState();
PersistentDataContainer cont = state.getPersistentDataContainer();
cont.set(new NamespacedKey(MissileWarfare.getInstance(), "canfire"), PersistentDataType.INTEGER, 1);
state.update();
/*if (bottom.getType() == Material.GREEN_CONCRETE){
event.getPlayer().sendMessage("Created Small Launcher!");
}else{
event.getPlayer().sendMessage("Bottom Block is type: " + bottom.getType() + " It needs Type GREEN_CONCRETE");
event.setCancelled(true);
}*/
} else {
event.getPlayer().sendMessage(Translations.get("messages.launchers.ground.create.failure").replace("{type}", below.getType().name()));
}
}
};
addItemHandler(blockPlaceHandler);
BlockUseHandler blockUseHandler = this::onBlockRightClick;
addItemHandler(blockUseHandler);
BlockDispenseHandler blockDispenseHandler = this::blockDispense;
addItemHandler(blockDispenseHandler);
}
use of io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler in project Slimefun4 by Slimefun.
the class ElevatorPlate method onPlace.
@Nonnull
private BlockPlaceHandler onPlace() {
return new BlockPlaceHandler(false) {
@Override
public void onPlayerPlace(BlockPlaceEvent e) {
Block b = e.getBlock();
BlockStorage.addBlockInfo(b, DATA_KEY, ChatColor.WHITE + "Floor #0");
BlockStorage.addBlockInfo(b, "owner", e.getPlayer().getUniqueId().toString());
}
};
}
use of io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler in project Slimefun4 by Slimefun.
the class HologramProjector method onPlace.
@Nonnull
private BlockPlaceHandler onPlace() {
return new BlockPlaceHandler(false) {
@Override
public void onPlayerPlace(BlockPlaceEvent e) {
Block b = e.getBlockPlaced();
BlockStorage.addBlockInfo(b, "text", "Edit me via the Projector");
BlockStorage.addBlockInfo(b, OFFSET_PARAMETER, "0.5");
BlockStorage.addBlockInfo(b, "owner", e.getPlayer().getUniqueId().toString());
getArmorStand(b, true);
}
};
}
use of io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler in project Slimefun4 by Slimefun.
the class BlockPlacer method onPlace.
@Nonnull
private BlockPlaceHandler onPlace() {
return new BlockPlaceHandler(false) {
@Override
public void onPlayerPlace(BlockPlaceEvent e) {
Player p = e.getPlayer();
Block b = e.getBlock();
BlockStorage.addBlockInfo(b, "owner", p.getUniqueId().toString());
}
};
}
Aggregations