Advertisement
Ghaz-ranka

Untitled

May 19th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. package com.esinia.server.events;
  2.  
  3.  
  4. import org.spongepowered.api.Sponge;
  5. import org.spongepowered.api.entity.Entity;
  6. import org.spongepowered.api.event.Listener;
  7. import org.spongepowered.api.event.entity.SpawnEntityEvent;
  8. import org.spongepowered.api.text.Text;
  9.  
  10. //Class name and main method
  11. public class EventSpawnEntity {
  12. //listener for the event
  13. @Listener
  14. //event for when enities spawn
  15. public void onEntitySpawn(SpawnEntityEvent event) {
  16. //loops for every entity during the event. Entity variable titled entity is set to each the entity during that specific loop
  17. for (Entity entity : event.getEntities()){
  18. //creating string variable with the name of the entity during the loop
  19. String entityType = entity.getType().getName();
  20. //if the string variable entityType contains any of the following strings it proceeds
  21. if(entityType.contains("customnpc") || entityType.contains("item") || entityType.contains("arrow") || entityType.contains("coraliumarrow") || entityType.contains("projectile")){
  22. //if the previous method is false
  23. } else{
  24. //cancels the event
  25. event.setCancelled(true);
  26. }
  27. //Sponge.getServer().getBroadcastChannel().send(Text.of("test"));
  28. //Sponge.getServer().getBroadcastChannel().send(Text.of(entityType));
  29. }
  30. }
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement