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.EnumSet;
import java.util.List;
import java.util.UUID;
public class SchematicCommand implements CommandExecutor {
private static ArrayList<UUID> deletePlayers = new ArrayList<>();
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
@ -59,15 +56,6 @@ public class SchematicCommand implements CommandExecutor {
sendHelp(player);
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;
case 2:
@ -118,26 +106,18 @@ public class SchematicCommand implements CommandExecutor {
Schematic schematic = Schematic.getSchemFromDB(args[1], player.getUniqueId());
if(schematic != null) {
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? ");
message.setBold(true);
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Waehle eine Option...").create()));
TextComponent message = new TextComponent("§6Möchtest du die Schematic wirklich löschen?");
message.setBold(true);
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Wähle eine Option...").create()));
TextComponent ja = new TextComponent("§aja ");
ja.setBold(true);
ja.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem savedelete " + args[1]));
TextComponent ja = new TextComponent("§aja");
ja.setBold(true);
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");
nein.setColor(ChatColor.RED);
nein.setBold(true);
nein.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem removesavedelete"));
message.addExtra(ja);
message.addExtra(nein);
player.spigot().sendMessage(message);
}
player.spigot().sendMessage(message);
player.spigot().sendMessage(ja);
return false;
} else {
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(isSchematicNameAllowed(args[1])) {
if(deletePlayers.contains(player.getUniqueId())) {
Schematic schematic = Schematic.getSchemFromDB(args[1], player.getUniqueId());
if(schematic != null) {
if(WarkingUser.get(schematic.getSchemOwner()).getUUID().equals(player.getUniqueId())) {
File file = new File(SchematicSystem.SCHEM_DIR + player.getUniqueId() + "/" + args[1] + ".schematic");
file.delete();
schematic.remove();
deletePlayers.remove(player.getUniqueId());
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;
}
Schematic schematic = Schematic.getSchemFromDB(args[1], player.getUniqueId());
if(schematic != null) {
if(WarkingUser.get(schematic.getSchemOwner()).getUUID().equals(player.getUniqueId())) {
File file = new File(SchematicSystem.SCHEM_DIR + player.getUniqueId() + "/" + args[1] + ".schematic");
file.delete();
schematic.remove();
player.sendMessage(SchematicSystem.PREFIX + "Schematic §6" + args[1] + " §7gelöscht.");
return false;
} 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;
}
} else {
player.sendMessage(SchematicSystem.PREFIX + "§cDiese Schematic existiert nicht!");
return false;
}
} else {
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();
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.createNewFile();
@ -211,7 +191,6 @@ public class SchematicCommand implements CommandExecutor {
FaweAPI.wrapPlayer(player).getSession().getClipboard().getWorldData());
Schematic schematic = new Schematic(args[1], player.getUniqueId(), "", SchematicType.normal);
player.sendMessage(SchematicSystem.PREFIX + "Schematic §6" + args[1] + " §7gespeichert!");
} else {
player.sendMessage(SchematicSystem.PREFIX + "§cDein Clipboard ist leer!");
@ -252,7 +231,7 @@ public class SchematicCommand implements CommandExecutor {
player.spigot().sendMessage(loadSchematic);
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.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem delete " + schematic.getSchemName()));
player.spigot().sendMessage(deleteSchematic);
@ -350,12 +329,12 @@ public class SchematicCommand implements CommandExecutor {
Player target = Bukkit.getPlayer(warkingUser.getUUID());
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;
}
} 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;
}
} else {
@ -458,10 +437,24 @@ public class SchematicCommand implements CommandExecutor {
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;
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++) {
if(schematicList.size() <= i) break;
@ -494,19 +487,34 @@ public class SchematicCommand implements CommandExecutor {
player.spigot().sendMessage(schematics);
}
if(pages < 1) return;
if(pages <= 1) return;
TextComponent nextPage = new TextComponent(">> Naechste Seite <<");
nextPage.setColor(ChatColor.RED);
if(currPage == 0) {
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) {
nextPage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem list " + 0));
} else
nextPage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem list " + (currentPage + 1)));
player.spigot().sendMessage(nextPage);
beforePage.addExtra(nextPage);
player.spigot().sendMessage(beforePage);
}
}
private boolean isSchematicNameAllowed(String schematicName) {