Minecraftfailzzz

Hub Plugin

Jun 27th, 2014
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.67 KB | None | 0 0
  1. package me.tomg.hub;
  2.  
  3. import static org.bukkit.ChatColor.DARK_AQUA;
  4. import static org.bukkit.ChatColor.DARK_GRAY;
  5. import static org.bukkit.ChatColor.GOLD;
  6. import static org.bukkit.ChatColor.GRAY;
  7. import static org.bukkit.ChatColor.GREEN;
  8. import static org.bukkit.ChatColor.RED;
  9.  
  10. import java.util.ArrayList;
  11. import java.util.Random;
  12.  
  13. import org.bukkit.Color;
  14. import org.bukkit.FireworkEffect;
  15. import org.bukkit.command.Command;
  16. import org.bukkit.command.CommandSender;
  17. import org.bukkit.entity.EntityType;
  18. import org.bukkit.entity.Firework;
  19. import org.bukkit.entity.Player;
  20. import org.bukkit.event.EventHandler;
  21. import org.bukkit.event.EventPriority;
  22. import org.bukkit.event.Listener;
  23. import org.bukkit.event.player.PlayerJoinEvent;
  24. import org.bukkit.inventory.meta.FireworkMeta;
  25. import org.bukkit.plugin.java.JavaPlugin;
  26.  
  27. public class Main extends JavaPlugin implements Listener{
  28.    
  29.  
  30.     //Registering the events on the onEnbale().
  31.     @Override
  32.     public void onEnable(){
  33.         getServer().getPluginManager().registerEvents(this, this);
  34.     }
  35.    
  36.     /*
  37.      * If the player types /fly, it'll check if they have allow flight, if so it'll turn off fly.
  38.      * if they don't have it, it'll turn fly on for them. It will also send them a message.
  39.      * Also if the sender is not a player, it'll tell the sender to f*ck off.
  40.      */
  41.     @Override
  42.     public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
  43.         if(command.getName().equalsIgnoreCase("fly")){
  44.             if(!(sender instanceof Player)){
  45.                 sender.sendMessage(RED + "You can only fly if you're a player!");
  46.                 return true;
  47.             }
  48.             Player p = (Player) sender;
  49.             if(!(p.hasPermission("hub.fly"))){
  50.                 p.sendMessage(RED + "I'm sorry but you are not allowed to fly!");
  51.                 return true;
  52.             }
  53.             if(p.getAllowFlight() == true){
  54.                 p.setAllowFlight(false);
  55.                 p.sendMessage(GREEN + "Your flight has ended.");
  56.             }else if(p.getPlayer().getAllowFlight() == false){
  57.                 p.setAllowFlight(true);
  58.                 p.sendMessage(GREEN + "Have a good flight!");
  59.             }
  60.         }
  61.         /*
  62.          * Now comes the firework part, /fw for a firework with a
  63.          * randomized color, 30 seconds cooldown
  64.          * and only players who have the permission
  65.          * hub.fw can shoot a firework!
  66.          */
  67.        
  68.         else if(command.getName().equalsIgnoreCase("fw")){
  69.             if(!(sender instanceof Player)){
  70.                 sender.sendMessage(RED + "You have to be a player in order to shoot fireworks!");
  71.                 return true;
  72.             }
  73.             if(!(sender.hasPermission("hub.fw"))){
  74.                 sender.sendMessage(RED +"I'm sorry but you are not allowed to shoot fireworks!");
  75.             }
  76.            
  77.             Player p = (Player) sender;
  78.             if(fireworks.contains(p.getName())){
  79.                 p.sendMessage(RED + "You  have to wait 30 seconds before using this command again.");
  80.             }if(!(fireworks.contains(p.getName()))){
  81.                 firework(p);
  82.                 fireworks.add(p.getName());
  83.                 fireworks(p);
  84.             }
  85.         }
  86.         return true;
  87.     }
  88.    
  89.    
  90.     //This makes the firework and launches it.
  91.    
  92.     public void firework(Player player){
  93.        
  94.         //randomizing firework colors
  95.         Player p = (Player) player;
  96.         Random color = new Random();
  97.         int colors;
  98.         Color fwColor = null;
  99.        
  100.         for(int counter =1; counter<=1; counter++){
  101.             colors = 1+color.nextInt(4);
  102.            
  103.             if(colors == 1){
  104.                 fwColor = Color.RED;
  105.             }else if(colors == 2){
  106.                 fwColor = Color.GREEN;
  107.             }else if(colors == 3){
  108.                 fwColor = Color.BLUE;
  109.             }else if(colors == 4){
  110.                 fwColor = Color.ORANGE;
  111.             }
  112.         }
  113.         //randomizing firework fading colors.
  114.         Random color2 = new Random();
  115.         int colors2;
  116.         Color fwColor2 = null;
  117.        
  118.         for(int counter =1; counter<=1; counter++){
  119.             colors2 = 1+color2.nextInt(4);
  120.            
  121.             if(colors2 == 1){
  122.                 fwColor2 = Color.AQUA;
  123.             }else if(colors2 == 2){
  124.                 fwColor2 = Color.YELLOW;
  125.             }else if(colors2 == 3){
  126.                 fwColor2 = Color.PURPLE;
  127.             }else if(colors2 == 4){
  128.                 fwColor2 = Color.FUCHSIA;
  129.             }
  130.         }
  131.        
  132.         //building the firework and launching it.
  133.         Firework fw = (Firework) player.getWorld().spawnEntity(player.getLocation(), EntityType.FIREWORK);
  134.         FireworkMeta fwmeta = fw.getFireworkMeta();
  135.         FireworkEffect.Builder builder = FireworkEffect.builder();
  136.         builder.withTrail();
  137.         builder.withFlicker();
  138.         builder.withFade(fwColor2);
  139.         builder.withColor(fwColor);
  140.         builder.with(FireworkEffect.Type.BALL_LARGE);
  141.         fwmeta.addEffects(builder.build());
  142.         fwmeta.setPower(2);
  143.         fw.setFireworkMeta(fwmeta);
  144.        
  145.     }
  146.    
  147.    
  148.     /*
  149.      * The delayed task for the 15s cooldown.
  150.      */
  151.     public ArrayList<String> fireworks = new ArrayList<String>();
  152.    
  153.     public void fireworks(final Player player){
  154.         getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
  155.             public void run(){
  156.                 fireworks.remove(player.getName());
  157.                 player.sendMessage(GREEN + "You can now use /fw again!");
  158.             }
  159.         }, 30*20);
  160.     }
  161.    
  162.    
  163.    
  164.     /*
  165.      * When the player logs on, it checks if they have the permission easyfly.join, if so, it'll
  166.      * set allow flight to true.
  167.      * Also if they have the permission for easyfly.donor it'll set the joinmessage to something
  168.      * special. And the normal join message for normal people will also be different but not
  169.      * special.
  170.      */
  171.    
  172.     @EventHandler(priority = EventPriority.LOWEST)
  173.     public void onPlayerJoin(PlayerJoinEvent e){
  174.         Player p = e.getPlayer();
  175.         if(p.hasPermission("hub.join")){
  176.             p.setAllowFlight(true);
  177.         }
  178.         if(p.hasPermission("hub.joinmessage.donor")){
  179.             e.setJoinMessage(GOLD + p.getDisplayName() + DARK_AQUA + " has joined the lobby!");
  180.         }
  181.         if(p.hasPermission("hub.joinmessage.default")){
  182.             e.setJoinMessage(DARK_GRAY + p.getDisplayName() + GRAY + " has joined the lobby!");
  183.         }
  184.         if(p.hasPermission("hub.joinmessage.staff")){
  185.             e.setJoinMessage(RED + p.getDisplayName() + GOLD + " has joined the lobby!");
  186.         }
  187.     }
  188. }
Advertisement
Add Comment
Please, Sign In to add comment