13
0

first stable version

Signed-off-by: yaruma3341 <yaruma3341@gmail.com>
Dieser Commit ist enthalten in:
Yaruma3341 2019-04-04 21:09:30 +02:00 committet von yaruma3341
Ursprung a20b9fd2aa
Commit b23ee2dd59
2 geänderte Dateien mit 221 neuen und 54 gelöschten Zeilen

Datei anzeigen

@ -4,7 +4,6 @@ import com.boydti.fawe.FaweAPI;
import com.sk89q.worldedit.EmptyClipboardException;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter;
import com.sk89q.worldedit.session.ClipboardHolder;
import de.warking.hunjy.MySQL.Schematic;
import de.warking.hunjy.MySQL.SchematicMember;
@ -24,10 +23,17 @@ import org.bukkit.entity.Player;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
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) {
@ -50,22 +56,45 @@ public class SchematicCommand implements CommandExecutor {
if(args[0].equalsIgnoreCase("help")) {
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;
case 2:
if(args[0].equalsIgnoreCase("list")) {
try {
sendPlayerSchematicList(Integer.parseInt(args[1]), 15, player);
return false;
} catch (NumberFormatException ex) {
player.sendMessage(SchematicSystem.PREFIX + "§cDu musst eine Seitenzahl angeben!");
return false;
}
}
if(args[0].equalsIgnoreCase("load")) {
if(isSchematicNameAllowed(args[1])) {
if (Schematic.getSchemFromDB(args[1], player.getUniqueId()) != null) {
Schematic schematic = Schematic.getSchemFromDB(args[1], player.getUniqueId());
if (schematic != null) {
try {
Actor actor = SchematicSystem.getWorldEditPlugin().wrapCommandSender(player);
SchematicSystem.getWorldEditPlugin().getWorldEdit().getSessionManager().get(actor).setClipboard((ClipboardHolder) FaweAPI.load(new File(SchematicSystem.SCHEM_DIR + player.getUniqueId() + "/", args[1] + ".schematic")).getClipboard());
File file;
if(WarkingUser.get(schematic.getSchemOwner()).getUUID() != player.getUniqueId()) {
file = new File(SchematicSystem.SCHEM_DIR + WarkingUser.get(schematic.getSchemOwner()).getUUID() + "/", args[1] + ".schematic");
} else {
file = new File(SchematicSystem.SCHEM_DIR + player.getUniqueId() + "/", args[1] + ".schematic");
}
SchematicSystem.getWorldEditPlugin().getWorldEdit().getSessionManager().get(actor).setClipboard(new ClipboardHolder(FaweAPI.load(file).getClipboard(), FaweAPI.getWorld(player.getWorld().getName()).getWorldData()));
player.sendMessage(SchematicSystem.PREFIX + "Schematic §6" + args[1] + " §7geladen.");
} catch (IOException ex) {
ex.printStackTrace();
@ -86,11 +115,54 @@ public class SchematicCommand implements CommandExecutor {
if(isSchematicNameAllowed(args[1])) {
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 ja = new TextComponent("§6Moechtest du die Schematic wirklich loeschen? §aja ");
ja.setBold(true);
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"));
ja.addExtra(nein);
player.spigot().sendMessage(ja);
}
return false;
} else {
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!");
return false;
}
}
if(args[0].equalsIgnoreCase("savedelete")) {
if(isSchematicNameAllowed(args[1])) {
Schematic schematic = Schematic.getSchemFromDB(args[1], player.getUniqueId());
if(schematic != null) {
if(deletePlayers.contains(player.getUniqueId())) {
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;
}
}
} else {
player.sendMessage(SchematicSystem.PREFIX + "§cDiese Schematic existiert nicht!");
return false;
@ -105,22 +177,81 @@ public class SchematicCommand implements CommandExecutor {
if(isSchematicNameAllowed(args[1])) {
try {
if(FaweAPI.wrapPlayer(player).getSession().getClipboard().getClipboard() != null) {
if(Schematic.getSchemFromDB(args[1], player.getUniqueId()) != null) {
if(Schematic.getSchemFromDB(args[1], player.getUniqueId()).getSchemType() != SchematicType.normal) {
player.sendMessage(SchematicSystem.PREFIX + "§cDu darfst dieses Schematic Typ nicht überschreiben!");
return false;
} else {
Schematic.getSchemFromDB(args[1], player.getUniqueId()).remove();
}
}
if(Schematic.getSchemFromDB(args[1], player.getUniqueId()) != null)
Schematic.getSchemFromDB(args[1], player.getUniqueId()).remove();
File file = new File(SchematicSystem.SCHEM_DIR + player.getUniqueId() + "/" + args[1] + ".schematic");
File file = new File(SchematicSystem.SCHEM_DIR + player.getUniqueId().toString() + "/", args[1] + ".schematic");
file.createNewFile();
ClipboardWriter writer = ClipboardFormat.SCHEMATIC.getWriter(new FileOutputStream(file));
writer.write(FaweAPI.wrapPlayer(player).getSession().getClipboard().getClipboard(), FaweAPI.wrapPlayer(player).getSession().getClipboard().getWorldData());
Files.setPosixFilePermissions(file.toPath(),
EnumSet.of(PosixFilePermission.OWNER_READ,
PosixFilePermission.OWNER_WRITE,
PosixFilePermission.GROUP_READ,
PosixFilePermission.OTHERS_READ,
PosixFilePermission.OTHERS_WRITE));
ClipboardFormat.SCHEMATIC.getWriter(new FileOutputStream(file)).write(
FaweAPI.wrapPlayer(player).getSession().getClipboard().getClipboard(),
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!");
} catch (IOException ex) { ex.printStackTrace(); } catch (EmptyClipboardException ex) { ex.printStackTrace(); player.sendMessage(SchematicSystem.PREFIX + "§cBeim Speichern der Schematic ist ein Fehler aufgetreten!");}
player.sendMessage(SchematicSystem.PREFIX + "Schematic §6" + args[1] + " §7gespeichert!");
} else {
player.sendMessage(SchematicSystem.PREFIX + "§cDein Clipboard ist leer!");
return false;
}
} catch (IOException ex) { ex.printStackTrace(); } catch (EmptyClipboardException ex) { ex.printStackTrace(); }
} else {
player.sendMessage(SchematicSystem.PREFIX + "§cDer angegebene Schematic Name enthält verbotene Zeichen!");
return false;
}
}
if(args[0].equalsIgnoreCase("info")) {
if(isSchematicNameAllowed(args[1])) {
Schematic schematic = Schematic.getSchemFromDB(args[1], player.getUniqueId());
if(schematic != null) {
if(!WarkingUser.get(schematic.getSchemOwner()).getUUID().equals(player.getUniqueId())) {
player.sendMessage("§6Owner: §7" + WarkingUser.get(schematic.getSchemOwner()).getUserName());
} else {
List<String> schematicMembers = new ArrayList<>();
for(SchematicMember schematicMember : SchematicMember.getSchemMembers(schematic.getSchemName(), schematic.getSchemOwner())) {
schematicMembers.add(WarkingUser.get(schematicMember.getMember()).getUserName());
}
if(schematicMembers.size() <= 3) {
player.sendMessage("§6Member: §7" + schematicMembers.toString());
} else
player.sendMessage("§6Member: §7...");
}
TextComponent loadSchematic = new TextComponent("LADEN");
loadSchematic.setColor(ChatColor.DARK_GREEN);
loadSchematic.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem load " + schematic.getSchemName()));
player.spigot().sendMessage(loadSchematic);
if(WarkingUser.get(schematic.getSchemOwner()).getUUID().equals(player.getUniqueId())) {
TextComponent deleteSchematic = new TextComponent("LOESCHEN");
deleteSchematic.setColor(ChatColor.RED);
deleteSchematic.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem delete " + schematic.getSchemName()));
player.spigot().sendMessage(deleteSchematic);
}
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!");
return false;
@ -134,8 +265,8 @@ public class SchematicCommand implements CommandExecutor {
WarkingUser warkingUser = WarkingUser.get(args[2]);
if(warkingUser != null) {
if(isSchematicNameAllowed(args[1])) {
File file = new File(SchematicSystem.SCHEM_DIR + warkingUser.getUUID().toString() + "/" + args[1] + ".schematic");
if(file.exists()) {
Schematic schematic = Schematic.getSchemFromDB(args[1], warkingUser.getUUID());
if(schematic != null) {
try {
Actor actor = SchematicSystem.getWorldEditPlugin().wrapCommandSender(player);
SchematicSystem.getWorldEditPlugin().getWorldEdit().getSessionManager().get(actor).setClipboard((ClipboardHolder) FaweAPI.load(new File(SchematicSystem.SCHEM_DIR + warkingUser.getUUID().toString() + "/", args[1] + ".schematic")).getClipboard());
@ -179,7 +310,7 @@ public class SchematicCommand implements CommandExecutor {
if(args[2].equalsIgnoreCase("normal")) {
schematic.setSchemType(SchematicType.normal);
player.sendMessage(SchematicSystem.PREFIX + "§Schematic Type §6normal §7gesetzt!");
player.sendMessage(SchematicSystem.PREFIX + "Schematic Type §6normal §7gesetzt!");
return false;
}
} else {
@ -193,12 +324,17 @@ public class SchematicCommand implements CommandExecutor {
Schematic schematic = Schematic.getSchemFromDB(args[1], player.getUniqueId());
if(schematic != null) {
WarkingUser warkingUser = WarkingUser.get(args[2]);
if(warkingUser != null) {
if(warkingUser.getUUID() != null) {
if(schematic.getSchemOwner() != warkingUser.getId()) {
if(SchematicMember.getSchemMembers(schematic.getSchemName(), schematic.getSchemOwner()) != null) {
SchematicMember schematicMember = new SchematicMember(schematic.getSchemName(), player.getUniqueId(), warkingUser.getUUID());
SchematicMember schematicMember = new SchematicMember(schematic.getSchemName(), WarkingUser.get(schematic.getSchemOwner()).getUUID(), warkingUser.getUUID());
player.sendMessage(SchematicSystem.PREFIX + "Der Spieler §6" + warkingUser.getUserName() + " §7hat nun Zugriff auf die Schematic §6" + schematic.getSchemName() + "§7.");
return false;
} else {
player.sendMessage(SchematicSystem.PREFIX + "§cDieser Spieler ist bereits auf diese Schematic geaddet!");
return false;
}
} else {
player.sendMessage(SchematicSystem.PREFIX + "§cDu kannst dich nicht auf deine eigenen Schematics adden!");
@ -252,21 +388,21 @@ public class SchematicCommand implements CommandExecutor {
public void sendHelp(Player player) {
player.sendMessage(SchematicSystem.PREFIX + "Befehle:");
player.sendMessage("§8//schem - §6Zeigt Informationen zum Plugin");
player.sendMessage("§8//schem help - §6Zeigt eine Liste mit Befehlen");
player.sendMessage("§8//schem list - §6Listet deine Schematics auf");
player.sendMessage("§8//schem load <Name> [Besitzer] - §6Du lädst eine Schematic");
player.sendMessage("§8//schem save <Name> - §6Du speicherst dein Clipboard als Datei");
player.sendMessage("§8//schem changetype <Name> <airship/miniwargear/wargear/normal> - §6Ändert den Typ deiner Schematic");
//Vlt. später --> player.sendMessage("§8//schem info <Name> - §6Zeigt dir Informationen zu der Schematic");
player.sendMessage("§8//schem delete <Name> - §6Löscht eine Schematic");
player.sendMessage("§8//schem addmember <Schematic> <Spieler> - §6Fügt einen Spieler zu einer Schematic hinzu");
player.sendMessage("§8//schem delmember <Schematic> <Spieler> - §6Entfernt einen Spieler von einer Schematic");
player.sendMessage("§8/schem - §6Zeigt Informationen zum Plugin");
player.sendMessage("§8/schem help - §6Zeigt eine Liste mit Befehlen");
player.sendMessage("§8/schem list - §6Listet deine Schematics auf");
player.sendMessage("§8/schem load <Name> [Besitzer] - §6Du lädst eine Schematic");
player.sendMessage("§8/schem save <Name> - §6Du speicherst dein Clipboard als Datei");
//Kommt später --> player.sendMessage("§8/schem changetype <Name> <airship/miniwargear/wargear/normal> - §6Ändert den Typ deiner Schematic");
player.sendMessage("§8/schem info <Name> - §6Zeigt dir Informationen zu der Schematic");
player.sendMessage("§8/schem delete <Name> - §6Löscht eine Schematic");
player.sendMessage("§8/schem addmember <Schematic> <Spieler> - §6Fügt einen Spieler zu einer Schematic hinzu");
player.sendMessage("§8/schem delmember <Schematic> <Spieler> - §6Entfernt einen Spieler von einer Schematic");
if (player.hasPermission("bau.team")) {
player.sendMessage(SchematicSystem.PREFIX + "§cTeambefehle:");
player.sendMessage("§8//schem lock <Name> <Besitzer/Team> - §6Sperrt eine Schematic");
player.sendMessage("§8//schem unlock <Name> <Besitzer/Team> - §6Entsperrt eine Schematic");
player.sendMessage("§8/schem lock <Name> <Besitzer/Team> - §6Sperrt eine Schematic");
player.sendMessage("§8/schem unlock <Name> <Besitzer/Team> - §6Entsperrt eine Schematic");
}
}
@ -274,31 +410,58 @@ public class SchematicCommand implements CommandExecutor {
public static void sendPlayerSchematicList(int currentPage, int filesPerPage, Player player) {
List<Schematic> schematicList = Schematic.getSchemsAccessibleByUser(player.getUniqueId());
if(schematicList.isEmpty()) {
player.sendMessage(SchematicSystem.PREFIX + "§cDu hast noch keine Schematic(s)!");
return;
}
int pages = schematicList.size() / filesPerPage;
int currPage = currentPage;
if(currPage > pages) {
currPage = 0;
}
for(int i = currPage * filesPerPage; i < (currPage * filesPerPage) + filesPerPage; i++) {
if(schematicList.get(i) == null) return;
if(schematicList.size() <= i) break;
TextComponent schematics = new TextComponent(schematicList.get(i).getSchemName());
schematics.setColor(ChatColor.AQUA);
Schematic schematic = schematicList.get(i);
String schematicType = "";
if(schematic.getSchemType() == SchematicType.normal)
schematicType = "§7[§8---§7] ";
if(schematic.getSchemType() == SchematicType.airship)
schematicType = "§7[§8AS§7] ";
if(schematic.getSchemType() == SchematicType.miniwargear)
schematicType = "§7[§8MWG§7] ";
if(schematic.getSchemType() == SchematicType.wargear)
schematicType = "§7[§8WG§7] ";
if(schematic.getSchemType() == SchematicType.warship)
schematicType = "§7[§8WS§7] ";
String schematicPlayer;
if(!WarkingUser.get(schematic.getSchemOwner()).getUUID().equals(player.getUniqueId())) {
schematicPlayer = "§7[§aM§7] ";
} else
schematicPlayer = "§7[§cO§7] ";
TextComponent schematics = new TextComponent(schematicType + schematicPlayer + "§b" + schematic.getSchemName());
schematics.setBold(true);
schematics.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Schematic laden...").create()));
schematics.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "schematic load " + schematicList.get(i).getSchemName())); //COMMAND MISSING
schematics.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Schematic verwalten...").create()));
schematics.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem info " + schematic.getSchemName()));
player.spigot().sendMessage(schematics);
}
if(pages < 1) return;
TextComponent nextPage = new TextComponent(">> Naechste Seite <<");
nextPage.setColor(ChatColor.RED);
nextPage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Naechste Seite...").create()));
nextPage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "schematic list " + currentPage + 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);
}

Datei anzeigen

@ -17,9 +17,13 @@ public class PlayerJoinListener implements Listener {
Player player = event.getPlayer();
File file = new File(SchematicSystem.SCHEM_DIR + player.getUniqueId() + "/");
File[] files = file.listFiles();
if(files.length == 0) return;
for(int i = 0; i < files.length; i++) {
if(Schematic.getSchemFromDB(files[i].getName(), player.getUniqueId()) != null) {
Schematic schematic = new Schematic(files[i].getName(), player.getUniqueId(), "", SchematicType.normal);
if(Schematic.getSchemFromDB(files[i].getName(), player.getUniqueId()) == null) {
String fileName = files[i].getName();
Schematic schematic = new Schematic(fileName.substring(0, fileName.lastIndexOf(".")), player.getUniqueId(), "", SchematicType.normal);
}
}
}