mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2024-11-26 20:26:34 +01:00
Multiple generator fixes.
This commit is contained in:
parent
504f0ff57f
commit
63441f1d6c
@ -47,7 +47,7 @@ public class GeneratorManager {
|
||||
Materials materials = Materials.fromString(materialList);
|
||||
|
||||
if (materials != null) {
|
||||
generatorMaterials.add(new GeneratorMaterial(materials, configLoad.getInt(
|
||||
generatorMaterials.add(new GeneratorMaterial(materials, configLoad.getDouble(
|
||||
"Generators." + generatorList + ".Materials." + materialList + ".Chance")));
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ public class GeneratorMaterial {
|
||||
private Materials materials;
|
||||
private double chance;
|
||||
|
||||
public GeneratorMaterial(Materials materials, int chance) {
|
||||
public GeneratorMaterial(Materials materials, double chance) {
|
||||
this.materials = materials;
|
||||
this.chance = chance;
|
||||
}
|
||||
|
@ -312,6 +312,10 @@ public class Block implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Material material = event.getBlock().getType();
|
||||
if (material != Material.WATER && material != Material.LAVA) return;
|
||||
|
||||
if (generatorManager != null && generatorManager.getGenerators().size() > 0) {
|
||||
Island island = islandManager.getIslandAtLocation(event.getBlock().getLocation());
|
||||
IslandWorld world = worldManager.getIslandWorld(event.getBlock().getWorld());
|
||||
|
@ -1,22 +1,5 @@
|
||||
package me.goodandevil.skyblock.menus.admin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
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.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import me.goodandevil.skyblock.SkyBlock;
|
||||
import me.goodandevil.skyblock.config.FileManager;
|
||||
import me.goodandevil.skyblock.config.FileManager.Config;
|
||||
@ -32,6 +15,22 @@ import me.goodandevil.skyblock.utils.item.nInventoryUtil;
|
||||
import me.goodandevil.skyblock.utils.version.Materials;
|
||||
import me.goodandevil.skyblock.utils.version.NMSUtil;
|
||||
import me.goodandevil.skyblock.utils.version.Sounds;
|
||||
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.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Generator implements Listener {
|
||||
|
||||
@ -68,7 +67,7 @@ public class Generator implements Listener {
|
||||
nInv.createItem(new ItemStack(org.bukkit.Material.SIGN),
|
||||
configLoad.getString("Menu.Admin.Generator.Browse.Item.Information.Displayname"),
|
||||
configLoad.getStringList("Menu.Admin.Generator.Browse.Item.Information.Lore"),
|
||||
new Placeholder[] { new Placeholder("%generators", "" + generators.size()) }, null, null),
|
||||
new Placeholder[]{new Placeholder("%generators", "" + generators.size())}, null, null),
|
||||
4);
|
||||
nInv.addItem(nInv.createItem(Materials.BLACK_STAINED_GLASS_PANE.parseItem(),
|
||||
configLoad.getString("Menu.Admin.Generator.Browse.Item.Barrier.Displayname"), null, null, null,
|
||||
@ -130,9 +129,9 @@ public class Generator implements Listener {
|
||||
|
||||
nInv.addItem(nInv.createItem(Materials.LEGACY_EMPTY_MAP.getPostItem(),
|
||||
configLoad.getString("Menu.Admin.Generator.Generator.Item.Information.Displayname"), permissionLore,
|
||||
new Placeholder[] { new Placeholder("%name", generator.getName()),
|
||||
new Placeholder[]{new Placeholder("%name", generator.getName()),
|
||||
new Placeholder("%materials", "" + generator.getGeneratorMaterials().size()),
|
||||
new Placeholder("%permission", generator.getPermission()) },
|
||||
new Placeholder("%permission", generator.getPermission())},
|
||||
null, null), 4);
|
||||
nInv.addItem(nInv.createItem(Materials.OAK_FENCE_GATE.parseItem(),
|
||||
configLoad.getString("Menu.Admin.Generator.Generator.Item.Return.Displayname"), null, null, null,
|
||||
@ -148,12 +147,12 @@ public class Generator implements Listener {
|
||||
configLoad.getString("Menu.Admin.Generator.Generator.Item.Nothing.Displayname"), null, null,
|
||||
null, null), 31);
|
||||
} else {
|
||||
int index = 1 * 36 - 36,
|
||||
endIndex = index >= generatorMaterials.size() ? generatorMaterials.size() - 1 : index + 36,
|
||||
int index = 0,
|
||||
endIndex = index + 36,
|
||||
inventorySlot = 17;
|
||||
|
||||
for (; index < endIndex; index++) {
|
||||
if (generatorMaterials.size() > index) {
|
||||
if (generatorMaterials.size() <= index) continue;
|
||||
inventorySlot++;
|
||||
|
||||
GeneratorMaterial generatorMaterial = generatorMaterials.get(index);
|
||||
@ -162,22 +161,16 @@ public class Generator implements Listener {
|
||||
configLoad.getString("Menu.Admin.Generator.Generator.Item.Material.Displayname")
|
||||
.replace("%material", generatorMaterial.getMaterials().name())),
|
||||
configLoad.getStringList("Menu.Admin.Generator.Generator.Item.Material.Lore"),
|
||||
new Placeholder[] { new Placeholder("%chance", "" + generatorMaterial.getChance()) },
|
||||
new Placeholder[]{new Placeholder("%chance", "" + generatorMaterial.getChance())},
|
||||
null, null), inventorySlot);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nInv.setTitle(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Menu.Admin.Generator.Title")));
|
||||
nInv.setRows(6);
|
||||
|
||||
Bukkit.getServer().getScheduler().runTask(skyblock, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
nInv.open();
|
||||
}
|
||||
});
|
||||
Bukkit.getServer().getScheduler().runTask(skyblock, nInv::open);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@ -186,7 +179,8 @@ public class Generator implements Listener {
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
ItemStack is = event.getCurrentItem();
|
||||
|
||||
if (event.getCurrentItem() != null && event.getCurrentItem().getType() != Material.AIR) {
|
||||
if (event.getCurrentItem() == null || event.getCurrentItem().getType() == Material.AIR) return;
|
||||
|
||||
SkyBlock skyblock = SkyBlock.getInstance();
|
||||
|
||||
GeneratorManager generatorManager = skyblock.getGeneratorManager();
|
||||
@ -197,8 +191,9 @@ public class Generator implements Listener {
|
||||
Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml"));
|
||||
FileConfiguration configLoad = config.getFileConfiguration();
|
||||
|
||||
if (event.getInventory().getName().equals(
|
||||
ChatColor.translateAlternateColorCodes('&', configLoad.getString("Menu.Admin.Generator.Title")))) {
|
||||
if (!event.getInventory().getName().equals(
|
||||
ChatColor.translateAlternateColorCodes('&', configLoad.getString("Menu.Admin.Generator.Title"))))
|
||||
return;
|
||||
event.setCancelled(true);
|
||||
|
||||
PlayerData playerData = skyblock.getPlayerDataManager().getPlayerData(player);
|
||||
@ -339,12 +334,7 @@ public class Generator implements Listener {
|
||||
|
||||
player.closeInventory();
|
||||
|
||||
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(skyblock, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
open(player);
|
||||
}
|
||||
}, 1L);
|
||||
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(skyblock, () -> open(player), 1L);
|
||||
} else {
|
||||
String name = ((Generator.Viewer) playerData.getViewer()).getName();
|
||||
|
||||
@ -359,22 +349,19 @@ public class Generator implements Listener {
|
||||
|
||||
soundManager.playSound(player, Sounds.WOOD_CLICK.bukkitSound(), 1.0F, 1.0F);
|
||||
|
||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(skyblock, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Config config = fileManager
|
||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(skyblock, () -> {
|
||||
Config config1 = fileManager
|
||||
.getConfig(new File(skyblock.getDataFolder(), "generators.yml"));
|
||||
FileConfiguration configLoad = config.getFileConfiguration();
|
||||
FileConfiguration configLoad1 = config1.getFileConfiguration();
|
||||
|
||||
configLoad.set("Generators." + generator.getName() + ".Permission",
|
||||
configLoad1.set("Generators." + generator.getName() + ".Permission",
|
||||
generator.isPermission());
|
||||
|
||||
try {
|
||||
configLoad.save(config.getFile());
|
||||
configLoad1.save(config1.getFile());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
player.closeInventory();
|
||||
@ -484,7 +471,7 @@ public class Generator implements Listener {
|
||||
soundManager.playSound(player, Sounds.ANVIL_LAND.bukkitSound(),
|
||||
1.0F, 1.0F);
|
||||
} else if (!event1.getName().replace(" ", "")
|
||||
.matches("^[a-zA-Z0-9]+$")) {
|
||||
.matches("^[a-zA-Z0-9|.]+$")) {
|
||||
messageManager.sendMessage(player, configLoad
|
||||
.getString("Island.Admin.Generator.Characters.Message"));
|
||||
soundManager.playSound(player, Sounds.ANVIL_LAND.bukkitSound(),
|
||||
@ -495,13 +482,13 @@ public class Generator implements Listener {
|
||||
"Island.Admin.Generator.Material.Exist.Message"));
|
||||
soundManager.playSound(player, Sounds.ANVIL_LAND.bukkitSound(),
|
||||
1.0F, 1.0F);
|
||||
} else if (!event1.getName().matches("[0-9]+")) {
|
||||
} else if (!event1.getName().matches("-?\\d+(?:\\.\\d+)?")) {
|
||||
messageManager.sendMessage(player, configLoad.getString(
|
||||
"Island.Admin.Generator.Chance.Numerical.Message"));
|
||||
soundManager.playSound(player, Sounds.ANVIL_LAND.bukkitSound(),
|
||||
1.0F, 1.0F);
|
||||
} else {
|
||||
int materialChance = Integer.valueOf(event1.getName());
|
||||
double materialChance = Double.valueOf(event1.getName());
|
||||
double totalMaterialChance = materialChance;
|
||||
|
||||
for (GeneratorMaterial generatorMaterialList1 : generator
|
||||
@ -519,43 +506,35 @@ public class Generator implements Listener {
|
||||
1.0F, 1.0F);
|
||||
} else {
|
||||
generatorMaterialList
|
||||
.setChance(Integer.valueOf(event1.getName()));
|
||||
.setChance(Double.valueOf(event1.getName()));
|
||||
soundManager.playSound(player, Sounds.NOTE_PLING.bukkitSound(),
|
||||
1.0F, 1.0F);
|
||||
|
||||
Bukkit.getServer().getScheduler()
|
||||
.runTaskAsynchronously(skyblock, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Config config = fileManager.getConfig(
|
||||
.runTaskAsynchronously(skyblock, () -> {
|
||||
Config config12 = fileManager.getConfig(
|
||||
new File(skyblock.getDataFolder(),
|
||||
"generators.yml"));
|
||||
FileConfiguration configLoad = config
|
||||
FileConfiguration configLoad12 = config12
|
||||
.getFileConfiguration();
|
||||
|
||||
configLoad.set("Generators."
|
||||
configLoad12.set("Generators."
|
||||
+ generator.getName() + ".Materials."
|
||||
+ generatorMaterialList.getMaterials()
|
||||
.name()
|
||||
+ ".Chance", materialChance);
|
||||
|
||||
try {
|
||||
configLoad.save(config.getFile());
|
||||
configLoad12.save(config12.getFile());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
player.closeInventory();
|
||||
|
||||
Bukkit.getServer().getScheduler()
|
||||
.runTaskLaterAsynchronously(skyblock, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
open(player);
|
||||
}
|
||||
}, 1L);
|
||||
.runTaskLaterAsynchronously(skyblock, () -> open(player), 1L);
|
||||
}
|
||||
}
|
||||
|
||||
@ -603,12 +582,7 @@ public class Generator implements Listener {
|
||||
player.closeInventory();
|
||||
|
||||
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(skyblock,
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
open(player);
|
||||
}
|
||||
}, 1L);
|
||||
() -> open(player), 1L);
|
||||
}
|
||||
|
||||
return;
|
||||
@ -669,12 +643,7 @@ public class Generator implements Listener {
|
||||
|
||||
player.closeInventory();
|
||||
|
||||
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(skyblock, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
open(player);
|
||||
}
|
||||
}, 1L);
|
||||
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(skyblock, () -> open(player), 1L);
|
||||
}
|
||||
|
||||
return;
|
||||
@ -687,12 +656,7 @@ public class Generator implements Listener {
|
||||
|
||||
player.closeInventory();
|
||||
|
||||
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(skyblock, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
open(player);
|
||||
}
|
||||
}, 1L);
|
||||
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(skyblock, () -> open(player), 1L);
|
||||
}
|
||||
|
||||
return;
|
||||
@ -709,12 +673,7 @@ public class Generator implements Listener {
|
||||
|
||||
player.closeInventory();
|
||||
|
||||
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(skyblock, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
open(player);
|
||||
}
|
||||
}, 1L);
|
||||
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(skyblock, () -> open(player), 1L);
|
||||
} else if (event.getClick() == ClickType.RIGHT) {
|
||||
generatorManager.removeGenerator(generatorList);
|
||||
|
||||
@ -723,31 +682,23 @@ public class Generator implements Listener {
|
||||
.replace("%generator", generatorList.getName()));
|
||||
soundManager.playSound(player, Sounds.IRONGOLEM_HIT.bukkitSound(), 1.0F, 1.0F);
|
||||
|
||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(skyblock, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Config config = fileManager
|
||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(skyblock, () -> {
|
||||
Config config13 = fileManager
|
||||
.getConfig(new File(skyblock.getDataFolder(), "generators.yml"));
|
||||
FileConfiguration configLoad = config.getFileConfiguration();
|
||||
FileConfiguration configLoad13 = config13.getFileConfiguration();
|
||||
|
||||
configLoad.set("Generators." + generatorList.getName(), null);
|
||||
configLoad13.set("Generators." + generatorList.getName(), null);
|
||||
|
||||
try {
|
||||
configLoad.save(config.getFile());
|
||||
configLoad13.save(config13.getFile());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
player.closeInventory();
|
||||
|
||||
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(skyblock, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
open(player);
|
||||
}
|
||||
}, 1L);
|
||||
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(skyblock, () -> open(player), 1L);
|
||||
}
|
||||
|
||||
return;
|
||||
@ -760,8 +711,6 @@ public class Generator implements Listener {
|
||||
open(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class Viewer {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user