Skip to content

Commit

Permalink
Fix errors and mc8 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
HumorousFool committed Jun 13, 2021
1 parent 74872b1 commit 5d2c087
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.github.humorousfool</groupId>
<artifactId>Movecraft-AutoSign</artifactId>
<version>1.2.0</version>
<version>1.2.1</version>
<packaging>jar</packaging>

<name>Movecraft-AutoSign</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import net.countercraft.movecraft.MovecraftLocation;
import net.countercraft.movecraft.craft.Craft;
import net.countercraft.movecraft.craft.PlayerCraft;
import net.countercraft.movecraft.events.CraftDetectEvent;
import net.countercraft.movecraft.events.CraftReleaseEvent;
import net.countercraft.movecraft.events.CraftRotateEvent;
import net.countercraft.movecraft.util.MathUtils;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.Sign;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
Expand Down Expand Up @@ -39,18 +41,19 @@ public void onEnable()
@EventHandler
public void onDetect(CraftDetectEvent event)
{
if(event.isCancelled() || event.getCraft().getNotificationPlayer() == null)
if(event.isCancelled() | !(event.getCraft() instanceof PlayerCraft))
return;
PlayerCraft craft = (PlayerCraft) event.getCraft();

List<SignData> signs = new ArrayList<>();

for(MovecraftLocation loc : event.getCraft().getHitBox())
{
Block block = event.getCraft().getW().getBlockAt(loc.getX(), loc.getY(), loc.getZ());
Block block = event.getCraft().getWorld().getBlockAt(loc.getX(), loc.getY(), loc.getZ());

if(block.getType().name().endsWith("SIGN"))
if(!block.getType().name().endsWith("SIGN") || !(block.getState() instanceof Sign))
continue;

//Why do I have to do this? I don't know but my server seems to think block.getState() refers to a CraftBlockState.
Sign sign = (Sign) block.getState();
String[] originalLines = sign.getLines().clone();
if(sign.getLine(0).toLowerCase().contains("place pilot"))
Expand All @@ -59,7 +62,7 @@ public void onDetect(CraftDetectEvent event)
continue;

sign.setLine(0, "Pilot:");
sign.setLine(1, event.getCraft().getNotificationPlayer().getName());
sign.setLine(1, craft.getPlayer().getName());
sign.update();
continue;
}
Expand All @@ -69,7 +72,7 @@ else if(sign.getLine(0).toLowerCase().contains("place crew"))
continue;

sign.setLine(0, "Crew:");
sign.setLine(1, event.getCraft().getNotificationPlayer().getName());
sign.setLine(1, craft.getPlayer().getName());
sign.update();
continue;
}
Expand All @@ -79,7 +82,7 @@ else if(sign.getLine(0).toLowerCase().contains("place private") || sign.getLine(
continue;

sign.setLine(0, "[Private]");
sign.setLine(1, event.getCraft().getNotificationPlayer().getName());
sign.setLine(1, craft.getPlayer().getName());
sign.update();
continue;
}
Expand All @@ -91,7 +94,7 @@ else if(sign.getLine(0).toLowerCase().contains("place private") || sign.getLine(
{
if(sign.getLine(i).equalsIgnoreCase("[Pilot]"))
{
sign.setLine(i, event.getCraft().getNotificationPlayer().getName());
sign.setLine(i, craft.getPlayer().getName());
sign.update();
MovecraftLocation relativeLocation = loc.subtract(event.getCraft().getHitBox().getMidPoint());
SignData data = new SignData(relativeLocation, originalLines);
Expand Down Expand Up @@ -126,9 +129,9 @@ public void onRelease(CraftReleaseEvent event)
for (SignData d : craftSigns.get(event.getCraft()))
{
MovecraftLocation mLoc = d.relativeLocation.add(event.getCraft().getHitBox().getMidPoint());
Block block = event.getCraft().getW().getBlockAt(mLoc.getX(), mLoc.getY(), mLoc.getZ());
Block block = event.getCraft().getWorld().getBlockAt(mLoc.getX(), mLoc.getY(), mLoc.getZ());

if(block.getType().name().endsWith("SIGN"))
if(!block.getType().name().endsWith("SIGN") || !(block.getState() instanceof Sign))
continue;

Sign sign = (Sign) block.getState();
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Movecraft-AutoSign
version: 1.0
version: 1.2.1
description: An extension for Movecraft that allows dynamic names on signs.
prefix: Movecraft-AutoSign
author: HumorousFool
Expand Down

0 comments on commit 5d2c087

Please sign in to comment.