mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-22 17:17:37 +00:00
Merge branch 'master' of https://github.com/plexusorg/Plex
This commit is contained in:
commit
9708f871c8
@ -43,7 +43,7 @@ public class BlockListener extends PlexListener
|
|||||||
|
|
||||||
if (blockedBlocks.contains(event.getBlock().getType()))
|
if (blockedBlocks.contains(event.getBlock().getType()))
|
||||||
{
|
{
|
||||||
event.getBlock().setType(Material.COBWEB);
|
event.getBlock().setType(Material.CAKE);
|
||||||
Particle.CLOUD.builder().location(event.getBlock().getLocation().add(0.5,0.5,0.5)).receivers(event.getPlayer()).extra(0).offset(0.5,0.5,0.5).count(5).spawn();
|
Particle.CLOUD.builder().location(event.getBlock().getLocation().add(0.5,0.5,0.5)).receivers(event.getPlayer()).extra(0).offset(0.5,0.5,0.5).count(5).spawn();
|
||||||
Particle.FLAME.builder().location(event.getBlock().getLocation().add(0.5,0.5,0.5)).receivers(event.getPlayer()).extra(0).offset(0.5,0.5,0.5).count(3).spawn();
|
Particle.FLAME.builder().location(event.getBlock().getLocation().add(0.5,0.5,0.5)).receivers(event.getPlayer()).extra(0).offset(0.5,0.5,0.5).count(3).spawn();
|
||||||
Particle.SOUL_FIRE_FLAME.builder().location(event.getBlock().getLocation().add(0.5,0.5,0.5)).receivers(event.getPlayer()).offset(0.5,0.5,0.5).extra(0).count(2).spawn();
|
Particle.SOUL_FIRE_FLAME.builder().location(event.getBlock().getLocation().add(0.5,0.5,0.5)).receivers(event.getPlayer()).offset(0.5,0.5,0.5).extra(0).count(2).spawn();
|
||||||
|
@ -1,57 +0,0 @@
|
|||||||
package dev.plex.listener.impl;
|
|
||||||
|
|
||||||
import dev.plex.listener.PlexListener;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.entity.EntityType;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.block.Action;
|
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class SpawnEggListener extends PlexListener
|
|
||||||
{
|
|
||||||
public static final List<Material> SPAWN_EGGS = Arrays.stream(Material.values()).filter((mat) -> mat.name().endsWith("_SPAWN_EGG")).toList();
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
|
||||||
public void onPlayerInteract(PlayerInteractEvent event)
|
|
||||||
{
|
|
||||||
if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)
|
|
||||||
{
|
|
||||||
if (SPAWN_EGGS.contains(event.getMaterial()))
|
|
||||||
{
|
|
||||||
event.setCancelled(true);
|
|
||||||
Block clickedBlock = event.getClickedBlock();
|
|
||||||
if (clickedBlock == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
EntityType eggType = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Material mat = event.getMaterial();
|
|
||||||
if (mat == Material.MOOSHROOM_SPAWN_EGG)
|
|
||||||
{
|
|
||||||
eggType = EntityType.MUSHROOM_COW;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
eggType = EntityType.valueOf(mat.name().substring(0, mat.name().length() - 10));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException ignored)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
if (eggType != null)
|
|
||||||
{
|
|
||||||
clickedBlock.getWorld().spawnEntity(clickedBlock.getLocation().add(event.getBlockFace().getDirection()).add(0.5, 0.5, 0.5), eggType);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
87
src/main/java/dev/plex/listener/impl/SpawnListener.java
Normal file
87
src/main/java/dev/plex/listener/impl/SpawnListener.java
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
package dev.plex.listener.impl;
|
||||||
|
|
||||||
|
import dev.plex.listener.PlexListener;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.data.Directional;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.block.Action;
|
||||||
|
import org.bukkit.event.block.BlockDispenseEvent;
|
||||||
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class SpawnListener extends PlexListener
|
||||||
|
{
|
||||||
|
// TODO: CONFIGURABILITY!!!
|
||||||
|
|
||||||
|
public static final List<Material> SPAWN_EGGS = Arrays.stream(Material.values()).filter((mat) -> mat.name().endsWith("_SPAWN_EGG")).toList();
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onDispense(BlockDispenseEvent event)
|
||||||
|
{
|
||||||
|
ItemStack item = event.getItem();
|
||||||
|
Material itemType = item.getType();
|
||||||
|
if (SPAWN_EGGS.contains(itemType))
|
||||||
|
{
|
||||||
|
Block block = event.getBlock();
|
||||||
|
Location blockLoc = block.getLocation().add(0.5,0.5,0.5).add(((Directional) block.getBlockData()).getFacing().getDirection().multiply(0.8));
|
||||||
|
event.setCancelled(true);
|
||||||
|
item.setAmount(item.getAmount() - 1);
|
||||||
|
event.setItem(item);
|
||||||
|
EntityType eggType = spawnEggToEntityType(itemType);
|
||||||
|
if (eggType != null)
|
||||||
|
{
|
||||||
|
blockLoc.getWorld().spawnEntity(blockLoc, eggType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
|
public void onPlayerInteract(PlayerInteractEvent event)
|
||||||
|
{
|
||||||
|
if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)
|
||||||
|
{
|
||||||
|
if (SPAWN_EGGS.contains(event.getMaterial()))
|
||||||
|
{
|
||||||
|
event.setCancelled(true);
|
||||||
|
Block clickedBlock = event.getClickedBlock();
|
||||||
|
if (clickedBlock == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
EntityType eggType = spawnEggToEntityType(event.getMaterial());
|
||||||
|
if (eggType != null)
|
||||||
|
{
|
||||||
|
clickedBlock.getWorld().spawnEntity(clickedBlock.getLocation().add(event.getBlockFace().getDirection().multiply(0.8)).add(0.5, 0.5, 0.5), eggType);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static EntityType spawnEggToEntityType(Material mat){
|
||||||
|
EntityType eggType;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (mat == Material.MOOSHROOM_SPAWN_EGG)
|
||||||
|
{
|
||||||
|
eggType = EntityType.MUSHROOM_COW;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
eggType = EntityType.valueOf(mat.name().substring(0, mat.name().length() - 10));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IllegalArgumentException ignored)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return eggType;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user