WildStacker support attempt (disabled), bug fixes

This commit is contained in:
Esophose 2019-06-01 23:43:58 -06:00
parent 27695157bb
commit 481099b65a
12 changed files with 157 additions and 124 deletions

View File

@ -38,7 +38,7 @@ dependencies {
implementation (group: 'com.songoda', name: 'epicanchors', version: '1.2.5')
// WildStacker
implementation (group: 'com.bgsoftware', name: 'wildstacker-api', version: 'b14')
implementation (group: 'com.bgsoftware', name: 'wildstacker-api', version: 'b15')
// WorldEdit
implementation (group: 'com.sk89q', name: 'worldedit', version: '7.0.0')

View File

@ -29,7 +29,7 @@ public class Chunk {
private int initialNumberOfChunks = -1;
private Set<ChunkPosition> chunkPositions = new HashSet<>();
private Set<ChunkSnapshot> chunkSnapshots = new HashSet<>();
private Set<LevelChunkSnapshotWrapper> chunkSnapshots = new HashSet<>();
private boolean isReady = false;
private boolean isFinished = false;
@ -62,7 +62,7 @@ public class Chunk {
return this.isReady;
}
public Set<ChunkSnapshot> getAvailableChunkSnapshots() {
public Set<LevelChunkSnapshotWrapper> getAvailableChunkSnapshots() {
this.isReady = false;
return this.chunkSnapshots;
}
@ -72,6 +72,8 @@ public class Chunk {
}
public void prepareNextChunkSnapshots() {
boolean isWildStackerEnabled = Bukkit.getPluginManager().isPluginEnabled("WildStacker") && false; // TODO: Disabled for now until we figure out why it isn't working properly
Bukkit.getScheduler().runTask(this.skyblock, () -> {
this.chunkSnapshots.clear();
@ -93,10 +95,22 @@ public class Chunk {
int z = chunkPosition.getZ();
if (!world.isChunkLoaded(x, z)) {
world.loadChunk(x, z);
this.chunkSnapshots.add(world.getChunkAt(x, z).getChunkSnapshot());
org.bukkit.Chunk chunk = world.getChunkAt(x, z);
ChunkSnapshot chunkSnapshot = chunk.getChunkSnapshot();
if (isWildStackerEnabled) {
this.chunkSnapshots.add(new WildStackerChunkSnapshotWrapper(chunkSnapshot, com.bgsoftware.wildstacker.api.WildStackerAPI.getWildStacker().getSystemManager().getStackedSnapshot(chunk, true)));
} else {
this.chunkSnapshots.add(new ChunkSnapshotWrapper(chunkSnapshot));
}
world.unloadChunk(x, z);
} else {
this.chunkSnapshots.add(world.getChunkAt(x, z).getChunkSnapshot());
org.bukkit.Chunk chunk = world.getChunkAt(x, z);
ChunkSnapshot chunkSnapshot = chunk.getChunkSnapshot();
if (isWildStackerEnabled) {
this.chunkSnapshots.add(new WildStackerChunkSnapshotWrapper(chunkSnapshot, com.bgsoftware.wildstacker.api.WildStackerAPI.getWildStacker().getSystemManager().getStackedSnapshot(chunk, true)));
} else {
this.chunkSnapshots.add(new ChunkSnapshotWrapper(chunkSnapshot));
}
}
it.remove();
}
@ -148,27 +162,4 @@ public class Chunk {
}
}
}
private class ChunkPosition {
private World world;
private int x, z;
public ChunkPosition(World world, int x, int z) {
this.world = world;
this.x = x;
this.z = z;
}
public World getWorld() {
return this.world;
}
public int getX() {
return this.x;
}
public int getZ() {
return this.z;
}
}
}

View File

@ -0,0 +1,26 @@
package me.goodandevil.skyblock.levelling;
import org.bukkit.World;
public class ChunkPosition {
private World world;
private int x, z;
public ChunkPosition(World world, int x, int z) {
this.world = world;
this.x = x;
this.z = z;
}
public World getWorld() {
return this.world;
}
public int getX() {
return this.x;
}
public int getZ() {
return this.z;
}
}

View File

@ -0,0 +1,16 @@
package me.goodandevil.skyblock.levelling;
import org.bukkit.ChunkSnapshot;
public class ChunkSnapshotWrapper extends LevelChunkSnapshotWrapper {
public ChunkSnapshotWrapper(ChunkSnapshot chunkSnapshot) {
super(chunkSnapshot);
}
@Override
public boolean hasWildStackerData() {
return false;
}
}

View File

@ -0,0 +1,19 @@
package me.goodandevil.skyblock.levelling;
import org.bukkit.ChunkSnapshot;
public abstract class LevelChunkSnapshotWrapper {
private ChunkSnapshot chunkSnapshot;
public LevelChunkSnapshotWrapper(ChunkSnapshot chunkSnapshot) {
this.chunkSnapshot = chunkSnapshot;
}
public ChunkSnapshot getChunkSnapshot() {
return this.chunkSnapshot;
}
abstract boolean hasWildStackerData();
}

View File

@ -85,7 +85,6 @@ public class LevellingManager {
int worldMaxHeight = height;
boolean isEpicSpawnersEnabled = Bukkit.getPluginManager().isPluginEnabled("EpicSpawners");
boolean isWildStackerEnabled = Bukkit.getPluginManager().isPluginEnabled("WildStacker");
Map<LevellingData, Long> levellingData = new HashMap<>();
Set<Location> spawnerLocations = new HashSet<>(); // These have to be checked synchronously :(
@ -109,10 +108,12 @@ public class LevellingManager {
return;
}
for (ChunkSnapshot chunkSnapshotList : chunk.getAvailableChunkSnapshots()) {
for (LevelChunkSnapshotWrapper chunkSnapshotList : chunk.getAvailableChunkSnapshots()) {
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
for (int y = 0; y < worldMaxHeight; y++) {
ChunkSnapshot chunkSnapshot = chunkSnapshotList.getChunkSnapshot();
try {
org.bukkit.Material blockMaterial = org.bukkit.Material.AIR;
int blockData = 0;
@ -120,20 +121,20 @@ public class LevellingManager {
if (NMSVersion > 12) {
if (getBlockTypeMethod == null) {
getBlockTypeMethod = chunkSnapshotList.getClass()
getBlockTypeMethod = chunkSnapshot.getClass()
.getMethod("getBlockType", int.class, int.class, int.class);
}
blockMaterial = (org.bukkit.Material) getBlockTypeMethod
.invoke(chunkSnapshotList, x, y, z);
.invoke(chunkSnapshot, x, y, z);
} else {
if (getBlockTypeIdMethod == null) {
getBlockTypeIdMethod = chunkSnapshotList.getClass()
getBlockTypeIdMethod = chunkSnapshot.getClass()
.getMethod("getBlockTypeId", int.class, int.class, int.class);
}
if (getBlockTypeDataMethod == null) {
getBlockTypeDataMethod = chunkSnapshotList.getClass()
getBlockTypeDataMethod = chunkSnapshot.getClass()
.getMethod("getBlockData", int.class, int.class, int.class);
}
@ -144,8 +145,8 @@ public class LevellingManager {
blockMaterial = (org.bukkit.Material) getMaterialMethod.invoke(
blockMaterial,
(int) getBlockTypeIdMethod.invoke(chunkSnapshotList, x, y, z));
blockData = (int) getBlockTypeDataMethod.invoke(chunkSnapshotList, x, y, z);
(int) getBlockTypeIdMethod.invoke(chunkSnapshot, x, y, z));
blockData = (int) getBlockTypeDataMethod.invoke(chunkSnapshot, x, y, z);
}
if (blacklistedMaterials.contains(blockMaterial))
@ -154,8 +155,8 @@ public class LevellingManager {
long amount = 1;
if (blockMaterial == Materials.SPAWNER.parseMaterial()) {
World world = Bukkit.getWorld(chunkSnapshotList.getWorldName());
Location location = new Location(world, chunkSnapshotList.getX() * 16 + x, y, chunkSnapshotList.getZ() * 16 + z);
World world = Bukkit.getWorld(chunkSnapshot.getWorldName());
Location location = new Location(world, chunkSnapshot.getX() * 16 + x, y, chunkSnapshot.getZ() * 16 + z);
if (isEpicSpawnersEnabled) {
com.songoda.epicspawners.EpicSpawners epicSpawners = com.songoda.epicspawners.EpicSpawners.getInstance();
@ -167,39 +168,37 @@ public class LevellingManager {
}
}
// if (isWildStackerEnabled) {
// com.bgsoftware.wildstacker.api.handlers.SystemManager wildStacker = com.bgsoftware.wildstacker.api.WildStackerAPI.getWildStacker().getSystemManager();
// com.bgsoftware.wildstacker.api.objects.StackedSpawner spawner = wildStacker.getStackedSpawner(location);
// if (spawner != null) {
// amount = spawner.getStackAmount();
// spawnerType = spawner.getSpawnedType();
// }
// }
if (chunkSnapshotList.hasWildStackerData()) {
com.bgsoftware.wildstacker.api.objects.StackedSnapshot snapshot = ((WildStackerChunkSnapshotWrapper)chunkSnapshotList).getStackedSnapshot();
if (snapshot.isStackedSpawner(location)) {
Map.Entry<Integer, EntityType> spawnerData = snapshot.getStackedSpawner(location);
amount = spawnerData.getKey();
blockData = 0;
}
}
if (spawnerType == null) {
spawnerLocations.add(location);
continue;
}
} else {
// if (isWildStackerEnabled) {
// World world = Bukkit.getWorld(chunkSnapshotList.getWorldName());
// Location location = new Location(world, chunkSnapshotList.getX() * 16 + x, y, chunkSnapshotList.getZ() * 16 + z);
// com.bgsoftware.wildstacker.api.handlers.SystemManager wildStacker = com.bgsoftware.wildstacker.api.WildStackerAPI.getWildStacker().getSystemManager();
// com.bgsoftware.wildstacker.api.objects.StackedBarrel barrel = wildStacker.getStackedBarrel(location);
// if (barrel != null) {
// amount = barrel.getStackAmount();
// blockMaterial = barrel.getType();
// blockData = barrel.getData();
// if (NMSUtil.getVersionNumber() > 12 && blockMaterial.name().startsWith("LEGACY_")) {
// blockMaterial = Material.matchMaterial(blockMaterial.name().replace("LEGACY_", ""));
// blockData = 0;
// }
// }
// }
if (chunkSnapshotList.hasWildStackerData()) {
com.bgsoftware.wildstacker.api.objects.StackedSnapshot snapshot = ((WildStackerChunkSnapshotWrapper)chunkSnapshotList).getStackedSnapshot();
World world = Bukkit.getWorld(chunkSnapshot.getWorldName());
Location location = new Location(world, chunkSnapshot.getX() * 16 + x, y, chunkSnapshot.getZ() * 16 + z);
if (snapshot.isStackedBarrel(location)) {
Map.Entry<Integer, Material> barrelData = snapshot.getStackedBarrel(location);
amount = barrelData.getKey();
blockMaterial = barrelData.getValue();
if (NMSUtil.getVersionNumber() > 12 && blockMaterial.name().startsWith("LEGACY_")) {
blockMaterial = Material.matchMaterial(blockMaterial.name().replace("LEGACY_", ""));
}
}
}
if (stackableManager != null && stackableManager.getStackableMaterials().contains(blockMaterial) && amount == 1) {
World world = Bukkit.getWorld(chunkSnapshotList.getWorldName());
Location location = new Location(world, chunkSnapshotList.getX() * 16 + x, y, chunkSnapshotList.getZ() * 16 + z);
World world = Bukkit.getWorld(chunkSnapshot.getWorldName());
Location location = new Location(world, chunkSnapshot.getX() * 16 + x, y, chunkSnapshot.getZ() * 16 + z);
if (stackableManager.isStacked(location)) {
Stackable stackable = stackableManager.getStack(location, blockMaterial);
if (stackable != null) {

View File

@ -0,0 +1,24 @@
package me.goodandevil.skyblock.levelling;
import com.bgsoftware.wildstacker.api.objects.StackedSnapshot;
import org.bukkit.ChunkSnapshot;
public class WildStackerChunkSnapshotWrapper extends LevelChunkSnapshotWrapper {
private StackedSnapshot stackedSnapshot;
public WildStackerChunkSnapshotWrapper(ChunkSnapshot chunkSnapshot, StackedSnapshot stackedSnapshot) {
super(chunkSnapshot);
this.stackedSnapshot = stackedSnapshot;
}
@Override
public boolean hasWildStackerData() {
return true;
}
public StackedSnapshot getStackedSnapshot() {
return this.stackedSnapshot;
}
}

View File

@ -651,7 +651,7 @@ public class Block implements Listener {
} else {
try {
@SuppressWarnings("unchecked")
ArrayList<org.bukkit.block.Block> blocks = (ArrayList<org.bukkit.block.Block>) event.getClass().getMethod("getBlocks").invoke(event);
List<org.bukkit.block.Block> blocks = (List<org.bukkit.block.Block>) event.getClass().getMethod("getBlocks").invoke(event);
for (org.bukkit.block.Block block : blocks) {
if (LocationUtil.isLocationAffectingLocation(block.getLocation(), islandLocation)) {
event.setCancelled(true);

View File

@ -90,6 +90,19 @@ public class Interact implements Listener {
}
}
if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_AIR) {
if (event.getItem() != null && event.getItem().getType() == Material.EGG) {
if (!skyblock.getIslandManager().hasPermission(player, "Projectile")) {
event.setCancelled(true);
messageManager.sendMessage(player,
skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml"))
.getFileConfiguration().getString("Island.Settings.Permission.Message"));
soundManager.playSound(player, Sounds.VILLAGER_NO.bukkitSound(), 1.0F, 1.0F);
}
}
}
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (stackableManager != null
&& stackableManager.getStackableMaterials().contains(event.getMaterial())
@ -555,17 +568,6 @@ public class Interact implements Listener {
if (!islandManager.hasPermission(player, block.getLocation(), "Redstone")) {
event.setCancelled(true);
messageManager.sendMessage(player,
skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml"))
.getFileConfiguration().getString("Island.Settings.Permission.Message"));
soundManager.playSound(player, Sounds.VILLAGER_NO.bukkitSound(), 1.0F, 1.0F);
}
}
} else if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_AIR) {
if (event.getItem() != null && event.getItem().getType() == Material.EGG) {
if (!skyblock.getIslandManager().hasPermission(player, "Projectile")) {
event.setCancelled(true);
messageManager.sendMessage(player,
skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml"))
.getFileConfiguration().getString("Island.Settings.Permission.Message"));

View File

@ -237,52 +237,4 @@ public class WildStacker implements Listener {
}
}
// TODO: Readd after WildStacker 2.7.4 is released. A feature is being added that will let us multiply the drops by 2x.
// @EventHandler
// public void onMobStack(EntityStackEvent event) {
// LivingEntity livingEntity = event.getEntity().getLivingEntity();
//
// // Certain entities shouldn't drop twice the amount
// if (livingEntity instanceof Player ||
// livingEntity instanceof ArmorStand ||
// livingEntity instanceof Horse) {
// return;
// }
//
// if (NMSUtil.getVersionNumber() > 8) {
// if (livingEntity instanceof Donkey || livingEntity instanceof Mule)
// return;
// }
//
// if (livingEntity.hasMetadata("SkyBlock")) {
// return;
// }
//
// IslandManager islandManager = skyblock.getIslandManager();
//
// if (skyblock.getWorldManager().isIslandWorld(livingEntity.getWorld())) {
// Island island = islandManager.getIslandAtLocation(livingEntity.getLocation());
//
// if (island != null) {
// List<Upgrade> upgrades = skyblock.getUpgradeManager().getUpgrades(Upgrade.Type.Drops);
//
// if (upgrades != null && upgrades.size() > 0 && upgrades.get(0).isEnabled()
// && island.isUpgrade(Upgrade.Type.Drops)) {
// StackedEntity entity = event.getEntity();
// StackedEntity target = event.getTarget();
//
// List<ItemStack> drops = target.getDrops(0);
// for (ItemStack item : drops) {
// item.setAmount(item.getAmount() * 2);
// }
//
// List<ItemStack> newDrops = entity.getDrops(0);
// newDrops.addAll(drops);
//
// entity.setTempLootTable(newDrops);
// }
// }
// }
// }
}

View File

@ -91,6 +91,10 @@ public class Weather {
event.setWillClose(false);
event.setWillDestroy(false);
} else if (is.getType() == Materials.BARRIER.parseMaterial()) {
event.setWillClose(false);
event.setWillDestroy(false);
soundManager.playSound(player, Sounds.VILLAGER_NO.bukkitSound(), 1.0F, 1.0F);
} else if ((is.getType() == Materials.SUNFLOWER.parseMaterial()) && (is.hasItemMeta())
&& (is.getItemMeta().getDisplayName().equals(ChatColor.translateAlternateColorCodes('&',
configLoad.getString("Menu.Weather.Item.Time.Displayname"))))) {

View File

@ -30,7 +30,7 @@ public class MaterialUtil {
} else if (material == Materials.LEGACY_SUGAR_CANE_BLOCK.getPostMaterial()) {
material = Material.SUGAR_CANE;
} else if (material == Material.TRIPWIRE) {
material = Material.TRIPWIRE_HOOK;
material = Material.STRING;
} else if (material == Material.FLOWER_POT) {
material = Materials.LEGACY_FLOWER_POT_ITEM.getPostMaterial();
} else if (material.name().startsWith("POTTED_")) {