Initial commit
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>ProjectCranked</artifactId>
|
||||
<groupId>net.crankedpvp</groupId>
|
||||
<version>1.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>Spawners</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<!--you need to compile Storage utils for this to stop being red -->
|
||||
<dependency>
|
||||
<groupId>net.crankedpvp</groupId>
|
||||
<artifactId>StorageUtilsShaded</artifactId>
|
||||
<version>1.0</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/../StorageUtils/target/StorageUtils-1.0-shaded.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.golfing.wineSpigot</groupId>
|
||||
<artifactId>winespigot</artifactId>
|
||||
<version>1.0</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/../.lib/WineSpigot-V1.4.4.3.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>coreprotect</groupId>
|
||||
<artifactId>coreprotect</artifactId>
|
||||
<version>1.0</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/../.lib/CoreProtect_2.12.0.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>Utils</artifactId>
|
||||
<groupId>net.crankedpvp</groupId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>Lootboxes</artifactId>
|
||||
<groupId>net.crankedpvp</groupId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>Masks</artifactId>
|
||||
<groupId>net.crankedpvp</groupId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>Pets</artifactId>
|
||||
<groupId>net.crankedpvp</groupId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.massivecraft</groupId>
|
||||
<artifactId>Factions</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.crankedpvp</groupId>
|
||||
<artifactId>Captcha</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.crankedpvp</groupId>
|
||||
<artifactId>Shop</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>Keys</artifactId>
|
||||
<groupId>net.crankedpvp</groupId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.crankedpvp</groupId>
|
||||
<artifactId>FactionLogs</artifactId>
|
||||
<version>1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>Enchants</artifactId>
|
||||
<groupId>net.crankedpvp</groupId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.crankedpvp</groupId>
|
||||
<artifactId>CustomExplosions</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.crankedpvp</groupId>
|
||||
<artifactId>Leaderboards</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>Armor</artifactId>
|
||||
<groupId>net.crankedpvp</groupId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.crankedpvp</groupId>
|
||||
<artifactId>Shards</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,128 @@
|
||||
package net.crankedpvp.spawners;
|
||||
|
||||
import lombok.Getter;
|
||||
import me.mattstudios.mf.base.CommandManager;
|
||||
import me.mattstudios.mf.base.components.TypeResult;
|
||||
import net.crankedpvp.crankedutils.utils.PluginUtils;
|
||||
import net.crankedpvp.spawners.commands.*;
|
||||
import net.crankedpvp.spawners.guis.AntiAFKGrindingGUI;
|
||||
import net.crankedpvp.spawners.language.LanguageHandler;
|
||||
import net.crankedpvp.spawners.listeners.*;
|
||||
import net.crankedpvp.spawners.struct.ftop.FactionsTopManager;
|
||||
import net.crankedpvp.spawners.struct.ftop.RecalculationTask;
|
||||
import net.crankedpvp.spawners.struct.grinding.GrindingManager;
|
||||
import net.crankedpvp.spawners.struct.spawners.SpawnerManager;
|
||||
import net.crankedpvp.spawners.utils.ConfigManager;
|
||||
import net.crankedpvp.spawners.utils.MobStackerUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Getter
|
||||
public class SpawnerPlugin extends JavaPlugin {
|
||||
|
||||
@Getter
|
||||
private static SpawnerPlugin instance;
|
||||
|
||||
@Getter
|
||||
public static List<Player> coolDownSpawnerPlace = new ArrayList<>();
|
||||
@Getter
|
||||
private List<UUID> waitingForAfkGrindingVerification;
|
||||
@Getter
|
||||
private Map<UUID, Integer> afkGrinders;
|
||||
private LanguageHandler languagehandler;
|
||||
private ConfigManager configManager;
|
||||
private FactionsTopManager factionsTopManager;
|
||||
private MobStackerUtils mobStackerUtils;
|
||||
private CommandManager commandManager;
|
||||
private SpawnerManager spawnerManager;
|
||||
private GrindingManager grindingManager;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
|
||||
this.mobStackerUtils = new MobStackerUtils();
|
||||
|
||||
this.languagehandler = new LanguageHandler(this);
|
||||
this.languagehandler.load();
|
||||
this.configManager = new ConfigManager(this);
|
||||
this.configManager.setupFiles();
|
||||
|
||||
this.factionsTopManager = new FactionsTopManager(this);
|
||||
|
||||
this.commandManager = new CommandManager(this, true);
|
||||
registerCommandParameters();
|
||||
commandManager.register(new CommandAdminFactionsTop(this), new CommandFactionsTop(this),new CommandAdminSpawner(), new CommandGiveSpawner(), new CommandSplitSpawners(), new CommandStackSpawners(), new CommandStopSpawnersPlace());
|
||||
|
||||
this.spawnerManager = new SpawnerManager(this);
|
||||
spawnerManager.loadAll();
|
||||
|
||||
Bukkit.getScheduler().scheduleAsyncRepeatingTask(this, ()-> {
|
||||
spawnerManager.saveAll();
|
||||
}, 60L, 5*20*60);
|
||||
|
||||
new RecalculationTask(this).runTaskTimerAsynchronously(this, 100L, 18000L);
|
||||
|
||||
this.grindingManager = new GrindingManager();
|
||||
this.registerListeners();
|
||||
this.afkGrinders = new HashMap<>();
|
||||
this.waitingForAfkGrindingVerification = new ArrayList<>();
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(this, MobStackerUtils::onEnable, 20L);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
spawnerManager.saveAll();
|
||||
instance = null;
|
||||
}
|
||||
|
||||
public void registerListeners() {
|
||||
PluginUtils.registerListeners(this,
|
||||
new SpawnerBreakListener(),
|
||||
new CombineSpawnersInventoryListener(),
|
||||
new EntityStackerListener(this),
|
||||
new MobSpawnerListener(this),
|
||||
new FtopCommandListener(this),
|
||||
new GrindingGuiClose(),
|
||||
new SpawnerSpawnListener(this)
|
||||
);
|
||||
}
|
||||
|
||||
private void registerCommandParameters() {
|
||||
this.commandManager.getParameterHandler().register(EntityType.class, argument -> {
|
||||
EntityType type = EntityType.valueOf(String.valueOf(argument).toUpperCase());
|
||||
return new TypeResult(type, argument);
|
||||
});
|
||||
}
|
||||
|
||||
public void addPlayerToAfkGrinding(Player p) {
|
||||
UUID uuid = p.getUniqueId();
|
||||
|
||||
if (afkGrinders.containsKey(uuid)) {
|
||||
int amount = afkGrinders.get(uuid);
|
||||
afkGrinders.put(uuid, amount+1);
|
||||
} else {
|
||||
afkGrinders.put(uuid, 1);
|
||||
}
|
||||
|
||||
int amount = afkGrinders.get(uuid);
|
||||
if (amount >= 5000) {
|
||||
p.closeInventory();
|
||||
//CaptchaAPI.forceCaptchaForPlayer(p);
|
||||
this.afkGrinders.put(uuid, 1);
|
||||
AntiAFKGrindingGUI antiAFKGrindingGUI = new AntiAFKGrindingGUI(p);
|
||||
antiAFKGrindingGUI.getAntiAfkGrindingGui().open(p);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package net.crankedpvp.spawners.commands;
|
||||
|
||||
import me.mattstudios.mf.annotations.Command;
|
||||
import me.mattstudios.mf.annotations.Default;
|
||||
import me.mattstudios.mf.annotations.Permission;
|
||||
import me.mattstudios.mf.base.CommandBase;
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.spawners.SpawnerPlugin;
|
||||
import net.crankedpvp.spawners.struct.ftop.FactionsTopManager;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@Command("aftop")
|
||||
public class CommandAdminFactionsTop extends CommandBase {
|
||||
|
||||
private final FactionsTopManager factionsTopManager;
|
||||
|
||||
public CommandAdminFactionsTop(SpawnerPlugin plugin) {
|
||||
this.factionsTopManager = plugin.getFactionsTopManager();
|
||||
}
|
||||
|
||||
@Default
|
||||
@Permission("ftop.recalculate")
|
||||
public void onCommand(CommandSender sender) {
|
||||
this.factionsTopManager.recalculateFactionsTop();
|
||||
sender.sendMessage(CC.GreenB + "(!) " + CC.Green + "Forcefully recalculated F-Top!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package net.crankedpvp.spawners.commands;
|
||||
|
||||
import me.mattstudios.mf.annotations.Alias;
|
||||
import me.mattstudios.mf.annotations.Command;
|
||||
import me.mattstudios.mf.annotations.Default;
|
||||
import me.mattstudios.mf.annotations.Permission;
|
||||
import me.mattstudios.mf.base.CommandBase;
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.spawners.SpawnerPlugin;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@Command("aspawner")
|
||||
@Alias("as")
|
||||
public class CommandAdminSpawner extends CommandBase {
|
||||
|
||||
@Default
|
||||
@Permission("cranked.admin")
|
||||
public void onReload(CommandSender sender) {
|
||||
SpawnerPlugin.getInstance().getConfigManager().reloadFiles();
|
||||
|
||||
sender.sendMessage(CC.translate("&aReload Config files..."));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package net.crankedpvp.spawners.commands;
|
||||
|
||||
import me.mattstudios.mf.annotations.Alias;
|
||||
import me.mattstudios.mf.annotations.Command;
|
||||
import me.mattstudios.mf.annotations.Default;
|
||||
import me.mattstudios.mf.annotations.Optional;
|
||||
import me.mattstudios.mf.base.CommandBase;
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.crankedutils.utils.NumberUtils;
|
||||
import net.crankedpvp.spawners.SpawnerPlugin;
|
||||
import net.crankedpvp.spawners.data.ftop.FactionData;
|
||||
import net.crankedpvp.spawners.struct.ftop.FactionsTopManager;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Command("ftop")
|
||||
@Alias("ftopp")
|
||||
public class CommandFactionsTop extends CommandBase {
|
||||
|
||||
private final FactionsTopManager factionsTopManager;
|
||||
|
||||
public CommandFactionsTop(SpawnerPlugin plugin) {
|
||||
this.factionsTopManager = plugin.getFactionsTopManager();
|
||||
}
|
||||
|
||||
@Default
|
||||
public void onCommand(CommandSender sender, @Optional Integer page) {
|
||||
Player player = (Player)sender;
|
||||
if (page == null) {
|
||||
page = 1;
|
||||
}
|
||||
page = Math.min(5, Math.max(1, page));
|
||||
player.sendMessage("");
|
||||
player.sendMessage(CC.GoldB + "Top Factions (" + CC.WhiteB + page + CC.Gold + "/" + CC.WhiteB + "5" + CC.GoldB + ")");
|
||||
int pos = 1;
|
||||
int from = (page - 1) * 9;
|
||||
int to = (page - 1) * 9 + 9;
|
||||
Map<Integer, FactionData> data = this.factionsTopManager.getTopFactions(from, to);
|
||||
for (int x = from; x < to; x++) {
|
||||
if (data.containsKey(x)) {
|
||||
FactionData faction = data.get(x);
|
||||
TextComponent msg = new TextComponent(CC.GoldB + pos + ". " + CC.Green + faction.getFaction().getTag() + CC.Gold + " - " + CC.WhiteB + "$" + NumberUtils.formatMoney(faction.getSpawnerValue()));
|
||||
String builder = CC.GoldB + CC.Underline + faction.getFaction().getTag() + "\n\n" +
|
||||
CC.White + "Member Wealth: " + CC.Gold + "$" + NumberUtils.formatMoney(faction.getMemberValue()) + "\n" +
|
||||
CC.White + "Spawner Value: " + CC.Gold + "$" + NumberUtils.formatMoney(faction.getSpawnerValue()) + "\n" +
|
||||
CC.White + "Spawners: " + CC.Gold + faction.getSpawnerCount() + "\n" +
|
||||
CC.White + "Stacked Spawners: " + CC.Gold + faction
|
||||
.getStackedSpawnerCount() +
|
||||
"\n" +
|
||||
CC.White + "Richest Member:\n" +
|
||||
" " + CC.GoldB + faction.getRichestPlayer() + ": $" + NumberUtils.formatMoney(faction.getRichestPlayerBalance());
|
||||
msg.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, (new ComponentBuilder(builder)).create()));
|
||||
player.sendMessage(msg);
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
player.sendMessage("");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package net.crankedpvp.spawners.commands;
|
||||
|
||||
import me.mattstudios.mf.annotations.*;
|
||||
import me.mattstudios.mf.base.CommandBase;
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.crankedutils.utils.PlayerUtils;
|
||||
import net.crankedpvp.spawners.items.ItemSpawner;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
|
||||
@Command("givespawner")
|
||||
@Alias("givespawners")
|
||||
public class CommandGiveSpawner extends CommandBase {
|
||||
|
||||
@Permission("cranked.admin")
|
||||
@Default
|
||||
@WrongUsage("&cUsage: /givespawner [IGN] [Type] [Amount]")
|
||||
public void onCommand(CommandSender sender, @Completion("#players") Player forPlayer, @Completion("#enum") EntityType type, @Optional Integer amount) {
|
||||
if (amount == null) {
|
||||
amount = 1;
|
||||
}
|
||||
PlayerUtils.giveOrDropProtectedItem(forPlayer, ItemSpawner.getItem(type, amount), 60);
|
||||
sender.sendMessage(CC.translate("&a&l(!)&a Given " + forPlayer.getName() + " " + amount + "x " + type.getName() + " Spawners."));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package net.crankedpvp.spawners.commands;
|
||||
|
||||
import me.mattstudios.mf.annotations.Alias;
|
||||
import me.mattstudios.mf.annotations.Command;
|
||||
import me.mattstudios.mf.annotations.Default;
|
||||
import me.mattstudios.mf.annotations.WrongUsage;
|
||||
import me.mattstudios.mf.base.CommandBase;
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.spawners.items.ItemSpawner;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
||||
@Command("splitspawner")
|
||||
@Alias("splitspawners")
|
||||
public class CommandSplitSpawners extends CommandBase {
|
||||
|
||||
@Default
|
||||
@WrongUsage("&cUsage: /splitspawners [count]")
|
||||
public void onCommand(CommandSender sender, Integer amount) {
|
||||
Player player = (Player) sender;
|
||||
ItemStack item = player.getItemInHand();
|
||||
if(amount <= 0) {
|
||||
player.sendMessage(CC.RedB + "(!) " + CC.Red + "You cannot split 0 or less spawners");
|
||||
return;
|
||||
}
|
||||
int count = ItemSpawner.getSpawnerAmount(item);
|
||||
EntityType type = ItemSpawner.getEntityTypeFromItem(item);
|
||||
if(type == null || count <= -1) {
|
||||
player.sendMessage(CC.RedB + "(!) " + CC.Red + "That is not a valid spawner!");
|
||||
return;
|
||||
}
|
||||
|
||||
if(amount >= count) {
|
||||
player.sendMessage(CC.RedB + "(!) " + CC.Red + "You have to choose a count lower than the spawner count.");
|
||||
return;
|
||||
}
|
||||
player.getInventory().addItem(ItemSpawner.getItem(type, amount));
|
||||
player.setItemInHand(ItemSpawner.getItem(type, count - amount));
|
||||
player.playSound(player.getLocation(), Sound.ANVIL_USE, 0.75F, 2F);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package net.crankedpvp.spawners.commands;
|
||||
|
||||
|
||||
import me.mattstudios.mf.annotations.Alias;
|
||||
import me.mattstudios.mf.annotations.Command;
|
||||
import me.mattstudios.mf.annotations.Default;
|
||||
import me.mattstudios.mf.base.CommandBase;
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.crankedutils.utils.PlayerUtils;
|
||||
import net.crankedpvp.spawners.items.ItemSpawner;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Command("stackspawner")
|
||||
@Alias("stackspawners")
|
||||
public class CommandStackSpawners extends CommandBase {
|
||||
@Default
|
||||
public void onCommand(CommandSender sender) {
|
||||
Map<EntityType, Integer> spawners = new HashMap<>();
|
||||
Player player = ((Player) sender).getPlayer();
|
||||
|
||||
for (ItemStack item : player.getInventory().getContents()) {
|
||||
|
||||
int amount = ItemSpawner.getSpawnerAmount(item);
|
||||
EntityType type = ItemSpawner.getEntityTypeFromItem(item);
|
||||
|
||||
|
||||
|
||||
if(type == null || amount <= -1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (item.getAmount() >1) {
|
||||
amount *=item.getAmount();
|
||||
}
|
||||
|
||||
player.getInventory().remove(item);
|
||||
if (spawners.containsKey(type)) {
|
||||
int currentAmount = spawners.get(type);
|
||||
spawners.put(type, currentAmount+amount);
|
||||
} else {
|
||||
spawners.put(type, amount);
|
||||
}
|
||||
}
|
||||
|
||||
if (spawners.isEmpty()) {
|
||||
player.sendMessage(CC.translate("&c&l(!)&c Could not find valid spawners to stack."));
|
||||
return;
|
||||
}
|
||||
|
||||
for (Map.Entry<EntityType, Integer> entry : spawners.entrySet()) {
|
||||
EntityType type = entry.getKey();
|
||||
int amount = entry.getValue();
|
||||
PlayerUtils.giveOrDropProtectedItem(player, ItemSpawner.getItem(type, amount), -1);
|
||||
}
|
||||
player.sendMessage(CC.translate("&a&l(!)&a Stacked all the spawners in your inventory."));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package net.crankedpvp.spawners.commands;
|
||||
|
||||
|
||||
import me.mattstudios.mf.annotations.Alias;
|
||||
import me.mattstudios.mf.annotations.Command;
|
||||
import me.mattstudios.mf.annotations.Default;
|
||||
import me.mattstudios.mf.annotations.Permission;
|
||||
import me.mattstudios.mf.base.CommandBase;
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.spawners.SpawnerPlugin;
|
||||
import net.crankedpvp.spawners.utils.ConfigManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@Command("stopspawners")
|
||||
@Alias({"stopspawner", "stopspawnerplace", "stopspawnersplace"})
|
||||
public class CommandStopSpawnersPlace extends CommandBase {
|
||||
|
||||
@Permission("cranked.admin")
|
||||
@Default
|
||||
public void onCommand(CommandSender commandSender) {
|
||||
|
||||
|
||||
boolean allowSpawners = SpawnerPlugin.getInstance().getConfigManager().getConfig(ConfigManager.ConfigFile.PRIMARY).getBoolean("spawners.can-place");
|
||||
|
||||
|
||||
Bukkit.broadcastMessage(CC.translate(""));
|
||||
if (!allowSpawners) {
|
||||
Bukkit.broadcastMessage(CC.translate("&a&l** SPAWNER PLACEMENT HAS BEEN ENABLED **"));
|
||||
Bukkit.broadcastMessage(CC.translate("&7&o( You can now place spawners again for FTOP value. )"));
|
||||
Bukkit.broadcastMessage(CC.translate(""));
|
||||
SpawnerPlugin.getInstance().getConfigManager().getConfig(ConfigManager.ConfigFile.PRIMARY).set("spawners.can-place", true);
|
||||
|
||||
|
||||
} else {
|
||||
Bukkit.broadcastMessage(CC.translate("&c&l** SPAWNER PLACEMENT HAS BEEN DISABLED **"));
|
||||
Bukkit.broadcastMessage(CC.translate("&7&o( You can no longer place spawners for FTOP value anymore. )"));
|
||||
Bukkit.broadcastMessage(CC.translate(""));
|
||||
SpawnerPlugin.getInstance().getConfigManager().getConfig(ConfigManager.ConfigFile.PRIMARY).set("spawners.can-place", false);
|
||||
}
|
||||
SpawnerPlugin.getInstance().getConfigManager().getAbstractConfig(ConfigManager.ConfigFile.PRIMARY).saveConfig();
|
||||
SpawnerPlugin.getInstance().getConfigManager().getAbstractConfig(ConfigManager.ConfigFile.PRIMARY).reloadConfig();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package net.crankedpvp.spawners.data.ftop;
|
||||
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import net.crankedpvp.crankedutils.utils.EconomyUtils;
|
||||
import net.crankedpvp.crankedutils.utils.FactionUtils;
|
||||
import net.crankedpvp.spawners.SpawnerPlugin;
|
||||
import net.crankedpvp.spawners.data.spawners.SpawnerData;
|
||||
import net.crankedpvp.spawners.struct.ftop.FactionsTopManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class FactionData {
|
||||
|
||||
private final Faction faction;
|
||||
private final Object[] richestMember;
|
||||
private long memberValue;
|
||||
private long spawnerValue;
|
||||
private long spawnerAmount;
|
||||
private long stackedSpawners;
|
||||
|
||||
public FactionData(Faction faction) {
|
||||
this.faction = faction;
|
||||
this.spawnerValue = 0L;
|
||||
this.memberValue = 0L;
|
||||
this.spawnerAmount = 0L;
|
||||
this.stackedSpawners = 0L;
|
||||
this.richestMember = new Object[2];
|
||||
double cash = 0.0D;
|
||||
String richest = "";
|
||||
for (FPlayer player : faction.getFPlayers()) {
|
||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(player.getName());
|
||||
if (offlinePlayer == null)
|
||||
continue;
|
||||
double balance = EconomyUtils.getBalance(offlinePlayer);
|
||||
if (balance > cash) {
|
||||
cash = balance;
|
||||
richest = offlinePlayer.getName();
|
||||
}
|
||||
this.memberValue = (long)(this.memberValue + balance);
|
||||
}
|
||||
this.richestMember[0] = richest;
|
||||
this.richestMember[1] = (long) cash;
|
||||
String tag = this.faction.getTag();
|
||||
for (SpawnerData data : SpawnerPlugin.getInstance().getSpawnerManager().getCacheValues()) {
|
||||
Location location = SpawnerData.locationFromString(data.getKey());
|
||||
if (FactionUtils.getFactionAt(location).getTag().contentEquals(tag)) {
|
||||
this.stackedSpawners++;
|
||||
this.spawnerAmount += data.getSpawnerAmount();
|
||||
this.spawnerValue += SpawnerPlugin.getInstance().getFactionsTopManager().getValueOfSpawner(data.getEntityType()) * data.getSpawnerAmount();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public long getSpawnerCount() {
|
||||
return this.spawnerAmount;
|
||||
}
|
||||
|
||||
public long getSpawnerValue() {
|
||||
return this.spawnerValue;
|
||||
}
|
||||
|
||||
public long getMemberValue() {
|
||||
return this.memberValue;
|
||||
}
|
||||
|
||||
public long getStackedSpawnerCount() {
|
||||
return this.stackedSpawners;
|
||||
}
|
||||
|
||||
public Faction getFaction() {
|
||||
return this.faction;
|
||||
}
|
||||
|
||||
public String getRichestPlayer() {
|
||||
return (String)this.richestMember[0];
|
||||
}
|
||||
|
||||
public long getRichestPlayerBalance() {
|
||||
return (Long) this.richestMember[1];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package net.crankedpvp.spawners.data.spawners;
|
||||
|
||||
import net.crankedpvp.storageutils.utils.KeyToSave;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
|
||||
public class SpawnerData implements KeyToSave {
|
||||
|
||||
public int spawnerAmount;
|
||||
private final EntityType type;
|
||||
private Location location;
|
||||
|
||||
public SpawnerData(EntityType type, int spawnerAmount, Location location) {
|
||||
this.spawnerAmount = spawnerAmount;
|
||||
this.type = type;
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public EntityType getEntityType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public int getSpawnerAmount() {
|
||||
return this.spawnerAmount;
|
||||
}
|
||||
|
||||
public void setSpawnerAmount(int spawnerAmount) {
|
||||
this.spawnerAmount = spawnerAmount;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static String locationToString(Location location) {
|
||||
return location.getWorld().getName().replace("_","|") + "_" + location.getBlockX()+ "_" + location.getBlockY()+ "_" + location.getBlockZ();
|
||||
}
|
||||
|
||||
|
||||
public static Location locationFromString(String location) {
|
||||
String[] locationSplit = location.split("_");
|
||||
World world = Bukkit.getWorld(locationSplit[0].replace("|", "_"));
|
||||
double x = Double.parseDouble(locationSplit[1]);
|
||||
double y = Double.parseDouble(locationSplit[2]);
|
||||
double z = Double.parseDouble(locationSplit[3]);
|
||||
|
||||
return new Location(world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return locationToString(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setKey(String key) {
|
||||
this.location = locationFromString(key);
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package net.crankedpvp.spawners.data.spawners;
|
||||
|
||||
import net.crankedpvp.crankedutils.utils.cache.cooldown.CurrentCooldown;
|
||||
|
||||
public class SpawnerPlaceCooldown extends CurrentCooldown {
|
||||
|
||||
public SpawnerPlaceCooldown() {
|
||||
super("spawner-cooldown", 500L);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package net.crankedpvp.spawners.events;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
public class SpawnerBreakEvent extends Event implements Cancellable {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean canceled = false;
|
||||
@Getter
|
||||
private final Location location;
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return this.canceled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean b) {
|
||||
this.canceled = b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return SpawnerBreakEvent.handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return SpawnerBreakEvent.handlers;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package net.crankedpvp.spawners.events;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
public class SpawnerPlaceEvent extends Event implements Cancellable {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean canceled = false;
|
||||
@Getter
|
||||
private final Location location;
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return this.canceled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean b) {
|
||||
this.canceled = b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return SpawnerPlaceEvent.handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return SpawnerPlaceEvent.handlers;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package net.crankedpvp.spawners.events;
|
||||
|
||||
import net.crankedpvp.shop.ShopPlugin;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
public class StackedMobDeathEvent extends Event implements Cancellable {
|
||||
|
||||
private boolean cancel;
|
||||
private final Entity entity;
|
||||
private final Entity damager;
|
||||
|
||||
private static final HandlerList handlers;
|
||||
private static final Map<EntityType, ItemStack> itemDrops = new EnumMap<>(EntityType.class);
|
||||
private static final Map<EntityType, Integer> xpDrops = new EnumMap<>(EntityType.class);
|
||||
private static final Map<EntityType, Integer> moneyDrops = new EnumMap<>(EntityType.class);
|
||||
|
||||
|
||||
static {
|
||||
Random random = new Random();
|
||||
itemDrops.put(EntityType.VILLAGER, new ItemStack(Material.EMERALD, random.nextInt((3 - 1) + 1) + 1));
|
||||
itemDrops.put(EntityType.CREEPER, new ItemStack(Material.TNT, 1));
|
||||
itemDrops.put(EntityType.WITCH, new ItemStack(Material.DIAMOND, random.nextInt((3 - 1) + 1) + 1));
|
||||
itemDrops.put(EntityType.IRON_GOLEM, new ItemStack(Material.IRON_INGOT, random.nextInt((3 - 1) + 1) + 1));
|
||||
itemDrops.put(EntityType.PIG_ZOMBIE, new ItemStack(Material.GOLD_INGOT, 1));
|
||||
itemDrops.put(EntityType.SKELETON, new ItemStack(Material.BONE));
|
||||
itemDrops.put(EntityType.ZOMBIE, new ItemStack(Material.ROTTEN_FLESH));
|
||||
itemDrops.put(EntityType.BLAZE, new ItemStack(Material.BLAZE_ROD, 1));
|
||||
}
|
||||
|
||||
static {
|
||||
Random random = new Random();
|
||||
xpDrops.put(EntityType.VILLAGER, random.nextInt((50 - 1) + 1) + 35);
|
||||
xpDrops.put(EntityType.CREEPER, random.nextInt((25 - 1) + 1) + 15);
|
||||
xpDrops.put(EntityType.WITCH, random.nextInt((50 - 1) + 1) + 35);
|
||||
xpDrops.put(EntityType.IRON_GOLEM, random.nextInt((40 - 1) + 1) + 25);
|
||||
xpDrops.put(EntityType.PIG_ZOMBIE, random.nextInt((40 - 1) + 1) + 20);
|
||||
xpDrops.put(EntityType.SKELETON, random.nextInt((35 - 1) + 1) + 20);
|
||||
xpDrops.put(EntityType.ZOMBIE, random.nextInt((35 - 1) + 1) + 20);
|
||||
xpDrops.put(EntityType.BLAZE, random.nextInt((50 - 1) + 1) + 35);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public StackedMobDeathEvent(Entity entity, Entity damager) {
|
||||
this.entity = entity;
|
||||
this.damager = damager;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return StackedMobDeathEvent.handlers;
|
||||
}
|
||||
|
||||
public ItemStack getItemDrops(EntityType entityType) {
|
||||
return itemDrops.get(entityType);
|
||||
}
|
||||
|
||||
public double getExp(EntityType entityType) {
|
||||
return xpDrops.getOrDefault(entityType, 75);
|
||||
}
|
||||
|
||||
public double getMoney(EntityType entityType) {
|
||||
return ShopPlugin.getShopHandler().getSellPrice(getItemDrops(entityType));
|
||||
}
|
||||
|
||||
public Entity getDamager() {
|
||||
return damager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final HandlerList getHandlers() {
|
||||
return StackedMobDeathEvent.handlers;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final void setCancelled(final boolean cancel) {
|
||||
this.cancel = cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isCancelled() {
|
||||
return this.cancel;
|
||||
}
|
||||
|
||||
static {
|
||||
handlers = new HandlerList();
|
||||
}
|
||||
|
||||
|
||||
public Entity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package net.crankedpvp.spawners.guis;
|
||||
|
||||
|
||||
import dev.triumphteam.gui.guis.GuiItem;
|
||||
import dev.triumphteam.gui.guis.PaginatedGui;
|
||||
import lombok.Getter;
|
||||
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.crankedutils.utils.items.ItemBuilder;
|
||||
import net.crankedpvp.spawners.SpawnerPlugin;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
public class AntiAFKGrindingGUI {
|
||||
private final PaginatedGui antiAfkGrindingGui;
|
||||
private final SpawnerPlugin crankedSpawners;
|
||||
private final Player player;
|
||||
|
||||
public AntiAFKGrindingGUI(Player player) {
|
||||
this.crankedSpawners = SpawnerPlugin.getInstance();
|
||||
this.antiAfkGrindingGui = new PaginatedGui(1, 1, CC.translate("&8Anti AFK Grinding Verification"));
|
||||
this.player = player;
|
||||
UUID uuid = player.getUniqueId();
|
||||
if (!crankedSpawners.getWaitingForAfkGrindingVerification().contains(uuid)) {
|
||||
crankedSpawners.getWaitingForAfkGrindingVerification().add(uuid);
|
||||
}
|
||||
|
||||
|
||||
this.antiAfkGrindingGui.setDefaultClickAction(event -> event.setCancelled(true));
|
||||
Random random = new Random();
|
||||
int randomInt = random.nextInt(9) + 1;
|
||||
this.antiAfkGrindingGui.setItem(1, randomInt, new GuiItem(new ItemBuilder(Material.NETHER_STAR, CC.translate("&a&lVerify!")).addLoreLine(CC.translate("&7Click here to verify you are not afk grinding!")).build(), event -> {
|
||||
crankedSpawners.getAfkGrinders().put(uuid, 1);
|
||||
crankedSpawners.getWaitingForAfkGrindingVerification().remove(uuid);
|
||||
player.sendMessage(CC.translate("&a&l(!)&a You have completed the anti afk grinding captcha! You can now enjoy grinding again."));
|
||||
player.playSound(player.getLocation(), Sound.VILLAGER_YES, 50, 50);
|
||||
player.closeInventory();
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package net.crankedpvp.spawners.items;
|
||||
|
||||
import de.tr7zw.nbtapi.NBTCompound;
|
||||
import de.tr7zw.nbtapi.NBTItem;
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.crankedutils.utils.EntityUtils;
|
||||
import net.crankedpvp.spawners.SpawnerPlugin;
|
||||
import net.crankedpvp.spawners.utils.ConfigManager;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
public class ItemSpawner {
|
||||
|
||||
public static ItemStack getItem(EntityType creatureType, int amount) {
|
||||
ItemStack item = new ItemStack(Material.MOB_SPAWNER);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(CC.translate("&c&l" + EntityUtils.getEntityName(creatureType) + " &f&lSpawner &7(" + amount + "x)"));
|
||||
meta.setLore(Arrays.asList(
|
||||
CC.translate("&8Stacked Spawner"),
|
||||
CC.translate(""),
|
||||
CC.translate("&4&lSpawner Info"),
|
||||
CC.translate("&4┇ &cType: &7" + EntityUtils.getEntityName(creatureType)),
|
||||
CC.translate("&4┇ &cAmount: &7" + amount),
|
||||
CC.translate("&4┖")
|
||||
|
||||
));
|
||||
item.setItemMeta(meta);
|
||||
NBTItem nbtItem = new NBTItem(item);
|
||||
NBTCompound compound = nbtItem.addCompound("spawnerData");
|
||||
compound.setString("spawnerType", creatureType.name());
|
||||
compound.setInteger("amount", amount);
|
||||
compound.setString("uuid", UUID.randomUUID().toString());
|
||||
return nbtItem.getItem();
|
||||
}
|
||||
|
||||
public static EntityType getEntityTypeFromItem(ItemStack item) {
|
||||
if (item == null || item.getType() != Material.MOB_SPAWNER) {
|
||||
return null;
|
||||
}
|
||||
NBTItem wrapper = new NBTItem(item);
|
||||
if (!wrapper.hasKey("spawnerData")) {
|
||||
return null;
|
||||
}
|
||||
NBTCompound compound = wrapper.getCompound("spawnerData");
|
||||
return EntityType.valueOf(compound.getString("spawnerType"));
|
||||
}
|
||||
|
||||
public static int getSpawnerAmount(ItemStack item) {
|
||||
if (item == null || item.getType() != Material.MOB_SPAWNER) {
|
||||
return -1;
|
||||
}
|
||||
NBTItem wrapper = new NBTItem(item);
|
||||
if (!wrapper.hasKey("spawnerData")) {
|
||||
return -1;
|
||||
}
|
||||
NBTCompound compound = wrapper.getCompound("spawnerData");
|
||||
return compound.getInteger("amount");
|
||||
}
|
||||
|
||||
public static int getSpawnerLimit() {
|
||||
return SpawnerPlugin.getInstance().getConfigManager().getConfig(ConfigManager.ConfigFile.PRIMARY).getInt("spawners.max-stack-size");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package net.crankedpvp.spawners.language;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.UnaryOperator;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public enum Language {
|
||||
|
||||
GRINDING_MONEY_GIVE
|
||||
;
|
||||
|
||||
private String value;
|
||||
private ImmutableList<String> valueList;
|
||||
|
||||
public String getValue() {
|
||||
return this.value != null ? this.value : this.name();
|
||||
}
|
||||
|
||||
public String getValue(UnaryOperator<String> function) {
|
||||
return this.value != null ? function.apply(this.value) : this.name();
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return this.name();
|
||||
}
|
||||
|
||||
public List<String> getValuesAsList() {
|
||||
return this.valueList;
|
||||
}
|
||||
|
||||
public List<String> getValuesAsList(String oldString, String newString) {
|
||||
List<String> list = new ArrayList<>(this.valueList);
|
||||
list.replaceAll(s -> s.replace(oldString, newString));
|
||||
return list;
|
||||
}
|
||||
|
||||
void setValue(String value) {
|
||||
this.value = CC.translate(value);
|
||||
|
||||
List<String> tempList = Arrays.stream(StringUtils.split(value, System.lineSeparator()))
|
||||
.map(CC::translate)
|
||||
.collect(Collectors.toList());
|
||||
this.valueList = ImmutableList.copyOf(tempList);
|
||||
}
|
||||
|
||||
void setValue(List<String> valueList) {
|
||||
this.value = CC.translate(valueList.parallelStream().collect(Collectors.joining(System.lineSeparator())));
|
||||
|
||||
List<String> tempList = valueList.stream()
|
||||
.map(CC::translate)
|
||||
.collect(Collectors.toList());
|
||||
this.valueList = ImmutableList.copyOf(tempList);
|
||||
}
|
||||
|
||||
public void send(CommandSender sender, UnaryOperator<String> function) {
|
||||
sender.sendMessage(CC.translate(this.getValue(function)));
|
||||
}
|
||||
|
||||
public void send(CommandSender sender) {
|
||||
sender.sendMessage(CC.translate(this.getValue()));
|
||||
}
|
||||
|
||||
|
||||
public void send(List<CommandSender> senders, UnaryOperator<String> function) {
|
||||
String msg = CC.translate(this.getValue(function));
|
||||
senders.forEach(sender -> sender.sendMessage(msg));
|
||||
}
|
||||
|
||||
public void sendPlayers(List<Player> senders, UnaryOperator<String> function) {
|
||||
String msg = CC.translate(this.getValue(function));
|
||||
senders.forEach(sender -> sender.sendMessage(msg));
|
||||
}
|
||||
|
||||
public void send(CommandSender ...senders) {
|
||||
String msg = CC.translate(this.getValue());
|
||||
Arrays.asList(senders).forEach(sender -> sender.sendMessage(msg));
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return CC.translate(this.getValue());
|
||||
}
|
||||
|
||||
public String getMessage(UnaryOperator<String> function) {
|
||||
return CC.translate(this.getValue(function));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package net.crankedpvp.spawners.language;
|
||||
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
public final class LanguageHandler {
|
||||
|
||||
private final File file;
|
||||
private final FileConfiguration config;
|
||||
private final String path;
|
||||
private final JavaPlugin plugin;
|
||||
|
||||
public LanguageHandler(JavaPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.path = "language.yml";
|
||||
file = new File(plugin.getDataFolder(), path);
|
||||
config = new YamlConfiguration();
|
||||
}
|
||||
|
||||
public void load() {
|
||||
this.saveDefaultConfig();
|
||||
|
||||
this.loadConfigFromDisk();
|
||||
this.copyDefaults();
|
||||
this.save();
|
||||
|
||||
this.loadConfigFromDisk();
|
||||
|
||||
this.loadLangMessages();
|
||||
}
|
||||
|
||||
private void loadLangMessages() {
|
||||
for (Language entry : Language.values()) {
|
||||
String path = entry.getPath();
|
||||
if (config.isList(path)) {
|
||||
entry.setValue(config.getStringList(path));
|
||||
continue;
|
||||
}
|
||||
entry.setValue(config.getString(path));
|
||||
}
|
||||
}
|
||||
|
||||
private void loadConfigFromDisk() {
|
||||
try {
|
||||
config.load(file);
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void save() {
|
||||
try {
|
||||
config.save(file);
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().severe("Could not save config file for " + file.getPath() + "!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void copyDefaults() {
|
||||
InputStream defConfig = plugin.getResource(this.path);
|
||||
if (defConfig != null) {
|
||||
config.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(defConfig)));
|
||||
}
|
||||
config.options().copyDefaults(true);
|
||||
}
|
||||
|
||||
private void saveDefaultConfig() {
|
||||
if (!file.exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
plugin.saveResource(file.getName(),false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
package net.crankedpvp.spawners.listeners;
|
||||
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.crankedutils.utils.InventoryClickUtils;
|
||||
import net.crankedpvp.spawners.items.ItemSpawner;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
|
||||
public class CombineSpawnersInventoryListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onClick(InventoryClickEvent event) {
|
||||
|
||||
if (event.getCurrentItem() != null && event.getCursor() != null) {
|
||||
if (event.getCurrentItem().getType() != Material.MOB_SPAWNER
|
||||
|| event.getCursor().getType() != Material.MOB_SPAWNER) {
|
||||
return;
|
||||
}
|
||||
if (event.getCurrentItem().getAmount() > 1 || event.getCursor().getAmount() > 1) {
|
||||
event.getWhoClicked().sendMessage(CC.translate("&c&l(!)&c You cannot stack stacked spawners, type /stackspawners"));
|
||||
((Player) event.getWhoClicked()).playSound(event.getWhoClicked().getLocation(), Sound.ANVIL_LAND, 0.75F, 2F);
|
||||
return;
|
||||
}
|
||||
if(event.isCancelled()) return;
|
||||
// if (event.getClickedInventory() != event.getWhoClicked().getOpenInventory().getBottomInventory()) return;
|
||||
if(!InventoryClickUtils.canClickItem(event)) return;
|
||||
int amount = ItemSpawner.getSpawnerAmount(event.getCursor());
|
||||
int other = ItemSpawner.getSpawnerAmount(event.getCurrentItem());
|
||||
EntityType type = ItemSpawner.getEntityTypeFromItem(event.getCursor());
|
||||
EntityType otherType = ItemSpawner.getEntityTypeFromItem(event.getCurrentItem());
|
||||
if (amount <= 0 || other <= 0 || otherType != type) {
|
||||
return;
|
||||
}
|
||||
amount += other;
|
||||
if(event.getCursor().getAmount() > 1) {
|
||||
event.getCursor().setAmount(event.getCursor().getAmount() - 1);
|
||||
} else {
|
||||
event.setCursor(null);
|
||||
}
|
||||
event.setCurrentItem(ItemSpawner.getItem(type, amount));
|
||||
((Player) event.getWhoClicked()).playSound(event.getWhoClicked().getLocation(), Sound.ANVIL_USE, 0.75F, 2F);
|
||||
((Player) event.getWhoClicked()).playSound(event.getWhoClicked().getLocation(), Sound.LEVEL_UP, 0.75F, 2F);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
package net.crankedpvp.spawners.listeners;
|
||||
|
||||
import net.crankedpvp.crankedarmor.CrankedArmor;
|
||||
import net.crankedpvp.crankedarmor.CrankedArmorAPI;
|
||||
import net.crankedpvp.crankedarmor.struct.ArmorSet;
|
||||
import net.crankedpvp.crankedenchants.struct.items.EnchantedItemBuilder;
|
||||
import net.crankedpvp.crankedmasks.CrankedMasks;
|
||||
import net.crankedpvp.crankedmasks.CrankedMasksAPI;
|
||||
import net.crankedpvp.crankedpets.CrankedPets;
|
||||
import net.crankedpvp.crankedpets.pets.ExperiencePet;
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.crankedutils.utils.items.ItemUtils;
|
||||
import net.crankedpvp.cratekeys.CrankedCrateKeysAPI;
|
||||
import net.crankedpvp.cratekeys.enums.CrateKeyType;
|
||||
import net.crankedpvp.lootboxes.CrankedLootboxes;
|
||||
import net.crankedpvp.spawners.SpawnerPlugin;
|
||||
import net.crankedpvp.spawners.events.StackedMobDeathEvent;
|
||||
import net.crankedpvp.spawners.struct.grinding.GrindingCache;
|
||||
import net.crankedpvp.spawners.struct.grinding.GrindingManager;
|
||||
import net.crankedpvp.spawners.utils.ConfigManager;
|
||||
import net.crankedpvp.spawners.utils.MobStackerUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Creature;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class EntityStackerListener implements Listener {
|
||||
private final MobStackerUtils mobStackerUtils;
|
||||
private final SpawnerPlugin plugin;
|
||||
private final Map<UUID, Long> blazeCooldown;
|
||||
private final GrindingManager grindingManager;
|
||||
|
||||
public EntityStackerListener(SpawnerPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.mobStackerUtils = plugin.getMobStackerUtils();
|
||||
this.blazeCooldown = new HashMap<>();
|
||||
this.grindingManager = plugin.getGrindingManager();
|
||||
Bukkit.getScheduler().runTaskTimer(plugin, this.blazeCooldown::clear, 10, 5 * 20 * 60);
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onStackedEntityDeath(StackedMobDeathEvent event) {
|
||||
Entity entity = event.getEntity();
|
||||
if (event.getDamager() instanceof Player) {
|
||||
|
||||
|
||||
if (!mobStackerUtils.isStackedMob(entity)) return;
|
||||
|
||||
if (event.getEntity().getLastDamageCause() != null) {
|
||||
if (event.getEntity().getLastDamageCause().getCause() == EntityDamageEvent.DamageCause.FALL) return;
|
||||
if (event.getEntity().getLastDamageCause().getCause() == EntityDamageEvent.DamageCause.FIRE) return;
|
||||
if (event.getEntity().getLastDamageCause().getCause() == EntityDamageEvent.DamageCause.FIRE_TICK)
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.getWaitingForAfkGrindingVerification().contains(event.getDamager().getUniqueId())) {
|
||||
event.setCancelled(true);
|
||||
event.getDamager().sendMessage(CC.translate("&c&l(!)&c You cannot interact with blazes until you have solved the captcha, if you think there is an issue, relog and it will resolve it."));
|
||||
return;
|
||||
}
|
||||
|
||||
Player p = (Player) event.getDamager();
|
||||
/*
|
||||
ArmorSet fortuneSet = CrankedArmor.getInstance().getArmorSetRegister().getArmorSetFromID("fortune");
|
||||
boolean inFortuneSet = CrankedArmorAPI.getCurrentArmorSet(p) != null && CrankedArmorAPI.getCurrentArmorSet(p) == fortuneSet;
|
||||
|
||||
*/
|
||||
int amountMobsToKill = 1;
|
||||
int keyGrindLevel = 1;
|
||||
int exp = (int) event.getExp(entity.getType());
|
||||
GrindingCache grindingCache = grindingManager.getGrindingCache(p);
|
||||
|
||||
/*
|
||||
if (inFortuneSet && Math.random() < 0.2) {
|
||||
amountMobsToKill++;
|
||||
}
|
||||
|
||||
|
||||
if (!ItemUtils.isAirOrNull(p.getItemInHand())) {
|
||||
|
||||
EnchantedItemBuilder enchantedItemBuilder = new EnchantedItemBuilder(p.getItemInHand());
|
||||
keyGrindLevel = enchantedItemBuilder.hasEnchantment("jewels") ? (1 + (enchantedItemBuilder.getEnchantmentLevel("jewels"))) : 1;
|
||||
|
||||
if (enchantedItemBuilder.hasEnchantment("plunder")) {
|
||||
keyGrindLevel++;
|
||||
exp *= 1.25;
|
||||
}
|
||||
double chefChance = SpawnerPlugin.getInstance().getConfigManager().getConfig(ConfigManager.ConfigFile.PRIMARY).getDouble("chefRewardChance") * 0.01;
|
||||
|
||||
if (enchantedItemBuilder.hasEnchantment("chef") && Math.random() < chefChance) {
|
||||
try {
|
||||
CrankedLootboxes.getInstance().getLootboxManager().giveLootbox(p, CrankedLootboxes.getInstance().getLootboxRegister().getLootbox("ValentineCube"), 1);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
*/
|
||||
if (CrankedMasksAPI.hasMaskEquipped(p, CrankedMasks.getInstance().getMasksRegister().getMaskFromID("tinker"))) {
|
||||
exp *= 1.5;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
if (inFortuneSet) {
|
||||
exp *= 2;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
if (((ExperiencePet) CrankedPets.getInstance().getPetRegister().getPetFromID("experience")).getPlayersUsingExpPet().contains(p.getUniqueId())) {
|
||||
exp *= ((ExperiencePet) CrankedPets.getInstance().getPetRegister().getPetFromID("experience")).getExpMultiplier();
|
||||
}
|
||||
|
||||
grindingCache.addMobKilled(amountMobsToKill);
|
||||
for (int i = 0; i < amountMobsToKill; i++) {
|
||||
grindingCache.addMoney(event.getMoney(entity.getType()));
|
||||
grindingCache.addExp(exp);
|
||||
handleKeyGiving(p, keyGrindLevel);
|
||||
if (Math.random() < 0.02 * Math.max(1, keyGrindLevel / 2)) {
|
||||
grindingCache.addShards(new Random().nextInt((3 - 1) + 1) + 1);
|
||||
}
|
||||
}
|
||||
|
||||
plugin.addPlayerToAfkGrinding(p);
|
||||
mobStackerUtils.setStackSize(entity, mobStackerUtils.getStackSize(entity) - amountMobsToKill);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onMobDeath(EntityDamageByEntityEvent event) {
|
||||
if (!(event.getEntity() instanceof Creature)) return;
|
||||
|
||||
if (event.getEntity().getLastDamageCause() != null) {
|
||||
if (event.getEntity().getLastDamageCause().getCause() == EntityDamageEvent.DamageCause.FALL) return;
|
||||
if (event.getEntity().getLastDamageCause().getCause() == EntityDamageEvent.DamageCause.FIRE) return;
|
||||
if (event.getEntity().getLastDamageCause().getCause() == EntityDamageEvent.DamageCause.FIRE_TICK) return;
|
||||
}
|
||||
|
||||
Creature entity = (Creature) event.getEntity();
|
||||
if (!mobStackerUtils.isStackedMob(entity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.blazeCooldown.containsKey(event.getEntity().getUniqueId())) {
|
||||
if (System.currentTimeMillis() < this.blazeCooldown.get(event.getEntity().getUniqueId()) + (long) 83) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.blazeCooldown.put(event.getEntity().getUniqueId(), System.currentTimeMillis());
|
||||
|
||||
StackedMobDeathEvent stackedMobDeathEvent = new StackedMobDeathEvent(entity, event.getDamager());
|
||||
try {
|
||||
Bukkit.getPluginManager().callEvent(stackedMobDeathEvent);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
entity.setHealth(entity.getMaxHealth());
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
|
||||
public void handleKeyGiving(Player player, int keyGrindLevel) {
|
||||
double MYTHIC_CHANCE = SpawnerPlugin.getInstance().getConfigManager().getConfig(ConfigManager.ConfigFile.PRIMARY).getDouble("mythicKeyChance") *0.01;
|
||||
if (Math.random() < (MYTHIC_CHANCE * Math.max(1, keyGrindLevel / 2))) {
|
||||
CrankedCrateKeysAPI.givePlayerKeys(player, CrateKeyType.MYTHIC_KEY, 1);
|
||||
return;
|
||||
}
|
||||
double RAREKEY_CHANCE = SpawnerPlugin.getInstance().getConfigManager().getConfig(ConfigManager.ConfigFile.PRIMARY).getDouble("rareKeyChance") *0.01;
|
||||
if (Math.random() < RAREKEY_CHANCE * Math.max(1, keyGrindLevel / 2)) {
|
||||
CrankedCrateKeysAPI.givePlayerKeys(player, CrateKeyType.ABYSS_KEY, 1);
|
||||
return;
|
||||
}
|
||||
double COMMON_CHANCE = SpawnerPlugin.getInstance().getConfigManager().getConfig(ConfigManager.ConfigFile.PRIMARY).getDouble("commonKeyChance") *0.01;
|
||||
if (Math.random() < COMMON_CHANCE * Math.max(1, keyGrindLevel / 2)) {
|
||||
CrankedCrateKeysAPI.givePlayerKeys(player, CrateKeyType.SEASON_KEY, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package net.crankedpvp.spawners.listeners;
|
||||
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.crankedutils.utils.NumberUtils;
|
||||
import net.crankedpvp.spawners.SpawnerPlugin;
|
||||
import net.crankedpvp.spawners.data.ftop.FactionData;
|
||||
import net.crankedpvp.spawners.struct.ftop.FactionsTopManager;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class FtopCommandListener implements Listener {
|
||||
|
||||
private final FactionsTopManager factionsTopManager;
|
||||
|
||||
public FtopCommandListener(SpawnerPlugin plugin) {
|
||||
this.factionsTopManager = plugin.getFactionsTopManager();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onFactionCommand(final PlayerCommandPreprocessEvent event) {
|
||||
final String cmd = event.getMessage().toLowerCase();
|
||||
Player player = event.getPlayer();
|
||||
if (cmd.startsWith("/f top")) {
|
||||
event.setCancelled(true);
|
||||
int page;
|
||||
try {
|
||||
page = Integer.parseInt(cmd.replace("/f top ", ""));
|
||||
if (page > 5) {
|
||||
page = 5;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
page = 1;
|
||||
}
|
||||
|
||||
player.sendMessage("");
|
||||
player.sendMessage(CC.GoldB + "Top Factions (" + CC.WhiteB + page + CC.Gold + "/" + CC.WhiteB + "5" + CC.Gold + ")");
|
||||
int pos = 1;
|
||||
int from = (page - 1) * 9;
|
||||
int to = (page - 1) * 9 + 9;
|
||||
Map<Integer, FactionData> data = this.factionsTopManager.getTopFactions(from, to);
|
||||
for (int x = from; x < to; x++) {
|
||||
if (data.containsKey(x)) {
|
||||
FactionData faction = data.get(x);
|
||||
TextComponent msg = new TextComponent(CC.GoldB + pos + ". " + CC.Gold + faction.getFaction().getTag() + CC.Gold + " - " + CC.WhiteB + "$" + NumberUtils.formatMoney(faction.getSpawnerValue()));
|
||||
String builder = CC.GoldB + CC.Underline + faction.getFaction().getTag() + "\n\n" +
|
||||
CC.White + "Member Wealth: " + CC.Gold + "$" + NumberUtils.formatMoney(faction.getMemberValue()) + "\n" +
|
||||
CC.White + "Spawner Value: " + CC.Gold + "$" + NumberUtils.formatMoney(faction.getSpawnerValue()) + "\n" +
|
||||
CC.White + "Spawners: " + CC.Gold + faction.getSpawnerCount() + "\n" +
|
||||
CC.White + "Stacked Spawners: " + CC.Gold + faction
|
||||
.getStackedSpawnerCount() +
|
||||
"\n" +
|
||||
CC.White + "Richest Member:\n" +
|
||||
" " + CC.Gold + faction.getRichestPlayer() + ": $" + NumberUtils.formatMoney(faction.getRichestPlayerBalance());
|
||||
msg.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, (new ComponentBuilder(builder)).create()));
|
||||
player.sendMessage(msg);
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
player.sendMessage("");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package net.crankedpvp.spawners.listeners;
|
||||
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.spawners.SpawnerPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public class GrindingGuiClose implements Listener {
|
||||
@EventHandler
|
||||
public void onClose(InventoryCloseEvent e) {
|
||||
if (SpawnerPlugin.getInstance().getWaitingForAfkGrindingVerification().contains(e.getPlayer().getUniqueId())) {
|
||||
Bukkit.getScheduler().runTaskLater(SpawnerPlugin.getInstance(), () -> {
|
||||
SpawnerPlugin.getInstance().getAfkGrinders().put(e.getPlayer().getUniqueId(), 1);
|
||||
SpawnerPlugin.getInstance().getWaitingForAfkGrindingVerification().remove(e.getPlayer().getUniqueId());
|
||||
e.getPlayer().sendMessage(CC.translate("&a&l(!)&a You have completed the anti afk grinding captcha! You can now enjoy grinding again."));
|
||||
e.getPlayer().closeInventory();
|
||||
}, 2L);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void cancelInteract(PlayerInteractEvent e) {
|
||||
if (SpawnerPlugin.getInstance().getWaitingForAfkGrindingVerification().contains(e.getPlayer().getUniqueId())) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onQuit(PlayerQuitEvent e) {
|
||||
SpawnerPlugin.getInstance().getWaitingForAfkGrindingVerification().remove(e.getPlayer().getUniqueId());
|
||||
SpawnerPlugin.getInstance().getAfkGrinders().remove(e.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,270 @@
|
||||
package net.crankedpvp.spawners.listeners;
|
||||
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.FPlayers;
|
||||
import net.coreprotect.CoreProtect;
|
||||
import net.coreprotect.CoreProtectAPI;
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.crankedutils.utils.EntityUtils;
|
||||
import net.crankedpvp.factionlogs.struct.impl.SpawnerPlace;
|
||||
import net.crankedpvp.factionlogs.utils.FactionsLogsAPI;
|
||||
import net.crankedpvp.spawners.SpawnerPlugin;
|
||||
import net.crankedpvp.spawners.data.spawners.SpawnerData;
|
||||
import net.crankedpvp.spawners.events.SpawnerPlaceEvent;
|
||||
import net.crankedpvp.spawners.items.ItemSpawner;
|
||||
import net.crankedpvp.spawners.struct.spawners.SpawnerManager;
|
||||
import net.crankedpvp.spawners.utils.ConfigManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class MobSpawnerListener implements Listener {
|
||||
|
||||
private final ConfigManager configManager;
|
||||
private final SpawnerPlugin plugin;
|
||||
private final CoreProtectAPI coreProtectAPI;
|
||||
|
||||
public MobSpawnerListener(SpawnerPlugin plugin) {
|
||||
this.configManager = plugin.getConfigManager();
|
||||
this.coreProtectAPI = CoreProtect.getInstance().getAPI();
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
//This is when you place a new spawner
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlace(BlockPlaceEvent event) {
|
||||
if (event.getBlockPlaced().getType() != Material.MOB_SPAWNER) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean allowSpawners = this.configManager.getConfig(ConfigManager.ConfigFile.PRIMARY).getConfigurationSection("spawners").getBoolean("can-place");
|
||||
|
||||
if (!allowSpawners) {
|
||||
event.getPlayer().sendMessage(CC.translate("&c&l(!)&c Spawner placement has been disabled!"));
|
||||
event.getPlayer().sendMessage(CC.translate("&7You can no longer place FTOP value."));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack item = event.getPlayer().getItemInHand();
|
||||
if (item.getAmount() > 1) {
|
||||
event.getPlayer().sendMessage(CC.translate("&c&l(!)&c You cannot place stacked spawners!"));
|
||||
event.getPlayer().sendMessage(CC.translate("&7Combine them by drag and dropping them together or type /stackspawners."));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
EntityType type = ItemSpawner.getEntityTypeFromItem(item);
|
||||
|
||||
if (!SpawnerManager.canPlaceStackedSpawnerInThisChunk(event.getBlock().getChunk(), type)) {
|
||||
event.getPlayer().sendMessage(CC.translate("&c&l(!)&c This chunk already contains this spawner type."));
|
||||
event.getPlayer().sendMessage(CC.translate("&cPlease stack it on the existing spawner."));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (type == null) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (SpawnerPlugin.coolDownSpawnerPlace.contains(event.getPlayer())) {
|
||||
event.getPlayer().sendMessage(CC.translate("&c&l(!)&c Please be patient, you are still on spawner place cooldown."));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int amount = ItemSpawner.getSpawnerAmount(item);
|
||||
if (amount <= 0) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
int math = Math.min(amount, ItemSpawner.getSpawnerLimit());
|
||||
int spawnersLeft = amount - math;
|
||||
event.getPlayer().sendMessage(CC.translate("&a&l+ &a&n" + amount + "&a " + EntityUtils.getEntityName(type) + " Spawner(s) &7[" + amount + " Total]"));
|
||||
|
||||
SpawnerPlugin.coolDownSpawnerPlace.add(event.getPlayer());
|
||||
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, () -> {
|
||||
SpawnerPlugin.coolDownSpawnerPlace.remove(event.getPlayer());
|
||||
}, 20L);
|
||||
|
||||
SpawnerData spawnerData = new SpawnerData(type, math, event.getBlock().getLocation());
|
||||
SpawnerPlugin.getInstance().getSpawnerManager().addToCache(spawnerData);
|
||||
|
||||
event.getPlayer().setItemInHand(spawnersLeft <= 0 ? null : ItemSpawner.getItem(type, spawnersLeft));
|
||||
Location location = event.getBlockPlaced().getLocation();
|
||||
Bukkit.getScheduler().runTaskLater(plugin, (Runnable) new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
location.getBlock().setType(Material.MOB_SPAWNER);
|
||||
((CreatureSpawner) location.getBlock().getState()).setSpawnedType(type);
|
||||
SpawnerPlaceEvent spawnerPlaceEvent = new SpawnerPlaceEvent(location);
|
||||
Bukkit.getPluginManager().callEvent(spawnerPlaceEvent);
|
||||
|
||||
//TODO: look into fixing this
|
||||
/* if (CollectorManager.DELEGATE.isCollectorContained(event.getBlock().getLocation())) {
|
||||
Collector collector = CollectorManager.DELEGATE.getCollector(event.getBlock().getLocation());
|
||||
collector.clearSpawners();
|
||||
collector.scanSpawners(collector.getLocation());
|
||||
}*/
|
||||
}
|
||||
|
||||
}, 1);
|
||||
event.setCancelled(true);
|
||||
|
||||
this.coreProtectAPI.logPlacement(event.getPlayer().getName(), event.getBlockPlaced().getLocation(), event.getBlockPlaced().getType(), event.getBlockPlaced().getData());
|
||||
|
||||
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(event.getPlayer());
|
||||
if (!fPlayer.getFaction().isWilderness()) {
|
||||
FactionsLogsAPI.log(fPlayer.getFaction().getId(), new SpawnerPlace(amount, location, type, fPlayer.getPlayer().getUniqueId()));
|
||||
}
|
||||
event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.NOTE_PLING, 10f, 10f);
|
||||
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onInteract(PlayerInteractEvent e) {
|
||||
if (e.getClickedBlock() == null && e.getPlayer().getItemInHand() != null && e.getPlayer().getItemInHand().getType() == Material.MOB_SPAWNER) {
|
||||
Player player = e.getPlayer();
|
||||
if(e.isCancelled()) return;
|
||||
EntityType type = ItemSpawner.getEntityTypeFromItem(e.getItem());
|
||||
int amount = ItemSpawner.getSpawnerAmount(e.getItem());
|
||||
player.sendMessage(CC.translate(""));
|
||||
player.sendMessage(CC.translate("&4&lSpawner Info"));
|
||||
player.sendMessage(CC.RedB + " * " + CC.White + "Type: " + CC.Red + EntityUtils.getEntityName(type));
|
||||
player.sendMessage(CC.RedB + " * " + CC.White + "Amount: " + CC.Red + amount);
|
||||
//player.sendMessage(CC.RedB + " * " + CC.White + "Income: " + CC.Red +"$" + NumberUtils.formatMoney(CollectorsPlugin.INSTANCE.getSpawnerUtil().getMoneyPerMinute(type)*60) + "/h");
|
||||
player.sendMessage(CC.translate(""));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//This is when you place a spawner on a different spawner
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onSpawnerPlaceOnSpawner(BlockPlaceEvent event) {
|
||||
Block block = event.getBlock();
|
||||
if (block.getType() == Material.MOB_SPAWNER) {
|
||||
if (event.getBlockAgainst().getType() == Material.MOB_SPAWNER) {
|
||||
EntityType type = ((CreatureSpawner) event.getBlockAgainst().getState()).getSpawnedType();
|
||||
if (ItemSpawner.getEntityTypeFromItem(event.getPlayer().getItemInHand()) == type) {
|
||||
int amount = ItemSpawner.getSpawnerAmount(event.getPlayer().getItemInHand());
|
||||
if (amount <= 0) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (SpawnerPlugin.coolDownSpawnerPlace.contains(event.getPlayer())) {
|
||||
event.getPlayer().sendMessage(CC.translate("&c&l(!)&c Please be patient, you are still on spawner place cooldown."));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//CHANGED
|
||||
event.setCancelled(true);
|
||||
Player player = event.getPlayer();
|
||||
SpawnerPlugin.coolDownSpawnerPlace.add(event.getPlayer());
|
||||
Bukkit.getScheduler().runTaskLaterAsynchronously(this.plugin, () -> {
|
||||
SpawnerPlugin.coolDownSpawnerPlace.remove(event.getPlayer());
|
||||
}, 20L);
|
||||
|
||||
SpawnerData found = plugin.getSpawnerManager().getSpawnerData(event.getBlockAgainst().getLocation());
|
||||
if (found != null) {
|
||||
if (found.getSpawnerAmount() >= ItemSpawner.getSpawnerLimit()) {
|
||||
player.sendMessage(CC.RedB + "(!) " + CC.Red + "You can not have more than "
|
||||
+ ItemSpawner.getSpawnerLimit() + " spawners stacked together!");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
boolean allowSpawners = configManager.getConfig(ConfigManager.ConfigFile.PRIMARY).getConfigurationSection("spawners").getBoolean("can-place");
|
||||
|
||||
|
||||
if (!allowSpawners) {
|
||||
event.getPlayer().sendMessage(CC.translate("&c&l(!)&c Spawner placement has been disabled!"));
|
||||
event.getPlayer().sendMessage(CC.translate("&7You can no longer place FTOP value."));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getItemInHand().getAmount() > 1) {
|
||||
event.getPlayer().sendMessage(CC.translate("&c&l(!)&c You cannot place stacked spawners!"));
|
||||
event.getPlayer().sendMessage(CC.translate("&7Combine them by drag and dropping them together or type /stackspawners."));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
int math = found.getSpawnerAmount() + amount >= ItemSpawner.getSpawnerLimit()
|
||||
? ItemSpawner.getSpawnerLimit() - found.getSpawnerAmount()
|
||||
: amount;
|
||||
int spawnersLeft = amount - math;
|
||||
found.setSpawnerAmount(found.getSpawnerAmount() + math);
|
||||
player.sendMessage(CC.translate("&a&l+ &a&n" + amount + "&a " + EntityUtils.getEntityName(type) + " Spawner(s) &7[" + found.getSpawnerAmount() + " Total]"));
|
||||
player.playSound(player.getLocation(), Sound.NOTE_PLING, 10f, 10f);
|
||||
SpawnerPlaceEvent spawnerPlaceEvent = new SpawnerPlaceEvent(block.getLocation());
|
||||
Bukkit.getPluginManager().callEvent(spawnerPlaceEvent);
|
||||
/*if (CollectorManager.DELEGATE.isCollectorContained(event.getBlock().getLocation())) {
|
||||
Collector collector = CollectorManager.DELEGATE.getCollector(event.getBlock().getLocation());
|
||||
collector.clearSpawners();
|
||||
collector.scanSpawners(collector.getLocation());
|
||||
}*/
|
||||
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(event.getPlayer());
|
||||
if (!fPlayer.getFaction().isWilderness()) {
|
||||
FactionsLogsAPI.log(fPlayer.getFaction().getId(), new SpawnerPlace(amount, event.getBlockAgainst().getLocation(), type, fPlayer.getPlayer().getUniqueId()));
|
||||
}
|
||||
|
||||
player.setItemInHand(
|
||||
spawnersLeft <= 0 ? null : ItemSpawner.getItem(type, spawnersLeft));
|
||||
} else {
|
||||
player.sendMessage(CC.translate("&c&l(!)&c This is not a valid stacked spawner. Contact an administrator if you think this is an issue."));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
player.updateInventory();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onSpawnerInteract(PlayerInteractEvent event) {
|
||||
if (event.isCancelled()) return;
|
||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getItem() == null) {
|
||||
Block block = event.getClickedBlock();
|
||||
if (block.getType() == Material.MOB_SPAWNER) {
|
||||
event.setCancelled(true);
|
||||
EntityType type = ((CreatureSpawner) block.getState()).getSpawnedType();
|
||||
|
||||
SpawnerData found = plugin.getSpawnerManager().getSpawnerData(event.getClickedBlock().getLocation());
|
||||
Player player = event.getPlayer();
|
||||
player.sendMessage("");
|
||||
player.sendMessage(CC.DarkRedB + "Spawner Info");
|
||||
player.sendMessage(CC.RedB + " * " + CC.White + "Type: " +
|
||||
CC.Red + EntityUtils.getEntityName(type));
|
||||
player.sendMessage(CC.RedB + " * " + CC.White + "Amount: " + CC.Red
|
||||
+ (found != null ? found.getSpawnerAmount() : 1) + "x");
|
||||
player.sendMessage("");
|
||||
player.playSound(player.getLocation(), Sound.NOTE_PLING, 10f, 10f);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
package net.crankedpvp.spawners.listeners;
|
||||
|
||||
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.FPlayers;
|
||||
import net.coreprotect.CoreProtect;
|
||||
import net.coreprotect.CoreProtectAPI;
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.crankedutils.utils.EntityUtils;
|
||||
import net.crankedpvp.customexplosions.listeners.CreeperListener;
|
||||
import net.crankedpvp.customexplosions.struct.CreeperTypes;
|
||||
import net.crankedpvp.factionlogs.struct.impl.SpawnerBreak;
|
||||
import net.crankedpvp.factionlogs.utils.FactionsLogsAPI;
|
||||
import net.crankedpvp.spawners.SpawnerPlugin;
|
||||
import net.crankedpvp.spawners.data.spawners.SpawnerData;
|
||||
import net.crankedpvp.spawners.events.SpawnerBreakEvent;
|
||||
import net.crankedpvp.spawners.items.ItemSpawner;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Creeper;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SpawnerBreakListener implements Listener {
|
||||
|
||||
private final CoreProtectAPI coreProtectAPI;
|
||||
|
||||
public SpawnerBreakListener() {
|
||||
this.coreProtectAPI = CoreProtect.getInstance().getAPI();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onExplode(EntityExplodeEvent event) {
|
||||
double chance = event.getEntity() instanceof TNTPrimed ? 0.20 : event.getEntity() instanceof Creeper ? 0.30 : 0;
|
||||
if (chance <= 0) {
|
||||
return;
|
||||
}
|
||||
if (!(event.getEntity() instanceof Creeper) && !(event.getEntity() instanceof TNTPrimed)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(event.getEntity() instanceof Creeper) {
|
||||
Creeper c = (Creeper) event.getEntity();
|
||||
if(CreeperListener.creepers.containsKey(c.getUniqueId())) {
|
||||
CreeperTypes egg_type = CreeperListener.creepers.get(c.getUniqueId());
|
||||
if(egg_type == CreeperTypes.LUCKY) {
|
||||
chance = 0.5;
|
||||
}
|
||||
if(egg_type == CreeperTypes.RAID) {
|
||||
chance = 1;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
List<Block> blocks = event.blockList();
|
||||
for (int i = blocks.size() - 1; i >= 0; i--) {
|
||||
Block block = blocks.get(i);
|
||||
if (block.getType() == Material.MOB_SPAWNER) {
|
||||
SpawnerData data = SpawnerPlugin.getInstance().getSpawnerManager().getSpawnerData(block.getLocation());
|
||||
if (data != null) {
|
||||
EntityType type = data.getEntityType();
|
||||
int amount = data.getSpawnerAmount();
|
||||
World world = block.getWorld();
|
||||
Location location = block.getLocation();
|
||||
int spawnerAmount = 0;
|
||||
for(int pos = 0; pos < amount; pos++) {
|
||||
if(chance > Math.random()) {
|
||||
spawnerAmount++;
|
||||
}
|
||||
}
|
||||
if (spawnerAmount > 0) {
|
||||
world.dropItem(location, ItemSpawner.getItem(type, spawnerAmount));
|
||||
}
|
||||
data.setSpawnerAmount(0);
|
||||
SpawnerPlugin.getInstance().getSpawnerManager().removeFromCache(data);
|
||||
|
||||
SpawnerBreakEvent spawnerBreakEvent = new SpawnerBreakEvent(block.getLocation());
|
||||
Bukkit.getPluginManager().callEvent(spawnerBreakEvent);
|
||||
|
||||
|
||||
/* if (CollectorManager.DELEGATE.isCollectorContained(block.getLocation())) {
|
||||
net.crankedpvp.collectors.collector.Collector collector = CollectorManager.DELEGATE.getCollector(block.getLocation());
|
||||
collector.clearSpawners();
|
||||
collector.scanSpawners(collector.getLocation());
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onMine(BlockBreakEvent event) {
|
||||
if (event.getBlock().getType() == Material.MOB_SPAWNER) {
|
||||
Block block = event.getBlock();
|
||||
SpawnerData data = SpawnerPlugin.getInstance().getSpawnerManager().getSpawnerData(block.getLocation());
|
||||
if (data != null) {
|
||||
this.coreProtectAPI.logRemoval(event.getPlayer().getName(), block.getLocation(), block.getType(), block.getData());
|
||||
|
||||
EntityType type = data.getEntityType();
|
||||
int amount = data.getSpawnerAmount();
|
||||
data.setSpawnerAmount(0);
|
||||
block.getWorld().dropItem(block.getLocation(), ItemSpawner.getItem(type, amount));
|
||||
event.getPlayer().sendMessage(CC.translate("&c&l- &c&n" + amount + "&c " + EntityUtils.getEntityName(type) + " Spawner(s)"));
|
||||
SpawnerPlugin.getInstance().getSpawnerManager().removeFromCache(data);
|
||||
block.setType(Material.AIR);
|
||||
event.setCancelled(true);
|
||||
|
||||
SpawnerBreakEvent spawnerBreakEvent = new SpawnerBreakEvent(block.getLocation());
|
||||
Bukkit.getPluginManager().callEvent(spawnerBreakEvent);
|
||||
|
||||
/* if (CollectorManager.DELEGATE.isCollectorContained(event.getBlock().getLocation())) {
|
||||
Collector collector = CollectorManager.DELEGATE.getCollector(event.getBlock().getLocation());
|
||||
collector.clearSpawners();
|
||||
collector.scanSpawners(collector.getLocation());
|
||||
}*/
|
||||
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(event.getPlayer());
|
||||
if (!fPlayer.getFaction().isWilderness()) {
|
||||
FactionsLogsAPI.log(fPlayer.getFaction().getId(), new SpawnerBreak(amount, event.getBlock().getLocation(), type, fPlayer.getPlayer().getUniqueId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package net.crankedpvp.spawners.listeners;
|
||||
|
||||
import net.crankedpvp.spawners.SpawnerPlugin;
|
||||
import net.crankedpvp.spawners.utils.MobStackerUtils;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.SpawnerSpawnEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SpawnerSpawnListener implements Listener {
|
||||
private final MobStackerUtils mobStackerUtils;
|
||||
private List<EntityType> stackMobs;
|
||||
|
||||
public SpawnerSpawnListener(SpawnerPlugin plugin) {
|
||||
this.mobStackerUtils = plugin.getMobStackerUtils();
|
||||
this.stackMobs = new ArrayList<>();
|
||||
stackMobs.add(EntityType.BLAZE);
|
||||
stackMobs.add(EntityType.SKELETON);
|
||||
stackMobs.add(EntityType.ZOMBIE);
|
||||
stackMobs.add(EntityType.SPIDER);
|
||||
stackMobs.add(EntityType.CAVE_SPIDER);
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void stopMobSpawn(SpawnerSpawnEvent e) {
|
||||
if (stackMobs.contains(e.getEntityType())) {
|
||||
mobStackerUtils.stackMobs(e);
|
||||
} else {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package net.crankedpvp.spawners.struct.ftop;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import net.crankedpvp.spawners.data.ftop.FactionData;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class FactionCache {
|
||||
private static Map<Integer, FactionData> factions = Maps.newHashMap();
|
||||
|
||||
public static Map<Integer, FactionData> getData() {
|
||||
return factions;
|
||||
}
|
||||
|
||||
public static void setFactionData(Map<Integer, FactionData> factions) {
|
||||
FactionCache.factions = factions;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package net.crankedpvp.spawners.struct.ftop;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import net.crankedpvp.crankedutils.utils.FactionUtils;
|
||||
import net.crankedpvp.crankedutils.utils.SortUtils;
|
||||
import net.crankedpvp.spawners.SpawnerPlugin;
|
||||
import net.crankedpvp.spawners.data.ftop.FactionData;
|
||||
import net.crankedpvp.spawners.utils.ConfigManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class FactionsTopManager {
|
||||
|
||||
private final EnumMap<EntityType, Integer> spawnerWorth;
|
||||
|
||||
public FactionsTopManager(SpawnerPlugin plugin) {
|
||||
this.spawnerWorth = new EnumMap<>(EntityType.class);
|
||||
|
||||
ConfigManager configmanager = plugin.getConfigManager();
|
||||
FileConfiguration config = configmanager.getConfig(ConfigManager.ConfigFile.PRIMARY);
|
||||
ConfigurationSection configurationSection = config.getConfigurationSection("spawners.worth");
|
||||
|
||||
for (String key : configurationSection.getKeys(false)) {
|
||||
int worth = configurationSection.getInt(key);
|
||||
EntityType entityType;
|
||||
|
||||
try {
|
||||
entityType = EntityType.valueOf(key.toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Invalid Spawner type in config");
|
||||
continue;
|
||||
}
|
||||
|
||||
this.spawnerWorth.put(entityType, worth);
|
||||
}
|
||||
}
|
||||
|
||||
public void recalculateFactionsTop() {
|
||||
FactionCache.getData().clear();
|
||||
Bukkit.getScheduler().runTaskAsynchronously(SpawnerPlugin.getInstance(), () -> {
|
||||
Map<FactionData, Long> factions = Maps.newHashMap();
|
||||
for (Faction faction : FactionUtils.getAllFactions()) {
|
||||
if (faction.isSafeZone() || faction.isWarZone() || faction.isWilderness())
|
||||
continue;
|
||||
FactionData factionData = new FactionData(faction);
|
||||
factions.put(factionData, factionData.getSpawnerValue());
|
||||
}
|
||||
factions = SortUtils.sort(factions);
|
||||
Map<Integer, FactionData> data = Maps.newLinkedHashMap();
|
||||
int pos = 0;
|
||||
for (Map.Entry<FactionData, Long> entry : factions.entrySet()) {
|
||||
data.put(pos, entry.getKey());
|
||||
pos++;
|
||||
}
|
||||
FactionCache.setFactionData(data);
|
||||
});
|
||||
}
|
||||
|
||||
public Map<Integer, FactionData> getTopFactions(int from, int to) {
|
||||
Map<Integer, FactionData> data = Maps.newHashMap();
|
||||
for (Map.Entry<Integer, FactionData> entry : FactionCache.getData().entrySet()) {
|
||||
int value = entry.getKey();
|
||||
if (from <= value && to >= value)
|
||||
data.put(value, entry.getValue());
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public int getFactionTop(Faction faction) {
|
||||
int place=0;
|
||||
for (Map.Entry<Integer, FactionData> entry : getTopFactions(0, 9999).entrySet()) {
|
||||
if (entry.getValue().getFaction().getId().equals(faction.getId())) {
|
||||
place = entry.getKey();
|
||||
return place +1;
|
||||
}
|
||||
}
|
||||
return place;
|
||||
}
|
||||
|
||||
public FactionData getFactionData(Faction faction) {
|
||||
for(FactionData value : FactionCache.getData().values()) {
|
||||
if(faction.equals(value.getFaction())) return value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public long getValueOfSpawner(EntityType type) {
|
||||
return this.spawnerWorth.getOrDefault(type, 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package net.crankedpvp.spawners.struct.ftop;
|
||||
|
||||
import net.crankedpvp.spawners.SpawnerPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class RecalculationTask extends BukkitRunnable {
|
||||
|
||||
private final FactionsTopManager factionsTopManager;
|
||||
|
||||
public RecalculationTask(SpawnerPlugin plugin) {
|
||||
this.factionsTopManager = plugin.getFactionsTopManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
this.factionsTopManager.recalculateFactionsTop();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package net.crankedpvp.spawners.struct.grinding;
|
||||
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.crankedutils.utils.EconomyUtils;
|
||||
import net.crankedpvp.crankedutils.utils.NumberUtils;
|
||||
import net.crankedpvp.crankedutils.utils.XPUtils;
|
||||
import net.crankedpvp.leaderboards.LeaderboardsAPI;
|
||||
import net.crankedpvp.shards.ShardsAPI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class GrindingCache {
|
||||
private int mobsKilled;
|
||||
private double moneyEarned;
|
||||
private int expEarned;
|
||||
private int shardsEarned;
|
||||
private UUID uuid;
|
||||
|
||||
public GrindingCache(UUID uuid) {
|
||||
this.moneyEarned = 0;
|
||||
this.expEarned = 0;
|
||||
this.shardsEarned = 0;
|
||||
this.mobsKilled = 0;
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public void claimGrindingRewards() {
|
||||
if (expEarned == 0 && moneyEarned == 0 && shardsEarned == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
if (player == null || !player.isOnline()) return;
|
||||
|
||||
XPUtils.addExperience(player, expEarned);
|
||||
EconomyUtils.depositBalance(player,moneyEarned);
|
||||
ShardsAPI.addShards(player, shardsEarned);
|
||||
LeaderboardsAPI.getPlayerStats(player.getUniqueId()).addEXPGained(expEarned);
|
||||
LeaderboardsAPI.getPlayerStats(player.getUniqueId()).addMobsKilled(this.mobsKilled);
|
||||
|
||||
player.sendMessage(CC.translate(""));
|
||||
player.sendMessage(CC.translate("&6&lGrinding Rewards"));
|
||||
player.sendMessage(CC.translate("&8 ➥ &7EXP: &d" + NumberUtils.formatMoney(expEarned)));
|
||||
player.sendMessage(CC.translate("&8 ➥ &7Money: &2$&a" + NumberUtils.formatMoney(moneyEarned)));
|
||||
player.sendMessage(CC.translate("&8 ➥ &7Gold: &6⛃&e" + NumberUtils.formatMoney(shardsEarned)));
|
||||
player.sendMessage(CC.translate("&8 ➥ &7Mobs Killed: &c" + NumberUtils.formatMoney(mobsKilled)));
|
||||
player.sendMessage(CC.translate("&7&o(( Every &f10s&7&o you will receive your grinding rewards from the last 10s. ))"));
|
||||
player.sendMessage(CC.translate(""));
|
||||
|
||||
this.expEarned = 0;
|
||||
this.moneyEarned = 0;
|
||||
this.shardsEarned = 0;
|
||||
this.mobsKilled = 0;
|
||||
}
|
||||
|
||||
public void addExp(int amount) {
|
||||
this.expEarned += amount;
|
||||
}
|
||||
|
||||
public void addShards(int amount) {
|
||||
this.shardsEarned += amount;
|
||||
}
|
||||
|
||||
public void addMoney(double amount) {
|
||||
this.moneyEarned += amount;
|
||||
}
|
||||
|
||||
public void addMobKilled(int amount) {
|
||||
this.mobsKilled += amount;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package net.crankedpvp.spawners.struct.grinding;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.crankedpvp.spawners.SpawnerPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
public class GrindingManager {
|
||||
private Map<UUID, GrindingCache> grindingCacheMap;
|
||||
|
||||
public GrindingManager() {
|
||||
this.grindingCacheMap = new HashMap<>();
|
||||
/*
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(SpawnerPlugin.getInstance(), ()-> {
|
||||
for (GrindingCache grindingCache : grindingCacheMap.values()) {
|
||||
grindingCache.claimGrindingRewards();
|
||||
}
|
||||
}, 40L, 10*20L);
|
||||
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
public GrindingCache getGrindingCache(Player player) {
|
||||
UUID uuid = player.getUniqueId();
|
||||
if (!grindingCacheMap.containsKey(uuid)) {
|
||||
grindingCacheMap.put(uuid, new GrindingCache(uuid));
|
||||
}
|
||||
return grindingCacheMap.get(uuid);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package net.crankedpvp.spawners.struct.spawners;
|
||||
|
||||
import net.crankedpvp.spawners.SpawnerPlugin;
|
||||
import net.crankedpvp.spawners.data.spawners.SpawnerData;
|
||||
import net.crankedpvp.storageutils.StorageUtils;
|
||||
import net.crankedpvp.storageutils.utils.SaveLoadManager;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class SpawnerManager extends SaveLoadManager<SpawnerData> {
|
||||
|
||||
|
||||
public SpawnerManager(SpawnerPlugin plugin) {
|
||||
super(plugin, StorageUtils.getInstance().getGson(), "/data", SpawnerData.class);
|
||||
}
|
||||
|
||||
public SpawnerData getSpawnerData(Location location, EntityType type, int amount) {
|
||||
if (!containsKey(SpawnerData.locationToString(location))) {
|
||||
SpawnerData spawnerData = new SpawnerData(type, amount, location);
|
||||
addToCache(spawnerData);
|
||||
}
|
||||
return getFromCache(SpawnerData.locationToString(location));
|
||||
|
||||
}
|
||||
|
||||
public SpawnerData getSpawnerData(Location location) {
|
||||
return getFromCache(SpawnerData.locationToString(location));
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static boolean canPlaceStackedSpawnerInThisChunk(Chunk chunk, EntityType spawnertype) {
|
||||
for (BlockState blockState : chunk.getTileEntities()) {
|
||||
if (blockState instanceof CreatureSpawner) {
|
||||
EntityType type = ((CreatureSpawner) blockState).getSpawnedType();
|
||||
if (type == spawnertype) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package net.crankedpvp.spawners.utils;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.crankedpvp.crankedutils.utils.config.AbstractConfig;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ConfigManager {
|
||||
|
||||
@Getter
|
||||
private final Map<ConfigFile, AbstractConfig> configs = new HashMap<>();
|
||||
|
||||
public ConfigManager(JavaPlugin plugin) {
|
||||
for (ConfigFile configFile : ConfigFile.values()) {
|
||||
AbstractConfig abstractConfig = new AbstractConfig(plugin, configFile.getFileName());
|
||||
configs.put(configFile, abstractConfig);
|
||||
}
|
||||
}
|
||||
|
||||
public void setupFiles() {
|
||||
configs.values().forEach(AbstractConfig::setupConfigFile);
|
||||
}
|
||||
|
||||
public void reloadFiles() {
|
||||
configs.values().forEach(AbstractConfig::reloadConfig);
|
||||
}
|
||||
|
||||
public AbstractConfig getAbstractConfig(ConfigFile configFile) {
|
||||
return configs.get(configFile);
|
||||
}
|
||||
|
||||
public FileConfiguration getConfig(ConfigFile configFile) {
|
||||
return getAbstractConfig(configFile).getConfig();
|
||||
}
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum ConfigFile {
|
||||
|
||||
PRIMARY("config.yml"),
|
||||
;
|
||||
|
||||
private final String fileName;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
package net.crankedpvp.spawners.utils;
|
||||
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.crankedutils.utils.ChunkUtils;
|
||||
import net.crankedpvp.crankedutils.utils.EntityUtils;
|
||||
import net.crankedpvp.spawners.SpawnerPlugin;
|
||||
import net.crankedpvp.spawners.data.spawners.SpawnerData;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.SpawnerSpawnEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class MobStackerUtils {
|
||||
|
||||
private final HashMap<Entity, Integer> mobMap;
|
||||
|
||||
public MobStackerUtils() {
|
||||
this.mobMap = new HashMap<>();
|
||||
int delayS = 15;
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(SpawnerPlugin.getInstance(), () -> {
|
||||
for (int i = 0; i < mobMap.keySet().size(); i++) {
|
||||
Entity entity = (Entity) mobMap.keySet().toArray()[i];
|
||||
if (!entity.isValid() || entity.isDead()) {
|
||||
mobMap.remove(entity);
|
||||
continue;
|
||||
}
|
||||
stackMobs(entity);
|
||||
}
|
||||
}, 40L, delayS * 20L);
|
||||
}
|
||||
|
||||
public static void onEnable() {
|
||||
for (World world : Bukkit.getWorlds()) {
|
||||
for (Entity entity : world.getEntities()) {
|
||||
if (!(entity instanceof Player) && !(entity instanceof ArmorStand)) {
|
||||
entity.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public HashMap<Entity, Integer> getMobMap() {
|
||||
return mobMap;
|
||||
}
|
||||
|
||||
public int getStackSize(Entity entity) {
|
||||
return mobMap.getOrDefault(entity, 1);
|
||||
}
|
||||
|
||||
public void setStackSize(Entity entity, int size) {
|
||||
entity.setCustomName(CC.RedB + EntityUtils.getEntityName(entity.getType()) + " " + CC.Gray + "[" + CC.White + "x " + CC.Underline + size + CC.Gray + "]");
|
||||
mobMap.put(entity, size);
|
||||
}
|
||||
|
||||
public boolean isStackedMob(Entity entity) {
|
||||
return mobMap.containsKey(entity);
|
||||
}
|
||||
|
||||
public void removeStackedMob(Entity entity) {
|
||||
if (!entity.isDead()) entity.remove();
|
||||
mobMap.remove(entity);
|
||||
}
|
||||
|
||||
public void stackMobs(SpawnerSpawnEvent event) {
|
||||
Chunk chunk = ChunkUtils.getChunkIfLoaded((int) Math.floor(event.getEntity().getLocation().getChunk().getX()), (int) Math.floor(event.getEntity().getLocation().getChunk().getZ()), event.getLocation().getWorld());
|
||||
//Chunk chunk = event.getLocation().getChunk();
|
||||
|
||||
if (chunk == null) {
|
||||
System.out.println("[Spawners] Skipping because chunk is null");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
List<CraftEntity> entities = ChunkUtils.getEntitiesInChunk(chunk);
|
||||
int entityStack = 0;
|
||||
Entity entity = event.getEntity();
|
||||
Location location = event.getSpawner().getLocation();
|
||||
SpawnerData data = SpawnerPlugin.getInstance().getSpawnerManager().getSpawnerData(location);
|
||||
|
||||
int size;
|
||||
|
||||
if (entity.getType() == EntityType.BLAZE) {
|
||||
size = entityStack + (data != null ? (data.getSpawnerAmount() * 10) + 100 : 100);
|
||||
|
||||
|
||||
} else {
|
||||
size = entityStack + (data != null ? data.getSpawnerAmount() : 100);
|
||||
}
|
||||
|
||||
int stackSize = 0;
|
||||
Entity highestStackedEntity = null;
|
||||
|
||||
|
||||
for (Entity nearbyEntity : entities) {
|
||||
if (nearbyEntity.getType() != entity.getType()) continue;
|
||||
if (!isStackedMob(nearbyEntity)) continue;
|
||||
if (getStackSize(nearbyEntity) <= stackSize) continue;
|
||||
highestStackedEntity = nearbyEntity;
|
||||
stackSize = getStackSize(nearbyEntity);
|
||||
}
|
||||
if (highestStackedEntity == null) {
|
||||
setStackSize(entity, size);
|
||||
} else {
|
||||
setStackSize(highestStackedEntity, stackSize + size);
|
||||
removeStackedMob(entity);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void stackMobs(Entity entity) {
|
||||
int stack = getStackSize(entity);
|
||||
Entity highestStackEntity = entity;
|
||||
|
||||
for (Entity nearbyEntity : entity.getNearbyEntities(10, 4, 10)) {
|
||||
if (nearbyEntity.getType() != entity.getType()) continue;
|
||||
if (!isStackedMob(nearbyEntity)) continue;
|
||||
int nearbyStack = getStackSize(nearbyEntity);
|
||||
if (nearbyStack >= stack) {
|
||||
highestStackEntity = nearbyEntity;
|
||||
}
|
||||
|
||||
}
|
||||
if (highestStackEntity.getUniqueId() != entity.getUniqueId()) {
|
||||
setStackSize(highestStackEntity, stack + getStackSize(highestStackEntity));
|
||||
removeStackedMob(entity);
|
||||
}
|
||||
}
|
||||
|
||||
/*public void stackMobs(SpawnerSpawnEvent event) {
|
||||
|
||||
Chunk chunk = event.getLocation().getChunk();
|
||||
Entity[] entities = chunk.getEntities();
|
||||
|
||||
|
||||
int entityStack = 0;
|
||||
Entity entity = event.getEntity();
|
||||
Location location = event.getSpawner().getLocation();
|
||||
SpawnerData data = SpawnerPlugin.getInstance().getSpawnerManager().getSpawnerData(location);
|
||||
|
||||
int size = 0;
|
||||
|
||||
if (entity.getType() == EntityType.BLAZE) {
|
||||
size = entityStack + (data != null ? (data.getSpawnerAmount()*10)+100 : 100);
|
||||
} else {
|
||||
size = entityStack + (data != null ? data.getSpawnerAmount() : 100);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int stackSize = 0;
|
||||
Entity highestStackedEntity = null;
|
||||
|
||||
|
||||
for (Entity nearbyEntity : entities) {
|
||||
if (nearbyEntity.getType() != entity.getType()) continue;
|
||||
if (!isStackedMob(nearbyEntity)) continue;
|
||||
if (getStackSize(nearbyEntity) <= stackSize) continue;
|
||||
highestStackedEntity = nearbyEntity;
|
||||
stackSize = getStackSize(nearbyEntity);
|
||||
}
|
||||
if (highestStackedEntity == null) {
|
||||
setStackSize(entity, size);
|
||||
} else {
|
||||
setStackSize(highestStackedEntity, stackSize + size);
|
||||
removeStackedMob(entity);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
commonKeyChance: 4
|
||||
rareKeyChance: 1
|
||||
mythicKeyChance: 0.35
|
||||
chefRewardChance: 0.2
|
||||
spawners:
|
||||
can-place: true
|
||||
max-stack-size: 1000
|
||||
worth:
|
||||
IRON_GOLEM: 5000000
|
||||
VILLAGER: 10000000
|
||||
WITCH: 8000000
|
||||
@@ -0,0 +1 @@
|
||||
GRINDING_MONEY_GIVE: "&3&lSpawners &8➥ &7You have received &2$&a%amount%&7 from grinding stacked mobs."
|
||||
@@ -0,0 +1,8 @@
|
||||
name: CrankedSpawners
|
||||
main: net.crankedpvp.spawners.SpawnerPlugin
|
||||
version: ${git.total.commit.count}.0
|
||||
description: "§fCommit ID: §a${git.commit.id.abbrev}"
|
||||
website: https://crankedpvp.net/
|
||||
depend:
|
||||
- CrankedUtils
|
||||
- StorageUtil
|
||||
Reference in New Issue
Block a user