mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 05:06:45 +01:00
Furnaces can now change owners during server lifespan for Smelting XP
This commit is contained in:
parent
fdd951f1f1
commit
f6c7049cac
@ -1,7 +1,9 @@
|
||||
Version 2.1.134
|
||||
Minor code cleanup
|
||||
Smelting furnaces are now more flexible about who they consider their owner (see notes)
|
||||
Smelting now has a Bonus Drops section in config.yml
|
||||
Smelting now only doubles smelting results for items which have bonus drop entries in the config
|
||||
Smelting now only doubles smelting results for items which have bonus drop entries in config.yml
|
||||
Minor code cleanup
|
||||
Changed the UUID updater task to not catastrophically fail when requests failed
|
||||
Fixed a bug where players could set each other on fire when partied or when PVP was disabled
|
||||
Fixed a NPE that could happen with thrown potions
|
||||
Fixed a potential NPE when damaging player armor with Axes
|
||||
@ -13,7 +15,16 @@ Version 2.1.134
|
||||
Fixed a potential NPE when players right click blocks
|
||||
Fixed a locale mistake in locale hu_HU
|
||||
Fixed a locale mistake in locale ru
|
||||
Changed the UUID updater task to not catastrophically fail when requests failed
|
||||
|
||||
NOTES:
|
||||
Furnaces give XP to their owner while smelting
|
||||
You become the owner of a Furnace by doing one of the following
|
||||
1) Opening an empty furnace
|
||||
2) Interacting with a furnace
|
||||
|
||||
It used to be that Furnaces would assign an owner and that would be their owner until the server shutdown, now owners will change based on who last had their hands on the furnace.
|
||||
|
||||
You won't become the owner if you are not allowed to view the inventory of a furnace
|
||||
|
||||
Version 2.1.133
|
||||
A fix for an 'array out of bounds' error related to players clicking outside the inventory windows has been fixed
|
||||
|
@ -29,6 +29,7 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.*;
|
||||
import org.bukkit.inventory.*;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -45,26 +46,57 @@ public class InventoryListener implements Listener {
|
||||
if(WorldBlacklist.isWorldBlacklisted(event.getPlayer().getWorld()))
|
||||
return;
|
||||
|
||||
Block furnaceBlock = processInventoryOpenOrCloseEvent(event.getInventory());
|
||||
|
||||
if (furnaceBlock == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
HumanEntity player = event.getPlayer();
|
||||
|
||||
if (!UserManager.hasPlayerDataKey(player)) {
|
||||
return;
|
||||
}
|
||||
HumanEntity humanEntity = event.getPlayer();
|
||||
Player player = (Player) humanEntity;
|
||||
|
||||
//Profile not loaded
|
||||
if(UserManager.getPlayer((Player) player) == null)
|
||||
if(UserManager.getPlayer(player) == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(!furnaceBlock.hasMetadata(mcMMO.furnaceMetadataKey) && furnaceBlock.getMetadata(mcMMO.furnaceMetadataKey).size() == 0)
|
||||
furnaceBlock.setMetadata(mcMMO.furnaceMetadataKey, UserManager.getPlayer((Player) player).getPlayerMetadata());
|
||||
if(event.getInventory() instanceof Furnace) {
|
||||
|
||||
}
|
||||
Furnace furnace = getFurnace(event.getInventory());
|
||||
|
||||
if (furnace != null) {
|
||||
if(isFurnaceAvailable(furnace, player)) {
|
||||
assignFurnace(furnace, player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isFurnaceAvailable(Furnace furnace, Player player) {
|
||||
if(!furnace.hasMetadata(mcMMO.furnaceMetadataKey)
|
||||
&& furnace.getMetadata(mcMMO.furnaceMetadataKey).size() == 0) {
|
||||
return true;
|
||||
} else {
|
||||
if(player != getPlayerFromFurnace(furnace)) {
|
||||
|
||||
if(isFurnaceResultEmpty(furnace)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isFurnaceResultEmpty(Furnace furnace) {
|
||||
return furnace.getInventory().getResult() == null;
|
||||
}
|
||||
|
||||
public void assignFurnace(Furnace furnace, Player player) {
|
||||
|
||||
if(furnace.hasMetadata(mcMMO.furnaceMetadataKey)) {
|
||||
furnace.removeMetadata(mcMMO.furnaceMetadataKey, mcMMO.p);
|
||||
}
|
||||
|
||||
furnace.setMetadata(mcMMO.furnaceMetadataKey, UserManager.getPlayer(player).getPlayerMetadata());
|
||||
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
@ -73,19 +105,15 @@ public class InventoryListener implements Listener {
|
||||
if(WorldBlacklist.isWorldBlacklisted(event.getPlayer().getWorld()))
|
||||
return;
|
||||
|
||||
Block furnaceBlock = processInventoryOpenOrCloseEvent(event.getInventory());
|
||||
if(event.getInventory() instanceof FurnaceInventory) {
|
||||
if(getFurnace(event.getInventory()) != null) {
|
||||
Furnace furnace = getFurnace(event.getInventory());
|
||||
|
||||
if (furnaceBlock == null || furnaceBlock.hasMetadata(mcMMO.furnaceMetadataKey)) {
|
||||
return;
|
||||
if(isFurnaceOwned(furnace) && isFurnaceResultEmpty(furnace)) {
|
||||
removeFurnaceOwner(furnace);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HumanEntity player = event.getPlayer();
|
||||
|
||||
if (!UserManager.hasPlayerDataKey(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
furnaceBlock.removeMetadata(mcMMO.furnaceMetadataKey, plugin);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
@ -102,7 +130,9 @@ public class InventoryListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = getPlayerFromFurnace(furnaceBlock);
|
||||
Furnace furnace = (Furnace) furnaceState;
|
||||
|
||||
Player player = getPlayerFromFurnace(furnace);
|
||||
|
||||
/* WORLD GUARD MAIN FLAG CHECK */
|
||||
if(WorldGuardUtils.isWorldGuardLoaded())
|
||||
@ -137,26 +167,29 @@ public class InventoryListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = getPlayerFromFurnace(furnaceBlock);
|
||||
|
||||
/* WORLD GUARD MAIN FLAG CHECK */
|
||||
if(WorldGuardUtils.isWorldGuardLoaded())
|
||||
if(furnaceBlock instanceof Furnace)
|
||||
{
|
||||
if(!WorldGuardManager.getInstance().hasMainFlag(player))
|
||||
Player player = getPlayerFromFurnace((Furnace) furnaceBlock);
|
||||
|
||||
/* WORLD GUARD MAIN FLAG CHECK */
|
||||
if(WorldGuardUtils.isWorldGuardLoaded())
|
||||
{
|
||||
if(!WorldGuardManager.getInstance().hasMainFlag(player))
|
||||
return;
|
||||
}
|
||||
|
||||
if (!UserManager.hasPlayerDataKey(player) || !PrimarySkillType.SMELTING.getPermissions(player)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!UserManager.hasPlayerDataKey(player) || !PrimarySkillType.SMELTING.getPermissions(player)) {
|
||||
return;
|
||||
}
|
||||
//Profile not loaded
|
||||
if(UserManager.getPlayer(player) == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//Profile not loaded
|
||||
if(UserManager.getPlayer(player) == null)
|
||||
{
|
||||
return;
|
||||
event.setResult(UserManager.getPlayer(player).getSmeltingManager().smeltProcessing(smelting, event.getResult()));
|
||||
}
|
||||
|
||||
event.setResult(UserManager.getPlayer(player).getSmeltingManager().smeltProcessing(smelting, event.getResult()));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
@ -171,28 +204,31 @@ public class InventoryListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = getPlayerFromFurnace(furnaceBlock);
|
||||
if(furnaceBlock instanceof Furnace) {
|
||||
Furnace furnace = (Furnace) furnaceBlock;
|
||||
Player player = getPlayerFromFurnace(furnace);
|
||||
|
||||
/* WORLD GUARD MAIN FLAG CHECK */
|
||||
if(WorldGuardUtils.isWorldGuardLoaded())
|
||||
{
|
||||
if(!WorldGuardManager.getInstance().hasMainFlag(player))
|
||||
/* WORLD GUARD MAIN FLAG CHECK */
|
||||
if(WorldGuardUtils.isWorldGuardLoaded())
|
||||
{
|
||||
if(!WorldGuardManager.getInstance().hasMainFlag(player))
|
||||
return;
|
||||
}
|
||||
|
||||
if (!UserManager.hasPlayerDataKey(player) || !Permissions.vanillaXpBoost(player, PrimarySkillType.SMELTING)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!UserManager.hasPlayerDataKey(player) || !Permissions.vanillaXpBoost(player, PrimarySkillType.SMELTING)) {
|
||||
return;
|
||||
}
|
||||
//Profile not loaded
|
||||
if(UserManager.getPlayer(player) == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//Profile not loaded
|
||||
if(UserManager.getPlayer(player) == null)
|
||||
{
|
||||
return;
|
||||
int xpToDrop = event.getExpToDrop();
|
||||
int exp = UserManager.getPlayer(player).getSmeltingManager().vanillaXPBoost(xpToDrop);
|
||||
event.setExpToDrop(exp);
|
||||
}
|
||||
|
||||
int xpToDrop = event.getExpToDrop();
|
||||
int exp = UserManager.getPlayer(player).getSmeltingManager().vanillaXPBoost(xpToDrop);
|
||||
event.setExpToDrop(exp);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
@ -206,12 +242,13 @@ public class InventoryListener implements Listener {
|
||||
if(event.getWhoClicked() instanceof Player)
|
||||
{
|
||||
Player player = ((Player) event.getWhoClicked()).getPlayer();
|
||||
Block furnaceBlock = processInventoryOpenOrCloseEvent(event.getInventory());
|
||||
Furnace furnace = getFurnace(event.getInventory());
|
||||
|
||||
if (furnaceBlock != null)
|
||||
if (furnace != null)
|
||||
{
|
||||
if (furnaceBlock.getMetadata(mcMMO.furnaceMetadataKey).size() > 0)
|
||||
furnaceBlock.removeMetadata(mcMMO.furnaceMetadataKey, mcMMO.p);
|
||||
if (isFurnaceOwned(furnace)) {
|
||||
removeFurnaceOwner(furnace);
|
||||
}
|
||||
|
||||
//Profile not loaded
|
||||
if(UserManager.getPlayer(player) == null)
|
||||
@ -219,7 +256,7 @@ public class InventoryListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
furnaceBlock.setMetadata(mcMMO.furnaceMetadataKey, UserManager.getPlayer(player).getPlayerMetadata());
|
||||
assignFurnace(furnace, player);
|
||||
}
|
||||
}
|
||||
|
||||
@ -325,6 +362,14 @@ public class InventoryListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isFurnaceOwned(Furnace furnace) {
|
||||
return furnace.getMetadata(mcMMO.furnaceMetadataKey).size() > 0;
|
||||
}
|
||||
|
||||
public void removeFurnaceOwner(Furnace furnace) {
|
||||
furnace.removeMetadata(mcMMO.furnaceMetadataKey, mcMMO.p);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onInventoryDragEvent(InventoryDragEvent event) {
|
||||
/* WORLD BLACKLIST CHECK */
|
||||
@ -480,7 +525,7 @@ public class InventoryListener implements Listener {
|
||||
new PlayerUpdateInventoryTask((Player) whoClicked).runTaskLater(plugin, 0);
|
||||
}
|
||||
|
||||
private Block processInventoryOpenOrCloseEvent(Inventory inventory) {
|
||||
private Furnace getFurnace(Inventory inventory) {
|
||||
if (!(inventory instanceof FurnaceInventory)) {
|
||||
return null;
|
||||
}
|
||||
@ -491,11 +536,12 @@ public class InventoryListener implements Listener {
|
||||
return null;
|
||||
}
|
||||
|
||||
return furnace.getBlock();
|
||||
return furnace;
|
||||
}
|
||||
|
||||
private Player getPlayerFromFurnace(Block furnaceBlock) {
|
||||
List<MetadataValue> metadata = furnaceBlock.getMetadata(mcMMO.furnaceMetadataKey);
|
||||
@Nullable
|
||||
private Player getPlayerFromFurnace(Furnace furnace) {
|
||||
List<MetadataValue> metadata = furnace.getMetadata(mcMMO.furnaceMetadataKey);
|
||||
|
||||
if (metadata.isEmpty()) {
|
||||
return null;
|
||||
|
Loading…
Reference in New Issue
Block a user