Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package bgggggg4.main;
- import java.util.ArrayList;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.block.BlockBreakEvent;
- import org.bukkit.event.inventory.InventoryClickEvent;
- import org.bukkit.event.player.PlayerMoveEvent;
- import org.bukkit.inventory.Inventory;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.meta.ItemMeta;
- import org.bukkit.plugin.PluginManager;
- import org.bukkit.plugin.java.JavaPlugin;
- public class EndlessParkour extends JavaPlugin implements Listener {
- Inventory gui;
- public void onEnable() {
- this.getConfig().options().copyDefaults();
- this.saveDefaultConfig();
- PluginManager pluginManager = Bukkit.getServer().getPluginManager();
- pluginManager.registerEvents(this, this);
- }
- public void onDisable() {
- this.saveDefaultConfig();
- }
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
- Player p = Bukkit.getPlayer(sender.getName());
- Location blockUnderPLoc = p.getLocation().subtract(0.0D, 1.0D, 0.0D);
- if (label.equalsIgnoreCase("eparkour")) {
- if (!this.getConfig().contains("players." + p.getUniqueId())) {
- this.getConfig().set("players." + p.getUniqueId() + ".isParkour", true);
- this.getConfig().set("players." + p.getUniqueId() + ".lastBlockLoc", (Object)null);
- this.getConfig().set("players." + p.getUniqueId() + ".prevLastBlockLoc", (Object)null);
- this.getConfig().set("players." + p.getUniqueId() + ".lastBlockMat", "STONE");
- this.getConfig().set("players." + p.getUniqueId() + ".prevLastBlockMat", "STONE");
- this.getConfig().set("players." + p.getUniqueId() + ".score", 0);
- this.getConfig().set("players." + p.getUniqueId() + ".record", 0);
- this.getConfig().set("players." + p.getUniqueId() + ".attempts", 0);
- this.getConfig().set("players." + p.getUniqueId() + ".blocks", 0);
- }
- this.saveConfig();
- if (args.length == 1) {
- if (args[0].equalsIgnoreCase("info")) {
- this.gui = Bukkit.createInventory(p, 9, "§6§lEndless Parkour");
- ItemStack emerald_block = new ItemStack(Material.EMERALD_BLOCK);
- ItemStack glass = new ItemStack(Material.STAINED_GLASS);
- ItemMeta emerald_block_meta = emerald_block.getItemMeta();
- emerald_block_meta.setDisplayName("§6Information about §l" + sender.getName() + "§6:");
- ArrayList<String> emb_lore = new ArrayList();
- emb_lore.add("§eRecord: §l" + this.getConfig().get("players." + p.getUniqueId() + ".record"));
- emb_lore.add("§eAll attempts: §l" + this.getConfig().get("players." + p.getUniqueId() + ".attempts"));
- emb_lore.add("§eTotal score: §l" + this.getConfig().get("players." + p.getUniqueId() + ".blocks"));
- emerald_block_meta.setLore(emb_lore);
- emerald_block.setItemMeta(emerald_block_meta);
- ItemStack[] menuItems = new ItemStack[]{glass, glass, glass, glass, emerald_block, glass, glass, glass, glass};
- this.gui.setContents(menuItems);
- p.openInventory(this.gui);
- return true;
- }
- } else if (args.length == 0) {
- this.getConfig().set("players." + p.getUniqueId() + ".isParkour", true);
- this.getConfig().set("players." + p.getUniqueId() + ".score", 0);
- this.getConfig().set("players." + p.getUniqueId() + ".attempts", this.getConfig().getInt("players." + p.getUniqueId() + ".attempts") + 1);
- this.nextBlockCreation(blockUnderPLoc, Bukkit.getPlayer(sender.getName()));
- return true;
- }
- }
- if (label.equalsIgnoreCase("record")) {
- p.sendMessage("§6Your record is " + this.getConfig().getInt("players." + p.getUniqueId() + ".record") + " points.");
- return true;
- } else {
- return false;
- }
- }
- @EventHandler
- public void clickEvent(InventoryClickEvent e) {
- if (e.getView().getTitle().equals("§6§lEndless Parkour")) {
- e.setCancelled(true);
- }
- }
- public void nextBlockCreation(Location currentPos, Player p) {
- Integer nextX = (int)(Math.random() * 3.0D);
- Integer nextZ = (int)(Math.random() * 3.0D);
- Location prevLastBlockLoc = (Location)this.getConfig().get("players." + p.getUniqueId() + ".prevLastBlockLoc");
- Material prevLastBlockMat = Material.valueOf(this.getConfig().getString("players." + p.getUniqueId() + ".prevLastBlockMat"));
- if (this.getConfig().get("players." + p.getUniqueId() + ".prevLastBlockLoc") != null) {
- prevLastBlockLoc.getBlock().setType(prevLastBlockMat);
- }
- if (nextX == 2) {
- nextX = -1;
- }
- if (nextZ == 2) {
- nextZ = -1;
- }
- if (nextX == 0 && nextZ == 0) {
- nextX = 1;
- }
- nextX = nextX * 2;
- nextZ = nextZ * 2;
- currentPos.setX((double)(currentPos.getBlockX() + nextX));
- currentPos.setZ((double)(currentPos.getBlockZ() + nextZ));
- currentPos.setY((double)(currentPos.getBlockY() + 1));
- this.getConfig().set("players." + p.getUniqueId() + ".prevLastBlockMat", this.getConfig().get("players." + p.getUniqueId() + ".lastBlockMat"));
- this.getConfig().set("players." + p.getUniqueId() + ".lastBlockMat", currentPos.getBlock().getType().name());
- currentPos.getBlock().setType(Material.STONE);
- this.getConfig().set("players." + p.getUniqueId() + ".prevLastBlockLoc", this.getConfig().get("players." + p.getUniqueId() + ".lastBlockLoc"));
- this.getConfig().set("players." + p.getUniqueId() + ".lastBlockLoc", currentPos);
- this.getConfig().set("players." + p.getUniqueId() + ".blocks", this.getConfig().getInt("players." + p.getUniqueId() + ".blocks") + 1);
- this.saveConfig();
- }
- @EventHandler
- public void onPlayerMove(PlayerMoveEvent e) {
- Player p = e.getPlayer();
- Location pLoc = p.getLocation().subtract(0.0D, 1.0D, 0.0D);
- Location lastBlockLoc = (Location)this.getConfig().get("players." + p.getUniqueId() + ".lastBlockLoc");
- Location blockUnderPLoc = p.getLocation().subtract(0.0D, 1.0D, 0.0D);
- if (pLoc.getBlockX() == lastBlockLoc.getBlockX() && pLoc.getBlockY() == lastBlockLoc.getBlockY() && pLoc.getBlockZ() == lastBlockLoc.getBlockZ()) {
- this.getConfig().set("players." + p.getUniqueId() + ".score", this.getConfig().getInt("players." + p.getUniqueId() + ".score") + 1);
- if (this.getConfig().contains("rewards." + this.getConfig().getInt("players." + p.getUniqueId() + ".score"))) {
- String message = this.getConfig().getString("rewards." + this.getConfig().getInt("players." + p.getUniqueId() + ".score") + ".command");
- if (message.contains("%player%")) {
- message = message.replace("%player%", p.getName());
- }
- p.sendMessage(this.getConfig().getString("rewards." + this.getConfig().getInt("players." + p.getUniqueId() + ".score") + ".message"));
- Bukkit.dispatchCommand(Bukkit.getConsoleSender(), message);
- }
- p.sendMessage("§6Your score is " + this.getConfig().get("players." + p.getUniqueId() + ".score"));
- this.nextBlockCreation(blockUnderPLoc, e.getPlayer());
- }
- if (this.getConfig().contains("players." + p.getUniqueId() + ".isParkour") && this.getConfig().getBoolean("players." + p.getUniqueId() + ".isParkour")) {
- Location lbLoc = (Location)this.getConfig().get("players." + p.getUniqueId() + ".lastBlockLoc");
- if (lbLoc.getY() - p.getLocation().getY() >= 2.0D) {
- this.getConfig().set("players." + p.getUniqueId() + ".isParkour", false);
- p.sendMessage("§6You felt from the parkour.");
- if (this.getConfig().getInt("players." + p.getUniqueId() + ".score") > this.getConfig().getInt("players." + p.getUniqueId() + ".record")) {
- this.getConfig().set("players." + p.getUniqueId() + ".record", this.getConfig().getInt("players." + p.getUniqueId() + ".score"));
- p.sendMessage("§aYou broke the record. Your new record is " + this.getConfig().getInt("players." + p.getUniqueId() + ".record") + " points");
- this.saveConfig();
- }
- Location prevLastBlockLoc = (Location)this.getConfig().get("players." + p.getUniqueId() + ".prevLastBlockLoc");
- Material prevLastBlockMat = Material.valueOf(this.getConfig().getString("players." + p.getUniqueId() + ".prevLastBlockMat"));
- if (this.getConfig().get("players." + p.getUniqueId() + ".prevLastBlockLoc") != null) {
- prevLastBlockLoc.getBlock().setType(prevLastBlockMat);
- }
- Material lastBlockMat = Material.valueOf(this.getConfig().getString("players." + p.getUniqueId() + ".lastBlockMat"));
- if (this.getConfig().get("players." + p.getUniqueId() + ".lastBlockLoc") != null) {
- lastBlockLoc.getBlock().setType(lastBlockMat);
- }
- this.saveConfig();
- }
- }
- }
- @EventHandler
- public void onBlockBreak(BlockBreakEvent e) {
- Player p = e.getPlayer();
- if (this.getConfig().contains("players." + p.getUniqueId() + ".isParkour") && this.getConfig().getBoolean("players." + p.getUniqueId() + ".isParkour")) {
- e.setCancelled(true);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement