use of net.countercraft.movecraft.craft.Craft in project Movecraft by APDevTeam.
the class DescendSign method onSignClick.
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onSignClick(@NotNull PlayerInteractEvent event) {
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
return;
}
BlockState state = event.getClickedBlock().getState();
if (!(state instanceof Sign)) {
return;
}
Sign sign = (Sign) state;
if (ChatColor.stripColor(sign.getLine(0)).equalsIgnoreCase("Descend: OFF")) {
if (CraftManager.getInstance().getCraftByPlayer(event.getPlayer()) == null) {
return;
}
Craft c = CraftManager.getInstance().getCraftByPlayer(event.getPlayer());
if (!c.getType().getBoolProperty(CraftType.CAN_CRUISE)) {
return;
}
// c.resetSigns(true, true, false);
sign.setLine(0, "Descend: ON");
sign.update(true);
c.setCruiseDirection(CruiseDirection.DOWN);
c.setLastCruiseUpdate(System.currentTimeMillis());
c.setCruising(true);
c.resetSigns(sign);
if (!c.getType().getBoolProperty(CraftType.MOVE_ENTITIES)) {
CraftManager.getInstance().addReleaseTask(c);
}
return;
}
if (ChatColor.stripColor(sign.getLine(0)).equalsIgnoreCase("Descend: ON")) {
Craft c = CraftManager.getInstance().getCraftByPlayer(event.getPlayer());
if (c != null && c.getType().getBoolProperty(CraftType.CAN_CRUISE)) {
sign.setLine(0, "Descend: OFF");
sign.update(true);
c.setCruising(false);
c.resetSigns(sign);
}
}
}
use of net.countercraft.movecraft.craft.Craft in project Movecraft by APDevTeam.
the class HelmSign method onSignClick.
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onSignClick(@NotNull PlayerInteractEvent event) {
MovecraftRotation rotation;
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
rotation = MovecraftRotation.CLOCKWISE;
} else if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
rotation = MovecraftRotation.ANTICLOCKWISE;
} else {
return;
}
BlockState state = event.getClickedBlock().getState();
if (!(state instanceof Sign)) {
return;
}
Sign sign = (Sign) state;
if (!(ChatColor.stripColor(sign.getLine(0)).equals("\\ || /") && ChatColor.stripColor(sign.getLine(1)).equals("== ==") && ChatColor.stripColor(sign.getLine(2)).equals("/ || \\"))) {
return;
}
Craft craft = CraftManager.getInstance().getCraftByPlayer(event.getPlayer());
if (craft == null) {
return;
}
if (!event.getPlayer().hasPermission("movecraft." + craft.getType().getStringProperty(CraftType.NAME) + ".rotate")) {
event.getPlayer().sendMessage(I18nSupport.getInternationalisedString("Insufficient Permissions"));
return;
}
if (!MathUtils.locIsNearCraftFast(craft, MathUtils.bukkit2MovecraftLoc(event.getPlayer().getLocation())))
return;
if (craft.getType().getBoolProperty(CraftType.ROTATE_AT_MIDPOINT)) {
CraftManager.getInstance().getCraftByPlayer(event.getPlayer()).rotate(rotation, craft.getHitBox().getMidPoint());
} else {
CraftManager.getInstance().getCraftByPlayer(event.getPlayer()).rotate(rotation, MathUtils.bukkit2MovecraftLoc(sign.getLocation()));
}
// timeMap.put(event.getPlayer(), System.currentTimeMillis());
event.setCancelled(true);
// TODO: Lower speed while turning
/*int curTickCooldown = CraftManager.getInstance().getCraftByPlayer(event.getPlayer()).getCurTickCooldown();
int baseTickCooldown = CraftManager.getInstance().getCraftByPlayer(event.getPlayer()).getType().getCruiseTickCooldown();
if (curTickCooldown * 2 > baseTickCooldown)
curTickCooldown = baseTickCooldown;
else
curTickCooldown = curTickCooldown * 2;*/
// CraftManager.getInstance().getCraftByPlayer(event.getPlayer()).setCurTickCooldown(curTickCooldown); // lose half your speed when turning
}
use of net.countercraft.movecraft.craft.Craft in project Movecraft by APDevTeam.
the class ReleaseSign method onSignClick.
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onSignClick(@NotNull PlayerInteractEvent event) {
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
return;
}
BlockState state = event.getClickedBlock().getState();
if (!(state instanceof Sign)) {
return;
}
Sign sign = (Sign) state;
if (!ChatColor.stripColor(sign.getLine(0)).equalsIgnoreCase(HEADER)) {
return;
}
Craft craft = CraftManager.getInstance().getCraftByPlayer(event.getPlayer());
if (craft == null) {
return;
}
CraftManager.getInstance().release(craft, CraftReleaseEvent.Reason.PLAYER, false);
}
use of net.countercraft.movecraft.craft.Craft in project Movecraft by APDevTeam.
the class BlockListener method onRedstoneEvent.
// process certain redstone on cruising crafts
@EventHandler(priority = EventPriority.HIGHEST)
public void onRedstoneEvent(BlockRedstoneEvent event) {
Block block = event.getBlock();
CraftManager.getInstance().getCraftsInWorld(block.getWorld());
for (Craft tcraft : CraftManager.getInstance().getCraftsInWorld(block.getWorld())) {
MovecraftLocation mloc = new MovecraftLocation(block.getX(), block.getY(), block.getZ());
if (MathUtils.locIsNearCraftFast(tcraft, mloc) && tcraft.getCruising() && (block.getType() == Material.STICKY_PISTON || block.getType() == Material.PISTON || block.getType() == Material.DISPENSER && !tcraft.isNotProcessing())) {
// don't allow piston movement on cruising crafts
event.setNewCurrent(event.getOldCurrent());
return;
}
}
}
use of net.countercraft.movecraft.craft.Craft in project Movecraft by APDevTeam.
the class BlockListener method onIceForm.
@EventHandler
public void onIceForm(BlockFormEvent e) {
if (e.isCancelled() || !Settings.DisableIceForm)
return;
if (e.getBlock().getType() != Material.WATER)
return;
MovecraftLocation loc = MathUtils.bukkit2MovecraftLoc(e.getBlock().getLocation());
Craft craft = MathUtils.fastNearestCraftToLoc(CraftManager.getInstance().getCrafts(), e.getBlock().getLocation());
if (craft != null && craft.getHitBox().contains((loc)))
e.setCancelled(true);
}
Aggregations