13
0

Add Schemdownload

Dieser Commit ist enthalten in:
Chaoscaot 2021-01-07 17:40:14 +01:00
Ursprung bd679f0b0a
Commit 5c02275b4e
5 geänderte Dateien mit 170 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -43,10 +43,27 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>9</source>
<target>9</target>
</configuration>
</plugin>
</plugins>
<finalName>schematicsystem</finalName>
</build>
<repositories>
<repository>
<id>maven-restlet</id>
<name>Public online Restlet repository</name>
<url>http://maven.restlet.org</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>steamwar</groupId>
@ -73,5 +90,15 @@
<version>1.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.5.13</version>
</dependency>
</dependencies>
</project>

Datei anzeigen

@ -0,0 +1,107 @@
package de.steamwar.schematicsystem;
import de.steamwar.sql.Schematic;
import de.steamwar.sql.SchematicType;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.HttpClients;
import org.bukkit.entity.Player;
import java.io.InputStream;
import java.net.URL;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
public class ExternalUpDownload {
public static void downloadSchemsFromWGW(Player player, String pw) {
BasicCookieStore cookieStore = new BasicCookieStore();
HttpClient httpclient = HttpClients.custom().setDefaultCookieStore(cookieStore).build();
try {
//Login to WGW
HttpPost loginPost = new HttpPost("https://wargearworld.net/index.php");
MultipartEntity loginEntity = new MultipartEntity();
loginEntity.addPart("login-username", new StringBody(player.getName()));
loginEntity.addPart("login-password", new StringBody(pw));
loginEntity.addPart("send-login", new StringBody("login"));
loginPost.setEntity(loginEntity);
HttpResponse loginResponse = httpclient.execute(loginPost);
if(loginResponse.getStatusLine().getStatusCode() != 302) {
player.sendMessage(SchematicSystem.PREFIX + "§cLogin Fehlgeschlagen");
return;
}
//Prepare Schemdownload
HttpPost preparePost = new HttpPost("https://wargearworld.net/index.php");
MultipartEntity prepareEntity = new MultipartEntity();
prepareEntity.addPart("option", new StringBody("com_ajax"));
prepareEntity.addPart("module", new StringBody("account"));
prepareEntity.addPart("content", new StringBody("getDir"));
prepareEntity.addPart("data[dir]", new StringBody("/"));
prepareEntity.addPart("data[event]", new StringBody("download_all"));
prepareEntity.addPart("data[data]", new StringBody(""));
prepareEntity.addPart("format", new StringBody("raw"));
preparePost.setEntity(prepareEntity);
HttpResponse prepareResponse = httpclient.execute(preparePost);
InputStream content = prepareResponse.getEntity().getContent();
StringBuilder builder = new StringBuilder();
byte[] remover = new byte[67];
content.read(remover);
while (content.available() > 0) {
int readed = content.read();
if(readed == 46)
break;
builder.append((char) readed);
}
player.sendMessage(SchematicSystem.PREFIX + "§aDownload erstellt!");
player.sendMessage("§ahttps://wargearworld.net/images/temp/schematics/" + builder.toString() + ".zip");
//Process Schems
player.sendMessage(SchematicSystem.PREFIX + "§aSchematics werden verarbeitet!");
ZipInputStream zipInputStream = new ZipInputStream(new URL("https://wargearworld.net/images/temp/schematics/" + builder.toString() + ".zip").openStream());
while (true) {
ZipEntry schematic = zipInputStream.getNextEntry();
if(schematic == null)
break;
if(schematic.isDirectory())
continue;
String[] schemName = schematic.getName().split("\\.");
StringBuilder name = new StringBuilder();
for (int i = 0; i < schemName.length - 1; i++) {
if(!name.toString().equals(""))
name.append(".");
name.append(schemName[i].replace("/", "-"));
}
Schematic testSchem = Schematic.getSchemFromDB(name.toString(), player.getUniqueId());
byte[] schemData = zipInputStream.readAllBytes();
if(testSchem != null) {
int i = 1;
while (true) {
if(Schematic.getSchemFromDB(name.toString() + "-" + i, player.getUniqueId()) == null) {
name = new StringBuilder(name.toString() + "-" + i);
break;
}
i++;
}
}
Schematic.createSchem(name.toString(), player.getUniqueId(), "", SchematicType.Normal);
Schematic schem = Schematic.getSchemFromDB(name.toString(), player.getUniqueId());
schem.saveFromBytes(schemData, schemName[schemName.length - 1].equals("schem"));
zipInputStream.closeEntry();
player.sendMessage(SchematicSystem.PREFIX + "§6Die Schematic §e" + schematic.getName() + " §6wurde von WarGearWorld.net als §e" + name.toString() + " §6herruntergeladen!");
}
player.sendMessage(SchematicSystem.PREFIX + "§aAlle deine Schematics wurden von §6W§7ar§6G§7ear§6W§7orld.net §aauf §eSteam§8War §aHochgeladen!");
zipInputStream.close();
} catch (Exception e) {
player.sendMessage("Beidem Schemdownload ist ein Fehler passiert, Versuche es Später nochmal.");
throw new SecurityException(e);
} finally {
httpclient.getConnectionManager().shutdown();
}
}
}

Datei anzeigen

@ -20,6 +20,7 @@
package de.steamwar.schematicsystem;
import de.steamwar.core.CommandRemover;
import de.steamwar.schematicsystem.commands.SchemTransferCommand;
import de.steamwar.schematicsystem.commands.SchematicCommand;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
@ -31,6 +32,7 @@ import java.io.File;
public class SchematicSystem extends JavaPlugin {
public static final String PREFIX = "§eSchematic§8» §7";
public static SchematicSystem INSTANCE;
@Override
public void onEnable() {
@ -48,5 +50,7 @@ public class SchematicSystem extends JavaPlugin {
CommandRemover.removeAll("/schematic", "/schem", "//schematic", "//schem");
getCommand("schem").setExecutor(new SchematicCommand());
getCommand("schemtransfer").setExecutor(new SchemTransferCommand());
INSTANCE = this;
}
}

Datei anzeigen

@ -0,0 +1,30 @@
package de.steamwar.schematicsystem.commands;
import de.steamwar.schematicsystem.ExternalUpDownload;
import de.steamwar.schematicsystem.SchematicSystem;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class SchemTransferCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
if(commandSender instanceof Player) {
if(args.length < 1) {
Player p = (Player) commandSender;
p.sendMessage("§6W§7ar§6G§7ear§6W§7orld §6Schematictransfer");
p.sendMessage("§7Mit diesem Command kannst du deine Wargearworld schematics auf Steamwar Transferieren");
p.sendMessage("§8/§eschemtransfer [Dein Wargearworld Website Passwort]");
p.sendMessage("§4§lDISCLAIMER: §eDein Passwort wird in keinster von uns gespeichert, es wird nut für den Download der Schematics von Wargearworld.net verwendet und danach sofort wieder gelöcht!");
p.sendMessage("§eWenn du uns das nicht glaubst, kannst du es gerne hier https://steamwar.de/devlabs/SteamWar/SchematicSystem/src/branch/master/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchemTranferCommand.java nachlesen oder auch einen Developer fragen.");
} else {
Bukkit.getScheduler().runTaskAsynchronously(SchematicSystem.INSTANCE, () -> ExternalUpDownload.downloadSchemsFromWGW((Player) commandSender, args[0]));
}
}
return true;
}
}

Datei anzeigen

@ -11,4 +11,5 @@ commands:
- schematic
- /schematic
- /schem
check:
check:
schemtransfer: