diff --git a/schematicsystem.iml b/schematicsystem.iml deleted file mode 100644 index 73f0348..0000000 --- a/schematicsystem.iml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/de/warking/schematicsystem/SchematicSystem.java b/src/de/warking/schematicsystem/SchematicSystem.java index 70f8d5a..8ce60fb 100644 --- a/src/de/warking/schematicsystem/SchematicSystem.java +++ b/src/de/warking/schematicsystem/SchematicSystem.java @@ -1,4 +1,43 @@ package de.warking.schematicsystem; -public class SchematicSystem { +import com.sk89q.worldedit.bukkit.WorldEditPlugin; +import de.warking.schematicsystem.commands.SchematicCommand; +import de.warking.schematicsystem.utils.CommandRemover; +import org.bukkit.Bukkit; +import org.bukkit.plugin.java.JavaPlugin; + +public class SchematicSystem extends JavaPlugin { + + public static String SCHEM_DIR = "/home/netuser/schematics/"; + public static String PREFIX = "§8[§3Schematic§8] §7"; + + private static SchematicSystem instance; + + public void onEnable() { + instance = this; + + try { + CommandRemover.removeAll("/schematic", "/schem", "//schematic", "//schem"); + } catch (Exception ex) { + ex.printStackTrace(); + } + + getCommand("schematic").setExecutor(new SchematicCommand()); + getCommand("/schematic").setExecutor(new SchematicCommand()); + getCommand("schem").setExecutor(new SchematicCommand()); + getCommand("/schem").setExecutor(new SchematicCommand()); + } + + public void onDisable() { + + } + + + public static SchematicSystem getInstance() { + return instance; + } + + public static WorldEditPlugin getWorldEditPlugin() { + return (WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit"); + } } diff --git a/src/de/warking/schematicsystem/commands/SchematicCommand.java b/src/de/warking/schematicsystem/commands/SchematicCommand.java new file mode 100644 index 0000000..30aa68e --- /dev/null +++ b/src/de/warking/schematicsystem/commands/SchematicCommand.java @@ -0,0 +1,133 @@ +package de.warking.schematicsystem.commands; + +import com.boydti.fawe.FaweAPI; +import com.sk89q.worldedit.session.ClipboardHolder; +import de.warking.hunjy.MySQL.Schematic; +import de.warking.schematicsystem.SchematicSystem; +import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.ComponentBuilder; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.TextComponent; +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.List; + +public class SchematicCommand implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + + if(!(sender instanceof Player)) { + return false; + } + + Player player = (Player) sender; + + switch (args.length) { + case 0: + sendHelp(player); + break; + + case 1: + if(args[0].equalsIgnoreCase("list")) { + sendPlayerScheamticList(0, 15, player); + break; + } + break; + + case 2: + if(args[0].equalsIgnoreCase("list")) { + sendPlayerScheamticList(Integer.parseInt(args[1]), 15, player); + return false; + } + + if(args[0].equalsIgnoreCase("load")) { + if(Schematic.getSchemFromDB(args[1], player.getUniqueId()) != null) { + //load schematic to player clipboard + + try { + SchematicSystem.getWorldEditPlugin().getSession(player).setClipboard((ClipboardHolder) FaweAPI.load(new File(SchematicSystem.PREFIX + args[1])).getClipboard()); + player.sendMessage(SchematicSystem.PREFIX + "Schematic §6" + args[1] + " §7geladen."); + } catch (IOException ex) { + ex.printStackTrace(); + } + + break; + } else { + player.sendMessage(SchematicSystem.PREFIX + "§cDie angegebene Schematic existiert nicht!"); + break; + } + } + + if(args[0].equalsIgnoreCase("delete")) { + File file = new File(SchematicSystem.SCHEM_DIR + args[1] + ".schematic"); + file.delete(); + player.sendMessage(SchematicSystem.PREFIX + "Schematic §6" + args[1] + "§7gelöscht."); + break; + } + + if(args[0].equalsIgnoreCase("save")) { + //save schematic + } + break; + } + return false; + } + + 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 [Besitzer] - §6Du lädst eine Schematic"); + player.sendMessage("§8//schem save - §6Du speicherst dein Clipboard als Datei"); + player.sendMessage("§8//schem changetype - §6Ändert den Typ deiner Schematic"); + player.sendMessage("§8//schem info - §6Zeigt dir Informationen zu der Schematic"); + player.sendMessage("§8//schem delete - §6Löscht eine Schematic"); + 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 (player.hasPermission("schemorg.help")) { + player.sendMessage(SchematicSystem.PREFIX + "§cTeambefehle:"); + player.sendMessage("§8//schem lock - §6Sperrt eine Schematic"); + player.sendMessage("§8//schem unlock - §6Entsperrt eine Schematic"); + } + + } + + public static void sendPlayerScheamticList(int currentPage, int filesPerPage, Player player) { + List schematicList = Schematic.getSchemsAccessibleByUser(player.getUniqueId()); + + int pages = schematicList.size() / filesPerPage; + int currPage = currentPage; + if(currPage > pages) { + currPage = 0; + } + + for(int i = currPage * filesPerPage; i < (currPage * filesPerPage) + filesPerPage; i++) { + + TextComponent schematics = new TextComponent(schematicList.get(i).getSchemName()); + schematics.setColor(ChatColor.AQUA); + 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 + + player.spigot().sendMessage(schematics); + } + + 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)); //COMMAND MISSING + + player.spigot().sendMessage(nextPage); + } +} diff --git a/src/de/warking/schematicsystem/utils/CommandRemover.java b/src/de/warking/schematicsystem/utils/CommandRemover.java new file mode 100644 index 0000000..11dca31 --- /dev/null +++ b/src/de/warking/schematicsystem/utils/CommandRemover.java @@ -0,0 +1,37 @@ +package de.warking.schematicsystem.utils; + +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.SimpleCommandMap; + +import java.lang.reflect.Field; +import java.util.Map; + +public class CommandRemover { + + private static String packageName = Bukkit.getServer().getClass().getPackage().getName(); + private static String version = packageName.substring(packageName.lastIndexOf(".") + 1); + + public static void removeAll(String... cmds) throws Exception { + for (int i = 0; i < cmds.length; i++) + removeCommand(cmds[i]); + } + + + public static boolean removeCommand(String command) throws Exception { + Class serverClass = Class.forName("org.bukkit.craftbukkit." + version + ".CraftServer"); + + Field f1 = serverClass.getDeclaredField("commandMap"); + f1.setAccessible(true); + SimpleCommandMap commandMap = (SimpleCommandMap) f1.get(Bukkit.getServer()); + + Field f2 = SimpleCommandMap.class.getDeclaredField("knownCommands"); + f2.setAccessible(true); + Map knownCommands = (Map) f2.get(commandMap); + + return knownCommands.remove(command.toLowerCase()) != null; + } + + + +} diff --git a/src/plugin.yml b/src/plugin.yml index e69de29..189aae7 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -0,0 +1,5 @@ +name: SchematicSystem +version: 1.0 +author: [Yaruma3341, Lixfel] + +main: de.warking.schematicsystem.SchematicSystem \ No newline at end of file