Fixed lombok building (javadoc) & fixed equals() and toString() methods
This commit is contained in:
parent
27bf53aaad
commit
13b5ab69a2
28 changed files with 374 additions and 354 deletions
|
@ -1,65 +0,0 @@
|
|||
package nl.SBDeveloper.V10Lift.API.Objects;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter @Setter @NoArgsConstructor
|
||||
public class Floor {
|
||||
private String world;
|
||||
private int y;
|
||||
private ArrayList<LiftBlock> doorBlocks = new ArrayList<>();
|
||||
private HashSet<UUID> whitelist = new HashSet<>();
|
||||
|
||||
public Floor(int y, String world) {
|
||||
this.y = y;
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (obj == null) return false;
|
||||
if (getClass() != obj.getClass()) return false;
|
||||
Floor other = (Floor) obj;
|
||||
if (getWorld() == null) {
|
||||
if (other.getWorld() != null) return false;
|
||||
} else if (!getWorld().equals(other.getWorld())) {
|
||||
return false;
|
||||
}
|
||||
return getY() == other.getY();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
String newLine = System.getProperty("line.separator");
|
||||
|
||||
result.append(this.getClass().getName());
|
||||
result.append(" Object {");
|
||||
result.append(newLine);
|
||||
|
||||
//determine fields declared in this class only (no fields of superclass)
|
||||
Field[] fields = this.getClass().getDeclaredFields();
|
||||
|
||||
//print field names paired with their values
|
||||
for (Field field: fields) {
|
||||
result.append(" ");
|
||||
try {
|
||||
result.append(field.getName());
|
||||
result.append(": ");
|
||||
//requires access to private field:
|
||||
result.append(field.get(this));
|
||||
} catch (IllegalAccessException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
result.append(newLine);
|
||||
}
|
||||
result.append("}");
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
package nl.SBDeveloper.V10Lift.API.Objects;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import nl.SBDeveloper.V10Lift.API.Runnables.DoorCloser;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
|
||||
@NoArgsConstructor
|
||||
public class Lift {
|
||||
@Getter @Setter private String worldName;
|
||||
@Getter @Setter private int y;
|
||||
@Getter private HashSet<UUID> owners;
|
||||
//@Getter @Setter private ArrayList<String> whitelist;
|
||||
@Getter private final TreeSet<LiftBlock> blocks = new TreeSet<>();
|
||||
@Getter private final LinkedHashMap<String, Floor> floors = new LinkedHashMap<>();
|
||||
@Getter private final HashSet<LiftSign> signs = new HashSet<>();
|
||||
@Getter private final HashSet<LiftBlock> inputs = new HashSet<>();
|
||||
@Getter private HashSet<LiftBlock> offlineInputs = new HashSet<>();
|
||||
@Getter @Setter private LinkedHashMap<String, Floor> queue = null;
|
||||
@Getter private final HashSet<LiftRope> ropes = new HashSet<>();
|
||||
@Getter private final ArrayList<V10Entity> toMove = new ArrayList<>();
|
||||
@Getter @Setter private int speed;
|
||||
@Getter @Setter private boolean realistic;
|
||||
@Getter @Setter private boolean offline = false;
|
||||
@Getter @Setter private boolean sound = true;
|
||||
@Getter @Setter private boolean defective = false;
|
||||
@Getter @Setter private String signText = null;
|
||||
@Getter @Setter private int counter = 0;
|
||||
@Getter @Setter private Floor doorOpen = null;
|
||||
@Getter @Setter private DoorCloser doorCloser = null;
|
||||
|
||||
public Lift(HashSet<UUID> owners, int speed, boolean realistic) {
|
||||
this.owners = owners;
|
||||
this.speed = speed;
|
||||
this.realistic = realistic;
|
||||
}
|
||||
|
||||
public Lift(UUID owner, int speed, boolean realistic) {
|
||||
HashSet<UUID> hs = new HashSet<>();
|
||||
hs.add(owner);
|
||||
this.owners = hs;
|
||||
this.speed = speed;
|
||||
this.realistic = realistic;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
String newLine = System.getProperty("line.separator");
|
||||
|
||||
result.append(this.getClass().getName());
|
||||
result.append(" Object {");
|
||||
result.append(newLine);
|
||||
|
||||
//determine fields declared in this class only (no fields of superclass)
|
||||
Field[] fields = this.getClass().getDeclaredFields();
|
||||
|
||||
//print field names paired with their values
|
||||
for (Field field: fields) {
|
||||
result.append(" ");
|
||||
try {
|
||||
result.append(field.getName());
|
||||
result.append(": ");
|
||||
//requires access to private field:
|
||||
result.append(field.get(this));
|
||||
} catch (IllegalAccessException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
result.append(newLine);
|
||||
}
|
||||
result.append("}");
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
}
|
|
@ -1,185 +0,0 @@
|
|||
package nl.SBDeveloper.V10Lift.API.Objects;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockFace;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Map;
|
||||
|
||||
@NoArgsConstructor
|
||||
public class LiftBlock implements Comparable<LiftBlock> {
|
||||
|
||||
@Getter @Setter private String world;
|
||||
@Getter private int x;
|
||||
@Getter @Setter private int y;
|
||||
@Getter private int z;
|
||||
|
||||
//Only used for cabine blocks, because those need caching!
|
||||
@Getter private Material mat;
|
||||
@Getter private byte data;
|
||||
@Getter private BlockFace face;
|
||||
@Getter private String bisected;
|
||||
@Getter private String[] signLines;
|
||||
|
||||
//Only used for inputs!
|
||||
@Getter private String floor;
|
||||
@Getter @Setter private boolean active = false;
|
||||
|
||||
//Only used for chests
|
||||
public Map<String, Object>[] serializedItemStacks = null;
|
||||
|
||||
/* Floor based liftblock, no material */
|
||||
public LiftBlock(String world, int x, int y, int z, String floor) {
|
||||
this.world = world;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.mat = null;
|
||||
this.data = 0;
|
||||
this.face = null;
|
||||
this.signLines = null;
|
||||
this.floor = floor;
|
||||
this.bisected = null;
|
||||
}
|
||||
|
||||
/** 1.12 liftblocks **/
|
||||
|
||||
/* 1.12 liftblock (Directional) */
|
||||
public LiftBlock(String world, int x, int y, int z, Material mat, byte data) {
|
||||
this.world = world;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.mat = mat;
|
||||
this.face = null;
|
||||
this.data = data;
|
||||
this.signLines = null;
|
||||
this.floor = null;
|
||||
this.bisected = null;
|
||||
}
|
||||
|
||||
/* 1.12 liftblock (sign) */
|
||||
public LiftBlock(String world, int x, int y, int z, Material mat, byte data, String[] signLines) {
|
||||
this.world = world;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.mat = mat;
|
||||
this.face = null;
|
||||
this.data = data;
|
||||
this.signLines = signLines;
|
||||
this.floor = null;
|
||||
this.bisected = null;
|
||||
}
|
||||
|
||||
/** 1.13 liftblocks **/
|
||||
|
||||
/* 1.13 liftblock (no Dir) */
|
||||
public LiftBlock(String world, int x, int y, int z, Material mat) {
|
||||
this.world = world;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.mat = mat;
|
||||
this.face = null;
|
||||
this.data = 0;
|
||||
this.signLines = null;
|
||||
this.floor = null;
|
||||
this.bisected = null;
|
||||
}
|
||||
|
||||
/* 1.13 liftblock (Directional) */
|
||||
public LiftBlock(String world, int x, int y, int z, Material mat, BlockFace face) {
|
||||
this.world = world;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.mat = mat;
|
||||
this.face = face;
|
||||
this.data = 0;
|
||||
this.signLines = null;
|
||||
this.floor = null;
|
||||
this.bisected = null;
|
||||
}
|
||||
|
||||
/* 1.13 liftblock (dir & bisec) */
|
||||
public LiftBlock(String world, int x, int y, int z, Material mat, BlockFace face, String bisected) {
|
||||
this.world = world;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.mat = mat;
|
||||
this.face = face;
|
||||
this.data = 0;
|
||||
this.signLines = null;
|
||||
this.floor = null;
|
||||
this.bisected = bisected;
|
||||
}
|
||||
|
||||
/* 1.13 liftblock (sign) */
|
||||
public LiftBlock(String world, int x, int y, int z, Material mat, BlockFace face, String[] signLines) {
|
||||
this.world = world;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.mat = mat;
|
||||
this.face = face;
|
||||
this.data = 0;
|
||||
this.signLines = signLines;
|
||||
this.floor = null;
|
||||
this.bisected = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(@Nonnull LiftBlock lb) {
|
||||
int ret = Integer.compare(y, lb.y);
|
||||
if (ret == 0) ret = Integer.compare(x, lb.x);
|
||||
if (ret == 0) ret = Integer.compare(z, lb.z);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof LiftBlock)) {
|
||||
if (!(obj instanceof LiftSign)) return false;
|
||||
LiftSign other = (LiftSign) obj;
|
||||
return getWorld().equals(other.getWorld()) && getX() == other.getX() && getY() == other.getY() && getZ() == other.getZ();
|
||||
}
|
||||
LiftBlock other = (LiftBlock) obj;
|
||||
return getWorld().equals(other.getWorld()) && getX() == other.getX() && getY() == other.getY() && getZ() == other.getZ();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
String newLine = System.getProperty("line.separator");
|
||||
|
||||
result.append(this.getClass().getName());
|
||||
result.append(" Object {");
|
||||
result.append(newLine);
|
||||
|
||||
//determine fields declared in this class only (no fields of superclass)
|
||||
Field[] fields = this.getClass().getDeclaredFields();
|
||||
|
||||
//print field names paired with their values
|
||||
for (Field field: fields) {
|
||||
result.append(" ");
|
||||
try {
|
||||
result.append(field.getName());
|
||||
result.append(": ");
|
||||
//requires access to private field:
|
||||
result.append(field.get(this));
|
||||
} catch (IllegalAccessException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
result.append(newLine);
|
||||
}
|
||||
result.append("}");
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
package nl.SBDeveloper.V10Lift.API.Objects;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockFace;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
@Getter @Setter @NoArgsConstructor
|
||||
public class LiftRope {
|
||||
private Material type;
|
||||
private BlockFace face;
|
||||
private String world;
|
||||
private int x;
|
||||
private int minY;
|
||||
private int maxY;
|
||||
private int z;
|
||||
private int currently;
|
||||
|
||||
public LiftRope(Material type, BlockFace face, String world, int x, int minY, int maxY, int z) {
|
||||
this.type = type;
|
||||
this.face = face;
|
||||
this.world = world;
|
||||
this.x = x;
|
||||
this.minY = minY;
|
||||
this.maxY = maxY;
|
||||
this.z = z;
|
||||
this.currently = minY;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (obj == null) return false;
|
||||
if (!(obj instanceof LiftRope)) return false;
|
||||
LiftRope other = (LiftRope) obj;
|
||||
return getWorld().equals(other.getWorld())
|
||||
&& getX() == other.getX()
|
||||
&& getMinY() == other.getMinY()
|
||||
&& getMaxY() == other.getMaxY()
|
||||
&& getZ() == other.getZ();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
String newLine = System.getProperty("line.separator");
|
||||
|
||||
result.append(this.getClass().getName());
|
||||
result.append(" Object {");
|
||||
result.append(newLine);
|
||||
|
||||
//determine fields declared in this class only (no fields of superclass)
|
||||
Field[] fields = this.getClass().getDeclaredFields();
|
||||
|
||||
//print field names paired with their values
|
||||
for (Field field: fields) {
|
||||
result.append(" ");
|
||||
try {
|
||||
result.append(field.getName());
|
||||
result.append(": ");
|
||||
//requires access to private field:
|
||||
result.append(field.get(this));
|
||||
} catch (IllegalAccessException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
result.append(newLine);
|
||||
}
|
||||
result.append("}");
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
package nl.SBDeveloper.V10Lift.API.Objects;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
@Getter @Setter @NoArgsConstructor
|
||||
public class LiftSign {
|
||||
private String world;
|
||||
private int x;
|
||||
private int z;
|
||||
private int y;
|
||||
private String oldText = null;
|
||||
private byte type;
|
||||
private byte state;
|
||||
|
||||
public LiftSign(String world, int x, int y, int z, byte type, byte state) {
|
||||
this.world = world;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.type = type;
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof LiftSign)) {
|
||||
if (!(obj instanceof LiftBlock)) return false;
|
||||
LiftBlock other = (LiftBlock) obj;
|
||||
return getWorld().equals(other.getWorld()) && getX() == other.getX() && getY() == other.getY() && getZ() == other.getZ();
|
||||
}
|
||||
LiftSign other = (LiftSign) obj;
|
||||
return getWorld().equals(other.getWorld()) && getX() == other.getX() && getY() == other.getY() && getZ() == other.getZ();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
String newLine = System.getProperty("line.separator");
|
||||
|
||||
result.append(this.getClass().getName());
|
||||
result.append(" Object {");
|
||||
result.append(newLine);
|
||||
|
||||
//determine fields declared in this class only (no fields of superclass)
|
||||
Field[] fields = this.getClass().getDeclaredFields();
|
||||
|
||||
//print field names paired with their values
|
||||
for (Field field: fields) {
|
||||
result.append(" ");
|
||||
try {
|
||||
result.append(field.getName());
|
||||
result.append(": ");
|
||||
//requires access to private field:
|
||||
result.append(field.get(this));
|
||||
} catch (IllegalAccessException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
result.append(newLine);
|
||||
}
|
||||
result.append("}");
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
package nl.SBDeveloper.V10Lift.API.Objects;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter @NoArgsConstructor
|
||||
public class V10Entity {
|
||||
private UUID entityUUID;
|
||||
private String world;
|
||||
private int locX;
|
||||
private int locY;
|
||||
private int locZ;
|
||||
private int y;
|
||||
@Setter private short step;
|
||||
|
||||
public V10Entity(UUID entityUUID, String worldName, int x, int y, int z, int cury) {
|
||||
this.entityUUID = entityUUID;
|
||||
this.world = worldName;
|
||||
this.locX = x;
|
||||
this.locY = y;
|
||||
this.locZ = z;
|
||||
this.y = cury;
|
||||
this.step = 0;
|
||||
}
|
||||
|
||||
public void moveUp() {
|
||||
if (entityUUID == null) return;
|
||||
Entity entity = Bukkit.getEntity(entityUUID);
|
||||
if (entity == null || entity.isDead()) return;
|
||||
locY = y + step;
|
||||
entity.teleport(new Location(Bukkit.getWorld(world), locX, locY, locZ));
|
||||
}
|
||||
|
||||
public void moveDown() {
|
||||
if (entityUUID == null) return;
|
||||
Entity entity = Bukkit.getEntity(entityUUID);
|
||||
if (entity == null || entity.isDead()) return;
|
||||
locY = y - step;
|
||||
entity.teleport(new Location(Bukkit.getWorld(world), locX, locY, locZ));
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (obj == null) return false;
|
||||
if (obj instanceof V10Entity) {
|
||||
return ((V10Entity) obj).getEntityUUID().equals(getEntityUUID());
|
||||
} else if (obj instanceof Entity) {
|
||||
return ((Entity) obj).getUniqueId().equals(getEntityUUID());
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
String newLine = System.getProperty("line.separator");
|
||||
|
||||
result.append(this.getClass().getName());
|
||||
result.append(" Object {");
|
||||
result.append(newLine);
|
||||
|
||||
//determine fields declared in this class only (no fields of superclass)
|
||||
Field[] fields = this.getClass().getDeclaredFields();
|
||||
|
||||
//print field names paired with their values
|
||||
for (Field field: fields) {
|
||||
result.append(" ");
|
||||
try {
|
||||
result.append(field.getName());
|
||||
result.append(": ");
|
||||
//requires access to private field:
|
||||
result.append(field.get(this));
|
||||
} catch (IllegalAccessException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
result.append(newLine);
|
||||
}
|
||||
result.append("}");
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
package nl.SBDeveloper.V10Lift.API.Runnables;
|
||||
|
||||
import nl.SBDeveloper.V10Lift.Managers.DataManager;
|
||||
import nl.SBDeveloper.V10Lift.V10LiftPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class DoorCloser implements Runnable {
|
||||
private final String liftName;
|
||||
private int pid;
|
||||
|
||||
public DoorCloser(String liftName) {
|
||||
this.liftName = liftName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (V10LiftPlugin.getAPI().closeDoor(liftName)) stop();
|
||||
}
|
||||
|
||||
public void setPid(int pid) {
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
Bukkit.getScheduler().cancelTask(pid);
|
||||
if (DataManager.containsLift(liftName)) DataManager.getLift(liftName).setDoorCloser(null);
|
||||
}
|
||||
}
|
|
@ -1,516 +0,0 @@
|
|||
package nl.SBDeveloper.V10Lift.API.Runnables;
|
||||
|
||||
import nl.SBDeveloper.V10Lift.API.Objects.*;
|
||||
import nl.SBDeveloper.V10Lift.Managers.DataManager;
|
||||
import nl.SBDeveloper.V10Lift.Utils.DirectionUtil;
|
||||
import nl.SBDeveloper.V10Lift.Utils.XMaterial;
|
||||
import nl.SBDeveloper.V10Lift.Utils.XSound;
|
||||
import nl.SBDeveloper.V10Lift.V10LiftPlugin;
|
||||
import nl.SBDevelopment.SBUtilities.Utils.LocationSerializer;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Chest;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class MoveLift implements Runnable {
|
||||
|
||||
private final String liftName;
|
||||
private final int ft;
|
||||
|
||||
public MoveLift(String liftName, long speed) {
|
||||
this.liftName = liftName;
|
||||
|
||||
if (speed > 32L) {
|
||||
ft = 1;
|
||||
} else if (speed > 16L) {
|
||||
ft = 2;
|
||||
} else if (speed > 8L) {
|
||||
ft = 4;
|
||||
} else if (speed > 4L) {
|
||||
ft = 8;
|
||||
} else if (speed > 2L) {
|
||||
ft = 16;
|
||||
} else if (speed > 1L) {
|
||||
ft = 32;
|
||||
} else {
|
||||
ft = 64;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Iterator<LiftBlock> iter;
|
||||
ArrayList<LiftBlock> tb = new ArrayList<>();
|
||||
Block block = null;
|
||||
World world;
|
||||
Location loc;
|
||||
BlockState bs;
|
||||
boolean by;
|
||||
int y;
|
||||
Chest c;
|
||||
V10Entity v10ent;
|
||||
Iterator<V10Entity> veiter;
|
||||
Sign sign;
|
||||
LiftBlock lb;
|
||||
Lift lift;
|
||||
LiftSign ls;
|
||||
Inventory inv;
|
||||
ItemStack is;
|
||||
ItemStack[] isa;
|
||||
|
||||
lift = DataManager.getLift(liftName);
|
||||
if (lift == null) {
|
||||
stopMe();
|
||||
return;
|
||||
}
|
||||
|
||||
if (lift.getQueue().isEmpty() || lift.isOffline()) {
|
||||
lift.setQueue(null);
|
||||
stopMe();
|
||||
return;
|
||||
}
|
||||
|
||||
if (DataManager.containsEditLift(liftName) || lift.isDefective()) return;
|
||||
|
||||
if (lift.getCounter() > 0) {
|
||||
lift.setCounter(lift.getCounter() - 1);
|
||||
return;
|
||||
}
|
||||
|
||||
lb = lift.getBlocks().first();
|
||||
world = Bukkit.getWorld(lb.getWorld());
|
||||
if (world == null) {
|
||||
lift.setCounter(ft);
|
||||
return;
|
||||
}
|
||||
|
||||
loc = new Location(world, lb.getX(), lb.getY(), lb.getZ());
|
||||
if (!loc.getChunk().isLoaded()) {
|
||||
lift.setCounter(ft);
|
||||
return;
|
||||
}
|
||||
|
||||
lb = lift.getBlocks().last();
|
||||
world = Bukkit.getWorld(lb.getWorld());
|
||||
if (world == null) {
|
||||
lift.setCounter(ft);
|
||||
return;
|
||||
}
|
||||
|
||||
loc = new Location(world, lb.getX(), lb.getY(), lb.getZ());
|
||||
if (!loc.getChunk().isLoaded()) {
|
||||
lift.setCounter(ft);
|
||||
return;
|
||||
}
|
||||
|
||||
double changeOfDefect = V10LiftPlugin.getSConfig().getFile().getDouble("DefectRate");
|
||||
if (changeOfDefect > 0.0D) {
|
||||
y = new Random().nextInt(100);
|
||||
double chance;
|
||||
if (y < 100) {
|
||||
long co = new Random().nextLong();
|
||||
if (co < 0) co = -co;
|
||||
chance = Double.parseDouble(y + "." + co);
|
||||
} else {
|
||||
chance = y;
|
||||
}
|
||||
|
||||
if (chance < changeOfDefect) {
|
||||
V10LiftPlugin.getAPI().setDefective(liftName, true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Iterator<Map.Entry<String, Floor>> quiter = lift.getQueue().entrySet().iterator();
|
||||
Map.Entry<String, Floor> floor = quiter.next();
|
||||
Floor to = floor.getValue();
|
||||
String fl = floor.getKey();
|
||||
boolean up = false;
|
||||
boolean down = false;
|
||||
if (lift.getY() < to.getY()) {
|
||||
up = true;
|
||||
} else if (lift.getY() > to.getY()) {
|
||||
down = true;
|
||||
}
|
||||
|
||||
if (up) {
|
||||
if (!V10LiftPlugin.getAPI().closeDoor(liftName)) return;
|
||||
|
||||
//MOVE ROPES
|
||||
for (LiftRope rope : lift.getRopes()) {
|
||||
if (rope.getCurrently() > rope.getMaxY()) {
|
||||
Bukkit.getLogger().info("[V10Lift] Lift " + liftName + " reaches the upper rope end but won't stop!! 1");
|
||||
V10LiftPlugin.getAPI().setDefective(liftName, true);
|
||||
lift.getToMove().clear();
|
||||
quiter.remove();
|
||||
return;
|
||||
}
|
||||
world = Objects.requireNonNull(Bukkit.getWorld(rope.getWorld()), "World is null at MoveLift");
|
||||
block = world.getBlockAt(rope.getX(), rope.getCurrently(), rope.getZ());
|
||||
block.setType(Material.AIR);
|
||||
rope.setCurrently(rope.getCurrently() + 1);
|
||||
}
|
||||
|
||||
iter = lift.getBlocks().iterator();
|
||||
while (iter.hasNext()) {
|
||||
lb = iter.next();
|
||||
if (V10LiftPlugin.getAPI().getACBM().isAntiCopy(lb.getMat())) {
|
||||
tb.add(lb);
|
||||
iter.remove();
|
||||
block = Objects.requireNonNull(Bukkit.getWorld(lb.getWorld()), "World is null at MoveLift").getBlockAt(lb.getX(), lb.getY(), lb.getZ());
|
||||
block.setType(Material.AIR);
|
||||
lb.setY(lb.getY() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
boolean wc = false;
|
||||
for (LiftBlock lib : lift.getBlocks().descendingSet()) {
|
||||
world = Objects.requireNonNull(Bukkit.getWorld(lib.getWorld()), "World is null at MoveLift");
|
||||
block = world.getBlockAt(lib.getX(), lib.getY(), lib.getZ());
|
||||
if ((lib.getMat() == Material.CHEST || lib.getMat() == Material.TRAPPED_CHEST) && lib.serializedItemStacks == null) {
|
||||
c = (Chest) block.getState();
|
||||
inv = c.getInventory();
|
||||
isa = inv.getContents();
|
||||
by = false;
|
||||
lib.serializedItemStacks = new Map[isa.length];
|
||||
for (int i = 0; i < isa.length; i++) {
|
||||
is = isa[i];
|
||||
if (is != null) {
|
||||
by = true;
|
||||
lib.serializedItemStacks[i] = is.serialize();
|
||||
}
|
||||
}
|
||||
if (by) {
|
||||
inv.clear();
|
||||
c.update();
|
||||
} else {
|
||||
lib.serializedItemStacks = null;
|
||||
}
|
||||
}
|
||||
|
||||
block.setType(Material.AIR);
|
||||
lib.setY(lib.getY() + 1);
|
||||
block = Objects.requireNonNull(Bukkit.getWorld(lib.getWorld()), "World is null at MoveLift").getBlockAt(lib.getX(), lib.getY(), lib.getZ());
|
||||
BlockState state = block.getState();
|
||||
state.setType(lib.getMat());
|
||||
if (!XMaterial.isNewVersion()) {
|
||||
state.setRawData(lib.getData());
|
||||
}
|
||||
state.update(true);
|
||||
if (XMaterial.isNewVersion()) {
|
||||
DirectionUtil.setDirection(block, lib.getFace());
|
||||
DirectionUtil.setBisected(block, lib.getBisected());
|
||||
}
|
||||
lb = lift.getBlocks().first();
|
||||
for (Entity ent : Objects.requireNonNull(Bukkit.getWorld(lib.getWorld()), "World is null at MoveLift").getBlockAt(lib.getX(), lib.getY(), lib.getZ()).getChunk().getEntities()) {
|
||||
v10ent = new V10Entity(ent.getUniqueId(), null, 0, 0, 0, 0);
|
||||
if (lift.getToMove().contains(v10ent)) continue;
|
||||
loc = ent.getLocation();
|
||||
y = loc.getBlockY();
|
||||
if (y == lib.getY()) {
|
||||
by = true;
|
||||
} else if (y + 1 == lib.getY()) {
|
||||
by = true;
|
||||
y++;
|
||||
} else {
|
||||
by = false;
|
||||
}
|
||||
|
||||
if (by && loc.getBlockX() == lib.getX() && loc.getBlockZ() == lib.getZ()) {
|
||||
loc.setY(loc.getY() + 1);
|
||||
ent.teleport(loc);
|
||||
}
|
||||
}
|
||||
}
|
||||
veiter = lift.getToMove().iterator();
|
||||
while (veiter.hasNext()) {
|
||||
v10ent = veiter.next();
|
||||
if (v10ent.getStep() > 0) {
|
||||
v10ent.moveUp();
|
||||
if (v10ent.getStep() > 16) {
|
||||
veiter.remove();
|
||||
}
|
||||
}
|
||||
v10ent.setStep((short) (v10ent.getStep() + 1));
|
||||
}
|
||||
for (LiftBlock lib : tb) {
|
||||
block = Objects.requireNonNull(Bukkit.getWorld(lib.getWorld()), "World is null at MoveLift").getBlockAt(lib.getX(), lib.getY(), lib.getZ());
|
||||
BlockState state = block.getState();
|
||||
state.setType(lib.getMat());
|
||||
if (!XMaterial.isNewVersion()) {
|
||||
state.setRawData(lib.getData());
|
||||
}
|
||||
state.update(true);
|
||||
if (XMaterial.isNewVersion()) {
|
||||
DirectionUtil.setDirection(block, lib.getFace());
|
||||
DirectionUtil.setBisected(block, lib.getBisected());
|
||||
}
|
||||
lift.getBlocks().add(lib);
|
||||
if (lib.getSignLines() != null) {
|
||||
bs = block.getState();
|
||||
if (bs instanceof Sign) {
|
||||
sign = (Sign) bs;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
sign.setLine(i, lib.getSignLines()[i]);
|
||||
if (i == 0 && lib.getSignLines()[i].equalsIgnoreCase("[v10lift]") && lib.getSignLines()[1].equals(liftName)) {
|
||||
sign.setLine(1, liftName);
|
||||
sign.setLine(3, ChatColor.GOLD + fl);
|
||||
}
|
||||
}
|
||||
sign.update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lift.setY(lift.getY() + 1);
|
||||
Iterator<LiftSign> liter = lift.getSigns().iterator();
|
||||
while (liter.hasNext()) {
|
||||
ls = liter.next();
|
||||
if (ls.getState() == 1) continue;
|
||||
block = Objects.requireNonNull(Bukkit.getWorld(ls.getWorld()), "World is null at MoveLift").getBlockAt(ls.getX(), ls.getY(), ls.getZ());
|
||||
bs = block.getState();
|
||||
if (!(bs instanceof Sign)) {
|
||||
Bukkit.getLogger().severe("[V10Lift] Wrong sign removed at: " + LocationSerializer.serialize(block.getLocation()));
|
||||
liter.remove();
|
||||
continue;
|
||||
}
|
||||
sign = (Sign) bs;
|
||||
if (ls.getType() == 0) {
|
||||
sign.setLine(3, ChatColor.GREEN + "up");
|
||||
} else {
|
||||
sign.setLine(3, ChatColor.GRAY + ChatColor.stripColor(sign.getLine(3)));
|
||||
}
|
||||
sign.update();
|
||||
ls.setState((byte) 1);
|
||||
}
|
||||
} else if (down) {
|
||||
if (!V10LiftPlugin.getAPI().closeDoor(liftName)) return;
|
||||
|
||||
iter = lift.getBlocks().iterator();
|
||||
while (iter.hasNext()) {
|
||||
lb = iter.next();
|
||||
if (V10LiftPlugin.getAPI().getACBM().isAntiCopy(lb.getMat())) {
|
||||
tb.add(lb);
|
||||
iter.remove();
|
||||
block = Objects.requireNonNull(Bukkit.getWorld(lb.getWorld()), "World is null at MoveLift").getBlockAt(lb.getX(), lb.getY(), lb.getZ());
|
||||
block.setType(Material.AIR);
|
||||
lb.setY(lb.getY() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
for (LiftBlock lib : lift.getBlocks()) {
|
||||
block = Objects.requireNonNull(Bukkit.getWorld(lib.getWorld()), "World is null at MoveLift").getBlockAt(lib.getX(), lib.getY(), lib.getZ());
|
||||
if ((lib.getMat() == Material.CHEST || lib.getMat() == Material.TRAPPED_CHEST) && lib.serializedItemStacks == null) {
|
||||
c = (Chest) block.getState();
|
||||
inv = c.getInventory();
|
||||
isa = inv.getContents();
|
||||
by = false;
|
||||
lib.serializedItemStacks = new Map[isa.length];
|
||||
for (int i = 0; i < isa.length; i++) {
|
||||
is = isa[i];
|
||||
if (is != null) {
|
||||
by = true;
|
||||
lib.serializedItemStacks[i] = is.serialize();
|
||||
}
|
||||
}
|
||||
if (by) {
|
||||
inv.clear();
|
||||
c.update();
|
||||
} else {
|
||||
lib.serializedItemStacks = null;
|
||||
}
|
||||
}
|
||||
block.setType(Material.AIR);
|
||||
lib.setY(lib.getY() - 1);
|
||||
y = lib.getY();
|
||||
block = world.getBlockAt(lib.getX(), lib.getY(), lib.getZ());
|
||||
BlockState state = block.getState();
|
||||
state.setType(lib.getMat());
|
||||
if (!XMaterial.isNewVersion()) {
|
||||
state.setRawData(lib.getData());
|
||||
}
|
||||
state.update(true);
|
||||
if (XMaterial.isNewVersion()) {
|
||||
DirectionUtil.setDirection(block, lib.getFace());
|
||||
DirectionUtil.setBisected(block, lib.getBisected());
|
||||
}
|
||||
}
|
||||
veiter = lift.getToMove().iterator();
|
||||
while (veiter.hasNext()) {
|
||||
v10ent = veiter.next();
|
||||
if (v10ent.getStep() > 0) {
|
||||
v10ent.moveDown();
|
||||
if (v10ent.getStep() > 16) {
|
||||
veiter.remove();
|
||||
}
|
||||
}
|
||||
v10ent.setStep((short) (v10ent.getStep() + 1));
|
||||
}
|
||||
for (LiftBlock lib : tb) {
|
||||
block = Objects.requireNonNull(Bukkit.getWorld(lib.getWorld()), "World is null at MoveLift").getBlockAt(lib.getX(), lib.getY(), lib.getZ());
|
||||
BlockState state = block.getState();
|
||||
state.setType(lib.getMat());
|
||||
if (!XMaterial.isNewVersion()) {
|
||||
state.setRawData(lib.getData());
|
||||
}
|
||||
state.update(true);
|
||||
if (XMaterial.isNewVersion()) {
|
||||
DirectionUtil.setDirection(block, lib.getFace());
|
||||
DirectionUtil.setBisected(block, lib.getBisected());
|
||||
}
|
||||
lift.getBlocks().add(lib);
|
||||
if (lib.getSignLines() != null) {
|
||||
bs = block.getState();
|
||||
if (bs instanceof Sign) {
|
||||
sign = (Sign) bs;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
sign.setLine(i, lib.getSignLines()[i]);
|
||||
if (i == 0 && lib.getSignLines()[i].equalsIgnoreCase("[v10lift]") && lib.getSignLines()[1].equals(liftName)) {
|
||||
sign.setLine(1, liftName);
|
||||
sign.setLine(3, ChatColor.GOLD + fl);
|
||||
}
|
||||
}
|
||||
sign.update();
|
||||
}
|
||||
}
|
||||
}
|
||||
lift.setY(lift.getY() - 1);
|
||||
Iterator<LiftSign> liter = lift.getSigns().iterator();
|
||||
while (liter.hasNext()) {
|
||||
ls = liter.next();
|
||||
if (ls.getState() == 2) continue;
|
||||
block = Objects.requireNonNull(Bukkit.getWorld(ls.getWorld()), "World is null at MoveLift").getBlockAt(ls.getX(), ls.getY(), ls.getZ());
|
||||
bs = block.getState();
|
||||
if (!(bs instanceof Sign)) {
|
||||
Bukkit.getLogger().severe("[V10Lift] Wrong sign removed at: " + LocationSerializer.serialize(block.getLocation()));
|
||||
liter.remove();
|
||||
continue;
|
||||
}
|
||||
sign = (Sign) bs;
|
||||
if (ls.getType() == 0) {
|
||||
sign.setLine(3, ChatColor.GREEN + "down");
|
||||
} else {
|
||||
sign.setLine(3, ChatColor.GRAY + ChatColor.stripColor(sign.getLine(3)));
|
||||
}
|
||||
sign.update();
|
||||
ls.setState((byte) 2);
|
||||
}
|
||||
|
||||
//MOVE ROPES
|
||||
for (LiftRope rope : lift.getRopes()) {
|
||||
|
||||
if (rope.getCurrently() < rope.getMinY()) {
|
||||
Bukkit.getLogger().info("[V10Lift] Lift " + liftName + " reaches the upper rope end but won't stop!! 2");
|
||||
V10LiftPlugin.getAPI().setDefective(liftName, true);
|
||||
lift.getToMove().clear();
|
||||
quiter.remove();
|
||||
rope.setCurrently(rope.getCurrently() - 1);
|
||||
block = world.getBlockAt(rope.getX(), rope.getCurrently(), rope.getZ());
|
||||
block.setType(rope.getType());
|
||||
if (XMaterial.isNewVersion()) {
|
||||
org.bukkit.block.data.Directional data = (org.bukkit.block.data.Directional) block.getBlockData();
|
||||
data.setFacing(rope.getFace());
|
||||
block.setBlockData(data);
|
||||
} else {
|
||||
BlockState state = block.getState();
|
||||
org.bukkit.material.Ladder ladder = new org.bukkit.material.Ladder(rope.getType());
|
||||
ladder.setFacingDirection(rope.getFace());
|
||||
state.setData(ladder);
|
||||
state.update(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
world = Objects.requireNonNull(Bukkit.getWorld(rope.getWorld()), "World is null at MoveLift");
|
||||
rope.setCurrently(rope.getCurrently() - 1);
|
||||
block = world.getBlockAt(rope.getX(), rope.getCurrently(), rope.getZ());
|
||||
block.setType(rope.getType());
|
||||
if (XMaterial.isNewVersion()) {
|
||||
org.bukkit.block.data.Directional data = (org.bukkit.block.data.Directional) block.getBlockData();
|
||||
data.setFacing(rope.getFace());
|
||||
block.setBlockData(data);
|
||||
} else {
|
||||
BlockState state = block.getState();
|
||||
org.bukkit.material.Ladder ladder = new org.bukkit.material.Ladder(rope.getType());
|
||||
ladder.setFacingDirection(rope.getFace());
|
||||
state.setData(ladder);
|
||||
state.update(true);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
lift.getToMove().clear();
|
||||
quiter.remove();
|
||||
bs = null;
|
||||
for (LiftBlock lib : lift.getBlocks()) {
|
||||
bs = Objects.requireNonNull(Bukkit.getWorld(lib.getWorld()), "World is null at MoveLift").getBlockAt(lib.getX(), lib.getY(), lib.getZ()).getState();
|
||||
if (!(bs instanceof Sign)) {
|
||||
if (bs instanceof Chest && lib.serializedItemStacks != null) {
|
||||
isa = new ItemStack[lib.serializedItemStacks.length];
|
||||
by = false;
|
||||
for (int i = 0; i < lib.serializedItemStacks.length; i++) {
|
||||
if (lib.serializedItemStacks[i] != null) {
|
||||
isa[i] = ItemStack.deserialize(lib.serializedItemStacks[i]);
|
||||
by = true;
|
||||
}
|
||||
}
|
||||
if (by) {
|
||||
c = (Chest) bs;
|
||||
c.getInventory().setContents(isa);
|
||||
c.update();
|
||||
}
|
||||
lib.serializedItemStacks = null;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
sign = (Sign) bs;
|
||||
if (!sign.getLine(0).equalsIgnoreCase("[v10lift]")) continue;
|
||||
sign.setLine(1, liftName);
|
||||
sign.setLine(3, ChatColor.GREEN + fl);
|
||||
sign.update();
|
||||
}
|
||||
Iterator<LiftSign> liter = lift.getSigns().iterator();
|
||||
while (liter.hasNext()) {
|
||||
ls = liter.next();
|
||||
if (ls.getState() == 0) continue;
|
||||
block = Objects.requireNonNull(Bukkit.getWorld(ls.getWorld()), "World is null at MoveLift").getBlockAt(ls.getX(), ls.getY(), ls.getZ());
|
||||
bs = block.getState();
|
||||
if (!(bs instanceof Sign)) {
|
||||
Bukkit.getLogger().severe("[V10Lift] Wrong sign removed at: " + LocationSerializer.serialize(block.getLocation()));
|
||||
liter.remove();
|
||||
continue;
|
||||
}
|
||||
sign = (Sign) bs;
|
||||
if (ls.getType() == 0) {
|
||||
sign.setLine(3, ChatColor.GREEN + fl);
|
||||
} else {
|
||||
String l3 = ChatColor.stripColor(sign.getLine(3));
|
||||
if (!fl.equals(l3)) {
|
||||
sign.setLine(3, ChatColor.GRAY + l3);
|
||||
} else {
|
||||
sign.setLine(3, ChatColor.GREEN + l3);
|
||||
}
|
||||
}
|
||||
sign.update();
|
||||
ls.setState((byte) 0);
|
||||
}
|
||||
V10LiftPlugin.getAPI().openDoor(lift, liftName, to);
|
||||
if (lift.isRealistic()) lift.setCounter(ft);
|
||||
if (lift.isSound()) {
|
||||
if (block != null) {
|
||||
loc = block.getLocation();
|
||||
XSound.ENTITY_EXPERIENCE_ORB_PICKUP.playSound(loc, 2.0F, 63.0F);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void stopMe() {
|
||||
Bukkit.getServer().getScheduler().cancelTask(DataManager.getMovingTask(liftName));
|
||||
DataManager.removeMovingTask(liftName);
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -1,946 +0,0 @@
|
|||
package nl.SBDeveloper.V10Lift.Commands;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import nl.SBDeveloper.V10Lift.API.Objects.Floor;
|
||||
import nl.SBDeveloper.V10Lift.API.Objects.Lift;
|
||||
import nl.SBDeveloper.V10Lift.API.Objects.LiftBlock;
|
||||
import nl.SBDeveloper.V10Lift.API.Objects.LiftSign;
|
||||
import nl.SBDeveloper.V10Lift.Managers.DataManager;
|
||||
import nl.SBDeveloper.V10Lift.Utils.ConfigUtil;
|
||||
import nl.SBDeveloper.V10Lift.Utils.XMaterial;
|
||||
import nl.SBDeveloper.V10Lift.V10LiftPlugin;
|
||||
import nl.SBDevelopment.SBUtilities.Utils.LocationSerializer;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
|
||||
public class V10LiftCommand implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@Nonnull CommandSender sender, @Nonnull Command cmd, @Nonnull String label, @Nonnull String[] args) {
|
||||
if (args.length == 0) {
|
||||
//v10lift
|
||||
return helpCommand(sender);
|
||||
} else if (args[0].equalsIgnoreCase("info") && args.length == 1) {
|
||||
//v10lift info
|
||||
return infoCommand(sender);
|
||||
} else if (args[0].equalsIgnoreCase("create") && (args.length == 1 || args.length == 2)) {
|
||||
//v10lift create || v10lift create <Name>
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(ChatColor.RED + "You have to be a player to do this.");
|
||||
return true;
|
||||
}
|
||||
if (sender.hasPermission("v10lift.build") || sender.hasPermission("v10lift.admin")) {
|
||||
return createCommand(sender, args);
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!");
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("delete") && args.length == 2) {
|
||||
//v10lift delete <Name>
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(ChatColor.RED + "You have to be a player to do this.");
|
||||
return true;
|
||||
}
|
||||
if (sender.hasPermission("v10lift.build") || sender.hasPermission("v10lift.admin")) {
|
||||
return deleteCommand(sender, args);
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!");
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("edit") && (args.length == 1 || args.length == 2)) {
|
||||
//v10lift edit <Name>
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(ChatColor.RED + "You have to be a player to do this.");
|
||||
return true;
|
||||
}
|
||||
if (sender.hasPermission("v10lift.build") || sender.hasPermission("v10lift.admin")) {
|
||||
return editCommand(sender, args);
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!");
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("floor") && (args.length == 3 || args.length == 4)) {
|
||||
//v10lift floor add <Name> || v10lift floor del <Name> || v10lift floor rename <Old> <New>
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(ChatColor.RED + "You have to be a player to do this.");
|
||||
return true;
|
||||
}
|
||||
if (sender.hasPermission("v10lift.build") || sender.hasPermission("v10lift.admin")) {
|
||||
return floorCommand(sender, args);
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!");
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("input") && (args.length == 2 || args.length == 3)) {
|
||||
//v10lift input add <Floor name> || v10lift input del
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(ChatColor.RED + "You have to be a player to do this.");
|
||||
return true;
|
||||
}
|
||||
if (sender.hasPermission("v10lift.build") || sender.hasPermission("v10lift.admin")) {
|
||||
return inputCommand(sender, args);
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!");
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("offline") && args.length == 2) {
|
||||
//v10lift offline add || v10lift offline del
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(ChatColor.RED + "You have to be a player to do this.");
|
||||
return true;
|
||||
}
|
||||
if (sender.hasPermission("v10lift.build") || sender.hasPermission("v10lift.admin")) {
|
||||
return offlineCommand(sender, args);
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!");
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("rename") && args.length == 2) {
|
||||
//v10lift rename <New name>
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(ChatColor.RED + "You have to be a player to do this.");
|
||||
return true;
|
||||
}
|
||||
if (sender.hasPermission("v10lift.build") || sender.hasPermission("v10lift.admin")) {
|
||||
return renameCommand(sender, args);
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!");
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("build") && args.length == 1) {
|
||||
//v10lift build
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(ChatColor.RED + "You have to be a player to do this.");
|
||||
return true;
|
||||
}
|
||||
if (sender.hasPermission("v10lift.build") || sender.hasPermission("v10lift.admin")) {
|
||||
return buildCommand(sender);
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!");
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("rope") && args.length == 2) {
|
||||
//v10lift rope add || v10lift rope del
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(ChatColor.RED + "You have to be a player to do this.");
|
||||
return true;
|
||||
}
|
||||
if (sender.hasPermission("v10lift.build") || sender.hasPermission("v10lift.admin")) {
|
||||
return ropeCommand(sender, args);
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!");
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("door") && (args.length == 1 || args.length == 2)) {
|
||||
//v10lift door <Name> || v10lift door
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(ChatColor.RED + "You have to be a player to do this.");
|
||||
return true;
|
||||
}
|
||||
if (sender.hasPermission("v10lift.build") || sender.hasPermission("v10lift.admin")) {
|
||||
return doorCommand(sender, args);
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!");
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("whitelist") && (args.length == 3 || args.length == 4)) {
|
||||
//v10lift whitelist add <Player> <Floor> || v10lift whitelist del <Player> <Floor>
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(ChatColor.RED + "You have to be a player to do this.");
|
||||
return true;
|
||||
}
|
||||
if (sender.hasPermission("v10lift.build") || sender.hasPermission("v10lift.admin")) {
|
||||
return whitelistCommand(sender, args);
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!");
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("whois") && (args.length == 1 || args.length == 2)) {
|
||||
//v10lift whois || v10lift whois <Name>
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(ChatColor.RED + "You have to be a player to do this.");
|
||||
return true;
|
||||
}
|
||||
if (sender.hasPermission("v10lift.build") || sender.hasPermission("v10lift.admin")) {
|
||||
return whoisCommand(sender, args);
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!");
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("speed") && args.length == 2) {
|
||||
//v10lift speed <Speed>
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(ChatColor.RED + "You have to be a player to do this.");
|
||||
return true;
|
||||
}
|
||||
if (sender.hasPermission("v10lift.build") || sender.hasPermission("v10lift.admin")) {
|
||||
return speedCommand(sender, args);
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!");
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("sound") && args.length == 1) {
|
||||
//v10lift sound
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(ChatColor.RED + "You have to be a player to do this.");
|
||||
return true;
|
||||
}
|
||||
if (sender.hasPermission("v10lift.build") || sender.hasPermission("v10lift.admin")) {
|
||||
return soundCommand(sender);
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!");
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("realistic") && args.length == 1) {
|
||||
//v10lift realistic
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(ChatColor.RED + "You have to be a player to do this.");
|
||||
return true;
|
||||
}
|
||||
if (sender.hasPermission("v10lift.build") || sender.hasPermission("v10lift.admin")) {
|
||||
return realisticCommand(sender);
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!");
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("abort") && args.length == 1) {
|
||||
//v10lift abort
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(ChatColor.RED + "You have to be a player to do this.");
|
||||
return true;
|
||||
}
|
||||
if (sender.hasPermission("v10lift.build") || sender.hasPermission("v10lift.admin")) {
|
||||
return abortCommand(sender);
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!");
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("reload") && args.length == 1) {
|
||||
//v10lift reload
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(ChatColor.RED + "You have to be a player to do this.");
|
||||
return true;
|
||||
}
|
||||
if (sender.hasPermission("v10lift.admin")) {
|
||||
return reloadCommand(sender);
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!");
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("repair") && args.length == 2) {
|
||||
//v10lift repair <Name>
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(ChatColor.RED + "You have to be a player to do this.");
|
||||
return true;
|
||||
}
|
||||
if (sender.hasPermission("v10lift.build") || sender.hasPermission("v10lift.admin")) {
|
||||
return repairCommand(sender, args);
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!");
|
||||
}
|
||||
} else {
|
||||
return helpCommand(sender);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean reloadCommand(CommandSender sender) {
|
||||
for (Map.Entry<String, Lift> e : DataManager.getLifts().entrySet()) {
|
||||
String lift = e.getKey();
|
||||
if (DataManager.containsMovingTask(lift)) {
|
||||
Bukkit.getScheduler().cancelTask(DataManager.getMovingTask(lift));
|
||||
}
|
||||
|
||||
e.getValue().setQueue(null);
|
||||
V10LiftPlugin.getAPI().sortLiftBlocks(lift);
|
||||
}
|
||||
|
||||
DataManager.clearMovingTasks();
|
||||
V10LiftPlugin.getSConfig().reloadConfig();
|
||||
try {
|
||||
V10LiftPlugin.getDBManager().save();
|
||||
V10LiftPlugin.getDBManager().load();
|
||||
} catch (SQLException | JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.YELLOW + "Plugin reset successful!");
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean abortCommand(CommandSender sender) {
|
||||
Player p = (Player) sender;
|
||||
boolean abort = false;
|
||||
|
||||
if (DataManager.containsPlayer(p.getUniqueId())) {
|
||||
DataManager.removePlayer(p.getUniqueId());
|
||||
abort = true;
|
||||
}
|
||||
|
||||
if (DataManager.containsWhoisREQPlayer(p.getUniqueId())) {
|
||||
DataManager.removeWhoisREQPlayer(p.getUniqueId());
|
||||
abort = true;
|
||||
}
|
||||
|
||||
if (DataManager.containsInputEditsPlayer(p.getUniqueId())) {
|
||||
DataManager.removeInputEditsPlayer(p.getUniqueId());
|
||||
abort = true;
|
||||
}
|
||||
|
||||
if (DataManager.containsInputRemovesPlayer(p.getUniqueId())) {
|
||||
DataManager.removeInputRemovesPlayer(p.getUniqueId());
|
||||
abort = true;
|
||||
}
|
||||
|
||||
if (DataManager.containsOfflineEditsPlayer(p.getUniqueId())) {
|
||||
DataManager.removeOfflineEditsPlayer(p.getUniqueId());
|
||||
abort = true;
|
||||
}
|
||||
|
||||
if (DataManager.containsOfflineRemovesPlayer(p.getUniqueId())) {
|
||||
DataManager.removeOfflineRemovesPlayer(p.getUniqueId());
|
||||
abort = true;
|
||||
}
|
||||
|
||||
if (DataManager.containsBuilderPlayer(p.getUniqueId())) {
|
||||
DataManager.removeBuilderPlayer(p.getUniqueId());
|
||||
V10LiftPlugin.getAPI().sortLiftBlocks(DataManager.getEditPlayer(p.getUniqueId()));
|
||||
abort = true;
|
||||
}
|
||||
|
||||
if (DataManager.containsRopeEditPlayer(p.getUniqueId())) {
|
||||
DataManager.removeRopeEditPlayer(p.getUniqueId());
|
||||
abort = true;
|
||||
}
|
||||
|
||||
if (DataManager.containsRopeRemovesPlayer(p.getUniqueId())) {
|
||||
DataManager.removeRopeRemovesPlayer(p.getUniqueId());
|
||||
abort = true;
|
||||
}
|
||||
|
||||
if (DataManager.containsDoorEditPlayer(p.getUniqueId())) {
|
||||
DataManager.removeDoorEditPlayer(p.getUniqueId());
|
||||
abort = true;
|
||||
}
|
||||
|
||||
if (abort) {
|
||||
p.sendMessage(ChatColor.GOLD + "Cancelled.");
|
||||
} else {
|
||||
p.sendMessage(ChatColor.RED + "Oops! You can't cancel anything.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean repairCommand(CommandSender sender, @Nonnull String[] args) {
|
||||
Player p = (Player) sender;
|
||||
String liftName = args[1];
|
||||
if (!DataManager.containsLift(liftName)) {
|
||||
sender.sendMessage(ChatColor.RED + "Lift " + args[1] + " doesn't exists!");
|
||||
return true;
|
||||
}
|
||||
|
||||
Lift lift = DataManager.getLift(liftName);
|
||||
|
||||
if (!lift.isDefective()) {
|
||||
sender.sendMessage(ChatColor.RED + "This lift isn't defective!");
|
||||
return true;
|
||||
}
|
||||
|
||||
int masterAmount = V10LiftPlugin.getSConfig().getFile().getInt("MasterRepairAmount");
|
||||
Optional<XMaterial> mat = XMaterial.matchXMaterial(Objects.requireNonNull(V10LiftPlugin.getSConfig().getFile().getString("MasterRepairItem"), "MasterRepairItem is null"));
|
||||
if (!mat.isPresent()) {
|
||||
Bukkit.getLogger().severe("[V10Lift] The material for MasterRepairItem is undefined!");
|
||||
return true;
|
||||
}
|
||||
Material masterItem = mat.get().parseMaterial();
|
||||
if (masterItem == null) {
|
||||
Bukkit.getLogger().severe("[V10Lift] The material for MasterRepairItem is undefined!");
|
||||
return true;
|
||||
}
|
||||
if (p.getGameMode() != GameMode.CREATIVE && masterAmount > 0) {
|
||||
if (!p.getInventory().contains(masterItem)) {
|
||||
sender.sendMessage(ChatColor.RED + "You need " + masterAmount + "x " + masterItem.toString().toLowerCase() + "!");
|
||||
return true;
|
||||
}
|
||||
p.getInventory().remove(new ItemStack(masterItem, masterAmount));
|
||||
}
|
||||
V10LiftPlugin.getAPI().setDefective(liftName, false);
|
||||
sender.sendMessage(ChatColor.GREEN + "Lift repaired!");
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean realisticCommand(CommandSender sender) {
|
||||
Player p = (Player) sender;
|
||||
if (!DataManager.containsEditPlayer(p.getUniqueId())) {
|
||||
sender.sendMessage(ChatColor.RED + "First switch on the editor mode!");
|
||||
return true;
|
||||
}
|
||||
|
||||
Lift lift = DataManager.getLift(DataManager.getEditPlayer(p.getUniqueId()));
|
||||
lift.setRealistic(!lift.isRealistic());
|
||||
sender.sendMessage(ChatColor.GREEN + "Realistic mode turned " + (lift.isSound() ? "on" : "off") + "!");
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean soundCommand(CommandSender sender) {
|
||||
Player p = (Player) sender;
|
||||
if (!DataManager.containsEditPlayer(p.getUniqueId())) {
|
||||
sender.sendMessage(ChatColor.RED + "First switch on the editor mode!");
|
||||
return true;
|
||||
}
|
||||
|
||||
Lift lift = DataManager.getLift(DataManager.getEditPlayer(p.getUniqueId()));
|
||||
lift.setSound(!lift.isSound());
|
||||
sender.sendMessage(ChatColor.GREEN + "Sound mode turned " + (lift.isSound() ? "on" : "off") + "!");
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean speedCommand(CommandSender sender, String[] args) {
|
||||
Player p = (Player) sender;
|
||||
if (!DataManager.containsEditPlayer(p.getUniqueId())) {
|
||||
sender.sendMessage(ChatColor.RED + "First switch on the editor mode!");
|
||||
return true;
|
||||
}
|
||||
|
||||
Lift lift = DataManager.getLift(DataManager.getEditPlayer(p.getUniqueId()));
|
||||
try {
|
||||
int speed = Integer.parseInt(args[1]);
|
||||
lift.setSpeed(speed);
|
||||
if (lift.getSpeed() < 1) lift.setSpeed(1);
|
||||
sender.sendMessage(ChatColor.GREEN + "Lift speed changed!");
|
||||
} catch (NumberFormatException e) {
|
||||
sender.sendMessage(ChatColor.RED + "Wrong speed: " + args[1]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean whoisCommand(CommandSender sender, @Nonnull String[] args) {
|
||||
Player p = (Player) sender;
|
||||
if (args.length < 2) {
|
||||
//Without name
|
||||
DataManager.addWhoisREQPlayer(p.getUniqueId());
|
||||
sender.sendMessage(ChatColor.GREEN + "Now right-click on the block you want to check.");
|
||||
} else {
|
||||
String liftName = args[1];
|
||||
if (!DataManager.containsLift(liftName)) {
|
||||
sender.sendMessage(ChatColor.RED + "Lift " + liftName + " not found!");
|
||||
} else {
|
||||
V10LiftPlugin.getAPI().sendLiftInfo(p, liftName);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean whitelistCommand(CommandSender sender, @Nonnull String[] args) {
|
||||
Player p = (Player) sender;
|
||||
if (!DataManager.containsEditPlayer(p.getUniqueId())) {
|
||||
sender.sendMessage(ChatColor.RED + "First switch on the editor mode!");
|
||||
return true;
|
||||
}
|
||||
|
||||
Lift lift = DataManager.getLift(DataManager.getEditPlayer(p.getUniqueId()));
|
||||
OfflinePlayer wp = Bukkit.getOfflinePlayer(args[2]);
|
||||
UUID wpu = wp.getUniqueId();
|
||||
|
||||
String floor = null;
|
||||
if (args.length < 4) {
|
||||
Block b = p.getLocation().getBlock();
|
||||
Floor f = new Floor(b.getY() - 1, Objects.requireNonNull(b.getWorld(), "World was null at doorCommand").getName());
|
||||
if (!lift.getFloors().containsValue(f)) {
|
||||
sender.sendMessage(ChatColor.RED + "Automatic floor detection failed!");
|
||||
return true;
|
||||
}
|
||||
for (Map.Entry<String, Floor> e : lift.getFloors().entrySet()) {
|
||||
Floor fl = e.getValue();
|
||||
if (fl.equals(f)) {
|
||||
floor = e.getKey();
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
floor = args[3];
|
||||
if (!lift.getFloors().containsKey(floor)) {
|
||||
sender.sendMessage(ChatColor.RED + "Floor " + args[3] + " not found!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Floor f = lift.getFloors().get(floor);
|
||||
if (args[1].equalsIgnoreCase("add")) {
|
||||
if (f.getWhitelist().contains(wpu)) {
|
||||
sender.sendMessage(ChatColor.RED + "Whitelist already contains this user!");
|
||||
} else {
|
||||
f.getWhitelist().add(wpu);
|
||||
sender.sendMessage(ChatColor.GREEN + "User added to whitelist!");
|
||||
}
|
||||
} else if (args[1].equalsIgnoreCase("del")) {
|
||||
if (!f.getWhitelist().contains(wpu)) {
|
||||
sender.sendMessage(ChatColor.RED + "Whitelist doesn't contain this user!");
|
||||
} else {
|
||||
f.getWhitelist().remove(wpu);
|
||||
sender.sendMessage(ChatColor.GREEN + "User removed from whitelist!");
|
||||
}
|
||||
} else {
|
||||
return helpCommand(sender);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean doorCommand(CommandSender sender, String[] args) {
|
||||
Player p = (Player) sender;
|
||||
if (!DataManager.containsEditPlayer(p.getUniqueId())) {
|
||||
sender.sendMessage(ChatColor.RED + "First switch on the editor mode!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (DataManager.containsDoorEditPlayer(p.getUniqueId())) {
|
||||
DataManager.removeDoorEditPlayer(p.getUniqueId());
|
||||
sender.sendMessage(ChatColor.RED + "Door editor mode disabled!");
|
||||
return true;
|
||||
}
|
||||
|
||||
Lift lift = DataManager.getLift(DataManager.getEditPlayer(p.getUniqueId()));
|
||||
String floor = null;
|
||||
if (args.length < 2) {
|
||||
Location loc = p.getLocation();
|
||||
Floor f = new Floor(loc.getBlockY() - 1, Objects.requireNonNull(loc.getWorld(), "World was null at doorCommand").getName());
|
||||
if (!lift.getFloors().containsValue(f)) {
|
||||
sender.sendMessage(ChatColor.RED + "Automatic floor detection failed!");
|
||||
return true;
|
||||
}
|
||||
for (Map.Entry<String, Floor> e : lift.getFloors().entrySet()) {
|
||||
Floor fl = e.getValue();
|
||||
if (fl.equals(f)) {
|
||||
floor = e.getKey();
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
floor = args[2];
|
||||
if (!lift.getFloors().containsKey(floor)) {
|
||||
sender.sendMessage(ChatColor.RED + "The floor " + args[2] + " doesn't exists!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
DataManager.addDoorEditPlayer(p.getUniqueId(), floor);
|
||||
sender.sendMessage(ChatColor.GREEN + "Now right-click on the door blocks!");
|
||||
sender.sendMessage(ChatColor.GREEN + "Then do /v10lift door to save it.");
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean ropeCommand(CommandSender sender, String[] args) {
|
||||
Player p = (Player) sender;
|
||||
if (!DataManager.containsEditPlayer(p.getUniqueId())) {
|
||||
sender.sendMessage(ChatColor.RED + "First switch on the editor mode!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[1].equalsIgnoreCase("add")) {
|
||||
if (DataManager.containsRopeEditPlayer(p.getUniqueId()) || DataManager.containsRopeRemovesPlayer(p.getUniqueId())) {
|
||||
sender.sendMessage(ChatColor.RED + "You're still adjusting the emergency stairs.");
|
||||
return true;
|
||||
}
|
||||
DataManager.addRopeEditPlayer(p.getUniqueId(), null);
|
||||
sender.sendMessage(ChatColor.GREEN + "Now right-click on the beginning and the end of the emergency stairs.");
|
||||
} else if (args[1].equalsIgnoreCase("del")) {
|
||||
if (DataManager.containsRopeEditPlayer(p.getUniqueId()) || DataManager.containsRopeRemovesPlayer(p.getUniqueId())) {
|
||||
sender.sendMessage(ChatColor.RED + "You're still adjusting the emergency stairs.");
|
||||
return true;
|
||||
}
|
||||
DataManager.addRopeRemovesPlayer(p.getUniqueId());
|
||||
sender.sendMessage(ChatColor.GREEN + "Now right-click on the the emergency stairs.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean buildCommand(CommandSender sender) {
|
||||
Player p = (Player) sender;
|
||||
if (!DataManager.containsEditPlayer(p.getUniqueId())) {
|
||||
sender.sendMessage(ChatColor.RED + "First switch on the editor mode!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (DataManager.containsBuilderPlayer(p.getUniqueId())) {
|
||||
DataManager.removeBuilderPlayer(p.getUniqueId());
|
||||
V10LiftPlugin.getAPI().sortLiftBlocks(DataManager.getEditPlayer(p.getUniqueId()));
|
||||
sender.sendMessage(ChatColor.GREEN + "Construction mode disabled!");
|
||||
} else {
|
||||
DataManager.addBuilderPlayer(p.getUniqueId());
|
||||
sender.sendMessage(ChatColor.GREEN + "Now right-click on the elevator blocks!");
|
||||
sender.sendMessage(ChatColor.GREEN + "Then do /v10lift build to save it!");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean renameCommand(CommandSender sender, String[] args) {
|
||||
Player p = (Player) sender;
|
||||
if (!DataManager.containsEditPlayer(p.getUniqueId())) {
|
||||
sender.sendMessage(ChatColor.RED + "First switch on the editor mode!");
|
||||
return true;
|
||||
}
|
||||
|
||||
String liftName = DataManager.getEditPlayer(p.getUniqueId());
|
||||
if (!DataManager.containsLift(liftName)) {
|
||||
sender.sendMessage(ChatColor.RED + "That lift doesn't exists.");
|
||||
return true;
|
||||
}
|
||||
|
||||
V10LiftPlugin.getAPI().renameLift(liftName, args[1]);
|
||||
sender.sendMessage(ChatColor.GREEN + "Lift successfully renamed!");
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean offlineCommand(CommandSender sender, String[] args) {
|
||||
Player p = (Player) sender;
|
||||
if (!DataManager.containsEditPlayer(p.getUniqueId())) {
|
||||
sender.sendMessage(ChatColor.RED + "First switch on the editor mode!");
|
||||
return true;
|
||||
}
|
||||
|
||||
String liftName = DataManager.getEditPlayer(p.getUniqueId());
|
||||
if (!DataManager.containsLift(liftName)) {
|
||||
sender.sendMessage(ChatColor.RED + "That lift doesn't exists.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Lift lift = DataManager.getLift(liftName);
|
||||
if (args[1].equalsIgnoreCase("add")) {
|
||||
if (DataManager.containsOfflineEditsPlayer(p.getUniqueId()) || DataManager.containsOfflineRemovesPlayer(p.getUniqueId())) {
|
||||
sender.sendMessage(ChatColor.RED + "You are still adjusting an input!");
|
||||
return true;
|
||||
}
|
||||
|
||||
DataManager.addOfflineEditsPlayer(p.getUniqueId());
|
||||
sender.sendMessage(ChatColor.GREEN + "Now right click on the offline input block!");
|
||||
} else if (args[1].equalsIgnoreCase("del")) {
|
||||
if (lift.getOfflineInputs().isEmpty()) {
|
||||
sender.sendMessage(ChatColor.RED + "There is no input to remove!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (DataManager.containsOfflineEditsPlayer(p.getUniqueId()) || DataManager.containsOfflineRemovesPlayer(p.getUniqueId())) {
|
||||
sender.sendMessage(ChatColor.RED + "You are still adjusting an input!");
|
||||
return true;
|
||||
}
|
||||
|
||||
DataManager.addOfflineRemovesPlayer(p.getUniqueId());
|
||||
sender.sendMessage(ChatColor.GREEN + "Now right click on the offline input block!");
|
||||
} else {
|
||||
return helpCommand(sender);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean inputCommand(CommandSender sender, String[] args) {
|
||||
Player p = (Player) sender;
|
||||
if (!DataManager.containsEditPlayer(p.getUniqueId())) {
|
||||
sender.sendMessage(ChatColor.RED + "First switch on the editor mode!");
|
||||
return true;
|
||||
}
|
||||
|
||||
String liftName = DataManager.getEditPlayer(p.getUniqueId());
|
||||
if (!DataManager.containsLift(liftName)) {
|
||||
sender.sendMessage(ChatColor.RED + "That lift doesn't exists.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Lift lift = DataManager.getLift(liftName);
|
||||
if (args[1].equalsIgnoreCase("add")) {
|
||||
String floor = null;
|
||||
if (args.length < 3) {
|
||||
Block b = p.getLocation().getBlock();
|
||||
Floor f = new Floor(b.getY() - 1, b.getWorld().getName());
|
||||
if (!lift.getFloors().containsValue(f)) {
|
||||
sender.sendMessage(ChatColor.RED + "Automatic floor detection failed!");
|
||||
return true;
|
||||
}
|
||||
|
||||
for (Map.Entry<String, Floor> e : lift.getFloors().entrySet()) {
|
||||
Floor fl = e.getValue();
|
||||
if (fl.equals(f)) {
|
||||
floor = e.getKey();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
floor = args[2];
|
||||
}
|
||||
|
||||
if (DataManager.containsInputEditsPlayer(p.getUniqueId()) || DataManager.containsInputRemovesPlayer(p.getUniqueId())) {
|
||||
sender.sendMessage(ChatColor.RED + "You are still adjusting an input!");
|
||||
return true;
|
||||
}
|
||||
|
||||
DataManager.addInputEditsPlayer(p.getUniqueId(), Objects.requireNonNull(floor, "Floor is null at input add command"));
|
||||
sender.sendMessage(ChatColor.GREEN + "Now right click on the input block!");
|
||||
} else if (args[1].equalsIgnoreCase("del")) {
|
||||
if (lift.getInputs().isEmpty()) {
|
||||
sender.sendMessage(ChatColor.RED + "There is no input to remove!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (DataManager.containsInputEditsPlayer(p.getUniqueId()) || DataManager.containsInputRemovesPlayer(p.getUniqueId())) {
|
||||
sender.sendMessage(ChatColor.RED + "You are still adjusting an input!");
|
||||
return true;
|
||||
}
|
||||
|
||||
DataManager.addInputRemovesPlayer(p.getUniqueId());
|
||||
sender.sendMessage(ChatColor.GREEN + "Now right click on the input block!");
|
||||
} else {
|
||||
return helpCommand(sender);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean floorCommand(CommandSender sender, String[] args) {
|
||||
Player p = (Player) sender;
|
||||
if (!DataManager.containsEditPlayer(p.getUniqueId())) {
|
||||
sender.sendMessage(ChatColor.RED + "First switch on the editor mode!");
|
||||
return true;
|
||||
}
|
||||
|
||||
String liftName = DataManager.getEditPlayer(p.getUniqueId());
|
||||
if (!DataManager.containsLift(liftName)) {
|
||||
sender.sendMessage(ChatColor.RED + "That lift doesn't exists.");
|
||||
return true;
|
||||
}
|
||||
if (args[1].equalsIgnoreCase("add")) {
|
||||
Block b = p.getLocation().getBlock();
|
||||
String floorName = args[2];
|
||||
int response = V10LiftPlugin.getAPI().addFloor(liftName, floorName, new Floor(b.getY() - 1, b.getWorld().getName()));
|
||||
switch (response) {
|
||||
case 0:
|
||||
sender.sendMessage(ChatColor.GREEN + "Floor successfully added!");
|
||||
break;
|
||||
case -2:
|
||||
sender.sendMessage(ChatColor.RED + "That floor is too high!");
|
||||
break;
|
||||
case -3:
|
||||
sender.sendMessage(ChatColor.RED + "That floor already exists!");
|
||||
break;
|
||||
default:
|
||||
sender.sendMessage(ChatColor.RED + "Internal error!");
|
||||
break;
|
||||
}
|
||||
} else if (args[1].equalsIgnoreCase("del")) {
|
||||
String floorName = args[2];
|
||||
if (!V10LiftPlugin.getAPI().removeFloor(liftName, floorName)) {
|
||||
sender.sendMessage(ChatColor.RED + "Internal error!");
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.GREEN + "Floor successfully removed!");
|
||||
}
|
||||
} else if (args[1].equalsIgnoreCase("rename")) {
|
||||
if (args.length < 4) {
|
||||
sender.sendMessage(ChatColor.RED + "Please use: /v10lift floor rename <Old name> <New name>");
|
||||
return true;
|
||||
}
|
||||
|
||||
String floorName = args[2];
|
||||
String newFloorName = args[3];
|
||||
int response = V10LiftPlugin.getAPI().renameFloor(liftName, floorName, newFloorName);
|
||||
switch (response) {
|
||||
case 0:
|
||||
sender.sendMessage(ChatColor.GREEN + "Floor successfully renamed!");
|
||||
break;
|
||||
case -2:
|
||||
sender.sendMessage(ChatColor.RED + "That floor doesn't exists!");
|
||||
break;
|
||||
case -3:
|
||||
sender.sendMessage(ChatColor.RED + "That floor already exists!");
|
||||
break;
|
||||
default:
|
||||
sender.sendMessage(ChatColor.RED + "Internal error!");
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
//args[1] not found!
|
||||
return helpCommand(sender);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean editCommand(@Nonnull CommandSender sender, @Nonnull String[] args) {
|
||||
Player p = (Player) sender;
|
||||
if (DataManager.containsEditPlayer(p.getUniqueId())) {
|
||||
//TURN OFF
|
||||
if (args.length < 2) {
|
||||
String liftName = DataManager.getEditPlayer(p.getUniqueId());
|
||||
if (!DataManager.containsLift(liftName)) {
|
||||
sender.sendMessage(ChatColor.RED + "That lift doesn't exists.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Lift lift = DataManager.getLift(liftName);
|
||||
DataManager.removeEditPlayer(p.getUniqueId());
|
||||
DataManager.removeInputEditsPlayer(p.getUniqueId());
|
||||
DataManager.removeInputRemovesPlayer(p.getUniqueId());
|
||||
DataManager.removeOfflineEditsPlayer(p.getUniqueId());
|
||||
DataManager.removeOfflineRemovesPlayer(p.getUniqueId());
|
||||
if (DataManager.containsBuilderPlayer(p.getUniqueId())) {
|
||||
DataManager.removeBuilderPlayer(p.getUniqueId());
|
||||
V10LiftPlugin.getAPI().sortLiftBlocks(liftName);
|
||||
}
|
||||
DataManager.removeRopeEditPlayer(p.getUniqueId());
|
||||
DataManager.removeRopeRemovesPlayer(p.getUniqueId());
|
||||
DataManager.removeDoorEditPlayer(p.getUniqueId());
|
||||
|
||||
BlockState bs;
|
||||
Sign sign;
|
||||
for (LiftBlock lb : lift.getBlocks()) {
|
||||
bs = Objects.requireNonNull(Bukkit.getWorld(lb.getWorld()), "World is null at edit command").getBlockAt(lb.getX(), lb.getY(), lb.getZ()).getState();
|
||||
if (!(bs instanceof Sign)) continue;
|
||||
sign = (Sign) bs;
|
||||
if (!sign.getLine(0).equalsIgnoreCase(ConfigUtil.getColored("SignText"))) continue;
|
||||
sign.setLine(3, "");
|
||||
sign.update();
|
||||
}
|
||||
|
||||
Iterator<LiftSign> liter = lift.getSigns().iterator();
|
||||
while (liter.hasNext()) {
|
||||
LiftSign ls = liter.next();
|
||||
bs = Objects.requireNonNull(Bukkit.getWorld(ls.getWorld()), "World is null at edit command").getBlockAt(ls.getX(), ls.getY(), ls.getZ()).getState();
|
||||
if (!(bs instanceof Sign)) {
|
||||
Bukkit.getLogger().severe("[V10Lift] Wrong sign removed at: " + LocationSerializer.serialize(bs.getBlock().getLocation()));
|
||||
liter.remove();
|
||||
continue;
|
||||
}
|
||||
sign = (Sign) bs;
|
||||
sign.setLine(3, ls.getOldText());
|
||||
sign.update();
|
||||
ls.setOldText(null);
|
||||
}
|
||||
sender.sendMessage(ChatColor.GREEN + "Editor turned off!");
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "You are still in editor mode.");
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
//TURN ON
|
||||
if (args.length < 2) {
|
||||
sender.sendMessage(ChatColor.RED + "Please use /v10lift edit <Name>");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!DataManager.containsLift(args[1])) {
|
||||
sender.sendMessage(ChatColor.RED + "That lift doesn't exists.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Lift lift = DataManager.getLift(args[1]);
|
||||
if (!lift.getOwners().contains(p.getUniqueId()) && !p.hasPermission("v10lift.admin")) {
|
||||
sender.sendMessage(ChatColor.RED + "You don't have the permission to remove that lift.");
|
||||
}
|
||||
|
||||
DataManager.addEditPlayer(p.getUniqueId(), args[1]);
|
||||
BlockState bs;
|
||||
Sign sign;
|
||||
for (LiftBlock lb : lift.getBlocks()) {
|
||||
bs = Objects.requireNonNull(Bukkit.getWorld(lb.getWorld()), "World is null at edit command").getBlockAt(lb.getX(), lb.getY(), lb.getZ()).getState();
|
||||
if (!(bs instanceof Sign)) continue;
|
||||
sign = (Sign) bs;
|
||||
if (!sign.getLine(0).equalsIgnoreCase(ConfigUtil.getColored("SignText"))) continue;
|
||||
sign.setLine(3, ChatColor.RED + "Maintenance");
|
||||
sign.update();
|
||||
}
|
||||
|
||||
Iterator<LiftSign> liter = lift.getSigns().iterator();
|
||||
while (liter.hasNext()) {
|
||||
LiftSign ls = liter.next();
|
||||
bs = Objects.requireNonNull(Bukkit.getWorld(ls.getWorld()), "World is null at edit command").getBlockAt(ls.getX(), ls.getY(), ls.getZ()).getState();
|
||||
if (!(bs instanceof Sign)) {
|
||||
Bukkit.getLogger().severe("[V10Lift] Wrong sign removed at: " + LocationSerializer.serialize(bs.getBlock().getLocation()));
|
||||
liter.remove();
|
||||
continue;
|
||||
}
|
||||
sign = (Sign) bs;
|
||||
ls.setOldText(sign.getLine(3));
|
||||
sign.setLine(3, ConfigUtil.getColored("MaintenanceText"));
|
||||
sign.update();
|
||||
}
|
||||
sender.sendMessage(ChatColor.GREEN + "Editor turned on!");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean deleteCommand(@Nonnull CommandSender sender, @Nonnull String[] args) {
|
||||
Player p = (Player) sender;
|
||||
if (!DataManager.containsLift(args[1])) {
|
||||
sender.sendMessage(ChatColor.RED + "That lift doesn't exists.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Lift lift = DataManager.getLift(args[1]);
|
||||
if (!lift.getOwners().contains(p.getUniqueId()) && !p.hasPermission("v10lift.admin")) {
|
||||
sender.sendMessage(ChatColor.RED + "You don't have the permission to remove that lift.");
|
||||
}
|
||||
|
||||
if (!V10LiftPlugin.getAPI().removeLift(args[1])) {
|
||||
sender.sendMessage(ChatColor.RED + "The lift " + args[1] + " couldn't be removed!");
|
||||
return true;
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.GREEN + "The lift " + args[1] + " is removed successfully!");
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean createCommand(@Nonnull CommandSender sender, @Nonnull String[] args) {
|
||||
Player p = (Player) sender;
|
||||
if (DataManager.containsPlayer(p.getUniqueId())) {
|
||||
//Already building!!
|
||||
if (args.length < 2) {
|
||||
sender.sendMessage(ChatColor.RED + "Please use /v10lift create <Name>");
|
||||
return true;
|
||||
}
|
||||
|
||||
TreeSet<LiftBlock> blocks = DataManager.getPlayer(p.getUniqueId());
|
||||
if (blocks.isEmpty()) {
|
||||
sender.sendMessage(ChatColor.RED + "Add blocks first!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!V10LiftPlugin.getAPI().createLift(p, args[1])) {
|
||||
sender.sendMessage(ChatColor.RED + "A lift with that name already exists.");
|
||||
}
|
||||
|
||||
TreeSet<LiftBlock> blcks = DataManager.getLift(args[1]).getBlocks();
|
||||
|
||||
blocks.forEach(block -> V10LiftPlugin.getAPI().addBlockToLift(blcks, block));
|
||||
V10LiftPlugin.getAPI().sortLiftBlocks(args[1]);
|
||||
DataManager.removePlayer(p.getUniqueId());
|
||||
sender.sendMessage(ChatColor.GREEN + "The lift " + args[1] + " is created successfully!");
|
||||
p.performCommand("v10lift edit " + args[1]);
|
||||
} else {
|
||||
//Not building yet!!
|
||||
DataManager.addPlayer(p.getUniqueId());
|
||||
sender.sendMessage(ChatColor.GREEN + "Okay, now add all the blocks from the cab by right-clicking on the blocks.");
|
||||
sender.sendMessage(ChatColor.GREEN + "Then type: /v10lift create <Name>");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean infoCommand(@Nonnull CommandSender sender) {
|
||||
sender.sendMessage("§1==================================");
|
||||
sender.sendMessage("§6V10Lift plugin made by §aSBDeveloper");
|
||||
sender.sendMessage("§6Version: " + V10LiftPlugin.getInstance().getDescription().getVersion());
|
||||
sender.sendMessage("§6Type /v10lift help for more information!");
|
||||
sender.sendMessage("§1==================================");
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean helpCommand(@Nonnull CommandSender sender) {
|
||||
sender.sendMessage("§8V10Lift commands:");
|
||||
sender.sendMessage("§6/v10lift info§f: Gives you information about the plugin.");
|
||||
sender.sendMessage("§6/v10lift help§f: Gives you this help page.");
|
||||
sender.sendMessage("§6/v10lift reload§f: Reload the plugin.");
|
||||
|
||||
sender.sendMessage("§6/v10lift create [Name]§f: Create a lift.");
|
||||
sender.sendMessage("§6/v10lift delete <Name>§f: Delete a lift.");
|
||||
sender.sendMessage("§6/v10lift abort§f: Abort your action.");
|
||||
sender.sendMessage("§6/v10lift whois [Name]§f: See information about a lift.");
|
||||
sender.sendMessage("§6/v10lift edit <Name>§f: Edit a lift.");
|
||||
sender.sendMessage("§6/v10lift floor <add/del/rename> <Name> [New name]§f: Add/remove/rename a floor.");
|
||||
sender.sendMessage("§6/v10lift input <add/del> [Floorname]§f: Add/remove a input.");
|
||||
sender.sendMessage("§6/v10lift build§f: Add/remove blocks to/from a cab.");
|
||||
sender.sendMessage("§6/v10lift rope <add/del>§f: Add/remove a rope.");
|
||||
sender.sendMessage("§6/v10lift door§f: Add doors to a lift.");
|
||||
sender.sendMessage("§6/v10lift speed <New speed>§f: Change the speed of a lift.");
|
||||
sender.sendMessage("§6/v10lift realistic§f: Toggle realistic mode.");
|
||||
sender.sendMessage("§6/v10lift repair§f: Repair a lift.");
|
||||
sender.sendMessage("§6/v10lift whitelist <add/del> <Player> [Floorname]§f: Add/remove someone of the whitelist.");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
package nl.SBDeveloper.V10Lift.Listeners;
|
||||
|
||||
import nl.SBDeveloper.V10Lift.API.Objects.Floor;
|
||||
import nl.SBDeveloper.V10Lift.API.Objects.Lift;
|
||||
import nl.SBDeveloper.V10Lift.API.Objects.LiftBlock;
|
||||
import nl.SBDeveloper.V10Lift.API.Objects.LiftSign;
|
||||
import nl.SBDeveloper.V10Lift.Managers.DataManager;
|
||||
import nl.SBDeveloper.V10Lift.V10LiftPlugin;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class BlockBreakListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onBlockBreak(BlockBreakEvent e) {
|
||||
Block b = e.getBlock();
|
||||
if (V10LiftPlugin.getAPI().isRope(b)) {
|
||||
e.getPlayer().sendMessage(ChatColor.RED + "You can't do this! Remove the rope first.");
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
LiftBlock tlb = new LiftBlock(b.getWorld().getName(), b.getX(), b.getY(), b.getZ(), (String) null);
|
||||
for (Map.Entry<String, Lift> entry : DataManager.getLifts().entrySet()) {
|
||||
Lift lift = entry.getValue();
|
||||
if (lift.getBlocks().contains(tlb)) {
|
||||
e.getPlayer().sendMessage(ChatColor.RED + "You can't do this! Remove the lift first.");
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
for (Floor f : lift.getFloors().values()) {
|
||||
if (f.getDoorBlocks().contains(tlb)) {
|
||||
e.getPlayer().sendMessage(ChatColor.RED + "You can't do this! Remove the door first.");
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(b.getState() instanceof Sign)) continue;
|
||||
|
||||
if (!lift.getSigns().contains(tlb)) continue;
|
||||
|
||||
if (!lift.getOwners().contains(e.getPlayer().getUniqueId()) && !e.getPlayer().hasPermission("v10lift.admin")) {
|
||||
e.getPlayer().sendMessage(ChatColor.RED + "You can't do this!");
|
||||
e.setCancelled(true);
|
||||
} else {
|
||||
lift.getSigns().remove(tlb);
|
||||
e.getPlayer().sendMessage(ChatColor.YELLOW + "Lift sign removed!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
package nl.SBDeveloper.V10Lift.Listeners;
|
||||
|
||||
import nl.SBDeveloper.V10Lift.API.Objects.Lift;
|
||||
import nl.SBDeveloper.V10Lift.API.Objects.LiftBlock;
|
||||
import nl.SBDeveloper.V10Lift.Managers.DataManager;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
|
||||
public class EntityDamageListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onEntityDamage(EntityDamageEvent e) {
|
||||
if (e.getCause() != EntityDamageEvent.DamageCause.SUFFOCATION) return;
|
||||
|
||||
Entity entity = e.getEntity();
|
||||
Location loc;
|
||||
if (e instanceof LivingEntity) {
|
||||
loc = ((LivingEntity) entity).getEyeLocation();
|
||||
} else {
|
||||
loc = entity.getLocation();
|
||||
}
|
||||
|
||||
if (loc.getWorld() == null) return;
|
||||
|
||||
String world = loc.getWorld().getName();
|
||||
int x = loc.getBlockX();
|
||||
int y = loc.getBlockY();
|
||||
int z = loc.getBlockZ();
|
||||
|
||||
for (Lift lift : DataManager.getLifts().values()) {
|
||||
for (LiftBlock lb : lift.getBlocks()) {
|
||||
if (world.equals(lb.getWorld()) && x == lb.getX() && y == lb.getY() && z == lb.getZ()) {
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,343 +0,0 @@
|
|||
package nl.SBDeveloper.V10Lift.Listeners;
|
||||
|
||||
import nl.SBDeveloper.V10Lift.API.Objects.Floor;
|
||||
import nl.SBDeveloper.V10Lift.API.Objects.Lift;
|
||||
import nl.SBDeveloper.V10Lift.API.Objects.LiftBlock;
|
||||
import nl.SBDeveloper.V10Lift.Managers.DataManager;
|
||||
import nl.SBDeveloper.V10Lift.Utils.ConfigUtil;
|
||||
import nl.SBDeveloper.V10Lift.Utils.XMaterial;
|
||||
import nl.SBDeveloper.V10Lift.V10LiftPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
public class PlayerInteractListener implements Listener {
|
||||
//BUTTON CLICK
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerInteractButton(PlayerInteractEvent e) {
|
||||
Action action = e.getAction();
|
||||
Block block = e.getClickedBlock();
|
||||
if (block == null) return;
|
||||
Material button = block.getType();
|
||||
|
||||
if (action == Action.RIGHT_CLICK_BLOCK
|
||||
&& e.getHand() != EquipmentSlot.OFF_HAND
|
||||
&& (button.toString().contains("BUTTON") || button == XMaterial.LEVER.parseMaterial())) {
|
||||
String world = block.getWorld().getName();
|
||||
int x = block.getX();
|
||||
int y = block.getY();
|
||||
int z = block.getZ();
|
||||
for (Map.Entry<String, Lift> entry : DataManager.getLifts().entrySet()) {
|
||||
Lift lift = entry.getValue();
|
||||
for (LiftBlock lb : lift.getOfflineInputs()) {
|
||||
if (world.equals(lb.getWorld()) && x == lb.getX() && y == lb.getY() && z == lb.getZ()) {
|
||||
lb.setActive(!lb.isActive());
|
||||
V10LiftPlugin.getAPI().setDefective(entry.getKey(), lb.isActive());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (lift.isOffline()) return;
|
||||
|
||||
for (LiftBlock lb : lift.getInputs()) {
|
||||
if (world.equals(lb.getWorld()) && x == lb.getX() && y == lb.getY() && z == lb.getZ()) {
|
||||
V10LiftPlugin.getAPI().addToQueue(entry.getKey(), lift.getFloors().get(lb.getFloor()), lb.getFloor());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//BLOCK ADD
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerInteract(PlayerInteractEvent e) {
|
||||
if (e.getHand() != EquipmentSlot.OFF_HAND && e.getClickedBlock() != null) {
|
||||
Player p = e.getPlayer();
|
||||
if (DataManager.containsPlayer(p.getUniqueId())) {
|
||||
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||
e.setCancelled(true);
|
||||
int res = V10LiftPlugin.getAPI().switchBlockAtLift(DataManager.getPlayer(p.getUniqueId()), e.getClickedBlock());
|
||||
switch (res) {
|
||||
case 0:
|
||||
p.sendMessage(ChatColor.GREEN + "Block added to the elevator.");
|
||||
break;
|
||||
case 1:
|
||||
p.sendMessage(ChatColor.GOLD + "Block removed from the elevator.");
|
||||
break;
|
||||
case -2:
|
||||
p.sendMessage(ChatColor.RED + "The material " + e.getClickedBlock().getType().toString() + " cannot be used!");
|
||||
break;
|
||||
default:
|
||||
p.sendMessage(ChatColor.RED + "Internal error.");
|
||||
break;
|
||||
}
|
||||
} else if (DataManager.containsInputEditsPlayer(p.getUniqueId())) {
|
||||
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||
Block block = e.getClickedBlock();
|
||||
LiftBlock tlb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), DataManager.getInputEditsPlayer(p.getUniqueId()));
|
||||
Lift lift = DataManager.getLift(DataManager.getEditPlayer(p.getUniqueId()));
|
||||
e.setCancelled(true);
|
||||
if (lift.getInputs().contains(tlb)) {
|
||||
p.sendMessage(ChatColor.RED + "This block has already been chosen as an input. Choose another block!");
|
||||
return;
|
||||
}
|
||||
lift.getInputs().add(tlb);
|
||||
DataManager.removeInputEditsPlayer(p.getUniqueId());
|
||||
p.sendMessage(ChatColor.GREEN + "Input created!");
|
||||
} else if (DataManager.containsOfflineEditsPlayer(p.getUniqueId())) {
|
||||
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||
Block block = e.getClickedBlock();
|
||||
LiftBlock tlb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), (String) null);
|
||||
Lift lift = DataManager.getLift(DataManager.getEditPlayer(p.getUniqueId()));
|
||||
e.setCancelled(true);
|
||||
if (lift.getOfflineInputs().contains(tlb)) {
|
||||
p.sendMessage(ChatColor.RED + "This block has already been chosen as an input. Choose another block!");
|
||||
return;
|
||||
}
|
||||
lift.getOfflineInputs().add(tlb);
|
||||
DataManager.removeOfflineEditsPlayer(p.getUniqueId());
|
||||
p.sendMessage(ChatColor.GREEN + "Offline input created!");
|
||||
} else if (DataManager.containsInputRemovesPlayer(p.getUniqueId())) {
|
||||
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||
Block block = e.getClickedBlock();
|
||||
LiftBlock tlb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), (String) null);
|
||||
Lift lift = DataManager.getLift(DataManager.getEditPlayer(p.getUniqueId()));
|
||||
e.setCancelled(true);
|
||||
if (lift.getInputs().contains(tlb)) {
|
||||
lift.getInputs().remove(tlb);
|
||||
DataManager.removeInputRemovesPlayer(p.getUniqueId());
|
||||
p.sendMessage(ChatColor.GREEN + "Input removed!");
|
||||
return;
|
||||
}
|
||||
p.sendMessage(ChatColor.RED + "This block is not an input. Choose another block!");
|
||||
} else if (DataManager.containsOfflineRemovesPlayer(p.getUniqueId())) {
|
||||
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||
Block block = e.getClickedBlock();
|
||||
LiftBlock tlb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), (String) null);
|
||||
Lift lift = DataManager.getLift(DataManager.getEditPlayer(p.getUniqueId()));
|
||||
e.setCancelled(true);
|
||||
if (lift.getOfflineInputs().contains(tlb)) {
|
||||
lift.getOfflineInputs().remove(tlb);
|
||||
DataManager.removeOfflineRemovesPlayer(p.getUniqueId());
|
||||
p.sendMessage(ChatColor.GREEN + "Offline input removed!");
|
||||
return;
|
||||
}
|
||||
p.sendMessage(ChatColor.RED + "This block is not an offline input. Choose another block!");
|
||||
} else if (DataManager.containsBuilderPlayer(p.getUniqueId())) {
|
||||
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||
e.setCancelled(true);
|
||||
int res = V10LiftPlugin.getAPI().switchBlockAtLift(DataManager.getEditPlayer(p.getUniqueId()), e.getClickedBlock());
|
||||
switch (res) {
|
||||
case 0:
|
||||
p.sendMessage(ChatColor.GREEN + "Block added to the elevator.");
|
||||
break;
|
||||
case 1:
|
||||
p.sendMessage(ChatColor.GOLD + "Block removed from the elevator.");
|
||||
break;
|
||||
case -2:
|
||||
p.sendMessage(ChatColor.RED + "The material " + e.getClickedBlock().getType().toString() + " cannot be used!");
|
||||
break;
|
||||
default:
|
||||
p.sendMessage(ChatColor.RED + "Internal error.");
|
||||
break;
|
||||
}
|
||||
} else if (DataManager.containsRopeEditPlayer(p.getUniqueId())) {
|
||||
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||
e.setCancelled(true);
|
||||
LiftBlock start = DataManager.getRopeEditPlayer(p.getUniqueId());
|
||||
Block now = e.getClickedBlock();
|
||||
if (start == null) {
|
||||
p.sendMessage(ChatColor.GOLD + "Now right-click on the end of the rope!");
|
||||
DataManager.addRopeEditPlayer(p.getUniqueId(), new LiftBlock(now.getWorld().getName(), now.getX(), now.getY(), now.getZ(), (String) null));
|
||||
} else if (start.equals(new LiftBlock(now.getWorld().getName(), now.getX(), now.getY(), now.getZ(), (String) null))) {
|
||||
DataManager.addRopeEditPlayer(p.getUniqueId(), null);
|
||||
p.sendMessage(ChatColor.GOLD + "Start removed!");
|
||||
p.sendMessage(ChatColor.GOLD + "Now right-click on the end of the rope!");
|
||||
} else {
|
||||
if (start.getX() != now.getX() || start.getZ() != now.getZ()) {
|
||||
p.sendMessage(ChatColor.RED + "A rope can only go up!");
|
||||
return;
|
||||
}
|
||||
int res = V10LiftPlugin.getAPI().addRope(DataManager.getEditPlayer(p.getUniqueId()), now.getWorld(), start.getX(), now.getY(), start.getY(), start.getZ());
|
||||
switch (res) {
|
||||
case 0:
|
||||
p.sendMessage(ChatColor.GREEN + "Rope created.");
|
||||
break;
|
||||
case -2:
|
||||
p.sendMessage(ChatColor.RED + "The rope must be of the same material!");
|
||||
break;
|
||||
case -3:
|
||||
p.sendMessage(ChatColor.RED + "Part of the rope is already part of another rope!");
|
||||
break;
|
||||
case -4:
|
||||
p.sendMessage(ChatColor.RED + "The rope is build of blacklisted blocks!");
|
||||
break;
|
||||
default:
|
||||
p.sendMessage(ChatColor.RED + "Internal error.");
|
||||
break;
|
||||
}
|
||||
DataManager.removeRopeEditPlayer(p.getUniqueId());
|
||||
}
|
||||
} else if (DataManager.containsRopeRemovesPlayer(p.getUniqueId())) {
|
||||
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||
e.setCancelled(true);
|
||||
Block block = e.getClickedBlock();
|
||||
if (V10LiftPlugin.getAPI().getFBM().isForbidden(block.getType())) {
|
||||
p.sendMessage(ChatColor.RED + "The material " + e.getClickedBlock().getType().toString() + " is currently not supported!");
|
||||
return;
|
||||
}
|
||||
String liftName = DataManager.getEditPlayer(p.getUniqueId());
|
||||
if (!V10LiftPlugin.getAPI().containsRope(liftName, block)) {
|
||||
p.sendMessage(ChatColor.RED + "This block is not part of the rope.");
|
||||
return;
|
||||
}
|
||||
V10LiftPlugin.getAPI().removeRope(liftName, block);
|
||||
DataManager.removeRopeRemovesPlayer(p.getUniqueId());
|
||||
p.sendMessage(ChatColor.GREEN + "Rope removed.");
|
||||
} else if (DataManager.containsDoorEditPlayer(p.getUniqueId())) {
|
||||
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||
e.setCancelled(true);
|
||||
Block block = e.getClickedBlock();
|
||||
if (V10LiftPlugin.getAPI().getFBM().isForbidden(block.getType())) {
|
||||
p.sendMessage(ChatColor.RED + "The material " + e.getClickedBlock().getType().toString() + " is currently not supported!");
|
||||
return;
|
||||
}
|
||||
LiftBlock lb;
|
||||
if (XMaterial.isNewVersion()) {
|
||||
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), block.getType());
|
||||
} else {
|
||||
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), block.getType(), block.getState().getRawData());
|
||||
}
|
||||
Lift lift = DataManager.getLift(DataManager.getEditPlayer(p.getUniqueId()));
|
||||
Floor floor = lift.getFloors().get(DataManager.getDoorEditPlayer(p.getUniqueId()));
|
||||
if (floor.getDoorBlocks().contains(lb)) {
|
||||
floor.getDoorBlocks().remove(lb);
|
||||
p.sendMessage(ChatColor.GOLD + "Door removed.");
|
||||
return;
|
||||
}
|
||||
floor.getDoorBlocks().add(lb);
|
||||
p.sendMessage(ChatColor.GREEN + "Door created.");
|
||||
} else if (DataManager.containsWhoisREQPlayer(p.getUniqueId())) {
|
||||
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||
e.setCancelled(true);
|
||||
Block block = e.getClickedBlock();
|
||||
LiftBlock lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), (String) null);
|
||||
DataManager.removeWhoisREQPlayer(p.getUniqueId());
|
||||
for (Map.Entry<String, Lift> entry : DataManager.getLifts().entrySet()) {
|
||||
Lift lift = entry.getValue();
|
||||
if (lift.getBlocks().contains(lb) || lift.getInputs().contains(lb) || lift.getSigns().contains(lb) || lift.getRopes().contains(lb) || lift.getOfflineInputs().contains(lb)) {
|
||||
V10LiftPlugin.getAPI().sendLiftInfo(p, entry.getKey(), lift);
|
||||
return;
|
||||
}
|
||||
}
|
||||
p.sendMessage(ChatColor.RED + "This block is not part of a lift.");
|
||||
} else {
|
||||
Action a = e.getAction();
|
||||
if (a != Action.RIGHT_CLICK_BLOCK && a != Action.LEFT_CLICK_BLOCK) return;
|
||||
|
||||
BlockState bs = e.getClickedBlock().getState();
|
||||
if (!(bs instanceof Sign)) return;
|
||||
|
||||
Sign sign = (Sign) bs;
|
||||
if (!sign.getLine(0).equalsIgnoreCase(ConfigUtil.getColored("SignText"))) return;
|
||||
|
||||
String liftName = sign.getLine(1);
|
||||
if (!DataManager.containsLift(liftName)) return;
|
||||
Lift lift = DataManager.getLift(liftName);
|
||||
if (lift.isOffline()) {
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (lift.isDefective()) {
|
||||
if (sign.getLine(3).equals(ConfigUtil.getColored("DefectText")) && p.hasPermission("v10lift.repair") && a == Action.RIGHT_CLICK_BLOCK) {
|
||||
int masterAmount = V10LiftPlugin.getSConfig().getFile().getInt("RepairAmount");
|
||||
Optional<XMaterial> mat = XMaterial.matchXMaterial(Objects.requireNonNull(V10LiftPlugin.getSConfig().getFile().getString("RepairItem"), "RepairItem is null"));
|
||||
if (!mat.isPresent()) {
|
||||
Bukkit.getLogger().severe("[V10Lift] The material for RepairItem is undefined!");
|
||||
return;
|
||||
}
|
||||
Material masterItem = mat.get().parseMaterial();
|
||||
if (masterItem == null) {
|
||||
Bukkit.getLogger().severe("[V10Lift] The material for RepairItem is undefined!");
|
||||
return;
|
||||
}
|
||||
if (p.getGameMode() != GameMode.CREATIVE && masterAmount > 0) {
|
||||
if (!p.getInventory().contains(masterItem)) {
|
||||
p.sendMessage(ChatColor.RED + "You need " + masterAmount + "x " + masterItem.toString().toLowerCase() + "!");
|
||||
return;
|
||||
}
|
||||
p.getInventory().remove(new ItemStack(masterItem, masterAmount));
|
||||
}
|
||||
V10LiftPlugin.getAPI().setDefective(liftName, false);
|
||||
}
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!lift.getBlocks().contains(new LiftBlock(sign.getWorld().getName(), sign.getX(), sign.getY(), sign.getZ(), (String) null))) return;
|
||||
if (DataManager.containsEditLift(liftName)) return;
|
||||
e.setCancelled(true);
|
||||
if (lift.isDefective()) return;
|
||||
String f = ChatColor.stripColor(sign.getLine(3));
|
||||
if (a == Action.RIGHT_CLICK_BLOCK) {
|
||||
Iterator<String> iter = lift.getFloors().keySet().iterator();
|
||||
if (!lift.getFloors().containsKey(f)) {
|
||||
if (!iter.hasNext()) {
|
||||
p.sendMessage(ChatColor.RED + "This elevator has no floors!");
|
||||
return;
|
||||
}
|
||||
f = iter.next();
|
||||
}
|
||||
while (iter.hasNext()) {
|
||||
if (iter.next().equals(f)) break;
|
||||
}
|
||||
if (!iter.hasNext()) iter = lift.getFloors().keySet().iterator();
|
||||
|
||||
String f2 = iter.next();
|
||||
Floor floor = lift.getFloors().get(f2);
|
||||
if (lift.getY() == floor.getY()) {
|
||||
sign.setLine(3, ChatColor.GREEN + f2);
|
||||
} else if (!floor.getWhitelist().isEmpty() && !floor.getWhitelist().contains(p.getUniqueId()) && !p.hasPermission("v10lift.admin")) {
|
||||
sign.setLine(3, ChatColor.RED + f2);
|
||||
} else {
|
||||
sign.setLine(3, ChatColor.YELLOW + f2);
|
||||
}
|
||||
sign.update();
|
||||
} else {
|
||||
if (!lift.getFloors().containsKey(f)) {
|
||||
p.sendMessage(ChatColor.RED + "Floor not found!");
|
||||
return;
|
||||
}
|
||||
|
||||
Floor floor = lift.getFloors().get(f);
|
||||
if (!floor.getWhitelist().isEmpty() && !floor.getWhitelist().contains(p.getUniqueId()) && !p.hasPermission("v10lift.admin")) {
|
||||
p.sendMessage(ChatColor.RED + "You can't go to that floor!");
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
V10LiftPlugin.getAPI().addToQueue(liftName, lift.getFloors().get(f), f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
package nl.SBDeveloper.V10Lift.Listeners;
|
||||
|
||||
import nl.SBDeveloper.V10Lift.API.Objects.Lift;
|
||||
import nl.SBDeveloper.V10Lift.API.Objects.LiftSign;
|
||||
import nl.SBDeveloper.V10Lift.Managers.DataManager;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
|
||||
public class SignChangeListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onSignChange(SignChangeEvent e) {
|
||||
String[] lines = e.getLines();
|
||||
if (!lines[0].equalsIgnoreCase("[v10lift]")) return;
|
||||
|
||||
Player p = e.getPlayer();
|
||||
if (lines[1].isEmpty()) {
|
||||
p.sendMessage(ChatColor.RED + "No lift name given!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!DataManager.containsLift(lines[1])) {
|
||||
p.sendMessage(ChatColor.RED + "Lift " + lines[1] + " doesn't exists!");
|
||||
return;
|
||||
}
|
||||
|
||||
Lift lift = DataManager.getLift(lines[1]);
|
||||
if (!lift.getOwners().contains(p.getUniqueId()) && !p.hasPermission("v10lift.admin")) {
|
||||
p.sendMessage(ChatColor.RED + "You can't do this!");
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
byte type;
|
||||
if (lift.getFloors().containsKey(lines[2])) {
|
||||
type = 1;
|
||||
e.setLine(3, ChatColor.GRAY + lines[2]);
|
||||
} else {
|
||||
type = 0;
|
||||
}
|
||||
e.setLine(2, "");
|
||||
|
||||
Block b = e.getBlock();
|
||||
lift.getSigns().add(new LiftSign(b.getWorld().getName(), b.getX(), b.getY(), b.getZ(), type, (byte) 0));
|
||||
p.sendMessage(ChatColor.GREEN + "Lift sign created!");
|
||||
}
|
||||
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
package nl.SBDeveloper.V10Lift.Managers;
|
||||
|
||||
import nl.SBDeveloper.V10Lift.Utils.XMaterial;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class AntiCopyBlockManager {
|
||||
private ArrayList<XMaterial> antiCopy = new ArrayList<>();
|
||||
|
||||
public AntiCopyBlockManager() {
|
||||
//TODO Add more anti copy materials
|
||||
antiCopy.add(XMaterial.REDSTONE_TORCH);
|
||||
antiCopy.add(XMaterial.REDSTONE_WALL_TORCH);
|
||||
antiCopy.add(XMaterial.REPEATER);
|
||||
antiCopy.add(XMaterial.COMPARATOR);
|
||||
antiCopy.add(XMaterial.REDSTONE_WIRE);
|
||||
antiCopy.add(XMaterial.ACACIA_BUTTON);
|
||||
antiCopy.add(XMaterial.BIRCH_BUTTON);
|
||||
antiCopy.add(XMaterial.DARK_OAK_BUTTON);
|
||||
antiCopy.add(XMaterial.JUNGLE_BUTTON);
|
||||
antiCopy.add(XMaterial.OAK_BUTTON);
|
||||
antiCopy.add(XMaterial.SPRUCE_BUTTON);
|
||||
antiCopy.add(XMaterial.STONE_BUTTON);
|
||||
antiCopy.add(XMaterial.TORCH);
|
||||
antiCopy.add(XMaterial.ACACIA_TRAPDOOR);
|
||||
antiCopy.add(XMaterial.BIRCH_TRAPDOOR);
|
||||
antiCopy.add(XMaterial.DARK_OAK_TRAPDOOR);
|
||||
antiCopy.add(XMaterial.JUNGLE_TRAPDOOR);
|
||||
antiCopy.add(XMaterial.OAK_TRAPDOOR);
|
||||
antiCopy.add(XMaterial.SPRUCE_TRAPDOOR);
|
||||
antiCopy.add(XMaterial.IRON_TRAPDOOR);
|
||||
antiCopy.add(XMaterial.ACACIA_PRESSURE_PLATE);
|
||||
antiCopy.add(XMaterial.BIRCH_PRESSURE_PLATE);
|
||||
antiCopy.add(XMaterial.DARK_OAK_PRESSURE_PLATE);
|
||||
antiCopy.add(XMaterial.JUNGLE_PRESSURE_PLATE);
|
||||
antiCopy.add(XMaterial.OAK_PRESSURE_PLATE);
|
||||
antiCopy.add(XMaterial.SPRUCE_PRESSURE_PLATE);
|
||||
antiCopy.add(XMaterial.STONE_PRESSURE_PLATE);
|
||||
antiCopy.add(XMaterial.HEAVY_WEIGHTED_PRESSURE_PLATE);
|
||||
antiCopy.add(XMaterial.LIGHT_WEIGHTED_PRESSURE_PLATE);
|
||||
antiCopy.add(XMaterial.ACACIA_SIGN);
|
||||
antiCopy.add(XMaterial.BIRCH_SIGN);
|
||||
antiCopy.add(XMaterial.DARK_OAK_SIGN);
|
||||
antiCopy.add(XMaterial.JUNGLE_SIGN);
|
||||
antiCopy.add(XMaterial.OAK_SIGN);
|
||||
antiCopy.add(XMaterial.SPRUCE_SIGN);
|
||||
antiCopy.add(XMaterial.ACACIA_WALL_SIGN);
|
||||
antiCopy.add(XMaterial.BIRCH_WALL_SIGN);
|
||||
antiCopy.add(XMaterial.DARK_OAK_WALL_SIGN);
|
||||
antiCopy.add(XMaterial.JUNGLE_WALL_SIGN);
|
||||
antiCopy.add(XMaterial.OAK_WALL_SIGN);
|
||||
antiCopy.add(XMaterial.SPRUCE_WALL_SIGN);
|
||||
antiCopy.add(XMaterial.RAIL);
|
||||
antiCopy.add(XMaterial.POWERED_RAIL);
|
||||
antiCopy.add(XMaterial.DETECTOR_RAIL);
|
||||
antiCopy.add(XMaterial.ACTIVATOR_RAIL);
|
||||
antiCopy.add(XMaterial.LADDER);
|
||||
}
|
||||
|
||||
public boolean isAntiCopy(Material mat) {
|
||||
XMaterial xmat = XMaterial.matchXMaterial(mat);
|
||||
return antiCopy.contains(xmat);
|
||||
}
|
||||
}
|
|
@ -1,133 +0,0 @@
|
|||
package nl.SBDeveloper.V10Lift.Managers;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
|
||||
import nl.SBDeveloper.V10Lift.API.Objects.Lift;
|
||||
import nl.SBDevelopment.SBUtilities.Data.SQLiteDB;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Map;
|
||||
|
||||
public class DBManager {
|
||||
|
||||
private static SQLiteDB data;
|
||||
private static Connection con;
|
||||
|
||||
public DBManager(String name) {
|
||||
data = new SQLiteDB(name);
|
||||
|
||||
try {
|
||||
con = data.getConnection();
|
||||
|
||||
String query = "CREATE TABLE IF NOT EXISTS lifts (liftName varchar(255) NOT NULL, liftData blob NOT NULL, UNIQUE (liftName))";
|
||||
PreparedStatement statement = con.prepareStatement(query);
|
||||
statement.execute();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void load() throws SQLException, JsonProcessingException {
|
||||
String query = "SELECT * FROM lifts";
|
||||
PreparedStatement statement = con.prepareStatement(query);
|
||||
ResultSet liftSet = statement.executeQuery();
|
||||
while (liftSet.next()) {
|
||||
//Loading a lift...
|
||||
|
||||
/*
|
||||
* @todo Fix migrating from 1.12.2- to 1.13+
|
||||
* - byte to Facing for signs
|
||||
* - Facing opposite for ropes
|
||||
* - New materials
|
||||
*/
|
||||
|
||||
byte[] blob = liftSet.getBytes("liftData");
|
||||
String json = new String(blob);
|
||||
ObjectMapper mapper = new ObjectMapper()
|
||||
.enable(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES)
|
||||
.registerModule(new ParameterNamesModule(JsonCreator.Mode.PROPERTIES));
|
||||
Lift lift = mapper.readValue(json, Lift.class);
|
||||
DataManager.addLift(liftSet.getString("liftName"), lift);
|
||||
|
||||
Bukkit.getLogger().info("[V10Lift] Loading lift " + liftSet.getString("liftName") + " from data...");
|
||||
}
|
||||
}
|
||||
|
||||
public void removeFromData() {
|
||||
try {
|
||||
String query0 = "SELECT * FROM lifts";
|
||||
PreparedStatement statement0 = con.prepareStatement(query0);
|
||||
ResultSet liftSet = statement0.executeQuery();
|
||||
while (liftSet.next()) {
|
||||
if (!DataManager.containsLift(liftSet.getString("liftName"))) {
|
||||
Bukkit.getLogger().info("[V10Lift] Removing lift " + liftSet.getString("liftName") + " to data...");
|
||||
|
||||
String query = "DELETE FROM lifts WHERE liftName = ?";
|
||||
PreparedStatement statement = con.prepareStatement(query);
|
||||
statement.setString(1, liftSet.getString("liftName"));
|
||||
statement.executeUpdate();
|
||||
}
|
||||
}
|
||||
} catch(SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void removeFromData(String name) {
|
||||
try {
|
||||
if (!DataManager.containsLift(name)) {
|
||||
Bukkit.getLogger().info("[V10Lift] Removing lift " + name + " to data...");
|
||||
|
||||
String query = "DELETE FROM lifts WHERE liftName = ?";
|
||||
PreparedStatement statement = con.prepareStatement(query);
|
||||
statement.setString(1, name);
|
||||
statement.executeUpdate();
|
||||
}
|
||||
} catch(SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void save() throws JsonProcessingException {
|
||||
for (Map.Entry<String, Lift> entry : DataManager.getLifts().entrySet()) {
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper()
|
||||
.enable(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES)
|
||||
.registerModule(new ParameterNamesModule(JsonCreator.Mode.PROPERTIES));
|
||||
|
||||
byte[] blob = mapper.writeValueAsString(entry.getValue()).getBytes();
|
||||
|
||||
Bukkit.getLogger().info("[V10Lift] Saving lift " + entry.getKey() + " to data...");
|
||||
|
||||
try {
|
||||
String query = "INSERT INTO lifts (liftName, liftData) VALUES (?, ?)";
|
||||
PreparedStatement statement = con.prepareStatement(query);
|
||||
statement.setString(1, entry.getKey());
|
||||
statement.setBytes(2, blob);
|
||||
statement.executeUpdate();
|
||||
} catch (SQLException ignored) {}
|
||||
|
||||
try {
|
||||
String query2 = "UPDATE lifts SET liftData = ? WHERE liftName = ?";
|
||||
PreparedStatement statement2 = con.prepareStatement(query2);
|
||||
statement2.setBytes(1, blob);
|
||||
statement2.setString(2, entry.getKey());
|
||||
statement2.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void closeConnection() {
|
||||
data.closeSource();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,234 +0,0 @@
|
|||
package nl.SBDeveloper.V10Lift.Managers;
|
||||
|
||||
import nl.SBDeveloper.V10Lift.API.Objects.Lift;
|
||||
import nl.SBDeveloper.V10Lift.API.Objects.LiftBlock;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class DataManager {
|
||||
/* A manager for general HashMaps */
|
||||
private static LinkedHashMap<String, Lift> lifts = new LinkedHashMap<>();
|
||||
private static LinkedHashMap<UUID, TreeSet<LiftBlock>> builds = new LinkedHashMap<>();
|
||||
private static LinkedHashMap<UUID, String> editors = new LinkedHashMap<>();
|
||||
private static LinkedHashMap<UUID, String> inputEdits = new LinkedHashMap<>();
|
||||
private static ArrayList<UUID> inputRemoves = new ArrayList<>();
|
||||
private static ArrayList<UUID> offlineEdits = new ArrayList<>();
|
||||
private static ArrayList<UUID> offlineRemoves = new ArrayList<>();
|
||||
private static ArrayList<UUID> builder = new ArrayList<>();
|
||||
private static LinkedHashMap<UUID, LiftBlock> ropeEdits = new LinkedHashMap<>();
|
||||
private static ArrayList<UUID> ropeRemoves = new ArrayList<>();
|
||||
private static HashMap<UUID, String> doorEdits = new HashMap<>();
|
||||
private static ArrayList<UUID> whoisReq = new ArrayList<>();
|
||||
private static HashMap<String, Integer> movingTasks = new HashMap<>();
|
||||
|
||||
/* HashMap methods */
|
||||
|
||||
// //
|
||||
public static void addLift(String liftName, Lift lift) {
|
||||
lifts.put(liftName, lift);
|
||||
}
|
||||
|
||||
public static void removeLift(String liftName) {
|
||||
lifts.remove(liftName);
|
||||
}
|
||||
|
||||
public static boolean containsLift(String liftName) {
|
||||
return lifts.containsKey(liftName);
|
||||
}
|
||||
|
||||
public static Lift getLift(String liftName) {
|
||||
return lifts.get(liftName);
|
||||
}
|
||||
|
||||
public static LinkedHashMap<String, Lift> getLifts() { return lifts; }
|
||||
|
||||
// //
|
||||
public static boolean containsPlayer(UUID player) {
|
||||
return builds.containsKey(player);
|
||||
}
|
||||
|
||||
public static void addPlayer(UUID player) {
|
||||
builds.put(player, new TreeSet<>());
|
||||
}
|
||||
|
||||
public static void removePlayer(UUID player) {
|
||||
builds.remove(player);
|
||||
}
|
||||
|
||||
public static TreeSet<LiftBlock> getPlayer(UUID player) {
|
||||
return builds.get(player);
|
||||
}
|
||||
|
||||
// //
|
||||
public static boolean containsInputEditsPlayer(UUID player) {
|
||||
return inputEdits.containsKey(player);
|
||||
}
|
||||
|
||||
public static void addInputEditsPlayer(UUID player, String liftName) {
|
||||
inputEdits.put(player, liftName);
|
||||
}
|
||||
|
||||
public static void removeInputEditsPlayer(UUID player) {
|
||||
inputEdits.remove(player);
|
||||
}
|
||||
|
||||
public static String getInputEditsPlayer(UUID player) {
|
||||
return inputEdits.get(player);
|
||||
}
|
||||
|
||||
// //
|
||||
public static boolean containsRopeEditPlayer(UUID player) {
|
||||
return ropeEdits.containsKey(player);
|
||||
}
|
||||
|
||||
public static void addRopeEditPlayer(UUID player, LiftBlock liftBlock) {
|
||||
ropeEdits.put(player, liftBlock);
|
||||
}
|
||||
|
||||
public static void removeRopeEditPlayer(UUID player) {
|
||||
ropeEdits.remove(player);
|
||||
}
|
||||
|
||||
public static LiftBlock getRopeEditPlayer(UUID player) {
|
||||
return ropeEdits.get(player);
|
||||
}
|
||||
|
||||
// //
|
||||
public static boolean containsEditPlayer(UUID player) {
|
||||
return editors.containsKey(player);
|
||||
}
|
||||
|
||||
public static boolean containsEditLift(String liftName) {
|
||||
return editors.containsValue(liftName);
|
||||
}
|
||||
|
||||
public static void addEditPlayer(UUID player, String liftName) {
|
||||
editors.put(player, liftName);
|
||||
}
|
||||
|
||||
public static void removeEditPlayer(UUID player) {
|
||||
editors.remove(player);
|
||||
}
|
||||
|
||||
public static String getEditPlayer(UUID player) {
|
||||
return editors.get(player);
|
||||
}
|
||||
|
||||
public static LinkedHashMap<UUID, String> getEditors() { return editors; }
|
||||
|
||||
// //
|
||||
public static void addMovingTask(String liftName, int taskid) {
|
||||
movingTasks.put(liftName, taskid);
|
||||
}
|
||||
|
||||
public static void removeMovingTask(String liftName) {
|
||||
movingTasks.remove(liftName);
|
||||
}
|
||||
|
||||
public static boolean containsMovingTask(String liftName) {
|
||||
return movingTasks.containsKey(liftName);
|
||||
}
|
||||
|
||||
public static int getMovingTask(String liftName) {
|
||||
return movingTasks.get(liftName);
|
||||
}
|
||||
|
||||
public static void clearMovingTasks() { movingTasks.clear(); }
|
||||
|
||||
// //
|
||||
public static boolean containsDoorEditPlayer(UUID player) {
|
||||
return doorEdits.containsKey(player);
|
||||
}
|
||||
|
||||
public static void addDoorEditPlayer(UUID player, String floorName) {
|
||||
doorEdits.put(player, floorName);
|
||||
}
|
||||
|
||||
public static void removeDoorEditPlayer(UUID player) {
|
||||
doorEdits.remove(player);
|
||||
}
|
||||
|
||||
public static String getDoorEditPlayer(UUID player) {
|
||||
return doorEdits.get(player);
|
||||
}
|
||||
|
||||
/* ArrayList methods */
|
||||
|
||||
// //
|
||||
public static boolean containsOfflineEditsPlayer(UUID player) {
|
||||
return offlineEdits.contains(player);
|
||||
}
|
||||
|
||||
public static void addOfflineEditsPlayer(UUID player) {
|
||||
offlineEdits.add(player);
|
||||
}
|
||||
|
||||
public static void removeOfflineEditsPlayer(UUID player) {
|
||||
offlineEdits.remove(player);
|
||||
}
|
||||
|
||||
// //
|
||||
public static boolean containsOfflineRemovesPlayer(UUID player) {
|
||||
return offlineRemoves.contains(player);
|
||||
}
|
||||
|
||||
public static void addOfflineRemovesPlayer(UUID player) {
|
||||
offlineRemoves.add(player);
|
||||
}
|
||||
|
||||
public static void removeOfflineRemovesPlayer(UUID player) {
|
||||
offlineRemoves.remove(player);
|
||||
}
|
||||
|
||||
// //
|
||||
public static boolean containsBuilderPlayer(UUID player) {
|
||||
return builder.contains(player);
|
||||
}
|
||||
|
||||
public static void addBuilderPlayer(UUID player) {
|
||||
builder.add(player);
|
||||
}
|
||||
|
||||
public static void removeBuilderPlayer(UUID player) {
|
||||
builder.remove(player);
|
||||
}
|
||||
|
||||
// //
|
||||
public static boolean containsRopeRemovesPlayer(UUID player) {
|
||||
return ropeRemoves.contains(player);
|
||||
}
|
||||
|
||||
public static void addRopeRemovesPlayer(UUID player) {
|
||||
ropeRemoves.add(player);
|
||||
}
|
||||
|
||||
public static void removeRopeRemovesPlayer(UUID player) {
|
||||
ropeRemoves.remove(player);
|
||||
}
|
||||
|
||||
// //
|
||||
public static boolean containsInputRemovesPlayer(UUID player) {
|
||||
return inputRemoves.contains(player);
|
||||
}
|
||||
|
||||
public static void addInputRemovesPlayer(UUID player) {
|
||||
inputRemoves.add(player);
|
||||
}
|
||||
|
||||
public static void removeInputRemovesPlayer(UUID player) {
|
||||
inputRemoves.remove(player);
|
||||
}
|
||||
|
||||
// //
|
||||
public static boolean containsWhoisREQPlayer(UUID player) {
|
||||
return whoisReq.contains(player);
|
||||
}
|
||||
|
||||
public static void addWhoisREQPlayer(UUID player) {
|
||||
whoisReq.add(player);
|
||||
}
|
||||
|
||||
public static void removeWhoisREQPlayer(UUID player) {
|
||||
whoisReq.remove(player);
|
||||
}
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
package nl.SBDeveloper.V10Lift.Managers;
|
||||
|
||||
import nl.SBDeveloper.V10Lift.Utils.XMaterial;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ForbiddenBlockManager {
|
||||
private ArrayList<XMaterial> forbidden = new ArrayList<>();
|
||||
|
||||
public ForbiddenBlockManager() {
|
||||
//TODO Add more forbidden materials
|
||||
forbidden.add(XMaterial.ACACIA_DOOR);
|
||||
forbidden.add(XMaterial.BIRCH_DOOR);
|
||||
forbidden.add(XMaterial.DARK_OAK_DOOR);
|
||||
forbidden.add(XMaterial.IRON_DOOR);
|
||||
forbidden.add(XMaterial.JUNGLE_DOOR);
|
||||
forbidden.add(XMaterial.OAK_DOOR);
|
||||
forbidden.add(XMaterial.SPRUCE_DOOR);
|
||||
forbidden.add(XMaterial.BLACK_BED);
|
||||
forbidden.add(XMaterial.BLUE_BED);
|
||||
forbidden.add(XMaterial.BROWN_BED);
|
||||
forbidden.add(XMaterial.CYAN_BED);
|
||||
forbidden.add(XMaterial.GRAY_BED);
|
||||
forbidden.add(XMaterial.GREEN_BED);
|
||||
forbidden.add(XMaterial.LIGHT_BLUE_BED);
|
||||
forbidden.add(XMaterial.LIGHT_GRAY_BED);
|
||||
forbidden.add(XMaterial.LIME_BED);
|
||||
forbidden.add(XMaterial.MAGENTA_BED);
|
||||
forbidden.add(XMaterial.ORANGE_BED);
|
||||
forbidden.add(XMaterial.PINK_BED);
|
||||
forbidden.add(XMaterial.PURPLE_BED);
|
||||
forbidden.add(XMaterial.RED_BED);
|
||||
forbidden.add(XMaterial.WHITE_BED);
|
||||
forbidden.add(XMaterial.YELLOW_BED);
|
||||
forbidden.add(XMaterial.ACACIA_SAPLING);
|
||||
forbidden.add(XMaterial.BAMBOO_SAPLING);
|
||||
forbidden.add(XMaterial.BIRCH_SAPLING);
|
||||
forbidden.add(XMaterial.DARK_OAK_SAPLING);
|
||||
forbidden.add(XMaterial.JUNGLE_SAPLING);
|
||||
forbidden.add(XMaterial.OAK_SAPLING);
|
||||
forbidden.add(XMaterial.SPRUCE_SAPLING);
|
||||
forbidden.add(XMaterial.TNT);
|
||||
forbidden.add(XMaterial.PISTON);
|
||||
forbidden.add(XMaterial.PISTON_HEAD);
|
||||
forbidden.add(XMaterial.MOVING_PISTON);
|
||||
forbidden.add(XMaterial.STICKY_PISTON);
|
||||
}
|
||||
|
||||
public boolean isForbidden(Material mat) {
|
||||
XMaterial xmat = XMaterial.matchXMaterial(mat);
|
||||
return forbidden.contains(xmat);
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package nl.SBDeveloper.V10Lift.Utils;
|
||||
|
||||
import nl.SBDeveloper.V10Lift.V10LiftPlugin;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ConfigUtil {
|
||||
@Nonnull
|
||||
public static String getColored(@Nonnull String path) {
|
||||
return ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(V10LiftPlugin.getSConfig().getFile().getString(path), "Message " + path + " not found!"));
|
||||
}
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
package nl.SBDeveloper.V10Lift.Utils;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.data.Bisected;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Directional;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class DirectionUtil {
|
||||
|
||||
@Nullable
|
||||
public static BlockFace getDirection(@Nonnull Block block) {
|
||||
if (block.getBlockData() instanceof Directional) {
|
||||
Directional dir = (Directional) block.getBlockData();
|
||||
return dir.getFacing();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void setDirection(@Nonnull Block block, BlockFace blockFace) {
|
||||
if (blockFace != null && block.getBlockData() instanceof Directional) {
|
||||
BlockData bd = block.getBlockData();
|
||||
Directional dir = (Directional) bd;
|
||||
dir.setFacing(blockFace);
|
||||
block.setBlockData(bd);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getBisected(@Nonnull Block block) {
|
||||
if (block.getBlockData() instanceof Bisected) {
|
||||
Bisected bis = (Bisected) block.getBlockData();
|
||||
return bis.getHalf().toString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void setBisected(@Nonnull Block block, String bisected) {
|
||||
if (bisected != null && block.getBlockData() instanceof Bisected) {
|
||||
|
||||
Bisected.Half half;
|
||||
try {
|
||||
half = Bisected.Half.valueOf(bisected);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return;
|
||||
}
|
||||
|
||||
BlockData bd = block.getBlockData();
|
||||
Bisected bis = (Bisected) bd;
|
||||
bis.setHalf(half);
|
||||
block.setBlockData(bd);
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -1,95 +0,0 @@
|
|||
package nl.SBDeveloper.V10Lift;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import nl.SBDeveloper.V10Lift.API.V10LiftAPI;
|
||||
import nl.SBDeveloper.V10Lift.Commands.V10LiftCommand;
|
||||
import nl.SBDeveloper.V10Lift.Listeners.BlockBreakListener;
|
||||
import nl.SBDeveloper.V10Lift.Listeners.EntityDamageListener;
|
||||
import nl.SBDeveloper.V10Lift.Listeners.PlayerInteractListener;
|
||||
import nl.SBDeveloper.V10Lift.Listeners.SignChangeListener;
|
||||
import nl.SBDeveloper.V10Lift.Managers.DBManager;
|
||||
import nl.SBDevelopment.SBUtilities.Data.YamlFile;
|
||||
import nl.SBDevelopment.SBUtilities.PrivateManagers.UpdateManager;
|
||||
import nl.SBDevelopment.SBUtilities.SBUtilities;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Objects;
|
||||
|
||||
public class V10LiftPlugin extends JavaPlugin {
|
||||
|
||||
private static V10LiftPlugin instance;
|
||||
private static YamlFile config;
|
||||
private static DBManager dbManager;
|
||||
private static V10LiftAPI api;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
|
||||
//Initialize the util
|
||||
new SBUtilities(this, "V10Lift");
|
||||
|
||||
config = new YamlFile("config");
|
||||
config.loadDefaults();
|
||||
|
||||
dbManager = new DBManager("data");
|
||||
try {
|
||||
dbManager.load();
|
||||
} catch (SQLException | JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
api = new V10LiftAPI();
|
||||
|
||||
Objects.requireNonNull(getCommand("v10lift"), "Internal error! Command not found.").setExecutor(new V10LiftCommand());
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(new PlayerInteractListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new BlockBreakListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new SignChangeListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new EntityDamageListener(), this);
|
||||
|
||||
new UpdateManager(this, 72317, UpdateManager.CheckType.SPIGOT).handleResponse((versionResponse, version) -> {
|
||||
if (versionResponse == UpdateManager.VersionResponse.FOUND_NEW) {
|
||||
Bukkit.getLogger().warning("[V10Lift] There is a new version available! Current: " + this.getDescription().getVersion() + " New: " + version);
|
||||
} else if (versionResponse == UpdateManager.VersionResponse.LATEST) {
|
||||
Bukkit.getLogger().info("[V10Lift] You are running the latest version [" + this.getDescription().getVersion() + "]!");
|
||||
} else if (versionResponse == UpdateManager.VersionResponse.UNAVAILABLE) {
|
||||
Bukkit.getLogger().severe("[V10Lift] Unable to perform an update check.");
|
||||
}
|
||||
}).check();
|
||||
|
||||
Bukkit.getLogger().info("[V10Lift] Plugin loaded successfully!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
V10LiftPlugin.getDBManager().removeFromData();
|
||||
try {
|
||||
dbManager.save();
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
dbManager.closeConnection();
|
||||
|
||||
instance = null;
|
||||
}
|
||||
|
||||
public static V10LiftPlugin getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static YamlFile getSConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public static DBManager getDBManager() {
|
||||
return dbManager;
|
||||
}
|
||||
|
||||
public static V10LiftAPI getAPI() {
|
||||
return api;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue