generated from Slimefun/Addon-Template
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⚡ work(ElectricalStimulator): Make Inventory ceck much less costly. T…
…hanks for the help Walshy
- Loading branch information
1 parent
64b9146
commit 0f40e33
Showing
2 changed files
with
68 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
## Steam Revolution | ||
- **Steam Tank** : A tank that hold steams for all machines in a Steam network can grab and use | ||
- **Boiler** : Takes in water and coal and produces steam. | ||
- **Furnace Heater** : When placed adjacent to a furnace powers it using steam instead of conventional materials | ||
- **Steam Turbine** : Takes in steam and produces electricity |
126 changes: 63 additions & 63 deletions
126
src/main/java/me/profelements/dynatech/listeners/ElectricalStimulatorListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,63 @@ | ||
package me.profelements.dynatech.listeners; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import me.mrCookieSlime.Slimefun.api.Slimefun; | ||
import me.profelements.dynatech.DynaTech; | ||
import me.profelements.dynatech.items.tools.ElectricalStimulator; | ||
|
||
import org.bukkit.Sound; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.entity.EntityDamageEvent; | ||
import org.bukkit.event.entity.FoodLevelChangeEvent; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
public class ElectricalStimulatorListener implements Listener { | ||
|
||
private final ElectricalStimulator electricalStimulator; | ||
|
||
public ElectricalStimulatorListener(@Nonnull DynaTech plugin, @Nonnull ElectricalStimulator electricalStimulator) { | ||
plugin.getServer().getPluginManager().registerEvents(this, plugin); | ||
this.electricalStimulator = electricalStimulator; | ||
} | ||
|
||
@EventHandler | ||
public void onHungerLoss(FoodLevelChangeEvent e) { | ||
if (e.getEntity() instanceof Player) { | ||
Player p = (Player) e.getEntity(); | ||
if (e.getFoodLevel() < p.getFoodLevel()) { | ||
feedPlayer((Player) e.getEntity()); | ||
} | ||
} | ||
} | ||
|
||
@EventHandler | ||
public void onHungerDamage(EntityDamageEvent e) { | ||
if (e.getEntity() instanceof Player && e.getCause() == EntityDamageEvent.DamageCause.STARVATION) { | ||
feedPlayer((Player) e.getEntity()); | ||
} | ||
} | ||
|
||
private void feedPlayer(Player p) { | ||
if (electricalStimulator == null || electricalStimulator.isDisabled()) { | ||
return; | ||
} | ||
|
||
for (ItemStack item : p.getInventory().getStorageContents()) { | ||
if (electricalStimulator.isItem(item)) { | ||
if (Slimefun.hasUnlocked(p, item, true)) { | ||
p.setFoodLevel(20); | ||
p.setSaturation(20f); | ||
p.playSound(p.getLocation(), Sound.ENTITY_PLAYER_BURP, 1F , 1F); | ||
electricalStimulator.removeItemCharge(item, electricalStimulator.getEnergyComsumption()); | ||
break; | ||
} else { | ||
return; | ||
} | ||
} | ||
} | ||
} | ||
|
||
} | ||
package me.profelements.dynatech.listeners; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import me.mrCookieSlime.Slimefun.api.Slimefun; | ||
import me.profelements.dynatech.DynaTech; | ||
import me.profelements.dynatech.items.tools.ElectricalStimulator; | ||
|
||
import org.bukkit.Sound; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.entity.EntityDamageEvent; | ||
import org.bukkit.event.entity.FoodLevelChangeEvent; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
public class ElectricalStimulatorListener implements Listener { | ||
|
||
private final ElectricalStimulator electricalStimulator; | ||
|
||
public ElectricalStimulatorListener(@Nonnull DynaTech plugin, @Nonnull ElectricalStimulator electricalStimulator) { | ||
plugin.getServer().getPluginManager().registerEvents(this, plugin); | ||
this.electricalStimulator = electricalStimulator; | ||
} | ||
|
||
@EventHandler | ||
public void onHungerLoss(FoodLevelChangeEvent e) { | ||
if (e.getEntity() instanceof Player) { | ||
Player p = (Player) e.getEntity(); | ||
if (e.getFoodLevel() < p.getFoodLevel()) { | ||
feedPlayer((Player) e.getEntity()); | ||
} | ||
} | ||
} | ||
|
||
@EventHandler | ||
public void onHungerDamage(EntityDamageEvent e) { | ||
if (e.getEntity() instanceof Player && e.getCause() == EntityDamageEvent.DamageCause.STARVATION) { | ||
feedPlayer((Player) e.getEntity()); | ||
} | ||
} | ||
|
||
private void feedPlayer(Player p) { | ||
if (electricalStimulator == null || electricalStimulator.isDisabled()) { | ||
return; | ||
} | ||
|
||
for (ItemStack item : p.getInventory().getStorageContents()) { | ||
if (item.getType() == electricalStimulator.getItem().getType() && item.hasItemMeta() && electricalStimulator.isItem(item)) { | ||
if (Slimefun.hasUnlocked(p, item, true)) { | ||
p.setFoodLevel(20); | ||
p.setSaturation(20f); | ||
p.playSound(p.getLocation(), Sound.ENTITY_PLAYER_BURP, 1F , 1F); | ||
electricalStimulator.removeItemCharge(item, electricalStimulator.getEnergyComsumption()); | ||
break; | ||
} else { | ||
return; | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |