Skip to content

Commit

Permalink
Implemente Silencing
Browse files Browse the repository at this point in the history
  • Loading branch information
drfiveminusmint committed Jul 2, 2024
1 parent 4cca6d8 commit 7f78bef
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
import net.countercraft.movecraft.movecraftoverheat.listener.CraftPilotListener;
import net.countercraft.movecraft.movecraftoverheat.listener.WeaponFireListener;
import net.countercraft.movecraft.movecraftoverheat.tracking.HeatManager;
import net.countercraft.movecraft.util.Tags;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;

public final class MovecraftOverheat extends JavaPlugin {
Expand Down Expand Up @@ -57,30 +59,38 @@ public void onEnable() {
Settings.DebugMode = getConfig().getBoolean("DebugMode", false);
Settings.HeatCheckInterval = getConfig().getInt("HeatCheckInterval", 1000);
Settings.DisasterCheckInterval = getConfig().getInt("DisasterCheckInterval", 10000);
Settings.SilenceOverheatedCrafts = getConfig().getBoolean("SilenceOverheatedCrafts", false);
Settings.SilenceHeatThreshold = getConfig().getDouble("SilenceHeatThreshold", 2.0);
if (getConfig().contains("HeatSinkBlocks")) {
Map<String,Object> tempMap = getConfig().getConfigurationSection("HeatSinkBlocks").getValues(false);
for(String str : tempMap.keySet()) {
Material type;
double value;
try {
type = Material.getMaterial(str);
value = (Double)tempMap.get(str);
} catch (ClassCastException ex) {
MovecraftOverheat.getInstance().getLogger().severe("Failed to load HeatSinkBlock " + str);
continue;
}
catch(NumberFormatException e) {
type = Material.getMaterial(str);
var tagged = Tags.parseMaterials(str);
for (Material m : tagged) {
Settings.HeatSinkBlocks.put(m, value);
}
Settings.HeatSinkBlocks.put(type,(Double)tempMap.get(str));
}
}
if (getConfig().contains("RadiatorBlocks")) {
Map<String,Object> tempMap = getConfig().getConfigurationSection("RadiatorBlocks").getValues(false);
for(String str : tempMap.keySet()) {
Material type;
for (String str : tempMap.keySet()) {
double value;
try {
type = Material.getMaterial(str);
value = (Double)tempMap.get(str);
} catch (ClassCastException ex) {
MovecraftOverheat.getInstance().getLogger().severe("Failed to load RadiatorBlock " + str);
continue;
}
catch(NumberFormatException e) {
type = Material.getMaterial(str);
var tagged = Tags.parseMaterials(str);
for (Material m : tagged) {
Settings.RadiatorBlocks.put(m, value);
}
Settings.RadiatorBlocks.put(type,(Double)tempMap.get(str));
}
}

Expand All @@ -106,7 +116,7 @@ public void onEnable() {
}
}

manager.runTaskTimer(this, 20, 4);
manager.runTaskTimer(this, 20, 1);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ public class Settings {
public static boolean DebugMode;
public static Map<Material, Double> RadiatorBlocks = new HashMap<>();
public static Map<Material, Double> HeatSinkBlocks = new HashMap<>();

public static boolean SilenceOverheatedCrafts = false;
public static double SilenceHeatThreshold = 2.0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public void trigger () {
currentBombs++;
}
if (currentBombs > 0) {
craft.getAudience().playSound(Sound.sound(Key.key("entity.wither.shoot"), Sound.Source.BLOCK, 5.0f, 5.0f));
craft.getAudience().playSound(Sound.sound(Key.key("entity.wither.shoot"), Sound.Source.BLOCK, 9.0f, 3.0f));
if (craft instanceof PlayerCraft) {
((PlayerCraft) craft).getPilot().sendMessage(ChatUtils.MOVECRAFT_COMMAND_PREFIX + ChatColor.RED+ " Your craft has overheated and suffered an explosion!");
((PlayerCraft) craft).getPilot().sendMessage(ChatUtils.MOVECRAFT_COMMAND_PREFIX + ChatColor.RED+ "Your craft has overheated and suffered an explosion!");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void trigger () {
if (currentFires > 0) {
craft.getAudience().playSound(Sound.sound(Key.key("item.firecharge.use"), Sound.Source.BLOCK, 5.0f, 5.0f));
if (craft instanceof PlayerCraft) {
((PlayerCraft) craft).getPilot().sendMessage(ChatUtils.MOVECRAFT_COMMAND_PREFIX + ChatColor.RED+ " The heat of your craft has set it ablaze!");
((PlayerCraft) craft).getPilot().sendMessage(ChatUtils.MOVECRAFT_COMMAND_PREFIX + ChatColor.RED+ "The heat of your craft has set it ablaze!");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@
import net.countercraft.movecraft.movecraftoverheat.config.Settings;
import net.countercraft.movecraft.movecraftoverheat.tracking.CraftHeat;
import net.countercraft.movecraft.util.MathUtils;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.sound.Sound;
import org.bukkit.Location;
import org.bukkit.Material;

import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockDispenseEvent;
import org.bukkit.event.entity.EntityExplodeEvent;

public class WeaponFireListener implements Listener {

@EventHandler (priority = EventPriority.HIGHEST, ignoreCancelled = true)
@EventHandler (priority = EventPriority.HIGHEST)
public void onWeaponFire (CraftFireWeaponEvent event) {
Craft craft = event.getCraft();
CraftHeat craftHeat = MovecraftOverheat.getInstance().getHeatManager().getHeat(craft);
Expand All @@ -46,6 +49,18 @@ public void onWeaponFire (CraftFireWeaponEvent event) {
}
}

@EventHandler (priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockDispense (BlockDispenseEvent event) {
Craft craft = MathUtils.fastNearestCraftToLoc(CraftManager.getInstance().getCrafts(), event.getBlock().getLocation());
CraftHeat heat = MovecraftOverheat.getInstance().getHeatManager().getHeat(craft);
if (heat != null) {
if (heat.isSilenced() && craft.getHitBox().contains(MathUtils.bukkit2MovecraftLoc(event.getBlock().getLocation()))) {
event.setCancelled(true);
craft.getAudience().playSound(Sound.sound(Key.key("block.dispenser.fail"), Sound.Source.BLOCK, 1f, 1f));
}
}
}

@EventHandler (priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEntityExplode (EntityExplodeEvent event) {
// Don't run this check if there's no per shot heat cost
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
import net.countercraft.movecraft.movecraftoverheat.MovecraftOverheat;
import net.countercraft.movecraft.movecraftoverheat.config.Settings;
import net.countercraft.movecraft.movecraftoverheat.disaster.DisasterType;
import net.countercraft.movecraft.util.ChatUtils;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.sound.Sound;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.boss.BarColor;
import org.bukkit.boss.BarStyle;
Expand Down Expand Up @@ -83,9 +88,22 @@ public void processDissipation () {
}

public void checkDisasters () {
// Update whether the craft is silenced
if (silenced) {
if (heat < heatCapacity * Settings.SilenceHeatThreshold) {
craft.getAudience().sendMessage(Component.text(ChatUtils.MOVECRAFT_COMMAND_PREFIX + "No longer silenced!"));
silenced = false;
}
} else {
if (Settings.SilenceOverheatedCrafts && heat > heatCapacity * Settings.SilenceHeatThreshold) {
craft.getAudience().sendMessage(Component.text(ChatUtils.MOVECRAFT_COMMAND_PREFIX + ChatColor.RED + "Silenced! Your guns are too hot to fire!"));
craft.getAudience().playSound(Sound.sound(Key.key("entity.blaze.death"), Sound.Source.BLOCK, 2.0f, 1.0f));
silenced = true;
}
}
for (DisasterType type : MovecraftOverheat.getDisasterTypes()) {
if (type.getHeatThreshold() * heatCapacity > heat) continue;
if (1-((1-type.getRandomChance()) * (Math.exp(-1 * type.getRandomChancePowerFactor() * (heat-type.getHeatThreshold())))) < Math.random()) continue;
if ((1-type.getRandomChance()) * (Math.exp(-1 * type.getRandomChancePowerFactor() * ((heat/heatCapacity)-type.getHeatThreshold()))) > Math.random()) continue;
MovecraftOverheat.getInstance().getHeatManager().addDisaster(type.createNew(this));
lastDisaster = System.currentTimeMillis();
}
Expand Down

0 comments on commit 7f78bef

Please sign in to comment.