13
0

added config and made it more modular; hotfixes

Signed-off-by: yaruma3341 <yaruma3341@gmail.com>
Dieser Commit ist enthalten in:
Yaruma3341 2019-04-20 18:09:46 +02:00 committet von yaruma3341
Ursprung 8ac792f0b8
Commit e5fdc2a047
5 geänderte Dateien mit 212 neuen und 3 gelöschten Zeilen

29
src/config.yml Normale Datei
Datei anzeigen

@ -0,0 +1,29 @@
Schematics:
WarGear:
Breite:
Höhe:
Tiefe:
Obsidian:
Bedrock:
ForbiddenIds:
MiniWarGear:
Breite:
Höhe:
Tiefe:
Obsidian:
Bedrock:
ForbiddenIds:
WarShip:
Breite:
Höhe:
Tiefe:
Obsidian:
Bedrock:
ForbiddenIds:
AirShip:
Breite:
Höhe:
Tiefe:
Obsidian:
Bedrock:
ForbiddenIds:

Datei anzeigen

@ -4,6 +4,7 @@ import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import de.warking.schematicsystem.commands.SchematicCommand; import de.warking.schematicsystem.commands.SchematicCommand;
import de.warking.schematicsystem.listener.PlayerJoinListener; import de.warking.schematicsystem.listener.PlayerJoinListener;
import de.warking.schematicsystem.utils.CommandRemover; import de.warking.schematicsystem.utils.CommandRemover;
import de.warking.schematicsystem.utils.Config;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@ -18,6 +19,8 @@ public class SchematicSystem extends JavaPlugin {
public void onEnable() { public void onEnable() {
instance = this; instance = this;
Config.load();
try { try {
CommandRemover.removeAll("/schematic", "/schem", "//schematic", "//schem"); CommandRemover.removeAll("/schematic", "/schem", "//schematic", "//schem");
} catch (Exception ex) { } catch (Exception ex) {

Datei anzeigen

@ -2,20 +2,27 @@ package de.warking.schematicsystem.commands;
import com.boydti.fawe.FaweAPI; import com.boydti.fawe.FaweAPI;
import com.sk89q.worldedit.EmptyClipboardException; import com.sk89q.worldedit.EmptyClipboardException;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.session.ClipboardHolder;
import de.warking.hunjy.MySQL.Schematic; import de.warking.hunjy.MySQL.Schematic;
import de.warking.hunjy.MySQL.SchematicMember; import de.warking.hunjy.MySQL.SchematicMember;
import de.warking.hunjy.MySQL.SchematicType; import de.warking.hunjy.MySQL.SchematicType;
import de.warking.hunjy.MySQL.WarkingUser; import de.warking.hunjy.MySQL.WarkingUser;
import de.warking.schematicsystem.SchematicSystem; import de.warking.schematicsystem.SchematicSystem;
import de.warking.schematicsystem.utils.Config;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -281,19 +288,45 @@ public class SchematicCommand implements CommandExecutor {
if(args[0].equalsIgnoreCase("changetype")) { if(args[0].equalsIgnoreCase("changetype")) {
Schematic schematic = Schematic.getSchemFromDB(args[1], player.getUniqueId()); Schematic schematic = Schematic.getSchemFromDB(args[1], player.getUniqueId());
if(schematic != null) { if(schematic != null) {
Clipboard clipboard;
try {
clipboard = FaweAPI.load(new File(SchematicSystem.SCHEM_DIR + player.getUniqueId() + "/" + args[1] + ".schematic")).getClipboard();
} catch (IOException ex) {
player.sendMessage(SchematicSystem.PREFIX + "§cBeim Ausführen des Commands ist ein Fehler aufgetreten!");
return false;
}
Vector origin = clipboard.getOrigin();
Vector dimensions = clipboard.getDimensions();
if(args[2].equalsIgnoreCase("airship")) { if(args[2].equalsIgnoreCase("airship")) {
if(dimensions.getBlockX() <= Config.AirShipBreite && dimensions.getBlockY() <= Config.AirShipHöhe && dimensions.getBlockZ() <= Config.AirShipTiefe && checkSchematic(clipboard, Config.AirShipForbiddenIds, true, true, "AirShip")) {
schematic.setSchemType(SchematicType.airship);
player.sendMessage(SchematicSystem.PREFIX + "Schematic Type §6airship §7angefordert!");
}
return false; return false;
} }
if(args[2].equalsIgnoreCase("miniwargear")) { if(args[2].equalsIgnoreCase("miniwargear")) {
if(dimensions.getBlockX() <= Config.MiniWarGearBreite && dimensions.getBlockY() <= Config.MiniWarGearHöhe && dimensions.getBlockZ() <= Config.MiniWarGearTiefe && checkSchematic(clipboard, Config.MiniWarGearForbiddenIds, true, true, "MiniWarGear")) {
schematic.setSchemType(SchematicType.miniwargear);
player.sendMessage(SchematicSystem.PREFIX + "Schematic Type §6miniwargear §7angefordert!");
}
return false; return false;
} }
if(args[2].equalsIgnoreCase("wargear")) { if(args[2].equalsIgnoreCase("wargear")) {
if(dimensions.getBlockX() <= Config.WarGearBreite && dimensions.getBlockY() <= Config.WarGearHöhe && dimensions.getBlockZ() <= Config.WarGearTiefe && checkSchematic(clipboard, Config.WarGearForbiddenIds, true, true, "WarGear")) {
schematic.setSchemType(SchematicType.wargear);
player.sendMessage(SchematicSystem.PREFIX + "Schematic Type §6wargear §7angefordert!");
}
return false; return false;
} }
if(args[2].equalsIgnoreCase("warships")) { if(args[2].equalsIgnoreCase("warship")) {
if(dimensions.getBlockX() <= Config.WarShipBreite && dimensions.getBlockY() <= Config.WarShipHöhe && dimensions.getBlockZ() <= Config.WarShipTiefe && checkSchematic(clipboard, Config.WarShipForbiddenIds, true, true, "WarShip")) {
schematic.setSchemType(SchematicType.warship);
player.sendMessage(SchematicSystem.PREFIX + "Schematic Type §6warship §7angefordert!");
}
return false; return false;
} }
@ -415,7 +448,7 @@ public class SchematicCommand implements CommandExecutor {
player.sendMessage("§8/schem list - §6Listet deine Schematics auf"); 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 load <Name> [Besitzer] - §6Du lädst eine Schematic");
player.sendMessage("§8/schem save <Name> - §6Du speicherst dein Clipboard als Datei"); 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 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 info <Name> - §6Zeigt dir Informationen zu der Schematic");
player.sendMessage("§8/schem delete <Name> - §6Löscht eine 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 addmember <Schematic> <Spieler> - §6Fügt einen Spieler zu einer Schematic hinzu");
@ -530,4 +563,62 @@ public class SchematicCommand implements CommandExecutor {
} else } else
return true; return true;
} }
private boolean checkSchematic(Clipboard clipboard, List<Integer> forbiddenBlocks, boolean obsidianToTnt, boolean slimeToBedrock, String modus) {
Region region = clipboard.getRegion();
Vector min = region.getMinimumPoint();
Vector max = region.getMaximumPoint();
int obsidian = 0;
int bedrock = 0;
for (int x = min.getBlockX(); x <= max.getBlockX(); x++) {
for (int y = min.getBlockY(); y <= max.getBlockY(); y++) {
for (int z = min.getBlockZ(); z <= max.getBlockZ(); z++) {
Vector vector = new Vector(x, y, z);
if (forbiddenBlocks.contains(clipboard.getBlock(vector).getId())) {
return false;
}
try {
if(obsidianToTnt && clipboard.getBlock(vector).getId() == 46) {
clipboard.setBlock(vector, new BaseBlock(49));
obsidian++;
}
if(slimeToBedrock && clipboard.getBlock(vector).getId() == 165) {
clipboard.setBlock(vector, new BaseBlock(7));
bedrock++;
}
} catch (WorldEditException ex) {
return false;
}
}
}
}
if(modus.equalsIgnoreCase("WarGear")) {
if(Config.WarGearMaxObsidian < obsidian)
return false;
if(Config.WarGearMaxBedrock < bedrock)
return false;
}
if(modus.equalsIgnoreCase("MiniWarGear")) {
if(Config.MiniWarGearMaxObsidian < obsidian)
return false;
if(Config.MiniWarGearMaxBedrock < bedrock)
return false;
}
if(modus.equalsIgnoreCase("WarShip")) {
if(Config.WarShipMaxObsidian < obsidian)
return false;
if(Config.MiniWarGearMaxBedrock < bedrock)
return false;
}
if(modus.equalsIgnoreCase("AirShip")) {
if(Config.AirShipMaxObsidian < obsidian)
return false;
if(Config.MiniWarGearMaxBedrock < bedrock)
return false;
}
return true;
}
} }

Datei anzeigen

@ -2,6 +2,7 @@ package de.warking.schematicsystem.listener;
import de.warking.hunjy.MySQL.Schematic; import de.warking.hunjy.MySQL.Schematic;
import de.warking.hunjy.MySQL.SchematicType; import de.warking.hunjy.MySQL.SchematicType;
import de.warking.hunjy.MySQL.WarkingUser;
import de.warking.schematicsystem.SchematicSystem; import de.warking.schematicsystem.SchematicSystem;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -9,6 +10,8 @@ import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import java.io.File; import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class PlayerJoinListener implements Listener { public class PlayerJoinListener implements Listener {
@ -19,9 +22,17 @@ public class PlayerJoinListener implements Listener {
File[] files = file.listFiles(); File[] files = file.listFiles();
if(files == null || files.length == 0) return; if(files == null || files.length == 0) return;
List<Schematic> schematics = Schematic.getSchemsAccessibleByUser(player.getUniqueId());
List<String> schematicNames = new ArrayList<>();
for(Schematic schematic : schematics) {
if(schematic.getSchemOwner() == WarkingUser.get(player.getUniqueId()).getId()) {
schematicNames.add(schematic.getSchemName());
}
}
for(int i = 0; i < files.length; i++) { for(int i = 0; i < files.length; i++) {
if(Schematic.getSchemFromDB(files[i].getName().substring(0, files[i].getName().lastIndexOf(".")), player.getUniqueId()) == null) { if(!schematicNames.contains(files[i].getName().substring(0, files[i].getName().lastIndexOf(".")))) {
String fileName = files[i].getName(); String fileName = files[i].getName();
Schematic schematic = new Schematic(fileName.substring(0, fileName.lastIndexOf(".")), player.getUniqueId(), "", SchematicType.normal); Schematic schematic = new Schematic(fileName.substring(0, fileName.lastIndexOf(".")), player.getUniqueId(), "", SchematicType.normal);
} }

Datei anzeigen

@ -0,0 +1,75 @@
package de.warking.schematicsystem.utils;
import de.warking.schematicsystem.SchematicSystem;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import java.io.File;
import java.util.List;
public class Config {
public static double WarGearBreite;
public static double WarGearHöhe;
public static double WarGearTiefe;
public static int WarGearMaxObsidian;
public static int WarGearMaxBedrock;
public static List<Integer> WarGearForbiddenIds;
public static double MiniWarGearBreite;
public static double MiniWarGearHöhe;
public static double MiniWarGearTiefe;
public static int MiniWarGearMaxObsidian;
public static int MiniWarGearMaxBedrock;
public static List<Integer> MiniWarGearForbiddenIds;
public static double WarShipBreite;
public static double WarShipHöhe;
public static double WarShipTiefe;
public static int WarShipMaxObsidian;
public static int WarShipMaxBedrock;
public static List<Integer> WarShipForbiddenIds;
public static double AirShipBreite;
public static double AirShipHöhe;
public static double AirShipTiefe;
public static int AirShipMaxObsidian;
public static int AirShipMaxBedrock;
public static List<Integer> AirShipForbiddenIds;
public static void load() {
if (!new File("plugins/" + SchematicSystem.getInstance().getName() + "/config.yml").exists()) {
SchematicSystem.getInstance().saveDefaultConfig();
System.out.println(SchematicSystem.PREFIX + "config.yml erstellt und geladen!");
Bukkit.shutdown();
}
FileConfiguration config = SchematicSystem.getInstance().getConfig();
WarGearBreite = config.getDouble("Schematics.WarGear.Breite");
WarGearHöhe = config.getDouble("Schematics.WarGear.Höhe");
WarGearTiefe = config.getDouble("Schematics.WarGear.Tiefe");
WarGearMaxObsidian = config.getInt("Schematics.WarGear.Obsidian");
WarGearMaxBedrock = config.getInt("Schematics.WarGear.Bedrock");
WarGearForbiddenIds = config.getIntegerList("Schematics.WarGear.ForbiddenIds");
MiniWarGearBreite = config.getDouble("Schematics.MiniWarGear.Breite");
MiniWarGearHöhe = config.getDouble("Schematics.MiniWarGear.Höhe");
MiniWarGearTiefe = config.getDouble("Schematics.MiniWarGear.Tiefe");
MiniWarGearMaxObsidian = config.getInt("Schematics.MiniWarGear.Obsidian");
MiniWarGearForbiddenIds = config.getIntegerList("Schematics.MiniWarGear.Bedrock");
WarShipBreite = config.getDouble("Schematics.WarShip.Breite");
WarShipHöhe = config.getDouble("Schematics.WarShip.Höhe");
WarShipTiefe = config.getDouble("Schematics.WarShip.Tiefe");
WarShipMaxObsidian = config.getInt("Schematics.WarShip.Obsidian");
WarShipMaxBedrock = config.getInt("Schematics.WarShip.Bedrock");
WarShipForbiddenIds = config.getIntegerList("Schematics.WarShip.ForbiddenIds");
AirShipBreite = config.getDouble("Schematics.AirShip.Breite");
AirShipHöhe = config.getDouble("Schematics.AirShip.Höhe");
AirShipTiefe = config.getDouble("Schematics.AirShip.Tiefe");
AirShipMaxObsidian = config.getInt("Schematics.AirShip.Obsidian");
AirShipMaxBedrock = config.getInt("Schematics.AirShip.Bedrock");
AirShipForbiddenIds = config.getIntegerList("Schematics.AirShip.ForbiddenIds");
}
}