mirror of
https://github.com/GeorgH93/Minepacks.git
synced 2025-02-13 01:12:43 +01:00
Add BackpackDropOnDeathEvent (#197)
This commit is contained in:
parent
2baf799979
commit
37d9ba7b35
@ -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;
|
||||
}
|
||||
}
|
@ -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()
|
||||
|
@ -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 @@
|
||||
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;
|
||||
|
@ -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>
|
||||
|
@ -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 @@
|
||||
|
||||
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 void onDeath(PlayerDeathEvent event)
|
||||
@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
|
||||
|
Loading…
Reference in New Issue
Block a user