Skip to content

Commit

Permalink
Merge pull request #825 from gundom0802/main
Browse files Browse the repository at this point in the history
Changes
  • Loading branch information
Chronoken authored Jan 15, 2024
2 parents 1a24d05 + cb29b0c commit fe8328a
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,20 @@

import com.nisovin.magicspells.util.*;
import com.nisovin.magicspells.Subspell;
import com.nisovin.magicspells.MagicSpells;
import com.nisovin.magicspells.util.config.ConfigData;

public class LocationSpell extends InstantSpell {

private MagicLocation location;

private Subspell spellToCast;
private String spellToCastName;

private ConfigData<String> locationData;

public LocationSpell(MagicConfig config, String spellName) {
super(config, spellName);

String s = getConfigString("location", "world,0,0,0");
try {
String[] split = s.split(",");
String world = split[0];
double x = Double.parseDouble(split[1]);
double y = Double.parseDouble(split[2]);
double z = Double.parseDouble(split[3]);
float yaw = 0;
float pitch = 0;
if (split.length > 4) yaw = Float.parseFloat(split[4]);
if (split.length > 5) pitch = Float.parseFloat(split[5]);
location = new MagicLocation(world, x, y, z, yaw, pitch);
} catch (Exception e) {
MagicSpells.error("LocationSpell '" + spellName + "' has an invalid location defined!");
}

spellToCastName = getConfigString("spell", "");
locationData = getConfigDataString("location", "world,0,0,0");
}

@Override
Expand All @@ -44,10 +29,23 @@ public void initialize() {

@Override
public CastResult cast(SpellData data) {
Location loc = location.getLocation();
if (loc == null) return new CastResult(PostCastAction.ALREADY_HANDLED, data);
MagicLocation location = null;
String s = locationData.get(data);
try {
String[] split = s.split(",");
String world = split[0];
double x = Double.parseDouble(split[1]);
double y = Double.parseDouble(split[2]);
double z = Double.parseDouble(split[3]);
float yaw = 0;
float pitch = 0;
if (split.length > 4) yaw = Float.parseFloat(split[4]);
if (split.length > 5) pitch = Float.parseFloat(split[5]);
location = new MagicLocation(world, x, y, z, yaw, pitch);
} catch (Exception ignored) {}
if (location == null) return new CastResult(PostCastAction.ALREADY_HANDLED, data);

data = data.location(loc);
data = data.location(location.getLocation());
if (spellToCast != null) spellToCast.subcast(data);
playSpellEffects(data);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

import io.papermc.paper.entity.TeleportFlag;

import org.bukkit.Bukkit;
import org.bukkit.entity.*;
import org.bukkit.Location;
Expand Down Expand Up @@ -545,7 +547,7 @@ public void onEntityUnload(ChunkUnloadEvent event) {
if (!owner.isOnline()) continue;
if (owner.isDead()) continue;

minion.teleport(owner);
minion.teleport(owner.getLocation(), TeleportFlag.EntityState.RETAIN_PASSENGERS, TeleportFlag.EntityState.RETAIN_VEHICLE);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import org.bukkit.block.BlockFace;
import org.bukkit.entity.LivingEntity;

import io.papermc.paper.entity.TeleportFlag;

import com.nisovin.magicspells.util.*;
import com.nisovin.magicspells.MagicSpells;
import com.nisovin.magicspells.spells.BuffSpell;
Expand Down Expand Up @@ -126,10 +128,10 @@ public void run() {

if (feet.getType() == Material.WATER) {
loc.setY(Math.floor(loc.getY() + 1) + 0.1);
pl.teleport(loc);
pl.teleport(loc, TeleportFlag.EntityState.RETAIN_PASSENGERS, TeleportFlag.EntityState.RETAIN_VEHICLE);
} else if (pl.isFlying() && BlockUtils.isAir(underfeet.getType())) {
loc.setY(Math.floor(loc.getY() - 1) + 0.1);
pl.teleport(loc);
pl.teleport(loc, TeleportFlag.EntityState.RETAIN_PASSENGERS, TeleportFlag.EntityState.RETAIN_VEHICLE);
}

feet = pl.getLocation().getBlock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.util.UUID;
import java.util.HashMap;

import io.papermc.paper.entity.TeleportFlag;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.util.Vector;
Expand Down Expand Up @@ -93,18 +95,12 @@ public boolean castBuff(SpellData data) {

float launchSpeed = this.launchSpeed.get(data);
if (launchSpeed > 0) {
target.teleportAsync(target.getLocation().add(0, 0.25, 0)).thenRun(() -> MagicSpells.scheduleDelayedTask(() -> {
target.setVelocity(new Vector(0, launchSpeed, 0));

target.setAllowFlight(true);
target.setFlying(true);
target.setFlySpeed(flyData.flySpeed);
}, 0));
} else {
target.setAllowFlight(true);
target.setFlying(true);
target.setFlySpeed(flyData.flySpeed);
target.teleport(target.getLocation().add(0, 0.25, 0), TeleportFlag.EntityState.RETAIN_PASSENGERS, TeleportFlag.EntityState.RETAIN_VEHICLE);
target.setVelocity(new Vector(0, launchSpeed, 0));
}
target.setAllowFlight(true);
target.setFlying(true);
target.setFlySpeed(flyData.flySpeed);

return true;
}
Expand Down Expand Up @@ -203,7 +199,7 @@ public void onPlayerToggleSneak(PlayerToggleSneakEvent event) {
if (!isActive(player) || player.getLocation().subtract(0, 1, 0).getBlock().getType().isAir()) return;

if (alwaysFly) {
player.teleport(player.getLocation().add(0, 0.25, 0));
player.teleport(player.getLocation().add(0, 0.25, 0), TeleportFlag.EntityState.RETAIN_PASSENGERS, TeleportFlag.EntityState.RETAIN_VEHICLE);
player.setFlying(true);
} else if (cancelOnLand) turnOff(player);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import org.bukkit.Location;
import org.bukkit.util.Vector;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.event.EventHandler;
Expand All @@ -16,6 +15,7 @@
import org.bukkit.event.player.PlayerTeleportEvent;

import com.nisovin.magicspells.util.*;
import com.nisovin.magicspells.Subspell;
import com.nisovin.magicspells.MagicSpells;
import com.nisovin.magicspells.spells.InstantSpell;
import com.nisovin.magicspells.util.config.ConfigData;
Expand All @@ -25,13 +25,17 @@ public class FlightPathSpell extends InstantSpell {

private FlightHandler flightHandler;

private final String landSpellName;

private final ConfigData<Float> speed;
private final ConfigData<Float> targetX;
private final ConfigData<Float> targetZ;

private final int interval;
private final ConfigData<Integer> cruisingAltitude;

private Subspell landSpell;

public FlightPathSpell(MagicConfig config, String spellName) {
super(config, spellName);

Expand All @@ -41,12 +45,18 @@ public FlightPathSpell(MagicConfig config, String spellName) {

interval = getConfigInt("interval", 5);
cruisingAltitude = getConfigDataInt("cruising-altitude", 150);

landSpellName = getConfigString("land-spell", "");
}

@Override
public void initialize() {
super.initialize();

landSpell = initSubspell(landSpellName,
"FlightPathSpell '" + internalName + "' has an invalid land-spell defined!",
true);

flightHandler = new FlightHandler();
}

Expand Down Expand Up @@ -141,7 +151,6 @@ private class ActiveFlight {
private final Player caster;

private FlightState state;
private Entity mountActive;
private Location lastLocation;

private final boolean wasFlying;
Expand Down Expand Up @@ -215,6 +224,7 @@ private void fly() {
Location l = caster.getLocation();
if (!BlockUtils.isAir(l.getBlock().getType()) || !BlockUtils.isAir(l.subtract(0, 1, 0).getBlock().getType()) || !BlockUtils.isAir(l.subtract(0, 2, 0).getBlock().getType())) {
caster.setFallDistance(0f);
landSpell.subcast(data);
cancel();
return;
} else {
Expand All @@ -231,13 +241,7 @@ private void cancel() {
state = FlightState.DONE;
caster.setFlying(wasFlying);
caster.setAllowFlight(wasFlyingAllowed);
if (mountActive != null) {
mountActive.eject();
mountActive.remove();
}
playSpellEffects(EffectPosition.DELAYED, caster, data);

mountActive = null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.LivingEntity;

import io.papermc.paper.entity.TeleportFlag;

import com.nisovin.magicspells.util.*;
import com.nisovin.magicspells.Subspell;
import com.nisovin.magicspells.MagicSpells;
Expand Down Expand Up @@ -302,13 +304,13 @@ public void run() {

if (armorStandSet != null) {
for (ArmorStand armorStand : armorStandSet) {
armorStand.teleportAsync(loc);
armorStand.teleport(loc, TeleportFlag.EntityState.RETAIN_PASSENGERS, TeleportFlag.EntityState.RETAIN_VEHICLE);
}
}

if (entityMap != null) {
for (var entry : entityMap.entrySet()) {
entry.getValue().teleportAsync(entry.getKey().applyOffsets(loc.clone()));
entry.getValue().teleport(entry.getKey().applyOffsets(loc.clone()), TeleportFlag.EntityState.RETAIN_PASSENGERS, TeleportFlag.EntityState.RETAIN_VEHICLE);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.util.HashSet;
import java.util.HashMap;

import io.papermc.paper.entity.TeleportFlag;

import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
Expand Down Expand Up @@ -111,22 +113,16 @@ private void onMove(PlayerMoveEvent event) {
StunnedInfo info = stunnedLivingEntities.get(player.getUniqueId());
if (info == null) return;

// Perform checks whether to stun the player.
boolean shouldStun = false;
Location from = event.getFrom();
Location to = event.getTo();
boolean movedBody = from.getX() != to.getX() || from.getY() != to.getY() || from.getZ() != to.getZ();
boolean movedMonitor = from.getPitch() != to.getPitch() || from.getYaw() != to.getYaw();
if (info.stunBody && movedBody) shouldStun = true;
if (info.stunMonitor && movedMonitor) shouldStun = true;
if (!shouldStun) return;

if (info.until > System.currentTimeMillis()) {
event.setTo(info.useTargetLocation ? info.targetLocation : from);
if (System.currentTimeMillis() >= info.until) {
removeStun(player);
return;
}

removeStun(player);
boolean stunBody = info.stunBody && event.hasExplicitlyChangedPosition();
boolean stunMonitor = info.stunMonitor && event.hasChangedOrientation();
if (!stunBody && !stunMonitor) return;
Location to = info.useTargetLocation ? info.targetLocation : event.getFrom();
player.teleport(to, TeleportFlag.EntityState.RETAIN_PASSENGERS, TeleportFlag.EntityState.RETAIN_VEHICLE);
}

@EventHandler
Expand Down Expand Up @@ -164,7 +160,7 @@ public void run() {
if (entity instanceof Player) continue;

if (entity.isValid() && until > System.currentTimeMillis()) {
entity.teleportAsync(info.targetLocation);
entity.teleport(info.targetLocation, TeleportFlag.EntityState.RETAIN_PASSENGERS, TeleportFlag.EntityState.RETAIN_VEHICLE);
continue;
}

Expand Down

0 comments on commit fe8328a

Please sign in to comment.