Merged Master into Legacy. & Overhauled SettingsManager

This commit is contained in:
Brianna 2019-05-23 16:15:04 -04:00
parent ae6fa4b3b7
commit 09d364a95c
22 changed files with 632 additions and 388 deletions

View File

@ -5,7 +5,7 @@ variables:
name: "UltimateStacker"
suffex: "Legacy"
path: "/builds/$CI_PROJECT_PATH"
version: "1.2.3"
version: "1.2.4"
build:
stage: build

View File

@ -66,7 +66,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.12.2</version>
<version>1.14.1</version>
</dependency>
<dependency>
<groupId>com.songoda</groupId>

View File

@ -3,7 +3,7 @@ package com.songoda.ultimatestacker;
import com.songoda.ultimatestacker.command.CommandManager;
import com.songoda.ultimatestacker.entity.EntityStack;
import com.songoda.ultimatestacker.entity.EntityStackManager;
import com.songoda.ultimatestacker.events.*;
import com.songoda.ultimatestacker.listeners.*;
import com.songoda.ultimatestacker.hologram.Hologram;
import com.songoda.ultimatestacker.hologram.HologramHolographicDisplays;
import com.songoda.ultimatestacker.spawner.SpawnerStack;
@ -14,6 +14,7 @@ import com.songoda.ultimatestacker.storage.types.StorageMysql;
import com.songoda.ultimatestacker.storage.types.StorageYaml;
import com.songoda.ultimatestacker.tasks.StackingTask;
import com.songoda.ultimatestacker.utils.*;
import com.songoda.ultimatestacker.utils.settings.SettingsManager;
import org.apache.commons.lang.ArrayUtils;
import com.songoda.ultimatestacker.utils.updateModules.LocaleModule;
import com.songoda.update.Plugin;
@ -63,38 +64,19 @@ public class UltimateStacker extends JavaPlugin {
console.sendMessage(Methods.formatText("&a============================="));
}
private boolean checkVersion() {
int maxVersion = 12; // also supports 1.8 and higher
int currentVersion = Integer.parseInt(Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3].split("_")[1]);
if (currentVersion > maxVersion) {
Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> {
Bukkit.getConsoleSender().sendMessage("");
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "You installed the legacy (1.8 - 1.12) only version of " + this.getDescription().getName() + " on a 1." + currentVersion + " server. Since you are on the wrong version we disabled the plugin for you. Please install correct version to continue using " + this.getDescription().getName() + ".");
Bukkit.getConsoleSender().sendMessage("");
}, 20L);
return false;
}
return true;
}
@Override
public void onEnable() {
INSTANCE = this;
// Check to make sure the Bukkit version is compatible.
if (!checkVersion()) return;
ConsoleCommandSender console = Bukkit.getConsoleSender();
console.sendMessage(Methods.formatText("&a============================="));
console.sendMessage(Methods.formatText("&7UltimateStacker " + this.getDescription().getVersion() + " by &5Songoda <3&7!"));
console.sendMessage(Methods.formatText("&7Action: &aEnabling&7..."));
this.settingsManager = new SettingsManager(this);
this.commandManager = new CommandManager(this);
this.settingsManager.setupConfig();
settingsManager.updateSettings();
this.commandManager = new CommandManager(this);
for (EntityType value : EntityType.values()) {
if (value.isSpawnable() && value.isAlive() && !value.toString().contains("ARMOR")) {
@ -123,9 +105,6 @@ public class UltimateStacker extends JavaPlugin {
spawnerFile.getConfig().options().copyDefaults(true);
spawnerFile.saveConfig();
getConfig().options().copyDefaults(true);
saveConfig();
String langMode = getConfig().getString("System.Language Mode");
Locale.init(this);
Locale.saveDefaultLocale("en_US");
@ -183,7 +162,6 @@ public class UltimateStacker extends JavaPlugin {
PluginManager pluginManager = Bukkit.getPluginManager();
if (isServerVersionAtLeast(ServerVersion.V1_10))
Bukkit.getPluginManager().registerEvents(new BreedListeners(this), this);
Bukkit.getPluginManager().registerEvents(new SpawnerListeners(this), this);
Bukkit.getPluginManager().registerEvents(new BlockListeners(this), this);
Bukkit.getPluginManager().registerEvents(new DeathListeners(this), this);
Bukkit.getPluginManager().registerEvents(new ShearListeners(this), this);
@ -221,7 +199,6 @@ public class UltimateStacker extends JavaPlugin {
}
public void reload() {
settingsManager.updateSettings();
String langMode = getConfig().getString("System.Language Mode");
this.locale = Locale.getLocale(getConfig().getString("System.Language Mode", langMode));
this.locale.reloadMessages();
@ -229,7 +206,7 @@ public class UltimateStacker extends JavaPlugin {
this.itemFile = new ConfigWrapper(this, "", "items.yml");
this.spawnerFile = new ConfigWrapper(this, "", "spawners.yml");
this.references = new References();
this.reloadConfig();
this.settingsManager.reloadConfig();
}
public boolean spawnersEnabled() {

View File

@ -2,8 +2,8 @@ package com.songoda.ultimatestacker.entity;
import com.songoda.ultimatestacker.UltimateStacker;
import com.songoda.ultimatestacker.utils.Methods;
import com.songoda.ultimatestacker.utils.SettingsManager;
import com.songoda.ultimatestacker.utils.ServerVersion;
import com.songoda.ultimatestacker.utils.settings.Setting;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Entity;
@ -28,7 +28,7 @@ public class EntityStack {
Entity entity = getEntityByUniqueId(this.entity);
if (entity == null) return;
entity.setCustomNameVisible(!SettingsManager.Settings.HOLOGRAMS_ON_LOOK_ENTITY.getBoolean());
entity.setCustomNameVisible(!Setting.HOLOGRAMS_ON_LOOK_ENTITY.getBoolean());
entity.setCustomName(Methods.compileEntityName(entity, amount));
}

View File

@ -1,64 +0,0 @@
package com.songoda.ultimatestacker.events;
import com.songoda.ultimatestacker.UltimateStacker;
import com.songoda.ultimatestacker.entity.EntityStack;
import com.songoda.ultimatestacker.utils.Methods;
import org.bukkit.entity.Entity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.SpawnerSpawnEvent;
import java.util.List;
public class SpawnerListeners implements Listener {
private UltimateStacker instance;
public SpawnerListeners(UltimateStacker instance) {
this.instance = instance;
}
@EventHandler
public void onSpawner(SpawnerSpawnEvent event) {
/*
Entity initalEntity = event.getEntity();
if (!instance.getConfig().getBoolean("Main.Stack Entities")) return;
List<Entity> entityList = Methods.getSimilarEntitesAroundEntity(initalEntity);
if (entityList.size() == 0) return;
int maxEntityStackSize = instance.getConfig().getInt("Entity.Max Stack Size");
if (instance.getConfig().getInt("Mobs." + initalEntity.getType().name() + ".Max Stack Size") != -1)
maxEntityStackSize = instance.getConfig().getInt("Mobs." + initalEntity.getType().name() + ".Max Stack Size");
for (Entity entity : entityList) {
EntityStack stack = instance.getEntityStackManager().getStack(entity);
//If a stack was found add 1 to this stack.
if (stack != null && stack.getAmount() < maxEntityStackSize) {
stack.addAmount(1);
stack.updateStack();
initalEntity.remove();
event.setCancelled(true);
return;
}
}
Bukkit.broadcastMessage(entityList.size() + 1 + "");
if ((entityList.size() + 1) >= instance.getConfig().getInt("Entity.Min Stack Amount")) {
EntityStack stack = instance.getEntityStackManager().addStack(new EntityStack(initalEntity, entityList.size() + 1));
stack.updateStack();
for (Entity entity : entityList) {
entity.remove();
}
entityList.size();
}
*/
}
}

View File

@ -3,6 +3,7 @@ package com.songoda.ultimatestacker.hologram;
import com.songoda.ultimatestacker.UltimateStacker;
import com.songoda.ultimatestacker.spawner.SpawnerStack;
import com.songoda.ultimatestacker.utils.Methods;
import com.songoda.ultimatestacker.utils.ServerVersion;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@ -41,7 +42,7 @@ public abstract class Hologram {
public void add(SpawnerStack spawner) {
int amount = spawner.getAmount();
if (spawner.getLocation().getBlock().getType() != Material.MOB_SPAWNER) return;
if (spawner.getLocation().getBlock().getType() != (instance.isServerVersion(ServerVersion.V1_13) ? Material.SPAWNER : Material.valueOf("MOB_SPAWNER"))) return;
CreatureSpawner creatureSpawner = (CreatureSpawner) spawner.getLocation().getBlock().getState();
String name = Methods.compileSpawnerName(creatureSpawner.getSpawnedType(), amount);
@ -55,7 +56,7 @@ public abstract class Hologram {
public void update(SpawnerStack spawner) {
int amount = spawner.getAmount();
if (spawner.getLocation().getBlock().getType() != Material.MOB_SPAWNER) return;
if (spawner.getLocation().getBlock().getType() != (instance.isServerVersion(ServerVersion.V1_13) ? Material.SPAWNER : Material.valueOf("MOB_SPAWNER"))) return;
CreatureSpawner creatureSpawner = (CreatureSpawner) spawner.getLocation().getBlock().getState();
String name = Methods.compileSpawnerName(creatureSpawner.getSpawnedType(), amount);
@ -70,7 +71,7 @@ public abstract class Hologram {
protected abstract void update(Location location, String line);
public void processChange(Block block) {
if (block.getType() != Material.MOB_SPAWNER) return;
if (block.getType() != (instance.isServerVersion(ServerVersion.V1_13) ? Material.SPAWNER : Material.valueOf("MOB_SPAWNER"))) return;
SpawnerStack spawner = instance.getSpawnerStackManager().getSpawner(block);
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(instance, () ->

View File

@ -1,14 +1,13 @@
package com.songoda.ultimatestacker.events;
package com.songoda.ultimatestacker.listeners;
import com.songoda.ultimatestacker.UltimateStacker;
import com.songoda.ultimatestacker.entity.EntityStackManager;
import com.songoda.ultimatestacker.spawner.SpawnerStack;
import com.songoda.ultimatestacker.utils.Methods;
import com.songoda.ultimatestacker.utils.SettingsManager;
import com.songoda.ultimatestacker.utils.ServerVersion;
import com.songoda.ultimatestacker.utils.settings.Setting;
import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.CreatureSpawner;
import org.bukkit.enchantments.Enchantment;
@ -40,9 +39,9 @@ public class BlockListeners implements Listener {
Player player = event.getPlayer();
ItemStack item = event.getPlayer().getInventory().getItemInHand();
if (block == null || item == null || block.getType() != Material.MOB_SPAWNER || item.getType() != Material.MOB_SPAWNER || event.getAction() == Action.LEFT_CLICK_BLOCK) return;
if (block == null || block.getType() != (instance.isServerVersion(ServerVersion.V1_13) ? Material.SPAWNER : Material.valueOf("MOB_SPAWNER")) || item.getType() != (instance.isServerVersion(ServerVersion.V1_13) ? Material.SPAWNER : Material.valueOf("MOB_SPAWNER")) || event.getAction() == Action.LEFT_CLICK_BLOCK) return;
List<String> disabledWorlds = SettingsManager.Settings.DISABLED_WORLDS.getStringList();
List<String> disabledWorlds = Setting.DISABLED_WORLDS.getStringList();
if (disabledWorlds.stream().anyMatch(worldStr -> event.getPlayer().getWorld().getName().equalsIgnoreCase(worldStr))) return;
if (!instance.spawnersEnabled()) return;
@ -54,7 +53,7 @@ public class BlockListeners implements Listener {
int itemAmount = getSpawnerAmount(item);
int specific = instance.getSpawnerFile().getConfig().getInt("Spawners." + cs.getSpawnedType().name() + ".Max Stack Size");
int maxStackSize = specific == -1 ? instance.getConfig().getInt("Spawners.Max Stack Size") : specific;
int maxStackSize = specific == -1 ? Setting.MAX_STACK_SPAWNERS.getInt() : specific;
cs = (CreatureSpawner) block.getState();
@ -96,7 +95,7 @@ public class BlockListeners implements Listener {
if (!event.isCancelled()) {
if (block == null
|| block.getType() != Material.MOB_SPAWNER
|| block.getType() != (instance.isServerVersion(ServerVersion.V1_13) ? Material.SPAWNER : Material.valueOf("MOB_SPAWNER"))
|| !instance.spawnersEnabled())
return;
@ -118,7 +117,7 @@ public class BlockListeners implements Listener {
@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockBreak(BlockBreakEvent event) {
Block block = event.getBlock();
if (block.getType() != Material.MOB_SPAWNER) return;
if (block.getType() != (instance.isServerVersion(ServerVersion.V1_13) ? Material.SPAWNER : Material.valueOf("MOB_SPAWNER"))) return;
if (!instance.spawnersEnabled()) return;
event.setExpToDrop(0);

View File

@ -1,4 +1,4 @@
package com.songoda.ultimatestacker.events;
package com.songoda.ultimatestacker.listeners;
import com.songoda.ultimatestacker.UltimateStacker;
import org.bukkit.Bukkit;

View File

@ -1,15 +1,10 @@
package com.songoda.ultimatestacker.events;
package com.songoda.ultimatestacker.listeners;
import com.songoda.ultimatestacker.UltimateStacker;
import com.songoda.ultimatestacker.entity.EntityStack;
import com.songoda.ultimatestacker.entity.EntityStackManager;
import com.songoda.ultimatestacker.utils.Methods;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import java.util.ArrayList;

View File

@ -1,10 +1,11 @@
package com.songoda.ultimatestacker.events;
package com.songoda.ultimatestacker.listeners;
import com.songoda.ultimatestacker.UltimateStacker;
import com.songoda.ultimatestacker.entity.EntityStack;
import com.songoda.ultimatestacker.entity.EntityStackManager;
import com.songoda.ultimatestacker.spawner.SpawnerStack;
import com.songoda.ultimatestacker.utils.Methods;
import com.songoda.ultimatestacker.utils.ServerVersion;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
@ -14,7 +15,6 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityPickupItemEvent;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.inventory.ItemStack;
@ -41,7 +41,7 @@ public class EntityListeners implements Listener {
List<Block> destroyed = event.blockList();
for (Block block : destroyed) {
if (block.getType() != Material.MOB_SPAWNER) continue;
if (block.getType() != (instance.isServerVersion(ServerVersion.V1_13) ? Material.SPAWNER : Material.valueOf("MOB_SPAWNER"))) continue;
Location spawnerLocation = block.getLocation();
SpawnerStack stack = instance.getSpawnerStackManager().getSpawner(spawnerLocation);

View File

@ -1,25 +1,19 @@
package com.songoda.ultimatestacker.events;
package com.songoda.ultimatestacker.listeners;
import com.songoda.ultimatestacker.UltimateStacker;
import com.songoda.ultimatestacker.entity.EntityStack;
import com.songoda.ultimatestacker.utils.ServerVersion;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityBreedEvent;
import org.bukkit.event.entity.EntityPickupItemEvent;
import org.bukkit.event.entity.SheepDyeWoolEvent;
import org.bukkit.event.inventory.InventoryPickupItemEvent;
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.util.Vector;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;
public class InteractListeners implements Listener {
@ -117,42 +111,58 @@ public class InteractListeners implements Listener {
}
private boolean correctFood(ItemStack is, Entity entity) {
boolean is13 = instance.isServerVersionAtLeast(ServerVersion.V1_13);
Material type = is.getType();
switch (entity.getType()) {
case COW:
case SHEEP:
switch (entity.getType().name()) {
case "COW":
case "SHEEP":
return type == Material.WHEAT;
case PIG:
return (type == Material.CARROT || type == Material.BEETROOT || type == Material.POTATO);
case CHICKEN:
return type == Material.SEEDS
case "PIG":
return type == Material.CARROT || type == Material.BEETROOT || type == Material.POTATO;
case "CHICKEN":
return type == (is13 ? Material.WHEAT_SEEDS : Material.valueOf("SEEDS"))
|| type == Material.MELON_SEEDS
|| type == Material.BEETROOT_SEEDS
|| type == Material.PUMPKIN_SEEDS;
case HORSE:
case "HORSE":
return (type == Material.GOLDEN_APPLE || type == Material.GOLDEN_CARROT) && ((Horse)entity).isTamed();
case WOLF:
return (type == Material.RAW_BEEF
|| type == Material.RAW_CHICKEN
case "WOLF":
return type == (is13 ? Material.BEEF : Material.valueOf("RAW_BEEF"))
|| type == (is13 ? Material.CHICKEN : Material.valueOf("RAW_CHICKEN"))
|| (is13 && type == Material.COD)
|| type == Material.MUTTON
|| type == Material.PORK
|| type == (is13 ? Material.PORKCHOP : Material.valueOf("PORK"))
|| type == Material.RABBIT
|| type == Material.RAW_FISH
|| (is13 && type == Material.SALMON)
|| type == Material.COOKED_BEEF
|| type == Material.COOKED_CHICKEN
|| (is13 && type == Material.COOKED_COD)
|| type == Material.COOKED_MUTTON
|| type == Material.GRILLED_PORK
|| type == (is13 ? Material.COOKED_PORKCHOP : Material.valueOf("GRILLED_PORK"))
|| type == Material.COOKED_RABBIT
|| type == Material.COOKED_FISH)
|| (is13 && type == Material.COOKED_SALMON)
&& ((Wolf) entity).isTamed();
case OCELOT:
return (type == Material.RAW_FISH)
&& ((Ocelot) entity).isTamed();
case RABBIT:
return type == Material.CARROT || type == Material.GOLDEN_CARROT || type == Material.YELLOW_FLOWER;
case LLAMA:
case "OCELOT":
return (is13 ? type == Material.SALMON
|| type == Material.COD
|| type == Material.PUFFERFISH
|| type == Material.TROPICAL_FISH
: type == Material.valueOf("RAW_FISH")); // Now broken in 1.13 ((Ocelot) entity).isTamed()
case "PANDA":
return (type == Material.BAMBOO);
case "FOX":
return type == Material.SWEET_BERRIES;
case "CAT":
return (type == Material.COD || type == Material.SALMON) && ((Cat) entity).isTamed();
case "RABBIT":
return type == Material.CARROT || type == Material.GOLDEN_CARROT || type == Material.DANDELION;
case "LLAMA":
return type == Material.HAY_BLOCK;
case "TURTLE":
return type == Material.SEAGRASS;
}
return false;
}
}

View File

@ -1,4 +1,4 @@
package com.songoda.ultimatestacker.events;
package com.songoda.ultimatestacker.listeners;
import com.songoda.ultimatestacker.UltimateStacker;
import org.bukkit.event.EventHandler;

View File

@ -1,4 +1,4 @@
package com.songoda.ultimatestacker.events;
package com.songoda.ultimatestacker.listeners;
import com.songoda.ultimatestacker.UltimateStacker;
import com.songoda.ultimatestacker.entity.EntityStack;

View File

@ -4,12 +4,10 @@ import com.songoda.ultimatestacker.UltimateStacker;
import com.songoda.ultimatestacker.storage.Storage;
import com.songoda.ultimatestacker.storage.StorageItem;
import com.songoda.ultimatestacker.storage.StorageRow;
import org.apache.commons.io.FileUtils;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.MemorySection;
import java.io.File;
import java.io.IOException;
import java.io.*;
import java.util.*;
public class StorageYaml extends Storage {
@ -110,7 +108,7 @@ public class StorageYaml extends Storage {
File data = new File(instance.getDataFolder(), "data.yml");
File dataClone = new File(instance.getDataFolder(), "data-backup-" + System.currentTimeMillis() + ".yml");
try {
FileUtils.copyFile(data, dataClone);
copyFile(data, dataClone);
} catch (IOException e) {
e.printStackTrace();
}
@ -129,4 +127,22 @@ public class StorageYaml extends Storage {
public void closeConnection() {
dataFile.saveConfig();
}
private static void copyFile(File source, File dest) throws IOException {
InputStream is = null;
OutputStream os = null;
try {
is = new FileInputStream(source);
os = new FileOutputStream(dest);
byte[] buffer = new byte[1024];
int length;
while ((length = is.read(buffer)) > 0) {
os.write(buffer, 0, length);
}
} finally {
is.close();
os.close();
}
}
}

View File

@ -4,7 +4,7 @@ import com.songoda.ultimatestacker.UltimateStacker;
import com.songoda.ultimatestacker.entity.EntityStack;
import com.songoda.ultimatestacker.entity.EntityStackManager;
import com.songoda.ultimatestacker.utils.Methods;
import com.songoda.ultimatestacker.utils.SettingsManager;
import com.songoda.ultimatestacker.utils.settings.Setting;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.configuration.ConfigurationSection;
@ -46,16 +46,16 @@ public class StackingTask extends BukkitRunnable {
}
// Start stacking task.
runTaskTimer(instance, 0, SettingsManager.Settings.STACK_SEARCH_TICK_SPEED.getInt());
runTaskTimer(instance, 0, Setting.STACK_SEARCH_TICK_SPEED.getInt());
}
@Override
public void run() {
int maxItemStackSize = SettingsManager.Settings.MAX_STACK_ITEMS.getInt();
int maxEntityStackSizeGlobal = SettingsManager.Settings.MAX_STACK_ENTITIES.getInt();
int minEntityStackAmount = SettingsManager.Settings.MIN_STACK_ENTITIES.getInt();
int maxItemStackSize = Setting.MAX_STACK_ITEMS.getInt();
int maxEntityStackSizeGlobal = Setting.MAX_STACK_ENTITIES.getInt();
int minEntityStackAmount = Setting.MIN_STACK_ENTITIES.getInt();
List<String> disabledWorlds = SettingsManager.Settings.DISABLED_WORLDS.getStringList();
List<String> disabledWorlds = Setting.DISABLED_WORLDS.getStringList();
EntityStackManager stackManager = instance.getEntityStackManager();
for (World world : Bukkit.getWorlds()) {
@ -70,7 +70,7 @@ public class StackingTask extends BukkitRunnable {
for (Entity entityO : entities) {
if (entityO == null || entityO instanceof Player || !entityO.isValid()) continue;
if (entityO instanceof Item && SettingsManager.Settings.STACK_ITEMS.getBoolean()) {
if (entityO instanceof Item && Setting.STACK_ITEMS.getBoolean()) {
ItemStack item = ((Item) entityO).getItemStack();
if (entityO.hasMetadata("grabbed")
@ -99,7 +99,7 @@ public class StackingTask extends BukkitRunnable {
continue;
}
if (!(entityO instanceof LivingEntity) || !SettingsManager.Settings.STACK_ENTITIES.getBoolean())
if (!(entityO instanceof LivingEntity) || !Setting.STACK_ENTITIES.getBoolean())
continue;
LivingEntity initalEntity = (LivingEntity) entityO;

View File

@ -3,6 +3,7 @@ package com.songoda.ultimatestacker.utils;
import com.songoda.ultimatestacker.UltimateStacker;
import com.songoda.ultimatestacker.entity.EntityStack;
import com.songoda.ultimatestacker.entity.EntityStackManager;
import com.songoda.ultimatestacker.utils.settings.Setting;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.block.CreatureSpawner;
@ -46,7 +47,7 @@ public class Methods {
newEntity.getEquipment().clear();
if (killed.getType() == EntityType.PIG_ZOMBIE)
newEntity.getEquipment().setItemInHand(new ItemStack(Material.GOLD_SWORD));
newEntity.getEquipment().setItemInHand(new ItemStack(instance.isServerVersion(ServerVersion.V1_13) ? Material.GOLDEN_SWORD : Material.valueOf("GOLD_SWORD")));
if (Bukkit.getPluginManager().isPluginEnabled("EpicSpawners"))
if (killed.hasMetadata("ES"))
@ -76,10 +77,10 @@ public class Methods {
EntityStack stack = stackManager.getStack(killed);
if (SettingsManager.Settings.KILL_WHOLE_STACK_ON_DEATH.getBoolean() && stack.getAmount() != 1) {
if (Setting.KILL_WHOLE_STACK_ON_DEATH.getBoolean() && stack.getAmount() != 1) {
handleWholeStackDeath(killed, stack, items, droppedExp);
} else if(SettingsManager.Settings.KILL_WHOLE_STACK_ON_SPECIAL_DEATH.getBoolean() && stack.getAmount() != 1) {
List<String> reasons = SettingsManager.Settings.SPECIAL_DEATH_CAUSE.getStringList();
} else if(stack.getAmount() != 1) {
List<String> reasons = Setting.SPECIAL_DEATH_CAUSE.getStringList();
EntityDamageEvent lastDamageCause = killed.getLastDamageCause();
if(lastDamageCause != null) {
@ -111,6 +112,8 @@ public class Methods {
((Slime)newEntity).setSize(((Slime)killed).getSize());
}
//ToDo: Mooshroom Color Handling.
//ToDO: Ravenger Banner Handling.
newEntity.setFireTicks(killed.getFireTicks());
newEntity.addPotionEffects(killed.getActivePotionEffects());
@ -119,7 +122,7 @@ public class Methods {
public static List<Entity> getSimilarEntitesAroundEntity(Entity initalEntity) {
int searchRadius = SettingsManager.Settings.SEARCH_RADIUS.getInt();
int searchRadius = Setting.SEARCH_RADIUS.getInt();
//Create a list of all entities around the initial entity of the same type.
List<Entity> entityList = initalEntity.getNearbyEntities(searchRadius, searchRadius, searchRadius).stream()
@ -212,7 +215,7 @@ public class Methods {
}
public static ItemStack getSpawnerItem(EntityType entityType, int amount) {
ItemStack item = new ItemStack(Material.MOB_SPAWNER, 1);
ItemStack item = new ItemStack((UltimateStacker.getInstance().isServerVersion(ServerVersion.V1_13) ? Material.SPAWNER : Material.valueOf("MOB_SPAWNER")), 1);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(Methods.compileSpawnerName(entityType, amount));
CreatureSpawner cs = (CreatureSpawner) ((BlockStateMeta) meta).getBlockState();
@ -222,6 +225,35 @@ public class Methods {
return item;
}
public static ItemStack getGlass() {
UltimateStacker instance = UltimateStacker.getInstance();
return Methods.getGlass(instance.getConfig().getBoolean("Interfaces.Replace Glass Type 1 With Rainbow Glass"), instance.getConfig().getInt("Interfaces.Glass Type 1"));
}
public static ItemStack getBackgroundGlass(boolean type) {
UltimateStacker instance = UltimateStacker.getInstance();
if (type)
return getGlass(false, instance.getConfig().getInt("Interfaces.Glass Type 2"));
else
return getGlass(false, instance.getConfig().getInt("Interfaces.Glass Type 3"));
}
private static ItemStack getGlass(Boolean rainbow, int type) {
int randomNum = 1 + (int) (Math.random() * 6);
ItemStack glass;
if (rainbow) {
glass = new ItemStack(UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ?
Material.LEGACY_STAINED_GLASS_PANE : Material.valueOf("STAINED_GLASS_PANE"), 1, (short) randomNum);
} else {
glass = new ItemStack(UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ?
Material.LEGACY_STAINED_GLASS_PANE : Material.valueOf("STAINED_GLASS_PANE"), 1, (short) type);
}
ItemMeta glassmeta = glass.getItemMeta();
glassmeta.setDisplayName("§l");
glass.setItemMeta(glassmeta);
return glass;
}
/**
* Serializes the location of the block specified.
*

View File

@ -1,221 +0,0 @@
package com.songoda.ultimatestacker.utils;
import com.songoda.ultimatestacker.UltimateStacker;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class SettingsManager implements Listener {
private static final Pattern SETTINGS_PATTERN = Pattern.compile("(.{1,28}(?:\\s|$))|(.{0,28})", Pattern.DOTALL);
private final UltimateStacker instance;
private String pluginName = "UltimateStacker";
private Map<Player, String> cat = new HashMap<>();
private Map<Player, String> current = new HashMap<>();
public SettingsManager(UltimateStacker plugin) {
this.instance = plugin;
Bukkit.getPluginManager().registerEvents(this, plugin);
}
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
ItemStack clickedItem = event.getCurrentItem();
if (event.getInventory() != event.getWhoClicked().getOpenInventory().getTopInventory()
|| clickedItem == null || !clickedItem.hasItemMeta()
|| !clickedItem.getItemMeta().hasDisplayName()) {
return;
}
if (event.getInventory().getTitle().equals(pluginName + " Settings Manager")) {
event.setCancelled(true);
if (clickedItem.getType().name().contains("STAINED_GLASS")) return;
String type = ChatColor.stripColor(clickedItem.getItemMeta().getDisplayName());
this.cat.put((Player) event.getWhoClicked(), type);
this.openEditor((Player) event.getWhoClicked());
} else if (event.getInventory().getTitle().equals(pluginName + " Settings Editor")) {
event.setCancelled(true);
if (clickedItem.getType().name().contains("STAINED_GLASS")) return;
Player player = (Player) event.getWhoClicked();
String key = cat.get(player) + "." + ChatColor.stripColor(clickedItem.getItemMeta().getDisplayName());
if (instance.getConfig().get(key).getClass().getName().equals("java.lang.Boolean")) {
this.instance.getConfig().set(key, !instance.getConfig().getBoolean(key));
this.finishEditing(player);
} else {
this.editObject(player, key);
}
}
}
@EventHandler
public void onChat(AsyncPlayerChatEvent event) {
Player player = event.getPlayer();
if (!current.containsKey(player)) return;
String value = current.get(player);
FileConfiguration config = instance.getConfig();
if (config.isInt(value)) {
config.set(value, Integer.parseInt(event.getMessage()));
} else if (config.isDouble(value)) {
config.set(value, Double.parseDouble(event.getMessage()));
} else if (config.isString(value)) {
config.set(value, event.getMessage());
}
this.finishEditing(player);
event.setCancelled(true);
}
public void finishEditing(Player player) {
this.current.remove(player);
this.instance.saveConfig();
this.openEditor(player);
}
public void editObject(Player player, String current) {
this.current.put(player, ChatColor.stripColor(current));
player.closeInventory();
player.sendMessage("");
player.sendMessage(Methods.formatText("&7Please enter a value for &6" + current + "&7."));
if (instance.getConfig().isInt(current) || instance.getConfig().isDouble(current)) {
player.sendMessage(Methods.formatText("&cUse only numbers."));
}
player.sendMessage("");
}
public void openSettingsManager(Player player) {
Inventory inventory = Bukkit.createInventory(null, 27, pluginName + " Settings Manager");
int slot = 10;
for (String key : instance.getConfig().getDefaultSection().getKeys(false)) {
ItemStack item = new ItemStack(Material.WOOL, 1, (byte) (slot - 9)); //ToDo: Make this function as it was meant to.
ItemMeta meta = item.getItemMeta();
meta.setLore(Collections.singletonList(Methods.formatText("&6Click To Edit This Category.")));
meta.setDisplayName(Methods.formatText("&f&l" + key));
item.setItemMeta(meta);
inventory.setItem(slot, item);
slot++;
}
player.openInventory(inventory);
}
public void openEditor(Player player) {
Inventory inventory = Bukkit.createInventory(null, 54, pluginName + " Settings Editor");
FileConfiguration config = instance.getConfig();
int slot = 0;
for (String key : config.getConfigurationSection(cat.get(player)).getKeys(true)) {
String fKey = cat.get(player) + "." + key;
ItemStack item = new ItemStack(Material.DIAMOND_HELMET);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(Methods.formatText("&6" + key));
List<String> lore = new ArrayList<>();
if (config.isBoolean(fKey)) {
item.setType(Material.LEVER);
lore.add(Methods.formatText(config.getBoolean(fKey) ? "&atrue" : "&cfalse"));
} else if (config.isString(fKey)) {
item.setType(Material.PAPER);
lore.add(Methods.formatText("&9" + config.getString(fKey)));
} else if (config.isInt(fKey)) {
item.setType(Material.WATCH);
lore.add(Methods.formatText("&5" + config.getInt(fKey)));
}
meta.setLore(lore);
item.setItemMeta(meta);
inventory.setItem(slot, item);
slot++;
}
player.openInventory(inventory);
}
public void updateSettings() {
for (Settings s : Settings.values()) {
instance.getConfig().addDefault(s.setting, s.option);
}
}
public enum Settings {
STACK_ITEMS("Main.Stack Items", true),
STACK_ENTITIES("Main.Stack Entities", true),
STACK_SPAWNERS("Main.Stack Spawners", true),
STACK_SEARCH_TICK_SPEED("Main.Stack Search Tick Speed", 5),
DISABLED_WORLDS("Main.DISABLED Worlds", Arrays.asList("World1", "World2", "World3")),
MAX_STACK_ENTITIES("Entity.Max Stack Size", 15),
MIN_STACK_ENTITIES("Entity.Min Stack Amount", 5),
HOLOGRAMS_ON_LOOK_ENTITY("Entity.Only Show Holograms On Look", false),
KILL_WHOLE_STACK_ON_DEATH("Entity.Kill Whole Stack On Death", false),
KILL_WHOLE_STACK_ON_SPECIAL_DEATH("Entity.Kill Whole Stack On Special Death Cause", true),
SPECIAL_DEATH_CAUSE("Entity.Special Death Cause", Arrays.asList("FALL", "DROWNING", "LAVA", "VOID")),
NAME_FORMAT_ENTITY("Entity.Name Format", "&f{TYPE} &6{AMT}x"),
SEARCH_RADIUS("Entity.Search Radius", 5),
MAX_STACK_ITEMS("Item.Max Stack Size", 120),
NAME_FORMAT_ITEM("Item.Name Format", "&f{TYPE} &6{AMT}x"),
o7("Spawners.Holograms Enabled", true),
o8("Spawners.Max Stack Size", 5),
NAME_FORMAT_SPAWNER("Spawners.Name Format", "&f{TYPE} Spawner &6{AMT}x"),
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", "UltimateStacker"),
DATABASE_PREFIX("Database.Prefix", "US-"),
DATABASE_USERNAME("Database.Username", "PUT_USERNAME_HERE"),
DATABASE_PASSWORD("Database.Password", "PUT_PASSWORD_HERE"),
LANGUGE_MODE("System.Language Mode", "en_US");
private String setting;
private Object option;
Settings(String setting, Object option) {
this.setting = setting;
this.option = option;
}
public List<String> getStringList() {
return UltimateStacker.getInstance().getConfig().getStringList(setting);
}
public boolean getBoolean() {
return UltimateStacker.getInstance().getConfig().getBoolean(setting);
}
public int getInt() {
return UltimateStacker.getInstance().getConfig().getInt(setting);
}
public String getString() {
return UltimateStacker.getInstance().getConfig().getString(setting);
}
}
}

View File

@ -0,0 +1,29 @@
package com.songoda.epicheads.utils.settings;
public enum Category {
MAIN("General settings and options."),
INTERFACES("These settings allow you to alter the way interfaces look.",
"They are used in GUI's to make paterns, change them up then open up a",
"GUI to see how it works."),
ECONOMY("Settings regarding economy.",
"Only one economy option can be used at a time. If you enable more than",
"one of these the first one will be used."),
ECONOMY_ITEM("Item token options."),
SYSTEM("System related settings.");
private String[] comments;
Category(String... comments) {
this.comments = comments;
}
public String[] getComments() {
return comments;
}
}

View File

@ -0,0 +1,143 @@
package com.songoda.epicheads.utils.settings;
import com.songoda.epicheads.EpicHeads;
import com.songoda.epicheads.utils.ServerVersion;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public enum Setting {
AUTOSAVE("Main.Auto Save Interval In Seconds", 15,
"The amount of time in between saving to file.",
"This is purely a safety function to prevent against unplanned crashes or",
"restarts. With that said it is advised to keep this enabled.",
"If however you enjoy living on the edge, feel free to turn it off."),
DISCORD("Main.Show Discord Button", true,
"This is the discord button displayed in the main GUI",
"Clicking this button will bring you to a discord where you can",
"add or remove heads to the global library this plugin uses.",
"AS well as get updates on future releases and features."),
FREE_IN_CREATIVE("Main.Heads Free In Creative Mode", false,
"Enabling this will make it so that a player can get all heads",
"for free as long as they are in the creative game mode."),
DROP_MOB_HEADS("Main.Drop Mob Heads", true,
"Should heads drop after a monster is killed?"),
DROP_PLAYER_HEADS("Main.Drop Player Heads", true,
"Should a players drop their head on death?"),
DROP_CHANCE("Main.Head Drop Chance", "25%",
"When a player or monster is killed what should be",
"the chance that their head drops?"),
DISABLED_HEADS("Main.Disabled Global Heads", Arrays.asList(34567, 34568, 34569),
"These are head ID's from the global database that are disabled.",
"By default this is filled with non existent ID's."),
GLASS_TYPE_1("Interfaces.Glass Type 1", 7),
GLASS_TYPE_2("Interfaces.Glass Type 2", 11),
GLASS_TYPE_3("Interfaces.Glass Type 3", 3),
HEAD_COST("Economy.Head Cost", 24.99,
"The cost the of the head. If you wan't to use PlayerPoints",
"or item tokens you need to use whole numbers."),
VAULT_ECONOMY("Economy.Use Vault Economy", true,
"Should Vault be used?"),
PLAYER_POINTS_ECONOMY("Economy.Use Player Points Economy", false,
"Should PlayerPoints be used?"),
ITEM_ECONOMY("Economy.Use Item Economy", false,
"Should item tokens be used?"),
ITEM_TOKEN_TYPE("Economy.Item.Type", EpicHeads.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ? "PLAYER_HEAD" : "SKULL_ITEM",
"Which item material type should be used?",
"You can use any of the materials from the following link:",
"https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html"),
ITEM_TOKEN_ID("Economy.Item.Head ID", 14395,
"If a player head is used as the token which head ID should be used?",
"This can be any head from the global database."),
ITEM_TOKEN_NAME("Economy.Item.Name", "&6Player Head Token",
"What should the token be named?"),
ITEM_TOKEN_LORE("Economy.Item.Lore", Arrays.asList("&8Use in /Heads!"),
"What should the tokens lore be?"),
LANGUGE_MODE("System.Language Mode", "en_US",
"The enabled language file.",
"More language files (if available) can be found in the plugins data folder.");
private String setting;
private Object option;
private String[] comments;
Setting(String setting, Object option, String... comments) {
this.setting = setting;
this.option = option;
this.comments = comments;
}
Setting(String setting, Object option) {
this.setting = setting;
this.option = option;
this.comments = null;
}
public static Setting getSetting(String setting) {
List<Setting> settings = Arrays.stream(values()).filter(setting1 -> setting1.setting.equals(setting)).collect(Collectors.toList());
if (settings.isEmpty()) return null;
return settings.get(0);
}
public String getSetting() {
return setting;
}
public Object getOption() {
return option;
}
public String[] getComments() {
return comments;
}
public List<Integer> getIntegerList() {
return EpicHeads.getInstance().getConfig().getIntegerList(setting);
}
public List<String> getStringList() {
return EpicHeads.getInstance().getConfig().getStringList(setting);
}
public boolean getBoolean() {
return EpicHeads.getInstance().getConfig().getBoolean(setting);
}
public int getInt() {
return EpicHeads.getInstance().getConfig().getInt(setting);
}
public long getLong() {
return EpicHeads.getInstance().getConfig().getLong(setting);
}
public String getString() {
return EpicHeads.getInstance().getConfig().getString(setting);
}
public char getChar() {
return EpicHeads.getInstance().getConfig().getString(setting).charAt(0);
}
public double getDouble() {
return EpicHeads.getInstance().getConfig().getDouble(setting);
}
}

View File

@ -0,0 +1,326 @@
package com.songoda.epicheads.utils.settings;
import com.songoda.epicheads.EpicHeads;
import com.songoda.epicheads.utils.Methods;
import com.songoda.epicheads.utils.ServerVersion;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.io.*;
import java.util.*;
/**
* Created by songoda on 6/4/2017.
*/
public class SettingsManager implements Listener {
private final EpicHeads plugin;
private Map<Player, String> cat = new HashMap<>();
private Map<Player, String> current = new HashMap<>();
public SettingsManager(EpicHeads plugin) {
this.plugin = plugin;
Bukkit.getPluginManager().registerEvents(this, plugin);
}
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
ItemStack clickedItem = event.getCurrentItem();
if (event.getInventory() != event.getWhoClicked().getOpenInventory().getTopInventory()
|| clickedItem == null || !clickedItem.hasItemMeta()
|| !clickedItem.getItemMeta().hasDisplayName()) {
return;
}
if (event.getView().getTitle().equals(plugin.getName() + " Settings Manager")) {
event.setCancelled(true);
if (clickedItem.getType().name().contains("STAINED_GLASS")) return;
String type = ChatColor.stripColor(clickedItem.getItemMeta().getDisplayName());
this.cat.put((Player) event.getWhoClicked(), type);
this.openEditor((Player) event.getWhoClicked());
} else if (event.getView().getTitle().equals(plugin.getName() + " Settings Editor")) {
event.setCancelled(true);
if (clickedItem.getType().name().contains("STAINED_GLASS")) return;
Player player = (Player) event.getWhoClicked();
String key = cat.get(player) + "." + ChatColor.stripColor(clickedItem.getItemMeta().getDisplayName());
if (plugin.getConfig().get(key).getClass().getName().equals("java.lang.Boolean")) {
this.plugin.getConfig().set(key, !plugin.getConfig().getBoolean(key));
this.finishEditing(player);
} else {
this.editObject(player, key);
}
}
}
@EventHandler
public void onChat(AsyncPlayerChatEvent event) {
Player player = event.getPlayer();
if (!current.containsKey(player)) return;
String value = current.get(player);
FileConfiguration config = plugin.getConfig();
if (config.isLong(value)) {
config.set(value, Long.parseLong(event.getMessage()));
} else if (config.isInt(value)) {
config.set(value, Integer.parseInt(event.getMessage()));
} else if (config.isDouble(value)) {
config.set(value, Double.parseDouble(event.getMessage()));
} else if (config.isString(value)) {
config.set(value, event.getMessage());
}
Bukkit.getScheduler().scheduleSyncDelayedTask(EpicHeads.getInstance(), () ->
this.finishEditing(player), 0L);
event.setCancelled(true);
}
private void finishEditing(Player player) {
this.current.remove(player);
this.saveConfig();
this.openEditor(player);
}
private void editObject(Player player, String current) {
this.current.put(player, ChatColor.stripColor(current));
player.closeInventory();
player.sendMessage("");
player.sendMessage(Methods.formatText("&7Please enter a value for &6" + current + "&7."));
if (plugin.getConfig().isInt(current) || plugin.getConfig().isDouble(current)) {
player.sendMessage(Methods.formatText("&cUse only numbers."));
}
player.sendMessage("");
}
public void openSettingsManager(Player player) {
Inventory inventory = Bukkit.createInventory(null, 27, plugin.getName() + " Settings Manager");
ItemStack glass = Methods.getGlass();
for (int i = 0; i < inventory.getSize(); i++) {
inventory.setItem(i, glass);
}
int slot = 10;
for (String key : plugin.getConfig().getDefaultSection().getKeys(false)) {
ItemStack item = new ItemStack(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.LEGACY_WOOL : Material.valueOf("WOOL"), 1, (byte) (slot - 9));
ItemMeta meta = item.getItemMeta();
meta.setLore(Collections.singletonList(Methods.formatText("&6Click To Edit This Category.")));
meta.setDisplayName(Methods.formatText("&f&l" + key));
item.setItemMeta(meta);
inventory.setItem(slot, item);
slot++;
}
player.openInventory(inventory);
}
private void openEditor(Player player) {
Inventory inventory = Bukkit.createInventory(null, 54, plugin.getName() + " Settings Editor");
FileConfiguration config = plugin.getConfig();
int slot = 0;
for (String key : config.getConfigurationSection(cat.get(player)).getKeys(true)) {
String fKey = cat.get(player) + "." + key;
ItemStack item = new ItemStack(Material.DIAMOND_HELMET);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(Methods.formatText("&6" + key));
List<String> lore = new ArrayList<>();
if (config.isBoolean(fKey)) {
item.setType(Material.LEVER);
lore.add(Methods.formatText(config.getBoolean(fKey) ? "&atrue" : "&cfalse"));
} else if (config.isString(fKey)) {
item.setType(Material.PAPER);
lore.add(Methods.formatText("&7" + config.getString(fKey)));
} else if (config.isInt(fKey)) {
item.setType(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.CLOCK : Material.valueOf("WATCH"));
lore.add(Methods.formatText("&7" + config.getInt(fKey)));
} else if (config.isLong(fKey)) {
item.setType(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.CLOCK : Material.valueOf("WATCH"));
lore.add(Methods.formatText("&7" + config.getLong(fKey)));
} else if (config.isDouble(fKey)) {
item.setType(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.CLOCK : Material.valueOf("WATCH"));
lore.add(Methods.formatText("&7" + config.getDouble(fKey)));
}
Setting setting = Setting.getSetting(fKey);
if (setting != null && setting.getComments() != null) {
lore.add("");
String comment = String.join(" ", setting.getComments());
int lastIndex = 0;
for (int n = 0; n < comment.length(); n++) {
if (n - lastIndex < 30)
continue;
if (comment.charAt(n) == ' ') {
lore.add(Methods.formatText("&8" + comment.substring(lastIndex, n).trim()));
lastIndex = n;
}
}
if (lastIndex - comment.length() < 30)
lore.add(Methods.formatText("&8" + comment.substring(lastIndex).trim()));
}
meta.setLore(lore);
item.setItemMeta(meta);
inventory.setItem(slot, item);
slot++;
}
player.openInventory(inventory);
}
public void reloadConfig() {
plugin.reloadConfig();
this.setupConfig();
}
public void setupConfig() {
FileConfiguration config = plugin.getConfig();
for (Setting setting : Setting.values()) {
config.addDefault(setting.getSetting(), setting.getOption());
}
plugin.getConfig().options().copyDefaults(true);
saveConfig();
}
private void saveConfig() {
String dump = plugin.getConfig().saveToString();
StringBuilder config = new StringBuilder();
BufferedReader bufReader = new BufferedReader(new StringReader(dump));
try {
boolean first = true;
String line;
int currentTab = 0;
String category = "";
while ((line = bufReader.readLine()) != null) {
if (line.trim().startsWith("#")) continue;
int tabChange = line.length() - line.trim().length();
if (currentTab != tabChange) {
category = category.contains(".") && tabChange != 0 ? category.substring(0, category.indexOf(".")) : "";
currentTab = tabChange;
}
if (line.endsWith(":")) {
bufReader.mark(1000);
String found = bufReader.readLine();
bufReader.reset();
if (!found.trim().startsWith("-")) {
String newCategory = line.substring(0, line.length() - 1).trim();
if (category.equals(""))
category = newCategory;
else
category += "." + newCategory;
currentTab = tabChange + 2;
if (!first) {
config.append("\n\n");
} else {
first = false;
}
if (!category.contains("."))
config.append("#").append("\n");
try {
Category categoryObj = Category.valueOf(category.toUpperCase()
.replace(" ", "_")
.replace(".", "_"));
config.append(new String(new char[tabChange]).replace('\0', ' '));
for (String l : categoryObj.getComments())
config.append("# ").append(l).append("\n");
} catch (IllegalArgumentException e) {
config.append("# ").append(category).append("\n");
}
if (!category.contains("."))
config.append("#").append("\n");
config.append(line).append("\n");
continue;
}
}
if (line.trim().startsWith("-")) {
config.append(line).append("\n");
continue;
}
String key = category + "." + (line.split(":")[0].trim());
for (Setting setting : Setting.values()) {
if (!setting.getSetting().equals(key) || setting.getComments() == null) continue;
config.append(" ").append("\n");
for (String l : setting.getComments()) {
config.append(new String(new char[currentTab]).replace('\0', ' '));
config.append("# ").append(l).append("\n");
}
}
config.append(line).append("\n");
}
} catch (IOException e) {
e.printStackTrace();
}
try {
BufferedWriter writer =
new BufferedWriter(new FileWriter(new File(plugin.getDataFolder() + "\\config.yml")));
writer.write(config.toString());
writer.flush();
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static <K, V> void add(LinkedHashMap<K, V> map, int index, K key, V value) {
assert (map != null);
assert !map.containsKey(key);
assert (index >= 0) && (index < map.size());
int i = 0;
List<Map.Entry<K, V>> rest = new ArrayList<>();
for (Map.Entry<K, V> entry : map.entrySet()) {
if (i++ >= index) {
rest.add(entry);
}
}
map.put(key, value);
for (Map.Entry<K, V> entry : rest) {
map.remove(entry.getKey());
map.put(entry.getKey(), entry.getValue());
}
}
}

View File

@ -4,6 +4,7 @@ version: maven-version-number
softdepend: [Arconix, HolographicDisplays, WorldGuard, EpicSpawners]
main: com.songoda.ultimatestacker.UltimateStacker
author: songoda
api-version: 1.13
commands:
UltimateStacker:
description: I have no idea.