Skip to content

Commit 5d4a495

Browse files
authored
Merge pull request #95 from Multiverse/fix-94
Fix: teleport Allays with redstone portals
2 parents fca61f5 + a713a9d commit 5d4a495

File tree

1 file changed

+58
-41
lines changed

1 file changed

+58
-41
lines changed

src/main/java/com/onarandombox/MultiverseSignPortals/utils/PortalDetector.java

Lines changed: 58 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232

3333
import java.util.ArrayList;
3434
import java.util.List;
35-
import java.util.logging.Level;
3635
import java.util.regex.Pattern;
3736

3837
public class PortalDetector {
@@ -199,26 +198,26 @@ public SignStatus getSignStatus(Sign sign) {
199198
return SignStatus.NotASignPortal;
200199
}
201200

202-
private final static int ALL = 0;
203-
private final static int PLAYERS = 1;
204-
private final static int MONSTERS = 2;
205-
private final static int ANIMALS = 3;
206-
207201
public Entity[] getRedstoneTeleportEntities(Sign sign) {
208202
if (REDSTONE_TELEPORT_PATTERN.matcher(sign.getLine(0)).matches()) {
209203
String line = ChatColor.stripColor(sign.getLine(0).replaceAll("(\\[|\\])", ""));
210204
String[] data = line.split(":");
211-
final int type;
212-
if (data[0].equals("ALL") || data[0].equals("all")) {
213-
type = ALL;
214-
} else if (data[0].equals("p") || data[0].equals("P")) {
215-
type = PLAYERS;
216-
} else if (data[0].equals("m") || data[0].equals("M")) {
217-
type = MONSTERS;
218-
} else if (data[0].equals("a") || data[0].equals("A")) {
219-
type = ANIMALS;
220-
} else {
221-
return new Entity[0];
205+
final RedstoneTeleportType type;
206+
switch (data[0].toUpperCase()) {
207+
case "ALL":
208+
type = RedstoneTeleportType.ALL;
209+
break;
210+
case "P":
211+
type = RedstoneTeleportType.PLAYERS;
212+
break;
213+
case "M":
214+
type = RedstoneTeleportType.MONSTERS;
215+
break;
216+
case "A":
217+
type = RedstoneTeleportType.ANIMALS;
218+
break;
219+
default:
220+
return new Entity[0];
222221
}
223222
final int radius;
224223
try {
@@ -227,38 +226,49 @@ public Entity[] getRedstoneTeleportEntities(Sign sign) {
227226
return new Entity[0];
228227
}
229228
int xOff = 0, yOff = 0, zOff = 0;
229+
// Get offset
230230
if (data.length > 2) {
231-
if (data[2].equals("north") || data[2].equals("NORTH")) {
232-
xOff = -radius;
233-
} else if (data[2].equals("south") || data[2].equals("SOUTH")) {
234-
xOff = radius;
235-
} else if (data[2].equals("east") || data[2].equals("EAST")) {
236-
zOff = -radius;
237-
} else if (data[2].equals("west") || data[2].equals("WEST")) {
238-
zOff = radius;
239-
} else if (data[2].equals("up") || data[2].equals("UP")) {
240-
yOff = radius;
241-
} else if (data[2].equals("down") || data[2].equals("DOWN")) {
242-
yOff = -radius;
231+
switch (data[2].toUpperCase()) {
232+
case "NORTH":
233+
xOff = -radius;
234+
break;
235+
case "SOUTH":
236+
xOff = radius;
237+
break;
238+
case "EAST":
239+
zOff = -radius;
240+
break;
241+
case "WEST":
242+
zOff = radius;
243+
break;
244+
case "UP":
245+
yOff = radius;
246+
break;
247+
case "DOWN":
248+
yOff = -radius;
249+
break;
243250
}
244251
}
245252
Vector signVector = sign.getBlock().getLocation().toVector();
246253
Vector min = new Vector(signVector.getX() + (xOff - radius), signVector.getY() + (yOff - radius), signVector.getZ() + (zOff - radius));
247254
Vector max = new Vector(signVector.getX() + (xOff + radius), signVector.getY() + (yOff + radius), signVector.getZ() + (zOff + radius));
248255
List<LivingEntity> worldEntities = sign.getBlock().getWorld().getLivingEntities();
249256
List<LivingEntity> entitiesInRange = new ArrayList<LivingEntity>(worldEntities.size());
257+
250258
for (LivingEntity entity : worldEntities) {
251-
if ((type == ALL || type == ANIMALS) && (entity instanceof Animals || entity instanceof Squid || entity instanceof Villager)) {
252-
if (entity.getLocation().toVector().isInAABB(min, max)) {
253-
Logging.finest("Found " + entity + " within range!");
254-
entitiesInRange.add(entity);
255-
}
256-
} else if ((type == ALL || type == MONSTERS) && (entity instanceof Monster)) {
257-
if (entity.getLocation().toVector().isInAABB(min, max)) {
258-
Logging.finest("Found " + entity + " within range!");
259-
entitiesInRange.add(entity);
260-
}
261-
} else if ((type == ALL || type == PLAYERS) && (entity instanceof HumanEntity)) {
259+
boolean tryToAddEntity = false;
260+
261+
if (type == RedstoneTeleportType.ALL) {
262+
tryToAddEntity = true;
263+
} else if (type == RedstoneTeleportType.ANIMALS && (entity instanceof Animals || entity instanceof Squid || entity instanceof Villager)) {
264+
tryToAddEntity = true;
265+
} else if (type == RedstoneTeleportType.MONSTERS && (entity instanceof Monster)) {
266+
tryToAddEntity = true;
267+
} else if (type == RedstoneTeleportType.PLAYERS && (entity instanceof HumanEntity)) {
268+
tryToAddEntity = true;
269+
}
270+
271+
if (tryToAddEntity && entity.getLocation().toVector().isInAABB(min, max)) {
262272
if (entity.getLocation().toVector().isInAABB(min, max)) {
263273
Logging.finest("Found " + entity + " within range!");
264274
entitiesInRange.add(entity);
@@ -355,6 +365,13 @@ public boolean playerCanGoToDestination(Player player, MVDestination d) {
355365
return false;
356366
}
357367
return this.plugin.getCore().getMVPerms().hasPermission(player, d.getRequiredPermission(), true);
358-
}
368+
}
369+
370+
enum RedstoneTeleportType {
371+
ALL,
372+
PLAYERS,
373+
MONSTERS,
374+
ANIMALS
375+
}
359376

360377
}

0 commit comments

Comments
 (0)