mirror of
https://github.com/craftaro/EpicSpawners.git
synced 2025-01-09 03:57:40 +08:00
Merge branch 'master' into 'patch-1'
# Conflicts: # EpicSpawners-Plugin/src/main/java/com/songoda/epicspawners/EpicSpawnersPlugin.java
This commit is contained in:
commit
44f3484284
@ -4,7 +4,7 @@ stages:
|
||||
variables:
|
||||
name: "EpicSpawners"
|
||||
path: "/builds/Songoda/$name"
|
||||
version: "5.5.25"
|
||||
version: "5.5.35"
|
||||
|
||||
build:
|
||||
stage: build
|
||||
@ -12,6 +12,8 @@ build:
|
||||
script:
|
||||
- find $path/ -type f -name "*.xml" -print0 | xargs -0 sed -i -e s/maven-version-number/$version/g
|
||||
- mvn clean package
|
||||
- find $path/ -type f -name "*.yml" -print0 | xargs -0 sed -i -e s/maven-version-number/$version/g
|
||||
- mvn clean package
|
||||
- find $path/$name-Plugin/ -depth -path '*original*' -delete
|
||||
- mv -v $path/$name-Plugin/target/*.jar $path
|
||||
artifacts:
|
||||
|
@ -97,6 +97,6 @@ public interface EpicSpawners {
|
||||
*
|
||||
* @param hook the hook to register
|
||||
*/
|
||||
void registerProtectionHook(ProtectionPluginHook hook);
|
||||
ProtectionPluginHook registerProtectionHook(ProtectionPluginHook hook);
|
||||
|
||||
}
|
||||
|
@ -157,6 +157,8 @@ public interface Spawner {
|
||||
*/
|
||||
boolean checkConditions();
|
||||
|
||||
boolean isRedstonePowered();
|
||||
|
||||
/**
|
||||
* Get the cost needed to upgrade this spawner with
|
||||
* either Experience or Economy.
|
||||
@ -239,5 +241,5 @@ public interface Spawner {
|
||||
/**
|
||||
* You can use this method to force a spawn of this spawner.
|
||||
*/
|
||||
void spawn();
|
||||
boolean spawn();
|
||||
}
|
@ -2,6 +2,7 @@ package com.songoda.epicspawners.api.spawner;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
@ -141,4 +142,5 @@ public interface SpawnerManager {
|
||||
*/
|
||||
Collection<Spawner> getSpawners();
|
||||
|
||||
int getAmountPlaced(Player player);
|
||||
}
|
@ -67,7 +67,13 @@
|
||||
<dependency>
|
||||
<groupId>com</groupId>
|
||||
<artifactId>plotsquared</artifactId>
|
||||
<version>RELEASE</version>
|
||||
<version>BREAKING</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>skyblockearth</artifactId>
|
||||
<version>LATEST</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -109,7 +109,7 @@ public class EpicSpawnersPlugin extends JavaPlugin implements EpicSpawners {
|
||||
private Locale locale;
|
||||
|
||||
private List<ProtectionPluginHook> protectionHooks = new ArrayList<>();
|
||||
private ClaimableProtectionPluginHook factionsHook, townyHook, aSkyblockHook, uSkyblockHook;
|
||||
private ClaimableProtectionPluginHook factionsHook, townyHook, aSkyblockHook, uSkyblockHook, skyBlockEarhHook;
|
||||
|
||||
private Storage storage;
|
||||
|
||||
@ -279,11 +279,14 @@ public class EpicSpawnersPlugin extends JavaPlugin implements EpicSpawners {
|
||||
if (pluginManager.isPluginEnabled("Kingdoms")) this.register(HookKingdoms::new);
|
||||
if (pluginManager.isPluginEnabled("PlotSquared")) this.register(HookPlotSquared::new);
|
||||
if (pluginManager.isPluginEnabled("RedProtect")) this.register(HookRedProtect::new);
|
||||
if (pluginManager.isPluginEnabled("Towny")) this.register(HookTowny::new);
|
||||
if (pluginManager.isPluginEnabled("USkyBlock")) this.register(HookUSkyBlock::new);
|
||||
if (pluginManager.isPluginEnabled("Towny")) townyHook = (ClaimableProtectionPluginHook)this.register(HookTowny::new);
|
||||
if (pluginManager.isPluginEnabled("USkyBlock")) uSkyblockHook = (ClaimableProtectionPluginHook)this.register(HookUSkyBlock::new);
|
||||
if (pluginManager.isPluginEnabled("SkyBlock")) skyBlockEarhHook = (ClaimableProtectionPluginHook)this.register(HookSkyBlockEarth::new);
|
||||
if (pluginManager.isPluginEnabled("WorldGuard")) this.register(HookWorldGuard::new);
|
||||
|
||||
Bukkit.getScheduler().runTaskTimerAsynchronously(this, this::saveToFile, 6000, 6000);
|
||||
|
||||
int timeout = SettingsManager.Setting.AUTOSAVE.getInt() * 60 * 20;
|
||||
Bukkit.getScheduler().runTaskTimerAsynchronously(this, this::saveToFile, timeout, timeout);
|
||||
|
||||
// Start tasks
|
||||
this.particleTask = SpawnerParticleTask.startTask(this);
|
||||
@ -585,8 +588,8 @@ public class EpicSpawnersPlugin extends JavaPlugin implements EpicSpawners {
|
||||
this.spawnerFile.saveConfig();
|
||||
}
|
||||
|
||||
private void register(Supplier<ProtectionPluginHook> hookSupplier) {
|
||||
this.registerProtectionHook(hookSupplier.get());
|
||||
private ProtectionPluginHook register(Supplier<ProtectionPluginHook> hookSupplier) {
|
||||
return this.registerProtectionHook(hookSupplier.get());
|
||||
}
|
||||
|
||||
private void processDefault(String value) {
|
||||
@ -612,7 +615,7 @@ public class EpicSpawnersPlugin extends JavaPlugin implements EpicSpawners {
|
||||
}
|
||||
|
||||
if (value.equalsIgnoreCase("MUSHROOM_COW")) {
|
||||
spawnBlock = "MYCEL";
|
||||
spawnBlock = "MYCELIUM";
|
||||
}
|
||||
|
||||
if (value.equalsIgnoreCase("SQUID") || value.equalsIgnoreCase("ELDER_GUARDIAN") || value.equalsIgnoreCase("COD") ||
|
||||
@ -769,7 +772,9 @@ public class EpicSpawnersPlugin extends JavaPlugin implements EpicSpawners {
|
||||
}
|
||||
|
||||
public boolean isInIsland(String name, Location l) {
|
||||
return (aSkyblockHook != null && aSkyblockHook.isInClaim(l, name)) || (uSkyblockHook != null && uSkyblockHook.isInClaim(l, name));
|
||||
return aSkyblockHook != null && aSkyblockHook.isInClaim(l, name)
|
||||
|| uSkyblockHook != null && uSkyblockHook.isInClaim(l, name)
|
||||
|| skyBlockEarhHook != null && skyBlockEarhHook.isInClaim(l, name);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@ -847,7 +852,7 @@ public class EpicSpawnersPlugin extends JavaPlugin implements EpicSpawners {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerProtectionHook(ProtectionPluginHook hook) {
|
||||
public ProtectionPluginHook registerProtectionHook(ProtectionPluginHook hook) {
|
||||
Preconditions.checkNotNull(hook, "Cannot register null hook");
|
||||
Preconditions.checkNotNull(hook.getPlugin(), "Protection plugin hook returns null plugin instance (#getPlugin())");
|
||||
|
||||
@ -859,11 +864,12 @@ public class EpicSpawnersPlugin extends JavaPlugin implements EpicSpawners {
|
||||
}
|
||||
|
||||
this.hooksFile.getConfig().addDefault("hooks." + hookPlugin.getName(), true);
|
||||
if (!hooksFile.getConfig().getBoolean("hooks." + hookPlugin.getName(), true)) return;
|
||||
if (!hooksFile.getConfig().getBoolean("hooks." + hookPlugin.getName(), true)) return null;
|
||||
this.hooksFile.getConfig().options().copyDefaults(true);
|
||||
this.hooksFile.saveConfig();
|
||||
|
||||
this.protectionHooks.add(hook);
|
||||
this.getLogger().info("Registered protection hook for plugin: " + hook.getPlugin().getName());
|
||||
return hook;
|
||||
}
|
||||
}
|
||||
|
@ -2,13 +2,7 @@ package com.songoda.epicspawners;
|
||||
|
||||
public class References {
|
||||
|
||||
private String prefix;
|
||||
|
||||
public References() {
|
||||
prefix = EpicSpawnersPlugin.getInstance().getLocale().getMessage("general.nametag.prefix") + " ";
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return this.prefix;
|
||||
public static String getPrefix() {
|
||||
return EpicSpawnersPlugin.getInstance().getLocale().getMessage("general.nametag.prefix") + " ";
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package com.songoda.epicspawners.command;
|
||||
|
||||
import com.songoda.arconix.api.methods.formatting.TextComponent;
|
||||
import com.songoda.epicspawners.EpicSpawnersPlugin;
|
||||
import com.songoda.epicspawners.References;
|
||||
import com.songoda.epicspawners.command.commands.*;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
@ -58,7 +59,7 @@ public class CommandManager implements CommandExecutor {
|
||||
}
|
||||
}
|
||||
}
|
||||
commandSender.sendMessage(instance.getReferences().getPrefix() + TextComponent.formatText("&7The command you entered does not exist or is spelt incorrectly."));
|
||||
commandSender.sendMessage(References.getPrefix() + TextComponent.formatText("&7The command you entered does not exist or is spelt incorrectly."));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -70,12 +71,12 @@ public class CommandManager implements CommandExecutor {
|
||||
if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) {
|
||||
AbstractCommand.ReturnType returnType = command.runCommand(instance, sender, strings);
|
||||
if (returnType == AbstractCommand.ReturnType.SYNTAX_ERROR) {
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + TextComponent.formatText("&cInvalid Syntax!"));
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + TextComponent.formatText("&7The valid syntax is: &6" + command.getSyntax() + "&7."));
|
||||
sender.sendMessage(References.getPrefix() + TextComponent.formatText("&cInvalid Syntax!"));
|
||||
sender.sendMessage(References.getPrefix() + TextComponent.formatText("&7The valid syntax is: &6" + command.getSyntax() + "&7."));
|
||||
}
|
||||
return;
|
||||
}
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("event.general.nopermission"));
|
||||
sender.sendMessage(References.getPrefix() + instance.getLocale().getMessage("event.general.nopermission"));
|
||||
}
|
||||
|
||||
public List<AbstractCommand> getCommands() {
|
||||
|
@ -3,6 +3,7 @@ package com.songoda.epicspawners.command.commands;
|
||||
import com.songoda.arconix.api.methods.formatting.TextComponent;
|
||||
import com.songoda.arconix.api.methods.math.AMath;
|
||||
import com.songoda.epicspawners.EpicSpawnersPlugin;
|
||||
import com.songoda.epicspawners.References;
|
||||
import com.songoda.epicspawners.boost.BoostData;
|
||||
import com.songoda.epicspawners.boost.BoostType;
|
||||
import com.songoda.epicspawners.command.AbstractCommand;
|
||||
@ -21,19 +22,19 @@ public class CommandBoost extends AbstractCommand {
|
||||
@Override
|
||||
protected ReturnType runCommand(EpicSpawnersPlugin instance, CommandSender sender, String... args) {
|
||||
if (args.length < 3) {
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + TextComponent.formatText("&7Syntax error..."));
|
||||
sender.sendMessage(References.getPrefix() + TextComponent.formatText("&7Syntax error..."));
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
}
|
||||
if (!args[1].contains("p:") && !args[1].contains("player:") &&
|
||||
!args[1].contains("f:") && !args[1].contains("faction:") &&
|
||||
!args[1].contains("t:") && !args[1].contains("town:") &&
|
||||
!args[1].contains("i:") && !args[1].contains("island:")) {
|
||||
sender.sendMessage(TextComponent.formatText(instance.getReferences().getPrefix() + "&6" + args[1] + " &7this is incorrect"));
|
||||
sender.sendMessage(TextComponent.formatText(References.getPrefix() + "&6" + args[1] + " &7this is incorrect"));
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
}
|
||||
String[] arr = (args[1]).split(":");
|
||||
if (!AMath.isInt(args[2])) {
|
||||
sender.sendMessage(TextComponent.formatText(instance.getReferences().getPrefix() + "&6" + args[2] + " &7is not a number..."));
|
||||
sender.sendMessage(TextComponent.formatText(References.getPrefix() + "&6" + args[2] + " &7is not a number..."));
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
@ -61,7 +62,7 @@ public class CommandBoost extends AbstractCommand {
|
||||
c.add(Calendar.YEAR, Integer.parseInt(arr2[1]));
|
||||
response += " &7for &6" + arr2[1] + " years&7.";
|
||||
} else {
|
||||
sender.sendMessage(TextComponent.formatText(instance.getReferences().getPrefix() + "&7" + args[3] + " &7is invalid."));
|
||||
sender.sendMessage(TextComponent.formatText(References.getPrefix() + "&7" + args[3] + " &7is invalid."));
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
}
|
||||
} else {
|
||||
@ -77,7 +78,7 @@ public class CommandBoost extends AbstractCommand {
|
||||
|
||||
if (arr[0].equalsIgnoreCase("p") || arr[0].equalsIgnoreCase("player")) {
|
||||
if (Bukkit.getOfflinePlayer(arr[1]) == null) {
|
||||
sender.sendMessage(TextComponent.formatText(instance.getReferences().getPrefix() + "&cThat player does not exist..."));
|
||||
sender.sendMessage(TextComponent.formatText(References.getPrefix() + "&cThat player does not exist..."));
|
||||
} else {
|
||||
start += "The player";
|
||||
boostType = BoostType.PLAYER;
|
||||
@ -85,7 +86,7 @@ public class CommandBoost extends AbstractCommand {
|
||||
}
|
||||
} else if (arr[0].equalsIgnoreCase("f") || arr[0].equalsIgnoreCase("faction")) {
|
||||
if (instance.getFactionId(arr[1]) == null) {
|
||||
sender.sendMessage(TextComponent.formatText(instance.getReferences().getPrefix() + "&cThat faction does not exist..."));
|
||||
sender.sendMessage(TextComponent.formatText(References.getPrefix() + "&cThat faction does not exist..."));
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
@ -94,7 +95,7 @@ public class CommandBoost extends AbstractCommand {
|
||||
boostObject = instance.getFactionId(arr[1]);
|
||||
} else if (arr[0].equalsIgnoreCase("t") || arr[0].equalsIgnoreCase("town")) {
|
||||
if (instance.getTownId(arr[1]) == null) {
|
||||
sender.sendMessage(TextComponent.formatText(instance.getReferences().getPrefix() + "&cThat town does not exist..."));
|
||||
sender.sendMessage(TextComponent.formatText(References.getPrefix() + "&cThat town does not exist..."));
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
@ -103,7 +104,7 @@ public class CommandBoost extends AbstractCommand {
|
||||
boostObject = instance.getTownId(arr[1]);
|
||||
} else if (arr[0].equalsIgnoreCase("i") || arr[0].equalsIgnoreCase("island")) {
|
||||
if (instance.getIslandId(arr[1]) == null) {
|
||||
sender.sendMessage(TextComponent.formatText(instance.getReferences().getPrefix() + "&cThat island does not exist..."));
|
||||
sender.sendMessage(TextComponent.formatText(References.getPrefix() + "&cThat island does not exist..."));
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
@ -118,7 +119,7 @@ public class CommandBoost extends AbstractCommand {
|
||||
|
||||
BoostData boostData = new BoostData(boostType, Integer.parseInt(args[2]), c.getTime().getTime(), boostObject);
|
||||
instance.getBoostManager().addBoostToSpawner(boostData);
|
||||
sender.sendMessage(TextComponent.formatText(instance.getReferences().getPrefix() + start + response));
|
||||
sender.sendMessage(TextComponent.formatText(References.getPrefix() + start + response));
|
||||
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.songoda.epicspawners.command.commands;
|
||||
|
||||
import com.songoda.arconix.api.methods.formatting.TextComponent;
|
||||
import com.songoda.epicspawners.EpicSpawnersPlugin;
|
||||
import com.songoda.epicspawners.References;
|
||||
import com.songoda.epicspawners.api.spawner.Spawner;
|
||||
import com.songoda.epicspawners.api.spawner.SpawnerData;
|
||||
import com.songoda.epicspawners.api.spawner.SpawnerStack;
|
||||
@ -23,14 +24,14 @@ public class CommandChange extends AbstractCommand {
|
||||
protected ReturnType runCommand(EpicSpawnersPlugin instance, CommandSender sender, String... args) {
|
||||
if (args.length != 2) return ReturnType.SYNTAX_ERROR;
|
||||
if (!sender.hasPermission("epicspawners.admin") && !sender.hasPermission("epicspawners.change.*") && !sender.hasPermission("epicspawners.change." + args[1].toUpperCase())) {
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("event.general.nopermission"));
|
||||
sender.sendMessage(References.getPrefix() + instance.getLocale().getMessage("event.general.nopermission"));
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
Block block = player.getTargetBlock(null, 200);
|
||||
|
||||
if (block.getType() != Material.SPAWNER) {
|
||||
sender.sendMessage(TextComponent.formatText(instance.getReferences().getPrefix() + "&cThis is not a spawner."));
|
||||
sender.sendMessage(TextComponent.formatText(References.getPrefix() + "&cThis is not a spawner."));
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
@ -61,10 +62,10 @@ public class CommandChange extends AbstractCommand {
|
||||
}
|
||||
spawner.getCreatureSpawner().update();
|
||||
instance.getHologramHandler().processChange(block);
|
||||
sender.sendMessage(TextComponent.formatText(instance.getReferences().getPrefix() + "&7Successfully changed this spawner to &6" + args[1] + "&7."));
|
||||
sender.sendMessage(TextComponent.formatText(References.getPrefix() + "&7Successfully changed this spawner to &6" + args[1] + "&7."));
|
||||
return ReturnType.SUCCESS;
|
||||
} catch (Exception ee) {
|
||||
sender.sendMessage(TextComponent.formatText(instance.getReferences().getPrefix() + "&7That entity does not exist."));
|
||||
sender.sendMessage(TextComponent.formatText(References.getPrefix() + "&7That entity does not exist."));
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.songoda.epicspawners.command.commands;
|
||||
|
||||
import com.songoda.arconix.api.methods.formatting.TextComponent;
|
||||
import com.songoda.epicspawners.EpicSpawnersPlugin;
|
||||
import com.songoda.epicspawners.References;
|
||||
import com.songoda.epicspawners.command.AbstractCommand;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@ -14,7 +15,7 @@ public class CommandEpicSpawners extends AbstractCommand {
|
||||
@Override
|
||||
protected ReturnType runCommand(EpicSpawnersPlugin instance, CommandSender sender, String... args) {
|
||||
sender.sendMessage("");
|
||||
sender.sendMessage(TextComponent.formatText(instance.getReferences().getPrefix() + "&7Version " + instance.getDescription().getVersion() + " Created with <3 by &5&l&oBrianna"));
|
||||
sender.sendMessage(TextComponent.formatText(References.getPrefix() + "&7Version " + instance.getDescription().getVersion() + " Created with <3 by &5&l&oBrianna"));
|
||||
|
||||
for (AbstractCommand command : instance.getCommandManager().getCommands()) {
|
||||
if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) {
|
||||
|
@ -4,6 +4,7 @@ import com.google.common.collect.Iterables;
|
||||
import com.songoda.arconix.api.methods.formatting.TextComponent;
|
||||
import com.songoda.arconix.api.methods.math.AMath;
|
||||
import com.songoda.epicspawners.EpicSpawnersPlugin;
|
||||
import com.songoda.epicspawners.References;
|
||||
import com.songoda.epicspawners.api.spawner.SpawnerData;
|
||||
import com.songoda.epicspawners.command.AbstractCommand;
|
||||
import com.songoda.epicspawners.utils.Methods;
|
||||
@ -27,7 +28,7 @@ public class CommandGive extends AbstractCommand {
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
}
|
||||
if (Bukkit.getPlayerExact(args[1]) == null && !args[1].toLowerCase().equals("all")) {
|
||||
sender.sendMessage(TextComponent.formatText(instance.getReferences().getPrefix() + "&cThat username does not exist, or the user is not online!"));
|
||||
sender.sendMessage(TextComponent.formatText(References.getPrefix() + "&cThat username does not exist, or the user is not online!"));
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
int multi = 1;
|
||||
@ -41,7 +42,7 @@ public class CommandGive extends AbstractCommand {
|
||||
}
|
||||
|
||||
if (data == null && !args[2].equalsIgnoreCase("random")) {
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + TextComponent.formatText(instance.getReferences().getPrefix() + "&7The entity Type &6" + args[2] + " &7does not exist. Try one of these:"));
|
||||
sender.sendMessage(References.getPrefix() + TextComponent.formatText(References.getPrefix() + "&7The entity Type &6" + args[2] + " &7does not exist. Try one of these:"));
|
||||
StringBuilder list = new StringBuilder();
|
||||
|
||||
for (SpawnerData spawnerData : instance.getSpawnerManager().getAllSpawnerData()) {
|
||||
@ -56,7 +57,7 @@ public class CommandGive extends AbstractCommand {
|
||||
}
|
||||
if (args.length == 4) {
|
||||
if (!AMath.isInt(args[3])) {
|
||||
sender.sendMessage(TextComponent.formatText(instance.getReferences().getPrefix() + "&6" + args[3] + "&7 is not a number."));
|
||||
sender.sendMessage(TextComponent.formatText(References.getPrefix() + "&6" + args[3] + "&7 is not a number."));
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
}
|
||||
int amt = Integer.parseInt(args[3]);
|
||||
@ -64,21 +65,21 @@ public class CommandGive extends AbstractCommand {
|
||||
if (args[1].toLowerCase().equals("all")) {
|
||||
for (Player pl : Bukkit.getOnlinePlayers()) {
|
||||
pl.getInventory().addItem(spawnerItem);
|
||||
pl.sendMessage(TextComponent.formatText(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.give.success", amt, Methods.compileName(data, multi, false))));
|
||||
pl.sendMessage(TextComponent.formatText(References.getPrefix() + instance.getLocale().getMessage("command.give.success", amt, Methods.compileName(data, multi, false))));
|
||||
}
|
||||
} else {
|
||||
Player pl = Bukkit.getPlayerExact(args[1]);
|
||||
pl.getInventory().addItem(spawnerItem);
|
||||
pl.sendMessage(TextComponent.formatText(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.give.success", amt, Methods.compileName(data, multi, false))));
|
||||
pl.sendMessage(TextComponent.formatText(References.getPrefix() + instance.getLocale().getMessage("command.give.success", amt, Methods.compileName(data, multi, false))));
|
||||
|
||||
}
|
||||
} else {
|
||||
if (!AMath.isInt(args[3])) {
|
||||
sender.sendMessage(TextComponent.formatText(instance.getReferences().getPrefix() + "&6" + args[3] + "&7 is not a number."));
|
||||
sender.sendMessage(TextComponent.formatText(References.getPrefix() + "&6" + args[3] + "&7 is not a number."));
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
if (!AMath.isInt(args[4])) {
|
||||
sender.sendMessage(TextComponent.formatText(instance.getReferences().getPrefix() + "&6" + args[4] + "&7 is not a number."));
|
||||
sender.sendMessage(TextComponent.formatText(References.getPrefix() + "&6" + args[4] + "&7 is not a number."));
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
int amt = Integer.parseInt(args[3]);
|
||||
@ -87,12 +88,12 @@ public class CommandGive extends AbstractCommand {
|
||||
if (args[1].toLowerCase().equals("all")) {
|
||||
for (Player pl : Bukkit.getOnlinePlayers()) {
|
||||
pl.getInventory().addItem(spawnerItem);
|
||||
pl.sendMessage(TextComponent.formatText(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.give.success", amt, Methods.compileName(data, multi, false))));
|
||||
pl.sendMessage(TextComponent.formatText(References.getPrefix() + instance.getLocale().getMessage("command.give.success", amt, Methods.compileName(data, multi, false))));
|
||||
}
|
||||
} else {
|
||||
Player pl = Bukkit.getPlayerExact(args[1]);
|
||||
pl.getInventory().addItem(spawnerItem);
|
||||
pl.sendMessage(TextComponent.formatText(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.give.success", amt, Methods.compileName(data, multi, false))));
|
||||
pl.sendMessage(TextComponent.formatText(References.getPrefix() + instance.getLocale().getMessage("command.give.success", amt, Methods.compileName(data, multi, false))));
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.songoda.epicspawners.command.commands;
|
||||
|
||||
import com.songoda.arconix.api.methods.formatting.TextComponent;
|
||||
import com.songoda.epicspawners.EpicSpawnersPlugin;
|
||||
import com.songoda.epicspawners.References;
|
||||
import com.songoda.epicspawners.command.AbstractCommand;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@ -14,7 +15,7 @@ public class CommandReload extends AbstractCommand {
|
||||
@Override
|
||||
protected ReturnType runCommand(EpicSpawnersPlugin instance, CommandSender sender, String... args) {
|
||||
instance.reload();
|
||||
sender.sendMessage(TextComponent.formatText(instance.getReferences().getPrefix() + "&7Configuration and Language files reloaded."));
|
||||
sender.sendMessage(TextComponent.formatText(References.getPrefix() + "&7Configuration and Language files reloaded."));
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -2,8 +2,10 @@ package com.songoda.epicspawners.command.commands;
|
||||
|
||||
import com.songoda.arconix.api.methods.formatting.TextComponent;
|
||||
import com.songoda.epicspawners.EpicSpawnersPlugin;
|
||||
import com.songoda.epicspawners.References;
|
||||
import com.songoda.epicspawners.api.spawner.SpawnerData;
|
||||
import com.songoda.epicspawners.command.AbstractCommand;
|
||||
import com.songoda.epicspawners.gui.GUISpawnerStats;
|
||||
import com.songoda.epicspawners.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
@ -27,76 +29,14 @@ public class CommandSpawnerStats extends AbstractCommand {
|
||||
protected ReturnType runCommand(EpicSpawnersPlugin instance, CommandSender sender, String... args) {
|
||||
Player player = (Player) sender;
|
||||
|
||||
int size = 0;
|
||||
|
||||
for (Map.Entry<EntityType, Integer> entry : instance.getPlayerActionManager().getPlayerAction(player).getEntityKills().entrySet()) {
|
||||
if (instance.getSpawnerManager().getSpawnerData(entry.getKey()).isActive())
|
||||
size++;
|
||||
}
|
||||
|
||||
String title = instance.getLocale().getMessage("interface.spawnerstats.title");
|
||||
|
||||
Inventory i = Bukkit.createInventory(null, 54, title);
|
||||
if (size <= 9) {
|
||||
i = Bukkit.createInventory(null, 18, title);
|
||||
} else if (size <= 18) {
|
||||
i = Bukkit.createInventory(null, 27, title);
|
||||
} else if (size <= 27) {
|
||||
i = Bukkit.createInventory(null, 36, title);
|
||||
} else if (size <= 36) {
|
||||
i = Bukkit.createInventory(null, 45, title);
|
||||
}
|
||||
|
||||
int num = 0;
|
||||
while (num != 9) {
|
||||
i.setItem(num, Methods.getGlass());
|
||||
num++;
|
||||
}
|
||||
ItemStack exit = new ItemStack(Material.valueOf(instance.getConfig().getString("Interfaces.Exit Icon")), 1);
|
||||
ItemMeta exitmeta = exit.getItemMeta();
|
||||
exitmeta.setDisplayName(instance.getLocale().getMessage("general.nametag.exit"));
|
||||
exit.setItemMeta(exitmeta);
|
||||
i.setItem(8, exit);
|
||||
|
||||
short place = 9;
|
||||
player.sendMessage("");
|
||||
|
||||
|
||||
if (instance.getPlayerActionManager().getPlayerAction(player).getEntityKills().size() == 0) {
|
||||
player.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("interface.spawnerstats.nokills"));
|
||||
return ReturnType.SUCCESS;
|
||||
player.sendMessage(References.getPrefix() + instance.getLocale().getMessage("interface.spawnerstats.nokills"));
|
||||
return AbstractCommand.ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
player.sendMessage(instance.getReferences().getPrefix());
|
||||
player.sendMessage(instance.getLocale().getMessage("interface.spawnerstats.prefix"));
|
||||
for (Map.Entry<EntityType, Integer> entry : instance.getPlayerActionManager().getPlayerAction(player).getEntityKills().entrySet()) {
|
||||
int goal = instance.getConfig().getInt("Spawner Drops.Kills Needed for Drop");
|
||||
|
||||
SpawnerData spawnerData = instance.getSpawnerManager().getSpawnerData(entry.getKey());
|
||||
|
||||
int customGoal = spawnerData.getKillGoal();
|
||||
if (customGoal != 0) goal = customGoal;
|
||||
|
||||
ItemStack it = new ItemStack(Material.PLAYER_HEAD, 1, (byte) 3);
|
||||
|
||||
ItemStack item = instance.getHeads().addTexture(it, spawnerData);
|
||||
|
||||
ItemMeta itemmeta = item.getItemMeta();
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
itemmeta.setLore(lore);
|
||||
itemmeta.setDisplayName(TextComponent.formatText("&6" + spawnerData.getDisplayName() + "&7: &e" + entry.getValue() + "&7/&e" + goal));
|
||||
item.setItemMeta(itemmeta);
|
||||
i.setItem(place, item);
|
||||
|
||||
place++;
|
||||
player.sendMessage(TextComponent.formatText("&7- &6" + spawnerData.getDisplayName() + "&7: &e" + entry.getValue() + "&7/&e" + goal));
|
||||
}
|
||||
player.sendMessage(instance.getLocale().getMessage("interface.spawnerstats.ongoal"));
|
||||
|
||||
player.sendMessage("");
|
||||
|
||||
player.openInventory(i);
|
||||
|
||||
new GUISpawnerStats(instance, player);
|
||||
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,231 @@
|
||||
package com.songoda.epicspawners.gui;
|
||||
|
||||
import com.songoda.arconix.api.methods.formatting.TextComponent;
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.epicspawners.EpicSpawnersPlugin;
|
||||
import com.songoda.epicspawners.References;
|
||||
import com.songoda.epicspawners.api.spawner.Spawner;
|
||||
import com.songoda.epicspawners.boost.BoostData;
|
||||
import com.songoda.epicspawners.boost.BoostType;
|
||||
import com.songoda.epicspawners.spawners.spawner.ESpawner;
|
||||
import com.songoda.epicspawners.utils.Debugger;
|
||||
import com.songoda.epicspawners.utils.Methods;
|
||||
import com.songoda.epicspawners.utils.SettingsManager;
|
||||
import com.songoda.epicspawners.utils.gui.AbstractGUI;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
public class GUISpawnerBoost extends AbstractGUI {
|
||||
|
||||
private final EpicSpawnersPlugin plugin;
|
||||
private final Spawner spawner;
|
||||
private int amount = 1;
|
||||
|
||||
public GUISpawnerBoost(EpicSpawnersPlugin plugin, Spawner spawner, Player player) {
|
||||
super(player);
|
||||
this.plugin = plugin;
|
||||
this.spawner = spawner;
|
||||
setUp();
|
||||
}
|
||||
|
||||
private void setUp() {
|
||||
if (amount > SettingsManager.Setting.MAX_PLAYER_BOOST.getInt()) {
|
||||
amount = SettingsManager.Setting.MAX_PLAYER_BOOST.getInt();
|
||||
return;
|
||||
} else if (amount < 1) {
|
||||
amount = 1;
|
||||
}
|
||||
init(plugin.getLocale().getMessage("interface.boost.title", Methods.compileName(spawner.getIdentifyingData(), spawner.getSpawnerDataCount(), false), amount), 27);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void constructGUI() {
|
||||
if (!player.hasPermission("epicspawners.canboost")) return;
|
||||
|
||||
int num = 0;
|
||||
while (num != 27) {
|
||||
inventory.setItem(num, Methods.getGlass());
|
||||
num++;
|
||||
}
|
||||
|
||||
ItemStack coal = new ItemStack(Material.COAL);
|
||||
ItemMeta coalMeta = coal.getItemMeta();
|
||||
coalMeta.setDisplayName(EpicSpawnersPlugin.getInstance().getLocale().getMessage("interface.boost.boostfor", "5"));
|
||||
ArrayList<String> coalLore = new ArrayList<>();
|
||||
coalLore.add(TextComponent.formatText("&7Costs &6&l" + Methods.getBoostCost(5, amount) + "."));
|
||||
coalMeta.setLore(coalLore);
|
||||
coal.setItemMeta(coalMeta);
|
||||
|
||||
ItemStack iron = new ItemStack(Material.IRON_INGOT);
|
||||
ItemMeta ironMeta = iron.getItemMeta();
|
||||
ironMeta.setDisplayName(EpicSpawnersPlugin.getInstance().getLocale().getMessage("interface.boost.boostfor", "15"));
|
||||
ArrayList<String> ironLore = new ArrayList<>();
|
||||
ironLore.add(TextComponent.formatText("&7Costs &6&l" + Methods.getBoostCost(15, amount) + "."));
|
||||
ironMeta.setLore(ironLore);
|
||||
iron.setItemMeta(ironMeta);
|
||||
|
||||
ItemStack diamond = new ItemStack(Material.DIAMOND);
|
||||
ItemMeta diamondMeta = diamond.getItemMeta();
|
||||
diamondMeta.setDisplayName(EpicSpawnersPlugin.getInstance().getLocale().getMessage("interface.boost.boostfor", "30"));
|
||||
ArrayList<String> diamondLore = new ArrayList<>();
|
||||
diamondLore.add(TextComponent.formatText("&7Costs &6&l" + Methods.getBoostCost(30, amount) + "."));
|
||||
diamondMeta.setLore(diamondLore);
|
||||
diamond.setItemMeta(diamondMeta);
|
||||
|
||||
ItemStack emerald = new ItemStack(Material.EMERALD);
|
||||
ItemMeta emeraldMeta = emerald.getItemMeta();
|
||||
emeraldMeta.setDisplayName(EpicSpawnersPlugin.getInstance().getLocale().getMessage("interface.boost.boostfor", "60"));
|
||||
ArrayList<String> emeraldLore = new ArrayList<>();
|
||||
emeraldLore.add(TextComponent.formatText("&7Costs &6&l" + Methods.getBoostCost(60, amount) + "."));
|
||||
emeraldMeta.setLore(emeraldLore);
|
||||
emerald.setItemMeta(emeraldMeta);
|
||||
|
||||
inventory.setItem(10, coal);
|
||||
inventory.setItem(12, iron);
|
||||
inventory.setItem(14, diamond);
|
||||
inventory.setItem(16, emerald);
|
||||
|
||||
inventory.setItem(0, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(1, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(2, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(6, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(7, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(8, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(9, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(17, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(18, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(19, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(20, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(24, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(25, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(26, Methods.getBackgroundGlass(true));
|
||||
|
||||
ItemStack head = new ItemStack(Material.PLAYER_HEAD, 1, (byte) 3);
|
||||
ItemStack skull = Arconix.pl().getApi().getGUI().addTexture(head, "http://textures.minecraft.net/texture/1b6f1a25b6bc199946472aedb370522584ff6f4e83221e5946bd2e41b5ca13b");
|
||||
SkullMeta skullMeta = (SkullMeta) skull.getItemMeta();
|
||||
skull.setDurability((short) 3);
|
||||
skullMeta.setDisplayName(TextComponent.formatText("&6&l+1"));
|
||||
skull.setItemMeta(skullMeta);
|
||||
|
||||
ItemStack head2 = new ItemStack(Material.PLAYER_HEAD, 1, (byte) 3);
|
||||
ItemStack skull2 = Arconix.pl().getApi().getGUI().addTexture(head2, "http://textures.minecraft.net/texture/3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23");
|
||||
SkullMeta skull2Meta = (SkullMeta) skull2.getItemMeta();
|
||||
skull2.setDurability((short) 3);
|
||||
skull2Meta.setDisplayName(TextComponent.formatText("&6&l-1"));
|
||||
skull2.setItemMeta(skull2Meta);
|
||||
|
||||
if (amount != 1) {
|
||||
inventory.setItem(0, skull2);
|
||||
}
|
||||
if (amount < EpicSpawnersPlugin.getInstance().getConfig().getInt("Spawner Boosting.Max Multiplier For A Spawner Boost")) {
|
||||
inventory.setItem(8, skull);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerClickables() {
|
||||
resetClickables();
|
||||
registerClickable(0, (player, inventory, cursor, slot, type) -> {
|
||||
amount--;
|
||||
setUp();
|
||||
constructGUI();
|
||||
});
|
||||
|
||||
registerClickable(8, (player, inventory, cursor, slot, type) -> {
|
||||
amount++;
|
||||
setUp();
|
||||
constructGUI();
|
||||
});
|
||||
|
||||
registerClickable(10, (player, inventory, cursor, slot, type) ->
|
||||
purchaseBoost(player, 5, amount));
|
||||
|
||||
registerClickable(12, (player, inventory, cursor, slot, type) ->
|
||||
purchaseBoost(player, 15, amount));
|
||||
|
||||
registerClickable(14, (player, inventory, cursor, slot, type) ->
|
||||
purchaseBoost(player, 30, amount));
|
||||
|
||||
registerClickable(16, (player, inventory, cursor, slot, type) ->
|
||||
purchaseBoost(player, 60, amount));
|
||||
}
|
||||
|
||||
public void purchaseBoost(Player player, int time, int amt) {
|
||||
try {
|
||||
Location location = spawner.getLocation();
|
||||
player.closeInventory();
|
||||
EpicSpawnersPlugin instance = EpicSpawnersPlugin.getInstance();
|
||||
|
||||
String un = EpicSpawnersPlugin.getInstance().getConfig().getString("Spawner Boosting.Item Charged For A Boost");
|
||||
|
||||
String[] parts = un.split(":");
|
||||
|
||||
String type = parts[0];
|
||||
String multi = parts[1];
|
||||
int cost = Methods.boostCost(multi, time, amt);
|
||||
if (!type.equals("ECO") && !type.equals("XP")) {
|
||||
ItemStack stack = new ItemStack(Material.valueOf(type));
|
||||
int invAmt = Arconix.pl().getApi().getGUI().getAmount(player.getInventory(), stack);
|
||||
if (invAmt >= cost) {
|
||||
stack.setAmount(cost);
|
||||
Arconix.pl().getApi().getGUI().removeFromInventory(player.getInventory(), stack);
|
||||
} else {
|
||||
player.sendMessage(References.getPrefix() + EpicSpawnersPlugin.getInstance().getLocale().getMessage("event.upgrade.cannotafford"));
|
||||
return;
|
||||
}
|
||||
} else if (type.equals("ECO")) {
|
||||
if (EpicSpawnersPlugin.getInstance().getServer().getPluginManager().getPlugin("Vault") != null) {
|
||||
RegisteredServiceProvider<Economy> rsp = EpicSpawnersPlugin.getInstance().getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
|
||||
net.milkbowl.vault.economy.Economy econ = rsp.getProvider();
|
||||
if (econ.has(player, cost)) {
|
||||
econ.withdrawPlayer(player, cost);
|
||||
} else {
|
||||
player.sendMessage(References.getPrefix() + EpicSpawnersPlugin.getInstance().getLocale().getMessage("event.upgrade.cannotafford"));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
player.sendMessage("Vault is not installed.");
|
||||
return;
|
||||
}
|
||||
} else if (type.equals("XP")) {
|
||||
if (player.getLevel() >= cost || player.getGameMode() == GameMode.CREATIVE) {
|
||||
if (player.getGameMode() != GameMode.CREATIVE) {
|
||||
player.setLevel(player.getLevel() - cost);
|
||||
}
|
||||
} else {
|
||||
player.sendMessage(References.getPrefix() + EpicSpawnersPlugin.getInstance().getLocale().getMessage("event.upgrade.cannotafford"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
Calendar c = Calendar.getInstance();
|
||||
Date currentDate = new Date();
|
||||
c.setTime(currentDate);
|
||||
c.add(Calendar.MINUTE, time);
|
||||
|
||||
|
||||
BoostData boostData = new BoostData(BoostType.LOCATION, amt, c.getTime().getTime(), location);
|
||||
instance.getBoostManager().addBoostToSpawner(boostData);
|
||||
player.sendMessage(References.getPrefix() + plugin.getLocale().getMessage("event.boost.applied"));
|
||||
player.playSound(location, Sound.ENTITY_VILLAGER_YES, 1,1);
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerOnCloses() {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,197 @@
|
||||
package com.songoda.epicspawners.gui;
|
||||
|
||||
import com.songoda.arconix.api.methods.formatting.TextComponent;
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.epicspawners.EpicSpawnersPlugin;
|
||||
import com.songoda.epicspawners.api.spawner.Spawner;
|
||||
import com.songoda.epicspawners.api.spawner.SpawnerData;
|
||||
import com.songoda.epicspawners.player.MenuType;
|
||||
import com.songoda.epicspawners.player.PlayerData;
|
||||
import com.songoda.epicspawners.spawners.spawner.ESpawner;
|
||||
import com.songoda.epicspawners.utils.Methods;
|
||||
import com.songoda.epicspawners.utils.gui.AbstractGUI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class GUISpawnerConvert extends AbstractGUI {
|
||||
|
||||
private final EpicSpawnersPlugin plugin;
|
||||
private final Spawner spawner;
|
||||
private List<SpawnerData> entities;
|
||||
private int page = 1;
|
||||
private int max = 0;
|
||||
private int totalAmount = 0;
|
||||
private int slots = 0;
|
||||
|
||||
public GUISpawnerConvert(EpicSpawnersPlugin plugin, Spawner spawner, Player player) {
|
||||
super(player);
|
||||
this.plugin = plugin;
|
||||
this.spawner = spawner;
|
||||
|
||||
setUp();
|
||||
}
|
||||
|
||||
|
||||
private void setUp() {
|
||||
int show = 0;
|
||||
int start = (page - 1) * 32;
|
||||
entities = new ArrayList<>();
|
||||
totalAmount = 0;
|
||||
for (SpawnerData spawnerData : plugin.getSpawnerManager().getAllSpawnerData()) {
|
||||
if (spawnerData.getIdentifyingName().equalsIgnoreCase("omni")
|
||||
|| !spawnerData.isConvertible()
|
||||
|| !player.hasPermission("epicspawners.convert." + spawnerData.getIdentifyingName().replace(" ", "_"))) continue;
|
||||
if (totalAmount >= start) {
|
||||
if (show <= 32) {
|
||||
entities.add(spawnerData);
|
||||
show++;
|
||||
}
|
||||
}
|
||||
totalAmount++;
|
||||
}
|
||||
|
||||
int size = entities.size();
|
||||
if (size == 24 || size == 25) size = 26;
|
||||
slots = 54;
|
||||
if (size <= 7) {
|
||||
slots = 27;
|
||||
} else if (size <= 15) {
|
||||
slots = 36;
|
||||
} else if (size <= 25) {
|
||||
slots = 45;
|
||||
}
|
||||
|
||||
init(plugin.getLocale().getMessage("interface.convert.title"), slots);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void constructGUI() {
|
||||
inventory.clear();
|
||||
max = (int) Math.ceil((double) totalAmount / (double) 32);
|
||||
|
||||
int place = 10;
|
||||
for (SpawnerData spawnerData : entities) {
|
||||
if (place == 17)
|
||||
place++;
|
||||
if (place == (slots - 18))
|
||||
place++;
|
||||
ItemStack it = new ItemStack(Material.PLAYER_HEAD, 1, (byte) 3);
|
||||
|
||||
ItemStack item = plugin.getHeads().addTexture(it, spawnerData);
|
||||
|
||||
if (spawnerData.getDisplayItem() != null) {
|
||||
Material mat = spawnerData.getDisplayItem();
|
||||
if (!mat.equals(Material.AIR))
|
||||
item = new ItemStack(mat, 1);
|
||||
}
|
||||
|
||||
ItemMeta itemmeta = item.getItemMeta();
|
||||
String name = Methods.compileName(spawnerData, 1, true);
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
double price = spawnerData.getConvertPrice() * spawner.getSpawnerDataCount();
|
||||
|
||||
lore.add(plugin.getLocale().getMessage("interface.shop.buyprice", TextComponent.formatEconomy(price)));
|
||||
String loreString = plugin.getLocale().getMessage("interface.convert.lore", Methods.getTypeFromString(spawnerData.getIdentifyingName()));
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
|
||||
loreString = me.clip.placeholderapi.PlaceholderAPI.setPlaceholders(player, loreString.replace(" ", "_")).replace("_", " ");
|
||||
}
|
||||
lore.add(loreString);
|
||||
itemmeta.setLore(lore);
|
||||
itemmeta.setDisplayName(name);
|
||||
item.setItemMeta(itemmeta);
|
||||
inventory.setItem(place, item);
|
||||
place++;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 9; i ++) {
|
||||
inventory.setItem(i, Methods.getGlass());
|
||||
}
|
||||
for (int i = slots - 9; i < slots; i ++) {
|
||||
inventory.setItem(i, Methods.getGlass());
|
||||
}
|
||||
|
||||
inventory.setItem(0, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(1, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(9, Methods.getBackgroundGlass(true));
|
||||
|
||||
inventory.setItem(7, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(17, Methods.getBackgroundGlass(true));
|
||||
|
||||
inventory.setItem(slots - 18, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(slots - 9, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(slots - 8, Methods.getBackgroundGlass(true));
|
||||
|
||||
inventory.setItem(slots - 10, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(slots - 2, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(slots - 1, Methods.getBackgroundGlass(true));
|
||||
|
||||
inventory.setItem(2, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(6, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(slots - 7, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(slots - 3, Methods.getBackgroundGlass(false));
|
||||
|
||||
createButton(8, Material.valueOf(plugin.getConfig().getString("Interfaces.Exit Icon")),
|
||||
plugin.getLocale().getMessage("general.nametag.exit"));
|
||||
|
||||
ItemStack head = new ItemStack(Material.PLAYER_HEAD, 1, (byte) 3);
|
||||
ItemStack skull = Arconix.pl().getApi().getGUI().addTexture(head, "http://textures.minecraft.net/texture/1b6f1a25b6bc199946472aedb370522584ff6f4e83221e5946bd2e41b5ca13b");
|
||||
SkullMeta skullMeta = (SkullMeta) skull.getItemMeta();
|
||||
skull.setDurability((short) 3);
|
||||
skullMeta.setDisplayName(plugin.getLocale().getMessage("general.nametag.next"));
|
||||
skull.setItemMeta(skullMeta);
|
||||
|
||||
ItemStack head2 = new ItemStack(Material.PLAYER_HEAD, 1, (byte) 3);
|
||||
ItemStack skull2 = Arconix.pl().getApi().getGUI().addTexture(head2, "http://textures.minecraft.net/texture/3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23");
|
||||
SkullMeta skull2Meta = (SkullMeta) skull2.getItemMeta();
|
||||
skull2.setDurability((short) 3);
|
||||
skull2Meta.setDisplayName(plugin.getLocale().getMessage("general.nametag.back"));
|
||||
skull2.setItemMeta(skull2Meta);
|
||||
|
||||
if (page != 1) inventory.setItem(slots - 8, skull2);
|
||||
if (page != max) inventory.setItem(slots - 2, skull);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerClickables() {
|
||||
resetClickables();
|
||||
|
||||
registerClickable(8, (player, inventory, cursor, slot, type) -> player.closeInventory());
|
||||
|
||||
registerClickable(10, 10 + entities.size(), (player, inventory, cursor, slot, type) -> {
|
||||
if (inventory.getItem(slot).getType() == Material.PLAYER_HEAD) {
|
||||
((ESpawner)spawner).convert(plugin.getSpawnerDataFromItem(inventory.getItem(slot)), player);
|
||||
}
|
||||
});
|
||||
|
||||
registerClickable(slots - 8, (player, inventory, cursor, slot, type) -> {
|
||||
if (page == 1) return;
|
||||
page --;
|
||||
setUp();
|
||||
constructGUI();
|
||||
registerClickables();
|
||||
});
|
||||
|
||||
registerClickable(slots - 2, (player, inventory, cursor, slot, type) -> {
|
||||
if (page == max) return;
|
||||
page ++;
|
||||
setUp();
|
||||
constructGUI();
|
||||
registerClickables();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerOnCloses() {
|
||||
|
||||
}
|
||||
}
|
@ -11,6 +11,7 @@ import com.songoda.epicspawners.player.MenuType;
|
||||
import com.songoda.epicspawners.spawners.spawner.ESpawner;
|
||||
import com.songoda.epicspawners.utils.Debugger;
|
||||
import com.songoda.epicspawners.utils.Methods;
|
||||
import com.songoda.epicspawners.utils.SettingsManager;
|
||||
import com.songoda.epicspawners.utils.gui.AbstractGUI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -45,21 +46,18 @@ public class GUISpawnerOverview extends AbstractGUI {
|
||||
private int infoPage = 1;
|
||||
|
||||
public GUISpawnerOverview(EpicSpawnersPlugin plugin, ESpawner spawner, Player player) {
|
||||
super(27, TextComponent.formatTitle(Objects.requireNonNull(Methods.compileName(spawner.getIdentifyingData(), spawner.getSpawnerDataCount(), false))));
|
||||
super(player);
|
||||
this.spawner = spawner;
|
||||
this.player = player;
|
||||
this.plugin = plugin;
|
||||
|
||||
this.config = plugin.getConfig();
|
||||
this.locale = plugin.getLocale();
|
||||
init(Methods.compileName(spawner.getIdentifyingData(), spawner.getSpawnerDataCount(), false), 27);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initInventoryItems(Inventory inventory) {
|
||||
|
||||
|
||||
SpawnerData spawnerData = spawner.getFirstStack().getSpawnerData();
|
||||
|
||||
protected void constructGUI() {
|
||||
int showAmt = spawner.getSpawnerDataCount();
|
||||
if (showAmt > 64)
|
||||
showAmt = 1;
|
||||
@ -67,22 +65,22 @@ public class GUISpawnerOverview extends AbstractGUI {
|
||||
showAmt = 1;
|
||||
|
||||
ItemStack item = new ItemStack(Material.PLAYER_HEAD, showAmt, (byte) 3);
|
||||
|
||||
if (spawner.getSpawnerStacks().size() != 1) {
|
||||
item = plugin.getHeads().addTexture(item, plugin.getSpawnerManager().getSpawnerData("omni"));
|
||||
} else {
|
||||
try {
|
||||
item = plugin.getHeads().addTexture(item, spawnerData);
|
||||
} catch (Exception e) {
|
||||
item = new ItemStack(Material.SPAWNER, showAmt);
|
||||
Material displayItem = spawner.getFirstStack().getSpawnerData().getDisplayItem();
|
||||
if (displayItem != null && displayItem != Material.AIR) {
|
||||
item = new ItemStack(spawner.getFirstStack().getSpawnerData().getDisplayItem());
|
||||
} else {
|
||||
try {
|
||||
item = plugin.getHeads().addTexture(item, spawner.getIdentifyingData());
|
||||
} catch (Exception e) {
|
||||
item = new ItemStack(Material.SPAWNER, showAmt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (spawner.getSpawnerStacks().size() == 1
|
||||
&& spawner.getFirstStack().getSpawnerData().getDisplayItem() != null
|
||||
&& spawner.getFirstStack().getSpawnerData().getDisplayItem() != Material.AIR) {
|
||||
item.setType(spawner.getFirstStack().getSpawnerData().getDisplayItem());
|
||||
}
|
||||
|
||||
ItemMeta itemmeta = item.getItemMeta();
|
||||
itemmeta.setDisplayName(plugin.getLocale().getMessage("interface.spawner.statstitle"));
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
@ -129,7 +127,7 @@ public class GUISpawnerOverview extends AbstractGUI {
|
||||
if (spawner.getBoost() != 0) {
|
||||
|
||||
// ToDo: Make it display all boosts.
|
||||
String[] parts = plugin.getLocale().getMessage("interface.spawner.boostedstats", Integer.toString(spawner.getBoost()), spawnerData.getIdentifyingName(), TimeComponent.makeReadable(spawner.getBoostEnd().toEpochMilli() - System.currentTimeMillis())).split("\\|");
|
||||
String[] parts = plugin.getLocale().getMessage("interface.spawner.boostedstats", Integer.toString(spawner.getBoost()), spawner.getIdentifyingData().getIdentifyingName(), TimeComponent.makeReadable(spawner.getBoostEnd().toEpochMilli() - System.currentTimeMillis())).split("\\|");
|
||||
lore.add("");
|
||||
for (String line : parts)
|
||||
lore.add(TextComponent.formatText(line));
|
||||
@ -187,7 +185,7 @@ public class GUISpawnerOverview extends AbstractGUI {
|
||||
inventory.setItem(25, BACKGROUND_GLASS_TYPE_2);
|
||||
inventory.setItem(26, BACKGROUND_GLASS_TYPE_2);
|
||||
|
||||
if (plugin.getConfig().getBoolean("Main.Display Help Button In Spawner Overview")) {
|
||||
if (SettingsManager.Setting.DISPLAY_HELP_BUTTON.getBoolean()) {
|
||||
ItemStack itemO = new ItemStack(Material.PAPER, 1);
|
||||
ItemMeta itemmetaO = itemO.getItemMeta();
|
||||
itemmetaO.setDisplayName(plugin.getLocale().getMessage("interface.spawner.howtotitle"));
|
||||
@ -242,26 +240,24 @@ public class GUISpawnerOverview extends AbstractGUI {
|
||||
inventory.setItem(15, itemECO);
|
||||
}
|
||||
}
|
||||
plugin.getPlayerActionManager().getPlayerAction(player).setInMenu(MenuType.OVERVIEW);
|
||||
plugin.getPlayerActionManager().getPlayerAction(player).setLastSpawner(spawner);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initClickableObjects() {
|
||||
this.registerClickableObject(8, (player, inventory, cursor, slot, type) -> {
|
||||
protected void registerClickables() {
|
||||
registerClickable(8, (player, inventory, cursor, slot, type) -> {
|
||||
this.infoPage++;
|
||||
addInfo(inventory);
|
||||
});
|
||||
|
||||
this.registerClickableObject(13, (player, inventory, cursor, slot, type) -> {
|
||||
registerClickable(13, (player, inventory, cursor, slot, type) -> {
|
||||
if (type.isRightClick() && spawner.getBoost() == 0) {
|
||||
this.spawner.playerBoost(player);
|
||||
new GUISpawnerBoost(plugin, spawner, player);
|
||||
} else if (type.isLeftClick() && spawner.getSpawnerStacks().size() == 1) {
|
||||
this.spawner.convertOverview(player, 1);
|
||||
new GUISpawnerConvert(plugin, spawner, player);
|
||||
}
|
||||
});
|
||||
|
||||
this.registerClickableObject(11, (player, inventory, cursor, slot, type) -> {
|
||||
registerClickable(11, (player, inventory, cursor, slot, type) -> {
|
||||
if (config.getBoolean("Main.Upgrade With XP")
|
||||
&& !inventory.getItem(slot).getItemMeta().getDisplayName().equals(ChatColor.COLOR_CHAR + "l")) {
|
||||
this.spawner.upgrade(player, CostType.EXPERIENCE);
|
||||
@ -269,7 +265,7 @@ public class GUISpawnerOverview extends AbstractGUI {
|
||||
this.spawner.overview(player);
|
||||
});
|
||||
|
||||
this.registerClickableObject(15, (player, inventory, cursor, slot, type) -> {
|
||||
registerClickable(15, (player, inventory, cursor, slot, type) -> {
|
||||
if (config.getBoolean("Main.Upgrade With Economy")
|
||||
&& !inventory.getItem(slot).getItemMeta().getDisplayName().equals(ChatColor.COLOR_CHAR + "l")) {
|
||||
this.spawner.upgrade(player, CostType.ECONOMY);
|
||||
@ -443,4 +439,10 @@ public class GUISpawnerOverview extends AbstractGUI {
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void registerOnCloses() {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
package com.songoda.epicspawners.gui;
|
||||
|
||||
import com.songoda.arconix.api.methods.formatting.TextComponent;
|
||||
import com.songoda.epicspawners.EpicSpawnersPlugin;
|
||||
import com.songoda.epicspawners.api.spawner.SpawnerData;
|
||||
import com.songoda.epicspawners.command.AbstractCommand;
|
||||
import com.songoda.epicspawners.utils.Methods;
|
||||
import com.songoda.epicspawners.utils.gui.AbstractGUI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
public class GUISpawnerStats extends AbstractGUI {
|
||||
|
||||
private final EpicSpawnersPlugin plugin;
|
||||
|
||||
public GUISpawnerStats(EpicSpawnersPlugin plugin, Player player) {
|
||||
super(player);
|
||||
this.plugin = plugin;
|
||||
|
||||
int size = 0;
|
||||
|
||||
for (Map.Entry<EntityType, Integer> entry : plugin.getPlayerActionManager().getPlayerAction(player).getEntityKills().entrySet()) {
|
||||
if (plugin.getSpawnerManager().getSpawnerData(entry.getKey()).isActive())
|
||||
size++;
|
||||
}
|
||||
|
||||
int slots = 54;
|
||||
if (size <= 9) {
|
||||
slots = 18;
|
||||
} else if (size <= 18) {
|
||||
slots = 27;
|
||||
} else if (size <= 27) {
|
||||
slots = 36;
|
||||
} else if (size <= 36) {
|
||||
slots = 45;
|
||||
}
|
||||
|
||||
init(plugin.getLocale().getMessage("interface.spawnerstats.title"), slots);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void constructGUI() {
|
||||
|
||||
for (int i = 0; i < 9; i ++) {
|
||||
inventory.setItem(i, Methods.getGlass());
|
||||
}
|
||||
ItemStack exit = new ItemStack(Material.valueOf(plugin.getConfig().getString("Interfaces.Exit Icon")), 1);
|
||||
ItemMeta exitmeta = exit.getItemMeta();
|
||||
exitmeta.setDisplayName(plugin.getLocale().getMessage("general.nametag.exit"));
|
||||
exit.setItemMeta(exitmeta);
|
||||
inventory.setItem(8, exit);
|
||||
|
||||
short place = 9;
|
||||
for (Map.Entry<EntityType, Integer> entry : plugin.getPlayerActionManager().getPlayerAction(player).getEntityKills().entrySet()) {
|
||||
int goal = plugin.getConfig().getInt("Spawner Drops.Kills Needed for Drop");
|
||||
|
||||
SpawnerData spawnerData = plugin.getSpawnerManager().getSpawnerData(entry.getKey());
|
||||
|
||||
int customGoal = spawnerData.getKillGoal();
|
||||
if (customGoal != 0) goal = customGoal;
|
||||
|
||||
ItemStack it = new ItemStack(Material.PLAYER_HEAD, 1, (byte) 3);
|
||||
|
||||
ItemStack item = plugin.getHeads().addTexture(it, spawnerData);
|
||||
|
||||
ItemMeta itemmeta = item.getItemMeta();
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
itemmeta.setLore(lore);
|
||||
itemmeta.setDisplayName(TextComponent.formatText("&6" + spawnerData.getDisplayName() + "&7: &e" + entry.getValue() + "&7/&e" + goal));
|
||||
item.setItemMeta(itemmeta);
|
||||
inventory.setItem(place, item);
|
||||
|
||||
place++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerClickables() {
|
||||
registerClickable(8, (player, inventory, cursor, slot, type) -> player.closeInventory());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerOnCloses() {
|
||||
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ import com.songoda.epicspawners.api.spawner.SpawnerStack;
|
||||
import com.songoda.epicspawners.spawners.spawner.ESpawner;
|
||||
import com.songoda.epicspawners.utils.Debugger;
|
||||
import com.songoda.epicspawners.utils.Methods;
|
||||
import com.songoda.epicspawners.utils.SettingsManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -36,14 +37,8 @@ public class AppearanceHandler {
|
||||
try {
|
||||
EpicSpawnersPlugin instance = EpicSpawnersPlugin.getInstance();
|
||||
|
||||
if (!EpicSpawnersPlugin.getInstance().getConfig().getBoolean("Main.OmniSpawners Enabled")) return;
|
||||
|
||||
for (Spawner spawner : instance.getSpawnerManager().getSpawners()) {
|
||||
if (spawner.getSpawnerStacks().size() <= 1) {
|
||||
updateDisplayItem(spawner, spawner.getFirstStack().getSpawnerData());
|
||||
continue;
|
||||
}
|
||||
|
||||
Location location = spawner.getLocation();
|
||||
if (location == null || location.getWorld() == null) continue;
|
||||
int destx = location.getBlockX() >> 4;
|
||||
@ -52,6 +47,14 @@ public class AppearanceHandler {
|
||||
continue;
|
||||
}
|
||||
if (location.getBlock().getType() != Material.SPAWNER) continue;
|
||||
|
||||
if (spawner.getSpawnerStacks().size() <= 1) {
|
||||
updateDisplayItem(spawner, spawner.getFirstStack().getSpawnerData());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!SettingsManager.Setting.OMNI_SPAWNERS.getBoolean()) continue;
|
||||
|
||||
String last = null;
|
||||
SpawnerData next = null;
|
||||
List<SpawnerStack> list = new ArrayList<>(spawner.getSpawnerStacks());
|
||||
@ -67,6 +70,7 @@ public class AppearanceHandler {
|
||||
}
|
||||
updateDisplayItem(spawner, next);
|
||||
((ESpawner) spawner).setOmniState(next.getIdentifyingName());
|
||||
spawner.getCreatureSpawner().update();
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
@ -1,7 +1,8 @@
|
||||
package com.songoda.epicspawners.hooks;
|
||||
|
||||
import com.intellectualcrafters.plot.api.PlotAPI;
|
||||
import com.plotsquared.bukkit.BukkitMain;
|
||||
import com.github.intellectualsites.plotsquared.api.PlotAPI;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.BukkitMain;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||
import com.songoda.epicspawners.api.utils.ProtectionPluginHook;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -22,8 +23,15 @@ public class HookPlotSquared implements ProtectionPluginHook {
|
||||
|
||||
@Override
|
||||
public boolean canBuild(Player player, Location location) {
|
||||
return plotSquared.getPlot(location) != null && plotSquared.isInPlot(player)
|
||||
&& plotSquared.getPlot(location) == plotSquared.getPlot(player);
|
||||
com.github.intellectualsites.plotsquared.plot.object.Location plotLocation =
|
||||
new com.github.intellectualsites.plotsquared.plot.object.Location(location.getWorld().getName(),
|
||||
location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
|
||||
Plot plot = plotLocation.getPlot();
|
||||
|
||||
return plot != null
|
||||
&& plot.getOwners().contains(player.getUniqueId())
|
||||
&& plot.getMembers().contains(player.getUniqueId());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package com.songoda.epicspawners.hooks;
|
||||
|
||||
import com.songoda.epicspawners.api.utils.ClaimableProtectionPluginHook;
|
||||
import me.goodandevil.skyblock.SkyBlock;
|
||||
import me.goodandevil.skyblock.island.Island;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class HookSkyBlockEarth implements ClaimableProtectionPluginHook {
|
||||
|
||||
private final SkyBlock skyblock;
|
||||
|
||||
public HookSkyBlockEarth() {
|
||||
this.skyblock = SkyBlock.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaPlugin getPlugin() {
|
||||
return SkyBlock.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBuild(Player player, Location location) {
|
||||
Island island = skyblock.getIslandManager().getIslandAtLocation(location);
|
||||
if (island == null) return true;
|
||||
|
||||
UUID owner = island.getOwnerUUID();
|
||||
UUID playerUUID = player.getUniqueId();
|
||||
if (owner == null || owner.equals(playerUUID)) return true;
|
||||
|
||||
Set<UUID> teamMembers = island.getCoopPlayers();
|
||||
if (teamMembers.contains(playerUUID)) return true;
|
||||
|
||||
List<Island> coopIslands = skyblock.getIslandManager().getCoopIslands(player);
|
||||
for (Island is : coopIslands) {
|
||||
if (is.getOwnerUUID().equals(playerUUID)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInClaim(Location location, String id) {
|
||||
return skyblock.getIslandManager().getIslandAtLocation(location).getOwnerUUID().toString().equals(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClaimID(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package com.songoda.epicspawners.listeners;
|
||||
|
||||
import com.songoda.epicspawners.EpicSpawnersPlugin;
|
||||
import com.songoda.epicspawners.References;
|
||||
import com.songoda.epicspawners.api.events.SpawnerBreakEvent;
|
||||
import com.songoda.epicspawners.api.events.SpawnerPlaceEvent;
|
||||
import com.songoda.epicspawners.api.spawner.Spawner;
|
||||
@ -14,6 +15,7 @@ import net.milkbowl.vault.economy.Economy;
|
||||
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;
|
||||
@ -24,6 +26,7 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockFromToEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
/**
|
||||
@ -76,7 +79,7 @@ public class BlockListeners implements Listener {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean doForceCombine(Player player, ESpawner placedSpawner) {
|
||||
private boolean doForceCombine(Player player, ESpawner placedSpawner) {
|
||||
if (instance.getConfig().getInt("Main.Force Combine Radius") == 0) return false;
|
||||
|
||||
for (Spawner spawner : instance.getSpawnerManager().getSpawners()) {
|
||||
@ -89,14 +92,24 @@ public class BlockListeners implements Listener {
|
||||
}
|
||||
|
||||
if (instance.getConfig().getBoolean("Main.Deny Place On Force Combine"))
|
||||
player.sendMessage(instance.getLocale().getMessage("event.block.forcedeny"));
|
||||
player.sendMessage(References.getPrefix() + instance.getLocale().getMessage("event.block.forcedeny"));
|
||||
else if (spawner.stack(player, placedSpawner.getFirstStack().getSpawnerData(), placedSpawner.getSpawnerDataCount()))
|
||||
player.sendMessage(instance.getLocale().getMessage("event.block.mergedistance"));
|
||||
player.sendMessage(References.getPrefix() + instance.getLocale().getMessage("event.block.mergedistance"));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private int maxSpawners(Player player) {
|
||||
int limit = -1;
|
||||
for (PermissionAttachmentInfo permissionAttachmentInfo : player.getEffectivePermissions()) {
|
||||
if (!permissionAttachmentInfo.getPermission().toLowerCase().startsWith("epicspawners.limit")) continue;
|
||||
limit = Integer.parseInt(permissionAttachmentInfo.getPermission().split("\\.")[2]);
|
||||
}
|
||||
if (limit == -1) limit = instance.getConfig().getInt("Main.Max Spawners Per Player");
|
||||
return limit;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onSpawnerPlace(BlockPlaceEvent event) {
|
||||
//We are ignoring canceled inside the event so that it will still remove holograms when the event is canceled.
|
||||
@ -126,11 +139,22 @@ public class BlockListeners implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
player.playSound(player.getLocation(), Sound.BLOCK_ANVIL_STEP, 1L, 1L);
|
||||
|
||||
if (doForceCombine(player, spawner)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
int amountPlaced = instance.getSpawnerManager().getAmountPlaced(player);
|
||||
int maxSpawners = maxSpawners(player);
|
||||
|
||||
if (maxSpawners != -1 && amountPlaced > maxSpawners) {
|
||||
player.sendMessage(instance.getLocale().getMessage("event.spawner.toomany", maxSpawners));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
SpawnerPlaceEvent placeEvent = new SpawnerPlaceEvent(player, spawner);
|
||||
Bukkit.getPluginManager().callEvent(placeEvent);
|
||||
if (placeEvent.isCancelled()) {
|
||||
@ -147,7 +171,7 @@ public class BlockListeners implements Listener {
|
||||
instance.getSpawnerManager().addSpawnerToWorld(location, spawner);
|
||||
|
||||
if (instance.getConfig().getBoolean("Main.Alerts On Place And Break"))
|
||||
player.sendMessage(instance.getLocale().getMessage("event.block.place", Methods.compileName(spawnerData, spawner.getFirstStack().getStackSize(), false)));
|
||||
player.sendMessage(References.getPrefix() + instance.getLocale().getMessage("event.block.place", Methods.compileName(spawnerData, spawner.getFirstStack().getStackSize(), false)));
|
||||
|
||||
try {
|
||||
spawner.getCreatureSpawner().setSpawnedType(EntityType.valueOf(spawnerData.getIdentifyingName().toUpperCase().replace(" ", "_")));
|
||||
@ -220,7 +244,7 @@ public class BlockListeners implements Listener {
|
||||
|
||||
if (spawner.getFirstStack().getSpawnerData().getPickupCost() != 0 && (!naturalOnly || spawner.getPlacedBy() == null)) {
|
||||
if (!((ESpawnerManager) instance.getSpawnerManager()).hasCooldown(spawner)) {
|
||||
player.sendMessage(instance.getLocale().getMessage("event.block.chargebreak", spawner.getFirstStack().getSpawnerData().getPickupCost()));
|
||||
player.sendMessage(References.getPrefix() + instance.getLocale().getMessage("event.block.chargebreak", spawner.getFirstStack().getSpawnerData().getPickupCost()));
|
||||
((ESpawnerManager) instance.getSpawnerManager()).addCooldown(spawner);
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(instance, () -> ((ESpawnerManager) instance.getSpawnerManager()).removeCooldown(spawner), 300L);
|
||||
event.setCancelled(true);
|
||||
@ -235,7 +259,7 @@ public class BlockListeners implements Listener {
|
||||
if (econ.has(player, cost)) {
|
||||
econ.withdrawPlayer(player, cost);
|
||||
} else {
|
||||
player.sendMessage(instance.getLocale().getMessage("event.block.cannotbreak"));
|
||||
player.sendMessage(References.getPrefix() + instance.getLocale().getMessage("event.block.cannotbreak"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -246,9 +270,9 @@ public class BlockListeners implements Listener {
|
||||
if (spawner.unstack(event.getPlayer())) {
|
||||
if (instance.getConfig().getBoolean("Main.Alerts On Place And Break")) {
|
||||
if (spawner.getSpawnerStacks().size() != 0) {
|
||||
player.sendMessage(instance.getLocale().getMessage("event.downgrade.success", Integer.toString(spawner.getSpawnerDataCount())));
|
||||
player.sendMessage(References.getPrefix() + instance.getLocale().getMessage("event.downgrade.success", Integer.toString(spawner.getSpawnerDataCount())));
|
||||
} else {
|
||||
player.sendMessage(instance.getLocale().getMessage("event.block.break", Methods.compileName(firstData, currentStackSize, true)));
|
||||
player.sendMessage(References.getPrefix() + instance.getLocale().getMessage("event.block.break", Methods.compileName(firstData, currentStackSize, true)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package com.songoda.epicspawners.listeners;
|
||||
import com.songoda.arconix.api.methods.formatting.TextComponent;
|
||||
import com.songoda.arconix.api.methods.math.AMath;
|
||||
import com.songoda.epicspawners.EpicSpawnersPlugin;
|
||||
import com.songoda.epicspawners.References;
|
||||
import com.songoda.epicspawners.api.spawner.SpawnerData;
|
||||
import com.songoda.epicspawners.spawners.editor.EditingMenu;
|
||||
import com.songoda.epicspawners.utils.Debugger;
|
||||
@ -80,7 +81,7 @@ public class ChatListeners implements Listener {
|
||||
break;
|
||||
case COMMAND:
|
||||
String msg = e.getMessage();
|
||||
player.sendMessage(TextComponent.formatText(instance.getReferences().getPrefix() + "&8Command &5" + msg + "&8 saved to your inventory."));
|
||||
player.sendMessage(TextComponent.formatText(References.getPrefix() + "&8Command &5" + msg + "&8 saved to your inventory."));
|
||||
instance.getSpawnerEditor().addCommand(player, e.getMessage());
|
||||
break;
|
||||
case CUSTOM_GOAL:
|
||||
|
@ -172,7 +172,7 @@ public class InteractListeners implements Listener {
|
||||
}
|
||||
}
|
||||
} else if (event.getClickedBlock().getType() == Material.SPAWNER && !EpicSpawnersPlugin.getInstance().getBlacklistHandler().isBlacklisted(player, false)) {
|
||||
if (!player.isSneaking()) {
|
||||
if (!player.isSneaking() || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
Spawner spawner = EpicSpawnersPlugin.getInstance().getSpawnerManager().getSpawnerFromWorld(location);
|
||||
|
||||
((ESpawner) spawner).overview(player);
|
||||
|
@ -2,6 +2,7 @@ package com.songoda.epicspawners.listeners;
|
||||
|
||||
import com.songoda.arconix.api.methods.formatting.TextComponent;
|
||||
import com.songoda.epicspawners.EpicSpawnersPlugin;
|
||||
import com.songoda.epicspawners.References;
|
||||
import com.songoda.epicspawners.api.particles.ParticleDensity;
|
||||
import com.songoda.epicspawners.api.particles.ParticleEffect;
|
||||
import com.songoda.epicspawners.api.particles.ParticleType;
|
||||
@ -80,44 +81,6 @@ public class InventoryListeners implements Listener {
|
||||
instance.getShop().confirm(player, amt);
|
||||
player.closeInventory();
|
||||
}
|
||||
} else if (instance.getPlayerActionManager().getPlayerAction(player).getInMenu() == MenuType.PLAYERBOOST) {
|
||||
event.setCancelled(true);
|
||||
ESpawner spawner = instance.getPlayerActionManager().getPlayerAction(player).getLastSpawner();
|
||||
if (event.getSlot() == 8) {
|
||||
spawner.addBoostAmt(player, spawner.getBoostAmt(player) + 1);
|
||||
spawner.playerBoost(player);
|
||||
} else if (event.getSlot() == 0) {
|
||||
spawner.addBoostAmt(player, spawner.getBoostAmt(player) - 1);
|
||||
spawner.playerBoost(player);
|
||||
} else if (event.getSlot() == 10) {
|
||||
spawner.purchaseBoost(player, 5);
|
||||
} else if (event.getSlot() == 12) {
|
||||
spawner.purchaseBoost(player, 15);
|
||||
} else if (event.getSlot() == 14) {
|
||||
spawner.purchaseBoost(player, 30);
|
||||
} else if (event.getSlot() == 16) {
|
||||
spawner.purchaseBoost(player, 60);
|
||||
}
|
||||
} else if (instance.getPlayerActionManager().getPlayerAction(player).getInMenu() == MenuType.CONVERT) {
|
||||
event.setCancelled(true);
|
||||
ItemStack clicked = event.getCurrentItem();
|
||||
ESpawner spawner = instance.getPlayerActionManager().getPlayerAction(player).getLastSpawner();
|
||||
|
||||
int page = playerData.getCurrentPage();
|
||||
|
||||
if (event.getInventory().getType() == InventoryType.CHEST) {
|
||||
if (event.getSlot() == 8) {
|
||||
player.closeInventory();
|
||||
} else if (event.getCurrentItem().getItemMeta().getDisplayName().equals(instance.getLocale().getMessage("general.nametag.back"))) {
|
||||
if (page != 1) {
|
||||
spawner.convertOverview(player, page - 1);
|
||||
}
|
||||
} else if (event.getCurrentItem().getItemMeta().getDisplayName().equals(instance.getLocale().getMessage("general.nametag.next"))) {
|
||||
spawner.convertOverview(player, page + 1);
|
||||
} else if (clicked.getType() == Material.PLAYER_HEAD) {
|
||||
spawner.convert(instance.getSpawnerDataFromItem(clicked), player);
|
||||
}
|
||||
}
|
||||
} else if (instance.getSpawnerEditor().getEditingData(player).getMenu() != EditingMenu.NOT_IN) {
|
||||
|
||||
if (event.getRawSlot() >= event.getView().getTopInventory().getSize()) return;
|
||||
@ -132,7 +95,7 @@ public class InventoryListeners implements Listener {
|
||||
if (!event.getClick().isLeftClick() && !event.getClick().isRightClick()) {
|
||||
SpawnerData spawnerData = editingData.getSpawnerEditing();
|
||||
spawnerData.setDisplayItem(Material.valueOf(player.getInventory().getItemInHand().getType().toString()));
|
||||
player.sendMessage(TextComponent.formatText(instance.getReferences().getPrefix() + "&7Display Item for &6" + spawnerData.getIdentifyingName() + " &7set to &6" + player.getInventory().getItemInHand().getType().toString() + "&7."));
|
||||
player.sendMessage(TextComponent.formatText(References.getPrefix() + "&7Display Item for &6" + spawnerData.getIdentifyingName() + " &7set to &6" + player.getInventory().getItemInHand().getType().toString() + "&7."));
|
||||
instance.getSpawnerEditor().overview(player, editingData.getSpawnerEditing());
|
||||
} else if (event.getClick().isLeftClick()) {
|
||||
instance.getSpawnerEditor().editSpawnerName(player);
|
||||
@ -327,11 +290,6 @@ public class InventoryListeners implements Listener {
|
||||
//if (e.getClick().isLeftClick())
|
||||
instance.getSpawnerEditor().overview(player, instance.getSpawnerEditor().getType(event.getCurrentItem().getItemMeta().getDisplayName()));
|
||||
}
|
||||
} else if (event.getInventory().getTitle().equals(instance.getLocale().getMessage("interface.spawnerstats.title"))) {
|
||||
event.setCancelled(true);
|
||||
if (event.getSlot() == 8) {
|
||||
player.closeInventory();
|
||||
}
|
||||
} else if (event.getInventory().getTitle().equals(instance.getLocale().getMessage("interface.shop.title"))) {
|
||||
event.setCancelled(true);
|
||||
ItemStack clicked = event.getCurrentItem();
|
||||
|
@ -2,6 +2,7 @@ package com.songoda.epicspawners.listeners;
|
||||
|
||||
import com.songoda.arconix.api.methods.formatting.TextComponent;
|
||||
import com.songoda.epicspawners.EpicSpawnersPlugin;
|
||||
import com.songoda.epicspawners.References;
|
||||
import com.songoda.epicspawners.utils.Debugger;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -26,7 +27,7 @@ public class PlayerJoinListeners implements Listener {
|
||||
if (player.isOp() && instance.getConfig().getBoolean("Main.Display Helpful Tips For Operators")) {
|
||||
if (instance.getServer().getPluginManager().getPlugin("Factions") != null && instance.getServer().getPluginManager().getPlugin("FactionsFramework") == null) {
|
||||
player.sendMessage("");
|
||||
player.sendMessage(TextComponent.formatText(instance.getReferences().getPrefix() + "&7Here's the deal,"));
|
||||
player.sendMessage(TextComponent.formatText(References.getPrefix() + "&7Here's the deal,"));
|
||||
player.sendMessage(TextComponent.formatText("&7I cannot give you full support for Factions out of the box."));
|
||||
player.sendMessage(TextComponent.formatText("&7Things will work without it but if you wan't a flawless"));
|
||||
player.sendMessage(TextComponent.formatText("&7experience you need to download"));
|
||||
|
@ -3,6 +3,7 @@ package com.songoda.epicspawners.spawners.editor;
|
||||
import com.songoda.arconix.api.methods.formatting.TextComponent;
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.epicspawners.EpicSpawnersPlugin;
|
||||
import com.songoda.epicspawners.References;
|
||||
import com.songoda.epicspawners.api.spawner.SpawnerData;
|
||||
import com.songoda.epicspawners.listeners.ChatListeners;
|
||||
import com.songoda.epicspawners.player.PlayerData;
|
||||
@ -634,7 +635,7 @@ public class SpawnerEditor {
|
||||
}
|
||||
spawnerData.setCommands(list);
|
||||
}
|
||||
p.sendMessage(TextComponent.formatText(instance.getReferences().getPrefix() + "&7Spawner Saved."));
|
||||
p.sendMessage(TextComponent.formatText(References.getPrefix() + "&7Spawner Saved."));
|
||||
spawnerData.reloadSpawnMethods();
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
|
@ -3,6 +3,7 @@ package com.songoda.epicspawners.spawners.shop;
|
||||
import com.songoda.arconix.api.methods.formatting.TextComponent;
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.epicspawners.EpicSpawnersPlugin;
|
||||
import com.songoda.epicspawners.References;
|
||||
import com.songoda.epicspawners.api.spawner.SpawnerData;
|
||||
import com.songoda.epicspawners.player.MenuType;
|
||||
import com.songoda.epicspawners.player.PlayerData;
|
||||
@ -314,7 +315,7 @@ public class Shop {
|
||||
net.milkbowl.vault.economy.Economy econ = rsp.getProvider();
|
||||
double price = spawnerData.getShopPrice() * amount;
|
||||
if (!player.isOp() && !econ.has(player, price)) {
|
||||
player.sendMessage(EpicSpawnersPlugin.getInstance().getReferences().getPrefix() + instance.getLocale().getMessage("event.shop.cannotafford"));
|
||||
player.sendMessage(References.getPrefix() + instance.getLocale().getMessage("event.shop.cannotafford"));
|
||||
return;
|
||||
}
|
||||
ItemStack item = spawnerData.toItemStack(amount);
|
||||
@ -322,7 +323,7 @@ public class Shop {
|
||||
|
||||
player.getInventory().addItem(item);
|
||||
|
||||
player.sendMessage(EpicSpawnersPlugin.getInstance().getReferences().getPrefix() + instance.getLocale().getMessage("event.shop.purchasesuccess"));
|
||||
player.sendMessage(References.getPrefix() + instance.getLocale().getMessage("event.shop.purchasesuccess"));
|
||||
|
||||
|
||||
if (!player.isOp()) {
|
||||
|
@ -3,7 +3,9 @@ package com.songoda.epicspawners.spawners.spawner;
|
||||
import com.songoda.arconix.api.methods.formatting.TextComponent;
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.epicspawners.EpicSpawnersPlugin;
|
||||
import com.songoda.epicspawners.References;
|
||||
import com.songoda.epicspawners.api.CostType;
|
||||
import com.songoda.epicspawners.api.EpicSpawners;
|
||||
import com.songoda.epicspawners.api.EpicSpawnersAPI;
|
||||
import com.songoda.epicspawners.api.events.SpawnerChangeEvent;
|
||||
import com.songoda.epicspawners.api.particles.ParticleType;
|
||||
@ -18,6 +20,7 @@ import com.songoda.epicspawners.player.MenuType;
|
||||
import com.songoda.epicspawners.player.PlayerData;
|
||||
import com.songoda.epicspawners.utils.Debugger;
|
||||
import com.songoda.epicspawners.utils.Methods;
|
||||
import com.songoda.epicspawners.utils.SettingsManager;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
@ -50,7 +53,6 @@ public class ESpawner implements Spawner {
|
||||
//ToDo: Use this for all spawner things (Like items, commands and what not) instead of the old shit
|
||||
//ToDO: There is a weird error that is triggered when a spawner is not found in the config.
|
||||
private Map<Location, Date> lastSpawns = new HashMap<>();
|
||||
private Map<UUID, Integer> boostAmt = new HashMap<>();
|
||||
|
||||
public ESpawner(Location location) {
|
||||
this.location = location;
|
||||
@ -60,18 +62,15 @@ public class ESpawner implements Spawner {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawn() {
|
||||
public boolean spawn() {
|
||||
EpicSpawnersPlugin instance = EpicSpawnersPlugin.getInstance();
|
||||
long lastSpawn = lastSpawns.containsKey(location) ? new Date().getTime() - lastSpawns.get(location).getTime() : 1001;
|
||||
|
||||
if (lastSpawn >= 1000) {
|
||||
lastSpawns.put(location, new Date());
|
||||
} else return;
|
||||
} else return false;
|
||||
|
||||
if (location.getBlock().isBlockPowered() && instance.getConfig().getBoolean("Main.Redstone Power Deactivates Spawners"))
|
||||
return;
|
||||
|
||||
if (getFirstStack().getSpawnerData() == null) return;
|
||||
if (getFirstStack().getSpawnerData() == null) return false;
|
||||
|
||||
float x = (float) (0 + (Math.random() * .8));
|
||||
float y = (float) (0 + (Math.random() * .8));
|
||||
@ -82,6 +81,7 @@ public class ESpawner implements Spawner {
|
||||
|
||||
SpawnerData spawnerData = getFirstStack().getSpawnerData();
|
||||
|
||||
|
||||
ParticleType particleType = spawnerData.getSpawnerSpawnParticle();
|
||||
if (particleType != ParticleType.NONE)
|
||||
Arconix.pl().getApi().packetLibrary.getParticleManager().broadcastParticle(particleLocation, x, y, z, 0, particleType.getEffect(), spawnerData.getParticleDensity().getSpawnerSpawn());
|
||||
@ -90,6 +90,7 @@ public class ESpawner implements Spawner {
|
||||
((ESpawnerData) stack.getSpawnerData()).spawn(this, stack);
|
||||
}
|
||||
Bukkit.getScheduler().runTaskLater(instance, this::updateDelay, 10);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -129,6 +130,7 @@ public class ESpawner implements Spawner {
|
||||
|
||||
@Override
|
||||
public SpawnerStack getFirstStack() {
|
||||
if (spawnerStacks.size() == 0) return null;
|
||||
return spawnerStacks.getFirst();
|
||||
}
|
||||
|
||||
@ -141,115 +143,6 @@ public class ESpawner implements Spawner {
|
||||
return multi;
|
||||
}
|
||||
|
||||
public void playerBoost(Player player) {
|
||||
try {
|
||||
if (!player.hasPermission("epicspawners.canboost")) return;
|
||||
|
||||
if (boostAmt.containsKey(player.getUniqueId())) {
|
||||
if (boostAmt.get(player.getUniqueId()) > EpicSpawnersPlugin.getInstance().getConfig().getInt("Spawner Boosting.Max Multiplier For A Spawner Boost")) {
|
||||
boostAmt.put(player.getUniqueId(), EpicSpawnersPlugin.getInstance().getConfig().getInt("Spawner Boosting.Max Multiplier For A Spawner Boost"));
|
||||
return;
|
||||
} else if (boostAmt.get(player.getUniqueId()) < 1) {
|
||||
boostAmt.put(player.getUniqueId(), 1);
|
||||
}
|
||||
}
|
||||
|
||||
int amt = 1;
|
||||
|
||||
if (boostAmt.containsKey(player.getUniqueId()))
|
||||
amt = boostAmt.get(player.getUniqueId());
|
||||
else
|
||||
boostAmt.put(player.getUniqueId(), amt);
|
||||
|
||||
Inventory i = Bukkit.createInventory(null, 27, EpicSpawnersPlugin.getInstance().getLocale().getMessage("interface.boost.title", Integer.toString(amt), Methods.compileName(getIdentifyingData(), getSpawnerDataCount(), false)));
|
||||
|
||||
int num = 0;
|
||||
while (num != 27) {
|
||||
i.setItem(num, Methods.getGlass());
|
||||
num++;
|
||||
}
|
||||
|
||||
ItemStack coal = new ItemStack(Material.COAL);
|
||||
ItemMeta coalMeta = coal.getItemMeta();
|
||||
coalMeta.setDisplayName(EpicSpawnersPlugin.getInstance().getLocale().getMessage("interface.boost.boostfor", "5"));
|
||||
ArrayList<String> coalLore = new ArrayList<>();
|
||||
coalLore.add(TextComponent.formatText("&7Costs &6&l" + Methods.getBoostCost(5, amt) + "."));
|
||||
coalMeta.setLore(coalLore);
|
||||
coal.setItemMeta(coalMeta);
|
||||
|
||||
ItemStack iron = new ItemStack(Material.IRON_INGOT);
|
||||
ItemMeta ironMeta = iron.getItemMeta();
|
||||
ironMeta.setDisplayName(EpicSpawnersPlugin.getInstance().getLocale().getMessage("interface.boost.boostfor", "15"));
|
||||
ArrayList<String> ironLore = new ArrayList<>();
|
||||
ironLore.add(TextComponent.formatText("&7Costs &6&l" + Methods.getBoostCost(15, amt) + "."));
|
||||
ironMeta.setLore(ironLore);
|
||||
iron.setItemMeta(ironMeta);
|
||||
|
||||
ItemStack diamond = new ItemStack(Material.DIAMOND);
|
||||
ItemMeta diamondMeta = diamond.getItemMeta();
|
||||
diamondMeta.setDisplayName(EpicSpawnersPlugin.getInstance().getLocale().getMessage("interface.boost.boostfor", "30"));
|
||||
ArrayList<String> diamondLore = new ArrayList<>();
|
||||
diamondLore.add(TextComponent.formatText("&7Costs &6&l" + Methods.getBoostCost(30, amt) + "."));
|
||||
diamondMeta.setLore(diamondLore);
|
||||
diamond.setItemMeta(diamondMeta);
|
||||
|
||||
ItemStack emerald = new ItemStack(Material.EMERALD);
|
||||
ItemMeta emeraldMeta = emerald.getItemMeta();
|
||||
emeraldMeta.setDisplayName(EpicSpawnersPlugin.getInstance().getLocale().getMessage("interface.boost.boostfor", "60"));
|
||||
ArrayList<String> emeraldLore = new ArrayList<>();
|
||||
emeraldLore.add(TextComponent.formatText("&7Costs &6&l" + Methods.getBoostCost(60, amt) + "."));
|
||||
emeraldMeta.setLore(emeraldLore);
|
||||
emerald.setItemMeta(emeraldMeta);
|
||||
|
||||
i.setItem(10, coal);
|
||||
i.setItem(12, iron);
|
||||
i.setItem(14, diamond);
|
||||
i.setItem(16, emerald);
|
||||
|
||||
i.setItem(0, Methods.getBackgroundGlass(true));
|
||||
i.setItem(1, Methods.getBackgroundGlass(true));
|
||||
i.setItem(2, Methods.getBackgroundGlass(false));
|
||||
i.setItem(6, Methods.getBackgroundGlass(false));
|
||||
i.setItem(7, Methods.getBackgroundGlass(true));
|
||||
i.setItem(8, Methods.getBackgroundGlass(true));
|
||||
i.setItem(9, Methods.getBackgroundGlass(true));
|
||||
i.setItem(17, Methods.getBackgroundGlass(true));
|
||||
i.setItem(18, Methods.getBackgroundGlass(true));
|
||||
i.setItem(19, Methods.getBackgroundGlass(true));
|
||||
i.setItem(20, Methods.getBackgroundGlass(false));
|
||||
i.setItem(24, Methods.getBackgroundGlass(false));
|
||||
i.setItem(25, Methods.getBackgroundGlass(true));
|
||||
i.setItem(26, Methods.getBackgroundGlass(true));
|
||||
|
||||
ItemStack head = new ItemStack(Material.PLAYER_HEAD, 1, (byte) 3);
|
||||
ItemStack skull = Arconix.pl().getApi().getGUI().addTexture(head, "http://textures.minecraft.net/texture/1b6f1a25b6bc199946472aedb370522584ff6f4e83221e5946bd2e41b5ca13b");
|
||||
SkullMeta skullMeta = (SkullMeta) skull.getItemMeta();
|
||||
skull.setDurability((short) 3);
|
||||
skullMeta.setDisplayName(TextComponent.formatText("&6&l+1"));
|
||||
skull.setItemMeta(skullMeta);
|
||||
|
||||
ItemStack head2 = new ItemStack(Material.PLAYER_HEAD, 1, (byte) 3);
|
||||
ItemStack skull2 = Arconix.pl().getApi().getGUI().addTexture(head2, "http://textures.minecraft.net/texture/3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23");
|
||||
SkullMeta skull2Meta = (SkullMeta) skull2.getItemMeta();
|
||||
skull2.setDurability((short) 3);
|
||||
skull2Meta.setDisplayName(TextComponent.formatText("&6&l-1"));
|
||||
skull2.setItemMeta(skull2Meta);
|
||||
|
||||
if (amt != 1) {
|
||||
i.setItem(0, skull2);
|
||||
}
|
||||
if (amt < EpicSpawnersPlugin.getInstance().getConfig().getInt("Spawner Boosting.Max Multiplier For A Spawner Boost")) {
|
||||
i.setItem(8, skull);
|
||||
}
|
||||
|
||||
player.openInventory(i);
|
||||
EpicSpawnersPlugin.getInstance().getPlayerActionManager().getPlayerAction(player).setInMenu(MenuType.PLAYERBOOST);
|
||||
EpicSpawnersPlugin.getInstance().getPlayerActionManager().getPlayerAction(player).setLastSpawner(this);
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkConditions() {
|
||||
for (SpawnerStack stack : spawnerStacks) {
|
||||
@ -261,219 +154,18 @@ public class ESpawner implements Spawner {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void purchaseBoost(Player player, int time) {
|
||||
try {
|
||||
EpicSpawnersPlugin instance = EpicSpawnersPlugin.getInstance();
|
||||
|
||||
int amt = boostAmt.get(player.getUniqueId());
|
||||
boolean yes = false;
|
||||
|
||||
String un = EpicSpawnersPlugin.getInstance().getConfig().getString("Spawner Boosting.Item Charged For A Boost");
|
||||
|
||||
String[] parts = un.split(":");
|
||||
|
||||
String type = parts[0];
|
||||
String multi = parts[1];
|
||||
int cost = Methods.boostCost(multi, time, amt);
|
||||
if (!type.equals("ECO") && !type.equals("XP")) {
|
||||
ItemStack stack = new ItemStack(Material.valueOf(type));
|
||||
int invAmt = Arconix.pl().getApi().getGUI().getAmount(player.getInventory(), stack);
|
||||
if (invAmt >= cost) {
|
||||
stack.setAmount(cost);
|
||||
Arconix.pl().getApi().getGUI().removeFromInventory(player.getInventory(), stack);
|
||||
yes = true;
|
||||
} else {
|
||||
player.sendMessage(EpicSpawnersPlugin.getInstance().getLocale().getMessage("event.upgrade.cannotafford"));
|
||||
}
|
||||
} else if (type.equals("ECO")) {
|
||||
if (EpicSpawnersPlugin.getInstance().getServer().getPluginManager().getPlugin("Vault") != null) {
|
||||
RegisteredServiceProvider<net.milkbowl.vault.economy.Economy> rsp = EpicSpawnersPlugin.getInstance().getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
|
||||
net.milkbowl.vault.economy.Economy econ = rsp.getProvider();
|
||||
if (econ.has(player, cost)) {
|
||||
econ.withdrawPlayer(player, cost);
|
||||
yes = true;
|
||||
} else {
|
||||
player.sendMessage(EpicSpawnersPlugin.getInstance().getLocale().getMessage("event.upgrade.cannotafford"));
|
||||
}
|
||||
} else {
|
||||
player.sendMessage("Vault is not installed.");
|
||||
}
|
||||
} else if (type.equals("XP")) {
|
||||
if (player.getLevel() >= cost || player.getGameMode() == GameMode.CREATIVE) {
|
||||
if (player.getGameMode() != GameMode.CREATIVE) {
|
||||
player.setLevel(player.getLevel() - cost);
|
||||
}
|
||||
yes = true;
|
||||
} else {
|
||||
player.sendMessage(EpicSpawnersPlugin.getInstance().getLocale().getMessage("event.upgrade.cannotafford"));
|
||||
}
|
||||
}
|
||||
if (yes) {
|
||||
Calendar c = Calendar.getInstance();
|
||||
Date currentDate = new Date();
|
||||
c.setTime(currentDate);
|
||||
c.add(Calendar.MINUTE, time);
|
||||
|
||||
|
||||
BoostData boostData = new BoostData(BoostType.LOCATION, amt, c.getTime().getTime(), location);
|
||||
instance.getBoostManager().addBoostToSpawner(boostData);
|
||||
player.sendMessage(EpicSpawnersPlugin.getInstance().getLocale().getMessage("event.boost.applied"));
|
||||
}
|
||||
player.closeInventory();
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
@Override
|
||||
public boolean isRedstonePowered() {
|
||||
return (!location.getBlock().isBlockPowered()
|
||||
&& !location.getBlock().isBlockIndirectlyPowered())
|
||||
|| !SettingsManager.Setting.REDSTONE_ACTIVATE.getBoolean();
|
||||
}
|
||||
|
||||
public void overview(Player player) {
|
||||
try {
|
||||
EpicSpawnersPlugin instance = EpicSpawnersPlugin.getInstance();
|
||||
if (!player.hasPermission("epicspawners.overview")) return;
|
||||
new GUISpawnerOverview(instance, this, player).openFor(player);
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void convertOverview(Player player, int page) {
|
||||
try {
|
||||
EpicSpawnersPlugin instance = EpicSpawnersPlugin.getInstance();
|
||||
PlayerData playerData = instance.getPlayerActionManager().getPlayerAction(player);
|
||||
|
||||
playerData.setCurrentPage(page);
|
||||
|
||||
List<SpawnerData> entities = new ArrayList<>();
|
||||
|
||||
int num = 0;
|
||||
int show = 0;
|
||||
int start = (page - 1) * 32;
|
||||
for (SpawnerData spawnerData : instance.getSpawnerManager().getAllSpawnerData()) {
|
||||
if (spawnerData.getIdentifyingName().equalsIgnoreCase("omni")
|
||||
|| !spawnerData.isConvertible()
|
||||
|| !player.hasPermission("epicspawners.convert." + spawnerData.getIdentifyingName().replace(" ", "_"))) continue;
|
||||
if (num >= start) {
|
||||
if (show <= 32) {
|
||||
entities.add(spawnerData);
|
||||
show++;
|
||||
}
|
||||
}
|
||||
num++;
|
||||
}
|
||||
|
||||
int amt = entities.size();
|
||||
String title = instance.getLocale().getMessage("interface.convert.title");
|
||||
Inventory i = Bukkit.createInventory(null, 54, TextComponent.formatTitle(title));
|
||||
int max2 = 54;
|
||||
if (amt <= 7) {
|
||||
i = Bukkit.createInventory(null, 27, TextComponent.formatTitle(title));
|
||||
max2 = 27;
|
||||
} else if (amt <= 15) {
|
||||
i = Bukkit.createInventory(null, 36, TextComponent.formatTitle(title));
|
||||
max2 = 36;
|
||||
} else if (amt <= 25) {
|
||||
i = Bukkit.createInventory(null, 45, TextComponent.formatTitle(title));
|
||||
max2 = 45;
|
||||
}
|
||||
|
||||
final int max22 = max2;
|
||||
int place = 10;
|
||||
for (SpawnerData spawnerData : entities) {
|
||||
if (place == 17)
|
||||
place++;
|
||||
if (place == (max22 - 18))
|
||||
place++;
|
||||
ItemStack it = new ItemStack(Material.PLAYER_HEAD, 1, (byte) 3);
|
||||
|
||||
ItemStack item = instance.getHeads().addTexture(it, spawnerData);
|
||||
|
||||
if (spawnerData.getDisplayItem() != null) {
|
||||
Material mat = spawnerData.getDisplayItem();
|
||||
if (!mat.equals(Material.AIR))
|
||||
item = new ItemStack(mat, 1);
|
||||
}
|
||||
|
||||
ItemMeta itemmeta = item.getItemMeta();
|
||||
String name = Methods.compileName(spawnerData, 1, true);
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
double price = spawnerData.getConvertPrice() * getSpawnerDataCount();
|
||||
|
||||
lore.add(instance.getLocale().getMessage("interface.shop.buyprice", TextComponent.formatEconomy(price)));
|
||||
String loreString = instance.getLocale().getMessage("interface.convert.lore", Methods.getTypeFromString(spawnerData.getIdentifyingName()));
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
|
||||
loreString = me.clip.placeholderapi.PlaceholderAPI.setPlaceholders(player, loreString.replace(" ", "_")).replace("_", " ");
|
||||
}
|
||||
lore.add(loreString);
|
||||
itemmeta.setLore(lore);
|
||||
itemmeta.setDisplayName(name);
|
||||
item.setItemMeta(itemmeta);
|
||||
i.setItem(place, item);
|
||||
place++;
|
||||
}
|
||||
|
||||
int max = (int) Math.ceil((double) num / (double) 36);
|
||||
num = 0;
|
||||
while (num != 9) {
|
||||
i.setItem(num, Methods.getGlass());
|
||||
num++;
|
||||
}
|
||||
int num2 = max2 - 9;
|
||||
while (num2 != max2) {
|
||||
i.setItem(num2, Methods.getGlass());
|
||||
num2++;
|
||||
}
|
||||
|
||||
ItemStack exit = new ItemStack(Material.valueOf(instance.getConfig().getString("Interfaces.Exit Icon")), 1);
|
||||
ItemMeta exitmeta = exit.getItemMeta();
|
||||
exitmeta.setDisplayName(instance.getLocale().getMessage("general.nametag.exit"));
|
||||
exit.setItemMeta(exitmeta);
|
||||
|
||||
ItemStack head = new ItemStack(Material.PLAYER_HEAD, 1, (byte) 3);
|
||||
ItemStack skull = Arconix.pl().getApi().getGUI().addTexture(head, "http://textures.minecraft.net/texture/1b6f1a25b6bc199946472aedb370522584ff6f4e83221e5946bd2e41b5ca13b");
|
||||
SkullMeta skullMeta = (SkullMeta) skull.getItemMeta();
|
||||
skull.setDurability((short) 3);
|
||||
skullMeta.setDisplayName(instance.getLocale().getMessage("general.nametag.next"));
|
||||
skull.setItemMeta(skullMeta);
|
||||
|
||||
ItemStack head2 = new ItemStack(Material.PLAYER_HEAD, 1, (byte) 3);
|
||||
ItemStack skull2 = Arconix.pl().getApi().getGUI().addTexture(head2, "http://textures.minecraft.net/texture/3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23");
|
||||
SkullMeta skull2Meta = (SkullMeta) skull2.getItemMeta();
|
||||
skull2.setDurability((short) 3);
|
||||
skull2Meta.setDisplayName(instance.getLocale().getMessage("general.nametag.back"));
|
||||
skull2.setItemMeta(skull2Meta);
|
||||
|
||||
i.setItem(8, exit);
|
||||
|
||||
i.setItem(0, Methods.getBackgroundGlass(true));
|
||||
i.setItem(1, Methods.getBackgroundGlass(true));
|
||||
i.setItem(9, Methods.getBackgroundGlass(true));
|
||||
|
||||
i.setItem(7, Methods.getBackgroundGlass(true));
|
||||
i.setItem(17, Methods.getBackgroundGlass(true));
|
||||
|
||||
i.setItem(max22 - 18, Methods.getBackgroundGlass(true));
|
||||
i.setItem(max22 - 9, Methods.getBackgroundGlass(true));
|
||||
i.setItem(max22 - 8, Methods.getBackgroundGlass(true));
|
||||
|
||||
i.setItem(max22 - 10, Methods.getBackgroundGlass(true));
|
||||
i.setItem(max22 - 2, Methods.getBackgroundGlass(true));
|
||||
i.setItem(max22 - 1, Methods.getBackgroundGlass(true));
|
||||
|
||||
i.setItem(2, Methods.getBackgroundGlass(false));
|
||||
i.setItem(6, Methods.getBackgroundGlass(false));
|
||||
i.setItem(max22 - 7, Methods.getBackgroundGlass(false));
|
||||
i.setItem(max22 - 3, Methods.getBackgroundGlass(false));
|
||||
|
||||
if (page != 1) {
|
||||
i.setItem(max22 - 8, skull2);
|
||||
}
|
||||
if (page != max) {
|
||||
i.setItem(max22 - 2, skull);
|
||||
}
|
||||
|
||||
player.openInventory(i);
|
||||
|
||||
playerData.setInMenu(MenuType.CONVERT);
|
||||
playerData.setLastSpawner(this);
|
||||
new GUISpawnerOverview(instance, this, player);
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
@ -493,7 +185,7 @@ public class ESpawner implements Spawner {
|
||||
double price = type.getConvertPrice() * getSpawnerDataCount();
|
||||
|
||||
if (!(econ.has(p, price) || p.isOp())) {
|
||||
p.sendMessage(EpicSpawnersPlugin.getInstance().getReferences().getPrefix() + EpicSpawnersPlugin.getInstance().getLocale().getMessage("event.upgrade.cannotafford"));
|
||||
p.sendMessage(References.getPrefix() + EpicSpawnersPlugin.getInstance().getLocale().getMessage("event.upgrade.cannotafford"));
|
||||
return;
|
||||
}
|
||||
SpawnerChangeEvent event = new SpawnerChangeEvent(p, this, getFirstStack().getSpawnerData(), type);
|
||||
@ -510,7 +202,7 @@ public class ESpawner implements Spawner {
|
||||
}
|
||||
this.creatureSpawner.update();
|
||||
|
||||
p.sendMessage(EpicSpawnersPlugin.getInstance().getReferences().getPrefix() + EpicSpawnersPlugin.getInstance().getLocale().getMessage("event.convert.success"));
|
||||
p.sendMessage(References.getPrefix() + EpicSpawnersPlugin.getInstance().getLocale().getMessage("event.convert.success"));
|
||||
|
||||
instance.getHologramHandler().updateHologram(this);
|
||||
p.closeInventory();
|
||||
@ -559,12 +251,15 @@ public class ESpawner implements Spawner {
|
||||
int stackSize = 1;
|
||||
|
||||
if (player.isSneaking() && EpicSpawnersPlugin.getInstance().getConfig().getBoolean("Main.Sneak To Receive A Stacked Spawner")
|
||||
|| instance.getConfig().getBoolean("Spawner Drops.Only Drop Stacked Spawners")) {
|
||||
|| SettingsManager.Setting.ONLY_DROP_STACKED.getBoolean()) {
|
||||
stackSize = stack.getStackSize();
|
||||
}
|
||||
|
||||
if (instance.getConfig().getBoolean("Main.Sounds Enabled")) {
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 0.6F, 15.0F);
|
||||
if (stackSize == stack.getStackSize() && spawnerStacks.size() == 1)
|
||||
player.playSound(player.getLocation(), Sound.BLOCK_ANVIL_STEP, 1L, 1L);
|
||||
else
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 0.6F, 15.0F);
|
||||
}
|
||||
ItemStack item = stack.getSpawnerData().toItemStack(1, stackSize);
|
||||
|
||||
@ -573,10 +268,11 @@ public class ESpawner implements Spawner {
|
||||
player.getInventory().addItem(item);
|
||||
else if (!instance.getConfig().getBoolean("Main.Only Drop Placed Spawner") || placedBy != null) { //ToDo: Clean this up.
|
||||
|
||||
if (instance.getConfig().getBoolean("Spawner Drops.Drop On SilkTouch")
|
||||
if (SettingsManager.Setting.SILKTOUCH_SPAWNERS.getBoolean()
|
||||
&& player.getItemInHand() != null
|
||||
&& player.getItemInHand().hasItemMeta()
|
||||
&& player.getItemInHand().getItemMeta().hasEnchant(Enchantment.SILK_TOUCH)
|
||||
&& player.getItemInHand().getEnchantmentLevel(Enchantment.SILK_TOUCH) >= SettingsManager.Setting.SILKTOUCH_MIN_LEVEL.getInt()
|
||||
&& player.hasPermission("epicspawners.silkdrop." + stack.getSpawnerData().getIdentifyingName().replace(' ', '_'))
|
||||
|| player.hasPermission("epicspawners.no-silk-drop")) {
|
||||
|
||||
@ -586,7 +282,7 @@ public class ESpawner implements Spawner {
|
||||
double rand = Math.random() * 100;
|
||||
|
||||
if (rand - ch < 0 || ch == 100) {
|
||||
if (instance.getConfig().getBoolean("Main.Add Spawners To Inventory On Drop") && player.getInventory().firstEmpty() != -1)
|
||||
if (SettingsManager.Setting.SPAWNERS_TO_INVENTORY.getBoolean() && player.getInventory().firstEmpty() != -1)
|
||||
player.getInventory().addItem(item);
|
||||
else
|
||||
location.getWorld().dropItemNaturally(location.clone().add(.5, 0, .5), item);
|
||||
@ -624,11 +320,11 @@ public class ESpawner implements Spawner {
|
||||
public boolean stack(Player player, SpawnerData data, int amount) {
|
||||
EpicSpawnersPlugin instance = EpicSpawnersPlugin.getInstance();
|
||||
|
||||
int max = instance.getConfig().getInt("Main.Spawner Max Upgrade");
|
||||
int max = SettingsManager.Setting.SPAWNERS_MAX.getInt();
|
||||
int currentStackSize = getSpawnerDataCount();
|
||||
|
||||
if (getSpawnerDataCount() == max) {
|
||||
player.sendMessage(instance.getLocale().getMessage("event.upgrade.maxed", max));
|
||||
player.sendMessage(References.getPrefix() + instance.getLocale().getMessage("event.upgrade.maxed", max));
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -654,7 +350,7 @@ public class ESpawner implements Spawner {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!instance.getConfig().getBoolean("Main.OmniSpawners Enabled") || !player.hasPermission("epicspawners.omni"))
|
||||
if (!SettingsManager.Setting.OMNI_SPAWNERS.getBoolean() || !player.hasPermission("epicspawners.omni"))
|
||||
return false;
|
||||
|
||||
ESpawnerStack stack = new ESpawnerStack(data, amount);
|
||||
@ -670,10 +366,10 @@ public class ESpawner implements Spawner {
|
||||
try {
|
||||
int currentStackSize = getSpawnerDataCount();
|
||||
|
||||
if (getSpawnerDataCount() != EpicSpawnersPlugin.getInstance().getConfig().getInt("Main.Spawner Max Upgrade"))
|
||||
player.sendMessage(EpicSpawnersPlugin.getInstance().getLocale().getMessage("event.upgrade.success", currentStackSize));
|
||||
if (getSpawnerDataCount() != SettingsManager.Setting.SPAWNERS_MAX.getInt())
|
||||
player.sendMessage(References.getPrefix() + EpicSpawnersPlugin.getInstance().getLocale().getMessage("event.upgrade.success", currentStackSize));
|
||||
else
|
||||
player.sendMessage(EpicSpawnersPlugin.getInstance().getLocale().getMessage("event.upgrade.successmaxed", currentStackSize));
|
||||
player.sendMessage(References.getPrefix() + EpicSpawnersPlugin.getInstance().getLocale().getMessage("event.upgrade.successmaxed", currentStackSize));
|
||||
|
||||
SpawnerChangeEvent event = new SpawnerChangeEvent(player, this, currentStackSize, oldStackSize);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
@ -685,9 +381,8 @@ public class ESpawner implements Spawner {
|
||||
loc.setZ(loc.getZ() + .5);
|
||||
player.getWorld().spawnParticle(org.bukkit.Particle.valueOf(EpicSpawnersPlugin.getInstance().getConfig().getString("Main.Upgrade Particle Type")), loc, 100, .5, .5, .5);
|
||||
|
||||
|
||||
if (!EpicSpawnersPlugin.getInstance().getConfig().getBoolean("Main.Sounds Enabled")) {
|
||||
return;
|
||||
if (!SettingsManager.Setting.SOUNDS_ENABLED.getBoolean()) {
|
||||
return;
|
||||
}
|
||||
if (currentStackSize != EpicSpawnersPlugin.getInstance().getConfig().getInt("Main.Spawner Max Upgrade")) {
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 0.6F, 15.0F);
|
||||
@ -707,13 +402,10 @@ public class ESpawner implements Spawner {
|
||||
try {
|
||||
int cost = getUpgradeCost(type);
|
||||
|
||||
boolean maxed = false;
|
||||
boolean maxed = getSpawnerDataCount() == SettingsManager.Setting.SPAWNERS_MAX.getInt();
|
||||
|
||||
if (getSpawnerDataCount() == EpicSpawnersPlugin.getInstance().getConfig().getInt("Main.Spawner Max Upgrade")) {
|
||||
maxed = true;
|
||||
}
|
||||
if (maxed) {
|
||||
player.sendMessage(EpicSpawnersPlugin.getInstance().getLocale().getMessage("event.upgrade.maxed"));
|
||||
player.sendMessage(References.getPrefix() + EpicSpawnersPlugin.getInstance().getLocale().getMessage("event.upgrade.maxed"));
|
||||
} else {
|
||||
if (type == CostType.ECONOMY) {
|
||||
if (EpicSpawnersPlugin.getInstance().getServer().getPluginManager().getPlugin("Vault") != null) {
|
||||
@ -725,7 +417,7 @@ public class ESpawner implements Spawner {
|
||||
spawnerStacks.getFirst().setStackSize(spawnerStacks.getFirst().getStackSize() + 1);
|
||||
upgradeFinal(player, oldMultiplier);
|
||||
} else {
|
||||
player.sendMessage(EpicSpawnersPlugin.getInstance().getLocale().getMessage("event.upgrade.cannotafford"));
|
||||
player.sendMessage(References.getPrefix() + EpicSpawnersPlugin.getInstance().getLocale().getMessage("event.upgrade.cannotafford"));
|
||||
}
|
||||
} else {
|
||||
player.sendMessage("Vault is not installed.");
|
||||
@ -739,7 +431,7 @@ public class ESpawner implements Spawner {
|
||||
spawnerStacks.getFirst().setStackSize(spawnerStacks.getFirst().getStackSize() + 1);
|
||||
upgradeFinal(player, oldMultiplier);
|
||||
} else {
|
||||
player.sendMessage(EpicSpawnersPlugin.getInstance().getLocale().getMessage("event.upgrade.cannotafford"));
|
||||
player.sendMessage(References.getPrefix() + EpicSpawnersPlugin.getInstance().getLocale().getMessage("event.upgrade.cannotafford"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -937,14 +629,6 @@ public class ESpawner implements Spawner {
|
||||
this.omniState = omniState;
|
||||
}
|
||||
|
||||
public void addBoostAmt(Player player, int amt) {
|
||||
boostAmt.put(player.getUniqueId(), amt);
|
||||
}
|
||||
|
||||
public int getBoostAmt(Player player) {
|
||||
return boostAmt.getOrDefault(player.getUniqueId(), 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = 31 * (location == null ? 0 : location.hashCode());
|
||||
|
@ -5,6 +5,7 @@ import com.songoda.epicspawners.api.spawner.SpawnerData;
|
||||
import com.songoda.epicspawners.api.spawner.SpawnerManager;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@ -103,6 +104,16 @@ public class ESpawnerManager implements SpawnerManager {
|
||||
return pickingUp.contains(spawner);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAmountPlaced(Player player) {
|
||||
int amount = 0;
|
||||
for (Spawner spawner : spawnersInWorld.values()) {
|
||||
if (spawner.getPlacedBy() == null || player.getUniqueId() != spawner.getPlacedBy().getUniqueId()) continue;
|
||||
amount ++;
|
||||
}
|
||||
return amount;
|
||||
}
|
||||
|
||||
private Location roundLocation(Location location) {
|
||||
location = location.clone();
|
||||
location.setX(location.getBlockX());
|
||||
|
@ -225,7 +225,8 @@ public class SpawnOptionEntity implements SpawnOption {
|
||||
|
||||
for (Material material : spawnBlocks) {
|
||||
Material down = location.getBlock().getRelative(BlockFace.DOWN).getType();
|
||||
if ((location.getBlock().getType() == Material.AIR || location.getBlock().getType().name().toLowerCase().contains("pressure")) && material == Material.AIR)
|
||||
String str = location.getBlock().getType().name().toLowerCase();
|
||||
if ((location.getBlock().getType() == Material.AIR || str.contains("pressure") || str.contains("slab")) && material == Material.AIR)
|
||||
return true;
|
||||
if (material == null) continue;
|
||||
if (down.toString().equalsIgnoreCase(material.name())
|
||||
|
@ -35,15 +35,14 @@ public class SpawnerSpawnTask extends BukkitRunnable {
|
||||
for (Spawner spawner : manager.getSpawners()) {
|
||||
if (spawner == null || spawner.getSpawnerDataCount() == 0) continue;
|
||||
|
||||
int x = spawner.getX() >> 4;
|
||||
int z = spawner.getZ() >> 4;
|
||||
|
||||
int delay = spawner.getCreatureSpawner().getDelay();
|
||||
delay = delay - 30;
|
||||
spawner.getCreatureSpawner().setDelay(delay);
|
||||
if (delay >= 0) continue;
|
||||
|
||||
if (!spawner.getWorld().isChunkLoaded(x, z) || !spawner.checkConditions()) {
|
||||
if (!spawner.isRedstonePowered()) continue;
|
||||
|
||||
if (!spawner.getWorld().isChunkLoaded(spawner.getX() >> 4, spawner.getZ() >> 4) || !spawner.checkConditions()) {
|
||||
spawner.getCreatureSpawner().setDelay(300);
|
||||
continue;
|
||||
}
|
||||
|
@ -182,12 +182,7 @@ public class SettingsManager implements Listener {
|
||||
FileConfiguration config = instance.getConfig();
|
||||
|
||||
for (Setting setting : Setting.values()) {
|
||||
if (config.contains("settings." + setting.oldSetting)) {
|
||||
config.addDefault(setting.setting, instance.getConfig().get("settings." + setting.oldSetting));
|
||||
config.set("settings." + setting.oldSetting, null);
|
||||
} else {
|
||||
config.addDefault(setting.setting, setting.option);
|
||||
}
|
||||
config.addDefault(setting.setting, setting.option);
|
||||
}
|
||||
|
||||
config.set("settings", null);
|
||||
@ -195,93 +190,102 @@ public class SettingsManager implements Listener {
|
||||
|
||||
public enum Setting {
|
||||
|
||||
SPAWNERS_MAX("spawners-max", "Main.Spawner Max Upgrade", 5),
|
||||
NAME_FORMAT("Name-format", "Main.Spawner Name Format", "&e{TYPE} &fSpawner [&c{AMT}x]"),
|
||||
FORCE_COMBINE_RADIUS("Force-Combine-Radius", "Main.Force Combine Radius", 0),
|
||||
FORCE_COMBINE_DENY("Force-Combine-Deny", "Main.Deny Place On Force Combine", false),
|
||||
SEARCH_RADIUS("Search-Radius", "Main.Radius To Search Around Spawners", "8x4x8"),
|
||||
ALTER_DELAY("Alter-Delay", "Main.Default Minecraft Spawner Cooldowns", true),
|
||||
ALERT_PLACE_BREAK("Alert-place-break", "Main.Alerts On Place And Break", true),
|
||||
SNEAK_FOR_STACK("Sneak-for-stack", "Main.Sneak To Receive A Stacked Spawner", true),
|
||||
SPAWNER_HOLOGRAMS("spawners-holograms", "Main.Spawners Have Holograms", true),
|
||||
ONLY_DROP_PLACED("Only-drop-placed", "Main.Only Drop Placed Spawner", false),
|
||||
ONLY_CHARGE_NATURAL("Only-charge-natural", "Main.Only Charge Natural Spawners", false),
|
||||
CUSTOM_SPAWNER_TICK_RATE("123", "Main.Custom Spawner Tick Rate", 10),
|
||||
RANDOM_LOW_HIGH("Random-Low & Random-High", "Main.Random Amount Added To Each Spawn", "1:3"),
|
||||
SOUNDS_ENABLED("Sounds", "Main.Sounds Enabled", true),
|
||||
DISPLAY_LEVEL_ONE("Display-Level-One", "Main.Display Level In Spawner Title If Level 1", false),
|
||||
OMNI_SPAWNERS("OmniSpawners", "Main.OmniSpawners Enabled", true),
|
||||
EGGS_CONVERT_SPAWNERS("Eggs-convert-spawners", "Main.Convert Spawners With Eggs", true),
|
||||
HELPFUL_TIPS_ENABLED("Helpful-Tips", "Main.Display Helpful Tips For Operators", true),
|
||||
UPGRADE_WITH_ECO_ENABLED("Upgrade-with-eco", "Main.Upgrade With Economy", true),
|
||||
UPGRADE_WITH_XP_ENABLED("Upgrade-with-xp", "Main.Upgrade With XP", true),
|
||||
UPGRADE_COST_ECO("Upgrade-eco-cost", "Main.Cost To Upgrade With Economy", 10000),
|
||||
UPGRADE_COST_XP("Upgrade-xp-cost", "Main.Cost To Upgrade With XP", 50),
|
||||
USE_CUSTOM_UPGRADE_EQUATION("Use-equations", "Main.Use Custom Equations for Upgrade Costs", false),
|
||||
LIQUID_REPEL_RADIUS("spawners-repel-radius", "Main.Spawner Repel Liquid Radius", 1),
|
||||
REDSTONE_ACTIVATE("redstone-activate", "Main.Redstone Power Deactivates Spawners", true),
|
||||
DISPLAY_HELP_BUTTON("How-to", "Main.Display Help Button In Spawner Overview", true),
|
||||
SPAWNERS_DONT_EXPLODE("spawners-dont-explode", "Main.Prevent Spawners From Exploding", false),
|
||||
SPAWNERS_TO_INVENTORY("Add-spawners-To-Inventory-On-Drop", "Main.Add Spawners To Inventory On Drop", false),
|
||||
UPGRADE_PARTICLE_TYPE("Upgrade-particle-Type", "Main.Upgrade Particle Type", "SPELL_WITCH"),
|
||||
EXTRA_SPAWN_TICKS("Upgrade-particle-Type", "Main.Extra Ticks Added To Each Spawn", 0),
|
||||
SPAWNERS_MAX("Main.Spawner Max Upgrade", 5),
|
||||
NAME_FORMAT("Main.Spawner Name Format", "&e{TYPE} &fSpawner [&c{AMT}x]"),
|
||||
FORCE_COMBINE_RADIUS("Main.Force Combine Radius", 0),
|
||||
FORCE_COMBINE_DENY("Main.Deny Place On Force Combine", false),
|
||||
SEARCH_RADIUS("Main.Radius To Search Around Spawners", "8x4x8"),
|
||||
ALTER_DELAY("Main.Default Minecraft Spawner Cooldowns", true),
|
||||
ALERT_PLACE_BREAK("Main.Alerts On Place And Break", true),
|
||||
SNEAK_FOR_STACK("Main.Sneak To Receive A Stacked Spawner", true),
|
||||
SPAWNER_HOLOGRAMS("Main.Spawners Have Holograms", true),
|
||||
ONLY_DROP_PLACED("Main.Only Drop Placed Spawner", false),
|
||||
ONLY_CHARGE_NATURAL("Main.Only Charge Natural Spawners", false),
|
||||
CUSTOM_SPAWNER_TICK_RATE("Main.Custom Spawner Tick Rate", 10),
|
||||
RANDOM_LOW_HIGH("Main.Random Amount Added To Each Spawn", "1:3"),
|
||||
SOUNDS_ENABLED("Main.Sounds Enabled", true),
|
||||
DISPLAY_LEVEL_ONE("Main.Display Level In Spawner Title If Level 1", false),
|
||||
OMNI_SPAWNERS("Main.OmniSpawners Enabled", true),
|
||||
EGGS_CONVERT_SPAWNERS("Main.Convert Spawners With Eggs", true),
|
||||
HELPFUL_TIPS_ENABLED("Main.Display Helpful Tips For Operators", true),
|
||||
UPGRADE_WITH_ECO_ENABLED("Main.Upgrade With Economy", true),
|
||||
UPGRADE_WITH_XP_ENABLED("Main.Upgrade With XP", true),
|
||||
UPGRADE_COST_ECO("Main.Cost To Upgrade With Economy", 10000),
|
||||
UPGRADE_COST_XP("Main.Cost To Upgrade With XP", 50),
|
||||
USE_CUSTOM_UPGRADE_EQUATION("Main.Use Custom Equations for Upgrade Costs", false),
|
||||
LIQUID_REPEL_RADIUS("Main.Spawner Repel Liquid Radius", 1),
|
||||
REDSTONE_ACTIVATE("Main.Redstone Power Deactivates Spawners", true),
|
||||
DISPLAY_HELP_BUTTON("Main.Display Help Button In Spawner Overview", true),
|
||||
SPAWNERS_DONT_EXPLODE("Main.Prevent Spawners From Exploding", false),
|
||||
SPAWNERS_TO_INVENTORY("Main.Add Spawners To Inventory On Drop", false),
|
||||
UPGRADE_PARTICLE_TYPE("Main.Upgrade Particle Type", "SPELL_WITCH"),
|
||||
EXTRA_SPAWN_TICKS("Main.Extra Ticks Added To Each Spawn", 0),
|
||||
MAX_SPAWNERS("Main.Max Spawners Per Player", -1),
|
||||
AUTOSAVE("Main.Auto Save Interval In Seconds", 15),
|
||||
|
||||
COST_EQUATION_XP("XP-cost-equation", "Main.Equations.Calculate XP Upgrade Cost", "{XPCost} * {Level}"),
|
||||
COST_EQUATION_ECO("ECO-cost-equation", "Main.Equations.Calculate Economy Upgrade Cost", "{ECOCost} * {Level}"),
|
||||
SPAWNER_EQUATION_SPAWNS("spawners-Spawn-Equation", "Main.Equations.Mobs Spawned Per Spawn", "{MULTI} + {RAND}"),
|
||||
COST_EQUATION_XP("Main.Equations.Calculate XP Upgrade Cost", "{XPCost} * {Level}"),
|
||||
COST_EQUATION_ECO("Main.Equations.Calculate Economy Upgrade Cost", "{ECOCost} * {Level}"),
|
||||
SPAWNER_EQUATION_SPAWNS("Main.Equations.Mobs Spawned Per Spawn", "{MULTI} + {RAND}"),
|
||||
|
||||
NAMED_SPAWNER_TIERS("-", "Main.Named Spawners Tiers", false),
|
||||
TIER_NAMES("-", "Main.Tier Names", Arrays.asList("&7Common", "&6Uncommon", "&4Rare", "&5Mythic")),
|
||||
NAMED_SPAWNER_TIERS("Main.Named Spawners Tiers", false),
|
||||
TIER_NAMES("Main.Tier Names", Arrays.asList("&7Common", "&6Uncommon", "&4Rare", "&5Mythic")),
|
||||
|
||||
BOOST_MULTIPLIER("Boost-Multiplier", "Spawner Boosting.Boost Multiplier", "0.5"),
|
||||
MAX_PLAYER_BOOST("Max-Player-Boost", "Spawner Boosting.Max Multiplier For A Spawner Boost", 5),
|
||||
BOOST_COST("Boost-cost", "Spawner Boosting.Item Charged For A Boost", "DIAMOND:2"),
|
||||
BOOST_MULTIPLIER("Spawner Boosting.Boost Multiplier", "0.5"),
|
||||
MAX_PLAYER_BOOST("Spawner Boosting.Max Multiplier For A Spawner Boost", 5),
|
||||
BOOST_COST("Spawner Boosting.Item Charged For A Boost", "DIAMOND:2"),
|
||||
|
||||
HOSTILE_MOBS_ATTACK_SECOND("Hostile-mobs-attack-second", "entity.Hostile Mobs Attack Second", false),
|
||||
HOSTILE_MOBS_ATTACK_SECOND("entity.Hostile Mobs Attack Second", false),
|
||||
|
||||
ONLY_DROP_STACKED("Only-drop-stacked", "Spawner Drops.Only Drop Stacked Spawners", false),
|
||||
MOB_KILLING_COUNT("Mob-kill-counting", "Spawner Drops.Allow Killing Mobs To Drop Spawners", true),
|
||||
COUNT_UNNATURAL_KILLS("Count-unnatural-kills", "Spawner Drops.Count Unnatural Kills Towards Spawner Drop", false),
|
||||
KILL_GOAL("Goal", "Spawner Drops.Kills Needed for Drop", 100),
|
||||
ALERT_INTERVAL("Alert-every", "Spawner Drops.Alert Every X Before Drop", 10),
|
||||
DROP_ON_CREEPER_EXPLOSION("Drop-on-creeper-explosion", "Spawner Drops.Drop On Creeper Explosion", true),
|
||||
DROP_ON_TNT_EXPLOSION("Drop-on-tnt-explosion", "Spawner Drops.Drop On TNT Explosion", true),
|
||||
EXPLOSION_DROP_CHANCE_TNT("Tnt-explosion-drop-chance", "Spawner Drops.Chance On TNT Explosion", "100%"),
|
||||
EXPLOSION_DROP_CHANCE_CREEPER("Creeper-explosion-drop-chance", "Spawner Drops.Chance On Creeper Explosion", "100%"),
|
||||
SILKTOUCH_SPAWNERS("Silktouch-spawners", "Spawner Drops.Drop On SilkTouch", true),
|
||||
SILKTOUCH_NATURAL_SPAWNER_DROP_CHANCE("Silktouch-natural-drop-chance", "Spawner Drops.Chance On Natural Silktouch", "100%"),
|
||||
SILKTOUCH_PLACED_SPAWNER_DROP_CHANCE("Silktouch-placed-drop-chance", "Spawner Drops.Chance On Placed Silktouch", "100%"),
|
||||
ONLY_DROP_STACKED("Spawner Drops.Only Drop Stacked Spawners", false),
|
||||
MOB_KILLING_COUNT("Spawner Drops.Allow Killing Mobs To Drop Spawners", true),
|
||||
COUNT_UNNATURAL_KILLS("Spawner Drops.Count Unnatural Kills Towards Spawner Drop", false),
|
||||
KILL_GOAL("Spawner Drops.Kills Needed for Drop", 100),
|
||||
ALERT_INTERVAL("Spawner Drops.Alert Every X Before Drop", 10),
|
||||
DROP_ON_CREEPER_EXPLOSION("Spawner Drops.Drop On Creeper Explosion", true),
|
||||
DROP_ON_TNT_EXPLOSION("Spawner Drops.Drop On TNT Explosion", true),
|
||||
EXPLOSION_DROP_CHANCE_TNT("Spawner Drops.Chance On TNT Explosion", "100%"),
|
||||
EXPLOSION_DROP_CHANCE_CREEPER("Spawner Drops.Chance On Creeper Explosion", "100%"),
|
||||
SILKTOUCH_SPAWNERS("Spawner Drops.Drop On SilkTouch", true),
|
||||
SILKTOUCH_MIN_LEVEL("Spawner Drops.Minimum Required Silktouch Level", 1),
|
||||
SILKTOUCH_NATURAL_SPAWNER_DROP_CHANCE("Spawner Drops.Chance On Natural Silktouch", "100%"),
|
||||
SILKTOUCH_PLACED_SPAWNER_DROP_CHANCE("Spawner Drops.Chance On Placed Silktouch", "100%"),
|
||||
|
||||
EXIT_ICON("Exit-Icon", "Interfaces.Exit Icon", "OAK_DOOR"),
|
||||
BUY_ICON("Buy-Icon", "Interfaces.Buy Icon", "EMERALD"),
|
||||
ECO_ICON("ECO-Icon", "Interfaces.Economy Icon", "SUNFLOWER"),
|
||||
XP_ICON("XP-Icon", "Interfaces.XP Icon", "EXPERIENCE_BOTTLE"),
|
||||
GLASS_TYPE_1("Glass-Type-1", "Interfaces.Glass Type 1", 7),
|
||||
GLASS_TYPE_2("Glass-Type-2", "Interfaces.Glass Type 2", 11),
|
||||
GLASS_TYPE_3("Glass-Type-3", "Interfaces.Glass Type 3", 3),
|
||||
RAINBOW_GLASS("Rainbow-Glass", "Interfaces.Replace Glass Type 1 With Rainbow Glass", false),
|
||||
EXIT_ICON("Interfaces.Exit Icon", "OAK_DOOR"),
|
||||
BUY_ICON("Interfaces.Buy Icon", "EMERALD"),
|
||||
ECO_ICON("Interfaces.Economy Icon", "SUNFLOWER"),
|
||||
XP_ICON("Interfaces.XP Icon", "EXPERIENCE_BOTTLE"),
|
||||
GLASS_TYPE_1("Interfaces.Glass Type 1", 7),
|
||||
GLASS_TYPE_2("Interfaces.Glass Type 2", 11),
|
||||
GLASS_TYPE_3("Interfaces.Glass Type 3", 3),
|
||||
RAINBOW_GLASS("Interfaces.Replace Glass Type 1 With Rainbow Glass", false),
|
||||
|
||||
DATABASE_SUPPORT("-", "Database.Activate Mysql Support", false),
|
||||
DATABASE_IP("-", "Database.IP", "127.0.0.1"),
|
||||
DATABASE_PORT("-", "Database.Port", 3306),
|
||||
DATABASE_NAME("-", "Database.Database Name", "EpicSpawners"),
|
||||
DATABASE_PREFIX("-", "Database.Prefix", "ES-"),
|
||||
DATABASE_USERNAME("-", "Database.Username", "PUT_USERNAME_HERE"),
|
||||
DATABASE_PASSWORD("-", "Database.Password", "PUT_PASSWORD_HERE"),
|
||||
DATABASE_SUPPORT("Database.Activate Mysql Support", false),
|
||||
DATABASE_IP("Database.IP", "127.0.0.1"),
|
||||
DATABASE_PORT("Database.Port", 3306),
|
||||
DATABASE_NAME("Database.Database Name", "EpicSpawners"),
|
||||
DATABASE_PREFIX("Database.Prefix", "ES-"),
|
||||
DATABASE_USERNAME("Database.Username", "PUT_USERNAME_HERE"),
|
||||
DATABASE_PASSWORD("Database.Password", "PUT_PASSWORD_HERE"),
|
||||
|
||||
DOWNLOAD_FILES("-", "System.Download Needed Data Files", true),
|
||||
LANGUGE_MODE("-", "System.Language Mode", "en_US"),
|
||||
DEBUG_MODE("Debug-Mode", "System.Debugger Enabled", false);
|
||||
DOWNLOAD_FILES("System.Download Needed Data Files", true),
|
||||
LANGUGE_MODE("System.Language Mode", "en_US"),
|
||||
DEBUG_MODE("System.Debugger Enabled", false);
|
||||
|
||||
private final String setting, oldSetting;
|
||||
private final String setting;
|
||||
private final Object option;
|
||||
|
||||
private Setting(String oldSetting, String setting, Object option) {
|
||||
this.oldSetting = oldSetting;
|
||||
Setting(String setting, Object option) {
|
||||
this.setting = setting;
|
||||
this.option = option;
|
||||
}
|
||||
|
||||
public boolean getBoolean() {
|
||||
return EpicSpawnersPlugin.getInstance().getConfig().getBoolean(setting);
|
||||
}
|
||||
|
||||
public int getInt() {
|
||||
return EpicSpawnersPlugin.getInstance().getConfig().getInt(setting);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,270 @@
|
||||
package com.songoda.epicspawners.utils.gui;
|
||||
|
||||
import com.songoda.epicspawners.EpicSpawnersPlugin;
|
||||
import com.songoda.epicspawners.utils.version.NMSUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class AbstractAnvilGUI {
|
||||
|
||||
private static Class<?> BlockPosition;
|
||||
private static Class<?> PacketPlayOutOpenWindow;
|
||||
private static Class<?> ContainerAnvil;
|
||||
private static Class<?> ChatMessage;
|
||||
private static Class<?> EntityHuman;
|
||||
private static boolean loadedClasses = false;
|
||||
private Player player;
|
||||
@SuppressWarnings("unused")
|
||||
private AnvilClickEventHandler handler;
|
||||
private Map<AnvilSlot, ItemStack> items = new HashMap<>();
|
||||
private OnClose onClose = null;
|
||||
private Inventory inv;
|
||||
private Listener listener;
|
||||
|
||||
private Sound closeSound = Sound.ENTITY_PLAYER_LEVELUP;
|
||||
|
||||
public AbstractAnvilGUI(final Player player, final AnvilClickEventHandler handler) {
|
||||
loadClasses();
|
||||
this.player = player;
|
||||
this.handler = handler;
|
||||
|
||||
this.listener = new Listener() {
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
if (!(event.getWhoClicked() instanceof Player) || !event.getInventory().equals(inv)) return;
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
ItemStack item = event.getCurrentItem();
|
||||
int slot = event.getRawSlot();
|
||||
String name = "";
|
||||
|
||||
if (item != null) {
|
||||
if (item.hasItemMeta()) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
|
||||
if (meta.hasDisplayName()) {
|
||||
name = meta.getDisplayName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AnvilClickEvent clickEvent = new AnvilClickEvent(AnvilSlot.bySlot(slot), name);
|
||||
|
||||
handler.onAnvilClick(clickEvent);
|
||||
|
||||
if (clickEvent.getWillClose()) {
|
||||
event.getWhoClicked().closeInventory();
|
||||
}
|
||||
|
||||
if (clickEvent.getWillDestroy()) {
|
||||
destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClose(InventoryCloseEvent event) {
|
||||
if (!(event.getPlayer() instanceof Player)) return;
|
||||
Inventory inv = event.getInventory();
|
||||
player.setLevel(player.getLevel() - 1);
|
||||
if (!inv.equals(AbstractAnvilGUI.this.inv)) return;
|
||||
inv.clear();
|
||||
OnClose onClose = getOnClose();
|
||||
player.playSound(player.getLocation(), closeSound, 1F, 1F);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(EpicSpawnersPlugin.getInstance(), () -> {
|
||||
if (onClose != null) onClose.OnClose(player, inv);
|
||||
destroy();
|
||||
}, 1L);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
if (!event.getPlayer().equals(getPlayer())) return;
|
||||
player.setLevel(player.getLevel() - 1);
|
||||
destroy();
|
||||
}
|
||||
};
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(listener, EpicSpawnersPlugin.getInstance());
|
||||
}
|
||||
|
||||
private void loadClasses() {
|
||||
if (loadedClasses) return;
|
||||
BlockPosition = NMSUtil.getNMSClass("BlockPosition");
|
||||
PacketPlayOutOpenWindow = NMSUtil.getNMSClass("PacketPlayOutOpenWindow");
|
||||
ContainerAnvil = NMSUtil.getNMSClass("ContainerAnvil");
|
||||
EntityHuman = NMSUtil.getNMSClass("EntityHuman");
|
||||
ChatMessage = NMSUtil.getNMSClass("ChatMessage");
|
||||
loadedClasses = true;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public void setSlot(AnvilSlot slot, ItemStack item) {
|
||||
items.put(slot, item);
|
||||
}
|
||||
|
||||
public void open() {
|
||||
player.setLevel(player.getLevel() + 1);
|
||||
|
||||
try {
|
||||
Object craftPlayer = NMSUtil.getCraftClass("entity.CraftPlayer").cast(player);
|
||||
Method getHandleMethod = craftPlayer.getClass().getMethod("getHandle", new Class<?>[0]);
|
||||
Object entityPlayer = getHandleMethod.invoke(craftPlayer, new Object[0]);
|
||||
|
||||
Object container;
|
||||
|
||||
if (NMSUtil.getVersionNumber() == 7) {
|
||||
container = ContainerAnvil.getConstructor(new Class[]{NMSUtil.getNMSClass("PlayerInventory"), NMSUtil.getNMSClass("World"), Integer.TYPE, Integer.TYPE, Integer.TYPE, EntityHuman}).newInstance(new Object[]{NMSUtil.getFieldObject(entityPlayer, NMSUtil.getField(entityPlayer.getClass(), "inventory", false)), NMSUtil.getFieldObject(entityPlayer, NMSUtil.getField(entityPlayer.getClass(), "world", false)), Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0), entityPlayer});
|
||||
} else {
|
||||
container = ContainerAnvil.getConstructor(NMSUtil.getNMSClass("PlayerInventory"), NMSUtil.getNMSClass("World"), BlockPosition, EntityHuman).newInstance(NMSUtil.getFieldObject(entityPlayer, NMSUtil.getField(entityPlayer.getClass(), "inventory", false)), NMSUtil.getFieldObject(entityPlayer, NMSUtil.getField(entityPlayer.getClass(), "world", false)), BlockPosition.getConstructor(int.class, int.class, int.class).newInstance(0, 0, 0), entityPlayer);
|
||||
}
|
||||
|
||||
NMSUtil.getField(NMSUtil.getNMSClass("Container"), "checkReachable", true).set(container, false);
|
||||
|
||||
Method getBukkitViewMethod = container.getClass().getMethod("getBukkitView", new Class<?>[0]);
|
||||
Object bukkitView = getBukkitViewMethod.invoke(container);
|
||||
Method getTopInventoryMethod = bukkitView.getClass().getMethod("getTopInventory", new Class<?>[0]);
|
||||
inv = (Inventory) getTopInventoryMethod.invoke(bukkitView);
|
||||
|
||||
for (AnvilSlot slot : items.keySet()) {
|
||||
inv.setItem(slot.getSlot(), items.get(slot));
|
||||
}
|
||||
|
||||
Method nextContainerCounterMethod = entityPlayer.getClass().getMethod("nextContainerCounter", new Class<?>[0]);
|
||||
int c = (int) nextContainerCounterMethod.invoke(entityPlayer);
|
||||
|
||||
Constructor<?> chatMessageConstructor = ChatMessage.getConstructor(String.class, Object[].class);
|
||||
Object packet;
|
||||
|
||||
if (NMSUtil.getVersionNumber() == 7) {
|
||||
packet = PacketPlayOutOpenWindow.getConstructor(new Class[]{Integer.TYPE, Integer.TYPE, String.class, Integer.TYPE, Boolean.TYPE, Integer.TYPE}).newInstance(new Object[]{Integer.valueOf(c), Integer.valueOf(8), "Repairing", Integer.valueOf(0), Boolean.valueOf(true), Integer.valueOf(0)});
|
||||
} else {
|
||||
packet = PacketPlayOutOpenWindow.getConstructor(int.class, String.class, NMSUtil.getNMSClass("IChatBaseComponent"), int.class).newInstance(c, "minecraft:anvil", chatMessageConstructor.newInstance("Repairing", new Object[]{}), 0);
|
||||
}
|
||||
|
||||
NMSUtil.sendPacket(player, packet);
|
||||
|
||||
Field activeContainerField = NMSUtil.getField(EntityHuman, "activeContainer", true);
|
||||
|
||||
if (activeContainerField != null) {
|
||||
activeContainerField.set(entityPlayer, container);
|
||||
NMSUtil.getField(NMSUtil.getNMSClass("Container"), "windowId", true).set(activeContainerField.get(entityPlayer), c);
|
||||
|
||||
Method addSlotListenerMethod = activeContainerField.get(entityPlayer).getClass().getMethod("addSlotListener", NMSUtil.getNMSClass("ICrafting"));
|
||||
addSlotListenerMethod.invoke(activeContainerField.get(entityPlayer), entityPlayer);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
onClose = null;
|
||||
player = null;
|
||||
handler = null;
|
||||
items = null;
|
||||
|
||||
HandlerList.unregisterAll(listener);
|
||||
|
||||
listener = null;
|
||||
}
|
||||
|
||||
private OnClose getOnClose() {
|
||||
return onClose;
|
||||
}
|
||||
|
||||
public void setOnClose(OnClose onClose) {
|
||||
this.onClose = onClose;
|
||||
}
|
||||
|
||||
public void setCloseSound(Sound sound) {
|
||||
closeSound = sound;
|
||||
}
|
||||
|
||||
public enum AnvilSlot {
|
||||
INPUT_LEFT(0),
|
||||
INPUT_RIGHT(1),
|
||||
OUTPUT(2);
|
||||
|
||||
private int slot;
|
||||
|
||||
private AnvilSlot(int slot) {
|
||||
this.slot = slot;
|
||||
}
|
||||
|
||||
public static AnvilSlot bySlot(int slot) {
|
||||
for (AnvilSlot anvilSlot : values()) {
|
||||
if (anvilSlot.getSlot() == slot) {
|
||||
return anvilSlot;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getSlot() {
|
||||
return slot;
|
||||
}
|
||||
}
|
||||
|
||||
public interface AnvilClickEventHandler {
|
||||
void onAnvilClick(AnvilClickEvent event);
|
||||
}
|
||||
|
||||
public class AnvilClickEvent {
|
||||
private AnvilSlot slot;
|
||||
|
||||
private String name;
|
||||
|
||||
private boolean close = true;
|
||||
private boolean destroy = true;
|
||||
|
||||
public AnvilClickEvent(AnvilSlot slot, String name) {
|
||||
this.slot = slot;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public AnvilSlot getSlot() {
|
||||
return slot;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public boolean getWillClose() {
|
||||
return close;
|
||||
}
|
||||
|
||||
public void setWillClose(boolean close) {
|
||||
this.close = close;
|
||||
}
|
||||
|
||||
public boolean getWillDestroy() {
|
||||
return destroy;
|
||||
}
|
||||
|
||||
public void setWillDestroy(boolean destroy) {
|
||||
this.destroy = destroy;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,81 +1,41 @@
|
||||
package com.songoda.epicspawners.utils.gui;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.songoda.epicspawners.EpicSpawnersPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.*;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public abstract class AbstractGUI implements GUI {
|
||||
public abstract class AbstractGUI implements Listener {
|
||||
|
||||
private static boolean listenersInitialized = false;
|
||||
private final Inventory inventory;
|
||||
private final Clickable[] clickActions;
|
||||
private final Map<Range, Clickable> rangedClickActions = new HashMap<>();
|
||||
private boolean initialized = false;
|
||||
protected Player player;
|
||||
protected Inventory inventory = null;
|
||||
protected boolean cancelBottom = false;
|
||||
private Map<Range, Clickable> clickables = new HashMap<>();
|
||||
private List<OnClose> onCloses = new ArrayList<>();
|
||||
private Map<Range, Boolean> draggableRanges = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Construct a new GUI based on an {@link InventoryType}'s default size, as well
|
||||
* as a provided name
|
||||
*
|
||||
* @param type the type of inventory to create
|
||||
* @param inventoryName the name of the GUI
|
||||
*/
|
||||
protected AbstractGUI(InventoryType type, String inventoryName) {
|
||||
this.inventory = Bukkit.createInventory(new GUIHolder(), type, inventoryName);
|
||||
this.clickActions = new Clickable[inventory.getSize()];
|
||||
public AbstractGUI(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new Chest GUI with a particular size and a provided name
|
||||
*
|
||||
* @param size the size of the GUI to create (must be a multiple of 9)
|
||||
* @param inventoryName the name of the inventory
|
||||
*/
|
||||
protected AbstractGUI(int size, String inventoryName) {
|
||||
this.inventory = Bukkit.createInventory(new GUIHolder(), size, inventoryName);
|
||||
this.clickActions = new Clickable[inventory.getSize()];
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new GUI based on an {@link InventoryType}'s default size
|
||||
*
|
||||
* @param type the type of inventory to create
|
||||
*/
|
||||
protected AbstractGUI(InventoryType type) {
|
||||
this.inventory = Bukkit.createInventory(new GUIHolder(), type);
|
||||
this.clickActions = new Clickable[inventory.getSize()];
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new Chest GUI with a particular size
|
||||
*
|
||||
* @param size the size of the GUI to create (must be a multiple of 9)
|
||||
*/
|
||||
protected AbstractGUI(int size) {
|
||||
this.inventory = Bukkit.createInventory(new GUIHolder(), size);
|
||||
this.clickActions = new Clickable[inventory.getSize()];
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the GUI class and register its internal event listeners. This MUST be called before any
|
||||
* GUI functionality / implementations may be used. If this method has already been called and the
|
||||
* GUI API has been initialized, the call will fail silently
|
||||
*
|
||||
* @param plugin the plugin initializing the GUI listeners
|
||||
*/
|
||||
public static void initializeListeners(JavaPlugin plugin) {
|
||||
if (listenersInitialized) return;
|
||||
|
||||
@ -83,231 +43,175 @@ public abstract class AbstractGUI implements GUI {
|
||||
@EventHandler
|
||||
public void onClickGUI(InventoryClickEvent event) {
|
||||
Inventory inventory = event.getClickedInventory();
|
||||
AbstractGUI gui = (AbstractGUI) getGUIFromInventory(inventory);
|
||||
if (inventory == null) return;
|
||||
AbstractGUI gui = getGUIFromInventory(inventory);
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
|
||||
boolean bottom = false;
|
||||
|
||||
InventoryType type = event.getClickedInventory().getType();
|
||||
if (type != InventoryType.CHEST && type != InventoryType.PLAYER) return;
|
||||
|
||||
if (gui == null && event.getWhoClicked().getOpenInventory().getTopInventory() != null) {
|
||||
Inventory top = event.getWhoClicked().getOpenInventory().getTopInventory();
|
||||
gui = getGUIFromInventory(top);
|
||||
|
||||
if (gui != null && gui.cancelBottom) event.setCancelled(true);
|
||||
bottom = true;
|
||||
}
|
||||
|
||||
if (gui == null) return;
|
||||
|
||||
event.setCancelled(true);
|
||||
gui.invokeClickAction((Player) event.getWhoClicked(), inventory, event.getCursor(), event.getRawSlot(), event.getClick());
|
||||
}
|
||||
if (!bottom) event.setCancelled(true);
|
||||
|
||||
@EventHandler
|
||||
public void onOpenGUI(InventoryOpenEvent event) {
|
||||
Inventory inventory = event.getInventory();
|
||||
AbstractGUI gui = (AbstractGUI) getGUIFromInventory(inventory);
|
||||
if (gui == null) return;
|
||||
if (!gui.draggableRanges.isEmpty() && !bottom) {
|
||||
for (Map.Entry<Range, Boolean> entry : gui.draggableRanges.entrySet()) {
|
||||
Range range = entry.getKey();
|
||||
if (range.getMax() == range.getMin() && event.getSlot() == range.getMin()
|
||||
|| event.getSlot() >= range.getMin() && event.getSlot() <= range.getMax()) {
|
||||
event.setCancelled(!entry.getValue());
|
||||
if (!entry.getValue()) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Map<Range, Clickable> entries = new HashMap<>(gui.clickables);
|
||||
|
||||
gui.onGUIOpen((Player) event.getPlayer());
|
||||
for (Map.Entry<Range, Clickable> entry : entries.entrySet()) {
|
||||
Range range = entry.getKey();
|
||||
if (range.isBottom() && !bottom || !range.isBottom() && bottom || range.getClickType() != null && range.getClickType() != event.getClick())
|
||||
continue;
|
||||
if (event.getSlot() >= range.getMin() && event.getSlot() <= range.getMax()) {
|
||||
entry.getValue().Clickable(player, inventory, event.getCursor(), event.getSlot(), event.getClick());
|
||||
player.playSound(player.getLocation(), entry.getKey().getOnClickSound(), 1F, 1F);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onCloseGUI(InventoryCloseEvent event) {
|
||||
Inventory inventory = event.getInventory();
|
||||
AbstractGUI gui = (AbstractGUI) getGUIFromInventory(inventory);
|
||||
if (gui == null) return;
|
||||
AbstractGUI gui = getGUIFromInventory(inventory);
|
||||
|
||||
gui.onGUIClose((Player) event.getPlayer());
|
||||
if (gui == null || gui.inventory == null) return;
|
||||
|
||||
for (OnClose onClose : gui.onCloses) {
|
||||
onClose.OnClose((Player) event.getPlayer(), inventory);
|
||||
}
|
||||
}
|
||||
|
||||
private GUI getGUIFromInventory(Inventory inventory) {
|
||||
if (inventory == null) return null;
|
||||
|
||||
private AbstractGUI getGUIFromInventory(Inventory inventory) {
|
||||
if (inventory.getHolder() == null) return null;
|
||||
InventoryHolder holder = inventory.getHolder();
|
||||
if (!(holder instanceof GUIHolder)) return null;
|
||||
|
||||
return ((GUIHolder) holder).getGUI();
|
||||
return ((AbstractGUI.GUIHolder) holder).getGUI();
|
||||
}
|
||||
}, plugin);
|
||||
|
||||
listenersInitialized = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Inventory getInventory() {
|
||||
if (!initialized) {
|
||||
this.init();
|
||||
protected void init(String title, int slots) {
|
||||
if (inventory == null
|
||||
|| inventory.getSize() != slots
|
||||
|| ChatColor.translateAlternateColorCodes('&', title) != inventory.getTitle()) {
|
||||
this.inventory = Bukkit.getServer().createInventory(new GUIHolder(), slots, ChatColor.translateAlternateColorCodes('&', title));
|
||||
registerClickables();
|
||||
registerOnCloses();
|
||||
}
|
||||
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void openFor(Player player) {
|
||||
Preconditions.checkNotNull(player, "Cannot open inventory for null player");
|
||||
|
||||
if (!initialized) {
|
||||
this.init();
|
||||
}
|
||||
|
||||
constructGUI();
|
||||
initializeListeners(EpicSpawnersPlugin.getInstance());
|
||||
player.openInventory(inventory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean hasClickAction(int slot) {
|
||||
if (!initialized) {
|
||||
this.init();
|
||||
protected abstract void constructGUI();
|
||||
|
||||
protected void addDraggable(Range range, boolean option) {
|
||||
this.draggableRanges.put(range, option);
|
||||
}
|
||||
|
||||
protected void removeDraggable() {
|
||||
this.draggableRanges.clear();
|
||||
}
|
||||
|
||||
protected abstract void registerClickables();
|
||||
|
||||
protected abstract void registerOnCloses();
|
||||
|
||||
protected ItemStack createButton(int slot, Inventory inventory, ItemStack item, String name, String... lore) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
|
||||
if (lore != null && lore.length != 0) {
|
||||
List<String> newLore = new ArrayList<>();
|
||||
for (String line : lore) newLore.add(ChatColor.translateAlternateColorCodes('&', line));
|
||||
meta.setLore(newLore);
|
||||
}
|
||||
|
||||
return slot >= 0 && slot < inventory.getSize() && clickActions[slot] != null;
|
||||
item.setItemMeta(meta);
|
||||
inventory.setItem(slot, item);
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
Arrays.setAll(clickActions, null);
|
||||
this.rangedClickActions.clear();
|
||||
this.inventory.getViewers().forEach(HumanEntity::closeInventory);
|
||||
protected ItemStack createButton(int slot, ItemStack item, String name, String... lore) {
|
||||
return createButton(slot, inventory, item, name, lore);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a new {@link Clickable} action for the provided slot
|
||||
*
|
||||
* @param slot the slot at which a clickable action should be registered
|
||||
* @param action the action to register
|
||||
*/
|
||||
protected final void registerClickableObject(int slot, Clickable action) {
|
||||
Preconditions.checkArgument(slot >= 0 || slot < inventory.getSize(), "Action slots must be between 0 and %s", inventory.getSize());
|
||||
Preconditions.checkNotNull(action, "Cannot reigster a null action");
|
||||
|
||||
this.clickActions[slot] = action;
|
||||
protected ItemStack createButton(int slot, Inventory inventory, Material material, String name, String... lore) {
|
||||
return createButton(slot, inventory, new ItemStack(material), name, lore);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a new {@link Clickable} action for the provided range. If the
|
||||
* range overlaps that of an existing range or either bounds of the range exceed
|
||||
* the size of the inventory, an exception will be thrown. Additionally, for any
|
||||
* actions registered for an individual slot within the registered range, they
|
||||
* will be removed and replaced with the action registered in this range.
|
||||
*
|
||||
* @param from the beginning of the range (inclusive). Must be less than "to"
|
||||
* @param to the end of the range (inclusive). Must be greater than "from"
|
||||
* @param action the action to register
|
||||
*/
|
||||
protected final void registerClickableRange(int from, int to, Clickable action) {
|
||||
Preconditions.checkArgument(from >= 0 && from < inventory.getSize(), "Action slots must be between 0 and %s", inventory.getSize());
|
||||
Preconditions.checkArgument(to >= 0 && to < inventory.getSize(), "Action slots must be between 0 and %s", inventory.getSize());
|
||||
Preconditions.checkArgument(from < to, "From must be less than to");
|
||||
Preconditions.checkNotNull(action, "Cannot register a null action");
|
||||
|
||||
for (Range range : rangedClickActions.keySet()) {
|
||||
if (range.isWithin(from) || range.isWithin(to)) {
|
||||
throw new IllegalStateException("Range overlaps that of another range (Existing range: " + range.getLow() + " - " + range.getHigh() + ")");
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = from; i < to; i++) {
|
||||
this.clickActions[i] = null;
|
||||
}
|
||||
|
||||
this.rangedClickActions.put(Range.from(from, to), action);
|
||||
protected ItemStack createButton(int slot, Material material, String name, String... lore) {
|
||||
return createButton(slot, inventory, new ItemStack(material), name, lore);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an action from the specified slot. This does not affect ranged actions
|
||||
*
|
||||
* @param slot the slot to remove the action from
|
||||
*/
|
||||
protected final void removeActionFrom(int slot) {
|
||||
Preconditions.checkArgument(slot >= 0 || slot < inventory.getSize(), "Cannot remove action from invalid slot. Must be between 0 and %s", inventory.getSize());
|
||||
this.clickActions[slot] = null;
|
||||
protected ItemStack createButton(int slot, Material material, String name, ArrayList<String> lore) {
|
||||
return createButton(slot, material, name, lore.toArray(new String[0]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a ranged action such that it includes the specified slot
|
||||
*
|
||||
* @param slot the slot within the range for which to remove the action from
|
||||
* @return true if successful, false if no changes were made
|
||||
*/
|
||||
protected final boolean removeRangedActionForSlot(int slot) {
|
||||
Preconditions.checkArgument(slot >= 0 || slot < inventory.getSize(), "Cannot remove action from invalid slot. Must be between 0 and %s", inventory.getSize());
|
||||
|
||||
Iterator<Range> ranges = rangedClickActions.keySet().iterator();
|
||||
while (ranges.hasNext()) {
|
||||
Range range = ranges.next();
|
||||
if (range.isWithin(slot)) {
|
||||
ranges.remove();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
protected void registerClickable(int min, int max, ClickType clickType, boolean bottom, Clickable clickable) {
|
||||
clickables.put(new Range(min, max, clickType, bottom), clickable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the inventory's items. It is from here that the GUI's inventory should have ItemStacks added
|
||||
*
|
||||
* @param inventory the GUI's underlying inventory
|
||||
*/
|
||||
protected abstract void initInventoryItems(Inventory inventory);
|
||||
|
||||
/**
|
||||
* Initialize the inventory's clickable objects. It is from here that {@link #registerClickableObject(int, Clickable)}
|
||||
* should be called in GUI implementations
|
||||
*/
|
||||
protected abstract void initClickableObjects();
|
||||
|
||||
/**
|
||||
* Called the moment before the GUI has been opened by a player
|
||||
*
|
||||
* @param player the player opening the GUI
|
||||
*/
|
||||
protected void onGUIOpen(Player player) {
|
||||
protected void registerClickable(int min, int max, ClickType clickType, Clickable clickable) {
|
||||
registerClickable(min, max, clickType, false, clickable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called the moment before the GUI has been closed by the player
|
||||
*
|
||||
* @param player the player closing the GUI
|
||||
*/
|
||||
protected void onGUIClose(Player player) {
|
||||
protected void registerClickable(int slot, ClickType clickType, Clickable clickable) {
|
||||
registerClickable(slot, slot, clickType, false, clickable);
|
||||
}
|
||||
|
||||
private void init() {
|
||||
Preconditions.checkArgument(listenersInitialized, "The GUI class has not yet been initialized. Invoke GUI#initializeListeners(JavaPlugin)");
|
||||
Preconditions.checkArgument(!initialized, "This GUI has already been initialized");
|
||||
|
||||
this.initInventoryItems(inventory);
|
||||
this.initClickableObjects();
|
||||
this.initialized = true;
|
||||
protected void registerClickable(int min, int max, Clickable clickable) {
|
||||
registerClickable(min, max, null, false, clickable);
|
||||
}
|
||||
|
||||
private boolean invokeClickAction(Player player, Inventory inventory, ItemStack cursor, int slot, ClickType type) {
|
||||
Preconditions.checkNotNull(player, "A null player cannot click the inventory");
|
||||
Preconditions.checkNotNull(inventory, "A null inventory cannot be clicked");
|
||||
Preconditions.checkArgument(slot >= 0 && slot < inventory.getSize(), "The slot exceeds the size limitations of the inventory (0 - %s)", inventory.getSize());
|
||||
Preconditions.checkNotNull(type, "A null click type cannot be performed");
|
||||
|
||||
Clickable action = clickActions[slot];
|
||||
if (action == null) {
|
||||
for (Entry<Range, Clickable> rangedAction : rangedClickActions.entrySet()) {
|
||||
if (!rangedAction.getKey().isWithin(slot)) continue;
|
||||
action = rangedAction.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
if (action == null) return false; // If still no action, just give up
|
||||
|
||||
action.click(player, inventory, cursor, slot, type);
|
||||
return true;
|
||||
protected void registerClickable(int slot, boolean bottom, Clickable clickable) {
|
||||
registerClickable(slot, slot, null, bottom, clickable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents an InventoryHolder implementation for GUIs
|
||||
*/
|
||||
private class GUIHolder implements InventoryHolder {
|
||||
protected void registerClickable(int slot, Clickable clickable) {
|
||||
registerClickable(slot, slot, null, false, clickable);
|
||||
}
|
||||
|
||||
protected void resetClickables() {
|
||||
clickables.clear();
|
||||
}
|
||||
|
||||
protected void registerOnClose(OnClose onClose) {
|
||||
onCloses.add(onClose);
|
||||
}
|
||||
|
||||
public Inventory getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
public class GUIHolder implements InventoryHolder {
|
||||
|
||||
@Override
|
||||
public Inventory getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the GUI instance associated with this holder
|
||||
*
|
||||
* @return the associated GUI
|
||||
*/
|
||||
public GUI getGUI() {
|
||||
public AbstractGUI getGUI() {
|
||||
return AbstractGUI.this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -5,21 +5,7 @@ import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
* Represents an action to be called upon clicking an object in the slot of a GUI.
|
||||
*/
|
||||
public interface Clickable {
|
||||
|
||||
/**
|
||||
* Called when a GUI has been clicked. Whether the ItemStack at the slot clicked
|
||||
* is null or not will not affect the result of this method.
|
||||
*
|
||||
* @param player the player who performed the click
|
||||
* @param inventory the inventory in which was clicked (the GUI's inventory)
|
||||
* @param cursor the ItemStack on the player's cursor. May be null
|
||||
* @param slot the clicked inventory slot
|
||||
* @param type the type of click performed
|
||||
*/
|
||||
public void click(Player player, Inventory inventory, ItemStack cursor, int slot, ClickType type);
|
||||
|
||||
}
|
||||
void Clickable(Player player, Inventory inventory, ItemStack cursor, int slot, ClickType type);
|
||||
}
|
||||
|
@ -1,36 +0,0 @@
|
||||
package com.songoda.epicspawners.utils.gui;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
public interface GUI {
|
||||
|
||||
/**
|
||||
* Get this GUI's underlying Bukkit {@link Inventory}
|
||||
*
|
||||
* @return the Bukkit Inventory instance
|
||||
*/
|
||||
public Inventory getInventory();
|
||||
|
||||
/**
|
||||
* Open this GUI for the specified player
|
||||
*
|
||||
* @param player the player for whom to open the GUI
|
||||
*/
|
||||
public void openFor(Player player);
|
||||
|
||||
/**
|
||||
* Check whether the specified slot has an associated click action or not
|
||||
*
|
||||
* @param slot the slot to check
|
||||
* @return true if click action is present, false otherwise
|
||||
*/
|
||||
public boolean hasClickAction(int slot);
|
||||
|
||||
/**
|
||||
* Dispose of this GUI. Click actions will no longer be recognized and
|
||||
* any players viewing the GUI will be booted from viewing.
|
||||
*/
|
||||
public void dispose();
|
||||
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package com.songoda.epicspawners.utils.gui;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
public interface OnClose {
|
||||
|
||||
void OnClose(Player player, Inventory inventory);
|
||||
|
||||
}
|
@ -1,52 +1,48 @@
|
||||
package com.songoda.epicspawners.utils.gui;
|
||||
|
||||
public final class Range {
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
|
||||
private final int low, high;
|
||||
public class Range {
|
||||
|
||||
private Range(int low, int high) {
|
||||
this.low = low;
|
||||
this.high = high;
|
||||
private int min;
|
||||
private int max;
|
||||
private ClickType clickType;
|
||||
private boolean bottom;
|
||||
private Sound onClickSound = Sound.UI_BUTTON_CLICK;
|
||||
|
||||
public Range(int min, int max, ClickType clickType, boolean bottom) {
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
this.clickType = clickType;
|
||||
this.bottom = bottom;
|
||||
}
|
||||
|
||||
public static Range from(int from, int to) {
|
||||
return new Range(from, to);
|
||||
public Range(int min, int max, Sound onClickSound, ClickType clickType, boolean bottom) {
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
this.onClickSound = onClickSound;
|
||||
this.clickType = clickType;
|
||||
this.bottom = bottom;
|
||||
}
|
||||
|
||||
public int getLow() {
|
||||
return low;
|
||||
public int getMin() {
|
||||
return min;
|
||||
}
|
||||
|
||||
public int getHigh() {
|
||||
return high;
|
||||
public int getMax() {
|
||||
return max;
|
||||
}
|
||||
|
||||
public boolean isWithin(int value) {
|
||||
return value >= low && value <= high;
|
||||
public ClickType getClickType() {
|
||||
return clickType;
|
||||
}
|
||||
|
||||
public boolean isWithin(double value) {
|
||||
return value >= low && value <= high;
|
||||
public boolean isBottom() {
|
||||
return bottom;
|
||||
}
|
||||
|
||||
public boolean isWithin(float value) {
|
||||
return value >= low && value <= high;
|
||||
public Sound getOnClickSound() {
|
||||
return onClickSound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = 31 * Integer.hashCode(low);
|
||||
result += 31 * result + Integer.hashCode(high);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
if (object == this) return true;
|
||||
if (!(object instanceof Range)) return false;
|
||||
|
||||
Range other = (Range) object;
|
||||
return low == other.low && high == other.high;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,100 @@
|
||||
package com.songoda.epicspawners.utils.version;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class NMSUtil {
|
||||
|
||||
public static String getVersion() {
|
||||
String name = Bukkit.getServer().getClass().getPackage().getName();
|
||||
return name.substring(name.lastIndexOf('.') + 1) + ".";
|
||||
}
|
||||
|
||||
public static int getVersionNumber() {
|
||||
String name = getVersion().substring(3);
|
||||
return Integer.valueOf(name.substring(0, name.length() - 4));
|
||||
}
|
||||
|
||||
public static int getVersionReleaseNumber() {
|
||||
String NMSVersion = getVersion();
|
||||
return Integer.valueOf(NMSVersion.substring(NMSVersion.length() - 2).replace(".", ""));
|
||||
}
|
||||
|
||||
public static Class<?> getNMSClass(String className) {
|
||||
try {
|
||||
String fullName = "net.minecraft.server." + getVersion() + className;
|
||||
Class<?> clazz = Class.forName(fullName);
|
||||
return clazz;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Class<?> getCraftClass(String className) throws ClassNotFoundException {
|
||||
try {
|
||||
String fullName = "org.bukkit.craftbukkit." + getVersion() + className;
|
||||
Class<?> clazz = Class.forName(fullName);
|
||||
return clazz;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Field getField(Class<?> clazz, String name, boolean declared) {
|
||||
try {
|
||||
Field field;
|
||||
|
||||
if (declared) {
|
||||
field = clazz.getDeclaredField(name);
|
||||
} else {
|
||||
field = clazz.getField(name);
|
||||
}
|
||||
|
||||
field.setAccessible(true);
|
||||
return field;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Object getFieldObject(Object object, Field field) {
|
||||
try {
|
||||
return field.get(object);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void setField(Object object, String fieldName, Object fieldValue, boolean declared) {
|
||||
try {
|
||||
Field field;
|
||||
|
||||
if (declared) {
|
||||
field = object.getClass().getDeclaredField(fieldName);
|
||||
} else {
|
||||
field = object.getClass().getField(fieldName);
|
||||
}
|
||||
|
||||
field.setAccessible(true);
|
||||
field.set(object, fieldValue);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendPacket(Player player, Object packet) {
|
||||
try {
|
||||
Object handle = player.getClass().getMethod("getHandle").invoke(player);
|
||||
Object playerConnection = handle.getClass().getField("playerConnection").get(handle);
|
||||
playerConnection.getClass().getMethod("sendPacket", getNMSClass("Packet")).invoke(playerConnection, packet);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -37,7 +37,6 @@ interface.shop.remove10 = "&c&lRemove 10"
|
||||
interface.spawnerstats.title = "&5&lSpawnerStats"
|
||||
interface.spawnerstats.prefix = "&7Your current spawner stats:"
|
||||
interface.spawnerstats.nokills = "&7You currently have no mob kills. Go kill something!"
|
||||
interface.spawnerstats.ongoal = "&7Once you obtain enough &7kills, a Monster Spawner will drop."
|
||||
interface.boost.title = "&cBoosting %spawner% &cby %amount%"
|
||||
interface.boost.boostfor = "&7&lBoost for &6&l%amount% &7&lMinutes"
|
||||
|
||||
@ -73,6 +72,7 @@ event.omni.cannotmerge = "&cYou can't merge two OmniSpawners."
|
||||
event.omni.combinefail = "&cThe omni spawner refuses to absorb any more spawners of that type."
|
||||
event.omni.combinesuccess = "&7Your spawner was absorbed into the OmniSpawner."
|
||||
event.omni.takespawner = "&7You took a &6%type%&7 from the OmniSpawner."
|
||||
event.convert.success = "&9Your conversion was successful."
|
||||
event.convert.success = "&7Your conversion was successful."
|
||||
event.boost.applied = "&6Your boost has been applied."
|
||||
event.combine.onlyone = "&cYou can only combine one spawner at a time."
|
||||
event.combine.onlyone = "&cYou can only combine one spawner at a time."
|
||||
event.spawner.toomany = "&cYou can only place %amount% spawners..."
|
@ -2,7 +2,7 @@ name: EpicSpawners
|
||||
description: EpicSpawners
|
||||
version: maven-version-number
|
||||
depend: [Arconix, Vault]
|
||||
softdepend: [Towny, RedProtect Kingdoms, PlotSquared, GriefPrevention, USkyBlock, ASkyBlock, WorldGuard, Factions, PlaceholderAPI]
|
||||
softdepend: [SkyBlock, Towny, RedProtect Kingdoms, PlotSquared, GriefPrevention, USkyBlock, ASkyBlock, WorldGuard, Factions, PlaceholderAPI]
|
||||
main: com.songoda.epicspawners.EpicSpawnersPlugin
|
||||
author: songoda
|
||||
api-version: 1.13
|
||||
|
Loading…
Reference in New Issue
Block a user