org.spongepowered.api.event.Listener Java Examples

The following examples show how to use org.spongepowered.api.event.Listener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FactionKickListener.java    From EagleFactions with MIT License 6 votes vote down vote up
@Listener(order = Order.POST)
@IsCancelled(value = Tristate.FALSE)
public void onPlayerFactionKick(final FactionKickEvent event)
{
    final Faction faction = event.getFaction();
    final FactionPlayer kickedPlayer = event.getKickedPlayer();

    final List<Player> onlineFactionPlayers = super.getPlugin().getFactionLogic().getOnlinePlayers(faction);
    for(final Player player : onlineFactionPlayers)
    {
        if (player.equals(event.getCreator()))
            continue;

        if(player.getName().equals(kickedPlayer.getName()))
            continue;

        player.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, "Player " + kickedPlayer.getName() + " has been kicked from the faction."));
    }
}
 
Example #2
Source File: PlayerDisconnectListener.java    From EagleFactions with MIT License 6 votes vote down vote up
@Listener(order = Order.POST)
public void onDisconnect(ClientConnectionEvent.Disconnect event, @Root Player player)
{
    if (super.getPlugin().getPVPLogger().isActive() && EagleFactionsPlugin.getPlugin().getPVPLogger().isPlayerBlocked(player))
    {
        player.damage(1000, DamageSource.builder().type(DamageTypes.ATTACK).build());
        super.getPlugin().getPVPLogger().removePlayer(player);
    }

    EagleFactionsPlugin.REGEN_CONFIRMATION_MAP.remove(player.getUniqueId());

    final Optional<Faction> optionalFaction = getPlugin().getFactionLogic().getFactionByPlayerUUID(player.getUniqueId());
    optionalFaction.ifPresent(faction -> getPlugin().getFactionLogic().setLastOnline(faction, Instant.now()));

    //TODO: Unload player cache...
    FactionsCache.removePlayer(player.getUniqueId());
}
 
Example #3
Source File: PlayerInteractListener.java    From EagleFactions with MIT License 6 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onBlockInteract(final InteractBlockEvent event, @Root final Player player)
{
    //If AIR or NONE then return
    if (event.getTargetBlock() == BlockSnapshot.NONE || event.getTargetBlock().getState().getType() == BlockTypes.AIR)
        return;

    final Optional<Location<World>> optionalLocation = event.getTargetBlock().getLocation();
    if (!optionalLocation.isPresent())
        return;

    final Location<World> blockLocation = optionalLocation.get();

    final ProtectionResult protectionResult = super.getPlugin().getProtectionManager().canInteractWithBlock(blockLocation, player, true);
    if (!protectionResult.hasAccess())
    {
        event.setCancelled(true);
        return;
    }
    else
    {
        if(event instanceof InteractBlockEvent.Secondary && protectionResult.isEagleFeather())
            removeEagleFeather(player);
    }
}
 
Example #4
Source File: PlayerInteractListener.java    From EagleFactions with MIT License 6 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onEntityInteract(final InteractEntityEvent event, @Root final Player player)
{
    final Entity targetEntity = event.getTargetEntity();
    final Optional<Vector3d> optionalInteractionPoint = event.getInteractionPoint();

    if((targetEntity instanceof Living) && !(targetEntity instanceof ArmorStand))
        return;

    final Vector3d blockPosition = optionalInteractionPoint.orElseGet(() -> targetEntity.getLocation().getPosition());
    final Location<World> location = new Location<>(targetEntity.getWorld(), blockPosition);
    boolean canInteractWithEntity = super.getPlugin().getProtectionManager().canInteractWithBlock(location, player, true).hasAccess();
    if(!canInteractWithEntity)
    {
        event.setCancelled(true);
        return;
    }
}
 
Example #5
Source File: VirtualChestPlugin.java    From VirtualChest with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Listener
public void onClientConnectionJoin(ClientConnectionEvent.Join event)
{
    Server server = Sponge.getServer();
    if (server.getOnlineMode())
    {
        // prefetch the profile when a player joins the server
        // TODO: maybe we should also prefetch player profiles in offline mode
        GameProfile profile = event.getTargetEntity().getProfile();
        server.getGameProfileManager().fill(profile).thenRun(() ->
        {
            String message = "Successfully loaded the game profile for {} (player {})";
            this.logger.debug(message, profile.getUniqueId(), profile.getName().orElse("null"));
        });
    }
}
 
Example #6
Source File: VirtualChestPlugin.java    From VirtualChest with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Listener(order = Order.EARLY)
public void onInteractItemSecondary(InteractItemEvent.Secondary event, @First Player player)
{
    String name = "";
    for (String inventoryName : this.dispatcher.ids())
    {
        if (player.hasPermission("virtualchest.open.self." + inventoryName))
        {
            if (this.dispatcher.isInventoryMatchingSecondaryAction(inventoryName, event.getItemStack()))
            {
                event.setCancelled(true);
                name = inventoryName;
                break;
            }
        }
    }
    if (!name.isEmpty())
    {
        this.logger.debug("Player {} tries to create the GUI ({}) by secondary action", player.getName(), name);
        this.dispatcher.open(name, player);
    }
}
 
Example #7
Source File: VirtualChestPlugin.java    From VirtualChest with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Listener
public void onReload(GameReloadEvent event)
{
    try
    {
        MessageReceiver src = event.getCause().first(CommandSource.class).orElse(Sponge.getServer().getConsole());
        src.sendMessage(this.translation.take("virtualchest.reload.start"));
        this.loadConfig();
        this.saveConfig();
        src.sendMessage(this.translation.take("virtualchest.reload.finish"));
    }
    catch (IOException e)
    {
        throw new RuntimeException(e);
    }
}
 
Example #8
Source File: VirtualChestPlugin.java    From VirtualChest with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Listener(order = Order.EARLY)
public void onInteractItemPrimary(InteractItemEvent.Primary event, @First Player player)
{
    String name = "";
    for (String inventoryName : this.dispatcher.ids())
    {
        if (player.hasPermission("virtualchest.open.self." + inventoryName))
        {
            if (this.dispatcher.isInventoryMatchingPrimaryAction(inventoryName, event.getItemStack()))
            {
                event.setCancelled(true);
                name = inventoryName;
                break;
            }
        }
    }
    if (!name.isEmpty())
    {
        this.logger.debug("Player {} tries to create the GUI ({}) by primary action", player.getName(), name);
        this.dispatcher.open(name, player);
    }
}
 
Example #9
Source File: VirtualChestPlugin.java    From VirtualChest with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Listener
public void onStartedServer(GameStartedServerEvent event)
{
    try
    {
        this.logger.info("Start loading config ...");
        this.loadConfig();
        this.saveConfig();
        this.logger.info("Loading config complete.");
    }
    catch (IOException e)
    {
        throw new RuntimeException(e);
    }
    this.addMetricsInformation();
}
 
Example #10
Source File: VirtualChestPlugin.java    From VirtualChest with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Listener
public void onPostInitialization(GamePostInitializationEvent event)
{
    this.update = new VirtualChestPluginUpdate(this);
    this.translation = new VirtualChestTranslation(this);
    this.recordManager = new VirtualChestRecordManager(this);
    this.virtualChestActions = new VirtualChestActions(this);
    this.commandAliases = new VirtualChestCommandAliases(this);
    this.economyManager = new VirtualChestEconomyManager(this);
    this.dispatcher = new VirtualChestInventoryDispatcher(this);
    this.scriptManager = new VirtualChestJavaScriptManager(this);
    this.permissionManager = new VirtualChestPermissionManager(this);
    this.placeholderManager = new VirtualChestPlaceholderManager(this);
    this.virtualChestCommandManager = new VirtualChestCommandManager(this);
    this.actionIntervalManager = new VirtualChestActionIntervalManager(this);

    if (Sponge.getPluginManager().getPlugin("byte-items").isPresent())
    {
        byteItemsService = Sponge.getServiceManager().provide(ByteItemsService.class).get();
    }
}
 
Example #11
Source File: Metrics2.java    From bStats-Metrics with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Listener
public void startup(GamePreInitializationEvent event) {
    try {
        loadConfig();
    } catch (IOException e) {
        // Failed to load configuration
        logger.warn("Failed to load bStats config!", e);
        return;
    }

    if (Sponge.getServiceManager().isRegistered(Metrics.class)) {
        Metrics provider = Sponge.getServiceManager().provideUnchecked(Metrics.class);
        provider.linkMetrics(this);
    } else {
        Sponge.getServiceManager().setProvider(plugin.getInstance().get(), Metrics.class, this);
        this.linkMetrics(this);
        startSubmitting();
    }
}
 
Example #12
Source File: MetricsLite2.java    From bStats-Metrics with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Listener
public void startup(GamePreInitializationEvent event) {
    try {
        loadConfig();
    } catch (IOException e) {
        // Failed to load configuration
        logger.warn("Failed to load bStats config!", e);
        return;
    }

    if (Sponge.getServiceManager().isRegistered(Metrics.class)) {
        Metrics provider = Sponge.getServiceManager().provideUnchecked(Metrics.class);
        provider.linkMetrics(this);
    } else {
        Sponge.getServiceManager().setProvider(plugin.getInstance().get(), Metrics.class, this);
        this.linkMetrics(this);
        startSubmitting();
    }
}
 
Example #13
Source File: PlayerEventHandler.java    From GriefDefender with MIT License 6 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerLogin(ClientConnectionEvent.Login event) {
    GDTimings.PLAYER_LOGIN_EVENT.startTimingIfSync();
    User player = event.getTargetUser();
    if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(event.getToTransform().getExtent().getUniqueId())) {
        GDTimings.PLAYER_LOGIN_EVENT.stopTimingIfSync();
        return;
    }

    final WorldProperties worldProperties = event.getToTransform().getExtent().getProperties();
    final UUID playerUniqueId = player.getUniqueId();
    final GDClaimManager claimWorldManager = this.dataStore.getClaimWorldManager(worldProperties.getUniqueId());
    final Instant dateNow = Instant.now();
    for (Claim claim : claimWorldManager.getWorldClaims()) {
        if (claim.getType() != ClaimTypes.ADMIN && claim.getOwnerUniqueId().equals(playerUniqueId)) {
            claim.getData().setDateLastActive(dateNow);
            for (Claim subdivision : ((GDClaim) claim).children) {
                subdivision.getData().setDateLastActive(dateNow);
            }
            ((GDClaim) claim).getInternalClaimData().setRequiresSave(true);
            ((GDClaim) claim).getInternalClaimData().save();
        }
    }
    GDTimings.PLAYER_LOGIN_EVENT.stopTimingIfSync();
}
 
Example #14
Source File: PlayerEventHandler.java    From GriefDefender with MIT License 6 votes vote down vote up
@Listener(order = Order.FIRST)
public void onPlayerJoin(ClientConnectionEvent.Join event) {
    GDTimings.PLAYER_JOIN_EVENT.startTimingIfSync();
    Player player = event.getTargetEntity();
    if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(player.getWorld().getUniqueId())) {
        GDTimings.PLAYER_JOIN_EVENT.stopTimingIfSync();
        return;
    }

    UUID playerID = player.getUniqueId();

    final GDPlayerData playerData = this.dataStore.getOrCreatePlayerData(player.getWorld(), playerID);
    final GDClaim claim = this.dataStore.getClaimAtPlayer(playerData, player.getLocation());
    if (claim.isInTown()) {
        playerData.inTown = true;
    }

    GDTimings.PLAYER_JOIN_EVENT.stopTimingIfSync();
}
 
Example #15
Source File: PlayerEventHandler.java    From GriefDefender with MIT License 6 votes vote down vote up
@Listener(order= Order.LAST)
public void onPlayerQuit(ClientConnectionEvent.Disconnect event) {
    final Player player = event.getTargetEntity();
    if (!SpongeImpl.getServer().isServerRunning() || !GriefDefenderPlugin.getInstance().claimsEnabledForWorld(player.getWorld().getUniqueId())) {
        return;
    }

    GDTimings.PLAYER_QUIT_EVENT.startTimingIfSync();
    UUID playerID = player.getUniqueId();
    GDPlayerData playerData = this.dataStore.getOrCreatePlayerData(player.getWorld(), playerID);

    if (this.worldEditProvider != null) {
        this.worldEditProvider.revertVisuals(player, playerData, null);
        this.worldEditProvider.removePlayer(player);
    }

    playerData.onDisconnect();
    PaginationUtil.getInstance().removeActivePageData(player.getUniqueId());
    if (playerData.getClaims().isEmpty()) {
        this.dataStore.clearCachedPlayerData(player.getWorld().getUniqueId(), playerID);
    }
    GDCallbackHolder.getInstance().onPlayerDisconnect(player);
    GDTimings.PLAYER_QUIT_EVENT.stopTimingIfSync();
}
 
Example #16
Source File: PlayerEventHandler.java    From GriefDefender with MIT License 6 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerDeath(DestructEntityEvent.Death event) {
    if (!(event.getTargetEntity() instanceof Player)) {
        return;
    }

    final Player player = (Player) event.getTargetEntity();
    GDCauseStackManager.getInstance().pushCause(player);
    final GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
    final GDClaim claim = GriefDefenderPlugin.getInstance().dataStore.getClaimAtPlayer(playerData, player.getLocation());
    Tristate keepInventory = Tristate.UNDEFINED;
    if (GDOptions.isOptionEnabled(Options.PLAYER_KEEP_INVENTORY)) {
        keepInventory = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(Tristate.class), playerData.getSubject(), Options.PLAYER_KEEP_INVENTORY, claim);
    }
    if (keepInventory != Tristate.UNDEFINED) {
        event.setKeepInventory(keepInventory.asBoolean());
    }
    /*Tristate keepLevel = Tristate.UNDEFINED;
    if (GDOptions.isOptionEnabled(Options.PLAYER_KEEP_LEVEL)) {
        keepLevel = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(Tristate.class), playerData.getSubject(), Options.PLAYER_KEEP_LEVEL, claim);
    }
    if (keepLevel != Tristate.UNDEFINED) {
        event.setKeepLevel(keepLevel.asBoolean());
    }*/
}
 
Example #17
Source File: PlayerEventHandler.java    From GriefDefender with MIT License 6 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerInteractInventoryClose(InteractInventoryEvent.Close event, @Root Player player) {
    final ItemStackSnapshot cursor = event.getCursorTransaction().getOriginal();
    if (cursor == ItemStackSnapshot.NONE || !GDFlags.ITEM_DROP || !GriefDefenderPlugin.getInstance().claimsEnabledForWorld(player.getWorld().getUniqueId())) {
        return;
    }
    if (GriefDefenderPlugin.isTargetIdBlacklisted(Flags.ITEM_DROP.getName(), cursor, player.getWorld().getProperties())) {
        return;
    }

    GDTimings.PLAYER_INTERACT_INVENTORY_CLOSE_EVENT.startTimingIfSync();
    final Location<World> location = player.getLocation();
    final GDClaim claim = this.dataStore.getClaimAt(location);
    if (GDPermissionManager.getInstance().getFinalPermission(event, location, claim, Flags.ITEM_DROP, player, cursor, player, TrustTypes.ACCESSOR, true) == Tristate.FALSE) {
        final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.PERMISSION_ITEM_DROP,
                ImmutableMap.of(
                "player", claim.getOwnerName(),
                "item", cursor.getType().getId()));
        GriefDefenderPlugin.sendClaimDenyMessage(claim, player, message);
        event.setCancelled(true);
    }

    GDTimings.PLAYER_INTERACT_INVENTORY_CLOSE_EVENT.stopTimingIfSync();
}
 
Example #18
Source File: HuskyUI.java    From HuskyUI-Plugin with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Handler for ActionableElement actions.
 *
 * @param event When a player interacts with an item with their secondary mouse button.
 */
@Listener(order= Order.LAST)
public void onElementInteract(InteractItemEvent event){
    Optional<Element> ele = registry.getElementFromItemStack(event.getItemStack().createStack());
    if(ele.isPresent()){
        if(event instanceof InteractItemEvent.Secondary) {
            if (ele.get() instanceof ActionableElement) {
                ActionableElement aElement = ((ActionableElement) ele.get()).copy(registry);
                aElement.getAction().setObserver((Player) event.getCause().root());
                aElement.getAction().runAction("",null);
            }
        }

        event.setCancelled(true);
    }
}
 
Example #19
Source File: PlayerEventHandler.java    From GriefDefender with MIT License 6 votes vote down vote up
@Listener(order = Order.LAST, beforeModifications = true)
public void onPlayerPickupItem(ChangeInventoryEvent.Pickup.Pre event, @Root Player player) {
    if (!GDFlags.ITEM_PICKUP || !GriefDefenderPlugin.getInstance().claimsEnabledForWorld(player.getWorld().getUniqueId())) {
        return;
    }
    if (GriefDefenderPlugin.isTargetIdBlacklisted(Flags.ITEM_PICKUP.getName(), event.getTargetEntity(), player.getWorld().getProperties())) {
        return;
    }

    GDTimings.PLAYER_PICKUP_ITEM_EVENT.startTimingIfSync();
    final World world = player.getWorld();
    GDPlayerData playerData = this.dataStore.getOrCreatePlayerData(world, player.getUniqueId());
    Location<World> location = player.getLocation();
    GDClaim claim = this.dataStore.getClaimAtPlayer(playerData, location);
    if (GDPermissionManager.getInstance().getFinalPermission(event, location, claim, Flags.ITEM_PICKUP, player, event.getTargetEntity(), player, true) == Tristate.FALSE) {
        event.setCancelled(true);
    }

    GDTimings.PLAYER_PICKUP_ITEM_EVENT.stopTimingIfSync();
}
 
Example #20
Source File: PlayerEventHandler.java    From GriefDefender with MIT License 6 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerUseItem(UseItemStackEvent.Start event, @First Player player) {
    if (!GDFlags.ITEM_USE || !GriefDefenderPlugin.getInstance().claimsEnabledForWorld(player.getWorld().getUniqueId())) {
        return;
    }
    if (GriefDefenderPlugin.isTargetIdBlacklisted(Flags.ITEM_USE.getName(), event.getItemStackInUse().getType(), player.getWorld().getProperties())) {
        return;
    }

    GDTimings.PLAYER_USE_ITEM_EVENT.startTimingIfSync();
    Location<World> location = player.getLocation();
    GDPlayerData playerData = this.dataStore.getOrCreatePlayerData(location.getExtent(), player.getUniqueId());
    GDClaim claim = this.dataStore.getClaimAtPlayer(playerData, location);

    final Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, claim, Flags.ITEM_USE, player, event.getItemStackInUse().getType(), player, TrustTypes.ACCESSOR, true);
    if (result == Tristate.FALSE) {
        final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.PERMISSION_ITEM_USE,
                ImmutableMap.of(
                "item", event.getItemStackInUse().getType().getId()));
        GriefDefenderPlugin.sendClaimDenyMessage(claim, player,  message);
        event.setCancelled(true);
    }
    GDTimings.PLAYER_USE_ITEM_EVENT.stopTimingIfSync();
}
 
Example #21
Source File: WorldEventHandler.java    From GriefDefender with MIT License 6 votes vote down vote up
@Listener
public void onWorldSave(SaveWorldEvent.Post event) {
    if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(event.getTargetWorld().getUniqueId())) {
        return;
    }

    GDTimings.WORLD_SAVE_EVENT.startTimingIfSync();
    GDClaimManager claimWorldManager = GriefDefenderPlugin.getInstance().dataStore.getClaimWorldManager(event.getTargetWorld().getUniqueId());
    if (claimWorldManager == null) {
        GDTimings.WORLD_SAVE_EVENT.stopTimingIfSync();
        return;
    }

    claimWorldManager.save();
    GDTimings.WORLD_SAVE_EVENT.stopTimingIfSync();
}
 
Example #22
Source File: SpongePlugin.java    From BlueMap with MIT License 6 votes vote down vote up
@Listener
public void onServerStart(GameStartingServerEvent evt) {
	asyncExecutor = Sponge.getScheduler().createAsyncExecutor(this);
	
	//save all world properties to generate level_sponge.dat files
	for (WorldProperties properties : Sponge.getServer().getAllWorldProperties()) {
		Sponge.getServer().saveWorldProperties(properties);
	}
	
	//register commands
	for(SpongeCommandProxy command : commands.getRootCommands()) {
		Sponge.getCommandManager().register(this, command, command.getLabel());
	}
	
	asyncExecutor.execute(() -> {
		try {
			Logger.global.logInfo("Loading...");
			bluemap.load();
			if (bluemap.isLoaded()) Logger.global.logInfo("Loaded!");
		} catch (Throwable t) {
			Logger.global.logError("Failed to load!", t);
		}
	});
}
 
Example #23
Source File: ModifyBlockListener.java    From EagleFactions with MIT License 5 votes vote down vote up
@Listener
    public void onBlockModify(ChangeBlockEvent.Modify event)
    {
        User user = null;
        if(event.getCause().containsType(Player.class))
        {
            user = event.getCause().first(Player.class).get();
        }
        else if(event.getCause().containsType(User.class))
        {
            user = event.getCause().first(User.class).get();
        }

//        if(event.getContext().containsKey(EventContextKeys.OWNER)
//            && event.getContext().get(EventContextKeys.OWNER).isPresent()
//            && event.getContext().get(EventContextKeys.OWNER).get() instanceof Player)
//        {
//            Player player = (Player) event.getContext().get(EventContextKeys.OWNER).get();
        if(user != null)
        {
            for (Transaction<BlockSnapshot> transaction : event.getTransactions())
            {
                final Optional<Location<World>> optionalLocation = transaction.getFinal().getLocation();
                if(optionalLocation.isPresent() && !super.getPlugin().getProtectionManager().canInteractWithBlock(optionalLocation.get(), user, true).hasAccess())
                    event.setCancelled(true);
            }
        }
//        }
    }
 
Example #24
Source File: SpongePlugin.java    From ViaRewind with MIT License 5 votes vote down vote up
@Listener(order = Order.LATE)
public void onGameStart(GameInitializationEvent e) {
	// Setup Logger
	this.logger = new LoggerWrapper(loggerSlf4j);
	// Init!
	ViaRewindConfigImpl conf = new ViaRewindConfigImpl(configDir.resolve("config.yml").toFile());
	conf.reloadConfig();
	this.init(conf);
}
 
Example #25
Source File: GriefDefenderPlugin.java    From GriefDefender with MIT License 5 votes vote down vote up
@Listener(order = Order.LAST)
public void onGameReload(GameReloadEvent event) {
    this.loadConfig();
    if (event.getSource() instanceof CommandSource) {
        sendMessage((CommandSource) event.getSource(), MessageCache.getInstance().PLUGIN_RELOAD);
    }
}
 
Example #26
Source File: WorldEventHandler.java    From GriefDefender with MIT License 5 votes vote down vote up
@Listener
public void onChunkUnload(UnloadChunkEvent event) {
    if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(event.getTargetChunk().getWorld().getUniqueId())) {
        return;
    }

    final GDClaimManager claimWorldManager = GriefDefenderPlugin.getInstance().dataStore.getClaimWorldManager(event.getTargetChunk().getWorld().getUniqueId());
    final GDChunk gdChunk = claimWorldManager.getChunk(event.getTargetChunk());
    if (gdChunk != null) {
        claimWorldManager.removeChunk(gdChunk.getChunkKey());
    }
}
 
Example #27
Source File: WorldEventHandler.java    From GriefDefender with MIT License 5 votes vote down vote up
@Listener(order = Order.EARLY)
public void onChunkLoad(LoadChunkEvent event) {
    if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(event.getTargetChunk().getWorld().getUniqueId())) {
        return;
    }

    final GDClaimManager claimWorldManager = GriefDefenderPlugin.getInstance().dataStore.getClaimWorldManager(event.getTargetChunk().getWorld().getUniqueId());
    claimWorldManager.getChunk(event.getTargetChunk());
}
 
Example #28
Source File: WorldEventHandler.java    From GriefDefender with MIT License 5 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onWorldUnload(UnloadWorldEvent event) {
    if (!SpongeImpl.getServer().isServerRunning() || !GriefDefenderPlugin.getInstance().claimsEnabledForWorld(event.getTargetWorld().getUniqueId())) {
        return;
    }

    GriefDefenderPlugin.getInstance().dataStore.removeClaimWorldManager(event.getTargetWorld().getProperties());
}
 
Example #29
Source File: WorldEventHandler.java    From GriefDefender with MIT License 5 votes vote down vote up
@Listener(order = Order.EARLY, beforeModifications = true)
public void onWorldLoad(LoadWorldEvent event) {
    if (!SpongeImpl.getServer().isServerRunning() || !GriefDefenderPlugin.getInstance().claimsEnabledForWorld(event.getTargetWorld().getUniqueId())) {
        return;
    }

    GDTimings.WORLD_LOAD_EVENT.startTimingIfSync();
    GriefDefenderPlugin.getInstance().dataStore.registerWorld(event.getTargetWorld());
    GriefDefenderPlugin.getInstance().dataStore.loadWorldData(event.getTargetWorld());
    NMSUtil.getInstance().addEntityRemovalListener(event.getTargetWorld());
    GDTimings.WORLD_LOAD_EVENT.stopTimingIfSync();
}
 
Example #30
Source File: HuskyUI.java    From HuskyUI-Plugin with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Handle item usage
 * @param event useitemstackevent.start
 */
@Listener
public void onItemUse(UseItemStackEvent.Start event){
    Optional<Integer> potentialID = registry.getElementIDFromItemStack(event.getItemStackInUse().createStack());
    if(potentialID.isPresent()){
        if(registry.elementExists(potentialID.get())){
            event.setCancelled(true);
        }
    }
}