Skip to content

Commit

Permalink
allow teleportation between worlds
Browse files Browse the repository at this point in the history
  • Loading branch information
BLuFeNiX committed Jul 12, 2021
1 parent 59b34b7 commit 9cb90c4
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/main/java/net/blufenix/teleportationrunes/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class Config {
public static SwirlAnimation particleAnimation;
public static boolean particleAnimationEnabled;
public static int animationDutyCycle;
public static boolean allowTeleportBetweenWorlds;

private static JavaPlugin plugin;

Expand All @@ -52,6 +53,7 @@ private static void load() {
enabled = config.getBoolean("TeleportationRunes.enabled");
debug = config.getBoolean("TeleportationRunes.debug");
costFormula = config.getString("TeleportationRunes.costFormula");
allowTeleportBetweenWorlds = config.getBoolean("TeleportationRunes.allowTeleportBetweenWorlds", true);
enableRotation = config.getBoolean("TeleportationRunes.enableRotation");
enableLightningEffect = config.getBoolean("TeleportationRunes.enableLightningEffect", false);
enableEnderTeleportEffect = config.getBoolean("TeleportationRunes.enableEnderTeleportEffect", true);
Expand Down
39 changes: 35 additions & 4 deletions src/main/java/net/blufenix/teleportationrunes/TeleUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,12 @@ public static boolean attemptTeleport(final Player player, Location teleporterLo
return false;
}

// is the destination in our current world?
if (!existingWaypoint.loc.getWorld().equals(teleporterLoc.getWorld())) {
player.sendMessage(StringResources.WAYPOINT_DIFFERENT_WORLD);
return false;
if (!Config.allowTeleportBetweenWorlds) {
// is the destination in our current world?
if (!existingWaypoint.loc.getWorld().equals(teleporterLoc.getWorld())) {
player.sendMessage(StringResources.WAYPOINT_DIFFERENT_WORLD);
return false;
}
}

try {
Expand Down Expand Up @@ -215,14 +217,43 @@ private static Location getSafeDestination(Location loc) {
}

public static int calculateExpr(Location waypointLoc, Location teleporterLoc, String formula) throws UnparsableExpressionException, UnknownFunctionException {
boolean anotherWorld = !waypointLoc.getWorld().equals(teleporterLoc.getWorld());
if (anotherWorld) {
// fake the world for the destination, so we can measure a somewhat nonsensical distance between them
waypointLoc = waypointLoc.clone();
waypointLoc.setWorld(teleporterLoc.getWorld());
}

// calculate teleport distance
double distance = waypointLoc.distance(teleporterLoc);

Calculable calc = new ExpressionBuilder(formula)
.withVariable("distance", distance)
.withVariable("anotherWorld", anotherWorld ? 1 : 0)
.build();

return (int) Math.round(calc.calculate());
}

/*
public static int calculateFee(Location waypointLoc, Location teleporterLoc) throws UnparsableExpressionException, UnknownFunctionException {
Calculable calc;
if (waypointLoc.getWorld().equals(teleporterLoc.getWorld())) {
// calculate teleport distance
double distance = waypointLoc.distance(teleporterLoc);
calc = new ExpressionBuilder(Config.costFormula)
.withVariable("distance", distance)
.build();
} else {
// no such thing as distance between worlds
double distance = waypointLoc.distance(teleporterLoc);
calc = new ExpressionBuilder(Config.costFormulaBetweenWorlds)
.withVariable("distance", distance)
.build();
}
return (int) Math.round(calc.calculate());
}
*/

}
20 changes: 19 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
TeleportationRunes:
enabled: true
debug: false

# the XP cost for teleportation
# supported variables:
# distance - how far apart the waypoint and teleporter are
# anotherWorld - will be set to 0 if teleport occurs withing the same world, or 1 if across worlds
#
costFormula: (distance / 25)
# another examples...
#
# make teleportation across worlds cost an extra 100 XP
# costFormula: (distance / 25) + anotherWorld * 100
#

# whether teleporters and waypoints can be arbitrarily rotated
# this will increase CPU usage and may cause lag
enableRotation: false
debug: false

# whether or not to allow teleportation between worlds
# when using this feature, you may wish to use the variable called 'anotherWorld' in your cost formula
allowTeleportBetweenWorlds: true

# whether or not to strike lightning (non-damaging) whenever a player teleports
enableLightningEffect: false
Expand Down

0 comments on commit 9cb90c4

Please sign in to comment.