mirror of
https://github.com/Zrips/Jobs.git
synced 2025-01-17 05:31:19 +01:00
Players can have multiple campfires
This commit is contained in:
parent
ae1b8b5d3c
commit
0e2621e42a
@ -129,20 +129,18 @@ public class PlayerManager {
|
|||||||
public void addPlayerToCache(JobsPlayer jPlayer) {
|
public void addPlayerToCache(JobsPlayer jPlayer) {
|
||||||
String jName = jPlayer.getName().toLowerCase();
|
String jName = jPlayer.getName().toLowerCase();
|
||||||
|
|
||||||
if (!playersCache.containsKey(jName))
|
playersCache.put(jName, jPlayer);
|
||||||
playersCache.put(jName, jPlayer);
|
|
||||||
|
|
||||||
if (jPlayer.getUniqueId() != null && !playersUUIDCache.containsKey(jPlayer.getUniqueId()))
|
if (jPlayer.getUniqueId() != null)
|
||||||
playersUUIDCache.put(jPlayer.getUniqueId(), jPlayer);
|
playersUUIDCache.put(jPlayer.getUniqueId(), jPlayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPlayer(JobsPlayer jPlayer) {
|
public void addPlayer(JobsPlayer jPlayer) {
|
||||||
String jName = jPlayer.getName().toLowerCase();
|
String jName = jPlayer.getName().toLowerCase();
|
||||||
|
|
||||||
if (!players.containsKey(jName))
|
players.put(jName, jPlayer);
|
||||||
players.put(jName, jPlayer);
|
|
||||||
|
|
||||||
if (jPlayer.getUniqueId() != null && !playersUUID.containsKey(jPlayer.getUniqueId()))
|
if (jPlayer.getUniqueId() != null)
|
||||||
playersUUID.put(jPlayer.getUniqueId(), jPlayer);
|
playersUUID.put(jPlayer.getUniqueId(), jPlayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,48 +1,89 @@
|
|||||||
package com.gamingmesh.jobs.listeners;
|
package com.gamingmesh.jobs.listeners;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.block.Campfire;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
import org.bukkit.event.block.BlockCookEvent;
|
import org.bukkit.event.block.BlockCookEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
|
||||||
import com.gamingmesh.jobs.Jobs;
|
import com.gamingmesh.jobs.Jobs;
|
||||||
import com.gamingmesh.jobs.actions.ItemActionInfo;
|
import com.gamingmesh.jobs.actions.ItemActionInfo;
|
||||||
import com.gamingmesh.jobs.container.ActionType;
|
import com.gamingmesh.jobs.container.ActionType;
|
||||||
import com.gamingmesh.jobs.container.JobsPlayer;
|
|
||||||
import com.gamingmesh.jobs.container.PlayerCamp;
|
import com.gamingmesh.jobs.container.PlayerCamp;
|
||||||
|
|
||||||
public class JobsPayment14Listener implements Listener {
|
public final class JobsPayment14Listener implements Listener {
|
||||||
|
|
||||||
private final Map<PlayerCamp, Player> campPlayers = new HashMap<>();
|
// BlockCookEvent does not have "cooking owner"
|
||||||
|
private final Map<UUID, List<PlayerCamp>> campPlayers = new HashMap<>();
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOW)
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
public void onCook(BlockCookEvent event) {
|
public void onCook(BlockCookEvent event) {
|
||||||
if (event.isCancelled())
|
if (event.isCancelled() || !(event.getBlock().getType() != Material.CAMPFIRE) || campPlayers.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!Jobs.getGCManager().canPerformActionInWorld(event.getBlock().getWorld()) || !(event.getBlock().getState() instanceof Campfire))
|
if (!Jobs.getGCManager().canPerformActionInWorld(event.getBlock().getWorld()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (Iterator<Entry<PlayerCamp, Player>> it = campPlayers.entrySet().iterator(); it.hasNext();) {
|
for (Map.Entry<UUID, List<PlayerCamp>> map : campPlayers.entrySet()) {
|
||||||
Entry<PlayerCamp, Player> camps = it.next();
|
List<PlayerCamp> camps = map.getValue();
|
||||||
if (!camps.getKey().getBlock().getLocation().equals(event.getBlock().getLocation()))
|
|
||||||
|
if (camps.isEmpty()) {
|
||||||
|
campPlayers.remove(map.getKey());
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(camps.getValue());
|
for (PlayerCamp camp : new ArrayList<>(camps)) {
|
||||||
if (jPlayer == null)
|
if (camp.getBlock().getLocation().equals(event.getBlock().getLocation())) {
|
||||||
|
if (camp.getItem().equals(event.getSource())) {
|
||||||
|
camps.remove(camp);
|
||||||
|
|
||||||
|
if (camps.isEmpty()) {
|
||||||
|
campPlayers.remove(map.getKey());
|
||||||
|
} else {
|
||||||
|
campPlayers.replace(map.getKey(), camps);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Jobs.action(Jobs.getPlayerManager().getJobsPlayer(map.getKey()), new ItemActionInfo(event.getSource(), ActionType.BAKE));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(ignoreCancelled = true)
|
||||||
|
public void onBlockBreak(BlockBreakEvent event) {
|
||||||
|
if (event.getBlock().getType() != Material.CAMPFIRE || campPlayers.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
List<PlayerCamp> camps = campPlayers.get(event.getPlayer().getUniqueId());
|
||||||
|
|
||||||
|
if (camps != null) {
|
||||||
|
if (camps.isEmpty()) {
|
||||||
|
campPlayers.remove(event.getPlayer().getUniqueId());
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Jobs.action(jPlayer, new ItemActionInfo(event.getSource(), ActionType.BAKE));
|
for (PlayerCamp camp : new ArrayList<>(camps)) {
|
||||||
if (camps.getKey().getItem().equals(event.getSource())) {
|
if (camp.getBlock().getLocation().equals(event.getBlock().getLocation())) {
|
||||||
it.remove();
|
camps.remove(camp);
|
||||||
|
|
||||||
|
if (camps.isEmpty()) {
|
||||||
|
campPlayers.remove(event.getPlayer().getUniqueId());
|
||||||
|
} else {
|
||||||
|
campPlayers.replace(event.getPlayer().getUniqueId(), camps);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -50,15 +91,16 @@ public class JobsPayment14Listener implements Listener {
|
|||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void onCampPlace(PlayerInteractEvent ev) {
|
public void onCampPlace(PlayerInteractEvent ev) {
|
||||||
org.bukkit.block.Block click = ev.getClickedBlock();
|
org.bukkit.block.Block click = ev.getClickedBlock();
|
||||||
if (click == null || click.getType() != org.bukkit.Material.CAMPFIRE)
|
|
||||||
|
if (click == null || click.getType() != Material.CAMPFIRE || !ev.hasItem())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!Jobs.getGCManager().canPerformActionInWorld(click.getWorld()) || !(click.getState() instanceof Campfire))
|
if (!Jobs.getGCManager().canPerformActionInWorld(click.getWorld()) || !JobsPaymentListener.payIfCreative(ev.getPlayer()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!ev.hasItem() || !JobsPaymentListener.payIfCreative(ev.getPlayer()))
|
List<PlayerCamp> camps = campPlayers.getOrDefault(ev.getPlayer().getUniqueId(), new ArrayList<>());
|
||||||
return;
|
camps.add(new PlayerCamp(ev.getItem(), click));
|
||||||
|
|
||||||
campPlayers.put(new PlayerCamp(ev.getItem(), click), ev.getPlayer());
|
campPlayers.put(ev.getPlayer().getUniqueId(), camps);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -987,10 +987,9 @@ public class JobsPaymentListener implements Listener {
|
|||||||
if (!Jobs.getGCManager().PreventHopperFillUps || event.getItem().getType() == Material.AIR)
|
if (!Jobs.getGCManager().PreventHopperFillUps || event.getItem().getType() == Material.AIR)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
String type = event.getDestination().getType().toString();
|
|
||||||
Block block = null;
|
Block block = null;
|
||||||
|
|
||||||
switch (type.toLowerCase()) {
|
switch (event.getDestination().getType().toString().toLowerCase()) {
|
||||||
case "furnace":
|
case "furnace":
|
||||||
block = ((Furnace) event.getDestination().getHolder()).getBlock();
|
block = ((Furnace) event.getDestination().getHolder()).getBlock();
|
||||||
break;
|
break;
|
||||||
@ -1068,11 +1067,12 @@ public class JobsPaymentListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||||
public void onEntityDamageByPlayer(EntityDamageEvent event) {
|
public void onEntityDamageByPlayer(EntityDamageEvent event) {
|
||||||
if (!Jobs.getGCManager().MonsterDamageUse || !Jobs.getGCManager().canPerformActionInWorld(event.getEntity().getWorld()))
|
if (!Jobs.getGCManager().MonsterDamageUse || !(event instanceof EntityDamageByEntityEvent)
|
||||||
|
|| !Jobs.getGCManager().canPerformActionInWorld(event.getEntity().getWorld()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Entity ent = event.getEntity();
|
Entity ent = event.getEntity();
|
||||||
if (ent instanceof Player || !(ent instanceof Damageable) || !(event instanceof EntityDamageByEntityEvent))
|
if (ent instanceof Player || !(ent instanceof Damageable))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!(((EntityDamageByEntityEvent) event).getDamager() instanceof Player))
|
if (!(((EntityDamageByEntityEvent) event).getDamager() instanceof Player))
|
||||||
@ -1125,8 +1125,8 @@ public class JobsPaymentListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onEntityDeath(EntityDeathEvent event) {
|
public void onEntityDeath(EntityDeathEvent event) {
|
||||||
if (!Jobs.getGCManager().canPerformActionInWorld(event.getEntity().getWorld())
|
if (!(event.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent) ||
|
||||||
|| !(event.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent))
|
!Jobs.getGCManager().canPerformActionInWorld(event.getEntity().getWorld()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event.getEntity().getLastDamageCause();
|
EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event.getEntity().getLastDamageCause();
|
||||||
@ -1458,12 +1458,14 @@ public class JobsPaymentListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onPlayerEat(FoodLevelChangeEvent event) {
|
public void onPlayerEat(FoodLevelChangeEvent event) {
|
||||||
if (!(event.getEntity() instanceof Player) || !Jobs.getGCManager().canPerformActionInWorld(event.getEntity().getWorld())
|
HumanEntity human = event.getEntity();
|
||||||
|| event.getEntity().hasMetadata("NPC"))
|
|
||||||
|
if (event.getFoodLevel() <= human.getFoodLevel() || !(human instanceof Player)
|
||||||
|
|| !Jobs.getGCManager().canPerformActionInWorld(human.getWorld()) || human.hasMetadata("NPC"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Player player = (Player) event.getEntity();
|
Player player = (Player) human;
|
||||||
if (!player.isOnline() || event.getFoodLevel() <= player.getFoodLevel())
|
if (!player.isOnline())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// check if in creative
|
// check if in creative
|
||||||
@ -1643,14 +1645,11 @@ public class JobsPaymentListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onExplore(JobsChunkChangeEvent event) {
|
public void onExplore(JobsChunkChangeEvent event) {
|
||||||
if (event.isCancelled())
|
if (event.isCancelled() || !Jobs.getExplore().isExploreEnabled())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
if (player == null || !player.isOnline() || !Jobs.getGCManager().canPerformActionInWorld(player.getWorld()))
|
if (player == null || !player.isOnline())
|
||||||
return;
|
|
||||||
|
|
||||||
if (!Jobs.getExplore().isExploreEnabled())
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// check if in spectator, #330
|
// check if in spectator, #330
|
||||||
@ -1668,11 +1667,13 @@ public class JobsPaymentListener implements Listener {
|
|||||||
&& !Jobs.getGCManager().payExploringWhenGliding && player.isGliding())
|
&& !Jobs.getGCManager().payExploringWhenGliding && player.isGliding())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
org.bukkit.World playerWorld = player.getWorld();
|
||||||
|
|
||||||
// check if in creative
|
// check if in creative
|
||||||
if (!payIfCreative(player))
|
if (!Jobs.getGCManager().canPerformActionInWorld(playerWorld) || !payIfCreative(player))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName()))
|
if (!Jobs.getPermissionHandler().hasWorldPermission(player, playerWorld.getName()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
|
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
|
||||||
@ -1692,8 +1693,7 @@ public class JobsPaymentListener implements Listener {
|
|||||||
if (Version.isCurrentEqualOrHigher(Version.v1_13_R1) && entity.isPersistent())
|
if (Version.isCurrentEqualOrHigher(Version.v1_13_R1) && entity.isPersistent())
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (entity.hasMetadata(Jobs.getPlayerManager().getMobSpawnerMetadata()))
|
entity.removeMetadata(Jobs.getPlayerManager().getMobSpawnerMetadata(), plugin);
|
||||||
entity.removeMetadata(Jobs.getPlayerManager().getMobSpawnerMetadata(), plugin);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,8 +41,8 @@ public class BufferedPaymentTask implements Runnable {
|
|||||||
double money = payment.get(CurrencyType.MONEY);
|
double money = payment.get(CurrencyType.MONEY);
|
||||||
if (money > 0) {
|
if (money > 0) {
|
||||||
if (Jobs.getGCManager().isEconomyAsync()) {
|
if (Jobs.getGCManager().isEconomyAsync()) {
|
||||||
org.bukkit.Bukkit.getScheduler().runTaskLater(bufferedEconomy.getPlugin(), () ->
|
org.bukkit.Bukkit.getScheduler().scheduleSyncDelayedTask(bufferedEconomy.getPlugin(), () ->
|
||||||
economy.depositPlayer(payment.getOfflinePlayer(), money), 1L);
|
economy.depositPlayer(payment.getOfflinePlayer(), money));
|
||||||
} else {
|
} else {
|
||||||
economy.depositPlayer(payment.getOfflinePlayer(), money);
|
economy.depositPlayer(payment.getOfflinePlayer(), money);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user