Skip to content

Commit

Permalink
Added the ability to disable different upgrade types completely
Browse files Browse the repository at this point in the history
  • Loading branch information
OmerBenGera committed Jan 6, 2022
1 parent 9e993d5 commit f294eaf
Show file tree
Hide file tree
Showing 19 changed files with 998 additions and 671 deletions.
@@ -1,14 +1,22 @@
package com.bgsoftware.superiorskyblock.module.upgrades.listeners;

import com.bgsoftware.superiorskyblock.module.BuiltinModules;
import com.bgsoftware.superiorskyblock.module.upgrades.type.UpgradeTypeSpawnerRates;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

import javax.annotation.Nullable;

public final class WildStackerListener implements Listener {

@Nullable
private final UpgradeTypeSpawnerRates spawnerRates = BuiltinModules.UPGRADES
.getEnabledUpgradeType(UpgradeTypeSpawnerRates.class);

@EventHandler
public void onWildStackerStackSpawn(com.bgsoftware.wildstacker.api.events.SpawnerStackedEntitySpawnEvent e) {
if (UpgradesListener.IMP != null)
UpgradesListener.IMP.handleSpawnerSpawn(e.getSpawner());
if (spawnerRates != null)
spawnerRates.handleSpawnerSpawn(e.getSpawner());
}

}
Expand Up @@ -10,6 +10,12 @@
import com.bgsoftware.superiorskyblock.key.Key;
import com.bgsoftware.superiorskyblock.module.BuiltinModules;
import com.bgsoftware.superiorskyblock.lang.PlayerLocales;
import com.bgsoftware.superiorskyblock.module.upgrades.type.UpgradeTypeBlockLimits;
import com.bgsoftware.superiorskyblock.module.upgrades.type.UpgradeTypeCropGrowth;
import com.bgsoftware.superiorskyblock.module.upgrades.type.UpgradeTypeEntityLimits;
import com.bgsoftware.superiorskyblock.module.upgrades.type.UpgradeTypeIslandEffects;
import com.bgsoftware.superiorskyblock.module.upgrades.type.UpgradeTypeMobDrops;
import com.bgsoftware.superiorskyblock.module.upgrades.type.UpgradeTypeSpawnerRates;
import com.bgsoftware.superiorskyblock.utils.StringUtils;
import com.bgsoftware.superiorskyblock.utils.islands.IslandUtils;
import com.bgsoftware.superiorskyblock.wrappers.SBlockPosition;
Expand Down Expand Up @@ -135,7 +141,9 @@ public void execute(SuperiorSkyblockPlugin plugin, CommandSender sender, Superio
if (!Message.ISLAND_INFO_PAYPAL.isEmpty(locale))
infoMessage.append(Message.ISLAND_INFO_PAYPAL.getMessage(locale, island.getPaypal())).append("\n");

if (BuiltinModules.UPGRADES.isEnabled()) {
boolean upgradesModule = BuiltinModules.UPGRADES.isEnabled();

if (upgradesModule) {
// Island upgrades
if (!Message.ISLAND_INFO_ADMIN_UPGRADES.isEmpty(locale) && !Message.ISLAND_INFO_ADMIN_UPGRADE_LINE.isEmpty(locale)) {
StringBuilder upgradesString = new StringBuilder();
Expand Down Expand Up @@ -186,54 +194,61 @@ public void execute(SuperiorSkyblockPlugin plugin, CommandSender sender, Superio
infoMessage.append("\n");
}

if (BuiltinModules.UPGRADES.isEnabled()) {
if (upgradesModule) {
// Island spawners multiplier
if (!Message.ISLAND_INFO_ADMIN_SPAWNERS_MULTIPLIER.isEmpty(locale)) {
if (!Message.ISLAND_INFO_ADMIN_SPAWNERS_MULTIPLIER.isEmpty(locale) &&
BuiltinModules.UPGRADES.isUpgradeTypeEnabled(UpgradeTypeSpawnerRates.class)) {
infoMessage.append(Message.ISLAND_INFO_ADMIN_SPAWNERS_MULTIPLIER.getMessage(locale, island.getSpawnerRatesMultiplier()));
if (island.getSpawnerRatesRaw() != island.getSpawnerRatesMultiplier())
infoMessage.append(" ").append(Message.ISLAND_INFO_ADMIN_VALUE_SYNCED.getMessage(locale));
infoMessage.append("\n");
}

// Island drops multiplier
if (!Message.ISLAND_INFO_ADMIN_DROPS_MULTIPLIER.isEmpty(locale)) {
if (!Message.ISLAND_INFO_ADMIN_DROPS_MULTIPLIER.isEmpty(locale) &&
BuiltinModules.UPGRADES.isUpgradeTypeEnabled(UpgradeTypeMobDrops.class)) {
infoMessage.append(Message.ISLAND_INFO_ADMIN_DROPS_MULTIPLIER.getMessage(locale, island.getMobDropsMultiplier()));
if (island.getMobDropsRaw() != island.getMobDropsMultiplier())
infoMessage.append(" ").append(Message.ISLAND_INFO_ADMIN_VALUE_SYNCED.getMessage(locale));
infoMessage.append("\n");
}

// Island crops multiplier
if (!Message.ISLAND_INFO_ADMIN_CROPS_MULTIPLIER.isEmpty(locale)) {
if (!Message.ISLAND_INFO_ADMIN_CROPS_MULTIPLIER.isEmpty(locale) &&
BuiltinModules.UPGRADES.isUpgradeTypeEnabled(UpgradeTypeCropGrowth.class)) {
infoMessage.append(Message.ISLAND_INFO_ADMIN_CROPS_MULTIPLIER.getMessage(locale, island.getCropGrowthMultiplier()));
if (island.getCropGrowthRaw() != island.getCropGrowthMultiplier())
infoMessage.append(" ").append(Message.ISLAND_INFO_ADMIN_VALUE_SYNCED.getMessage(locale));
infoMessage.append("\n");
}
}

// Island entity limits
if (!Message.ISLAND_INFO_ADMIN_ENTITIES_LIMITS.isEmpty(locale) && !Message.ISLAND_INFO_ADMIN_ENTITIES_LIMITS_LINE.isEmpty(locale)) {
StringBuilder entitiesString = new StringBuilder();
for (Map.Entry<com.bgsoftware.superiorskyblock.api.key.Key, Integer> entry : island.getEntitiesLimitsAsKeys().entrySet()) {
entitiesString.append(Message.ISLAND_INFO_ADMIN_ENTITIES_LIMITS_LINE.getMessage(locale, StringUtils.format(entry.getKey().toString()), entry.getValue()));
if (!island.getCustomEntitiesLimits().containsKey(entry.getKey()))
entitiesString.append(" ").append(Message.ISLAND_INFO_ADMIN_VALUE_SYNCED.getMessage(locale));
entitiesString.append("\n");
// Island entity limits
if (!Message.ISLAND_INFO_ADMIN_ENTITIES_LIMITS.isEmpty(locale) &&
!Message.ISLAND_INFO_ADMIN_ENTITIES_LIMITS_LINE.isEmpty(locale) &&
BuiltinModules.UPGRADES.isUpgradeTypeEnabled(UpgradeTypeEntityLimits.class)) {
StringBuilder entitiesString = new StringBuilder();
for (Map.Entry<com.bgsoftware.superiorskyblock.api.key.Key, Integer> entry : island.getEntitiesLimitsAsKeys().entrySet()) {
entitiesString.append(Message.ISLAND_INFO_ADMIN_ENTITIES_LIMITS_LINE.getMessage(locale, StringUtils.format(entry.getKey().toString()), entry.getValue()));
if (!island.getCustomEntitiesLimits().containsKey(entry.getKey()))
entitiesString.append(" ").append(Message.ISLAND_INFO_ADMIN_VALUE_SYNCED.getMessage(locale));
entitiesString.append("\n");
}
infoMessage.append(Message.ISLAND_INFO_ADMIN_ENTITIES_LIMITS.getMessage(locale, entitiesString));
}
infoMessage.append(Message.ISLAND_INFO_ADMIN_ENTITIES_LIMITS.getMessage(locale, entitiesString));
}

// Island block limits
if (!Message.ISLAND_INFO_ADMIN_BLOCKS_LIMITS.isEmpty(locale) && !Message.ISLAND_INFO_ADMIN_BLOCKS_LIMITS_LINE.isEmpty(locale)) {
StringBuilder blocksString = new StringBuilder();
for (Map.Entry<com.bgsoftware.superiorskyblock.api.key.Key, Integer> entry : island.getBlocksLimits().entrySet()) {
blocksString.append(Message.ISLAND_INFO_ADMIN_BLOCKS_LIMITS_LINE.getMessage(locale, StringUtils.format(entry.getKey().toString()), entry.getValue()));
if (!island.getCustomBlocksLimits().containsKey(entry.getKey()))
blocksString.append(" ").append(Message.ISLAND_INFO_ADMIN_VALUE_SYNCED.getMessage(locale));
blocksString.append("\n");
// Island block limits
if (!Message.ISLAND_INFO_ADMIN_BLOCKS_LIMITS.isEmpty(locale) &&
!Message.ISLAND_INFO_ADMIN_BLOCKS_LIMITS_LINE.isEmpty(locale) &&
BuiltinModules.UPGRADES.isUpgradeTypeEnabled(UpgradeTypeBlockLimits.class)) {
StringBuilder blocksString = new StringBuilder();
for (Map.Entry<com.bgsoftware.superiorskyblock.api.key.Key, Integer> entry : island.getBlocksLimits().entrySet()) {
blocksString.append(Message.ISLAND_INFO_ADMIN_BLOCKS_LIMITS_LINE.getMessage(locale, StringUtils.format(entry.getKey().toString()), entry.getValue()));
if (!island.getCustomBlocksLimits().containsKey(entry.getKey()))
blocksString.append(" ").append(Message.ISLAND_INFO_ADMIN_VALUE_SYNCED.getMessage(locale));
blocksString.append("\n");
}
infoMessage.append(Message.ISLAND_INFO_ADMIN_BLOCKS_LIMITS.getMessage(locale, blocksString));
}
infoMessage.append(Message.ISLAND_INFO_ADMIN_BLOCKS_LIMITS.getMessage(locale, blocksString));
}

if (BuiltinModules.GENERATORS.isEnabled()) {
Expand All @@ -259,9 +274,11 @@ public void execute(SuperiorSkyblockPlugin plugin, CommandSender sender, Superio
}
}

if (BuiltinModules.UPGRADES.isEnabled()) {
if (upgradesModule) {
// Island effects
if (!Message.ISLAND_INFO_ADMIN_ISLAND_EFFECTS.isEmpty(locale) && !Message.ISLAND_INFO_ADMIN_ISLAND_EFFECTS_LINE.isEmpty(locale)) {
if (!Message.ISLAND_INFO_ADMIN_ISLAND_EFFECTS.isEmpty(locale) &&
!Message.ISLAND_INFO_ADMIN_ISLAND_EFFECTS_LINE.isEmpty(locale) &&
BuiltinModules.UPGRADES.isUpgradeTypeEnabled(UpgradeTypeIslandEffects.class)) {
StringBuilder blocksString = new StringBuilder();
for (Map.Entry<PotionEffectType, Integer> entry : island.getPotionEffects().entrySet()) {
blocksString.append(Message.ISLAND_INFO_ADMIN_ISLAND_EFFECTS_LINE.getMessage(locale, StringUtils.format(entry.getKey().getName()), entry.getValue())).append("\n");
Expand Down
44 changes: 32 additions & 12 deletions src/main/java/com/bgsoftware/superiorskyblock/island/SIsland.java
Expand Up @@ -37,6 +37,8 @@
import com.bgsoftware.superiorskyblock.menu.SuperiorMenu;
import com.bgsoftware.superiorskyblock.mission.MissionData;
import com.bgsoftware.superiorskyblock.module.BuiltinModules;
import com.bgsoftware.superiorskyblock.module.upgrades.type.UpgradeTypeCropGrowth;
import com.bgsoftware.superiorskyblock.module.upgrades.type.UpgradeTypeIslandEffects;
import com.bgsoftware.superiorskyblock.structure.CompletableFutureList;
import com.bgsoftware.superiorskyblock.threads.Executor;
import com.bgsoftware.superiorskyblock.threads.SyncedObject;
Expand Down Expand Up @@ -1384,15 +1386,21 @@ public void setIslandSize(int islandSize) {

PluginDebugger.debug("Action: Set Size, Island: " + owner.getName() + ", Size: " + islandSize);

// First, we want to remove all the current crop tile entities
getLoadedChunks(true, false).forEach(chunk ->
plugin.getNMSChunks().startTickingChunk(this, chunk, true));
boolean cropGrowthEnabled = BuiltinModules.UPGRADES.isUpgradeTypeEnabled(UpgradeTypeCropGrowth.class);

if (cropGrowthEnabled) {
// First, we want to remove all the current crop tile entities
getLoadedChunks(true, false).forEach(chunk ->
plugin.getNMSChunks().startTickingChunk(this, chunk, true));
}

this.islandSize = new UpgradeValue<>(islandSize, false);

// Now, we want to update the tile entities again
getLoadedChunks(true, false).forEach(chunk ->
plugin.getNMSChunks().startTickingChunk(this, chunk, false));
if (cropGrowthEnabled) {
// Now, we want to update the tile entities again
getLoadedChunks(true, false).forEach(chunk ->
plugin.getNMSChunks().startTickingChunk(this, chunk, false));
}

IslandsDatabaseBridge.saveSize(this);
}
Expand Down Expand Up @@ -2336,22 +2344,34 @@ public Map<PotionEffectType, Integer> getPotionEffects() {
@Override
public void applyEffects(SuperiorPlayer superiorPlayer) {
Preconditions.checkNotNull(superiorPlayer, "superiorPlayer parameter cannot be null.");

if (!BuiltinModules.UPGRADES.isUpgradeTypeEnabled(UpgradeTypeIslandEffects.class))
return;

Player player = superiorPlayer.asPlayer();
if (player != null)
getPotionEffects().forEach((potionEffectType, level) -> player.addPotionEffect(new PotionEffect(potionEffectType, Integer.MAX_VALUE, level - 1), true));
if (player != null) {
getPotionEffects().forEach((potionEffectType, level) -> player.addPotionEffect(
new PotionEffect(potionEffectType, Integer.MAX_VALUE, level - 1), true));
}
}

@Override
public void removeEffects(SuperiorPlayer superiorPlayer) {
Preconditions.checkNotNull(superiorPlayer, "superiorPlayer parameter cannot be null.");
Player player = superiorPlayer.asPlayer();
if (player != null)
getPotionEffects().keySet().forEach(player::removePotionEffect);
if (BuiltinModules.UPGRADES.isUpgradeTypeEnabled(UpgradeTypeIslandEffects.class))
removeEffectsNoUpgradeCheck(superiorPlayer);
}

@Override
public void removeEffects() {
getAllPlayersInside().forEach(this::removeEffects);
if (BuiltinModules.UPGRADES.isUpgradeTypeEnabled(UpgradeTypeIslandEffects.class))
getAllPlayersInside().forEach(this::removeEffectsNoUpgradeCheck);
}

private void removeEffectsNoUpgradeCheck(SuperiorPlayer superiorPlayer) {
Player player = superiorPlayer.asPlayer();
if (player != null)
getPotionEffects().keySet().forEach(player::removePotionEffect);
}

@Override
Expand Down
@@ -1,18 +1,20 @@
package com.bgsoftware.superiorskyblock.listeners;

import com.bgsoftware.superiorskyblock.lang.Message;
import com.bgsoftware.common.reflection.ReflectMethod;
import com.bgsoftware.superiorskyblock.SuperiorSkyblockPlugin;
import com.bgsoftware.superiorskyblock.api.island.Island;
import com.bgsoftware.superiorskyblock.api.wrappers.SuperiorPlayer;
import com.bgsoftware.superiorskyblock.key.ConstantKeys;
import com.bgsoftware.superiorskyblock.key.Key;
import com.bgsoftware.superiorskyblock.lang.Message;
import com.bgsoftware.superiorskyblock.menu.StackedBlocksDepositMenu;
import com.bgsoftware.superiorskyblock.threads.Executor;
import com.bgsoftware.superiorskyblock.utils.LocationUtils;
import com.bgsoftware.superiorskyblock.utils.logic.ProtectionLogic;
import com.bgsoftware.superiorskyblock.world.chunks.ChunksTracker;
import com.bgsoftware.superiorskyblock.utils.ServerVersion;
import com.bgsoftware.superiorskyblock.utils.logic.BlocksLogic;
import com.bgsoftware.superiorskyblock.utils.logic.ProtectionLogic;
import com.bgsoftware.superiorskyblock.utils.logic.StackedBlocksLogic;
import com.bgsoftware.superiorskyblock.threads.Executor;
import com.bgsoftware.superiorskyblock.world.chunks.ChunksTracker;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
Expand All @@ -21,6 +23,7 @@
import org.bukkit.entity.Entity;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.IronGolem;
import org.bukkit.entity.Minecart;
import org.bukkit.entity.Snowman;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.entity.Wither;
Expand All @@ -47,21 +50,21 @@
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerBucketFillEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.vehicle.VehicleDestroyEvent;
import org.bukkit.event.world.StructureGrowEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;

@SuppressWarnings("unused")
public final class BlocksListener implements Listener {

private final SuperiorSkyblockPlugin plugin;
private static final ReflectMethod<EquipmentSlot> INTERACT_GET_HAND = new ReflectMethod<>(
PlayerInteractEvent.class, "getHand");

private final Set<UUID> recentlyClicked = new HashSet<>();
private final SuperiorSkyblockPlugin plugin;

public BlocksListener(SuperiorSkyblockPlugin plugin) {
this.plugin = plugin;
Expand Down Expand Up @@ -327,8 +330,10 @@ public void onBlockUnstack(BlockBreakEvent e) {

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockUnstack(PlayerInteractEvent e) {
if (e.getAction() != Action.RIGHT_CLICK_BLOCK || e.getItem() != null ||
recentlyClicked.contains(e.getPlayer().getUniqueId()))
if (e.getAction() != Action.RIGHT_CLICK_BLOCK || e.getItem() != null)
return;

if (INTERACT_GET_HAND.isValid() && INTERACT_GET_HAND.invoke(e) != EquipmentSlot.HAND)
return;

if (plugin.getStackedBlocks().getStackedBlockAmount(e.getClickedBlock()) <= 1)
Expand All @@ -337,13 +342,9 @@ public void onBlockUnstack(PlayerInteractEvent e) {
if (plugin.getSettings().getStackedBlocks().getDepositMenu().isEnabled() && e.getPlayer().isSneaking()) {
StackedBlocksDepositMenu depositMenu = new StackedBlocksDepositMenu(e.getClickedBlock().getLocation());
e.getPlayer().openInventory(depositMenu.getInventory());
} else {
recentlyClicked.add(e.getPlayer().getUniqueId());
Executor.sync(() -> recentlyClicked.remove(e.getPlayer().getUniqueId()), 5L);

if (!ProtectionLogic.handleBlockBreak(e.getClickedBlock(), e.getPlayer(), true) ||
StackedBlocksLogic.tryUnstack(e.getPlayer(), e.getClickedBlock(), plugin))
e.setCancelled(true);
} else if (!ProtectionLogic.handleBlockBreak(e.getClickedBlock(), e.getPlayer(), true) ||
StackedBlocksLogic.tryUnstack(e.getPlayer(), e.getClickedBlock(), plugin)) {
e.setCancelled(true);
}
}

Expand Down Expand Up @@ -451,6 +452,58 @@ public void onBlockChangeState(BlockFormEvent e) {
e.setCancelled(true);
}

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onCartPlaceMonitor(PlayerInteractEvent e) {
if (e.getAction() != Action.RIGHT_CLICK_BLOCK || e.getItem() == null ||
!e.getClickedBlock().getType().name().contains("RAIL") ||
!e.getItem().getType().name().contains("MINECART"))
return;

if (INTERACT_GET_HAND.isValid() && INTERACT_GET_HAND.invoke(e) != EquipmentSlot.HAND)
return;

Island island = plugin.getGrid().getIslandAt(e.getClickedBlock().getLocation());

if (island == null)
return;

switch (e.getItem().getType().name()) {
case "HOPPER_MINECART":
island.handleBlockPlace(ConstantKeys.HOPPER, 1);
break;
case "COMMAND_MINECART":
case "COMMAND_BLOCK_MINECART":
island.handleBlockPlace(ServerVersion.isAtLeast(ServerVersion.v1_13) ?
ConstantKeys.COMMAND_BLOCK : ConstantKeys.COMMAND, 1);
break;
case "EXPLOSIVE_MINECART":
case "TNT_MINECART":
island.handleBlockPlace(ConstantKeys.TNT, 1);
break;
case "POWERED_MINECART":
case "FURNACE_MINECART":
island.handleBlockPlace(ConstantKeys.FURNACE, 1);
break;
case "STORAGE_MINECART":
case "CHEST_MINECART":
island.handleBlockPlace(ConstantKeys.CHEST, 1);
break;
}
}

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onCartBreakMonitor(VehicleDestroyEvent e) {
if (!(e.getVehicle() instanceof Minecart))
return;

Island island = plugin.getGrid().getIslandAt(e.getVehicle().getLocation());

if (island == null)
return;

island.handleBlockBreak(plugin.getNMSAlgorithms().getMinecartBlock((Minecart) e.getVehicle()), 1);
}

/*
* Island Warps
*/
Expand Down

0 comments on commit f294eaf

Please sign in to comment.