aaa
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
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;
|
||||
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 static eu.mhsl.minecraft.pixelblocks.PixelBlocks.plugin;
|
||||
|
||||
public class PlayerInteractListener implements Listener {
|
||||
@EventHandler
|
||||
static void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if(event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock() != null) {
|
||||
if(event.getClickedBlock().getType() == Material.GLASS) {
|
||||
// final WorldCreator worldCreator = new WorldCreator(plugin.getDataFolder().getPath()+"/"+event.getPlayer().getUniqueId());
|
||||
// worldCreator.type(WorldType.FLAT);
|
||||
//
|
||||
// World newWorld = Bukkit.createWorld(worldCreator);
|
||||
//
|
||||
// event.getPlayer().teleport(newWorld.getSpawnLocation());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
static void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
||||
if(event.getRightClicked() instanceof Interaction) {
|
||||
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))
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
UUID blockOwner = pixelBlock.owner;
|
||||
|
||||
if(playerUID == blockOwner) {
|
||||
pixelBlock.lastEntryLocation = event.getPlayer().getLocation();
|
||||
|
||||
final WorldCreator worldCreator = new WorldCreator(plugin.getDataFolder().getPath()+"/"+event.getPlayer().getUniqueId());
|
||||
worldCreator.type(WorldType.FLAT);
|
||||
World newWorld = Bukkit.createWorld(worldCreator);
|
||||
|
||||
event.getPlayer().teleport(newWorld.getSpawnLocation());
|
||||
} else {
|
||||
event.getPlayer().sendMessage("This Block is not yours!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
static void onPlayerAttackEntity(PrePlayerAttackEntityEvent event) {
|
||||
if(event.getAttacked() instanceof Interaction) {
|
||||
Location blockLocation = event.getAttacked().getLocation().add(0, PixelBlock.hitboxOffset+0.5, 0).toBlockLocation();
|
||||
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))
|
||||
.findFirst()
|
||||
.orElseThrow()
|
||||
.remove());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user