From 14238f621caf942919eb165ea3c19986fc7b74de Mon Sep 17 00:00:00 2001 From: Yaruma3341 Date: Tue, 23 Apr 2019 12:47:37 +0200 Subject: [PATCH] added schematic check system; extended config; fixed bugs; not stable version Signed-off-by: yaruma3341 --- src/config.yml | 6 +- .../schematicsystem/SchematicSystem.java | 19 +- .../schematicsystem/check/CheckSession.java | 194 +++++++++++++++++ .../check/{Check.java => CheckUtils.java} | 68 +++--- .../commands/CheckCommand.java | 204 ++++++++++++++++++ .../commands/SchematicCommand.java | 73 ++----- .../PlayerCommandPreProcessListener.java | 26 +++ .../listener/PlayerJoinListener.java | 7 +- .../listener/PlayerQuitListener.java | 17 +- .../warking/schematicsystem/utils/Config.java | 8 + src/plugin.yml | 3 +- 11 files changed, 512 insertions(+), 113 deletions(-) create mode 100644 src/de/warking/schematicsystem/check/CheckSession.java rename src/de/warking/schematicsystem/check/{Check.java => CheckUtils.java} (88%) create mode 100644 src/de/warking/schematicsystem/commands/CheckCommand.java create mode 100644 src/de/warking/schematicsystem/listener/PlayerCommandPreProcessListener.java diff --git a/src/config.yml b/src/config.yml index 154eb46..f153571 100644 --- a/src/config.yml +++ b/src/config.yml @@ -6,6 +6,7 @@ Schematics: Obsidian: Bedrock: ForbiddenIds: + CheckList: MiniWarGear: Breite: Höhe: @@ -13,6 +14,7 @@ Schematics: Obsidian: Bedrock: ForbiddenIds: + CheckList: WarShip: Breite: Höhe: @@ -20,10 +22,12 @@ Schematics: Obsidian: Bedrock: ForbiddenIds: + CheckList: AirShip: Breite: Höhe: Tiefe: Obsidian: Bedrock: - ForbiddenIds: \ No newline at end of file + ForbiddenIds: + CheckList: \ No newline at end of file diff --git a/src/de/warking/schematicsystem/SchematicSystem.java b/src/de/warking/schematicsystem/SchematicSystem.java index db38098..4488492 100644 --- a/src/de/warking/schematicsystem/SchematicSystem.java +++ b/src/de/warking/schematicsystem/SchematicSystem.java @@ -1,9 +1,8 @@ package de.warking.schematicsystem; import com.sk89q.worldedit.bukkit.WorldEditPlugin; -import de.warking.hunjy.MySQL.Schematic; -import de.warking.hunjy.MySQL.SchematicType; -import de.warking.schematicsystem.check.Check; +import de.warking.schematicsystem.check.CheckUtils; +import de.warking.schematicsystem.commands.CheckCommand; import de.warking.schematicsystem.commands.SchematicCommand; import de.warking.schematicsystem.listener.PlayerJoinListener; import de.warking.schematicsystem.listener.PlayerQuitListener; @@ -13,9 +12,6 @@ import org.bukkit.Bukkit; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; -import java.util.HashMap; -import java.util.UUID; - public class SchematicSystem extends JavaPlugin { public static String SCHEM_DIR = "/home/netuser/schematics/"; @@ -23,8 +19,6 @@ public class SchematicSystem extends JavaPlugin { private static SchematicSystem instance; - public static HashMap currCheckSchems = new HashMap<>(); - public void onEnable() { instance = this; @@ -40,14 +34,15 @@ public class SchematicSystem extends JavaPlugin { getCommand("/schematic").setExecutor(new SchematicCommand()); getCommand("schem").setExecutor(new SchematicCommand()); getCommand("/schem").setExecutor(new SchematicCommand()); + getCommand("check").setExecutor(new CheckCommand()); init(); Bukkit.getScheduler().scheduleAsyncRepeatingTask(instance, new Runnable() { @Override public void run() { - - Check.sendTeamMembersCSchematics(Check.sendTeamMembersCSchematicsInfo()); + if(CheckUtils.getCSchematicsSize() > 0) + CheckUtils.sendTeamMembersCSchematics(CheckUtils.sendTeamMembersCSchematicsInfo()); } }, 0, 20*60*10); } @@ -70,8 +65,4 @@ public class SchematicSystem extends JavaPlugin { public static WorldEditPlugin getWorldEditPlugin() { return (WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit"); } - - public static HashMap getCurrCheckSchems() { - return currCheckSchems; - } } diff --git a/src/de/warking/schematicsystem/check/CheckSession.java b/src/de/warking/schematicsystem/check/CheckSession.java new file mode 100644 index 0000000..82a6559 --- /dev/null +++ b/src/de/warking/schematicsystem/check/CheckSession.java @@ -0,0 +1,194 @@ +package de.warking.schematicsystem.check; + +import de.warking.hunjy.MySQL.Schematic; +import de.warking.hunjy.MySQL.SchematicType; +import de.warking.schematicsystem.utils.Config; +import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import java.util.*; + +public class CheckSession { + + public static ArrayList checkSessions = new ArrayList<>(); + + private UUID uuid; //player + private Schematic schematic; + private int position; //position in checklist + private HashMap checkTimes = new HashMap<>(); //position, time + + private long startTime; + private long stopTime; + + public CheckSession(UUID uuid, Schematic schematic, int position) { + this.uuid = uuid; + this.schematic = schematic; + this.position = position; + + checkSessions.add(this); + setStartTime(); + } + + public static boolean doesPlayerCheck(Player player) { + UUID uuid = player.getUniqueId(); + + for(CheckSession checkSession : checkSessions) { + return checkSession.equals(uuid); + } + return false; + } + + public static CheckSession getCheckSession(Player player) { + for(CheckSession checkSession : checkSessions) { + if(checkSession.getUuid().equals(player.getUniqueId())) + return checkSession; + } + return null; + } + + public int calculatePositionTime() { + return Math.round((stopTime - startTime) / 1000); + } + + public int calculateTotalTime() { + int totalTime = 0; + for(Map.Entry entry : this.checkTimes.entrySet()) { + totalTime += entry.getValue(); + } + return totalTime; + } + + public void sendNextCheck() { + setStopTime(); + this.position++; + setStartTime(); + if(getChecklist().size() > (this.position + 1)) { + Bukkit.getPlayer(uuid).sendMessage(getCheckListEntry(this.position)); + + TextComponent next = new TextComponent("next "); + next.setColor(ChatColor.GREEN); + next.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check next")); + + TextComponent decline = new TextComponent("decline"); + decline.setColor(ChatColor.DARK_RED); + decline.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/check decline ")); + + next.addExtra(decline); + Bukkit.getPlayer(uuid).spigot().sendMessage(next); + return; + } else if(getChecklist().size() == (this.position + 1)) { + Bukkit.getPlayer(uuid).sendMessage(getCheckListEntry(this.position)); + + TextComponent accept = new TextComponent("accept "); + accept.setColor(ChatColor.GREEN); + accept.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check allow")); + + TextComponent decline = new TextComponent("decline"); + decline.setColor(ChatColor.DARK_RED); + decline.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/check decline ")); + + accept.addExtra(decline); + Bukkit.getPlayer(uuid).spigot().sendMessage(accept); + return; + } + } + + public List getChecklist() { + if(schematic.getSchemType() == SchematicType.Cwargear) + return Config.WarGearCheckList; + if(schematic.getSchemType() == SchematicType.Cminiwargear) + return Config.MiniWarGearCheckList; + if(schematic.getSchemType() == SchematicType.Cwarship) + return Config.WarShipCheckList; + if(schematic.getSchemType() == SchematicType.Cairship) + return Config.AirShipCheckList; + + return null; + } + + public String getCheckListEntry(int position) { + return getChecklist().get(position); + } + + public void allowSchematic() { + if(schematic.getSchemType() == SchematicType.Cwargear) { + schematic.setSchemType(SchematicType.wargear); + return; + } + if(schematic.getSchemType() == SchematicType.Cminiwargear) { + schematic.setSchemType(SchematicType.miniwargear); + return; + } + if(schematic.getSchemType() == SchematicType.Cwarship) { + schematic.setSchemType(SchematicType.warship); + return; + } + if(schematic.getSchemType() == SchematicType.Cairship) { + schematic.setSchemType(SchematicType.airship); + return; + } + //TODO: save position times and total time to file + //calculateTotalTime(); + + remove(); + } + + public void declineSchematic() { + this.schematic.setSchemType(SchematicType.normal); + //TODO: save position times and total time to file + //calculateTotalTime(); + remove(); + } + + public void remove() { + checkSessions.remove(this); + } + + public UUID getUuid() { + return uuid; + } + + public void setUuid(UUID uuid) { + this.uuid = uuid; + } + + public Schematic getSchematic() { + return schematic; + } + + public void setSchematic(Schematic schematic) { + this.schematic = schematic; + } + + public int getPosition() { + return position; + } + + public void setPosition(int position) { + this.position = position; + } + + public HashMap getCheckTimes() { + return checkTimes; + } + + public long getStartTime() { + return startTime; + } + + public void setStartTime() { + this.startTime = System.currentTimeMillis(); + } + + public long getStopTime() { + return stopTime; + } + + public void setStopTime() { + this.stopTime = System.currentTimeMillis(); + checkTimes.put(this.position, calculatePositionTime()); + } +} diff --git a/src/de/warking/schematicsystem/check/Check.java b/src/de/warking/schematicsystem/check/CheckUtils.java similarity index 88% rename from src/de/warking/schematicsystem/check/Check.java rename to src/de/warking/schematicsystem/check/CheckUtils.java index 3d466e1..b17f341 100644 --- a/src/de/warking/schematicsystem/check/Check.java +++ b/src/de/warking/schematicsystem/check/CheckUtils.java @@ -3,6 +3,7 @@ package de.warking.schematicsystem.check; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.regions.Region; import de.warking.hunjy.MySQL.Schematic; @@ -22,7 +23,7 @@ import org.bukkit.entity.Player; import java.util.ArrayList; import java.util.List; -public class Check { +public class CheckUtils { public static boolean isSchematicNameAllowed(String schematicName) { if(schematicName.contains("/") || @@ -39,6 +40,7 @@ public class Check { } public static boolean checkSchematic(Clipboard clipboard, List forbiddenBlocks, boolean obsidianToTnt, boolean slimeToBedrock, String modus) { + Region region = clipboard.getRegion(); Vector min = region.getMinimumPoint(); Vector max = region.getMaximumPoint(); @@ -136,6 +138,15 @@ public class Check { } } + public static int getCSchematicsSize() { + int size = Schematic.getAllSchemsOfType(SchematicType.Cairship).size() + + Schematic.getAllSchemsOfType(SchematicType.Cminiwargear).size() + + Schematic.getAllSchemsOfType(SchematicType.Cwargear).size() + + Schematic.getAllSchemsOfType(SchematicType.Cwarship).size(); + + return size; + } + public static String sendTeamMembersCSchematicsInfo() { int size = Schematic.getAllSchemsOfType(SchematicType.Cairship).size() + Schematic.getAllSchemsOfType(SchematicType.Cminiwargear).size() + @@ -155,29 +166,7 @@ public class Check { public static void sendTeammemberSchematicList(Player player, int filesPerPage, int currentPage) { - List wargears = Schematic.getAllSchemsOfType(SchematicType.Cwargear); - List miniwargears = Schematic.getAllSchemsOfType(SchematicType.Cminiwargear); - List warships = Schematic.getAllSchemsOfType(SchematicType.Cwarship); - List airships = Schematic.getAllSchemsOfType(SchematicType.Cairship); - - List schematicList = new ArrayList<>(); - - for(Schematic schematic : wargears) { - if(!SchematicSystem.getCurrCheckSchems().containsValue(schematic)) - schematicList.add(schematic); - } - for(Schematic schematic : miniwargears) { - if(!SchematicSystem.getCurrCheckSchems().containsValue(schematic)) - schematicList.add(schematic); - } - for(Schematic schematic : warships) { - if(!SchematicSystem.getCurrCheckSchems().containsValue(schematic)) - schematicList.add(schematic); - } - for(Schematic schematic : airships) { - if(!SchematicSystem.getCurrCheckSchems().containsValue(schematic)) - schematicList.add(schematic); - } + List schematicList = getAllCSchems(); if(schematicList.isEmpty()) { @@ -224,7 +213,7 @@ public class Check { schematics.setBold(true); schematics.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Schematic prüfen...").create())); - schematics.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem check " + schematic.getSchemName())); + schematics.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check schematic " + schematic.getSchemName() + " " + WarkingUser.get(schematic.getSchemOwner()).getUserName())); player.spigot().sendMessage(schematics); } @@ -235,28 +224,49 @@ public class Check { TextComponent nextPage = new TextComponent("Nächste Seite >>"); nextPage.setColor(ChatColor.RED); nextPage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§6Nächste Seite...").create())); - nextPage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem checklist 1")); + nextPage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check checklist 1")); player.spigot().sendMessage(nextPage); } else if((currPage + 1) == pages) { TextComponent beforePage = new TextComponent("<< Vorherige Seite"); beforePage.setColor(ChatColor.RED); beforePage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§6Vorherige Seite...").create())); - beforePage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem checklist " + (currPage - 1))); + beforePage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check checklist " + (currPage - 1))); player.spigot().sendMessage(beforePage); } else { TextComponent beforePage = new TextComponent("<< Seite "); beforePage.setColor(ChatColor.RED); beforePage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§6Vorherige Seite...").create())); - beforePage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem checklist " + (currPage - 1))); + beforePage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check checklist " + (currPage - 1))); TextComponent nextPage = new TextComponent(">>"); nextPage.setColor(ChatColor.RED); nextPage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§6Nächste Seite...").create())); - nextPage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem checklist " + (currPage + 1))); + nextPage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check checklist " + (currPage + 1))); beforePage.addExtra(nextPage); player.spigot().sendMessage(beforePage); } } + public static List getAllCSchems() { + + List wargears = Schematic.getAllSchemsOfType(SchematicType.Cwargear); + List miniwargears = Schematic.getAllSchemsOfType(SchematicType.Cminiwargear); + List warships = Schematic.getAllSchemsOfType(SchematicType.Cwarship); + List airships = Schematic.getAllSchemsOfType(SchematicType.Cairship); + + List schematicList = new ArrayList<>(); + + for(Schematic schematic : wargears) + schematicList.add(schematic); + for(Schematic schematic : miniwargears) + schematicList.add(schematic); + for(Schematic schematic : warships) + schematicList.add(schematic); + for(Schematic schematic : airships) + schematicList.add(schematic); + + return schematicList; + } + } diff --git a/src/de/warking/schematicsystem/commands/CheckCommand.java b/src/de/warking/schematicsystem/commands/CheckCommand.java new file mode 100644 index 0000000..f69dbf4 --- /dev/null +++ b/src/de/warking/schematicsystem/commands/CheckCommand.java @@ -0,0 +1,204 @@ +package de.warking.schematicsystem.commands; + +import com.boydti.fawe.FaweAPI; +import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.bukkit.BukkitWorld; +import com.sk89q.worldedit.world.World; +import de.warking.hunjy.MySQL.Schematic; +import de.warking.hunjy.MySQL.SchematicType; +import de.warking.hunjy.MySQL.WarkingUser; +import de.warking.schematicsystem.SchematicSystem; +import de.warking.schematicsystem.check.CheckSession; +import de.warking.schematicsystem.check.CheckUtils; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +public class CheckCommand implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if(!(sender instanceof Player)) + return false; + + Player player = (Player) sender; + if(CheckUtils.allowedToCheck(player)) { + + if(args.length == 0) { + sendHelp(player); + return false; + } + + if(args.length == 1) { + if(args[0].equalsIgnoreCase("checklist")) { + CheckUtils.sendTeammemberSchematicList(player, 15, 0); + return false; + } + + if(args[0].equalsIgnoreCase("next")) { + CheckSession checkSession = CheckSession.getCheckSession(player); + if(checkSession != null) { + checkSession.sendNextCheck(); + } else { + player.sendMessage(SchematicSystem.PREFIX + "§cDu prüfst momentan keine Schematic!"); + return false; + } + } + + if(args[0].equalsIgnoreCase("allow")) { + CheckSession checkSession = CheckSession.getCheckSession(player); + if(checkSession != null) { + if(checkSession.getPosition() == (checkSession.getChecklist().size() - 1)) { + + String schemType = ""; + if(checkSession.getSchematic().getSchemType() == SchematicType.Cwargear) + schemType = SchematicType.wargear.name(); + if(checkSession.getSchematic().getSchemType() == SchematicType.Cminiwargear) + schemType = SchematicType.miniwargear.name(); + if(checkSession.getSchematic().getSchemType() == SchematicType.Cwarship) + schemType = SchematicType.warship.name(); + if(checkSession.getSchematic().getSchemType() == SchematicType.Cairship) + schemType = SchematicType.airship.name(); + + player.sendMessage(SchematicSystem.PREFIX + "§aDie Schematic §6" + checkSession.getSchematic().getSchemName() + " §avon §6" + WarkingUser.get(checkSession.getSchematic().getSchemOwner()).getUserName() + " §aist nun als §6" + schemType + " §afreigegeben!"); + checkSession.allowSchematic(); + return false; + } else { + player.sendMessage(SchematicSystem.PREFIX + "§cDu hast noch nicht alles überprüft!"); + return false; + } + } else { + player.sendMessage(SchematicSystem.PREFIX + "§cDu prüfst momentan keine Schematic!"); + return false; + } + } + return false; + } + + if(args.length == 2) { + if(args[0].equalsIgnoreCase("checklist")) { + int currentPage; + try { + currentPage = Integer.parseInt(args[1]); + } catch (NumberFormatException ex) { + player.sendMessage(SchematicSystem.PREFIX + "§cDu musst eine Zahl angeben!"); + return false; + } + CheckUtils.sendTeammemberSchematicList(player, 15, currentPage); + return false; + } + } + + if(args.length == 3) { + + if(args[0].equalsIgnoreCase("schematic")) { + String schemName = args[1]; + String owner = args[2]; + + if(!CheckUtils.isSchematicNameAllowed(schemName)) { + player.sendMessage(SchematicSystem.PREFIX + "§cDer angegebene Schematic Name enthält verbotene Zeichen!"); + return false; + } + + WarkingUser warkingUser = WarkingUser.get(owner); + if(warkingUser != null) { + + Schematic schematic = Schematic.getSchemFromDB(schemName, warkingUser.getUUID()); + if(schematic != null) { + for(CheckSession checkSession : CheckSession.checkSessions) { + if(checkSession.getSchematic().equals(schematic)) { + player.sendMessage(SchematicSystem.PREFIX +"§cDiese Schematic wird bereits geprüft!"); + return false; + } + } + + HashMap schematicList = new HashMap<>(); + for(Schematic schematics : CheckUtils.getAllCSchems()) { + schematicList.put(schematics.getSchemName(), WarkingUser.get(schematics.getSchemOwner()).getUUID()); + } + + for(Map.Entry entry : schematicList.entrySet()) { + if(!(entry.getKey().equals(schematic.getSchemName()) && entry.getValue().equals(WarkingUser.get(schematic.getSchemOwner()).getUUID()))) { + player.sendMessage(SchematicSystem.PREFIX + "§cBeim Laden der Schematic ist ein Fehler aufgetreten! CONTAINS"); + return false; + } + } + + File file = new File(SchematicSystem.SCHEM_DIR + warkingUser.getUUID().toString() + "/" + schemName + ".schematic"); + if(!file.exists()) { + player.sendMessage(SchematicSystem.PREFIX + "§cBeim Laden der Schematic ist ein Fehler aufgetreten! NO SUCH FILE"); + return false; + } + + try { + com.boydti.fawe.object.schematic.Schematic schematicFAWE = FaweAPI.load(file); + Location playerLocation = player.getLocation(); + + World weWorld = new BukkitWorld(player.getWorld()); + Vector vector = new Vector(playerLocation.getBlockX(), playerLocation.getBlockY(), playerLocation.getBlockZ()); + schematicFAWE.paste(weWorld, vector); + } catch (IOException ex) { + player.sendMessage(SchematicSystem.PREFIX + "§cBeim Laden der Schematic ist ein Fehler aufgetreten! PASTE"); + ex.printStackTrace(); + return false; + } + + CheckSession checkSession = new CheckSession(player.getUniqueId(), schematic, -1); + checkSession.sendNextCheck(); + + + } else { + player.sendMessage(SchematicSystem.PREFIX + "§cBeim Laden der Schematic ist ein Fehler aufgetreten! NULL"); + return false; + } + } else { + player.sendMessage(SchematicSystem.PREFIX + "§cBeim Laden der Schematic ist ein Fehler aufgetreten! USER"); + return false; + } + return false; + } + } + + if(args.length >= 3) { + if(args[0].equalsIgnoreCase("decline")) { + + CheckSession checkSession = CheckSession.getCheckSession(player); + if(checkSession != null) { + + String message = ""; + for (int i = 1; i < args.length; i++) { + message = message + args[i] + " "; + } + player.sendMessage(SchematicSystem.PREFIX + "§aDie Schematic §6" + checkSession.getSchematic().getSchemName() + " §avon §6" + WarkingUser.get(checkSession.getSchematic().getSchemOwner()).getUserName() + " §awurde aufgrund von §6" + message + " §anicht freigegeben!"); + checkSession.declineSchematic(); + } else { + player.sendMessage(SchematicSystem.PREFIX + "§cDu prüfst momentan keine Schematic!"); + return false; + } + return false; + } + } + } + + return false; + } + + public void sendHelp(Player player) { + if(CheckUtils.allowedToCheck(player)) { + player.sendMessage(SchematicSystem.PREFIX + "§cTeambefehle:"); + player.sendMessage("§8/ckeck checklist - §6Zeigt die Liste der ungeprüften Schematics"); + player.sendMessage("§8/ckeck schematic - §6Zum Checken einer Schematic"); + player.sendMessage("§8/ckeck allow - §6Schematic freigeben"); + player.sendMessage("§8/ckeck decline - §6Schematic nicht freigeben"); + } + } +} diff --git a/src/de/warking/schematicsystem/commands/SchematicCommand.java b/src/de/warking/schematicsystem/commands/SchematicCommand.java index 2377c58..f57a00d 100644 --- a/src/de/warking/schematicsystem/commands/SchematicCommand.java +++ b/src/de/warking/schematicsystem/commands/SchematicCommand.java @@ -9,7 +9,7 @@ import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; import com.sk89q.worldedit.session.ClipboardHolder; import de.warking.hunjy.MySQL.*; import de.warking.schematicsystem.SchematicSystem; -import de.warking.schematicsystem.check.Check; +import de.warking.schematicsystem.check.CheckUtils; import de.warking.schematicsystem.utils.Config; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.chat.ClickEvent; @@ -57,11 +57,6 @@ public class SchematicCommand implements CommandExecutor { sendHelp(player); return false; } - - if(args[0].equalsIgnoreCase("checklist") && Check.allowedToCheck(player)) { - Check.sendTeammemberSchematicList(player, 15, 0); - return false; - } return false; case 2: @@ -76,7 +71,7 @@ public class SchematicCommand implements CommandExecutor { } if(args[0].equalsIgnoreCase("load")) { - if(Check.isSchematicNameAllowed(args[1])) { + if(CheckUtils.isSchematicNameAllowed(args[1])) { Schematic schematic = Schematic.getSchemFromDB(args[1], player.getUniqueId()); if (schematic != null) { @@ -108,7 +103,7 @@ public class SchematicCommand implements CommandExecutor { } if(args[0].equalsIgnoreCase("delete")) { - if(Check.isSchematicNameAllowed(args[1])) { + if(CheckUtils.isSchematicNameAllowed(args[1])) { Schematic schematic = Schematic.getSchemFromDB(args[1], player.getUniqueId()); if(schematic != null) { if(WarkingUser.get(schematic.getSchemOwner()).getUUID().equals(player.getUniqueId())) { @@ -140,7 +135,7 @@ public class SchematicCommand implements CommandExecutor { } if(args[0].equalsIgnoreCase("savedelete")) { - if(Check.isSchematicNameAllowed(args[1])) { + if(CheckUtils.isSchematicNameAllowed(args[1])) { Schematic schematic = Schematic.getSchemFromDB(args[1], player.getUniqueId()); if(schematic != null) { if(WarkingUser.get(schematic.getSchemOwner()).getUUID().equals(player.getUniqueId())) { @@ -165,7 +160,7 @@ public class SchematicCommand implements CommandExecutor { if(args[0].equalsIgnoreCase("save")) { - if(Check.isSchematicNameAllowed(args[1])) { + if(CheckUtils.isSchematicNameAllowed(args[1])) { try { if(FaweAPI.wrapPlayer(player).getSession().getClipboard().getClipboard() != null) { if(Schematic.getSchemFromDB(args[1], player.getUniqueId()) != null) { @@ -180,7 +175,12 @@ public class SchematicCommand implements CommandExecutor { } else player.sendMessage(SchematicSystem.PREFIX + "Schematic §6" + args[1] + " §7gespeichert!"); - File file = new File(SchematicSystem.SCHEM_DIR + player.getUniqueId().toString() + "/", args[1] + ".schematic"); + + File folder = new File(SchematicSystem.SCHEM_DIR + player.getUniqueId().toString() + "/"); + if(!folder.exists()) + folder.mkdir(); + + File file = new File(folder, args[1] + ".schematic"); file.createNewFile(); Files.setPosixFilePermissions(file.toPath(), EnumSet.of(PosixFilePermission.OWNER_READ, @@ -207,7 +207,7 @@ public class SchematicCommand implements CommandExecutor { } if(args[0].equalsIgnoreCase("info")) { - if(Check.isSchematicNameAllowed(args[1])) { + if(CheckUtils.isSchematicNameAllowed(args[1])) { Schematic schematic = Schematic.getSchemFromDB(args[1], player.getUniqueId()); if(schematic != null) { @@ -249,18 +249,6 @@ public class SchematicCommand implements CommandExecutor { return false; } } - - if(args[0].equalsIgnoreCase("checklist") && Check.allowedToCheck(player)) { - int currentPage; - try { - currentPage = Integer.parseInt(args[1]); - } catch (NumberFormatException ex) { - player.sendMessage(SchematicSystem.PREFIX + "§cDu musst eine Zahl angeben!"); - return false; - } - Check.sendTeammemberSchematicList(player, 15, currentPage); - return false; - } return false; case 3: @@ -268,7 +256,7 @@ public class SchematicCommand implements CommandExecutor { if(!player.hasPermission("bau.team")) return false; WarkingUser warkingUser = WarkingUser.get(args[2]); if(warkingUser != null) { - if(Check.isSchematicNameAllowed(args[1])) { + if(CheckUtils.isSchematicNameAllowed(args[1])) { Schematic schematic = Schematic.getSchemFromDB(args[1], warkingUser.getUUID()); if(schematic != null) { try { @@ -323,52 +311,52 @@ public class SchematicCommand implements CommandExecutor { if(args[2].equalsIgnoreCase("airship")) { if(dimensions.getBlockX() <= Config.AirShipBreite && dimensions.getBlockY() <= Config.AirShipHöhe && dimensions.getBlockZ() <= Config.AirShipTiefe) { - if(!Check.checkSchematic(clipboard, Config.AirShipForbiddenIds, true, true, "AirShip")) { + if(!CheckUtils.checkSchematic(clipboard, Config.AirShipForbiddenIds, true, true, "AirShip")) { player.sendMessage(SchematicSystem.PREFIX + "§cDein AirShip ist nicht regelkonform!"); return false; } schematic.setSchemType(SchematicType.Cairship); player.sendMessage(SchematicSystem.PREFIX + "Schematic Type §6airship §7angefordert!"); - Check.sendTeamMembersCSchematics(SchematicSystem.PREFIX + "§aDer Benutzer §6" + player.getName() + " §ahat eine Schematic eingesendet §8[§6AirShip§8]"); + CheckUtils.sendTeamMembersCSchematics(SchematicSystem.PREFIX + "§aDer Benutzer §6" + player.getName() + " §ahat eine Schematic eingesendet §8[§6AirShip§8]"); } return false; } if(args[2].equalsIgnoreCase("miniwargear")) { if(dimensions.getBlockX() <= Config.MiniWarGearBreite && dimensions.getBlockY() <= Config.MiniWarGearHöhe && dimensions.getBlockZ() <= Config.MiniWarGearTiefe) { - if(!Check.checkSchematic(clipboard, Config.MiniWarGearForbiddenIds, true, true, "MiniWarGear")) { + if(!CheckUtils.checkSchematic(clipboard, Config.MiniWarGearForbiddenIds, true, true, "MiniWarGear")) { player.sendMessage(SchematicSystem.PREFIX + "§cDein MiniWarGear ist nicht regelkonform!"); return false; } schematic.setSchemType(SchematicType.Cminiwargear); player.sendMessage(SchematicSystem.PREFIX + "Schematic Type §6miniwargear §7angefordert!"); - Check.sendTeamMembersCSchematics(SchematicSystem.PREFIX + "§aDer Benutzer §6" + player.getName() + " §ahat eine Schematic eingesendet §8[§6MiniWarGear§8]"); + CheckUtils.sendTeamMembersCSchematics(SchematicSystem.PREFIX + "§aDer Benutzer §6" + player.getName() + " §ahat eine Schematic eingesendet §8[§6MiniWarGear§8]"); } return false; } if(args[2].equalsIgnoreCase("wargear")) { if(dimensions.getBlockX() <= Config.WarGearBreite && dimensions.getBlockY() <= Config.WarGearHöhe && dimensions.getBlockZ() <= Config.WarGearTiefe) { - if(!Check.checkSchematic(clipboard, Config.WarGearForbiddenIds, true, true, "WarGear")) { + if(!CheckUtils.checkSchematic(clipboard, Config.WarGearForbiddenIds, true, true, "WarGear")) { player.sendMessage(SchematicSystem.PREFIX + "§cDein WarGear ist nicht regelkonform!"); return false; } schematic.setSchemType(SchematicType.Cwargear); player.sendMessage(SchematicSystem.PREFIX + "Schematic Type §6wargear §7angefordert!"); - Check.sendTeamMembersCSchematics(SchematicSystem.PREFIX + "§aDer Benutzer §6" + player.getName() + " §ahat eine Schematic eingesendet §8[§6WarGear§8]"); + CheckUtils.sendTeamMembersCSchematics(SchematicSystem.PREFIX + "§aDer Benutzer §6" + player.getName() + " §ahat eine Schematic eingesendet §8[§6WarGear§8]"); } return false; } if(args[2].equalsIgnoreCase("warship")) { if(dimensions.getBlockX() <= Config.WarShipBreite && dimensions.getBlockY() <= Config.WarShipHöhe && dimensions.getBlockZ() <= Config.WarShipTiefe) { - if(!Check.checkSchematic(clipboard, Config.WarShipForbiddenIds, true, true, "WarShip")) { + if(!CheckUtils.checkSchematic(clipboard, Config.WarShipForbiddenIds, true, true, "WarShip")) { player.sendMessage(SchematicSystem.PREFIX + "§cDein WarShip ist nicht regelkonform!"); return false; } schematic.setSchemType(SchematicType.Cwarship); player.sendMessage(SchematicSystem.PREFIX + "Schematic Type §6warship §7angefordert!"); - Check.sendTeamMembersCSchematics(SchematicSystem.PREFIX + "§aDer Benutzer §6" + player.getName() + " §ahat eine Schematic eingesendet §8[§6WarShip§8]"); + CheckUtils.sendTeamMembersCSchematics(SchematicSystem.PREFIX + "§aDer Benutzer §6" + player.getName() + " §ahat eine Schematic eingesendet §8[§6WarShip§8]"); } return false; } @@ -383,7 +371,7 @@ public class SchematicCommand implements CommandExecutor { } if(args[0].equalsIgnoreCase("addmember")) { - if(Check.isSchematicNameAllowed(args[1])) { + if(CheckUtils.isSchematicNameAllowed(args[1])) { Schematic schematic = Schematic.getSchemFromDB(args[1], player.getUniqueId()); if(schematic != null) { if(schematic.getSchemOwner() != WarkingUser.get(player.getUniqueId()).getId()) { @@ -426,7 +414,7 @@ public class SchematicCommand implements CommandExecutor { } if(args[0].equalsIgnoreCase("delmember")) { - if(Check.isSchematicNameAllowed(args[1])) { + if(CheckUtils.isSchematicNameAllowed(args[1])) { Schematic schematic = Schematic.getSchemFromDB(args[1], player.getUniqueId()); if(schematic != null) { if(schematic.getSchemOwner() != WarkingUser.get(player.getUniqueId()).getId()) { @@ -469,14 +457,6 @@ public class SchematicCommand implements CommandExecutor { return false; } } - - if(args[0].equalsIgnoreCase("lock")) { - return false; - } - - if(args[0].equalsIgnoreCase("unlock")) { - return false; - } } return false; } @@ -494,13 +474,6 @@ public class SchematicCommand implements CommandExecutor { player.sendMessage("§8/schem addmember - §6Fügt einen Spieler zu einer Schematic hinzu"); player.sendMessage("§8/schem delmember - §6Entfernt einen Spieler von einer Schematic"); - if(Check.allowedToCheck(player)) { - player.sendMessage(SchematicSystem.PREFIX + "§cTeambefehle:"); - player.sendMessage("§8/schem checklist - §6Zeigt die Liste der ungeprüften Schematics"); - player.sendMessage("§8/schem check - §6Zum Checken einer Schematic"); - player.sendMessage("§8/schem allow / decline - §6Schematic (nicht) freigeben"); - } - } public static void sendPlayerSchematicList(int currentPage, int filesPerPage, Player player) { diff --git a/src/de/warking/schematicsystem/listener/PlayerCommandPreProcessListener.java b/src/de/warking/schematicsystem/listener/PlayerCommandPreProcessListener.java new file mode 100644 index 0000000..a82a5ea --- /dev/null +++ b/src/de/warking/schematicsystem/listener/PlayerCommandPreProcessListener.java @@ -0,0 +1,26 @@ +package de.warking.schematicsystem.listener; + +import de.warking.schematicsystem.SchematicSystem; +import de.warking.schematicsystem.check.CheckSession; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; + +public class PlayerCommandPreProcessListener implements Listener { + + @EventHandler + public void handlePlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { + Player player = event.getPlayer(); + if(!event.getMessage().contains("copy")) + return; + + if(CheckSession.doesPlayerCheck(player)) { + event.setCancelled(true); + player.sendMessage(SchematicSystem.PREFIX + "§cDu darfst nichts kopieren während du eine Schematic prüfst!"); + //eventuell Admin Benachrichtigen + } + } + + +} diff --git a/src/de/warking/schematicsystem/listener/PlayerJoinListener.java b/src/de/warking/schematicsystem/listener/PlayerJoinListener.java index 279a1e9..3ae693f 100644 --- a/src/de/warking/schematicsystem/listener/PlayerJoinListener.java +++ b/src/de/warking/schematicsystem/listener/PlayerJoinListener.java @@ -4,8 +4,7 @@ import de.warking.hunjy.MySQL.Schematic; import de.warking.hunjy.MySQL.SchematicType; import de.warking.hunjy.MySQL.WarkingUser; import de.warking.schematicsystem.SchematicSystem; -import de.warking.schematicsystem.check.Check; -import de.warking.schematicsystem.commands.SchematicCommand; +import de.warking.schematicsystem.check.CheckUtils; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -40,8 +39,8 @@ public class PlayerJoinListener implements Listener { } } - if(Check.allowedToCheck(player)) - player.sendMessage(Check.sendTeamMembersCSchematicsInfo()); + if(CheckUtils.allowedToCheck(player)) + player.sendMessage(CheckUtils.sendTeamMembersCSchematicsInfo()); } diff --git a/src/de/warking/schematicsystem/listener/PlayerQuitListener.java b/src/de/warking/schematicsystem/listener/PlayerQuitListener.java index 98f0b0c..12b1f49 100644 --- a/src/de/warking/schematicsystem/listener/PlayerQuitListener.java +++ b/src/de/warking/schematicsystem/listener/PlayerQuitListener.java @@ -1,29 +1,18 @@ package de.warking.schematicsystem.listener; -import de.warking.hunjy.MySQL.Schematic; -import de.warking.schematicsystem.SchematicSystem; +import de.warking.schematicsystem.check.CheckSession; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerQuitEvent; -import java.util.Iterator; -import java.util.Map; -import java.util.UUID; - public class PlayerQuitListener implements Listener { @EventHandler public void handlePlayerQuit(PlayerQuitEvent event) { Player player = event.getPlayer(); - if(SchematicSystem.getCurrCheckSchems().containsKey(player.getUniqueId())) { - Iterator itr = SchematicSystem.getCurrCheckSchems().entrySet().iterator(); - while (itr.hasNext()) { - Map.Entry pair = (Map.Entry) itr.next(); - if(pair.getKey().equals(player.getUniqueId())) - itr.remove(); - } - } + if(CheckSession.doesPlayerCheck(player)) + CheckSession.getCheckSession(player).remove(); } diff --git a/src/de/warking/schematicsystem/utils/Config.java b/src/de/warking/schematicsystem/utils/Config.java index 92cde94..a0ce672 100644 --- a/src/de/warking/schematicsystem/utils/Config.java +++ b/src/de/warking/schematicsystem/utils/Config.java @@ -17,6 +17,7 @@ public class Config { public static int WarGearObsidianBedrock; public static int WarGearMaxDispenser; public static List WarGearForbiddenIds; + public static List WarGearCheckList; public static double MiniWarGearBreite; public static double MiniWarGearHöhe; @@ -26,6 +27,7 @@ public class Config { public static int MiniWarGearObsidianBedrock; public static int MiniWarGearMaxDispenser; public static List MiniWarGearForbiddenIds; + public static List MiniWarGearCheckList; public static double WarShipBreite; public static double WarShipHöhe; @@ -35,6 +37,7 @@ public class Config { public static int WarShipObsidianBedrock; public static int WarShipMaxDispenser; public static List WarShipForbiddenIds; + public static List WarShipCheckList; public static double AirShipBreite; public static double AirShipHöhe; @@ -44,6 +47,7 @@ public class Config { public static int AirShipObsidianBedrock; public static int AirShipMaxDispenser; public static List AirShipForbiddenIds; + public static List AirShipCheckList; public static void load() { if (!new File("plugins/" + SchematicSystem.getInstance().getName() + "/config.yml").exists()) { @@ -61,6 +65,7 @@ public class Config { WarGearObsidianBedrock = config.getInt("Schematics.WarGear.ObsidianBedrock"); WarGearMaxDispenser = config.getInt("Schematics.WarGear.Dispenser"); WarGearForbiddenIds = config.getIntegerList("Schematics.WarGear.ForbiddenIds"); + WarGearCheckList = config.getStringList("Schematics.WarGear.CheckList"); MiniWarGearBreite = config.getDouble("Schematics.MiniWarGear.Breite"); MiniWarGearHöhe = config.getDouble("Schematics.MiniWarGear.Höhe"); @@ -70,6 +75,7 @@ public class Config { MiniWarGearObsidianBedrock = config.getInt("Schematics.MiniWarGear.ObsidianBedrock"); MiniWarGearMaxDispenser = config.getInt("Schematics.MiniWarGear.Dispenser"); MiniWarGearForbiddenIds = config.getIntegerList("Schematics.MiniWarGear.ForbiddenIds"); + MiniWarGearCheckList = config.getStringList("Schematics.MiniWarGear.CheckList"); WarShipBreite = config.getDouble("Schematics.WarShip.Breite"); WarShipHöhe = config.getDouble("Schematics.WarShip.Höhe"); @@ -79,6 +85,7 @@ public class Config { WarShipObsidianBedrock = config.getInt("Schematics.WarShip.ObsidianBedrock"); WarShipMaxDispenser = config.getInt("Schematics.WarShip.Dispenser"); WarShipForbiddenIds = config.getIntegerList("Schematics.WarShip.ForbiddenIds"); + WarShipCheckList = config.getStringList("Schematics.WarShip.CheckList"); AirShipBreite = config.getDouble("Schematics.AirShip.Breite"); AirShipHöhe = config.getDouble("Schematics.AirShip.Höhe"); @@ -88,5 +95,6 @@ public class Config { AirShipObsidianBedrock = config.getInt("Schematics.AirShip.ObsidianBedrock"); AirShipMaxDispenser = config.getInt("Schematics.AirShip.Dispenser"); AirShipForbiddenIds = config.getIntegerList("Schematics.AirShip.ForbiddenIds"); + AirShipCheckList = config.getStringList("Schematics.AirShip.CheckList"); } } diff --git a/src/plugin.yml b/src/plugin.yml index b1cdf32..fe8d7c0 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -8,4 +8,5 @@ commands: schematic: /schematic: schem: - /schem: \ No newline at end of file + /schem: + check: \ No newline at end of file