Search in sources :

Example 1 with BukkitUpdateSignLayoutsEvent

use of de.dytanic.cloudnet.bridge.event.bukkit.BukkitUpdateSignLayoutsEvent 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)

Aggregations

TypeToken (com.google.gson.reflect.TypeToken)1 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 SignLayoutConfig (de.dytanic.cloudnet.lib.serverselectors.sign.SignLayoutConfig)1 HashSet (java.util.HashSet)1 UUID (java.util.UUID)1