mirror of
https://github.com/hyperdefined/ToolStats.git
synced 2026-01-28 08:25:58 +00:00
handle finding who opens a newly spawned chest better
This commit is contained in:
60
src/main/java/lol/hyper/toolstats/events/PlayerInteract.java
Normal file
60
src/main/java/lol/hyper/toolstats/events/PlayerInteract.java
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* This file is part of ToolStats.
|
||||
*
|
||||
* ToolStats 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.
|
||||
*
|
||||
* ToolStats 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 ToolStats. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class PlayerInteract implements Listener {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
|
||||
public HashMap<Block, Player> openedChests = new HashMap<>();
|
||||
|
||||
public PlayerInteract(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInteract(PlayerInteractEvent event) {
|
||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
|
||||
return;
|
||||
}
|
||||
|
||||
Block block = event.getClickedBlock();
|
||||
if (block == null) {
|
||||
return;
|
||||
}
|
||||
// store when a player opens a chest
|
||||
// this is used to detect who opens a newly spawned chest
|
||||
// since that is not really tracked on the lootevent
|
||||
if (block.getType() != Material.AIR && block.getType() == Material.CHEST) {
|
||||
openedChests.put(block, event.getPlayer());
|
||||
Bukkit.getScheduler().runTaskLater(toolStats, () -> openedChests.remove(block), 20);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user