1.8.8 compatibility (almost)

This commit is contained in:
Fabrizio La Rosa 2020-06-16 01:39:26 +02:00
parent 7bd6d5aa08
commit 0c1b75d222
10 changed files with 102 additions and 69 deletions

View File

@ -160,7 +160,7 @@ public class Challenge {
ItemStack is = (ItemStack) obj; ItemStack is = (ItemStack) obj;
//p.getInventory().removeItem(new ItemStack(is.getType(), is.getAmount())); //p.getInventory().removeItem(new ItemStack(is.getType(), is.getAmount()));
int toRemove = is.getAmount(); int toRemove = is.getAmount();
for(ItemStack jis : p.getInventory().getStorageContents()) { for(ItemStack jis : p.getInventory().getContents()) {
if(jis != null && jis.isSimilar(is)) { if(jis != null && jis.isSimilar(is)) {
if(jis.getAmount() <= toRemove) { if(jis.getAmount() <= toRemove) {
toRemove -= jis.getAmount(); toRemove -= jis.getAmount();

View File

@ -61,8 +61,8 @@ public class ChallengeCategory {
Challenge c = new Challenge(this, id, name, maxTimes, showInChat, require, reward, ic); Challenge c = new Challenge(this, id, name, maxTimes, showInChat, require, reward, ic);
challenges.put(id, c); challenges.put(id, c);
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
throw new IllegalArgumentException("Exception at category " + this.name + "(" + this.id throw new IllegalArgumentException("Exception at category " + this.name.replace("&", "") + "(" + this.id
+ ") at challenge " + name + "(" + id + "): " + ex.getMessage()); + ") at challenge " + name.replace("&", "") + "(" + id + "): " + ex.getMessage());
} }
} }
Bukkit.getConsoleSender().sendMessage("[FabledSkyBlock] " + ChatColor.GREEN + "Category " + name + ChatColor.GREEN Bukkit.getConsoleSender().sendMessage("[FabledSkyBlock] " + ChatColor.GREEN + "Category " + name + ChatColor.GREEN

View File

@ -47,7 +47,6 @@ import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.IllegalPluginAccessException;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;

View File

@ -25,9 +25,8 @@ import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.block.CreatureSpawner; import org.bukkit.block.CreatureSpawner;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.ArmorStand; import org.bukkit.entity.*;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -323,22 +322,29 @@ public class Block implements Listener {
if(configLoad.getBoolean("Island.Nether.WaterDoNotFlowNearNetherMobs", false) && worldManager.getIslandWorld(block.getWorld()).equals(IslandWorld.Nether)){ if(configLoad.getBoolean("Island.Nether.WaterDoNotFlowNearNetherMobs", false) && worldManager.getIslandWorld(block.getWorld()).equals(IslandWorld.Nether)){
Collection<Entity> entities = block.getWorld().getNearbyEntities(block.getLocation(), 1d, 1d, 1d); Collection<Entity> entities = block.getWorld().getNearbyEntities(block.getLocation(), 1d, 1d, 1d);
if(entities.size() > 0){ if(entities.size() > 0){
EntityCycle: for(Entity ent : entities){ for(Entity ent : entities){
switch(ent.getType()){ boolean witherSkeleton;
case PIG_ZOMBIE: if (NMSUtil.getVersionNumber() > 10) {
case BLAZE: witherSkeleton = ent.getType().equals(EntityType.WITHER_SKELETON);
case MAGMA_CUBE: } else {
case WITHER_SKELETON: witherSkeleton = ent instanceof Skeleton && ((Skeleton) ent).getSkeletonType().equals(Skeleton.SkeletonType.WITHER);
case WITHER: }
case GHAST: if (ent.getType().equals(EntityType.PIG_ZOMBIE) ||
if(block.getRelative(event.getFace().getOppositeFace()).getType().equals(Material.WATER)){ ent.getType().equals(EntityType.BLAZE) ||
event.setCancelled(true); ent.getType().equals(EntityType.MAGMA_CUBE) ||
ent.getType().equals(EntityType.WITHER) ||
ent.getType().equals(EntityType.GHAST) ||
witherSkeleton) {
if(block.getRelative(event.getFace().getOppositeFace()).getType().equals(Material.WATER)){
event.setCancelled(true);
if(NMSUtil.getVersionNumber() > 8){
event.getToBlock().getWorld().playSound(block.getLocation(), Sound.BLOCK_FIRE_EXTINGUISH, 1f, 1f); event.getToBlock().getWorld().playSound(block.getLocation(), Sound.BLOCK_FIRE_EXTINGUISH, 1f, 1f);
event.getToBlock().getWorld().playEffect(block.getLocation(), Effect.SMOKE, 1); } else {
// TODO Find a sound for 1.8
} }
break EntityCycle; // TODO No spaghetti code event.getToBlock().getWorld().playEffect(block.getLocation(), Effect.SMOKE, 1);
default: }
break; break;
} }
} }
} }
@ -638,7 +644,7 @@ public class Block implements Listener {
// PortalCreateEvent.getBlocks() changed from ArrayList<Block> to // PortalCreateEvent.getBlocks() changed from ArrayList<Block> to
// ArrayList<BlockState> in 1.14.1 // ArrayList<BlockState> in 1.14.1
if (NMSUtil.getVersionNumber() > 13) { if (NMSUtil.getVersionNumber() > 13) {
List<BlockState> blocks = event.getBlocks(); List<BlockState> blocks = event.getBlocks(); // TODO 1.8
if (event.getBlocks().isEmpty()) return; if (event.getBlocks().isEmpty()) return;
Island island = islandManager.getIslandAtLocation(event.getBlocks().get(0).getLocation()); Island island = islandManager.getIslandAtLocation(event.getBlocks().get(0).getLocation());

View File

@ -18,6 +18,7 @@ import com.songoda.skyblock.stackable.Stackable;
import com.songoda.skyblock.stackable.StackableManager; import com.songoda.skyblock.stackable.StackableManager;
import com.songoda.skyblock.utils.NumberUtil; import com.songoda.skyblock.utils.NumberUtil;
import com.songoda.skyblock.utils.structure.StructureUtil; import com.songoda.skyblock.utils.structure.StructureUtil;
import com.songoda.skyblock.utils.version.NMSUtil;
import com.songoda.skyblock.utils.world.LocationUtil; import com.songoda.skyblock.utils.world.LocationUtil;
import com.songoda.skyblock.world.WorldManager; import com.songoda.skyblock.world.WorldManager;
import org.apache.commons.lang.WordUtils; import org.apache.commons.lang.WordUtils;
@ -121,7 +122,12 @@ public class Interact implements Listener {
if(configLoad.getBoolean("Island.Nether.AllowNetherWater", false)){ if(configLoad.getBoolean("Island.Nether.AllowNetherWater", false)){
event.setCancelled(true); event.setCancelled(true);
block.setType(Material.WATER, true); block.setType(Material.WATER, true);
block.getWorld().playSound(block.getLocation(), Sound.ITEM_BUCKET_EMPTY, 1f, 1f); if(NMSUtil.getVersionNumber() > 8){
block.getWorld().playSound(block.getLocation(), Sound.ITEM_BUCKET_EMPTY, 1f, 1f);
} else {
//block.getWorld().playSound(block.getLocation(), Sound.SPLASH, 1f, 1f);
// TODO Find a sound for 1.8
}
if(!event.getPlayer().getGameMode().equals(GameMode.CREATIVE)){ if(!event.getPlayer().getGameMode().equals(GameMode.CREATIVE)){
event.getItem().setType(Material.BUCKET); event.getItem().setType(Material.BUCKET);
} }

View File

@ -123,7 +123,7 @@ public class Leaderboard {
2); 2);
} else { } else {
nInv.addItem( nInv.addItem(
nInv.createItem(new ItemStack(Material.GRAY_STAINED_GLASS_PANE), "", null, null, null, null), 2); nInv.createItem(CompatibleMaterial.BLACK_STAINED_GLASS_PANE.getItem(), "", null, null, null, null), 2);
} }
nInv.addItem( nInv.addItem(
nInv.createItem(new ItemStack(Material.EMERALD), configLoad nInv.createItem(new ItemStack(Material.EMERALD), configLoad

View File

@ -11,6 +11,7 @@ import com.songoda.skyblock.leaderboard.Leaderboard;
import com.songoda.skyblock.leaderboard.LeaderboardManager; import com.songoda.skyblock.leaderboard.LeaderboardManager;
import com.songoda.skyblock.utils.NumberUtil; import com.songoda.skyblock.utils.NumberUtil;
import com.songoda.skyblock.utils.player.OfflinePlayer; import com.songoda.skyblock.utils.player.OfflinePlayer;
import com.songoda.skyblock.utils.version.NMSUtil;
import com.songoda.skyblock.utils.world.LocationUtil; import com.songoda.skyblock.utils.world.LocationUtil;
import com.songoda.skyblock.visit.Visit; import com.songoda.skyblock.visit.Visit;
import org.bukkit.*; import org.bukkit.*;
@ -18,7 +19,9 @@ import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Skeleton;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import java.io.File; import java.io.File;
@ -51,28 +54,22 @@ public class MobNetherWaterTask extends BukkitRunnable {
.getFileConfiguration().getBoolean("Island.Nether.WaterDisappearWithNetherMobs", false)){ .getFileConfiguration().getBoolean("Island.Nether.WaterDisappearWithNetherMobs", false)){
for(World world : Bukkit.getServer().getWorlds()){ for(World world : Bukkit.getServer().getWorlds()){
if(plugin.getWorldManager().isIslandWorld(world) && plugin.getWorldManager().getIslandWorld(world).equals(IslandWorld.Nether)){ if(plugin.getWorldManager().isIslandWorld(world) && plugin.getWorldManager().getIslandWorld(world).equals(IslandWorld.Nether)){
for(Entity ent : world.getEntities()){ for(Entity ent : world.getEntities()) {
switch(ent.getType()){ boolean witherSkeleton;
case PIG_ZOMBIE: if (NMSUtil.getVersionNumber() > 10) {
case BLAZE: witherSkeleton = ent.getType().equals(EntityType.WITHER_SKELETON);
case MAGMA_CUBE: } else {
case WITHER_SKELETON: witherSkeleton = ent instanceof Skeleton && ((Skeleton) ent).getSkeletonType().equals(Skeleton.SkeletonType.WITHER);
case WITHER: }
case GHAST: if (ent.getType().equals(EntityType.PIG_ZOMBIE) ||
Block block = ent.getLocation().getBlock(); ent.getType().equals(EntityType.BLAZE) ||
if(block.getType().equals(Material.WATER)){ ent.getType().equals(EntityType.MAGMA_CUBE) ||
block.setType(Material.AIR, true); ent.getType().equals(EntityType.WITHER) ||
world.playSound(block.getLocation(), Sound.BLOCK_FIRE_EXTINGUISH, 1f, 1f); ent.getType().equals(EntityType.GHAST) ||
world.playEffect(block.getLocation(), Effect.SMOKE, 1); witherSkeleton) {
} Block block = ent.getLocation().getBlock();
block = block.getRelative(BlockFace.UP); removeWater(world, block);
if(block.getType().equals(Material.WATER)){ removeWater(world, block.getRelative(BlockFace.UP));
block.setType(Material.AIR, true);
world.playSound(block.getLocation(), Sound.BLOCK_FIRE_EXTINGUISH, 1f, 1f);
world.playEffect(block.getLocation(), Effect.SMOKE, 1);
}
default:
break;
} }
} }
} }
@ -80,6 +77,18 @@ public class MobNetherWaterTask extends BukkitRunnable {
} }
} }
private void removeWater(World world, Block block) {
if (block.getType().equals(Material.WATER)) {
block.setType(Material.AIR, true);
if(NMSUtil.getVersionNumber() > 8){
world.playSound(block.getLocation(), Sound.BLOCK_FIRE_EXTINGUISH, 1f, 1f);
} else {
// TODO Find a sound for 1.8
}
world.playEffect(block.getLocation(), Effect.SMOKE, 1);
}
}
public void onDisable() { public void onDisable() {
} }

View File

@ -9,13 +9,13 @@ import com.songoda.skyblock.island.IslandEnvironment;
import com.songoda.skyblock.island.IslandManager; import com.songoda.skyblock.island.IslandManager;
import com.songoda.skyblock.island.IslandWorld; import com.songoda.skyblock.island.IslandWorld;
import com.songoda.skyblock.utils.math.VectorUtil; import com.songoda.skyblock.utils.math.VectorUtil;
import com.songoda.skyblock.utils.version.NMSUtil;
import com.songoda.skyblock.utils.world.block.BlockDegreesType; import com.songoda.skyblock.utils.world.block.BlockDegreesType;
import com.songoda.skyblock.world.WorldManager; import com.songoda.skyblock.world.WorldManager;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.World.Environment; import org.bukkit.World.Environment;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.block.data.Waterlogged;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.io.File; import java.io.File;
@ -32,10 +32,8 @@ public final class LocationUtil {
Location tempLoc = LocationUtil.getDefinitiveLocation(loc); Location tempLoc = LocationUtil.getDefinitiveLocation(loc);
if(tempLoc.getBlock().getType().equals(Material.WATER)){ if(tempLoc.getBlock().getType().equals(Material.WATER)){
tempLoc.getBlock().setType(Material.AIR); tempLoc.getBlock().setType(Material.AIR);
} else if(tempLoc.getBlock().getBlockData() instanceof Waterlogged){ } else if(NMSUtil.getVersionNumber() > 13){
Waterlogged blockData = (Waterlogged) tempLoc.getBlock().getBlockData(); LocationUtil113.removeWaterLoggedFromLocation(tempLoc);
blockData.setWaterlogged(false);
tempLoc.getBlock().setBlockData(blockData);
} }
} }
} }
@ -66,7 +64,8 @@ public final class LocationUtil {
Location locWorking = loc.clone(); Location locWorking = loc.clone();
for(int i=locWorking.getBlockY(); i>=0; i--){ for(int i=locWorking.getBlockY(); i>=0; i--){
if(!locWorking.getBlock().isEmpty()){ if(!locWorking.getBlock().isEmpty()){
if(locWorking.getBlock().getType().equals(Material.WATER) || locWorking.getBlock().getBlockData() instanceof Waterlogged){ if(locWorking.getBlock().getType().equals(Material.WATER) ||
(NMSUtil.getVersionNumber() > 13 && locWorking.getBlock().getBlockData() instanceof org.bukkit.block.data.Waterlogged)){
loc = locWorking; loc = locWorking;
} }
break; break;
@ -79,39 +78,38 @@ public final class LocationUtil {
boolean safe = false; boolean safe = false;
if(!locChecked.getBlock().isEmpty() && if(!locChecked.getBlock().isEmpty() &&
!locChecked.getBlock().isLiquid() && !locChecked.getBlock().isLiquid() &&
!locChecked.getBlock().isPassable() &&
locChecked.getBlock().getType().isSolid() && locChecked.getBlock().getType().isSolid() &&
locChecked.getBlock().getType().isBlock() && locChecked.getBlock().getType().isBlock() &&
locChecked.add(0d,1d,0d).getBlock().getType().isAir() && locChecked.add(0d,1d,0d).getBlock().getType().equals(Material.AIR) &&
locChecked.add(0d,2d,0d).getBlock().getType().isAir() && locChecked.add(0d,2d,0d).getBlock().getType().equals(Material.AIR) &&
!(locChecked.getBlock().getBlockData() instanceof Waterlogged)){ !(NMSUtil.getVersionNumber() <= 13 || locChecked.getBlock().getBlockData() instanceof org.bukkit.block.data.Waterlogged)){
safe = true; safe = true;
switch(locChecked.getBlock().getType()){ switch(locChecked.getBlock().getType()){
case ACACIA_BUTTON: case ACACIA_DOOR: // <= 1.8.8
case ACACIA_DOOR:
case ACACIA_FENCE_GATE: case ACACIA_FENCE_GATE:
case ACACIA_TRAPDOOR:
case BIRCH_DOOR: case BIRCH_DOOR:
case BIRCH_FENCE_GATE: case BIRCH_FENCE_GATE:
case BIRCH_TRAPDOOR:
case CACTUS: case CACTUS:
case CAKE: case CAKE:
case CAMPFIRE:
case COBWEB:
case DARK_OAK_DOOR: case DARK_OAK_DOOR:
case DARK_OAK_FENCE_GATE: case DARK_OAK_FENCE_GATE:
case DARK_OAK_TRAPDOOR:
case IRON_TRAPDOOR: case IRON_TRAPDOOR:
case JUNGLE_DOOR: case JUNGLE_DOOR:
case JUNGLE_FENCE_GATE: case JUNGLE_FENCE_GATE:
case JUNGLE_TRAPDOOR:
case LADDER: case LADDER:
case MAGMA_BLOCK:
case NETHER_PORTAL:
case OAK_DOOR:
case OAK_FENCE_GATE:
case SPRUCE_DOOR: case SPRUCE_DOOR:
case SPRUCE_FENCE_GATE: case SPRUCE_FENCE_GATE:
case ACACIA_BUTTON: // TODO check server version
case ACACIA_TRAPDOOR: // TODO check server version
case BIRCH_TRAPDOOR: // TODO check server version
case CAMPFIRE: // TODO check server version
case COBWEB: // TODO check server version
case DARK_OAK_TRAPDOOR: // TODO check server version
case JUNGLE_TRAPDOOR: // TODO check server version
case MAGMA_BLOCK: // TODO check server version
case NETHER_PORTAL: // TODO check server version
case OAK_DOOR: // TODO check server version
case OAK_FENCE_GATE: // TODO check server version
safe = false; safe = false;
break; break;
} }

View File

@ -0,0 +1,13 @@
package com.songoda.skyblock.utils.world;
import org.bukkit.Location;
public class LocationUtil113 {
public static void removeWaterLoggedFromLocation(Location loc){
if(loc.getBlock().getBlockData() instanceof org.bukkit.block.data.Waterlogged){
org.bukkit.block.data.Waterlogged blockData = (org.bukkit.block.data.Waterlogged) loc.getBlock().getBlockData();
blockData.setWaterlogged(false);
loc.getBlock().setBlockData(blockData);
}
}
}

View File

@ -498,7 +498,10 @@ public final class EntityUtil {
} }
public static boolean isMonster(EntityType type) { public static boolean isMonster(EntityType type) {
switch (type) { if (NMSUtil.getVersionNumber() > 10) {
if(type.equals(EntityType.WITHER_SKELETON)) return true; // TODO In < 11 we have SkeletonType.Wither
}
switch (type) { // TODO Check server versions
case BAT: case BAT:
case BLAZE: case BLAZE:
case CAVE_SPIDER: case CAVE_SPIDER:
@ -525,7 +528,6 @@ public final class EntityUtil {
case VINDICATOR: case VINDICATOR:
case WITCH: case WITCH:
case WITHER: case WITHER:
case WITHER_SKELETON:
case ZOMBIE: case ZOMBIE:
case ZOMBIE_VILLAGER: case ZOMBIE_VILLAGER:
return true; return true;