Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,21 @@ public interface StackedSpawner extends StackedObject<CreatureSpawner>, Upgradea
*/
ItemStack getDropItem(int amount);

/**
* Check if the spawner is natural.
* A natural spawner is a spawner that was generated by the world and not placed by a player.
*
* @return true if the spawner is natural, false otherwise.
*/
boolean isNatural();

/**
* Set the natural state of the spawner.
* This is used to mark a spawner as natural or not.
*
* @param natural true if the spawner is natural, false otherwise.
*/
void setNatural(boolean natural);


}
1 change: 1 addition & 0 deletions src/main/java/com/bgsoftware/wildstacker/Locale.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public final class Locale {
public static Locale ONLY_ONE_SPAWNER = new Locale("ONLY_ONE_SPAWNER");
public static Locale RELOAD_SUCCESS = new Locale("RELOAD_SUCCESS");
public static Locale SPAWNER_BREAK = new Locale("SPAWNER_BREAK");
public static Locale SPAWNER_BREAK_NATURAL_NOT_ALLOWED = new Locale("SPAWNER_BREAK_NATURAL_NOT_ALLOWED");
public static Locale SPAWNER_BREAK_NOT_ENOUGH_MONEY = new Locale("SPAWNER_BREAK_NOT_ENOUGH_MONEY");
public static Locale SPAWNER_BREAK_WITHOUT_SILK = new Locale("SPAWNER_BREAK_WITHOUT_SILK");
public static Locale SPAWNER_PLACE = new Locale("SPAWNER_PLACE");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public final class SettingsHandler {
public final List<ParticleWrapper> entitiesParticles;

//Spawners settings
public final boolean spawnersStackingEnabled, perSpawnerLimit, spawnersParticlesEnabled, chunkMergeSpawners,
public final boolean spawnersStackingEnabled, allowBreakVanillaSpawners, perSpawnerLimit, spawnersParticlesEnabled, chunkMergeSpawners,
silkTouchSpawners, explosionsDropSpawner, explosionsDropToInventory, dropToInventory, shiftGetWholeSpawnerStack,
getStackedItem, dropSpawnerWithoutSilk, spawnersMineRequireSilk, floatingSpawnerNames, spawnersPlacementPermission,
spawnersShiftPlaceStack, changeUsingEggs, eggsStackMultiply, nextSpawnerPlacement, onlyOneSpawner, inventoryTweaksEnabled,
Expand Down Expand Up @@ -295,6 +295,7 @@ public SettingsHandler(WildStackerPlugin plugin) {
entitiesFillVehicles = cfg.getBoolean("entities.entities-fill-vehicles");

spawnersStackingEnabled = cfg.getBoolean("spawners.enabled", true);
allowBreakVanillaSpawners = cfg.getBoolean("spawners.allow-break-vanilla-spawners", true);
spawnersMergeRadius = FastEnumMap.fromSection(cfg.getConfigurationSection("spawners.merge-radius"), EntityType.class);
perSpawnerLimit = cfg.getBoolean("spawners.per-spawner-limit", false);
spawnersParticlesEnabled = cfg.getBoolean("spawners.particles", true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@ public StackedSpawner getStackedSpawner(Location location) {
//Spawner wasn't found, creating a new object
stackedSpawner = new WStackedSpawner((CreatureSpawner) location.getBlock().getState());


if (!dataHandler.CACHED_SPAWNERS_RAW.containsKey(location)) {
stackedSpawner.setNatural(true);
}

//A new spawner was created. Let's see if we need to add him
if (stackedSpawner.isCached())
dataHandler.addStackedSpawner(stackedSpawner);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public void onBlockPlace(BlockPlaceEvent e) {

try {
StackedSpawner stackedSpawner = WStackedSpawner.of(e.getBlockPlaced());

stackedSpawner.setNatural(false);
if (!stackedSpawner.isCached())
return;

Expand Down Expand Up @@ -334,6 +334,15 @@ public void onBlockBreak(BlockBreakEvent e) {
return;

StackedSpawner stackedSpawner = WStackedSpawner.of(e.getBlock());

if (stackedSpawner.isNatural()) {
if (!plugin.getSettings().allowBreakVanillaSpawners && !e.getPlayer().hasPermission("wildstacker.break.natural.bypass")) {
e.setCancelled(true);
Locale.SPAWNER_BREAK_NATURAL_NOT_ALLOWED.send(e.getPlayer());
}
return;
}

CreatureSpawner creatureSpawner = (CreatureSpawner) e.getBlock().getState();

e.setCancelled(true);
Expand Down Expand Up @@ -570,6 +579,11 @@ public void onSpawnerChange(PlayerInteractEvent e) {

StackedSpawner stackedSpawner = WStackedSpawner.of(e.getClickedBlock());

if (stackedSpawner.isNatural() && !plugin.getSettings().allowBreakVanillaSpawners && !e.getPlayer().hasPermission("wildstacker.break.natural.bypass")) {
e.setCancelled(true);
return;
}

if (!plugin.getSettings().changeUsingEggs) {
e.setCancelled(true);

Expand Down Expand Up @@ -615,6 +629,11 @@ public void onSpawnerInteract(PlayerInteractEvent e) {

StackedSpawner stackedSpawner = WStackedSpawner.of(e.getClickedBlock());

if (stackedSpawner.isNatural() && !plugin.getSettings().allowBreakVanillaSpawners && !e.getPlayer().hasPermission("wildstacker.break.natural.bypass")) {
e.setCancelled(true);
return;
}

if (plugin.getSettings().manageMenuEnabled && (!plugin.getSettings().sneakingOpenMenu || e.getPlayer().isSneaking())) {
SpawnersManageMenu.open(e.getPlayer(), stackedSpawner);
e.setCancelled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public final class WStackedSpawner extends WStackedHologramObject<CreatureSpawne
private int spawnerUpgradeId = -1;
private EntityType cachedEntity;
private boolean isSpawnerOverridenTick;
private boolean isNatural = false;
private boolean debug = false;

public WStackedSpawner(CreatureSpawner creatureSpawner) {
Expand Down Expand Up @@ -166,6 +167,14 @@ public boolean isCached() {
return plugin.getSettings().spawnersStackingEnabled && (!isDefaultUpgrade() || super.isCached());
}

public boolean isNatural() {
return isNatural;
}

public void setNatural(boolean natural) {
this.isNatural = natural;
}

@Override
public void remove() {
if (!Bukkit.isPrimaryThread()) {
Expand Down Expand Up @@ -257,6 +266,7 @@ public Optional<CreatureSpawner> runStack() {
Optional<StackedSpawner> spawnerOptional = GeneralUtils.getClosest(blockLocation, spawnerStream
.filter(stackedSpawner -> runStackCheck(stackedSpawner) == StackCheckResult.SUCCESS));


if (spawnerOptional.isPresent()) {
StackedSpawner targetSpawner = spawnerOptional.get();

Expand All @@ -280,6 +290,10 @@ public StackResult runStack(StackedObject stackedObject) {

StackedSpawner targetSpawner = (StackedSpawner) stackedObject;

if (!plugin.getSettings().allowBreakVanillaSpawners && targetSpawner.isNatural()) {
return StackResult.NOT_SIMILAR;
}

if (!EventsCaller.callSpawnerStackEvent(targetSpawner, this))
return StackResult.EVENT_CANCELLED;

Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,9 @@ spawners:
# Should spawners get stacked on the server?
enabled: true

# Should vanilla spawners be allowed to break?
allow-break-vanilla-spawners: true

# How many blocks from the spawner should be checked for other spawners to stack into?
# EntityType list: https://bg-software.com/entities/
merge-radius:
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/lang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ RELOAD_SUCCESS: '&6&lWildStacker &7Successfully reloaded the configuration files

# Called when a player places / breaks a spawner
SPAWNER_BREAK: '&6&lWildStacker &7You broke a {0} spawner (x{1}) and were charged for ${2}.'
SPAWNER_BREAK_NATURAL_NOT_ALLOWED: '&6&lWildStacker &7You cannot break natural spawners.'
SPAWNER_BREAK_NOT_ENOUGH_MONEY: '&6&lWildStacker &fYou need {0} in order to break this amount of spawners.'
SPAWNER_BREAK_WITHOUT_SILK: '&6&lWildStacker &7You must have a silk touch in order to break spawners.'
SPAWNER_PLACE: '&6&lWildStacker &7You placed a {0} spawner (x{1}) and were charged for ${2}.'
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,6 @@ permissions:
default: true
description: Gives access to use the toggle command if enabled.
wildstacker.charge.bypass:
description: Bypass charging for placing and breaking spawners
description: Bypass charging for placing and breaking spawners
wildstacker.break.natural.bypass:
description: Bypass breaking natural spawners.