Skip to content

Commit

Permalink
Initial work on improved furnace tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
nsporillo committed Aug 12, 2019
1 parent ebf8d7e commit ada2251
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
62 changes: 62 additions & 0 deletions src/main/java/net/porillo/listeners/CO2Listener.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,85 @@
import net.porillo.util.AlertManager;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.FurnaceBurnEvent;
import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.event.world.StructureGrowEvent;
import org.bukkit.inventory.FurnaceInventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public class CO2Listener implements Listener {

private GlobalWarming gw;
private static final UUID untrackedUUID = UUID.fromString("1-1-1-1-1");

private Map<GLocation, Map<Material, Map<UUID, Integer>>> furnaceFuelMap = new HashMap<>();

public CO2Listener(GlobalWarming main) {
this.gw = main;
}

@EventHandler
public void onFurnaceInteract(InventoryMoveItemEvent event) {
InventoryHolder initHolder = event.getInitiator().getHolder();
InventoryHolder destHolder = event.getDestination().getHolder();
ItemStack item = event.getItem();

if (!item.getType().isFuel()) {
return;
}

if (initHolder instanceof Player && destHolder instanceof org.bukkit.block.Furnace) {
// Player moves fuel into a Furnace
Player player = (Player) initHolder;
Furnace furnace = (Furnace) destHolder;


if (!ClimateEngine.getInstance().isClimateEngineEnabled(player.getWorld().getUID())) {
return;
}

FurnaceTable furnaceTable = GlobalWarming.getInstance().getTableManager().getFurnaceTable();
GLocation location = new GLocation(furnace.getLocation());

if (furnaceFuelMap.containsKey(location)) {
Map<Material, Map<UUID, Integer>> fuelMap = furnaceFuelMap.get(location);
if (fuelMap.containsKey(item.getType())) {
Map<UUID, Integer> playerMap = fuelMap.get(item.getType());
playerMap.put(player.getUniqueId(), item.getAmount());
fuelMap.put(item.getType(), playerMap);
furnaceFuelMap.put(location, fuelMap);
} else {
Map<UUID, Integer> playerMap = new HashMap<>();
playerMap.put(player.getUniqueId(), item.getAmount());
fuelMap.put(item.getType(), playerMap);
furnaceFuelMap.put(location, fuelMap);
}
} else {
// Furnace is tracked
if (furnaceTable.getLocationMap().containsKey(furnace.getLocation())) {

}
Map<Material, Map<UUID, Integer>> fuelMap = new HashMap<>();
Map<UUID, Integer> playerMap = new HashMap<>();
playerMap.put(player.getUniqueId(), item.getAmount());
fuelMap.put(item.getType(), playerMap);
furnaceFuelMap.put(location, fuelMap);
}


} else if (initHolder instanceof org.bukkit.block.Furnace && destHolder instanceof Player) {
// Player moves fuel out of a furnace
}
}

/**
* Detect when CO2 is emitted via furnace
*
Expand Down Expand Up @@ -139,6 +200,7 @@ public void onFurnaceSmelt(FurnaceBurnEvent event) {

/**
* Detect when CO2 is absorbed via new tree
*
* @param event structure grow event (tree grow)
*/
@EventHandler(ignoreCancelled = true)
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/net/porillo/objects/GLocation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package net.porillo.objects;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.bukkit.Location;

import java.io.Serializable;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class GLocation implements Serializable {

private String world;
private int x, y, z;

public GLocation(Location location) {
this.world = location.getWorld().getName();
this.x = location.getBlockX();
this.y = location.getBlockY();
this.z = location.getBlockZ();
}
}

1 comment on commit ada2251

@nsporillo
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#36

@honsq90 use this old initial work as motivation for a solution

Please sign in to comment.