Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ru.lisenochek.mcrust.objects.blockMechanic;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.scheduler.BukkitRunnable;
- import ru.lisenochek.mcrust.Items;
- import ru.lisenochek.mcrust.Main;
- import ru.lisenochek.mcrust.sql.SQLManager;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- public class Chair {
- private static HashMap<Location, Chair> chairsMap = new HashMap<>();
- private Location location;
- private String ownerName;
- private Type type;
- private int time;
- public Chair(Location location, String ownerName, Type type, int time) {
- this.location = location;
- this.ownerName = ownerName;
- this.type = type;
- this.time = time;
- chairsMap.put(location, this);
- runTimer();
- }
- public static Chair create(Location location, String ownerName, Type type, int time) {
- return new Chair(location, ownerName, type, time);
- }
- public static List<Chair> getFromOwner(String playerName) {
- List<Chair> list = new ArrayList<>();
- for (Chair spc : chairsMap.values()) if (spc.getOwnerName().equals(playerName)) list.add(spc);
- return list;
- }
- public static Chair fromLocation(Location location) {
- return chairsMap.get(location);
- }
- public Location getLocation() {
- return location;
- }
- public String getOwnerName() {
- return ownerName;
- }
- public Type getType() {
- return type;
- }
- public int getTime() {
- return time;
- }
- public void setTime(int time) {
- this.time = time;
- }
- public void remove() {
- SQLManager.getManager().deleteChairData(this);
- Chair.chairsMap.remove(location);
- }
- public void runTimer() {
- new BukkitRunnable() {
- @Override
- public void run() {
- if (!chairsMap.containsValue(Chair.this)) {
- cancel();
- return;
- }
- if (location.getBlock().getType() == Material.AIR) {
- chairsMap.remove(location);
- SQLManager.getManager().deleteChairData(Chair.this);
- cancel();
- return;
- }
- if (time == 0) return;
- --time;
- SQLManager.getManager().updateChairData(Chair.this);
- }
- }.runTaskTimer(Main.plugin, 1, 20);
- }
- public enum Type {
- WOODEN_CHAIR(150, Items.WOODEN_CHAIR.getStack()),
- UPGRADED_CHAIR(90, Items.UPGRADED_CHAIR.getStack()),
- METAL_CHAIR(60, Items.METAL_CHAIR.getStack());
- private int cooldown;
- private ItemStack icon;
- Type(int cooldown, ItemStack stack) {
- this.cooldown = cooldown;
- this.icon = stack;
- }
- public int getCooldown() {
- return cooldown;
- }
- public ItemStack getStack() {
- return icon;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement