Skip to content

Commit

Permalink
Add craft pilot signs
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerS1066 committed Aug 11, 2024
1 parent 8102b2a commit d28d72c
Showing 1 changed file with 39 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@
import io.github.eirikh1996.structureboxes.localisation.I18nSupport;
import io.github.eirikh1996.structureboxes.utils.MovecraftUtils;
import net.countercraft.movecraft.MovecraftLocation;
import net.countercraft.movecraft.craft.Craft;
import net.countercraft.movecraft.craft.PilotedCraft;
import net.countercraft.movecraft.events.CraftDetectEvent;
import net.countercraft.movecraft.events.CraftRotateEvent;
import net.countercraft.movecraft.events.CraftSinkEvent;
import net.countercraft.movecraft.events.CraftTranslateEvent;
import net.countercraft.movecraft.events.*;
import net.countercraft.movecraft.processing.MovecraftWorld;
import net.countercraft.movecraft.util.hitboxes.HitBox;
import org.bukkit.ChatColor;
import org.bukkit.Tag;
import org.bukkit.block.BlockState;
import org.bukkit.block.Sign;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.jetbrains.annotations.NotNull;

import static io.github.eirikh1996.structureboxes.utils.ChatUtils.COMMAND_PREFIX;

Expand All @@ -34,6 +38,37 @@ public void onCraftDetect(CraftDetectEvent event) {
}
}

@EventHandler
public void onCraftPilot(@NotNull CraftPilotEvent e) {
Craft craft = e.getCraft();
MovecraftWorld world = e.getCraft().getMovecraftWorld();
for (MovecraftLocation ml : craft.getHitBox()) {
if (!Tag.SIGNS.isTagged(world.getMaterial(ml)))
continue;

BlockState state = world.getState(ml);
if (!(state instanceof Sign sign))
continue;

if (ChatColor.stripColor(sign.getLine(0)).equalsIgnoreCase("<<Private>>")) {
sign.setLine(0, "[Private]");
if (craft instanceof PilotedCraft pilotedCraft)
sign.setLine(1, pilotedCraft.getPilot().getName());
sign.update();
}
else if (ChatColor.stripColor(sign.getLine(0)).equalsIgnoreCase("<<More Users>>")) {
sign.setLine(0, "[More Users]");
sign.update();
}
else if (ChatColor.stripColor(sign.getLine(0)).equalsIgnoreCase("<<Pilot>>")) {
sign.setLine(0, "Pilot:");
if (craft instanceof PilotedCraft pilotedCraft)
sign.setLine(1, pilotedCraft.getPilot().getName());
sign.update();
}
}
}

@EventHandler
public void onCraftTranslate(CraftTranslateEvent event) {
if (!(event.getCraft() instanceof PilotedCraft))
Expand Down

0 comments on commit d28d72c

Please sign in to comment.