Search in sources :

Example 66 with Document

use of de.dytanic.cloudnet.lib.utility.document.Document in project CloudNet by Dytanic.

the class MobDatabase method loadAll.

public Map<UUID, ServerMob> loadAll() {
    boolean injectable = false;
    Map<UUID, ServerMob> mobMap = database.getDocument("server_selector_mobs").getObject("mobs", new TypeToken<Map<UUID, ServerMob>>() {
    }.getType());
    for (ServerMob serverMob : mobMap.values()) {
        if (serverMob.getItemId() == null) {
            serverMob.setItemId(138);
            injectable = true;
        }
        if (serverMob.getAutoJoin() == null) {
            serverMob.setAutoJoin(false);
            injectable = true;
        }
    }
    if (injectable) {
        Document document = database.getDocument("server_selector_mobs");
        document.append("mobs", mobMap);
        database.insert(document);
    }
    return mobMap;
}
Also used : ServerMob(de.dytanic.cloudnet.lib.serverselectors.mob.ServerMob) TypeToken(com.google.gson.reflect.TypeToken) UUID(java.util.UUID) Document(de.dytanic.cloudnet.lib.utility.document.Document) DatabaseDocument(de.dytanic.cloudnet.lib.database.DatabaseDocument)

Example 67 with Document

use of de.dytanic.cloudnet.lib.utility.document.Document in project CloudNet by Dytanic.

the class DocumentTest method reserve.

@Test
public void reserve() {
    Document document = new Document().append("wdfqwaef", UUID.randomUUID());
    System.out.println(document.getObject("wdfqwaef", UUID.class));
}
Also used : Document(de.dytanic.cloudnet.lib.utility.document.Document) UUID(java.util.UUID) Test(org.junit.Test)

Example 68 with Document

use of de.dytanic.cloudnet.lib.utility.document.Document in project CloudNet by Dytanic.

the class MasterTemplateLoader method load.

public MasterTemplateLoader load() {
    try {
        HttpURLConnection urlConnection = (HttpURLConnection) new URL(url).openConnection();
        urlConnection.setRequestMethod("GET");
        urlConnection.setRequestProperty("-Xcloudnet-user", simpledUser.getUserName());
        urlConnection.setRequestProperty("-Xcloudnet-token", simpledUser.getApiToken());
        urlConnection.setRequestProperty("-Xmessage", customName != null ? "custom" : "template");
        urlConnection.setRequestProperty("-Xvalue", customName != null ? customName : new Document("template", template.getName()).append("group", group).convertToJsonString());
        urlConnection.setUseCaches(false);
        urlConnection.connect();
        if (urlConnection.getHeaderField("-Xresponse") == null)
            Files.copy(urlConnection.getInputStream(), Paths.get(dest));
        urlConnection.disconnect();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return this;
}
Also used : HttpURLConnection(java.net.HttpURLConnection) IOException(java.io.IOException) Document(de.dytanic.cloudnet.lib.utility.document.Document) URL(java.net.URL)

Example 69 with Document

use of de.dytanic.cloudnet.lib.utility.document.Document in project CloudNet by Dytanic.

the class PacketManager method sendQuery.

public Result sendQuery(Packet packet, PacketSender packetSender) {
    UUID uniq = UUID.randomUUID();
    packet.uniqueId = uniq;
    Value<Result> handled = new Value<>(null);
    synchronizedHandlers.put(uniq, handled);
    executorService.execute(new Runnable() {

        @Override
        public void run() {
            packetSender.sendPacket(packet);
        }
    });
    short i = 0;
    while (synchronizedHandlers.get(uniq).getValue() == null && i++ < 5000) {
        try {
            Thread.sleep(0, 300000);
        } catch (InterruptedException e) {
        }
    }
    if (i >= 200) {
        synchronizedHandlers.get(uniq).setValue(new Result(uniq, new Document()));
    }
    Value<Result> values = synchronizedHandlers.get(uniq);
    synchronizedHandlers.remove(uniq);
    return values.getValue();
}
Also used : Value(de.dytanic.cloudnet.lib.Value) Document(de.dytanic.cloudnet.lib.utility.document.Document) Result(de.dytanic.cloudnet.lib.network.protocol.packet.result.Result)

Aggregations

Document (de.dytanic.cloudnet.lib.utility.document.Document)69 DatabaseDocument (de.dytanic.cloudnet.lib.database.DatabaseDocument)26 TypeToken (com.google.gson.reflect.TypeToken)7 ArrayList (java.util.ArrayList)7 File (java.io.File)6 UUID (java.util.UUID)6 OfflinePlayer (de.dytanic.cloudnet.lib.player.OfflinePlayer)5 ServerGroup (de.dytanic.cloudnet.lib.server.ServerGroup)5 ServerConfig (de.dytanic.cloudnet.lib.server.ServerConfig)4 ServerInfo (de.dytanic.cloudnet.lib.server.info.ServerInfo)4 HttpURLConnection (java.net.HttpURLConnection)4 URL (java.net.URL)4 ConnectableAddress (de.dytanic.cloudnet.lib.ConnectableAddress)3 CloudPlayer (de.dytanic.cloudnet.lib.player.CloudPlayer)3 Template (de.dytanic.cloudnet.lib.server.template.Template)3 ServerInstallablePlugin (de.dytanic.cloudnet.lib.service.plugin.ServerInstallablePlugin)3 SimpledUser (de.dytanic.cloudnet.lib.user.SimpledUser)3 Acceptable (de.dytanic.cloudnet.lib.utility.Acceptable)3 MinecraftServer (de.dytanic.cloudnetcore.network.components.MinecraftServer)3 IOException (java.io.IOException)3