Write GPowerAPI

This commit is contained in:
alisolarflare 2016-11-30 10:57:10 -05:00
parent 2ec5f26737
commit e605f72b4b
26 changed files with 366 additions and 370 deletions

View file

@ -14,7 +14,6 @@ import alisolarflare.components.gpowers.GPowerComponent;
import alisolarflare.components.insurance.InsuranceComponent;
import alisolarflare.components.magic.MagicComponent;
import alisolarflare.components.metrics.MetricsComponent;
import alisolarflare.components.minigames.MinigameComponent;
public class AliPresents extends JavaPlugin{
public void onEnable(){
@ -32,7 +31,6 @@ public class AliPresents extends JavaPlugin{
new InsuranceComponent().register(this);
new MagicComponent().register(this);
new MetricsComponent().register(this);
new MinigameComponent().register(this);
logger.info(pdfFile.getName() + " has fully registered (V." + pdfFile.getVersion()+ ").");

View file

@ -0,0 +1,90 @@
package alisolarflare.components.gpowers;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Color;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
public class GPowerAPI{
public static final int defaultPowerLength = 300;
public static Map<UUID, PoweredPlayer> poweredPlayerList = new HashMap<UUID, PoweredPlayer>();
public static void addPlayer(Player player, String colour, boolean powerIsActive){
poweredPlayerList.put(player.getUniqueId(), new PoweredPlayer(player.getUniqueId(), colour, true));
}
public static void PowerUpPlayer(Player player){
player.sendMessage("Powering up!");
if(poweredPlayerList.containsKey(player.getUniqueId())){
poweredPlayerList.get(player.getUniqueId()).isPowersActive = true;
player.sendMessage("Powered up!");
}else{
player.sendMessage("You must instantiate your power settings using /GPower");
}
}
public static void PowerUpAllPlayers(){
for (PoweredPlayer poweredPlayer : GPowerAPI.poweredPlayerList.values()){
poweredPlayer.isPowersActive = true;
}
}
public static void PowerDownPlayer(Player player){
player.sendMessage("Powering down!");
if (poweredPlayerList.containsKey(player.getUniqueId())){
player.sendMessage("Powered down!");
poweredPlayerList.get(player.getUniqueId()).isPowersActive = false;
}else{
player.sendMessage("P down!");
return;
}
}
public static void activatePower(Player player){
activatePower(player, poweredPlayerList.get(player.getUniqueId()).colour, defaultPowerLength);
}
public static void activatePower(Player player, String colour){
activatePower(player, colour, defaultPowerLength);
}
public static void activatePower(Player player, String colour, int powerLength) {
//GREY
for (PotionEffect potionEffect : player.getActivePotionEffects()){
player.removePotionEffect(potionEffect.getType());
}
if ((colour.startsWith("grey") || colour.startsWith("gra")) && (player.getWorld().getTime() > 12575 && player.getWorld().getTime() < 22925)){
player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, powerLength, 0, true, false, Color.GRAY), true);
player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, powerLength+100, 0, true, false, Color.GRAY), true);
//RED
}else if (colour.startsWith("r")){
player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, powerLength, 0, true, false, Color.RED), true);
//ORANGE
}else if (colour.startsWith("o")){
player.addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, powerLength, 0, true, false, Color.ORANGE), true);
player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, powerLength, 0, true, false, Color.ORANGE), true);
//YELLOW
}else if (colour.startsWith("y") && player.getLocation().getBlock().getLightFromSky() == 15 && player.getLocation().getBlock().getLightFromBlocks() == 15){
player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, powerLength, 0, true, false, Color.YELLOW), true);
//GREEN
}else if (colour.startsWith("g") && !colour.startsWith("gra") && !colour.startsWith("grey")){
player.addPotionEffect(new PotionEffect(PotionEffectType.LUCK, powerLength, 1, true, false, Color.GREEN), true);
player.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, powerLength, 0, true, false, Color.GREEN), true);
//BLUE
}else if (colour.startsWith("b")){
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, powerLength, 1, true, false, Color.BLUE), true);
player.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, powerLength, 0, true, false, Color.BLUE), true);
//PURPLE
}else if (colour.startsWith("p")){
player.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST, powerLength, 0, true, false, Color.PURPLE), true);
//NULL
}else{
}
}
public static boolean playerHasActivePowers(Player player){
return poweredPlayerList.containsKey(player.getUniqueId()) && poweredPlayerList.get(player.getUniqueId()).isPowersActive;
}
}

View file

@ -12,12 +12,11 @@ public class GPowerComponent extends Component {
@Override
public void register(JavaPlugin plugin) {
GPowerMemory gPowerMemory = new GPowerMemory();
registerCommand(plugin, new GPower(gPowerMemory));
registerCommand(plugin, new PowerUp(gPowerMemory));
registerCommand(plugin, new PowerDown(gPowerMemory));
registerCommand(plugin, new GPower());
registerCommand(plugin, new PowerUp());
registerCommand(plugin, new PowerDown());
registerListener(plugin, new EnchantingLoop(plugin, gPowerMemory));
registerListener(plugin, new EnchantingLoop(plugin));
}

View file

@ -1,52 +0,0 @@
package alisolarflare.components.gpowers;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.bukkit.entity.Player;
public class GPowerMemory{
public Map<UUID, poweredPlayer> poweredPlayerList = new HashMap<UUID, poweredPlayer>();
public void configurePlayer(Player player, String colour, boolean powerIsActive){
poweredPlayerList.put(player.getUniqueId(), new poweredPlayer(player.getUniqueId(), colour, true));
}
public void PowerUpPlayer(Player player){
player.sendMessage("Powering up!");
if(poweredPlayerList.containsKey(player.getUniqueId())){
poweredPlayerList.get(player.getUniqueId()).isPowersActive = true;
player.sendMessage("Powered up!");
}else{
player.sendMessage("You must instantiate your power settings using /GPower");
}
}
public void PowerDownPlayer(Player player){
player.sendMessage("Powering down!");
if (poweredPlayerList.containsKey(player.getUniqueId())){
player.sendMessage("Powered down!");
poweredPlayerList.get(player.getUniqueId()).isPowersActive = false;
}else{
player.sendMessage("P down!");
return;
}
}
public class poweredPlayer{
public UUID uuid;
public String colour;
public Boolean isPowersActive;
public poweredPlayer(UUID uuid, String colour, Boolean activated){
this.uuid = (uuid);
this.colour = (colour);
this.isPowersActive = (activated);
}
public String toString(){
return "[UUID: "+ uuid.toString() + ", Colour: "+ colour+", IsActivated: "+isPowersActive + "]";
}
}
}

View file

@ -0,0 +1,18 @@
package alisolarflare.components.gpowers;
import java.util.UUID;
public class PoweredPlayer{
public UUID uuid;
public String colour;
public Boolean isPowersActive;
public PoweredPlayer(UUID uuid, String colour, Boolean activated){
this.uuid = (uuid);
this.colour = (colour);
this.isPowersActive = (activated);
}
public String toString(){
return "[UUID: "+ uuid.toString() + ", Colour: "+ colour+", IsActivated: "+isPowersActive + "]";
}
}

View file

@ -3,16 +3,9 @@ package alisolarflare.components.gpowers.commands;
import org.bukkit.entity.Player;
import alisolarflare.architecture.commands.PlayerCommand;
import alisolarflare.components.gpowers.GPowerMemory;
import alisolarflare.components.gpowers.GPowerAPI;
public class GPower extends PlayerCommand {
private GPowerMemory gPowerMemory;
public GPower(GPowerMemory gPowerMemory) {
this.gPowerMemory = gPowerMemory;
}
@Override
public boolean OnCommand(Player player, String label, String[] args) {
if (args.length < 2) {
@ -39,7 +32,7 @@ public class GPower extends PlayerCommand {
}
player.sendMessage("Terms Vaild!");
player.sendMessage("Saving Data: "+ player.getName() + "|" + colour + "|" + isActive);
gPowerMemory.configurePlayer(player, colour, isActive);
GPowerAPI.addPlayer(player, colour, isActive);
return true;
}

View file

@ -1,75 +1,32 @@
package alisolarflare.components.gpowers.enchant;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Color;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitRunnable;
import alisolarflare.components.gpowers.GPowerMemory;
import alisolarflare.components.gpowers.GPowerMemory.poweredPlayer;
public class EnchantingLoop extends BukkitRunnable implements Listener{
private int powerLength = 300;
private Server server;
private Map<UUID, poweredPlayer> poweredPlayerList;
public EnchantingLoop(JavaPlugin plugin, GPowerMemory gPowerMemory){
this.server = plugin.getServer();
this.poweredPlayerList = gPowerMemory.poweredPlayerList;
this.runTaskTimer(plugin, 0, 190);
}
//REPEATS EVERY 5 SECONDS
@Override
public void run() {
//server.broadcastMessage("ping!");
for (Player player : server.getOnlinePlayers()){
if(poweredPlayerList.containsKey(player.getUniqueId()) && poweredPlayerList.get(player.getUniqueId()).isPowersActive){
activatePower(player, poweredPlayerList.get(player.getUniqueId()).colour);
}
}
}
private void activatePower(Player player, String colour) {
//GREY
for (PotionEffect potionEffect : player.getActivePotionEffects()){
player.removePotionEffect(potionEffect.getType());
}
if ((colour.startsWith("grey") || colour.startsWith("gra")) && (player.getWorld().getTime() > 12575 && player.getWorld().getTime() < 22925)){
player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, powerLength, 0, true, false, Color.GRAY), true);
player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, powerLength+100, 0, true, false, Color.GRAY), true);
//RED
}else if (colour.startsWith("r")){
player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, powerLength, 0, true, false, Color.RED), true);
//ORANGE
}else if (colour.startsWith("o")){
player.addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, powerLength, 0, true, false, Color.ORANGE), true);
player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, powerLength, 0, true, false, Color.ORANGE), true);
//YELLOW
}else if (colour.startsWith("y") && player.getLocation().getBlock().getLightFromSky() == 15 && player.getLocation().getBlock().getLightFromBlocks() == 15){
player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, powerLength, 0, true, false, Color.YELLOW), true);
//GREEN
}else if (colour.startsWith("g") && !colour.startsWith("gra") && !colour.startsWith("grey")){
player.addPotionEffect(new PotionEffect(PotionEffectType.LUCK, powerLength, 1, true, false, Color.GREEN), true);
player.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, powerLength, 0, true, false, Color.GREEN), true);
//BLUE
}else if (colour.startsWith("b")){
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, powerLength, 1, true, false, Color.BLUE), true);
player.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, powerLength, 0, true, false, Color.BLUE), true);
//PURPLE
}else if (colour.startsWith("p")){
player.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST, powerLength, 0, true, false, Color.PURPLE), true);
//NULL
}else{
}
}
}
package alisolarflare.components.gpowers.enchant;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import alisolarflare.components.gpowers.GPowerAPI;
public class EnchantingLoop extends BukkitRunnable implements Listener{
private Server server;
public EnchantingLoop(JavaPlugin plugin){
this.server = plugin.getServer();
this.runTaskTimer(plugin, 0, 190);
}
//REPEATS EVERY 5 SECONDS
@Override
public void run() {
for (Player player : server.getOnlinePlayers()){
if(GPowerAPI.playerHasActivePowers(player)){
GPowerAPI.activatePower(player);
}
}
}
}

