Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c119913071 |
No files matched your search
-52
@@ -1,52 +0,0 @@
|
|||||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.frostWalkerBoat;
|
|
||||||
|
|
||||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.block.BlockFace;
|
|
||||||
import org.bukkit.block.data.Levelled;
|
|
||||||
import org.bukkit.entity.Boat;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.vehicle.VehicleMoveEvent;
|
|
||||||
import org.bukkit.util.Vector;
|
|
||||||
|
|
||||||
class BoatMoveListener extends ApplianceListener<FrostWalkerBoat> {
|
|
||||||
@EventHandler
|
|
||||||
public void onBoatMove(VehicleMoveEvent event) {
|
|
||||||
if(!(event.getVehicle() instanceof Boat boat)) return;
|
|
||||||
|
|
||||||
// if(!event.getVehicle().getPersistentDataContainer().has(
|
|
||||||
// this.getAppliance().getNamespacedKey(),
|
|
||||||
// PersistentDataType.BOOLEAN)
|
|
||||||
// ) return;
|
|
||||||
//
|
|
||||||
// if(Boolean.FALSE.equals(event.getVehicle().getPersistentDataContainer().get(
|
|
||||||
// this.getAppliance().getNamespacedKey(),
|
|
||||||
// PersistentDataType.BOOLEAN
|
|
||||||
// ))) return;
|
|
||||||
|
|
||||||
Block blockAtBoat = event.getTo().getBlock();
|
|
||||||
|
|
||||||
if(blockAtBoat.getType() == Material.WATER) {
|
|
||||||
if (!(blockAtBoat.getBlockData() instanceof Levelled waterData)) return;
|
|
||||||
if (waterData.getLevel() != 0) return;
|
|
||||||
if (!blockAtBoat.getRelative(BlockFace.UP).isEmpty()) return;
|
|
||||||
|
|
||||||
Location teleportLocation = event.getTo().clone();
|
|
||||||
teleportLocation.setY(blockAtBoat.getY()+1.1);
|
|
||||||
boat.teleport(teleportLocation);
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector velocity = event.getTo().toVector().subtract(event.getFrom().toVector());
|
|
||||||
velocity.setY(0);
|
|
||||||
Block iceTargetBlock;
|
|
||||||
if(velocity.isZero()) {
|
|
||||||
iceTargetBlock = event.getTo().getBlock().getRelative(BlockFace.DOWN);
|
|
||||||
} else {
|
|
||||||
Location iceTargetLocation = blockAtBoat.getLocation().clone().add(velocity.clone().normalize().multiply(5));
|
|
||||||
iceTargetBlock = iceTargetLocation.getBlock().getRelative(BlockFace.DOWN);
|
|
||||||
}
|
|
||||||
this.getAppliance().freezeWater(iceTargetBlock);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-47
@@ -1,47 +0,0 @@
|
|||||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.frostWalkerBoat;
|
|
||||||
|
|
||||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.NamespacedKey;
|
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.block.BlockFace;
|
|
||||||
import org.bukkit.block.data.Levelled;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class FrostWalkerBoat extends Appliance {
|
|
||||||
public NamespacedKey getNamespacedKey() {
|
|
||||||
return new NamespacedKey(this.getClass().getSimpleName().toLowerCase(), "is_frostwalker_enchanted");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void freezeWater(Block targetBlock) {
|
|
||||||
int radius = 4;
|
|
||||||
double circleRadiusSquared = Math.pow(radius + 0.5, 2);
|
|
||||||
|
|
||||||
for(int xOffset = -radius; xOffset <= radius; xOffset++) {
|
|
||||||
for(int zOffset = -radius; zOffset <= radius; zOffset++) {
|
|
||||||
int distanceSquared =
|
|
||||||
xOffset * xOffset + zOffset * zOffset;
|
|
||||||
|
|
||||||
if(distanceSquared > circleRadiusSquared) continue;
|
|
||||||
|
|
||||||
Block block = targetBlock.getRelative(xOffset, 0, zOffset);
|
|
||||||
|
|
||||||
if(block.getType() != Material.WATER) continue;
|
|
||||||
if(!(block.getBlockData() instanceof Levelled waterData)) continue;
|
|
||||||
if(waterData.getLevel() != 0) continue;
|
|
||||||
if(!block.getRelative(BlockFace.UP).isEmpty()) continue;
|
|
||||||
|
|
||||||
block.setType(Material.FROSTED_ICE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@NotNull
|
|
||||||
protected List<Listener> listeners() {
|
|
||||||
return List.of(new BoatMoveListener());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.craftattack.appliances.metaGameplay.antiPlayerLootDespawn;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class AntiPlayerLootDespawn extends Appliance {
|
||||||
|
@Override
|
||||||
|
protected @NotNull List<Listener> listeners() {
|
||||||
|
return List.of(new AntiPlayerLootDespawnListener());
|
||||||
|
}
|
||||||
|
}
|
||||||
+51
@@ -0,0 +1,51 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.craftattack.appliances.metaGameplay.antiPlayerLootDespawn;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.entity.Item;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.entity.ItemDespawnEvent;
|
||||||
|
import org.bukkit.event.entity.ItemSpawnEvent;
|
||||||
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
|
import org.bukkit.persistence.PersistentDataContainer;
|
||||||
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
public class AntiPlayerLootDespawnListener extends ApplianceListener<AntiPlayerLootDespawn> {
|
||||||
|
private static final int extraCycles = 5;
|
||||||
|
private static final String namespace = AntiPlayerLootDespawnListener.class.getSimpleName().toLowerCase(Locale.ROOT);
|
||||||
|
public static NamespacedKey cyclesKey = new NamespacedKey(namespace, "item_deaths_cycles".toLowerCase());
|
||||||
|
private Location lastDeathLocation;
|
||||||
|
private long lastDeathTick = -1;
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onDeath(PlayerDeathEvent event) {
|
||||||
|
this.lastDeathLocation = event.getEntity().getLocation();
|
||||||
|
this.lastDeathTick = event.getPlayer().getWorld().getGameTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onItemSpawn(ItemSpawnEvent event) {
|
||||||
|
Item item = event.getEntity();
|
||||||
|
|
||||||
|
if(this.lastDeathLocation == null) return;
|
||||||
|
if(!item.getWorld().equals(this.lastDeathLocation.getWorld())) return;
|
||||||
|
if (item.getWorld().getGameTime() != this.lastDeathTick) return;
|
||||||
|
if(item.getLocation().distanceSquared(this.lastDeathLocation) > 9) return;
|
||||||
|
|
||||||
|
item.getPersistentDataContainer().set(cyclesKey, PersistentDataType.INTEGER, extraCycles);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onItemDespawn(ItemDespawnEvent event) {
|
||||||
|
PersistentDataContainer data = event.getEntity().getPersistentDataContainer();
|
||||||
|
Integer cycles = data.get(cyclesKey, PersistentDataType.INTEGER);
|
||||||
|
|
||||||
|
if(cycles == null || cycles <= 0) return;
|
||||||
|
|
||||||
|
data.set(cyclesKey, PersistentDataType.INTEGER, cycles - 1);
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user