13
0

Fixed bugs; updated schematic list; added messages; stable version

Signed-off-by: yaruma3341 <yaruma3341@gmail.com>
Dieser Commit ist enthalten in:
Yaruma3341 2019-04-07 15:15:35 +02:00 committet von yaruma3341
Ursprung e21495a77a
Commit f922fdfd14

Datei anzeigen

@ -29,12 +29,9 @@ import java.nio.file.attribute.PosixFilePermission;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.List; import java.util.List;
import java.util.UUID;
public class SchematicCommand implements CommandExecutor { public class SchematicCommand implements CommandExecutor {
private static ArrayList<UUID> deletePlayers = new ArrayList<>();
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
@ -59,15 +56,6 @@ public class SchematicCommand implements CommandExecutor {
sendHelp(player); sendHelp(player);
return false; return false;
} }
if(args[0].equalsIgnoreCase("removesavedelete")) {
if(deletePlayers.contains(player.getUniqueId())) {
deletePlayers.remove(player.getUniqueId());
player.sendMessage(SchematicSystem.PREFIX + "§6Schematic wird nicht gelöscht.");
return false;
}
return false;
}
return false; return false;
case 2: case 2:
@ -118,26 +106,18 @@ public class SchematicCommand implements CommandExecutor {
Schematic schematic = Schematic.getSchemFromDB(args[1], player.getUniqueId()); Schematic schematic = Schematic.getSchemFromDB(args[1], player.getUniqueId());
if(schematic != null) { if(schematic != null) {
if(WarkingUser.get(schematic.getSchemOwner()).getUUID().equals(player.getUniqueId())) { if(WarkingUser.get(schematic.getSchemOwner()).getUUID().equals(player.getUniqueId())) {
if(!deletePlayers.contains(player.getUniqueId())) {
deletePlayers.add(player.getUniqueId());
TextComponent message = new TextComponent("§6Moechtest du die Schematic wirklich loeschen? "); TextComponent message = new TextComponent("§6Möchtest du die Schematic wirklich löschen?");
message.setBold(true); message.setBold(true);
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Waehle eine Option...").create())); message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Wähle eine Option...").create()));
TextComponent ja = new TextComponent("§aja "); TextComponent ja = new TextComponent("§aja");
ja.setBold(true); ja.setBold(true);
ja.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem savedelete " + args[1])); ja.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§4Schematic löschen...").create()));
ja.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem savedelete " + args[1]));
TextComponent nein = new TextComponent("nein"); player.spigot().sendMessage(message);
nein.setColor(ChatColor.RED); player.spigot().sendMessage(ja);
nein.setBold(true);
nein.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem removesavedelete"));
message.addExtra(ja);
message.addExtra(nein);
player.spigot().sendMessage(message);
}
return false; return false;
} else { } else {
player.sendMessage(SchematicSystem.PREFIX + "§cZum Löschen musst du der Owner der Schematic sein!"); player.sendMessage(SchematicSystem.PREFIX + "§cZum Löschen musst du der Owner der Schematic sein!");
@ -155,24 +135,21 @@ public class SchematicCommand implements CommandExecutor {
if(args[0].equalsIgnoreCase("savedelete")) { if(args[0].equalsIgnoreCase("savedelete")) {
if(isSchematicNameAllowed(args[1])) { if(isSchematicNameAllowed(args[1])) {
if(deletePlayers.contains(player.getUniqueId())) { Schematic schematic = Schematic.getSchemFromDB(args[1], player.getUniqueId());
Schematic schematic = Schematic.getSchemFromDB(args[1], player.getUniqueId()); if(schematic != null) {
if(schematic != null) { if(WarkingUser.get(schematic.getSchemOwner()).getUUID().equals(player.getUniqueId())) {
if(WarkingUser.get(schematic.getSchemOwner()).getUUID().equals(player.getUniqueId())) { File file = new File(SchematicSystem.SCHEM_DIR + player.getUniqueId() + "/" + args[1] + ".schematic");
File file = new File(SchematicSystem.SCHEM_DIR + player.getUniqueId() + "/" + args[1] + ".schematic"); file.delete();
file.delete(); schematic.remove();
schematic.remove(); player.sendMessage(SchematicSystem.PREFIX + "Schematic §6" + args[1] + " §7gelöscht.");
deletePlayers.remove(player.getUniqueId()); return false;
player.sendMessage(SchematicSystem.PREFIX + "Schematic §6" + args[1] + " §7gelöscht.");
return false;
} else {
player.sendMessage(SchematicSystem.PREFIX + "§cZum Löschen musst du der Owner der Schematic sein!");
return false;
}
} else { } else {
player.sendMessage(SchematicSystem.PREFIX + "§cDiese Schematic existiert nicht!"); player.sendMessage(SchematicSystem.PREFIX + "§cZum Löschen musst du der Owner der Schematic sein!");
return false; return false;
} }
} else {
player.sendMessage(SchematicSystem.PREFIX + "§cDiese Schematic existiert nicht!");
return false;
} }
} else { } else {
player.sendMessage(SchematicSystem.PREFIX + "§cDer angegebene Schematic Name enthält verbotene Zeichen!"); player.sendMessage(SchematicSystem.PREFIX + "§cDer angegebene Schematic Name enthält verbotene Zeichen!");
@ -194,8 +171,11 @@ public class SchematicCommand implements CommandExecutor {
} }
} }
if(Schematic.getSchemFromDB(args[1], player.getUniqueId()) != null) if(Schematic.getSchemFromDB(args[1], player.getUniqueId()) != null) {
Schematic.getSchemFromDB(args[1], player.getUniqueId()).remove(); Schematic.getSchemFromDB(args[1], player.getUniqueId()).remove();
player.sendMessage(SchematicSystem.PREFIX + "Schematic §6" + args[1] + " §7überschrieben!");
} else
player.sendMessage(SchematicSystem.PREFIX + "Schematic §6" + args[1] + " §7gespeichert!");
File file = new File(SchematicSystem.SCHEM_DIR + player.getUniqueId().toString() + "/", args[1] + ".schematic"); File file = new File(SchematicSystem.SCHEM_DIR + player.getUniqueId().toString() + "/", args[1] + ".schematic");
file.createNewFile(); file.createNewFile();
@ -211,7 +191,6 @@ public class SchematicCommand implements CommandExecutor {
FaweAPI.wrapPlayer(player).getSession().getClipboard().getWorldData()); FaweAPI.wrapPlayer(player).getSession().getClipboard().getWorldData());
Schematic schematic = new Schematic(args[1], player.getUniqueId(), "", SchematicType.normal); Schematic schematic = new Schematic(args[1], player.getUniqueId(), "", SchematicType.normal);
player.sendMessage(SchematicSystem.PREFIX + "Schematic §6" + args[1] + " §7gespeichert!");
} else { } else {
player.sendMessage(SchematicSystem.PREFIX + "§cDein Clipboard ist leer!"); player.sendMessage(SchematicSystem.PREFIX + "§cDein Clipboard ist leer!");
@ -252,7 +231,7 @@ public class SchematicCommand implements CommandExecutor {
player.spigot().sendMessage(loadSchematic); player.spigot().sendMessage(loadSchematic);
if(WarkingUser.get(schematic.getSchemOwner()).getUUID().equals(player.getUniqueId())) { if(WarkingUser.get(schematic.getSchemOwner()).getUUID().equals(player.getUniqueId())) {
TextComponent deleteSchematic = new TextComponent("LOESCHEN"); TextComponent deleteSchematic = new TextComponent("LÖSCHEN");
deleteSchematic.setColor(ChatColor.RED); deleteSchematic.setColor(ChatColor.RED);
deleteSchematic.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem delete " + schematic.getSchemName())); deleteSchematic.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem delete " + schematic.getSchemName()));
player.spigot().sendMessage(deleteSchematic); player.spigot().sendMessage(deleteSchematic);
@ -350,12 +329,12 @@ public class SchematicCommand implements CommandExecutor {
Player target = Bukkit.getPlayer(warkingUser.getUUID()); Player target = Bukkit.getPlayer(warkingUser.getUUID());
if(target != null) if(target != null)
target.sendMessage(SchematicSystem.PREFIX + "Du hast keinen Zugriff mehr auf die Schematic §6" + schematic.getSchemName() + "§7von §6" + WarkingUser.get(schematic.getSchemOwner()).getUserName() + "§7."); target.sendMessage(SchematicSystem.PREFIX + "Du hast nun Zugriff auf die Schematic §6" + schematic.getSchemName() + "§7von §6" + WarkingUser.get(schematic.getSchemOwner()).getUserName() + "§7.");
return false; return false;
} }
} else { } else {
player.sendMessage(SchematicSystem.PREFIX + "§cDu kannst dich nicht auf deine eigenen Schematics adden!"); player.sendMessage(SchematicSystem.PREFIX + "§cDu kannst dich nicht auf deine eigene Schematic adden!");
return false; return false;
} }
} else { } else {
@ -458,10 +437,24 @@ public class SchematicCommand implements CommandExecutor {
return; return;
} }
int pages;
double doublePages = (Double.valueOf(schematicList.size()) / Double.valueOf(filesPerPage));
int intPages = schematicList.size() / filesPerPage;
if(schematicList.size() <= filesPerPage) {
pages = 1;
} else if(doublePages > intPages) {
pages = (intPages + 1);
} else
pages = intPages;
int pages = schematicList.size() / filesPerPage;
int currPage = currentPage; int currPage = currentPage;
if(currPage >= pages) return;
player.sendMessage("§5======§8[§dSeite " + (currentPage + 1) + " §7/ §d" + pages + " §7| §d" + schematicList.size() + " Schematic(s)§8]§5======");
for(int i = currPage * filesPerPage; i < (currPage * filesPerPage) + filesPerPage; i++) { for(int i = currPage * filesPerPage; i < (currPage * filesPerPage) + filesPerPage; i++) {
if(schematicList.size() <= i) break; if(schematicList.size() <= i) break;
@ -494,19 +487,34 @@ public class SchematicCommand implements CommandExecutor {
player.spigot().sendMessage(schematics); player.spigot().sendMessage(schematics);
} }
if(pages < 1) return; if(pages <= 1) return;
TextComponent nextPage = new TextComponent(">> Naechste Seite <<"); if(currPage == 0) {
nextPage.setColor(ChatColor.RED); 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 list 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 list " + (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 list " + (currPage - 1)));
nextPage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Naechste Seite...").create())); 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 list " + (currPage + 1)));
if(currPage >= pages) { beforePage.addExtra(nextPage);
nextPage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem list " + 0)); player.spigot().sendMessage(beforePage);
} else }
nextPage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem list " + (currentPage + 1)));
player.spigot().sendMessage(nextPage);
} }
private boolean isSchematicNameAllowed(String schematicName) { private boolean isSchematicNameAllowed(String schematicName) {