Started with the recode :)
This commit is contained in:
commit
5c8b10faa1
18 changed files with 3299 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
*.iml
|
||||||
|
.idea
|
89
pom.xml
Normal file
89
pom.xml
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>nl.SBDeveloper</groupId>
|
||||||
|
<artifactId>V10Lift2</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<name>V10Lift</name>
|
||||||
|
<version>0.5</version>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<directory>target</directory>
|
||||||
|
<finalName>V10Lift2</finalName>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<targetPath>.</targetPath>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<includes>
|
||||||
|
<include>plugin.yml</include>
|
||||||
|
</includes>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.2.1</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>shade</id>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>spigot-repo</id>
|
||||||
|
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spigotmc</groupId>
|
||||||
|
<artifactId>spigot-api</artifactId>
|
||||||
|
<version>1.15.2-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.code.findbugs</groupId>
|
||||||
|
<artifactId>jsr305</artifactId>
|
||||||
|
<version>3.0.2</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.zaxxer</groupId>
|
||||||
|
<artifactId>HikariCP</artifactId>
|
||||||
|
<version>3.4.2</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-simple</artifactId>
|
||||||
|
<version>1.7.28</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.18.10</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
|
</project>
|
22
src/main/java/nl/SBDeveloper/V10Lift/API/Objects/Floor.java
Normal file
22
src/main/java/nl/SBDeveloper/V10Lift/API/Objects/Floor.java
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
package nl.SBDeveloper.V10Lift.API.Objects;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Getter @Setter
|
||||||
|
public class Floor {
|
||||||
|
private String world;
|
||||||
|
private int y;
|
||||||
|
private ArrayList<LiftBlock> doorBlocks;
|
||||||
|
private ArrayList<UUID> whitelist;
|
||||||
|
|
||||||
|
public Floor(String world, int y) {
|
||||||
|
this.world = world;
|
||||||
|
this.y = y;
|
||||||
|
this.doorBlocks = new ArrayList<>();
|
||||||
|
this.whitelist = new ArrayList<>();
|
||||||
|
}
|
||||||
|
}
|
50
src/main/java/nl/SBDeveloper/V10Lift/API/Objects/Lift.java
Normal file
50
src/main/java/nl/SBDeveloper/V10Lift/API/Objects/Lift.java
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
package nl.SBDeveloper.V10Lift.API.Objects;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class Lift {
|
||||||
|
@Getter @Setter private String worldName;
|
||||||
|
@Getter @Setter private int y;
|
||||||
|
@Getter private ArrayList<UUID> owners;
|
||||||
|
@Getter private ArrayList<String> whitelist;
|
||||||
|
@Getter private ArrayList<LiftBlock> blocks;
|
||||||
|
@Getter private LinkedHashMap<String, Floor> floors;
|
||||||
|
@Getter private ArrayList<LiftSign> signs;
|
||||||
|
@Getter private ArrayList<LiftBlock> inputs;
|
||||||
|
@Getter private ArrayList<LiftBlock> offlineInputs;
|
||||||
|
@Getter private LinkedHashMap<String, Floor> queue;
|
||||||
|
@Getter private ArrayList<LiftRope> ropes;
|
||||||
|
@Getter @Setter private int speed;
|
||||||
|
@Getter @Setter private boolean realistic;
|
||||||
|
@Getter @Setter private boolean offline;
|
||||||
|
@Getter @Setter private boolean sound;
|
||||||
|
@Getter @Setter private boolean defective;
|
||||||
|
@Getter @Setter private String signText;
|
||||||
|
|
||||||
|
public Lift(ArrayList<UUID> owners, int speed, boolean realistic) {
|
||||||
|
this.owners = owners;
|
||||||
|
this.speed = speed;
|
||||||
|
this.realistic = realistic;
|
||||||
|
this.blocks = new ArrayList<>();
|
||||||
|
this.signs = new ArrayList<>();
|
||||||
|
this.whitelist = new ArrayList<>();
|
||||||
|
this.floors = new LinkedHashMap<>();
|
||||||
|
this.inputs = new ArrayList<>();
|
||||||
|
this.offlineInputs = new ArrayList<>();
|
||||||
|
this.queue = new LinkedHashMap<>();
|
||||||
|
this.ropes = new ArrayList<>();
|
||||||
|
this.offline = false;
|
||||||
|
this.sound = true;
|
||||||
|
this.defective = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Lift(UUID owner, int speed, boolean realistic) {
|
||||||
|
new Lift(new ArrayList<>(Collections.singletonList(owner)), speed, realistic);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,72 @@
|
||||||
|
package nl.SBDeveloper.V10Lift.API.Objects;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
|
||||||
|
@Getter @Setter
|
||||||
|
public class LiftBlock implements Comparable<LiftBlock> {
|
||||||
|
|
||||||
|
private String world;
|
||||||
|
private int x;
|
||||||
|
private int y;
|
||||||
|
private int z;
|
||||||
|
|
||||||
|
//Only used for cabine blocks, because those need caching!
|
||||||
|
private Material mat;
|
||||||
|
private String[] signLines;
|
||||||
|
|
||||||
|
//Only used for inputs!
|
||||||
|
private String floor;
|
||||||
|
private boolean active = false;
|
||||||
|
|
||||||
|
//Only used for chests
|
||||||
|
private LinkedHashMap<Integer, ItemStack> chestContent = new LinkedHashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add lift block with material
|
||||||
|
*
|
||||||
|
* @param world Worldname
|
||||||
|
* @param x x-pos
|
||||||
|
* @param y y-pos
|
||||||
|
* @param z z-pos
|
||||||
|
* @param mat the material
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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.floor = floor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LiftBlock(String world, int x, int y, int z, Material mat, String[] signLines) {
|
||||||
|
this.world = world;
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.z = z;
|
||||||
|
this.mat = mat;
|
||||||
|
this.signLines = signLines;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package nl.SBDeveloper.V10Lift.API.Objects;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter @Setter
|
||||||
|
public class LiftRope {
|
||||||
|
private String world;
|
||||||
|
private int x;
|
||||||
|
private int z;
|
||||||
|
private int minY;
|
||||||
|
private int maxY;
|
||||||
|
|
||||||
|
public LiftRope(String world, int x, int minY, int maxY, int z) {
|
||||||
|
this.world = world;
|
||||||
|
this.x = x;
|
||||||
|
this.minY = minY;
|
||||||
|
this.maxY = maxY;
|
||||||
|
this.z = z;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package nl.SBDeveloper.V10Lift.API.Objects;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
|
||||||
|
@Getter @Setter
|
||||||
|
public class LiftSign {
|
||||||
|
private LiftBlock block;
|
||||||
|
private String oldText;
|
||||||
|
|
||||||
|
public LiftSign(Location loc) {
|
||||||
|
block = new LiftBlock(loc);
|
||||||
|
}
|
||||||
|
}
|
449
src/main/java/nl/SBDeveloper/V10Lift/API/V10LiftAPI.java
Normal file
449
src/main/java/nl/SBDeveloper/V10Lift/API/V10LiftAPI.java
Normal file
|
@ -0,0 +1,449 @@
|
||||||
|
package nl.SBDeveloper.V10Lift.API;
|
||||||
|
|
||||||
|
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.Managers.ForbiddenBlockManager;
|
||||||
|
import nl.SBDeveloper.V10Lift.Utils.LocationSerializer;
|
||||||
|
import nl.SBDeveloper.V10Lift.Utils.XMaterial;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockState;
|
||||||
|
import org.bukkit.block.Sign;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.xml.crypto.Data;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class V10LiftAPI {
|
||||||
|
/* Load managers... */
|
||||||
|
private static ForbiddenBlockManager fbm;
|
||||||
|
|
||||||
|
public V10LiftAPI() {
|
||||||
|
fbm = new ForbiddenBlockManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ForbiddenBlockManager getFBM() {
|
||||||
|
return fbm;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Private API methods */
|
||||||
|
private void sortFloors(@Nonnull Lift lift) {
|
||||||
|
ArrayList<Map.Entry<String, Floor>> as = new ArrayList<>(lift.getFloors().entrySet());
|
||||||
|
as.sort(Comparator.comparingInt(o -> o.getValue().getY()));
|
||||||
|
Iterator<Map.Entry<String, Floor>> iter = as.iterator();
|
||||||
|
lift.getFloors().clear();
|
||||||
|
Map.Entry<String, Floor> e;
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
e = iter.next();
|
||||||
|
lift.getFloors().put(e.getKey(), e.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* API methods */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new Lift
|
||||||
|
*
|
||||||
|
* @param p The player [owner] of the lift
|
||||||
|
* @param liftName The name of the lift
|
||||||
|
* @return true if created, false if null or already exists
|
||||||
|
*/
|
||||||
|
public boolean createLift(Player p, String liftName) {
|
||||||
|
if (p == null || liftName == null || DataManager.containsLift(liftName)) return false;
|
||||||
|
|
||||||
|
//TODO Add defaults to config
|
||||||
|
DataManager.addLift(liftName, new Lift(p.getUniqueId(), 16, true));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a lift
|
||||||
|
*
|
||||||
|
* @param liftName The name of the lift
|
||||||
|
* @return true if removed, false if null or doesn't exists
|
||||||
|
*/
|
||||||
|
public boolean removeLift(String liftName) {
|
||||||
|
if (liftName == null || !DataManager.containsLift(liftName)) return false;
|
||||||
|
|
||||||
|
//TODO Remove lift from all data maps
|
||||||
|
|
||||||
|
//TODO Stop movingtask if running
|
||||||
|
|
||||||
|
DataManager.removeLift(liftName);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a block to a lift
|
||||||
|
* Use {@link nl.SBDeveloper.V10Lift.API.V10LiftAPI#sortLiftBlocks(String liftName)} after!
|
||||||
|
*
|
||||||
|
* @param liftName The name of the lift
|
||||||
|
* @param block The block
|
||||||
|
* @return 0 if added, -1 if null or doesn't exists, -2 if forbidden, -3 if already added
|
||||||
|
*/
|
||||||
|
public int addBlockToLift(String liftName, Block block) {
|
||||||
|
if (liftName == null || block == null || !DataManager.containsLift(liftName)) return -1;
|
||||||
|
Lift lift = DataManager.getLift(liftName);
|
||||||
|
Material type = block.getType();
|
||||||
|
if (getFBM().isForbidden(type)) return -2;
|
||||||
|
LiftBlock lb;
|
||||||
|
if (type.toString().contains("SIGN")) {
|
||||||
|
//SIGN
|
||||||
|
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, ((Sign) block.getState()).getLines());
|
||||||
|
} else {
|
||||||
|
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type);
|
||||||
|
}
|
||||||
|
if (lift.getBlocks().contains(lb)) return -3;
|
||||||
|
lift.getBlocks().add(lb);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a block from a lift
|
||||||
|
* Use {@link nl.SBDeveloper.V10Lift.API.V10LiftAPI#sortLiftBlocks(String liftName)} after!
|
||||||
|
*
|
||||||
|
* @param liftName The name of the lift
|
||||||
|
* @param block The block
|
||||||
|
* @return 0 if removed, -1 if null or doesn't exists, -2 if not added
|
||||||
|
*/
|
||||||
|
public int removeBlockFromLift(String liftName, Block block) {
|
||||||
|
if (liftName == null || block == null || !DataManager.containsLift(liftName)) return -1;
|
||||||
|
Lift lift = DataManager.getLift(liftName);
|
||||||
|
Material type = block.getType();
|
||||||
|
LiftBlock lb;
|
||||||
|
if (type.toString().contains("SIGN")) {
|
||||||
|
//SIGN
|
||||||
|
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, ((Sign) block.getState()).getLines());
|
||||||
|
} else {
|
||||||
|
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type);
|
||||||
|
}
|
||||||
|
if (!lift.getBlocks().contains(lb)) return -2;
|
||||||
|
lift.getBlocks().remove(lb);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Switch a block at a lift
|
||||||
|
* Use {@link nl.SBDeveloper.V10Lift.API.V10LiftAPI#sortLiftBlocks(String liftName)} after!
|
||||||
|
*
|
||||||
|
* @param liftName The name of the lift
|
||||||
|
* @param block The block
|
||||||
|
* @return 0 if added, 1 if removed, -1 if null or doesn't exists, -2 if forbidden
|
||||||
|
*/
|
||||||
|
public int switchBlockAtLift(String liftName, Block block) {
|
||||||
|
if (liftName == null || block == null || !DataManager.containsLift(liftName)) return -1;
|
||||||
|
Lift lift = DataManager.getLift(liftName);
|
||||||
|
Material type = block.getType();
|
||||||
|
if (getFBM().isForbidden(type)) return -2;
|
||||||
|
LiftBlock lb;
|
||||||
|
if (type.toString().contains("SIGN")) {
|
||||||
|
//SIGN
|
||||||
|
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, ((Sign) block.getState()).getLines());
|
||||||
|
} else {
|
||||||
|
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type);
|
||||||
|
}
|
||||||
|
if (lift.getBlocks().contains(lb)) {
|
||||||
|
lift.getBlocks().remove(lb);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
lift.getBlocks().add(lb);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sort the blocks of a lift.
|
||||||
|
* Use this after they have been modified.
|
||||||
|
*
|
||||||
|
* @param liftName The name of the lift
|
||||||
|
*/
|
||||||
|
public void sortLiftBlocks(String liftName) {
|
||||||
|
if (liftName != null && DataManager.containsLift(liftName)) {
|
||||||
|
Lift lift = DataManager.getLift(liftName);
|
||||||
|
if (lift.getWorldName() == null) lift.setWorldName(lift.getBlocks().get(0).getWorld());
|
||||||
|
World world = Bukkit.getWorld(lift.getWorldName());
|
||||||
|
if (world == null) return;
|
||||||
|
lift.setY(world.getMaxHeight());
|
||||||
|
for (LiftBlock lb : lift.getBlocks()) {
|
||||||
|
if (lb.getY() < lift.getY()) {
|
||||||
|
lift.setY(lb.getY());
|
||||||
|
lift.setWorldName(lb.getWorld());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a new floor to a lift
|
||||||
|
*
|
||||||
|
* @param liftName The name of the lift
|
||||||
|
* @param floorName The name of the floor
|
||||||
|
* @param floor The floor object
|
||||||
|
* @return 0 if added, -1 if null or doesn't exists, -2 if height is to high, -3 if floor already exists
|
||||||
|
*/
|
||||||
|
public int addFloor(String liftName, String floorName, Floor floor) {
|
||||||
|
if (liftName == null || floorName == null || floor == null || !DataManager.containsLift(liftName) || floor.getWorld() == null) return -1;
|
||||||
|
if (floor.getY() > Objects.requireNonNull(Bukkit.getServer().getWorld(floor.getWorld()), "World is null at addNewFloor!").getMaxHeight()) return -2;
|
||||||
|
if (floorName.length() > 13) floorName = floorName.substring(0, 13).trim();
|
||||||
|
Lift lift = DataManager.getLift(liftName);
|
||||||
|
if (lift.getFloors().containsKey(floorName) || lift.getFloors().containsValue(floor)) return -3;
|
||||||
|
|
||||||
|
lift.getFloors().put(floorName, floor);
|
||||||
|
sortFloors(lift);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a floor from a lift
|
||||||
|
*
|
||||||
|
* @param liftName The name of the lift
|
||||||
|
* @param floorName The name of the floor
|
||||||
|
* @return true if removed, false if null or doesn't exists
|
||||||
|
*/
|
||||||
|
public boolean removeFloor(String liftName, String floorName) {
|
||||||
|
if (liftName == null || floorName == null || !DataManager.containsLift(liftName)) return false;
|
||||||
|
Lift lift = DataManager.getLift(liftName);
|
||||||
|
if (!lift.getFloors().containsKey(floorName)) return false;
|
||||||
|
|
||||||
|
lift.getFloors().remove(floorName);
|
||||||
|
lift.getInputs().removeIf(liftBlock -> liftBlock.getFloor().equals(floorName));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rename a floor from a lift
|
||||||
|
*
|
||||||
|
* @param liftName The name of the lift
|
||||||
|
* @param oldName The old name of the floor
|
||||||
|
* @param newName The new name of the floor
|
||||||
|
* @return 0 if renamed, -1 if null or doesn't exists, -2 if floor doesn't exists, -3 if floor already exists
|
||||||
|
*/
|
||||||
|
public int renameFloor(String liftName, String oldName, String newName) {
|
||||||
|
if (liftName == null || oldName == null || newName == null || !DataManager.containsLift(liftName)) return -1;
|
||||||
|
Lift lift = DataManager.getLift(liftName);
|
||||||
|
if (!lift.getFloors().containsKey(oldName)) return -2;
|
||||||
|
if (newName.length() > 13) newName = newName.substring(0, 13).trim();
|
||||||
|
if (lift.getFloors().containsKey(newName)) return -3;
|
||||||
|
|
||||||
|
Floor f = lift.getFloors().get(oldName);
|
||||||
|
lift.getFloors().remove(oldName);
|
||||||
|
lift.getFloors().put(newName, f);
|
||||||
|
sortFloors(lift);
|
||||||
|
Iterator<LiftBlock> liter = lift.getInputs().iterator();
|
||||||
|
LiftBlock lb;
|
||||||
|
ArrayList<LiftBlock> newBlocks = new ArrayList<>();
|
||||||
|
while (liter.hasNext()) {
|
||||||
|
lb = liter.next();
|
||||||
|
if (lb.getFloor().equals(oldName)) {
|
||||||
|
liter.remove();
|
||||||
|
newBlocks.add(new LiftBlock(lb.getWorld(), lb.getX(), lb.getY(), lb.getZ(), newName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
newBlocks.forEach(nlb -> lift.getInputs().add(nlb));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a lift is defective
|
||||||
|
*
|
||||||
|
* @param liftName The name of the lift
|
||||||
|
* @return true/false
|
||||||
|
*/
|
||||||
|
public boolean isDefective(String liftName) {
|
||||||
|
if (liftName == null || !DataManager.containsLift(liftName)) return false;
|
||||||
|
return DataManager.getLift(liftName).isDefective();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a lift to (not) defective
|
||||||
|
*
|
||||||
|
* @param liftName The name of the lift
|
||||||
|
* @param state true/false
|
||||||
|
* @return 0 if set, -1 if null or doesn't exists, -2 if same state, -3 if no signs, -4 if wrong sign
|
||||||
|
*/
|
||||||
|
public int setDefective(String liftName, boolean state) {
|
||||||
|
if (liftName == null || !DataManager.containsLift(liftName)) return -1;
|
||||||
|
Lift lift = DataManager.getLift(liftName);
|
||||||
|
boolean oldState = lift.isDefective();
|
||||||
|
if (oldState == state) return -2;
|
||||||
|
lift.setDefective(state);
|
||||||
|
Iterator<LiftSign> liter = lift.getSigns().iterator();
|
||||||
|
if (state) {
|
||||||
|
//SET DEFECTIVE
|
||||||
|
int max = lift.getSigns().size();
|
||||||
|
if (max == 0) return -3;
|
||||||
|
LiftSign ls;
|
||||||
|
if (max == 1) {
|
||||||
|
//If one sign, update that one.
|
||||||
|
ls = liter.next();
|
||||||
|
} else {
|
||||||
|
//If multiple signs, get random one.
|
||||||
|
int r = new Random().nextInt(max);
|
||||||
|
for (int i = 0; i < r; i++) {
|
||||||
|
liter.next();
|
||||||
|
}
|
||||||
|
ls = liter.next();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Update sign
|
||||||
|
Block block = Objects.requireNonNull(Bukkit.getWorld(ls.getBlock().getWorld()), "World is null at setDefective").getBlockAt(ls.getBlock().getX(), ls.getBlock().getY(), ls.getBlock().getZ());
|
||||||
|
BlockState bs = block.getState();
|
||||||
|
if (!(bs instanceof Sign)) {
|
||||||
|
Bukkit.getLogger().severe("[V10Lift] Wrong sign removed at: " + LocationSerializer.serialize(block.getLocation()));
|
||||||
|
liter.remove();
|
||||||
|
return -4;
|
||||||
|
}
|
||||||
|
|
||||||
|
Sign s = (Sign) bs;
|
||||||
|
ls.setOldText(s.getLine(3));
|
||||||
|
//TODO Add defaults to config
|
||||||
|
s.setLine(3, ChatColor.MAGIC + "Defect!");
|
||||||
|
s.update();
|
||||||
|
|
||||||
|
//Update all other signs
|
||||||
|
for (LiftBlock lb : lift.getBlocks()) {
|
||||||
|
bs = Objects.requireNonNull(Bukkit.getWorld(lb.getWorld()), "World is null at setDefective").getBlockAt(lb.getX(), lb.getY(), lb.getZ()).getState();
|
||||||
|
if (!(bs instanceof Sign)) continue;
|
||||||
|
|
||||||
|
s = (Sign) bs;
|
||||||
|
lift.setSignText(s.getLine(3));
|
||||||
|
s.setLine(3, ChatColor.MAGIC + "Defect!");
|
||||||
|
s.update();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
LiftSign ls;
|
||||||
|
BlockState bs;
|
||||||
|
Sign s;
|
||||||
|
while (liter.hasNext()) {
|
||||||
|
ls = liter.next();
|
||||||
|
bs = Objects.requireNonNull(Bukkit.getWorld(ls.getBlock().getWorld()), "World is null at setDefective").getBlockAt(ls.getBlock().getX(), ls.getBlock().getY(), ls.getBlock().getZ()).getState();
|
||||||
|
if (!(bs instanceof Sign)) {
|
||||||
|
Bukkit.getLogger().severe("[V10Lift] Wrong sign removed at: " + LocationSerializer.serialize(bs.getBlock().getLocation()));
|
||||||
|
liter.remove();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
s = (Sign) bs;
|
||||||
|
if (s.getLine(3).equals(ChatColor.MAGIC + "Defect!")) {
|
||||||
|
s.setLine(3, ls.getOldText());
|
||||||
|
s.update();
|
||||||
|
ls.setOldText(null);
|
||||||
|
for (LiftBlock lb : lift.getBlocks()) {
|
||||||
|
bs = Objects.requireNonNull(Bukkit.getWorld(lb.getWorld()), "World is null at setDefective").getBlockAt(lb.getX(), lb.getY(), lb.getZ()).getState();
|
||||||
|
if (!(bs instanceof Sign)) continue;
|
||||||
|
|
||||||
|
s = (Sign) bs;
|
||||||
|
s.setLine(3, lift.getSignText());
|
||||||
|
s.update();
|
||||||
|
lift.setSignText(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the whitelist of a lift
|
||||||
|
*
|
||||||
|
* @param liftName The name of the lift
|
||||||
|
* @param floorName The name of the floor
|
||||||
|
* @return list with UUIDs of the players
|
||||||
|
*/
|
||||||
|
public ArrayList<UUID> getWhitelist(String liftName, String floorName) {
|
||||||
|
ArrayList<UUID> ret = new ArrayList<>();
|
||||||
|
if (liftName != null && floorName != null && DataManager.containsLift(liftName)) {
|
||||||
|
Lift lift = DataManager.getLift(liftName);
|
||||||
|
if (lift.getFloors().containsKey(floorName)) {
|
||||||
|
ret = lift.getFloors().get(floorName).getWhitelist();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a lift is offline
|
||||||
|
*
|
||||||
|
* @param liftName The name of the lift
|
||||||
|
* @return true/false
|
||||||
|
*/
|
||||||
|
public boolean isOffline(String liftName) {
|
||||||
|
if (liftName == null || !DataManager.containsLift(liftName)) return false;
|
||||||
|
return DataManager.getLift(liftName).isOffline();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a lift to (not) offline
|
||||||
|
*
|
||||||
|
* @param liftName The name of the lift
|
||||||
|
* @param state true/false
|
||||||
|
* @return 0 if set, -1 if null or doesn't exists, -2 if same state
|
||||||
|
*/
|
||||||
|
public int setOffline(String liftName, boolean state) {
|
||||||
|
if (liftName == null || !DataManager.containsLift(liftName)) return -1;
|
||||||
|
Lift lift = DataManager.getLift(liftName);
|
||||||
|
boolean oldState = lift.isOffline();
|
||||||
|
if (oldState == state) return -2;
|
||||||
|
lift.setOffline(state);
|
||||||
|
Iterator<LiftSign> liter = lift.getSigns().iterator();
|
||||||
|
BlockState bs;
|
||||||
|
Sign sign;
|
||||||
|
if (state) {
|
||||||
|
for (LiftBlock lb : lift.getBlocks()) {
|
||||||
|
bs = Objects.requireNonNull(Bukkit.getWorld(lb.getWorld()), "World is null at setOffline").getBlockAt(lb.getX(), lb.getY(), lb.getZ()).getState();
|
||||||
|
if (!(bs instanceof Sign)) continue;
|
||||||
|
sign = (Sign) bs;
|
||||||
|
//TODO Add defaults
|
||||||
|
if (!sign.getLine(0).equalsIgnoreCase("[v10lift]")) continue;
|
||||||
|
sign.setLine(3, ChatColor.RED + "Disabled");
|
||||||
|
sign.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
while (liter.hasNext()) {
|
||||||
|
LiftSign ls = liter.next();
|
||||||
|
bs = Objects.requireNonNull(Bukkit.getWorld(ls.getBlock().getWorld()), "World is null at setOffline").getBlockAt(ls.getBlock().getX(), ls.getBlock().getY(), ls.getBlock().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));
|
||||||
|
//TODO Add defaults
|
||||||
|
sign.setLine(3, ChatColor.RED + "Disabled");
|
||||||
|
sign.update();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (LiftBlock lb : lift.getBlocks()) {
|
||||||
|
bs = Objects.requireNonNull(Bukkit.getWorld(lb.getWorld()), "World is null at setOffline").getBlockAt(lb.getX(), lb.getY(), lb.getZ()).getState();
|
||||||
|
if (!(bs instanceof Sign)) continue;
|
||||||
|
sign = (Sign) bs;
|
||||||
|
//TODO Add defaults
|
||||||
|
if (!sign.getLine(0).equalsIgnoreCase("[v10lift]")) continue;
|
||||||
|
sign.setLine(3, "");
|
||||||
|
sign.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
while (liter.hasNext()) {
|
||||||
|
LiftSign ls = liter.next();
|
||||||
|
bs = Objects.requireNonNull(Bukkit.getWorld(ls.getBlock().getWorld()), "World is null at setOffline").getBlockAt(ls.getBlock().getX(), ls.getBlock().getY(), ls.getBlock().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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,123 @@
|
||||||
|
package nl.SBDeveloper.V10Lift.Commands;
|
||||||
|
|
||||||
|
import nl.SBDeveloper.V10Lift.API.Objects.Lift;
|
||||||
|
import nl.SBDeveloper.V10Lift.Managers.DataManager;
|
||||||
|
import nl.SBDeveloper.V10Lift.V10LiftPlugin;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
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.");
|
||||||
|
}
|
||||||
|
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.");
|
||||||
|
}
|
||||||
|
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!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean deleteCommand(@Nonnull CommandSender sender, @Nonnull String[] args) {
|
||||||
|
Player p = (Player) sender;
|
||||||
|
if (args.length < 2) {
|
||||||
|
sender.sendMessage(ChatColor.RED + "Please use /v10lift delete <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.");
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO Fix ignoring of result
|
||||||
|
V10LiftPlugin.getAPI().removeLift(args[1]);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayList<Block> 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.");
|
||||||
|
}
|
||||||
|
|
||||||
|
blocks.forEach(block -> V10LiftPlugin.getAPI().addBlockToLift(args[1], 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.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
package nl.SBDeveloper.V10Lift.Managers;
|
||||||
|
|
||||||
|
import nl.SBDeveloper.V10Lift.API.Objects.Lift;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class DataManager {
|
||||||
|
/* A manager for general HashMaps */
|
||||||
|
private static LinkedHashMap<String, Lift> lifts = new LinkedHashMap<>();
|
||||||
|
private static LinkedHashMap<UUID, ArrayList<Block>> builds = new LinkedHashMap<>();
|
||||||
|
|
||||||
|
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 ArrayList<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removePlayer(UUID player) {
|
||||||
|
builds.remove(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ArrayList<Block> getPlayer(UUID player) {
|
||||||
|
return builds.get(player);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package nl.SBDeveloper.V10Lift.Utils;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
public class LocationSerializer {
|
||||||
|
|
||||||
|
//Hieronder de methodes zonder yaw & pitch!
|
||||||
|
@Nonnull
|
||||||
|
public static Location deserialize(@Nonnull String string) {
|
||||||
|
String[] split = string.split("_");
|
||||||
|
|
||||||
|
//world_x_y_z
|
||||||
|
return new Location(
|
||||||
|
Bukkit.getWorld(split[0]),
|
||||||
|
Double.parseDouble(split[1]),
|
||||||
|
Double.parseDouble(split[2]),
|
||||||
|
Double.parseDouble(split[3])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static String serialize(@Nonnull Location loc) {
|
||||||
|
if (loc.getWorld() == null) return null;
|
||||||
|
return loc.getWorld().getName() + "_" + loc.getX() + "_" + loc.getY() + "_" + loc.getZ();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
164
src/main/java/nl/SBDeveloper/V10Lift/Utils/SBSQLiteDB.java
Normal file
164
src/main/java/nl/SBDeveloper/V10Lift/Utils/SBSQLiteDB.java
Normal file
|
@ -0,0 +1,164 @@
|
||||||
|
package nl.SBDeveloper.V10Lift.Utils;
|
||||||
|
|
||||||
|
import com.zaxxer.hikari.HikariConfig;
|
||||||
|
import com.zaxxer.hikari.HikariDataSource;
|
||||||
|
import com.zaxxer.hikari.util.DriverDataSource;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class SBSQLiteDB {
|
||||||
|
|
||||||
|
private HikariDataSource source;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize a new connection
|
||||||
|
*
|
||||||
|
* @param plugin The plugin (Main class)
|
||||||
|
* @param name The database name
|
||||||
|
*/
|
||||||
|
public SBSQLiteDB(@Nonnull Plugin plugin, String name) {
|
||||||
|
Bukkit.getLogger().info("[SBDBManager] Loading databases...");
|
||||||
|
|
||||||
|
File dbFile = new File(plugin.getDataFolder(), name + ".db");
|
||||||
|
|
||||||
|
if (!dbFile.exists()) {
|
||||||
|
try {
|
||||||
|
Bukkit.getLogger().info("[SBDBManager] Generating the " + name + ".db!");
|
||||||
|
dbFile.createNewFile();
|
||||||
|
} catch (IOException e) {
|
||||||
|
Bukkit.getLogger().severe("[SBDBManager] Couldn't generate the " + name + ".db!");
|
||||||
|
e.printStackTrace();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DataSource dataSource = new DriverDataSource("jdbc:sqlite:" + dbFile.getAbsolutePath(), "org.sqlite.JDBC", new Properties(), null, null);
|
||||||
|
HikariConfig config = new HikariConfig();
|
||||||
|
config.setPoolName("SQLiteConnectionPool");
|
||||||
|
config.setDataSource(dataSource);
|
||||||
|
|
||||||
|
this.source = new HikariDataSource(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute queries like CREATE TABLE, ALTER TABLE, ....
|
||||||
|
*
|
||||||
|
* @param query The query you want to execute
|
||||||
|
*
|
||||||
|
* @return true/false
|
||||||
|
*/
|
||||||
|
public boolean execute(String query) {
|
||||||
|
Connection con = null;
|
||||||
|
PreparedStatement statement = null;
|
||||||
|
boolean b;
|
||||||
|
|
||||||
|
try {
|
||||||
|
con = this.source.getConnection();
|
||||||
|
statement = con.prepareStatement(query);
|
||||||
|
b = statement.execute();
|
||||||
|
return b;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
Bukkit.getLogger().severe("[SBDBManager] SQL exception! Please check the stacktrace below.");
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (statement != null) statement.close();
|
||||||
|
if (con != null) con.close();
|
||||||
|
} catch(SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute queries like INSERT, UPDATE, DELETE, ...
|
||||||
|
*
|
||||||
|
* @param query The query you want to execute
|
||||||
|
* @param objects The objects you want to insert, in the right order
|
||||||
|
*
|
||||||
|
* @return true/false
|
||||||
|
*/
|
||||||
|
public boolean execute(String query, LinkedHashMap<Integer, Object> objects) {
|
||||||
|
Connection con = null;
|
||||||
|
PreparedStatement statement = null;
|
||||||
|
int b;
|
||||||
|
try {
|
||||||
|
con = this.source.getConnection();
|
||||||
|
statement = con.prepareStatement(query);
|
||||||
|
if (objects != null) {
|
||||||
|
for (Map.Entry<Integer, Object> entry : objects.entrySet()) {
|
||||||
|
statement.setObject(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
b = statement.executeUpdate();
|
||||||
|
if (b >= 0) return true;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
Bukkit.getLogger().severe("[SBDBManager] SQL exception! Please check the stacktrace below.");
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (statement != null) statement.close();
|
||||||
|
if (con != null) con.close();
|
||||||
|
} catch(SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute a SELECT query
|
||||||
|
*
|
||||||
|
* @param query The query you want to execute
|
||||||
|
* @param objects The objects you want to insert, in the right order
|
||||||
|
* @param requests The objects you want to select from the database
|
||||||
|
*
|
||||||
|
* @return HashMap<Object, Object> where the first object is the rowname and the second object is the value
|
||||||
|
*/
|
||||||
|
public ResultSet execute(String query, HashMap<Integer, Object> objects, ArrayList<Object> requests) {
|
||||||
|
Connection con = null;
|
||||||
|
PreparedStatement statement = null;
|
||||||
|
ResultSet set = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
con = this.source.getConnection();
|
||||||
|
statement = con.prepareStatement(query);
|
||||||
|
if (objects != null) {
|
||||||
|
for (Map.Entry<Integer, Object> entry : objects.entrySet()) {
|
||||||
|
statement.setObject(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
set = statement.executeQuery();
|
||||||
|
return set;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
Bukkit.getLogger().severe("[SBDBManager] SQL exception! Please check the stacktrace below.");
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (set != null) set.close();
|
||||||
|
if (statement != null) statement.close();
|
||||||
|
if (con != null) con.close();
|
||||||
|
} catch(SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void closeSource() {
|
||||||
|
Bukkit.getLogger().info("[SBDBManager] Closing the database connection!");
|
||||||
|
this.source.close();
|
||||||
|
}
|
||||||
|
}
|
67
src/main/java/nl/SBDeveloper/V10Lift/Utils/SBYamlFile.java
Normal file
67
src/main/java/nl/SBDeveloper/V10Lift/Utils/SBYamlFile.java
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
package nl.SBDeveloper.V10Lift.Utils;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.Reader;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
public class SBYamlFile {
|
||||||
|
//SBYamlFile file = new SBYamlFile(this, "data");
|
||||||
|
|
||||||
|
private FileConfiguration fileConfiguration;
|
||||||
|
private File file;
|
||||||
|
private String name;
|
||||||
|
private Plugin pl;
|
||||||
|
|
||||||
|
public SBYamlFile(@Nonnull Plugin pl, String name) {
|
||||||
|
this.pl = pl;
|
||||||
|
this.name = name;
|
||||||
|
|
||||||
|
if (!pl.getDataFolder().exists()) {
|
||||||
|
pl.getDataFolder().mkdir();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.file = new File(pl.getDataFolder(), name + ".yml");
|
||||||
|
if (!this.file.exists()) {
|
||||||
|
try {
|
||||||
|
this.file.createNewFile();
|
||||||
|
Bukkit.getLogger().info("[SBYamlManager] Generating the " + name + ".yml!");
|
||||||
|
} catch (IOException e) {
|
||||||
|
Bukkit.getLogger().severe("[SBYamlManager] Couldn't generate the " + name + ".yml!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.fileConfiguration = YamlConfiguration.loadConfiguration(this.file);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadDefaults() {
|
||||||
|
Bukkit.getLogger().info("[SBYamlManager] Copying default " + name + ".yml to the folder!");
|
||||||
|
Reader defConfigStream1 = new InputStreamReader(this.pl.getResource(name + ".yml"), StandardCharsets.UTF_8);
|
||||||
|
YamlConfiguration defConfig1 = YamlConfiguration.loadConfiguration(defConfigStream1);
|
||||||
|
getFile().setDefaults(defConfig1);
|
||||||
|
getFile().options().copyDefaults(true);
|
||||||
|
saveFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
public FileConfiguration getFile() {
|
||||||
|
return this.fileConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveFile() {
|
||||||
|
try {
|
||||||
|
this.fileConfiguration.save(this.file);
|
||||||
|
} catch (IOException e) {
|
||||||
|
Bukkit.getLogger().severe("[SBYamlManager] Couldn't save the " + name + ".yml!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reloadConfig() {
|
||||||
|
this.fileConfiguration = YamlConfiguration.loadConfiguration(this.file);
|
||||||
|
}
|
||||||
|
}
|
2031
src/main/java/nl/SBDeveloper/V10Lift/Utils/XMaterial.java
Normal file
2031
src/main/java/nl/SBDeveloper/V10Lift/Utils/XMaterial.java
Normal file
File diff suppressed because it is too large
Load diff
52
src/main/java/nl/SBDeveloper/V10Lift/V10LiftPlugin.java
Normal file
52
src/main/java/nl/SBDeveloper/V10Lift/V10LiftPlugin.java
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
package nl.SBDeveloper.V10Lift;
|
||||||
|
|
||||||
|
import nl.SBDeveloper.V10Lift.API.V10LiftAPI;
|
||||||
|
import nl.SBDeveloper.V10Lift.Commands.V10LiftCommand;
|
||||||
|
import nl.SBDeveloper.V10Lift.Utils.SBSQLiteDB;
|
||||||
|
import nl.SBDeveloper.V10Lift.Utils.SBYamlFile;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class V10LiftPlugin extends JavaPlugin {
|
||||||
|
|
||||||
|
private static V10LiftPlugin instance;
|
||||||
|
private static SBYamlFile config;
|
||||||
|
private static SBSQLiteDB data;
|
||||||
|
private static V10LiftAPI api;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
instance = this;
|
||||||
|
|
||||||
|
config = new SBYamlFile(this, "config");
|
||||||
|
config.loadDefaults();
|
||||||
|
data = new SBSQLiteDB(this, "data");
|
||||||
|
|
||||||
|
api = new V10LiftAPI();
|
||||||
|
|
||||||
|
getCommand("v10lift").setExecutor(new V10LiftCommand());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
instance = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static V10LiftPlugin getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SBYamlFile getSConfig() {
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SBSQLiteDB getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static V10LiftAPI getAPI() {
|
||||||
|
return api;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
0
src/main/resources/config.yml
Normal file
0
src/main/resources/config.yml
Normal file
7
src/main/resources/plugin.yml
Normal file
7
src/main/resources/plugin.yml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
name: V10Lift
|
||||||
|
main: nl.SBDeveloper.V10Lift.V10LiftPlugin
|
||||||
|
version: "0.5"
|
||||||
|
api-version: "1.13"
|
||||||
|
commands:
|
||||||
|
v10lift:
|
||||||
|
description: The V10Lift Command
|
Loading…
Reference in a new issue