Added some things, and added the edit command

This commit is contained in:
stijnb1234 2020-01-30 14:19:13 +01:00
parent d9679539de
commit 9e2a758dee
5 changed files with 287 additions and 23 deletions

View file

@ -1,22 +1,16 @@
package nl.SBDeveloper.V10Lift.API.Objects;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import java.util.ArrayList;
import java.util.UUID;
@Getter @Setter
@Getter @Setter @AllArgsConstructor
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<>();
}
}

View file

@ -1,21 +1,14 @@
package nl.SBDeveloper.V10Lift.API.Objects;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
@Getter @Setter
@Getter @Setter @AllArgsConstructor
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;
}
}

View file

@ -7,7 +7,6 @@ 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;
@ -18,7 +17,6 @@ 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 {

View file

@ -1,10 +1,16 @@
package nl.SBDeveloper.V10Lift.Commands;
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.LocationSerializer;
import nl.SBDeveloper.V10Lift.V10LiftPlugin;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
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;
@ -12,6 +18,8 @@ import org.bukkit.entity.Player;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Objects;
public class V10LiftCommand implements CommandExecutor {
@ -43,10 +51,127 @@ public class V10LiftCommand implements CommandExecutor {
} 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.");
}
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!");
}
}
return false;
}
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.removeDoorEditsPlayer(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;
//TODO Add defaults
if (!sign.getLine(0).equalsIgnoreCase("[v10lift]")) 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;
//TODO Add defaults
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;
//TODO Add defaults
if (!sign.getLine(0).equalsIgnoreCase("[v10lift]")) 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));
//TODO Add defaults
sign.setLine(3, ChatColor.RED + "Maintenance");
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 (args.length < 2) {

View file

@ -11,7 +11,20 @@ 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<>();
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, String> ropeEdits = new LinkedHashMap<>();
private static ArrayList<UUID> ropeRemoves = new ArrayList<>();
private static ArrayList<UUID> doorEdits = new ArrayList<>();
private static ArrayList<UUID> whoisReq = new ArrayList<>();
/* HashMap methods */
// //
public static void addLift(String liftName, Lift lift) {
lifts.put(liftName, lift);
}
@ -28,10 +41,7 @@ public class DataManager {
return lifts.get(liftName);
}
public static LinkedHashMap<String, Lift> getLifts() {
return lifts;
}
// //
public static boolean containsPlayer(UUID player) {
return builds.containsKey(player);
}
@ -47,4 +57,148 @@ public class DataManager {
public static ArrayList<Block> 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, String liftName) {
ropeEdits.put(player, liftName);
}
public static void removeRopeEditPlayer(UUID player) {
ropeEdits.remove(player);
}
public static String getRopeEditPlayer(UUID player) {
return ropeEdits.get(player);
}
// //
public static boolean containsEditPlayer(UUID player) {
return editors.containsKey(player);
}
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);
}
/* 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 containsDoorEditsPlayer(UUID player) {
return doorEdits.contains(player);
}
public static void addDoorEditsPlayer(UUID player) {
doorEdits.add(player);
}
public static void removeDoorEditsPlayer(UUID player) {
doorEdits.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);
}
}