Search in sources :

Example 1 with SignLayoutConfig

use of de.dytanic.cloudnet.lib.serverselectors.sign.SignLayoutConfig in project CloudNet by Dytanic.

the class PacketInSignSelector method handleInput.

@Override
public void handleInput(Document data, PacketSender packetSender) {
    Map<UUID, Sign> signMap = data.getObject("signs", new TypeToken<Map<UUID, Sign>>() {
    }.getType());
    SignLayoutConfig signLayoutConfig = data.getObject("signLayoutConfig", new TypeToken<SignLayoutConfig>() {
    }.getType());
    Map<UUID, Sign> values = MapWrapper.filter(signMap, new Acceptable<Sign>() {

        @Override
        public boolean isAccepted(Sign value) {
            return value.getPosition().getGroup().equals(CloudAPI.getInstance().getGroup());
        }
    });
    Bukkit.getPluginManager().callEvent(new BukkitUpdateSignLayoutsEvent(signLayoutConfig));
    if (SignSelector.getInstance() != null) {
        SignSelector.getInstance().setSignLayoutConfig(signLayoutConfig);
        Collection<UUID> collection = new HashSet<>();
        for (Sign sign : SignSelector.getInstance().getSigns().values()) {
            if (!values.containsKey(sign.getUniqueId())) {
                collection.add(sign.getUniqueId());
            }
        }
        for (UUID x : collection) {
            SignSelector.getInstance().getSigns().remove(x);
        }
        for (Sign sign : values.values()) {
            if (!SignSelector.getInstance().getSigns().containsKey(sign.getUniqueId())) {
                SignSelector.getInstance().getSigns().put(sign.getUniqueId(), sign);
            }
        }
    } else {
        SignSelector signSelector = new SignSelector(values, signLayoutConfig);
        signSelector.start();
    }
}
Also used : SignLayoutConfig(de.dytanic.cloudnet.lib.serverselectors.sign.SignLayoutConfig) TypeToken(com.google.gson.reflect.TypeToken) SignSelector(de.dytanic.cloudnet.bridge.internal.serverselectors.SignSelector) BukkitUpdateSignLayoutsEvent(de.dytanic.cloudnet.bridge.event.bukkit.BukkitUpdateSignLayoutsEvent) Sign(de.dytanic.cloudnet.lib.serverselectors.sign.Sign) UUID(java.util.UUID) HashSet(java.util.HashSet)

Example 2 with SignLayoutConfig

use of de.dytanic.cloudnet.lib.serverselectors.sign.SignLayoutConfig in project CloudNet by Dytanic.

the class ConfigSignLayout method loadLayout.

public de.dytanic.cloudnet.lib.serverselectors.sign.SignLayoutConfig loadLayout() {
    Document document = Document.loadDocument(path);
    if (!document.getDocument("layout_config").contains("knockbackOnSmallDistance")) {
        Document document1 = document.getDocument("layout_config").append("knockbackOnSmallDistance", false);
        document.append("layout_config", document1);
        document.saveAsConfig(path);
    }
    if (!document.getDocument("layout_config").contains("distance")) {
        Document document1 = document.getDocument("layout_config").append("distance", 1D);
        document.append("layout_config", document1);
        document.saveAsConfig(path);
    }
    if (!document.getDocument("layout_config").contains("strength")) {
        Document document1 = document.getDocument("layout_config").append("strength", 0.8D);
        document.append("layout_config", document1);
        document.saveAsConfig(path);
    }
    SignLayoutConfig signLayoutConfig = document.getObject("layout_config", new TypeToken<de.dytanic.cloudnet.lib.serverselectors.sign.SignLayoutConfig>() {
    }.getType());
    boolean injectable = false;
    for (SignGroupLayouts groupLayouts : signLayoutConfig.getGroupLayouts()) {
        {
            SignLayout signLayout = CollectionWrapper.filter(groupLayouts.getLayouts(), new Acceptable<SignLayout>() {

                @Override
                public boolean isAccepted(SignLayout signLayout) {
                    return signLayout.getName().equalsIgnoreCase("empty");
                }
            });
            if (signLayout == null) {
                groupLayouts.getLayouts().add(new SignLayout("empty", new String[] { "%server%", "&6%state%", "%online_players%/%max_players%", "%motd%" }, 159, 1));
                injectable = true;
            }
        }
    }
    if (injectable) {
        document.append("layout_config", signLayoutConfig).saveAsConfig(path);
    }
    return signLayoutConfig;
}
Also used : SignLayout(de.dytanic.cloudnet.lib.serverselectors.sign.SignLayout) SignLayoutConfig(de.dytanic.cloudnet.lib.serverselectors.sign.SignLayoutConfig) TypeToken(com.google.gson.reflect.TypeToken) Acceptable(de.dytanic.cloudnet.lib.utility.Acceptable) SignGroupLayouts(de.dytanic.cloudnet.lib.serverselectors.sign.SignGroupLayouts) Document(de.dytanic.cloudnet.lib.utility.document.Document)

Aggregations

TypeToken (com.google.gson.reflect.TypeToken)2 SignLayoutConfig (de.dytanic.cloudnet.lib.serverselectors.sign.SignLayoutConfig)2 BukkitUpdateSignLayoutsEvent (de.dytanic.cloudnet.bridge.event.bukkit.BukkitUpdateSignLayoutsEvent)1 SignSelector (de.dytanic.cloudnet.bridge.internal.serverselectors.SignSelector)1 Sign (de.dytanic.cloudnet.lib.serverselectors.sign.Sign)1 SignGroupLayouts (de.dytanic.cloudnet.lib.serverselectors.sign.SignGroupLayouts)1 SignLayout (de.dytanic.cloudnet.lib.serverselectors.sign.SignLayout)1 Acceptable (de.dytanic.cloudnet.lib.utility.Acceptable)1 Document (de.dytanic.cloudnet.lib.utility.document.Document)1 HashSet (java.util.HashSet)1 UUID (java.util.UUID)1