Advertisement
Guest User

Untitled

a guest
Jul 4th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.67 KB | None | 0 0
  1. package bgggggg4.main;
  2.  
  3. import java.util.ArrayList;
  4. import org.bukkit.Bukkit;
  5. import org.bukkit.Location;
  6. import org.bukkit.Material;
  7. import org.bukkit.command.Command;
  8. import org.bukkit.command.CommandSender;
  9. import org.bukkit.entity.Player;
  10. import org.bukkit.event.EventHandler;
  11. import org.bukkit.event.Listener;
  12. import org.bukkit.event.block.BlockBreakEvent;
  13. import org.bukkit.event.inventory.InventoryClickEvent;
  14. import org.bukkit.event.player.PlayerMoveEvent;
  15. import org.bukkit.inventory.Inventory;
  16. import org.bukkit.inventory.ItemStack;
  17. import org.bukkit.inventory.meta.ItemMeta;
  18. import org.bukkit.plugin.PluginManager;
  19. import org.bukkit.plugin.java.JavaPlugin;
  20.  
  21. public class EndlessParkour extends JavaPlugin implements Listener {
  22.    Inventory gui;
  23.  
  24.    public void onEnable() {
  25.       this.getConfig().options().copyDefaults();
  26.       this.saveDefaultConfig();
  27.       PluginManager pluginManager = Bukkit.getServer().getPluginManager();
  28.       pluginManager.registerEvents(this, this);
  29.    }
  30.  
  31.    public void onDisable() {
  32.       this.saveDefaultConfig();
  33.    }
  34.  
  35.    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
  36.       Player p = Bukkit.getPlayer(sender.getName());
  37.       Location blockUnderPLoc = p.getLocation().subtract(0.0D, 1.0D, 0.0D);
  38.       if (label.equalsIgnoreCase("eparkour")) {
  39.          if (!this.getConfig().contains("players." + p.getUniqueId())) {
  40.             this.getConfig().set("players." + p.getUniqueId() + ".isParkour", true);
  41.             this.getConfig().set("players." + p.getUniqueId() + ".lastBlockLoc", (Object)null);
  42.             this.getConfig().set("players." + p.getUniqueId() + ".prevLastBlockLoc", (Object)null);
  43.             this.getConfig().set("players." + p.getUniqueId() + ".lastBlockMat", "STONE");
  44.             this.getConfig().set("players." + p.getUniqueId() + ".prevLastBlockMat", "STONE");
  45.             this.getConfig().set("players." + p.getUniqueId() + ".score", 0);
  46.             this.getConfig().set("players." + p.getUniqueId() + ".record", 0);
  47.             this.getConfig().set("players." + p.getUniqueId() + ".attempts", 0);
  48.             this.getConfig().set("players." + p.getUniqueId() + ".blocks", 0);
  49.          }
  50.  
  51.          this.saveConfig();
  52.          if (args.length == 1) {
  53.             if (args[0].equalsIgnoreCase("info")) {
  54.                this.gui = Bukkit.createInventory(p, 9, "§6§lEndless Parkour");
  55.                ItemStack emerald_block = new ItemStack(Material.EMERALD_BLOCK);
  56.                ItemStack glass = new ItemStack(Material.STAINED_GLASS);
  57.                ItemMeta emerald_block_meta = emerald_block.getItemMeta();
  58.                emerald_block_meta.setDisplayName("§6Information about §l" + sender.getName() + "§6:");
  59.                ArrayList<String> emb_lore = new ArrayList();
  60.                emb_lore.add("§eRecord: §l" + this.getConfig().get("players." + p.getUniqueId() + ".record"));
  61.                emb_lore.add("§eAll attempts: §l" + this.getConfig().get("players." + p.getUniqueId() + ".attempts"));
  62.                emb_lore.add("§eTotal score: §l" + this.getConfig().get("players." + p.getUniqueId() + ".blocks"));
  63.                emerald_block_meta.setLore(emb_lore);
  64.                emerald_block.setItemMeta(emerald_block_meta);
  65.                ItemStack[] menuItems = new ItemStack[]{glass, glass, glass, glass, emerald_block, glass, glass, glass, glass};
  66.                this.gui.setContents(menuItems);
  67.                p.openInventory(this.gui);
  68.                return true;
  69.             }
  70.          } else if (args.length == 0) {
  71.             this.getConfig().set("players." + p.getUniqueId() + ".isParkour", true);
  72.             this.getConfig().set("players." + p.getUniqueId() + ".score", 0);
  73.             this.getConfig().set("players." + p.getUniqueId() + ".attempts", this.getConfig().getInt("players." + p.getUniqueId() + ".attempts") + 1);
  74.             this.nextBlockCreation(blockUnderPLoc, Bukkit.getPlayer(sender.getName()));
  75.             return true;
  76.          }
  77.       }
  78.  
  79.       if (label.equalsIgnoreCase("record")) {
  80.          p.sendMessage("§6Your record is " + this.getConfig().getInt("players." + p.getUniqueId() + ".record") + " points.");
  81.          return true;
  82.       } else {
  83.          return false;
  84.       }
  85.    }
  86.  
  87.    @EventHandler
  88.    public void clickEvent(InventoryClickEvent e) {
  89.       if (e.getView().getTitle().equals("§6§lEndless Parkour")) {
  90.          e.setCancelled(true);
  91.       }
  92.  
  93.    }
  94.  
  95.    public void nextBlockCreation(Location currentPos, Player p) {
  96.       Integer nextX = (int)(Math.random() * 3.0D);
  97.       Integer nextZ = (int)(Math.random() * 3.0D);
  98.       Location prevLastBlockLoc = (Location)this.getConfig().get("players." + p.getUniqueId() + ".prevLastBlockLoc");
  99.       Material prevLastBlockMat = Material.valueOf(this.getConfig().getString("players." + p.getUniqueId() + ".prevLastBlockMat"));
  100.       if (this.getConfig().get("players." + p.getUniqueId() + ".prevLastBlockLoc") != null) {
  101.          prevLastBlockLoc.getBlock().setType(prevLastBlockMat);
  102.       }
  103.  
  104.       if (nextX == 2) {
  105.          nextX = -1;
  106.       }
  107.  
  108.       if (nextZ == 2) {
  109.          nextZ = -1;
  110.       }
  111.  
  112.       if (nextX == 0 && nextZ == 0) {
  113.          nextX = 1;
  114.       }
  115.  
  116.       nextX = nextX * 2;
  117.       nextZ = nextZ * 2;
  118.       currentPos.setX((double)(currentPos.getBlockX() + nextX));
  119.       currentPos.setZ((double)(currentPos.getBlockZ() + nextZ));
  120.       currentPos.setY((double)(currentPos.getBlockY() + 1));
  121.       this.getConfig().set("players." + p.getUniqueId() + ".prevLastBlockMat", this.getConfig().get("players." + p.getUniqueId() + ".lastBlockMat"));
  122.       this.getConfig().set("players." + p.getUniqueId() + ".lastBlockMat", currentPos.getBlock().getType().name());
  123.       currentPos.getBlock().setType(Material.STONE);
  124.       this.getConfig().set("players." + p.getUniqueId() + ".prevLastBlockLoc", this.getConfig().get("players." + p.getUniqueId() + ".lastBlockLoc"));
  125.       this.getConfig().set("players." + p.getUniqueId() + ".lastBlockLoc", currentPos);
  126.       this.getConfig().set("players." + p.getUniqueId() + ".blocks", this.getConfig().getInt("players." + p.getUniqueId() + ".blocks") + 1);
  127.       this.saveConfig();
  128.    }
  129.  
  130.    @EventHandler
  131.    public void onPlayerMove(PlayerMoveEvent e) {
  132.       Player p = e.getPlayer();
  133.       Location pLoc = p.getLocation().subtract(0.0D, 1.0D, 0.0D);
  134.       Location lastBlockLoc = (Location)this.getConfig().get("players." + p.getUniqueId() + ".lastBlockLoc");
  135.       Location blockUnderPLoc = p.getLocation().subtract(0.0D, 1.0D, 0.0D);
  136.       if (pLoc.getBlockX() == lastBlockLoc.getBlockX() && pLoc.getBlockY() == lastBlockLoc.getBlockY() && pLoc.getBlockZ() == lastBlockLoc.getBlockZ()) {
  137.          this.getConfig().set("players." + p.getUniqueId() + ".score", this.getConfig().getInt("players." + p.getUniqueId() + ".score") + 1);
  138.          if (this.getConfig().contains("rewards." + this.getConfig().getInt("players." + p.getUniqueId() + ".score"))) {
  139.             String message = this.getConfig().getString("rewards." + this.getConfig().getInt("players." + p.getUniqueId() + ".score") + ".command");
  140.             if (message.contains("%player%")) {
  141.                message = message.replace("%player%", p.getName());
  142.             }
  143.  
  144.             p.sendMessage(this.getConfig().getString("rewards." + this.getConfig().getInt("players." + p.getUniqueId() + ".score") + ".message"));
  145.             Bukkit.dispatchCommand(Bukkit.getConsoleSender(), message);
  146.          }
  147.  
  148.          p.sendMessage("§6Your score is " + this.getConfig().get("players." + p.getUniqueId() + ".score"));
  149.          this.nextBlockCreation(blockUnderPLoc, e.getPlayer());
  150.       }
  151.  
  152.       if (this.getConfig().contains("players." + p.getUniqueId() + ".isParkour") && this.getConfig().getBoolean("players." + p.getUniqueId() + ".isParkour")) {
  153.          Location lbLoc = (Location)this.getConfig().get("players." + p.getUniqueId() + ".lastBlockLoc");
  154.          if (lbLoc.getY() - p.getLocation().getY() >= 2.0D) {
  155.             this.getConfig().set("players." + p.getUniqueId() + ".isParkour", false);
  156.             p.sendMessage("§6You felt from the parkour.");
  157.             if (this.getConfig().getInt("players." + p.getUniqueId() + ".score") > this.getConfig().getInt("players." + p.getUniqueId() + ".record")) {
  158.                this.getConfig().set("players." + p.getUniqueId() + ".record", this.getConfig().getInt("players." + p.getUniqueId() + ".score"));
  159.                p.sendMessage("§aYou broke the record. Your new record is " + this.getConfig().getInt("players." + p.getUniqueId() + ".record") + " points");
  160.                this.saveConfig();
  161.             }
  162.  
  163.             Location prevLastBlockLoc = (Location)this.getConfig().get("players." + p.getUniqueId() + ".prevLastBlockLoc");
  164.             Material prevLastBlockMat = Material.valueOf(this.getConfig().getString("players." + p.getUniqueId() + ".prevLastBlockMat"));
  165.             if (this.getConfig().get("players." + p.getUniqueId() + ".prevLastBlockLoc") != null) {
  166.                prevLastBlockLoc.getBlock().setType(prevLastBlockMat);
  167.             }
  168.  
  169.             Material lastBlockMat = Material.valueOf(this.getConfig().getString("players." + p.getUniqueId() + ".lastBlockMat"));
  170.             if (this.getConfig().get("players." + p.getUniqueId() + ".lastBlockLoc") != null) {
  171.                lastBlockLoc.getBlock().setType(lastBlockMat);
  172.             }
  173.  
  174.             this.saveConfig();
  175.          }
  176.       }
  177.  
  178.    }
  179.  
  180.    @EventHandler
  181.    public void onBlockBreak(BlockBreakEvent e) {
  182.       Player p = e.getPlayer();
  183.       if (this.getConfig().contains("players." + p.getUniqueId() + ".isParkour") && this.getConfig().getBoolean("players." + p.getUniqueId() + ".isParkour")) {
  184.          e.setCancelled(true);
  185.       }
  186.  
  187.    }
  188. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement