Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.tomg.hub;
- import static org.bukkit.ChatColor.DARK_AQUA;
- import static org.bukkit.ChatColor.DARK_GRAY;
- import static org.bukkit.ChatColor.GOLD;
- import static org.bukkit.ChatColor.GRAY;
- import static org.bukkit.ChatColor.GREEN;
- import static org.bukkit.ChatColor.RED;
- import java.util.ArrayList;
- import java.util.Random;
- import org.bukkit.Color;
- import org.bukkit.FireworkEffect;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.EntityType;
- import org.bukkit.entity.Firework;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.EventPriority;
- import org.bukkit.event.Listener;
- import org.bukkit.event.player.PlayerJoinEvent;
- import org.bukkit.inventory.meta.FireworkMeta;
- import org.bukkit.plugin.java.JavaPlugin;
- public class Main extends JavaPlugin implements Listener{
- //Registering the events on the onEnbale().
- @Override
- public void onEnable(){
- getServer().getPluginManager().registerEvents(this, this);
- }
- /*
- * If the player types /fly, it'll check if they have allow flight, if so it'll turn off fly.
- * if they don't have it, it'll turn fly on for them. It will also send them a message.
- * Also if the sender is not a player, it'll tell the sender to f*ck off.
- */
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
- if(command.getName().equalsIgnoreCase("fly")){
- if(!(sender instanceof Player)){
- sender.sendMessage(RED + "You can only fly if you're a player!");
- return true;
- }
- Player p = (Player) sender;
- if(!(p.hasPermission("hub.fly"))){
- p.sendMessage(RED + "I'm sorry but you are not allowed to fly!");
- return true;
- }
- if(p.getAllowFlight() == true){
- p.setAllowFlight(false);
- p.sendMessage(GREEN + "Your flight has ended.");
- }else if(p.getPlayer().getAllowFlight() == false){
- p.setAllowFlight(true);
- p.sendMessage(GREEN + "Have a good flight!");
- }
- }
- /*
- * Now comes the firework part, /fw for a firework with a
- * randomized color, 30 seconds cooldown
- * and only players who have the permission
- * hub.fw can shoot a firework!
- */
- else if(command.getName().equalsIgnoreCase("fw")){
- if(!(sender instanceof Player)){
- sender.sendMessage(RED + "You have to be a player in order to shoot fireworks!");
- return true;
- }
- if(!(sender.hasPermission("hub.fw"))){
- sender.sendMessage(RED +"I'm sorry but you are not allowed to shoot fireworks!");
- }
- Player p = (Player) sender;
- if(fireworks.contains(p.getName())){
- p.sendMessage(RED + "You have to wait 30 seconds before using this command again.");
- }if(!(fireworks.contains(p.getName()))){
- firework(p);
- fireworks.add(p.getName());
- fireworks(p);
- }
- }
- return true;
- }
- //This makes the firework and launches it.
- public void firework(Player player){
- //randomizing firework colors
- Player p = (Player) player;
- Random color = new Random();
- int colors;
- Color fwColor = null;
- for(int counter =1; counter<=1; counter++){
- colors = 1+color.nextInt(4);
- if(colors == 1){
- fwColor = Color.RED;
- }else if(colors == 2){
- fwColor = Color.GREEN;
- }else if(colors == 3){
- fwColor = Color.BLUE;
- }else if(colors == 4){
- fwColor = Color.ORANGE;
- }
- }
- //randomizing firework fading colors.
- Random color2 = new Random();
- int colors2;
- Color fwColor2 = null;
- for(int counter =1; counter<=1; counter++){
- colors2 = 1+color2.nextInt(4);
- if(colors2 == 1){
- fwColor2 = Color.AQUA;
- }else if(colors2 == 2){
- fwColor2 = Color.YELLOW;
- }else if(colors2 == 3){
- fwColor2 = Color.PURPLE;
- }else if(colors2 == 4){
- fwColor2 = Color.FUCHSIA;
- }
- }
- //building the firework and launching it.
- Firework fw = (Firework) player.getWorld().spawnEntity(player.getLocation(), EntityType.FIREWORK);
- FireworkMeta fwmeta = fw.getFireworkMeta();
- FireworkEffect.Builder builder = FireworkEffect.builder();
- builder.withTrail();
- builder.withFlicker();
- builder.withFade(fwColor2);
- builder.withColor(fwColor);
- builder.with(FireworkEffect.Type.BALL_LARGE);
- fwmeta.addEffects(builder.build());
- fwmeta.setPower(2);
- fw.setFireworkMeta(fwmeta);
- }
- /*
- * The delayed task for the 15s cooldown.
- */
- public ArrayList<String> fireworks = new ArrayList<String>();
- public void fireworks(final Player player){
- getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
- public void run(){
- fireworks.remove(player.getName());
- player.sendMessage(GREEN + "You can now use /fw again!");
- }
- }, 30*20);
- }
- /*
- * When the player logs on, it checks if they have the permission easyfly.join, if so, it'll
- * set allow flight to true.
- * Also if they have the permission for easyfly.donor it'll set the joinmessage to something
- * special. And the normal join message for normal people will also be different but not
- * special.
- */
- @EventHandler(priority = EventPriority.LOWEST)
- public void onPlayerJoin(PlayerJoinEvent e){
- Player p = e.getPlayer();
- if(p.hasPermission("hub.join")){
- p.setAllowFlight(true);
- }
- if(p.hasPermission("hub.joinmessage.donor")){
- e.setJoinMessage(GOLD + p.getDisplayName() + DARK_AQUA + " has joined the lobby!");
- }
- if(p.hasPermission("hub.joinmessage.default")){
- e.setJoinMessage(DARK_GRAY + p.getDisplayName() + GRAY + " has joined the lobby!");
- }
- if(p.hasPermission("hub.joinmessage.staff")){
- e.setJoinMessage(RED + p.getDisplayName() + GOLD + " has joined the lobby!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment