Add BackpackDropOnDeathEvent (#197)

This commit is contained in:
GeorgH93 2022-01-08 13:37:19 +01:00
parent 2baf799979
commit 37d9ba7b35
No known key found for this signature in database
GPG Key ID: D1630D37F9E4B3C8
6 changed files with 75 additions and 11 deletions

View File

@ -0,0 +1,59 @@
/*
* Copyright (C) 2022 GeorgH93
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package at.pcgamingfreaks.Minepacks.Bukkit.API.Events;
import at.pcgamingfreaks.Minepacks.Bukkit.API.Backpack;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
import lombok.Getter;
import lombok.Setter;
/**
* Event is triggered bevor the backpacks content is dropped to the ground!
*/
public class BackpackDropOnDeathEvent extends Event implements Cancellable
{
@Getter @Setter private boolean cancelled = false;
@Getter private final Player owner;
@Getter private final Backpack backpack;
public BackpackDropOnDeathEvent(final @NotNull Player owner, final @NotNull Backpack backpack)
{
this.owner = owner;
this.backpack = backpack;
}
// Bukkit handler stuff
private static final HandlerList handlers = new HandlerList();
@Override
public @NotNull HandlerList getHandlers()
{
return getHandlerList();
}
public static HandlerList getHandlerList()
{
return handlers;
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 GeorgH93
* Copyright (C) 2022 GeorgH93
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -34,7 +34,7 @@ public class InventoryClearEvent extends Event implements Cancellable
@Getter @Setter private boolean cancelled = false;
/**
* The player who's inventory should be cleared.
* The player whose inventory should be cleared.
*/
@Getter final private Player player;
@ -49,7 +49,7 @@ public class InventoryClearEvent extends Event implements Cancellable
@Override
public @NotNull HandlerList getHandlers()
{
return handlers;
return getHandlerList();
}
public static HandlerList getHandlerList()

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 GeorgH93
* Copyright (C) 2022 GeorgH93
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -30,7 +30,7 @@ import lombok.RequiredArgsConstructor;
public class InventoryClearedEvent extends Event
{
/**
* The player who's inventory has been cleared.
* The player whose inventory has been cleared.
*/
@Getter final private Player player;
@ -45,10 +45,9 @@ public class InventoryClearedEvent extends Event
@Override
public @NotNull HandlerList getHandlers()
{
return handlers;
return getHandlerList();
}
@SuppressWarnings("unused")
public static HandlerList getHandlerList()
{
return handlers;

View File

@ -58,7 +58,7 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.8.1</version>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 GeorgH93
* Copyright (C) 2022 GeorgH93
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -19,6 +19,7 @@ package at.pcgamingfreaks.Minepacks.Bukkit.Listener;
import at.pcgamingfreaks.Minepacks.Bukkit.API.Backpack;
import at.pcgamingfreaks.Minepacks.Bukkit.API.Callback;
import at.pcgamingfreaks.Minepacks.Bukkit.API.Events.BackpackDropOnDeathEvent;
import at.pcgamingfreaks.Minepacks.Bukkit.API.WorldBlacklistMode;
import at.pcgamingfreaks.Minepacks.Bukkit.Minepacks;
import at.pcgamingfreaks.Minepacks.Bukkit.Permissions;
@ -53,7 +54,12 @@ public class DropOnDeath extends MinepacksListener
@Override
public void onResult(Backpack backpack)
{
backpack.drop(location);
BackpackDropOnDeathEvent event = new BackpackDropOnDeathEvent(player, backpack);
plugin.getServer().getPluginManager().callEvent(event);
if(!event.isCancelled())
{
backpack.drop(location);
}
}
@Override

View File

@ -7,7 +7,7 @@
<packaging>pom</packaging>
<properties>
<revision>2.4.3</revision>
<revision>2.4.4-SNAPSHOT</revision>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>