use of io.github.thebusybiscuit.slimefun4.core.handlers.BlockDispenseHandler 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.BlockDispenseHandler 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.BlockDispenseHandler in project MissileWarfare by koiboi-dev.
the class AntiElytraLauncher 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.createantielytra.success"));
} else {
event.getPlayer().sendMessage(Translations.get("messages.launchers.createantielytra.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();
Player locked = null;
if (!block.isBlockPowered()) {
Collection<? extends Player> missiles = MissileWarfare.getInstance().getServer().getOnlinePlayers();
if (!missiles.isEmpty()) {
for (Player player : missiles) {
if (block.getLocation().distanceSquared(player.getLocation()) < range) {
if (player.isGliding() && !PlayerID.targets.contains(player)) {
List<OfflinePlayer> ignore = PlayerID.players.get(cont.get(new NamespacedKey(MissileWarfare.getInstance(), "groupid"), PersistentDataType.STRING));
if (ignore == null) {
locked = player;
break;
} else if (ignore.contains(player)) {
locked = player;
break;
}
}
}
}
}
state.update();
if (locked != null) {
UUID playerUUID = locked.getUniqueId();
PlayerID.targets.add(MissileWarfare.getInstance().getServer().getPlayer(playerUUID));
Player finalLocked = locked;
finalLocked.spigot().sendMessage(ChatMessageType.ACTION_BAR, new ComponentBuilder(Translations.get("messages.elytraattack.locking")).color(ChatColor.RED).create());
new BukkitRunnable() {
@Override
public void run() {
Player player = MissileWarfare.getInstance().getServer().getPlayer(playerUUID);
if (player == null) {
PlayerID.targets = new ArrayList<>();
return;
}
if (player.isGliding()) {
finalLocked.spigot().sendMessage(ChatMessageType.ACTION_BAR, new ComponentBuilder(Translations.get("messages.elytraattack.locked")).color(ChatColor.DARK_RED).create());
fireMissile((Dispenser) block.getState(), MissileWarfare.getInstance().getServer().getPlayer(playerUUID));
} else if (player.isInsideVehicle()) {
if (!player.getVehicle().isOnGround()) {
finalLocked.spigot().sendMessage(ChatMessageType.ACTION_BAR, new ComponentBuilder(Translations.get("messages.elytraattack.locked")).color(ChatColor.DARK_RED).create());
fireMissile((Dispenser) block.getState(), MissileWarfare.getInstance().getServer().getPlayer(playerUUID));
}
}
}
}.runTaskLater(MissileWarfare.getInstance(), 80);
}
}
}
});
BlockUseHandler blockUseHandler = this::onBlockRightClick;
addItemHandler(blockUseHandler);
}
Aggregations