Guest User

Code

a guest
Apr 16th, 2020
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 14.06 KB | None | 0 0
  1. package tv.hiddlebimpf.hey.spawn.main;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. import org.bukkit.Bukkit;
  6. import org.bukkit.Location;
  7. import org.bukkit.World;
  8. import org.bukkit.command.Command;
  9. import org.bukkit.command.CommandSender;
  10. import org.bukkit.entity.Player;
  11. import org.bukkit.event.EventHandler;
  12. import org.bukkit.event.Listener;
  13. import org.bukkit.event.player.PlayerJoinEvent;
  14. import org.bukkit.event.player.PlayerRespawnEvent;
  15. import org.bukkit.plugin.java.JavaPlugin;
  16.  
  17. public class Main extends JavaPlugin implements Listener {
  18.    
  19.     public static ArrayList<String> spawns = new ArrayList<>();
  20.    
  21.     public void onEnable() {
  22.         Bukkit.getConsoleSender().sendMessage("§a__________________");
  23.         Bukkit.getConsoleSender().sendMessage("§a|                |");
  24.         Bukkit.getConsoleSender().sendMessage("§a|#  #  #### #   #|");
  25.         Bukkit.getConsoleSender().sendMessage("§a|#  #  #     ### |");
  26.         Bukkit.getConsoleSender().sendMessage("§a|####  ###    #  |");
  27.         Bukkit.getConsoleSender().sendMessage("§a|#  #  #      #  |");
  28.         Bukkit.getConsoleSender().sendMessage("§a|#  #  ####   #  |");
  29.         Bukkit.getConsoleSender().sendMessage("§a|________________|");
  30.         Bukkit.getConsoleSender().sendMessage("§9This HeyPlugin is: HeySpawn version: 1.0!");
  31.         Bukkit.getConsoleSender().sendMessage("§9Developed by Hiddlebimpf_TV!");
  32.         Bukkit.getConsoleSender().sendMessage("§9Spigot: https://bit.ly/2RokrZ0 YouTube: https://bit.ly/2lVjs5w");
  33.        
  34.         Bukkit.getPluginManager().registerEvents(this, this);
  35.        
  36.         this.reloadConfig();
  37.         this.getConfig().options().header("HeySpawn Plugin by Hiddlebimpf_TV NOTE: I am German, which means that my translations do not have to be 100% correct.");
  38.         //Spawn Messages
  39.         this.getConfig().addDefault("Messages.Commands.Spawn.Success", "&8[&a&lHeySpawn&8]&a You have been&b successfully&a teleported to the spawn!");
  40.         this.getConfig().addDefault("Messages.Commands.Spawn.Syntax", "&8[&a&lHeySpawn&8]&c Please use&b /spawn&c or&b /spawn <spawn>&c!");
  41.         this.getConfig().addDefault("Messages.Commands.Spawn.Perms", "&8[&a&lHeySpawn&8]&c You have&b no&c rights to this!");
  42.         this.getConfig().addDefault("Messages.Commands.Spawn.Instance", "&8[&a&lHeySpawn&8]&c You have to be a&b player&c to do that!");
  43.         //SetSpawn Messages
  44.         this.getConfig().addDefault("Messages.Commands.SetSpawn.Success", "&8[&a&lHeySpawn&8]&a You have&b successfully&a set the spawn!");
  45.         this.getConfig().addDefault("Messages.Commands.SetSpawn.Syntax", "&8[&a&lHeySpawn&8]&c Please use&b /setspawn <spawn>&c!");
  46.         this.getConfig().addDefault("Messages.Commands.SetSpawn.Perms", "&8[&a&lHeySpawn&8]&c You have&b no&c rights to this!");
  47.         this.getConfig().addDefault("Messages.Commands.SetSpawn.Instance", "&8[&a&lHeySpawn&8]&c You have to be a&b player&c to do that!");
  48.         //SetMainSpawn Messages
  49.         this.getConfig().addDefault("Messages.Commands.SetMainSpawn.Success", "&8[&a&lHeySpawn&8]&a You have&b successfully&a set the mainspawn!");
  50.         this.getConfig().addDefault("Messages.Commands.SetMainSpawn.Syntax", "&8[&a&lHeySpawn&8]&c Please use&b /setmainspawn&c!");
  51.         this.getConfig().addDefault("Messages.Commands.SetMainSpawn.Perms", "&8[&a&lHeySpawn&8]&c You have&b no&c rights to this!");
  52.         this.getConfig().addDefault("Messages.Commands.SetMainSpawn.Instance", "&8[&a&lHeySpawn&8]&c You have to be a&b player&c to do that!");
  53.         //Permissions
  54.         this.getConfig().addDefault("Permissions.Commands.Spawn", "hey.spawn.spawn");
  55.         this.getConfig().addDefault("Permissions.Commands.SetSpawn", "hey.spawn.setspawn");
  56.         this.getConfig().addDefault("Permissions.Commands.SetMainSpawn", "hey.spawn.setmainspawn");
  57.         this.getConfig().addDefault("Permissions.SpawnOnJoin", "hey.spawn.spawnonjoin");
  58.         this.getConfig().addDefault("Permissions.SpawnOnDeath", "hey.spawn.spawnondeath");
  59.         //OtherThings
  60.         this.getConfig().options().copyDefaults(true);
  61.         this.saveConfig();
  62.    
  63. }
  64.     public void onDisable() {
  65.         Bukkit.getConsoleSender().sendMessage("§c__________________");
  66.         Bukkit.getConsoleSender().sendMessage("§c|                |");
  67.         Bukkit.getConsoleSender().sendMessage("§c|#  #  #### #   #|");
  68.         Bukkit.getConsoleSender().sendMessage("§c|#  #  #     ### |");
  69.         Bukkit.getConsoleSender().sendMessage("§c|####  ###    #  |");
  70.         Bukkit.getConsoleSender().sendMessage("§c|#  #  #      #  |");
  71.         Bukkit.getConsoleSender().sendMessage("§c|#  #  ####   #  |");
  72.         Bukkit.getConsoleSender().sendMessage("§c|________________|");
  73.         Bukkit.getConsoleSender().sendMessage("§9This HeyPlugin is: HeySpawn version: 1.0!");
  74.         Bukkit.getConsoleSender().sendMessage("§9Developed by Hiddlebimpf_TV!");
  75.         Bukkit.getConsoleSender().sendMessage("§9Spigot: https://bit.ly/2RokrZ0 YouTube: https://bit.ly/2lVjs5w");
  76.        
  77. }
  78.     @EventHandler
  79.     public void onJoin(PlayerJoinEvent e) {
  80.         Player p = e.getPlayer();
  81.             if(p.hasPermission(this.getConfig().getString("Permissions.SpawnOnJoin"))) {
  82.                 final World mainworld = Bukkit.getWorld(this.getConfig().getString("MainSpawn.World"));
  83.                 final double mainx = this.getConfig().getDouble("MainSpawn.X");
  84.                 final double mainy = this.getConfig().getDouble("MainSpawn.Y");
  85.                 final double mainz = this.getConfig().getDouble("MainSpawn.Z");
  86.                 final float mainyaw = (float) this.getConfig().getDouble("MainSpawn.Yaw");
  87.                 final float mainpitch = (float)this.getConfig().getDouble("MainSpawn.Pitch");
  88.                 final Location mainspawnlocation = new Location(mainworld, mainx, mainy, mainz, mainyaw, mainpitch);
  89.                 p.teleport(mainspawnlocation);
  90.                
  91. }
  92. }
  93.             @EventHandler
  94.             public void onRespawn(PlayerRespawnEvent e) {
  95.                 Player p = e.getPlayer();
  96.                     if(p.hasPermission(this.getConfig().getString("Permissions.SpawnOnDeath"))) {
  97.                         final World mainworld = Bukkit.getWorld(this.getConfig().getString("MainSpawn.World"));
  98.                         final double mainx = this.getConfig().getDouble("MainSpawn.X");
  99.                         final double mainy = this.getConfig().getDouble("MainSpawn.Y");
  100.                         final double mainz = this.getConfig().getDouble("MainSpawn.Z");
  101.                         final float mainyaw = (float) this.getConfig().getDouble("MainSpawn.Yaw");
  102.                         final float mainpitch = (float)this.getConfig().getDouble("MainSpawn.Pitch");
  103.                         final Location mainspawnlocation = new Location(mainworld, mainx, mainy, mainz, mainyaw, mainpitch);
  104.                         e.setRespawnLocation(mainspawnlocation);
  105.                        
  106. }
  107. }
  108.     public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
  109.         Player p = (Player) sender;
  110.        
  111.         String Message1 = this.getConfig().getString("Messages.Commands.SetSpawn.Success").replaceAll("&", "§");
  112.         String Message2 = this.getConfig().getString("Messages.Commands.SetSpawn.Syntax").replaceAll("&", "§");
  113.         String Message3 = this.getConfig().getString("Messages.Commands.SetSpawn.Perms").replaceAll("&", "§");
  114.         String Message4 = this.getConfig().getString("Messages.Commands.SetSpawn.Instance").replaceAll("&", "§");
  115.         String Message5 = this.getConfig().getString("Messages.Commands.SetMainSpawn.Success").replaceAll("&", "§");
  116.         String Message6 = this.getConfig().getString("Messages.Commands.SetMainSpawn.Syntax").replaceAll("&", "§");
  117.         String Message7 = this.getConfig().getString("Messages.Commands.SetMainSpawn.Perms").replaceAll("&", "§");
  118.         String Message8 = this.getConfig().getString("Messages.Commands.SetMainSpawn.Instance").replaceAll("&", "§");
  119.         String Message9 = this.getConfig().getString("Messages.Commands.Spawn.Success").replaceAll("&", "§");
  120.         String Message10 = this.getConfig().getString("Messages.Commands.Spawn.Syntax").replaceAll("&", "§");
  121.         String Message11 = this.getConfig().getString("Messages.Commands.Spawn.Perms").replaceAll("&", "§");
  122.         String Message12 = this.getConfig().getString("Messages.Commands.Spawn.Instance").replaceAll("&", "§");
  123.        
  124.             if(cmd.getName().equalsIgnoreCase("setspawn")) {
  125.                     if(sender instanceof Player) {
  126.                         if(p.hasPermission(this.getConfig().getString("Permissions.Commands.SetSpawn"))) {
  127.                             if(args.length == 1) {
  128.                                 this.getConfig().set(args[0] + ".World", p.getWorld().getName());
  129.                                 this.getConfig().set(args[0] + ".X", p.getLocation().getX());
  130.                                 this.getConfig().set(args[0] + ".Y", p.getLocation().getY());
  131.                                 this.getConfig().set(args[0] + ".Z", p.getLocation().getZ());
  132.                                 this.getConfig().set(args[0] + ".Yaw", p.getLocation().getYaw());
  133.                                 this.getConfig().set(args[0] + ".Pitch", p.getLocation().getPitch());
  134.                                 this.saveConfig();
  135.                                 spawns.add(args[0]);
  136.                                 p.sendMessage(Message1);
  137.                            
  138. }else
  139.     p.sendMessage(Message2);
  140.    
  141. }else
  142.     p.sendMessage(Message3);
  143.                        
  144. }else
  145.     p.sendMessage(Message4);
  146.                    
  147. }
  148.             if(cmd.getName().equalsIgnoreCase("setmainspawn")) {
  149.                 if(sender instanceof Player) {
  150.                     if(p.hasPermission(this.getConfig().getString("Permissions.Commands.SetMainSpawn"))) {
  151.                         if(args.length == 0) {
  152.                             this.getConfig().set("MainSpawn.World", p.getWorld().getName());
  153.                             this.getConfig().set("MainSpawn.X", p.getLocation().getX());
  154.                             this.getConfig().set("MainSpawn.Y", p.getLocation().getY());
  155.                             this.getConfig().set("MainSpawn.Z", p.getLocation().getZ());
  156.                             this.getConfig().set("MainSpawn.Yaw", p.getLocation().getYaw());
  157.                             this.getConfig().set("MainSpawn.Pitch", p.getLocation().getPitch());
  158.                             this.getConfig().options().copyDefaults(true);
  159.                             this.saveConfig();
  160.                             p.sendMessage(Message5);
  161.    
  162. }else
  163.     p.sendMessage(Message6);
  164.                            
  165. }else
  166.     p.sendMessage(Message7);
  167.                                                
  168. }else
  169.     p.sendMessage(Message8);
  170.                                        
  171. }
  172.             if(cmd.getName().equalsIgnoreCase("spawn")) {
  173.                 if(sender instanceof Player) {
  174.                     if(p.hasPermission(this.getConfig().getString("Permissions.Commands.Spawn"))) {
  175.                         if(args.length == 0) {
  176.                             final World mainworld = Bukkit.getWorld(this.getConfig().getString("MainSpawn.World"));
  177.                             final double mainx = this.getConfig().getDouble("MainSpawn.X");
  178.                             final double mainy = this.getConfig().getDouble("MainSpawn.Y");
  179.                             final double mainz = this.getConfig().getDouble("MainSpawn.Z");
  180.                             final float mainyaw = (float) this.getConfig().getDouble("MainSpawn.Yaw");
  181.                             final float mainpitch = (float)this.getConfig().getDouble("MainSpawn.Pitch");
  182.                             final Location mainspawnlocation = new Location(mainworld, mainx, mainy, mainz, mainyaw, mainpitch);
  183.                             Bukkit.getConsoleSender().getServer().dispatchCommand(Bukkit.getConsoleSender(), "setworldspawn" + mainspawnlocation);
  184.                             p.teleport(mainspawnlocation);
  185.                             p.sendMessage(Message9);
  186.                            
  187.                         }else if(args.length == 1) {
  188.                            
  189.                             final World world = Bukkit.getWorld(this.getConfig().getString(args[0] + ".World"));
  190.                             final double x = this.getConfig().getDouble(args[0] + ".X");
  191.                             final double y = this.getConfig().getDouble(args[0] + ".Y");
  192.                             final double z = this.getConfig().getDouble(args[0] + ".Z");
  193.                             final float yaw = (float) this.getConfig().getDouble(args[0] + ".Yaw");
  194.                             final float pitch = (float)this.getConfig().getDouble(args[0] + ".Pitch");
  195.                             final Location location = new Location(world, x, y, z, yaw, pitch);
  196.                             p.teleport(location);
  197.                             p.sendMessage(Message9);
  198.                            
  199. }else
  200.     p.sendMessage(Message10);
  201.                                                    
  202. }else
  203.     p.sendMessage(Message11);
  204.                                                                        
  205. }else
  206.     p.sendMessage(Message12);
  207.            
  208.                
  209.             if(cmd.getName().equalsIgnoreCase("heyspawn")) {
  210.                 if(sender instanceof Player) {
  211.                     p.sendMessage(" ");
  212.                     p.sendMessage("§a#   #  #### #   #");
  213.                     p.sendMessage("§a#   #  #      ### ");
  214.                     p.sendMessage("§a####  ###     #  ");
  215.                     p.sendMessage("§a#   #  #        #  ");
  216.                     p.sendMessage("§a#   #  ####   #  ");
  217.                     p.sendMessage(" ");
  218.                     p.sendMessage("§9This HeyPlugin is: HeySpawn version: 1.0!");
  219.                     p.sendMessage("§9Developed by Hiddlebimpf_TV!");
  220.                     p.sendMessage("§9Spigot: https://bit.ly/2RokrZ0 YouTube: https://bit.ly/2lVjs5w");
  221.                     p.sendMessage("§cType§b /heyspawnhelp§c for help!");
  222.        
  223. }else
  224.     Bukkit.getConsoleSender().sendMessage("§8[§a§lHeySpawn§8] &8[&a&lHeySpawn&8]&c You have to be a&b player&c to do that!");
  225.            
  226. }
  227.             if(cmd.getName().equalsIgnoreCase("heyspawnhelp")) {       
  228.                 if(sender instanceof Player) {
  229.                     if(p.hasPermission("hey.spawn.help")) {
  230.                         p.sendMessage("§aHelp for HeySpawn:");
  231.                         p.sendMessage("§aPermissions are customizable in Config.yml!");
  232.                         p.sendMessage("§b/spawn§a | Teleports you to the mainspawn! ");
  233.                         p.sendMessage("§b/spawn <spawn>§a | Teleports you to the spawn <spawn>!");
  234.                         p.sendMessage("§b/setspawn <spawn>§a | Sets a the spawn <spawn>!");
  235.                         p.sendMessage("§b/setmainspawn§a | Sets the mainspawn!");
  236.                         p.sendMessage("§b/heyspawn§a | Shows you information about this plugin!");
  237.                         p.sendMessage("§b/heyspawnhelp§a | Shows you all commands form the plugin!");
  238.                         p.sendMessage("§b/heyspawnreload§a | Reloads the plugin!");
  239.                        
  240. }else
  241.     p.sendMessage("&8[&a&lHeySpawn&8]&c You have&b no&c rights to this!");
  242.                    
  243. }else
  244.     Bukkit.getConsoleSender().sendMessage("§8[§a§lHeySpawn§8] &8[&a&lHeySpawn&8]&c You have to be a&b player&c to do that!");
  245.                
  246. }
  247.             if(cmd.getName().equalsIgnoreCase("heyspawnreload")) {     
  248.                 if(sender instanceof Player) {
  249.                     if(p.hasPermission("hey.spawn.help")) {
  250.                         Bukkit.getPluginManager().disablePlugin(this);
  251.                         Bukkit.getPluginManager().enablePlugin(this);
  252.                         p.sendMessage("§8[§a§lHeySpawn§8]§a The plugin reloaded§b successfull§a!");
  253.                        
  254. }else
  255.     p.sendMessage("&8[&a&lHeySpawn&8]&c You have&b no&c rights to this!");
  256.                    
  257. }else
  258.     Bukkit.getConsoleSender().sendMessage("§8[§a§lHeySpawn§8] &8[&a&lHeySpawn&8]&c You have to be a&b player&c to do that!");
  259.                                    
  260. }
  261. }
  262.             return false;
  263. }
  264. }
Add Comment
Please, Sign In to add comment