View file

@ -3,20 +3,12 @@ package alisolarflare.components.gpowers.powerstate;
import org.bukkit.entity.Player;
import alisolarflare.architecture.commands.ModCommand;
import alisolarflare.components.gpowers.GPowerMemory;
import alisolarflare.components.gpowers.GPowerMemory.poweredPlayer;
import alisolarflare.components.gpowers.GPowerAPI;
public class PowerAll extends ModCommand{
private GPowerMemory gPowerMemory;
public PowerAll(GPowerMemory gPowerMemory) {
this.gPowerMemory = gPowerMemory;
}
@Override
public boolean OnCommand(Player player, String alias, String[] args) {
for (poweredPlayer poweredPlayer : gPowerMemory.poweredPlayerList.values()){
poweredPlayer.isPowersActive = true;
}
GPowerAPI.PowerUpAllPlayers();
return true;
}
public String[] GetHelpText(String alias){

View file

@ -3,19 +3,12 @@ package alisolarflare.components.gpowers.powerstate;
import org.bukkit.entity.Player;
import alisolarflare.architecture.commands.PlayerCommand;
import alisolarflare.components.gpowers.GPowerMemory;
import alisolarflare.components.gpowers.GPowerAPI;
public class PowerDown extends PlayerCommand {
private GPowerMemory gPowerMemory;
public PowerDown(GPowerMemory gPowerMemory) {
this.gPowerMemory = gPowerMemory;
}
@Override
public boolean OnCommand(Player player, String label, String[] args) {
gPowerMemory.PowerDownPlayer(player);
GPowerAPI.PowerDownPlayer(player);
return true;
}
@Override

View file

@ -3,19 +3,12 @@ package alisolarflare.components.gpowers.powerstate;
import org.bukkit.entity.Player;
import alisolarflare.architecture.commands.PlayerCommand;
import alisolarflare.components.gpowers.GPowerMemory;
import alisolarflare.components.gpowers.GPowerAPI;
public class PowerUp extends PlayerCommand {
private GPowerMemory gPowerMemory;
public PowerUp(GPowerMemory gPowerMemory) {
this.gPowerMemory = gPowerMemory;
}
@Override
public boolean OnCommand(Player player, String label, String[] args) {
gPowerMemory.PowerUpPlayer(player);
GPowerAPI.PowerUpPlayer(player);
return true;
}
@Override

View file

@ -1,5 +1,6 @@
package alisolarflare.components.minigames;
/*package graveyard.minigames;
public enum GameState {
Idle, FreeForAll, Heroes;
}
*/

View file

@ -1,4 +1,4 @@
package alisolarflare.components.minigames;
/*package graveyard.minigames;
import java.util.List;
@ -6,11 +6,11 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import alisolarflare.architecture.Component;
import alisolarflare.components.minigames.commands.JoinMinigame;
import alisolarflare.components.minigames.commands.LeaveMinigame;
import alisolarflare.components.minigames.commands.ListFighters;
import alisolarflare.components.minigames.commands.SetColourSpawn;
import alisolarflare.components.minigames.data.SpawnSet;
import graveyard.minigames.commands.JoinMinigame;
import graveyard.minigames.commands.LeaveMinigame;
import graveyard.minigames.commands.ListFighters;
import graveyard.minigames.commands.SetColourSpawn;
import graveyard.minigames.data.SpawnSet;
public class MinigameComponent extends Component{
public SpawnSet spawnSet;
@ -34,3 +34,4 @@ public class MinigameComponent extends Component{
}
}
}
*/

View file

@ -1,11 +1,11 @@
package alisolarflare.components.minigames.commands;
/*package graveyard.minigames.commands;
import java.util.List;
import org.bukkit.entity.Player;
import alisolarflare.architecture.commands.PlayerCommand;
import alisolarflare.components.minigames.MinigameComponent;
import graveyard.minigames.MinigameComponent;
public class JoinMinigame extends PlayerCommand {
private List<String> fighterList;
@ -31,3 +31,4 @@ public class JoinMinigame extends PlayerCommand {
};
}
}
*/

View file

@ -1,11 +1,11 @@
package alisolarflare.components.minigames.commands;
/*package graveyard.minigames.commands;
import java.util.List;
import org.bukkit.entity.Player;
import alisolarflare.architecture.commands.PlayerCommand;
import alisolarflare.components.minigames.MinigameComponent;
import graveyard.minigames.MinigameComponent;
public class LeaveMinigame extends PlayerCommand {
private List<String> fighters;
@ -39,3 +39,4 @@ public class LeaveMinigame extends PlayerCommand {
};
}
}
*/

View file

@ -1,9 +1,9 @@
package alisolarflare.components.minigames.commands;
/*package graveyard.minigames.commands;
import org.bukkit.entity.Player;
import alisolarflare.architecture.commands.PlayerCommand;
import alisolarflare.components.minigames.MinigameComponent;
import graveyard.minigames.MinigameComponent;
public class ListFighters extends PlayerCommand {
private MinigameComponent component;
@ -24,3 +24,4 @@ public class ListFighters extends PlayerCommand {
};
}
}
*/

View file

@ -1,9 +1,9 @@
package alisolarflare.components.minigames.commands;
/*package graveyard.minigames.commands;
import org.bukkit.entity.Player;
import alisolarflare.architecture.commands.ModCommand;
import alisolarflare.components.minigames.data.SpawnSet;
import graveyard.minigames.data.SpawnSet;
public class SetColourSpawn extends ModCommand{
private SpawnSet spawnSet;
@ -62,3 +62,4 @@ public class SetColourSpawn extends ModCommand{
};
}
}
*/

View file

@ -1,4 +1,4 @@
package alisolarflare.components.minigames.data;
/*package graveyard.minigames.data;
import org.bukkit.Location;
@ -11,3 +11,4 @@ public class SpawnSet {
public Location PSpawn;
}
*/

View file

@ -1,4 +1,4 @@
package graveyard.thebuttonrebirth;
/*package graveyard.thebuttonrebirth;
import java.util.ArrayList;
import java.util.List;
@ -68,3 +68,4 @@ public class ButtonRebirthPlugin extends JavaPlugin{
shrineCreator.createShrine(chestX, chestY, chestZ, 10, Material.BEDROCK);
}
}
*/

View file

@ -1,4 +1,4 @@
package graveyard.thebuttonrebirth.admin;
/*package graveyard.thebuttonrebirth.admin;
import org.bukkit.Material;
import org.bukkit.World;
@ -96,7 +96,7 @@ public class CreateShrine implements CommandExecutor{
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;
@ -107,14 +107,14 @@ public class CreateShrine implements CommandExecutor{
//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");
@ -126,3 +126,4 @@ public class CreateShrine implements CommandExecutor{
return false;
}
}
*/

View file

@ -1,4 +1,4 @@
package graveyard.thebuttonrebirth.commands;
/*package graveyard.thebuttonrebirth.commands;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
@ -28,3 +28,4 @@ public class ShowBars implements CommandExecutor{
}
}
*/

View file

@ -1,4 +1,4 @@
package graveyard.thebuttonrebirth.listeners;
/*package graveyard.thebuttonrebirth.listeners;
import org.bukkit.event.Listener;
import org.bukkit.scheduler.BukkitTask;
@ -17,3 +17,4 @@ public class CyclicalDisplayListener implements Listener{
bukkitTask = cyclicalDisplayTask.runTaskTimer(this.plugin, 20, 20);
}
}
*/

View file

@ -1,4 +1,4 @@
package graveyard.thebuttonrebirth.listeners;
/*package graveyard.thebuttonrebirth.listeners;
import org.bukkit.event.Listener;
import org.bukkit.scheduler.BukkitTask;
@ -17,3 +17,4 @@ public class MidnightListener implements Listener{
checkChestTask = new CheckChestTask(this.plugin).runTaskTimer(this.plugin, 20, 60);
}
}
*/

View file

@ -1,4 +1,4 @@
package graveyard.thebuttonrebirth.listeners;
/*package graveyard.thebuttonrebirth.listeners;
import org.bukkit.event.Listener;
import org.bukkit.scheduler.BukkitTask;
@ -16,3 +16,4 @@ public class StealChestListener implements Listener{
stealChestTask = new StealChestTask(this.plugin).runTaskTimer(this.plugin, 20, 20);
}
}
*/

View file

@ -1,169 +1,169 @@
package graveyard.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.thebuttonrebirth.ButtonRebirthPlugin;
import graveyard.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);
}
}
//package graveyard.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.thebuttonrebirth.ButtonRebirthPlugin;
//import graveyard.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);
// }
//}

View file

@ -1,4 +1,4 @@
package graveyard.thebuttonrebirth.tasks;
/*package graveyard.thebuttonrebirth.tasks;
import java.time.Clock;
import java.time.Duration;
@ -213,7 +213,7 @@ public class CyclicalDisplayTask extends BukkitRunnable{
if (stack.getType() == Material.DIAMOND_BLOCK){
totalDiamonds += stack.getAmount();
}
}catch(Exception e){/*stack isn't a diamond block*/}
}catch(Exception e){stack isn't a diamond block}
}
diamondBar.setProgress((diamondsInserted+totalDiamonds)/(double)minimumDiamondBlocks);
@ -243,3 +243,4 @@ public class CyclicalDisplayTask extends BukkitRunnable{
currentBar = barCycleDuration * (bar);
}
}
*/

View file

@ -1,4 +1,4 @@
package graveyard.thebuttonrebirth.tasks;
/*package graveyard.thebuttonrebirth.tasks;
import java.time.Clock;
import java.time.LocalDateTime;
@ -135,7 +135,7 @@ public class StealChestTask extends BukkitRunnable{
totalDiamonds += (stack.getAmount() *1);
}
}catch(Exception e){/*stack is empty*/}
}catch(Exception e){stack is empty}
}
shrineInventory.clear();
diamondsInserted += totalDiamonds;
@ -198,3 +198,4 @@ public class StealChestTask extends BukkitRunnable{
return closestPlayer;
}
}
*/