Search in sources :

Example 1 with GriefDefender

use of com.griefdefender.api.GriefDefender in project Almura by AlmuraDev.

the class ServerClaimManager method sendUpdateTo.

public void sendUpdateTo(final Player player, Claim claim, List<UUID> players, final boolean everyone, final String reason) {
    if (!Sponge.getPluginManager().isLoaded("griefdefender")) {
        // Check here to see if its loaded because in the deobfuscated environment I force load the ClaimManager classes for testing purposes.
        return;
    }
    if ((player == null && players == null && !everyone) || (player == null && (players != null && players.isEmpty()) && !everyone)) {
        if (debug) {
            System.out.println("Claim sendUpdateTo canceled because no players listed and everyone was false, reason: " + reason);
        }
        return;
    }
    if (claim != null && debug)
        System.out.println("Claim sendUpdateTo: [" + reason + "] everyone: [" + everyone + "] name: [" + claim.getDisplayName() + "] owner: [" + claim.getOwnerName() + "] wilderness: [" + claim.isWilderness() + "]");
    // Lookup claim where player or players is standing
    if (claim == null) {
        if (player != null) {
            claim = GriefDefender.getCore().getClaimManager(player.getWorld().getUniqueId()).getClaimAt(player.getLocation().getPosition().toInt());
        }
        if (players != null) {
            for (UUID playerUUID : players) {
                final Player finalPlayer = (Player) FMLServerHandler.instance().getServer().getPlayerList().getPlayerByUUID(playerUUID);
                if (finalPlayer != null) {
                    Task.builder().delayTicks(10).execute(t -> this.sendUpdate(finalPlayer, null)).submit(this.container);
                }
            }
        }
    }
    // Send to specific player
    if (!everyone && player != null && claim != null) {
        final Claim finalClaim = claim;
        Task.builder().delayTicks(10).execute(t -> this.sendUpdate(player, finalClaim)).submit(this.container);
        return;
    }
    // Send to everyone regardless of implied list from events.
    if (everyone && player == null && claim != null) {
        final Claim finalClaim = claim;
        for (Player onlinePlayer : Sponge.getServer().getOnlinePlayers()) {
            Task.builder().delayTicks(10).execute(t -> this.sendUpdate(onlinePlayer, finalClaim)).submit(this.container);
        }
        return;
    }
    // Send to the implied list of players when claim is handed into the method.
    if (players != null && claim != null) {
        final Claim finalClaim = claim;
        for (UUID playerUUID : players) {
            final Player finalPlayer = (Player) FMLServerHandler.instance().getServer().getPlayerList().getPlayerByUUID(playerUUID);
            if (finalPlayer != null) {
                Task.builder().delayTicks(10).execute(t -> this.sendUpdate(finalPlayer, finalClaim)).submit(this.container);
            }
        }
        return;
    }
    // Send update to everyone on server regardless of location or claim
    if (player == null && players == null && claim == null && everyone) {
        for (final Player onlinePlayer : Sponge.getServer().getOnlinePlayers()) {
            if (onlinePlayer != null && onlinePlayer.getWorld() != null) {
                claim = GriefDefender.getCore().getClaimManager(onlinePlayer.getWorld().getUniqueId()).getClaimAt(onlinePlayer.getLocation().getPosition().toInt());
                if (claim != null) {
                    final Claim finalClaim = claim;
                    Task.builder().delayTicks(10).execute(t -> this.sendUpdate(onlinePlayer, finalClaim)).submit(this.container);
                }
            }
        }
        return;
    }
}
Also used : Almura(com.almuradev.almura.Almura) Getter(org.spongepowered.api.event.filter.Getter) SpongeImplHooks(org.spongepowered.common.SpongeImplHooks) FMLServerHandler(net.minecraftforge.fml.server.FMLServerHandler) PlayerData(com.griefdefender.api.data.PlayerData) Singleton(javax.inject.Singleton) ClientboundClaimGuiResponsePacket(com.almuradev.almura.feature.claim.network.ClientboundClaimGuiResponsePacket) Currency(org.spongepowered.api.service.economy.Currency) Inject(javax.inject.Inject) Text(org.spongepowered.api.text.Text) com.griefdefender.api.event(com.griefdefender.api.event) Order(org.spongepowered.api.event.Order) Component(net.kyori.adventure.text.Component) Task(org.spongepowered.api.scheduler.Task) PluginContainer(org.spongepowered.api.plugin.PluginContainer) TextComponent(net.kyori.adventure.text.TextComponent) EconomyService(org.spongepowered.api.service.economy.EconomyService) Location(org.spongepowered.api.world.Location) GroupDataRecalculateEvent(net.luckperms.api.event.group.GroupDataRecalculateEvent) ClientboundClaimDataPacket(com.almuradev.almura.feature.claim.network.ClientboundClaimDataPacket) ServerNotificationManager(com.almuradev.almura.feature.notification.ServerNotificationManager) Sponge(org.spongepowered.api.Sponge) Claim(com.griefdefender.api.claim.Claim) NetworkConfig(com.almuradev.almura.shared.network.NetworkConfig) UUID(java.util.UUID) GriefDefender(com.griefdefender.api.GriefDefender) Instant(java.time.Instant) LuckPermsProvider(net.luckperms.api.LuckPermsProvider) ClientConnectionEvent(org.spongepowered.api.event.network.ClientConnectionEvent) ChannelBinding(org.spongepowered.api.network.ChannelBinding) List(java.util.List) TrustTypes(com.griefdefender.api.claim.TrustTypes) Witness(com.almuradev.core.event.Witness) GameAboutToStartServerEvent(org.spongepowered.api.event.game.state.GameAboutToStartServerEvent) World(org.spongepowered.api.world.World) ChannelId(org.spongepowered.api.network.ChannelId) Player(org.spongepowered.api.entity.living.player.Player) Listener(org.spongepowered.api.event.Listener) UniqueAccount(org.spongepowered.api.service.economy.account.UniqueAccount) Player(org.spongepowered.api.entity.living.player.Player) UUID(java.util.UUID) Claim(com.griefdefender.api.claim.Claim)

Aggregations

Almura (com.almuradev.almura.Almura)1 ClientboundClaimDataPacket (com.almuradev.almura.feature.claim.network.ClientboundClaimDataPacket)1 ClientboundClaimGuiResponsePacket (com.almuradev.almura.feature.claim.network.ClientboundClaimGuiResponsePacket)1 ServerNotificationManager (com.almuradev.almura.feature.notification.ServerNotificationManager)1 NetworkConfig (com.almuradev.almura.shared.network.NetworkConfig)1 Witness (com.almuradev.core.event.Witness)1 GriefDefender (com.griefdefender.api.GriefDefender)1 Claim (com.griefdefender.api.claim.Claim)1 TrustTypes (com.griefdefender.api.claim.TrustTypes)1 PlayerData (com.griefdefender.api.data.PlayerData)1 com.griefdefender.api.event (com.griefdefender.api.event)1 Instant (java.time.Instant)1 List (java.util.List)1 UUID (java.util.UUID)1 Inject (javax.inject.Inject)1 Singleton (javax.inject.Singleton)1 Component (net.kyori.adventure.text.Component)1 TextComponent (net.kyori.adventure.text.TextComponent)1 LuckPermsProvider (net.luckperms.api.LuckPermsProvider)1 GroupDataRecalculateEvent (net.luckperms.api.event.group.GroupDataRecalculateEvent)1