feat: added fire item

This commit is contained in:
ShermansWorld committed 2024-04-11 19:36:32 -04:00
1 parent c49d45e395
commit 744d5d2d71
4 files changed
+51 -30

No files matched your search

+1 -1
View File
@@ -6,7 +6,7 @@
<groupId>com.github.alathra</groupId> <groupId>com.github.alathra</groupId>
<artifactId>SiegeEngines</artifactId> <artifactId>SiegeEngines</artifactId>
<version>1.0.0</version> <version>1.0.1</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<properties> <properties>
@@ -35,6 +35,7 @@ public class Config {
public static int configVersion = 1; public static int configVersion = 1;
public static Material controlItem = Material.CLOCK; public static Material controlItem = Material.CLOCK;
public static Material fireItem = Material.FLINT;
public static double placementDensity = 2.5d; public static double placementDensity = 2.5d;
public static int controlDistance = 10; public static int controlDistance = 10;
public static int rotateDistance = 10; public static int rotateDistance = 10;
@@ -106,6 +107,14 @@ public class Config {
.warn("Control item material could not be found, defaulting to " + controlItem.toString() + " !"); .warn("Control item material could not be found, defaulting to " + controlItem.toString() + " !");
} }
try {
fireItem = Material.getMaterial(config.getString("FireItem"));
} catch (Exception e) {
controlItem = Material.FLINT;
SiegeEnginesLogger
.warn("Control item material could not be found, defaulting to " + fireItem.toString() + " !");
}
controlDistance = config.getInt("ControlDistance"); controlDistance = config.getInt("ControlDistance");
rotateDistance = config.getInt("RotateDistance"); rotateDistance = config.getInt("RotateDistance");
placementDensity = config.getDouble("PlacementDensity"); placementDensity = config.getDouble("PlacementDensity");
@@ -2,6 +2,7 @@ package com.github.alathra.siegeengines.listeners;
import java.util.List; import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@@ -20,42 +21,49 @@ public class SiegeEngineFireListener implements Listener {
@EventHandler @EventHandler
public void onSiegeEngineFire(PlayerInteractEvent event) { public void onSiegeEngineFire(PlayerInteractEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
ItemStack ItemInHand = event.getPlayer().getInventory().getItemInMainHand(); ItemStack itemInHand = event.getPlayer().getInventory().getItemInMainHand();
if (ItemInHand == null) { if (itemInHand == null) {
return; return;
} }
if (event.getAction() == Action.RIGHT_CLICK_AIR) { if (event.getAction() == Action.RIGHT_CLICK_AIR && itemInHand.getType() == Config.controlItem) {
if (ItemInHand.getType() != Config.controlItem) {
return;
}
// If player is not sneaking, fire SiegeEngine // If player is not sneaking, fire SiegeEngine
if (!player.isSneaking()) { if (!player.isSneaking()) {
List<Entity> siegeEngineEntities = SiegeEngines.siegeEngineEntitiesPerPlayer.get(player.getUniqueId()); fire(player);
if (siegeEngineEntities == null) { }
return; return;
} } else if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
for (Entity siegeEngineEntity : siegeEngineEntities) { if (itemInHand.getType() == Config.fireItem) {
if (SiegeEngines.activeSiegeEngines.containsKey(siegeEngineEntity.getUniqueId())) { fire(player);
SiegeEngine siegeEngine = SiegeEngines.activeSiegeEngines.get(siegeEngineEntity.getUniqueId());
if (siegeEngine != null && siegeEngine.getEnabled() && !(siegeEngineEntity.isDead())
&& siegeEngine.isLoaded()) {
if (siegeEngine.isSetModelNumberWhenFullyLoaded() && siegeEngine.canLoadFuel()) {
player.sendMessage("§eFailed to fire. This siege engine needs to be fully loaded!");
} else {
siegeEngine.Fire(player, 10f, 1);
}
}
}
}
return; return;
} }
} }
// Attempt auto-reload if enabled in config
if (Config.autoReload) {
SiegeEnginesUtil.autoReload(player);
}
} }
private void fire(Player player) {
List<Entity> siegeEngineEntities = SiegeEngines.siegeEngineEntitiesPerPlayer.get(player.getUniqueId());
if (siegeEngineEntities == null) {
return;
}
for (Entity siegeEngineEntity : siegeEngineEntities) {
if (SiegeEngines.activeSiegeEngines.containsKey(siegeEngineEntity.getUniqueId())) {
SiegeEngine siegeEngine = SiegeEngines.activeSiegeEngines.get(siegeEngineEntity.getUniqueId());
if (siegeEngine != null && siegeEngine.getEnabled() && !(siegeEngineEntity.isDead())
&& siegeEngine.isLoaded()) {
if (siegeEngine.isSetModelNumberWhenFullyLoaded() && siegeEngine.canLoadFuel()) {
player.sendMessage("§eFailed to fire. This siege engine needs to be fully loaded!");
} else {
siegeEngine.Fire(player, 10f, 1);
// Attempt auto-reload if enabled in config
if (Config.autoReload) {
SiegeEnginesUtil.autoReload(player);
}
}
}
}
}
return;
}
} }
+5 -1
View File
@@ -9,7 +9,7 @@
# DO NOT CHANGE # DO NOT CHANGE
config-version: 1 config-version: 2
# ===================================== # =====================================
# | GENERAL SETTINGS | # | GENERAL SETTINGS |
@@ -22,6 +22,10 @@ Debug: false
# Must be a valid material. See https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Material.html # Must be a valid material. See https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Material.html
ControlItem: CLOCK ControlItem: CLOCK
# The item used to only fire siege engines, an alternative to using the control item
# Must be a valid material. See https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Material.html
FireItem: FLINT
# Allows the disabling of Arrow Damage towards SiegeEngines. # Allows the disabling of Arrow Damage towards SiegeEngines.
DisableArrowDamage: true DisableArrowDamage: true