added command blocker; Schematic Command (unfinished)
Signed-off-by: yaruma3341 <yaruma3341@gmail.com>
Dieser Commit ist enthalten in:
Ursprung
c4adab8881
Commit
ade7fb860e
@ -1,25 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
||||
<output url="file://$MODULE_DIR$/target/classes" />
|
||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.spigotmc:spigot-api:1.12.2-R0.1-SNAPSHOT" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-lang:commons-lang:2.6" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: junit:junit:4.10" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.guava:guava:21.0" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.gson:gson:2.8.0" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.yaml:snakeyaml:1.19" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: net.md-5:bungeecord-chat:1.12-SNAPSHOT" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: warking:SpigotCore:1.0" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: warking:WorldEdit:1.0" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: warking:FAWE:1.0" level="project" />
|
||||
</component>
|
||||
</module>
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
133
src/de/warking/schematicsystem/commands/SchematicCommand.java
Normale Datei
133
src/de/warking/schematicsystem/commands/SchematicCommand.java
Normale Datei
@ -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 <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");
|
||||
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("schemorg.help")) {
|
||||
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");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void sendPlayerScheamticList(int currentPage, int filesPerPage, Player player) {
|
||||
List<Schematic> 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);
|
||||
}
|
||||
}
|
37
src/de/warking/schematicsystem/utils/CommandRemover.java
Normale Datei
37
src/de/warking/schematicsystem/utils/CommandRemover.java
Normale Datei
@ -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<String, Command> knownCommands = (Map<String, Command>) f2.get(commandMap);
|
||||
|
||||
return knownCommands.remove(command.toLowerCase()) != null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
name: SchematicSystem
|
||||
version: 1.0
|
||||
author: [Yaruma3341, Lixfel]
|
||||
|
||||
main: de.warking.schematicsystem.SchematicSystem
|
In neuem Issue referenzieren
Einen Benutzer sperren