Swallowed The Button Rebirth
ahhhh, the good old first project of mine. I can smell the bad code from here
This commit is contained in:
parent
c802d8db9b
commit
48a30f8c7f
11 changed files with 900 additions and 2 deletions
|
@ -4,7 +4,7 @@ version: 2.0.1
|
||||||
|
|
||||||
commands:
|
commands:
|
||||||
flairme:
|
flairme:
|
||||||
description: Activates the Flair Me Command. Ask Ali, she was fucking tired when writing this description
|
description: Activates the Flair Me Command. Ask Ali, she was tired when writing this description
|
||||||
gpower:
|
gpower:
|
||||||
description: Testing command for ghostie powers
|
description: Testing command for ghostie powers
|
||||||
powerup:
|
powerup:
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package alisolarflare.components.flairdoor.commands;
|
package graveyard.shulker;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
|
@ -0,0 +1,70 @@
|
||||||
|
package graveyard.shulker.thebuttonrebirth;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import graveyard.shulker.thebuttonrebirth.admin.CreateShrine;
|
||||||
|
import graveyard.shulker.thebuttonrebirth.listeners.CyclicalDisplayListener;
|
||||||
|
import graveyard.shulker.thebuttonrebirth.listeners.MidnightListener;
|
||||||
|
import graveyard.shulker.thebuttonrebirth.listeners.StealChestListener;
|
||||||
|
|
||||||
|
public class ButtonRebirthPlugin extends JavaPlugin{
|
||||||
|
public PluginDescriptionFile pdfFile;
|
||||||
|
public Logger logger;
|
||||||
|
|
||||||
|
public List<Player> compactRequest = new ArrayList<Player>();
|
||||||
|
public List<Player> barsHidden = new ArrayList<Player>();
|
||||||
|
public CyclicalDisplayListener cyclicalDisplayListener;
|
||||||
|
|
||||||
|
public void onEnable(){
|
||||||
|
//Logs "Plugin Enabled:
|
||||||
|
pdfFile = getDescription();
|
||||||
|
logger = getLogger();
|
||||||
|
|
||||||
|
|
||||||
|
logger.info(pdfFile.getName() + " has been started (V." + pdfFile.getVersion()+ ").");
|
||||||
|
|
||||||
|
registerCommands();
|
||||||
|
registerEvents();
|
||||||
|
|
||||||
|
logger.info(pdfFile.getName() + " has been Enabled (V." + pdfFile.getVersion()+ ").");
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onDisable(){
|
||||||
|
logger.info(pdfFile.getName() + " has been Disabled (V." + pdfFile.getVersion()+ ").");
|
||||||
|
}
|
||||||
|
private void registerCommands(){
|
||||||
|
//Button
|
||||||
|
getCommand("createShrine").setExecutor(new CreateShrine(this));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerEvents(){
|
||||||
|
//INIT - Listeners
|
||||||
|
MidnightListener midnightListener = new MidnightListener(this);
|
||||||
|
cyclicalDisplayListener = new CyclicalDisplayListener(this);
|
||||||
|
StealChestListener stealChestListener = new StealChestListener(this);
|
||||||
|
|
||||||
|
//REGISTER - Listeners
|
||||||
|
getServer().getPluginManager().registerEvents(midnightListener, this);
|
||||||
|
getServer().getPluginManager().registerEvents(cyclicalDisplayListener,this);
|
||||||
|
getServer().getPluginManager().registerEvents(stealChestListener, this);
|
||||||
|
|
||||||
|
}
|
||||||
|
public void createShrine(){
|
||||||
|
int chestX = this.getConfig().getInt("chestX");
|
||||||
|
int chestY = this.getConfig().getInt("chestY");
|
||||||
|
int chestZ = this.getConfig().getInt("chestZ");
|
||||||
|
|
||||||
|
CreateShrine shrineCreator = new CreateShrine(this);
|
||||||
|
shrineCreator.createShrine(chestX, chestY, chestZ, 10, Material.BEDROCK);
|
||||||
|
}
|
||||||
|
}
|
128
src/graveyard/shulker/thebuttonrebirth/admin/CreateShrine.java
Normal file
128
src/graveyard/shulker/thebuttonrebirth/admin/CreateShrine.java
Normal file
|
@ -0,0 +1,128 @@
|
||||||
|
package graveyard.shulker.thebuttonrebirth.admin;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import graveyard.shulker.thebuttonrebirth.ButtonRebirthPlugin;
|
||||||
|
import net.md_5.bungee.api.ChatColor;
|
||||||
|
|
||||||
|
public class CreateShrine implements CommandExecutor{
|
||||||
|
|
||||||
|
private ButtonRebirthPlugin plugin;
|
||||||
|
private World world;
|
||||||
|
|
||||||
|
private int chestX;
|
||||||
|
private int chestY;
|
||||||
|
private int chestZ;
|
||||||
|
private int shrineRadius;
|
||||||
|
|
||||||
|
public CreateShrine(ButtonRebirthPlugin initPlugin){
|
||||||
|
plugin = initPlugin;
|
||||||
|
world = plugin.getServer().getWorld(plugin.getConfig().getString("world"));
|
||||||
|
chestX = plugin.getConfig().getInt("chestX");
|
||||||
|
chestY = plugin.getConfig().getInt("chestY");
|
||||||
|
chestZ = plugin.getConfig().getInt("chestZ");
|
||||||
|
shrineRadius = plugin.getConfig().getInt("shrineRadius");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createCube(int x, int y, int z, int radius, Material material){
|
||||||
|
//Creates a Cube under the Pyramid under the Chest
|
||||||
|
|
||||||
|
//---Parameters---
|
||||||
|
//Accepts x,y,z coordinates of the top center face, radius from center to edge, and BlockType
|
||||||
|
//Blocks placed by Radius does not include center block
|
||||||
|
//radius = 0 creates a single block
|
||||||
|
//radius = 1 creates a 9x9 cube
|
||||||
|
//Places down the cube
|
||||||
|
|
||||||
|
//---Variables---
|
||||||
|
//layer variable: layer being worked on, from the top
|
||||||
|
//layer[0] = top layer of cube
|
||||||
|
//layer[height] = bottom layer of cube
|
||||||
|
//row variable: relative value from center
|
||||||
|
//column variable:relative value from center
|
||||||
|
for (int layer = 0; layer <= radius; layer++){
|
||||||
|
for (int row = -radius; row <= radius; row++){
|
||||||
|
for (int column = -radius; column <= radius; column++){
|
||||||
|
world.getBlockAt(x+row,y-layer,z+column).setType(material);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void createPyramid(int x, int y, int z, int height, Material material){
|
||||||
|
//creates a pyramid under the chest
|
||||||
|
|
||||||
|
//sets the Top Block
|
||||||
|
//Places down the rest of the layers
|
||||||
|
//layer variable: layer being worked on, from the top
|
||||||
|
//layer[0] = top block of pyramid
|
||||||
|
//row variable: relative value from center
|
||||||
|
//column variable:relative value from center
|
||||||
|
|
||||||
|
//SET - top block, rest of the blocks
|
||||||
|
world.getBlockAt(x,y,z).setType(material);
|
||||||
|
for (int layer = 1; layer < height; layer++){
|
||||||
|
int radius = layer;
|
||||||
|
for (int row = -radius; row <= radius; row++){
|
||||||
|
for (int column = -radius; column <= radius; column++){
|
||||||
|
world.getBlockAt(x+row,y-layer,z+column).setType(material);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createShrine(int x, int y, int z, int radius, Material material){
|
||||||
|
//Creates Chest
|
||||||
|
world.getBlockAt(x, y, z).setType(Material.CHEST);
|
||||||
|
createPyramid(x, y-1, z, radius, material);
|
||||||
|
createCube(x, y-radius-1, z, radius, material);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
if (sender instanceof Player){
|
||||||
|
sender.sendMessage("You can't be a player to use this command");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try{
|
||||||
|
world = plugin.getServer().getWorld(plugin.getConfig().getString("world"));
|
||||||
|
}catch(Exception e){
|
||||||
|
//Sends Error message to the Player
|
||||||
|
sender.sendMessage("Error in CreateShrine Class: No world defined in config...");
|
||||||
|
sender.sendMessage("Defining world based on player location.");
|
||||||
|
|
||||||
|
/*
|
||||||
|
//Changes world variable in config file
|
||||||
|
if (sender instanceof Player){
|
||||||
|
Player player = (Player) sender;
|
||||||
|
plugin.getConfig().set("world", player.getWorld().getName());
|
||||||
|
plugin.saveConfig();
|
||||||
|
world = player.getWorld();
|
||||||
|
|
||||||
|
//Sends player the result of the change
|
||||||
|
sender.sendMessage("World variable set to " + player.getWorld().getName() + "in config file");
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
if (!(player.hasPermission("Moderator") || player.hasPermission("Admin"))){
|
||||||
|
player.sendMessage(ChatColor.RED + "You must be in the group Moderator or Admin to access this command!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
chestX = plugin.getConfig().getInt("chestX");
|
||||||
|
chestY = plugin.getConfig().getInt("chestY");
|
||||||
|
chestZ = plugin.getConfig().getInt("chestZ");
|
||||||
|
shrineRadius = plugin.getConfig().getInt("shrineRadius");
|
||||||
|
|
||||||
|
createShrine(chestX,chestY,chestZ,shrineRadius, Material.BEDROCK);
|
||||||
|
sender.sendMessage(ChatColor.AQUA + "Everything worked!");
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
package graveyard.shulker.thebuttonrebirth.commands;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import graveyard.shulker.thebuttonrebirth.ButtonRebirthPlugin;
|
||||||
|
|
||||||
|
|
||||||
|
public class ShowBars implements CommandExecutor{
|
||||||
|
private ButtonRebirthPlugin plugin;
|
||||||
|
|
||||||
|
public ShowBars(ButtonRebirthPlugin initPlugin){
|
||||||
|
plugin = initPlugin;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
|
||||||
|
if (!(sender instanceof Player)) {
|
||||||
|
sender.sendMessage("You must be a player to use this command");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player player = (Player) sender;
|
||||||
|
plugin.barsHidden.remove(player);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package graveyard.shulker.thebuttonrebirth.listeners;
|
||||||
|
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
|
import graveyard.shulker.thebuttonrebirth.ButtonRebirthPlugin;
|
||||||
|
import graveyard.shulker.thebuttonrebirth.tasks.CyclicalDisplayTask;
|
||||||
|
|
||||||
|
public class CyclicalDisplayListener implements Listener{
|
||||||
|
private final ButtonRebirthPlugin plugin;
|
||||||
|
public CyclicalDisplayTask cyclicalDisplayTask;
|
||||||
|
public BukkitTask bukkitTask;
|
||||||
|
|
||||||
|
public CyclicalDisplayListener (ButtonRebirthPlugin initPlugin){
|
||||||
|
plugin = initPlugin;
|
||||||
|
cyclicalDisplayTask = new CyclicalDisplayTask (this.plugin);
|
||||||
|
bukkitTask = cyclicalDisplayTask.runTaskTimer(this.plugin, 20, 20);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package graveyard.shulker.thebuttonrebirth.listeners;
|
||||||
|
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
|
import graveyard.shulker.thebuttonrebirth.ButtonRebirthPlugin;
|
||||||
|
import graveyard.shulker.thebuttonrebirth.tasks.CheckChestTask;
|
||||||
|
|
||||||
|
|
||||||
|
public class MidnightListener implements Listener{
|
||||||
|
private final ButtonRebirthPlugin plugin;
|
||||||
|
public BukkitTask checkChestTask;
|
||||||
|
|
||||||
|
public MidnightListener(ButtonRebirthPlugin initPlugin){
|
||||||
|
plugin = initPlugin;
|
||||||
|
|
||||||
|
checkChestTask = new CheckChestTask(this.plugin).runTaskTimer(this.plugin, 20, 60);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package graveyard.shulker.thebuttonrebirth.listeners;
|
||||||
|
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
|
import graveyard.shulker.thebuttonrebirth.ButtonRebirthPlugin;
|
||||||
|
import graveyard.shulker.thebuttonrebirth.tasks.StealChestTask;
|
||||||
|
|
||||||
|
|
||||||
|
public class StealChestListener implements Listener{
|
||||||
|
private final ButtonRebirthPlugin plugin;
|
||||||
|
public BukkitTask stealChestTask;
|
||||||
|
|
||||||
|
public StealChestListener(ButtonRebirthPlugin initPlugin){
|
||||||
|
plugin = initPlugin;
|
||||||
|
stealChestTask = new StealChestTask(this.plugin).runTaskTimer(this.plugin, 20, 20);
|
||||||
|
}
|
||||||
|
}
|
169
src/graveyard/shulker/thebuttonrebirth/tasks/CheckChestTask.java
Normal file
169
src/graveyard/shulker/thebuttonrebirth/tasks/CheckChestTask.java
Normal file
|
@ -0,0 +1,169 @@
|
||||||
|
package graveyard.shulker.thebuttonrebirth.tasks;
|
||||||
|
|
||||||
|
import java.time.Clock;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.Chest;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
import graveyard.shulker.thebuttonrebirth.ButtonRebirthPlugin;
|
||||||
|
import graveyard.shulker.thebuttonrebirth.admin.CreateShrine;
|
||||||
|
|
||||||
|
public class CheckChestTask extends BukkitRunnable{
|
||||||
|
//Plugin
|
||||||
|
private final ButtonRebirthPlugin BRplugin;
|
||||||
|
private World world;
|
||||||
|
|
||||||
|
//Chest
|
||||||
|
private int chestX;
|
||||||
|
private int chestY;
|
||||||
|
private int chestZ;
|
||||||
|
private Block chestBlock;
|
||||||
|
private Chest shrineChest;
|
||||||
|
private Inventory shrineInventory;
|
||||||
|
|
||||||
|
//Time
|
||||||
|
private LocalDateTime currentTime;
|
||||||
|
private LocalDateTime configTime;
|
||||||
|
|
||||||
|
private int minimumDiamondBlocks;
|
||||||
|
private int diamondsInserted;
|
||||||
|
|
||||||
|
public CheckChestTask(ButtonRebirthPlugin initBRplugin){
|
||||||
|
//INIT - plugin
|
||||||
|
this.BRplugin = initBRplugin;
|
||||||
|
|
||||||
|
//INIT - chestX, chestY, chestZ
|
||||||
|
chestX = BRplugin.getConfig().getInt("chestX");
|
||||||
|
chestY = BRplugin.getConfig().getInt("chestY");
|
||||||
|
chestZ = BRplugin.getConfig().getInt("chestZ");
|
||||||
|
|
||||||
|
//INIT - World
|
||||||
|
world = BRplugin.getServer().getWorld(BRplugin.getConfig().getString("world"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(){
|
||||||
|
//run() activates every 20 server ticks.
|
||||||
|
|
||||||
|
//CHECK - Plugin is Enabled
|
||||||
|
if (BRplugin.isEnabled() == false){
|
||||||
|
this.cancel();
|
||||||
|
}
|
||||||
|
//CHECK - World Exists
|
||||||
|
if (!(BRplugin.getServer().getWorlds().contains(BRplugin.getServer().getWorld(BRplugin.getConfig().getString("world"))))) {
|
||||||
|
BRplugin.logger.info("Error: Config world does not exist in Server.");
|
||||||
|
BRplugin.logger.info("Server Worlds: " + BRplugin.getServer().getWorlds().toString());
|
||||||
|
BRplugin.logger.info("Config World: " + BRplugin.getConfig().getString("world"));
|
||||||
|
BRplugin.logger.info("Turning off Display...");
|
||||||
|
this.cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//INIT - currentTime, configTime
|
||||||
|
currentTime = LocalDateTime.now(Clock.systemUTC());
|
||||||
|
configTime = LocalDateTime.parse(BRplugin.getConfig().getString("lastCheckChestTime"));
|
||||||
|
|
||||||
|
//TIME - Current Time after Config Time
|
||||||
|
if (currentTime.isAfter(configTime)){
|
||||||
|
|
||||||
|
//SANITIZE "world"
|
||||||
|
if (BRplugin.getConfig().getString("world") == null) BRplugin.getServer().broadcastMessage("Error: No world defined in config file.");
|
||||||
|
if (BRplugin.getServer().getWorlds() == null) BRplugin.getServer().broadcastMessage("Error: plugin.getServer().getWorlds() returns null");
|
||||||
|
|
||||||
|
//INIT - world, chestBlock
|
||||||
|
chestBlock = world.getBlockAt(chestX, chestY, chestZ);
|
||||||
|
|
||||||
|
//SANITIZE - chestBlock
|
||||||
|
if (!(chestBlock.getType() == Material.CHEST)){
|
||||||
|
damageShrine();
|
||||||
|
reconstructShrine();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//INIT - shrineChest, shrineInventory
|
||||||
|
shrineChest = (Chest) chestBlock.getState();
|
||||||
|
shrineInventory = shrineChest.getInventory();
|
||||||
|
|
||||||
|
|
||||||
|
//UPDATE - configTime
|
||||||
|
BRplugin.getConfig().set("lastCheckChestTime", currentTime.plusMinutes(BRplugin.getConfig().getInt("barDuration")).toString());
|
||||||
|
BRplugin.saveConfig();
|
||||||
|
|
||||||
|
//INIT - minimumDiamondBlocks, diamondsInserted
|
||||||
|
minimumDiamondBlocks = BRplugin.getConfig().getInt("minimumDiamondBlocks");
|
||||||
|
diamondsInserted = BRplugin.getConfig().getInt("diamondsInserted");
|
||||||
|
|
||||||
|
//CHECK - chest for diamonds
|
||||||
|
if(diamondsInserted > minimumDiamondBlocks || shrineInventory.contains(Material.DIAMOND_BLOCK, (minimumDiamondBlocks - diamondsInserted))){
|
||||||
|
//INVENTORY SUCCESS
|
||||||
|
|
||||||
|
//CHECK - First Time
|
||||||
|
if (minimumDiamondBlocks == 0){
|
||||||
|
broadcastExperimentHasBegun();
|
||||||
|
}else{
|
||||||
|
broadcastButtonRefuled();
|
||||||
|
}
|
||||||
|
|
||||||
|
//UPDATE minimumDiamondBlocks
|
||||||
|
minimumDiamondBlocks++;
|
||||||
|
BRplugin.getConfig().set("minimumDiamondBlocks", minimumDiamondBlocks);
|
||||||
|
BRplugin.getConfig().set("diamondsInserted", 0);
|
||||||
|
BRplugin.saveConfig();
|
||||||
|
}else{
|
||||||
|
//INVENTORY FAILURE
|
||||||
|
damageShrine();
|
||||||
|
}
|
||||||
|
|
||||||
|
//RESET - shrine, shrineInventory
|
||||||
|
reconstructShrine();
|
||||||
|
shrineInventory.clear();
|
||||||
|
BRplugin.getConfig().set("diamondsInserted",0);
|
||||||
|
|
||||||
|
}else{
|
||||||
|
//currentTime is before config time.
|
||||||
|
//therefore wait.
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
private void damageShrine(){
|
||||||
|
//UPDATE - buttonHealth
|
||||||
|
int buttonHealth = BRplugin.getConfig().getInt("buttonHealth");
|
||||||
|
buttonHealth--;
|
||||||
|
BRplugin.getConfig().set("buttonHealth", buttonHealth);
|
||||||
|
|
||||||
|
//DISPLAY AND MAKE SOUND
|
||||||
|
BRplugin.getServer().broadcastMessage(ChatColor.DARK_RED + "--------------------------");
|
||||||
|
BRplugin.getServer().broadcastMessage(ChatColor.DARK_RED + "----- BUTTON DAMAGED -----");
|
||||||
|
BRplugin.getServer().broadcastMessage(ChatColor.DARK_RED + "--------------------------");
|
||||||
|
BRplugin.getServer().broadcastMessage(ChatColor.RED + " " + buttonHealth + "s of Health left");
|
||||||
|
world.playSound(new Location(world,chestX,chestY,chestZ), Sound.ENTITY_ENDERDRAGON_DEATH,50,1);
|
||||||
|
world.playSound(new Location(world,chestX,chestY,chestZ), Sound.ENTITY_LIGHTNING_THUNDER,50,1);
|
||||||
|
world.playSound(new Location(world,chestX,chestY,chestZ), Sound.ENTITY_GENERIC_EXPLODE,50,50);
|
||||||
|
}
|
||||||
|
private void reconstructShrine(){
|
||||||
|
CreateShrine shrineConstructor= new CreateShrine(BRplugin);
|
||||||
|
shrineConstructor.createShrine(chestX, chestY, chestZ, 10, Material.BEDROCK);
|
||||||
|
}
|
||||||
|
private void broadcastExperimentHasBegun(){
|
||||||
|
BRplugin.getServer().broadcastMessage(ChatColor.AQUA + "------------------------------------");
|
||||||
|
BRplugin.getServer().broadcastMessage(ChatColor.AQUA + "----- THE EXPERIMENT HAS BEGUN -----");
|
||||||
|
BRplugin.getServer().broadcastMessage(ChatColor.AQUA + "------------------------------------");
|
||||||
|
BRplugin.getServer().broadcastMessage(ChatColor.BLUE + " " + minimumDiamondBlocks + " Blocks required");
|
||||||
|
world.playSound(new Location(world,chestX,chestY,chestZ), Sound.ENTITY_WITHER_SPAWN,50,10);
|
||||||
|
}
|
||||||
|
private void broadcastButtonRefuled(){
|
||||||
|
BRplugin.getServer().broadcastMessage(ChatColor.AQUA + "--------------------------");
|
||||||
|
BRplugin.getServer().broadcastMessage(ChatColor.AQUA + "----- BUTTON REFULED -----");
|
||||||
|
BRplugin.getServer().broadcastMessage(ChatColor.AQUA + "--------------------------");
|
||||||
|
BRplugin.getServer().broadcastMessage(ChatColor.BLUE + " " + minimumDiamondBlocks + " Blocks required");
|
||||||
|
world.playSound(new Location(world,chestX,chestY,chestZ), Sound.ENTITY_WITHER_SPAWN,50,10);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,245 @@
|
||||||
|
package graveyard.shulker.thebuttonrebirth.tasks;
|
||||||
|
|
||||||
|
import java.time.Clock;
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Server;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.Chest;
|
||||||
|
import org.bukkit.boss.BarColor;
|
||||||
|
import org.bukkit.boss.BarStyle;
|
||||||
|
import org.bukkit.boss.BossBar;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
import graveyard.shulker.thebuttonrebirth.ButtonRebirthPlugin;
|
||||||
|
|
||||||
|
public class CyclicalDisplayTask extends BukkitRunnable{
|
||||||
|
//Pointers
|
||||||
|
private ButtonRebirthPlugin plugin;
|
||||||
|
private Server server;
|
||||||
|
private World world;
|
||||||
|
|
||||||
|
//Config Variables
|
||||||
|
public int buttonHealth;
|
||||||
|
public int minimumDiamondBlocks;
|
||||||
|
public String lastCheckChestTime;
|
||||||
|
|
||||||
|
//Boss bars
|
||||||
|
private BossBar buttonBar;
|
||||||
|
private BossBar diamondBar;
|
||||||
|
private BossBar timeBar;
|
||||||
|
|
||||||
|
//Time
|
||||||
|
private LocalDateTime currentTime;
|
||||||
|
private LocalDateTime configTime;
|
||||||
|
private Duration timeDifference;
|
||||||
|
|
||||||
|
//Chest
|
||||||
|
private int chestX;
|
||||||
|
private int chestY;
|
||||||
|
private int chestZ;
|
||||||
|
private Block chestBlock;
|
||||||
|
private Chest shrineChest;
|
||||||
|
private Inventory shrineInventory;
|
||||||
|
private ItemStack[] chestContents;
|
||||||
|
private int diamondsInserted;
|
||||||
|
|
||||||
|
//Players
|
||||||
|
private List<Player> playerList;
|
||||||
|
|
||||||
|
public List<Player> healthBlocked;
|
||||||
|
public List<Player> diamondBlocked;
|
||||||
|
public List<Player> timeBlocked;
|
||||||
|
private int totalDiamonds;
|
||||||
|
private int currentBar;
|
||||||
|
private int barCycleDuration = 20;
|
||||||
|
|
||||||
|
public CyclicalDisplayTask(ButtonRebirthPlugin initPlugin){
|
||||||
|
//INIT - plugin,server
|
||||||
|
plugin = initPlugin;
|
||||||
|
server = plugin.getServer();
|
||||||
|
|
||||||
|
//INIT - buttonBar,diamondBar,timeBar
|
||||||
|
buttonBar = server.createBossBar("INIT Easter Egg!", BarColor.PURPLE, BarStyle.SEGMENTED_20);
|
||||||
|
diamondBar = server.createBossBar("INIT Easter Egg!", BarColor.BLUE, BarStyle.SOLID);
|
||||||
|
timeBar = server.createBossBar("INIT Easter Egg!", BarColor.RED, BarStyle.SOLID);
|
||||||
|
|
||||||
|
//INIT - chestX, chestY, chestZ, diamondsInserted
|
||||||
|
chestX = plugin.getConfig().getInt("chestX");
|
||||||
|
chestY = plugin.getConfig().getInt("chestY");
|
||||||
|
chestZ = plugin.getConfig().getInt("chestZ");
|
||||||
|
diamondsInserted = plugin.getConfig().getInt("diamondsInserted");
|
||||||
|
|
||||||
|
currentBar = 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
//CHECK - Plugin is Enabled
|
||||||
|
if (plugin.isEnabled() == false){
|
||||||
|
this.cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
//CHECK - World Exists
|
||||||
|
if (!(plugin.getServer().getWorlds().contains(plugin.getServer().getWorld(plugin.getConfig().getString("world"))))) {
|
||||||
|
plugin.logger.info("Error: Config world does not exist in Server.");
|
||||||
|
plugin.logger.info("Server Worlds: " + plugin.getServer().getWorlds().toString());
|
||||||
|
plugin.logger.info("Config World: " + plugin.getConfig().getString("world"));
|
||||||
|
plugin.logger.info("Turning off Display...");
|
||||||
|
this.cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//INIT - world,buttonHealth,minimumDiamondBlocks, diamondsInserted
|
||||||
|
world = plugin.getServer().getWorld(plugin.getConfig().getString("world"));
|
||||||
|
buttonHealth = plugin.getConfig().getInt("buttonHealth");
|
||||||
|
minimumDiamondBlocks = plugin.getConfig().getInt("minimumDiamondBlocks");
|
||||||
|
diamondsInserted = plugin.getConfig().getInt("diamondsInserted");
|
||||||
|
|
||||||
|
//INIT - currentTime, configTime, timeDifference
|
||||||
|
currentTime = LocalDateTime.now(Clock.systemUTC());
|
||||||
|
configTime = LocalDateTime.parse(plugin.getConfig().getString("lastCheckChestTime"));
|
||||||
|
timeDifference = Duration.of(currentTime.until(configTime, ChronoUnit.NANOS), ChronoUnit.NANOS);
|
||||||
|
|
||||||
|
|
||||||
|
setBarTitles();
|
||||||
|
setButtonBarProgress();
|
||||||
|
setDiamondBarProgress();
|
||||||
|
setTimeBarProgress();
|
||||||
|
|
||||||
|
//INIT - playerList,buttonPlayers,diamondPlayers,timePlayers
|
||||||
|
playerList = world.getPlayers();
|
||||||
|
|
||||||
|
//Bar Switching
|
||||||
|
currentBar++;
|
||||||
|
if (currentBar < barCycleDuration){
|
||||||
|
|
||||||
|
//Health Case
|
||||||
|
diamondBar.removeAll();
|
||||||
|
timeBar.removeAll();
|
||||||
|
for(Player player: playerList) buttonBar.addPlayer(player);
|
||||||
|
|
||||||
|
} else if (currentBar < barCycleDuration*2){
|
||||||
|
|
||||||
|
//Diamond Case
|
||||||
|
buttonBar.removeAll();
|
||||||
|
timeBar.removeAll();
|
||||||
|
|
||||||
|
for(Player player: playerList) diamondBar.addPlayer(player);
|
||||||
|
|
||||||
|
} else if (currentBar < barCycleDuration*3){
|
||||||
|
|
||||||
|
//Time Case
|
||||||
|
buttonBar.removeAll();
|
||||||
|
diamondBar.removeAll();
|
||||||
|
|
||||||
|
for(Player player: playerList) timeBar.addPlayer(player);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
buttonBar.removeAll();
|
||||||
|
diamondBar.removeAll();
|
||||||
|
|
||||||
|
for(Player player: playerList) timeBar.addPlayer(player);
|
||||||
|
currentBar = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void setBarTitles(){
|
||||||
|
//SET TITLE - buttonBar,diamondBar,timeBar
|
||||||
|
|
||||||
|
if (buttonHealth >= 50){ buttonBar.setColor(BarColor.PURPLE);}
|
||||||
|
else if (buttonHealth >= 40) {buttonBar.setColor(BarColor.BLUE); }
|
||||||
|
else if (buttonHealth >= 30) {buttonBar.setColor(BarColor.GREEN); }
|
||||||
|
else if (buttonHealth >= 20) {buttonBar.setColor(BarColor.YELLOW); }
|
||||||
|
else if (buttonHealth >= 10) {buttonBar.setColor(BarColor.WHITE); }
|
||||||
|
else if (buttonHealth >= 00) {buttonBar.setColor(BarColor.RED); }
|
||||||
|
else{
|
||||||
|
buttonBar.setColor(BarColor.WHITE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
buttonBar.setTitle("Button Health: "+ buttonHealth + "HP");
|
||||||
|
diamondBar.setTitle("Diamonds Needed At ("+chestX+","+chestY+","+chestZ+ "): " + (diamondsInserted) + "/" + minimumDiamondBlocks);
|
||||||
|
timeBar.setTitle("Button Damage in: " + timeDifference.toHours()+":"+ timeDifference.toMinutes()%60 +":"+ (int)Math.floor(timeDifference.toMillis()%60000/1000));
|
||||||
|
}
|
||||||
|
public void setButtonBarProgress(){
|
||||||
|
//SET PROGRESS - buttonBar
|
||||||
|
if (buttonHealth < 0){
|
||||||
|
buttonBar.setProgress(0.0);
|
||||||
|
}else if (buttonHealth > 60){
|
||||||
|
buttonBar.setProgress(1.0);
|
||||||
|
}else{
|
||||||
|
buttonBar.setProgress((double)buttonHealth/60.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void setDiamondBarProgress(){
|
||||||
|
//SET PROGRESS - diamomndBar
|
||||||
|
if (minimumDiamondBlocks < 1 || diamondsInserted > minimumDiamondBlocks){
|
||||||
|
diamondBar.setProgress(1.0);
|
||||||
|
}else if(diamondsInserted < 0){
|
||||||
|
diamondBar.setProgress(0.0);
|
||||||
|
}else{
|
||||||
|
|
||||||
|
//GET - chestBlock
|
||||||
|
chestBlock = world.getBlockAt(chestX, chestY, chestZ);
|
||||||
|
|
||||||
|
//SANITIZE - chestBlock
|
||||||
|
if (!(chestBlock.getType() == Material.CHEST)) return;
|
||||||
|
|
||||||
|
//INIT - shrineChest, shrineInventory
|
||||||
|
shrineChest = (Chest) chestBlock.getState();
|
||||||
|
shrineInventory = shrineChest.getInventory();
|
||||||
|
|
||||||
|
//SET PROGRESS - diamondBar
|
||||||
|
if(shrineInventory.contains(Material.DIAMOND_BLOCK, (minimumDiamondBlocks - diamondsInserted))){
|
||||||
|
diamondBar.setProgress(1.0);
|
||||||
|
}else{
|
||||||
|
//INIT - chestContents,totalDiamonds
|
||||||
|
chestContents = shrineInventory.getContents();
|
||||||
|
totalDiamonds = 0;
|
||||||
|
//CALCULATE - totalDiamonds
|
||||||
|
for (ItemStack stack: chestContents){
|
||||||
|
try{
|
||||||
|
if (stack.getType() == Material.DIAMOND_BLOCK){
|
||||||
|
totalDiamonds += stack.getAmount();
|
||||||
|
}
|
||||||
|
}catch(Exception e){/*stack isn't a diamond block*/}
|
||||||
|
}
|
||||||
|
|
||||||
|
diamondBar.setProgress((diamondsInserted+totalDiamonds)/(double)minimumDiamondBlocks);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void setTimeBarProgress(){
|
||||||
|
//Time Progress Setting
|
||||||
|
Duration barMinutes = Duration.of(plugin.getConfig().getInt("barDuration"),ChronoUnit.MINUTES);
|
||||||
|
long timeDifferenceMillis = timeDifference.toMillis();
|
||||||
|
long barMinutesMilis = barMinutes.toMillis();
|
||||||
|
double durationRatio = (double)timeDifferenceMillis /(double)barMinutesMilis;
|
||||||
|
|
||||||
|
//SET PROGRESS - timeBar
|
||||||
|
if (durationRatio > 1){
|
||||||
|
timeBar.setProgress(1.0);
|
||||||
|
}else if(durationRatio < 0){
|
||||||
|
timeBar.setProgress(0.0);
|
||||||
|
}else{
|
||||||
|
timeBar.setProgress(durationRatio);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void setBar(int bar){
|
||||||
|
if (bar < 0){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
currentBar = barCycleDuration * (bar);
|
||||||
|
}
|
||||||
|
}
|
200
src/graveyard/shulker/thebuttonrebirth/tasks/StealChestTask.java
Normal file
200
src/graveyard/shulker/thebuttonrebirth/tasks/StealChestTask.java
Normal file
|
@ -0,0 +1,200 @@
|
||||||
|
package graveyard.shulker.thebuttonrebirth.tasks;
|
||||||
|
|
||||||
|
import java.time.Clock;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.Chest;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
import graveyard.shulker.thebuttonrebirth.ButtonRebirthPlugin;
|
||||||
|
|
||||||
|
|
||||||
|
public class StealChestTask extends BukkitRunnable{
|
||||||
|
private ButtonRebirthPlugin plugin;
|
||||||
|
private World world;
|
||||||
|
private int diamondsInserted;
|
||||||
|
private int chestX;
|
||||||
|
private int chestY;
|
||||||
|
private int chestZ;
|
||||||
|
private Block chestBlock;
|
||||||
|
private Inventory shrineInventory;
|
||||||
|
|
||||||
|
private LocalDateTime currentTime;
|
||||||
|
private LocalDateTime configTime;
|
||||||
|
private LocalDateTime messageAllowedTime;
|
||||||
|
private int noRefuelMessagePeriod = 1;//minutes
|
||||||
|
private Player presserPlayer;
|
||||||
|
private String presserName;
|
||||||
|
|
||||||
|
public StealChestTask(ButtonRebirthPlugin initPlugin){
|
||||||
|
//INIT - plugin,server,world
|
||||||
|
plugin = initPlugin;
|
||||||
|
diamondsInserted = plugin.getConfig().getInt("diamondsInserted");
|
||||||
|
|
||||||
|
//INIT - chestX, chestY, chestZ
|
||||||
|
chestX = plugin.getConfig().getInt("chestX");
|
||||||
|
chestY = plugin.getConfig().getInt("chestY");
|
||||||
|
chestZ = plugin.getConfig().getInt("chestZ");
|
||||||
|
|
||||||
|
world = plugin.getServer().getWorld(plugin.getConfig().getString("world"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
//CHECK - Plugin is Enabled
|
||||||
|
if (plugin.isEnabled() == false){
|
||||||
|
this.cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
//CHECK - World Exists
|
||||||
|
if (!(plugin.getServer().getWorlds().contains(plugin.getServer().getWorld(plugin.getConfig().getString("world"))))) {
|
||||||
|
plugin.logger.info("Error: Config world does not exist in Server.");
|
||||||
|
plugin.logger.info("Server Worlds: " + plugin.getServer().getWorlds().toString());
|
||||||
|
plugin.logger.info("Config World: " + plugin.getConfig().getString("world"));
|
||||||
|
plugin.logger.info("Turning off StealChest Task...");
|
||||||
|
this.cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//INIT - diamondsInserted
|
||||||
|
diamondsInserted = plugin.getConfig().getInt("diamondsInserted");
|
||||||
|
|
||||||
|
//SANITIZE - world
|
||||||
|
if (plugin.getConfig().getString("world") == null) {
|
||||||
|
plugin.logger.info("Error: No world defined in config file.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (plugin.getServer().getWorlds() == null) {
|
||||||
|
plugin.logger.info("plugin.getServer().getWorlds() returns null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//INIT - chestBlock
|
||||||
|
chestBlock = world.getBlockAt(chestX, chestY, chestZ);
|
||||||
|
|
||||||
|
//SANITIZE - chestBlock
|
||||||
|
if (!(chestBlock.getType() == Material.CHEST)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//INIT - shrineInventory, minimumDiamondBlocks
|
||||||
|
shrineInventory = ((Chest) chestBlock.getState()).getInventory();
|
||||||
|
|
||||||
|
//STEAL - from shrine chest, put into button health
|
||||||
|
int totalDiamonds = 0;
|
||||||
|
ItemStack[] chestContents = shrineInventory.getContents();
|
||||||
|
//CALCULATE - totalDiamonds
|
||||||
|
for (ItemStack stack: chestContents){
|
||||||
|
try{
|
||||||
|
if (stack.getType() == Material.DIAMOND_BLOCK){
|
||||||
|
totalDiamonds += (stack.getAmount() *9);
|
||||||
|
|
||||||
|
}else if (stack.getType() == Material.DIAMOND){
|
||||||
|
totalDiamonds += (stack.getAmount() *1);
|
||||||
|
|
||||||
|
}else if (stack.getType() == Material.DIAMOND_ORE){
|
||||||
|
totalDiamonds += (stack.getAmount() *1);
|
||||||
|
|
||||||
|
}else if (stack.getType() == Material.DIAMOND_SWORD){
|
||||||
|
totalDiamonds += (stack.getAmount() *2);
|
||||||
|
|
||||||
|
}else if(stack.getType() == Material.DIAMOND_PICKAXE){
|
||||||
|
totalDiamonds += (stack.getAmount() *3);
|
||||||
|
|
||||||
|
}else if (stack.getType() == Material.DIAMOND_HELMET){
|
||||||
|
totalDiamonds += (stack.getAmount() *5);
|
||||||
|
|
||||||
|
}else if (stack.getType() == Material.DIAMOND_CHESTPLATE){
|
||||||
|
totalDiamonds += (stack.getAmount() *8);
|
||||||
|
|
||||||
|
}else if (stack.getType() == Material.DIAMOND_LEGGINGS){
|
||||||
|
totalDiamonds += (stack.getAmount() *7);
|
||||||
|
|
||||||
|
}else if(stack.getType() == Material.DIAMOND_BOOTS){
|
||||||
|
totalDiamonds += (stack.getAmount() *4);
|
||||||
|
|
||||||
|
}else if(stack.getType() == Material.DIAMOND_AXE){
|
||||||
|
totalDiamonds += (stack.getAmount() *3);
|
||||||
|
|
||||||
|
}else if(stack.getType() == Material.DIAMOND_HOE){
|
||||||
|
totalDiamonds += (stack.getAmount() *2);
|
||||||
|
|
||||||
|
}else if(stack.getType() == Material.DIAMOND_SPADE){
|
||||||
|
totalDiamonds += (stack.getAmount() *1);
|
||||||
|
|
||||||
|
}else if(stack.getType() == Material.DIAMOND_BARDING){
|
||||||
|
totalDiamonds += (stack.getAmount() *1);
|
||||||
|
|
||||||
|
}
|
||||||
|
}catch(Exception e){/*stack is empty*/}
|
||||||
|
}
|
||||||
|
shrineInventory.clear();
|
||||||
|
diamondsInserted += totalDiamonds;
|
||||||
|
plugin.getConfig().set("diamondsInserted", diamondsInserted);
|
||||||
|
plugin.saveConfig();
|
||||||
|
//RESET TIMER CHECK
|
||||||
|
if (plugin.getConfig().getInt("diamondsInserted") >= plugin.getConfig().getInt("minimumDiamondBlocks")){
|
||||||
|
|
||||||
|
plugin.getConfig().set("diamondsInserted", 0);
|
||||||
|
plugin.saveConfig();
|
||||||
|
|
||||||
|
currentTime = LocalDateTime.now(Clock.systemUTC());
|
||||||
|
configTime = LocalDateTime.parse(plugin.getConfig().getString("lastCheckChestTime"));
|
||||||
|
|
||||||
|
plugin.getConfig().set("lastCheckChestTime", currentTime.plusMinutes(plugin.getConfig().getInt("barDuration")).toString());
|
||||||
|
plugin.saveConfig();
|
||||||
|
|
||||||
|
messageAllowedTime = configTime.minusMinutes(plugin.getConfig().getInt("barDuration")).plusMinutes(noRefuelMessagePeriod);
|
||||||
|
|
||||||
|
if(currentTime.isAfter(messageAllowedTime)){
|
||||||
|
|
||||||
|
try {presserPlayer = getNearestPresser();} catch(Exception noPlayers) {return;}
|
||||||
|
|
||||||
|
presserName = presserPlayer.getDisplayName();
|
||||||
|
plugin.getServer().broadcastMessage(ChatColor.AQUA + "--------------------------");
|
||||||
|
plugin.getServer().broadcastMessage(ChatColor.AQUA + "SHRINE REFULED BY " + presserName);
|
||||||
|
plugin.getServer().broadcastMessage(ChatColor.AQUA + "--------------------------");
|
||||||
|
for (Player player: plugin.getServer().getOnlinePlayers()){
|
||||||
|
Location tempLocation = player.getLocation();
|
||||||
|
world.playSound(tempLocation, Sound.ENTITY_WITHER_SPAWN,30,10);
|
||||||
|
}
|
||||||
|
|
||||||
|
}else{
|
||||||
|
|
||||||
|
try {presserPlayer = getNearestPresser();} catch(Exception noPlayers) {return;}
|
||||||
|
|
||||||
|
presserPlayer.sendMessage(ChatColor.AQUA + "---------------");
|
||||||
|
presserPlayer.sendMessage(ChatColor.AQUA + "SHRINE REFUELED");
|
||||||
|
presserPlayer.sendMessage(ChatColor.AQUA + "---------------");
|
||||||
|
}
|
||||||
|
world.playSound(new Location(world,chestX,chestY,chestZ), Sound.ENTITY_WITHER_SPAWN,50,10);
|
||||||
|
((CyclicalDisplayTask) plugin.cyclicalDisplayListener.cyclicalDisplayTask).setBar(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Player getNearestPresser() throws Exception{
|
||||||
|
if (plugin.getServer().getOnlinePlayers().isEmpty()) throw new Exception();
|
||||||
|
Player closestPlayer = null;
|
||||||
|
int closestDistance = 0;
|
||||||
|
for (Player player: plugin.getServer().getOnlinePlayers()){
|
||||||
|
int distance = (int) player.getLocation().distance(new Location(world, chestX,chestY,chestZ));
|
||||||
|
if (closestPlayer == null){
|
||||||
|
closestPlayer = player;
|
||||||
|
closestDistance = distance;
|
||||||
|
}else if(distance < closestDistance){
|
||||||
|
closestPlayer = player;
|
||||||
|
closestDistance = distance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return closestPlayer;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue