own world per pixelblock, live update, owners
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package eu.mhsl.minecraft.pixelblocks.listeners;
|
||||
|
||||
import eu.mhsl.minecraft.pixelblocks.PixelBlocks;
|
||||
import eu.mhsl.minecraft.pixelblocks.pixelblock.Pixel;
|
||||
import eu.mhsl.minecraft.pixelblocks.pixelblock.PixelBlock;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class BlockBreakListener implements Listener {
|
||||
@EventHandler
|
||||
static void onBlockBreak(BlockBreakEvent event) {
|
||||
Location blockLocation = event.getBlock().getLocation();
|
||||
World[] standardWorlds = {Bukkit.getWorlds().get(0), Bukkit.getWorlds().get(1), Bukkit.getWorlds().get(2)};
|
||||
|
||||
if(!Arrays.stream(standardWorlds).toList().contains(blockLocation.getWorld())) {
|
||||
Location spawnLocation = blockLocation.getWorld().getSpawnLocation();
|
||||
|
||||
if(blockLocation.x() < spawnLocation.x() || blockLocation.z() < spawnLocation.z() || blockLocation.y() < spawnLocation.y()-1) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
} else if(blockLocation.x() > spawnLocation.x()+15 || blockLocation.z() > spawnLocation.z()+15 || blockLocation.y() > spawnLocation.y()+14) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().runTask(PixelBlocks.plugin, () -> {
|
||||
String blockUUID = Arrays.stream(blockLocation.getWorld().getName().split("/")).toList().getLast();
|
||||
List<PixelBlock> pixelBlocks = PixelBlock.placedBlocks.stream().filter(block -> block.uuid.toString().equals(blockUUID)).toList();
|
||||
|
||||
if(!pixelBlocks.isEmpty()) {
|
||||
PixelBlock pixelBlock = pixelBlocks.getFirst();
|
||||
Location relativeLocation = blockLocation.subtract(spawnLocation.x(), spawnLocation.y()-1, spawnLocation.z());
|
||||
relativeLocation.setWorld(pixelBlock.pixelBlockLocation.getWorld());
|
||||
List<Pixel> pixels = pixelBlock.pixels.stream().filter(pixel -> pixel.relativeLocation.equals(relativeLocation)).toList();
|
||||
|
||||
if(!pixels.isEmpty()) {
|
||||
Pixel pixel = pixels.getFirst();
|
||||
pixel.remove();
|
||||
pixelBlock.pixels.remove(pixel);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package eu.mhsl.minecraft.pixelblocks.listeners;
|
||||
|
||||
import eu.mhsl.minecraft.pixelblocks.PixelBlocks;
|
||||
import eu.mhsl.minecraft.pixelblocks.pixelblock.Pixel;
|
||||
import eu.mhsl.minecraft.pixelblocks.pixelblock.PixelBlock;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class BlockPlaceListener implements Listener {
|
||||
@EventHandler
|
||||
static void onBlockPlace(BlockPlaceEvent event) {
|
||||
Location blockLocation = event.getBlock().getLocation();
|
||||
World[] standardWorlds = {Bukkit.getWorlds().get(0), Bukkit.getWorlds().get(1), Bukkit.getWorlds().get(2)};
|
||||
|
||||
if(!Arrays.stream(standardWorlds).toList().contains(blockLocation.getWorld())) {
|
||||
Location spawnLocation = blockLocation.getWorld().getSpawnLocation();
|
||||
|
||||
if(blockLocation.x() < spawnLocation.x() || blockLocation.z() < spawnLocation.z() || blockLocation.y() < spawnLocation.y()-1) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
} else if(blockLocation.x() > spawnLocation.x()+15 || blockLocation.z() > spawnLocation.z()+15 || blockLocation.y() > spawnLocation.y()+14) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().runTask(PixelBlocks.plugin, () -> {
|
||||
String blockUUID = Arrays.stream(blockLocation.getWorld().getName().split("/")).toList().getLast();
|
||||
List<PixelBlock> pixelBlocks = PixelBlock.placedBlocks.stream().filter(block -> block.uuid.toString().equals(blockUUID)).toList();
|
||||
|
||||
if(!pixelBlocks.isEmpty()) {
|
||||
PixelBlock pixelBlock = pixelBlocks.getFirst();
|
||||
Location relativeLocation = blockLocation.subtract(spawnLocation.x(), spawnLocation.y()-1, spawnLocation.z());
|
||||
relativeLocation.setWorld(pixelBlock.pixelBlockLocation.getWorld());
|
||||
|
||||
Pixel newPixel = new Pixel(
|
||||
relativeLocation,
|
||||
event.getBlock().getBlockData(),
|
||||
(1/pixelBlock.pixelsPerBlock)-0.0001,
|
||||
0.00005*pixelBlock.pixelsPerBlock);
|
||||
pixelBlock.pixels.add(newPixel);
|
||||
newPixel.spawn(pixelBlock.pixelBlockLocation);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package eu.mhsl.minecraft.pixelblocks.listeners;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class CreatureSpawnListener implements Listener {
|
||||
@EventHandler
|
||||
static void onCreatureSpawn(CreatureSpawnEvent event) {
|
||||
Location entityLocation = event.getEntity().getLocation();
|
||||
World[] standardWorlds = {Bukkit.getWorlds().get(0), Bukkit.getWorlds().get(1), Bukkit.getWorlds().get(2)};
|
||||
|
||||
if(!Arrays.stream(standardWorlds).toList().contains(entityLocation.getWorld())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package eu.mhsl.minecraft.pixelblocks.listeners;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class EntityDamageListener implements Listener {
|
||||
@EventHandler
|
||||
static void onEntityDamage(EntityDamageEvent event) {
|
||||
if(event.getEntity() instanceof Player player) {
|
||||
World playerWorld = player.getWorld();
|
||||
World[] standardWorlds = {Bukkit.getWorlds().get(0), Bukkit.getWorlds().get(1), Bukkit.getWorlds().get(2)};
|
||||
|
||||
if(!Arrays.stream(standardWorlds).toList().contains(playerWorld)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,9 @@
|
||||
package eu.mhsl.minecraft.pixelblocks.listeners;
|
||||
|
||||
import eu.mhsl.minecraft.pixelblocks.PixelBlocks;
|
||||
import eu.mhsl.minecraft.pixelblocks.pixelblock.Pixel;
|
||||
import eu.mhsl.minecraft.pixelblocks.pixelblock.PixelBlock;
|
||||
import io.papermc.paper.event.player.PrePlayerAttackEntityEvent;
|
||||
import io.papermc.paper.math.Position;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.entity.Blaze;
|
||||
import org.bukkit.entity.BlockDisplay;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Interaction;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@@ -16,9 +11,7 @@ import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
import static eu.mhsl.minecraft.pixelblocks.PixelBlocks.plugin;
|
||||
|
||||
@@ -43,6 +36,7 @@ public class PlayerInteractListener implements Listener {
|
||||
Location interactionLocation = event.getRightClicked().getLocation().add(0, PixelBlock.hitboxOffset+0.5, 0).toBlockLocation();
|
||||
interactionLocation.setYaw(0);
|
||||
interactionLocation.setPitch(0);
|
||||
|
||||
UUID playerUID = event.getPlayer().getUniqueId();
|
||||
PixelBlock pixelBlock = PixelBlock.placedBlocks.stream()
|
||||
.filter(block -> block.pixelBlockLocation.equals(interactionLocation))
|
||||
@@ -52,14 +46,21 @@ public class PlayerInteractListener implements Listener {
|
||||
|
||||
if(playerUID == blockOwner) {
|
||||
pixelBlock.lastEntryLocation = event.getPlayer().getLocation();
|
||||
pixelBlock.lastEntryTime = System.currentTimeMillis();
|
||||
|
||||
final WorldCreator worldCreator = new WorldCreator(plugin.getDataFolder().getPath()+"/"+event.getPlayer().getUniqueId());
|
||||
worldCreator.type(WorldType.FLAT);
|
||||
World newWorld = Bukkit.createWorld(worldCreator);
|
||||
World blockWorld = Bukkit.getWorld(plugin.getDataFolder().getPath()+"/"+pixelBlock.uuid);
|
||||
assert blockWorld != null;
|
||||
event.getPlayer().teleport(blockWorld.getSpawnLocation());
|
||||
|
||||
event.getPlayer().teleport(newWorld.getSpawnLocation());
|
||||
Bukkit.getScheduler().cancelTask(pixelBlock.updateTaskID);
|
||||
pixelBlock.updateTaskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(
|
||||
PixelBlocks.plugin,
|
||||
pixelBlock::update,
|
||||
100L,
|
||||
100L
|
||||
);
|
||||
} else {
|
||||
event.getPlayer().sendMessage("This Block is not yours!");
|
||||
event.getPlayer().sendMessage("Dieser Block gehört nicht dir!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -71,14 +72,19 @@ public class PlayerInteractListener implements Listener {
|
||||
blockLocation.setYaw(0);
|
||||
blockLocation.setPitch(0);
|
||||
|
||||
Bukkit.getScheduler().runTask(
|
||||
PixelBlocks.plugin,
|
||||
() -> PixelBlock.placedBlocks.stream()
|
||||
// .filter(pixelBlock -> pixelBlock.pixelBlockLocation.distance(blockLocation) < 0.5)
|
||||
.filter(pixelBlock -> pixelBlock.pixelBlockLocation.equals(blockLocation))
|
||||
UUID playerUID = event.getPlayer().getUniqueId();
|
||||
PixelBlock pixelBlock = PixelBlock.placedBlocks.stream()
|
||||
.filter(block -> block.pixelBlockLocation.equals(blockLocation))
|
||||
.findFirst()
|
||||
.orElseThrow()
|
||||
.remove());
|
||||
.orElseThrow();
|
||||
UUID blockOwner = pixelBlock.owner;
|
||||
|
||||
if(playerUID == blockOwner) {
|
||||
Bukkit.getScheduler().runTask(PixelBlocks.plugin, pixelBlock::remove);
|
||||
} else {
|
||||
event.getPlayer().sendMessage("Dieser Block gehört nicht dir!");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package eu.mhsl.minecraft.pixelblocks.listeners;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class PlayerMoveListener implements Listener {
|
||||
@EventHandler
|
||||
static void onPlayerMove(PlayerMoveEvent event) {
|
||||
World playerWorld = event.getPlayer().getWorld();
|
||||
World[] standardWorlds = {Bukkit.getWorlds().get(0), Bukkit.getWorlds().get(1), Bukkit.getWorlds().get(2)};
|
||||
|
||||
if(!Arrays.stream(standardWorlds).toList().contains(playerWorld)) {
|
||||
Location playerLocation = event.getPlayer().getLocation();
|
||||
if(playerLocation.y() < -65) {
|
||||
playerWorld.getSpawnLocation().clone().subtract(1, 1, 1).getBlock().setType(Material.WHITE_CONCRETE);
|
||||
event.getPlayer().teleport(event.getPlayer().getWorld().getSpawnLocation());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user