From 38e1769f0d2be6ff75dc5ef5b9362ce29970cb52 Mon Sep 17 00:00:00 2001 From: ZeroEpoch1969 <13510767+ZeroEpoch1969@users.noreply.github.com> Date: Wed, 25 Jul 2018 14:23:23 -0700 Subject: [PATCH] More 1.13 things --- .../totalfreedommod/MovementValidator.java | 1 + .../totalfreedommod/TotalFreedomMod.java | 8 + .../command/Command_kicknoob.java | 6 +- .../world/CleanroomBlockPopulator.java | 62 ------ .../world/CleanroomChunkGenerator.java | 207 ++++++------------ .../totalfreedommod/world/Flatlands.java | 2 + .../totalfreedommod/world/WorldManager.java | 2 +- 7 files changed, 79 insertions(+), 209 deletions(-) delete mode 100644 src/main/java/me/totalfreedom/totalfreedommod/world/CleanroomBlockPopulator.java diff --git a/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java b/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java index b9697a2a..574d408b 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java @@ -17,6 +17,7 @@ import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.inventory.ItemStack; +import java.util.HashSet; import java.util.List; import java.util.Objects; diff --git a/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java b/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java index 51e42d16..772e3076 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java @@ -24,10 +24,12 @@ import me.totalfreedom.totalfreedommod.rollback.RollbackManager; import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.MethodTimer; +import me.totalfreedom.totalfreedommod.world.CleanroomChunkGenerator; import me.totalfreedom.totalfreedommod.world.WorldManager; import net.pravian.aero.component.service.ServiceManager; import net.pravian.aero.plugin.AeroPlugin; import org.bukkit.Bukkit; +import org.bukkit.generator.ChunkGenerator; import org.bukkit.plugin.Plugin; import org.bukkit.scheduler.BukkitRunnable; import org.mcstats.Metrics; @@ -341,4 +343,10 @@ public class TotalFreedomMod extends AeroPlugin return null; } + @Override + public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) + { + return new CleanroomChunkGenerator(id); + } + } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_kicknoob.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_kicknoob.java index 382a5af7..eec6b01f 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_kicknoob.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_kicknoob.java @@ -8,20 +8,20 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @CommandPermissions(level = Rank.SENIOR_ADMIN, source = SourceType.BOTH, blockHostConsole = true) -@CommandParameters(description = "Kick all non-superadmins on server.", usage = "/") +@CommandParameters(description = "Kick all non-admins on server.", usage = "/") public class Command_kicknoob extends FreedomCommand { @Override public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - FUtil.adminAction(sender.getName(), "Disconnecting all non-superadmins.", true); + FUtil.adminAction(sender.getName(), "Disconnecting all non-admins.", true); for (Player player : server.getOnlinePlayers()) { if (!plugin.al.isAdmin(player)) { - player.kickPlayer(ChatColor.RED + "All non-superadmins were kicked by " + sender.getName() + "."); + player.kickPlayer(ChatColor.RED + "All non-admins were kicked by " + sender.getName() + "."); } } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/world/CleanroomBlockPopulator.java b/src/main/java/me/totalfreedom/totalfreedommod/world/CleanroomBlockPopulator.java deleted file mode 100644 index 075c0e91..00000000 --- a/src/main/java/me/totalfreedom/totalfreedommod/world/CleanroomBlockPopulator.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Cleanroom Generator - * Copyright (C) 2011-2012 nvx - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package me.totalfreedom.totalfreedommod.world; - -import java.util.Random; -import org.bukkit.Chunk; -import org.bukkit.World; -import org.bukkit.generator.BlockPopulator; - -@SuppressWarnings("deprecation") -public class CleanroomBlockPopulator extends BlockPopulator -{ - - byte[] layerDataValues; - - protected CleanroomBlockPopulator(byte[] layerDataValues) - { - this.layerDataValues = layerDataValues; - } - - @Override - public void populate(World world, Random random, Chunk chunk) - { - if (layerDataValues != null) - { - int x = chunk.getX() << 4; - int z = chunk.getZ() << 4; - - for (int y = 0; y < layerDataValues.length; y++) - { - byte dataValue = layerDataValues[y]; - if (dataValue == 0) - { - continue; - } - for (int xx = 0; xx < 16; xx++) - { - for (int zz = 0; zz < 16; zz++) - { - // xd dont know what im gonna do, ill come back to this later - //world.getBlockAt(x + xx, y, z + zz).setData(dataValue); - } - } - } - } - } -} diff --git a/src/main/java/me/totalfreedom/totalfreedommod/world/CleanroomChunkGenerator.java b/src/main/java/me/totalfreedom/totalfreedommod/world/CleanroomChunkGenerator.java index 06a55fbe..fced7177 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/world/CleanroomChunkGenerator.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/world/CleanroomChunkGenerator.java @@ -15,206 +15,127 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ + package me.totalfreedom.totalfreedommod.world; -import me.totalfreedom.totalfreedommod.util.FLog; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; -import org.bukkit.generator.BlockPopulator; import org.bukkit.generator.ChunkGenerator; -import java.util.ArrayList; import java.util.Arrays; -import java.util.List; import java.util.Random; +import java.util.logging.Logger; import static java.lang.System.arraycopy; -@SuppressWarnings("deprecation") public class CleanroomChunkGenerator extends ChunkGenerator { - private short[] layer; - private byte[] layerDataValues; + private Logger log = Logger.getLogger("Minecraft"); + + private Material[] materials; public CleanroomChunkGenerator() { this("64,stone"); } - public CleanroomChunkGenerator(String id) - { - if (id != null) - { - try - { + public CleanroomChunkGenerator(String id) { + if (id != null) { + try { int y = 0; - layer = new short[128]; // Default to 128, will be resized later if required - layerDataValues = null; + materials = new Material[128]; // Default to 128, will be resized later if required - if ((id.length() > 0) && (id.charAt(0) == '.')) // Is the first character a '.'? If so, skip bedrock generation. - { + if ((id.length() > 0) && (id.charAt(0) == '.')) { + // Is the first character a '.'? If so, skip bedrock generation. id = id.substring(1); // Skip bedrock then and remove the . - } - else // Guess not, bedrock at layer0 it is then. - { - layer[y++] = (short) Material.BEDROCK.getId(); + } else { + // Guess not, bedrock at layer0 it is then. + materials[y++] = Material.BEDROCK; } - if (id.length() > 0) - { + if (id.length() > 0) { String tokens[] = id.split("[,]"); - if ((tokens.length % 2) != 0) - { - throw new Exception(); - } + if ((tokens.length % 2) != 0) throw new Exception(); - for (int i = 0; i < tokens.length; i += 2) - { + for (int i = 0; i < tokens.length; i += 2) { int height = Integer.parseInt(tokens[i]); - if (height <= 0) - { - FLog.warning("[CleanroomGenerator] Invalid height '" + tokens[i] + "'. Using 64 instead."); + if (height <= 0) { + log.warning("[CleanroomGenerator] Invalid height '" + tokens[i] + "'. Using 64 instead."); height = 64; } String materialTokens[] = tokens[i + 1].split("[:]", 2); - byte dataValue = 0; - if (materialTokens.length == 2) - { - try - { - // Lets try to read the data value - dataValue = Byte.parseByte(materialTokens[1]); - } - catch (Exception e) - { - FLog.warning("[CleanroomGenerator] Invalid Data Value '" + materialTokens[1] + "'. Defaulting to 0."); - dataValue = 0; - } + + if (materialTokens.length == 2) { + log.warning("[CleanroomGenerator] Data values are no longer supported in 1.13. Defaulting to the base material for " + materialTokens[0]); } + + log.warning(materialTokens[0]); + Material mat = Material.matchMaterial(materialTokens[0]); - if (mat == null) - { - try - { - // Mabe it's an integer? - mat = Material.getMaterial(String.valueOf(materialTokens[0])); - } - catch (Exception e) - { - // Well, I guess it wasn't an integer after all... Awkward... - } - - if (mat == null) - { - FLog.warning("[CleanroomGenerator] Invalid Block ID '" + materialTokens[0] + "'. Defaulting to stone."); - mat = Material.STONE; - } - } - - if (!mat.isBlock()) - { - FLog.warning("[CleanroomGenerator] Error, '" + materialTokens[0] + "' is not a block. Defaulting to stone."); + if (mat == null) { + log.warning("[CleanroomGenerator] Invalid Block ID '" + materialTokens[0] + "'. Defaulting to stone. (Integer IDs were removed in 1.13)"); mat = Material.STONE; } - if (y + height > layer.length) - { - short[] newLayer = new short[Math.max(y + height, layer.length * 2)]; - arraycopy(layer, 0, newLayer, 0, y); - layer = newLayer; - if (layerDataValues != null) - { - byte[] newLayerDataValues = new byte[Math.max(y + height, layerDataValues.length * 2)]; - arraycopy(layerDataValues, 0, newLayerDataValues, 0, y); - layerDataValues = newLayerDataValues; - } + if (!mat.isBlock()) { + log.warning("[CleanroomGenerator] Error, '" + materialTokens[0] + "' is not a block. Defaulting to stone."); + mat = Material.STONE; } - Arrays.fill(layer, y, y + height, (short) mat.getId()); - if (dataValue != 0) - { - if (layerDataValues == null) - { - layerDataValues = new byte[layer.length]; - } - Arrays.fill(layerDataValues, y, y + height, dataValue); + if (y + height > materials.length) { + Material[] newMaterials = new Material[Math.max(y + height, materials.length * 2)]; + + arraycopy(materials, 0, newMaterials, 0, y); + materials = newMaterials; } + + Arrays.fill(materials, y, y + height, mat); y += height; } } // Trim to size - if (layer.length > y) - { - short[] newLayer = new short[y]; - arraycopy(layer, 0, newLayer, 0, y); - layer = newLayer; + if (materials.length > y) { + Material[] newMaterials = new Material[y]; + arraycopy(materials, 0, newMaterials, 0, y); + materials = newMaterials; } - if (layerDataValues != null && layerDataValues.length > y) - { - byte[] newLayerDataValues = new byte[y]; - arraycopy(layerDataValues, 0, newLayerDataValues, 0, y); - layerDataValues = newLayerDataValues; - } - } - catch (Exception e) - { - FLog.severe("[CleanroomGenerator] Error parsing CleanroomGenerator ID '" + id + "'. using defaults '64,1': " + e.toString()); + } catch (Exception e) { + log.severe("[CleanroomGenerator] Error parsing CleanroomGenerator ID '" + id + "'. using defaults '64,1': " + e.toString()); e.printStackTrace(); - layerDataValues = null; - layer = new short[65]; - layer[0] = (short) Material.BEDROCK.getId(); - Arrays.fill(layer, 1, 65, (short) Material.STONE.getId()); - } - } - else - { - layerDataValues = null; - layer = new short[65]; - layer[0] = (short) Material.BEDROCK.getId(); - Arrays.fill(layer, 1, 65, (short) Material.STONE.getId()); - } - } - public short[][] generateExtBlockSections(World world, Random random, int x, int z, BiomeGrid biomes) - { - int maxHeight = world.getMaxHeight(); - if (layer.length > maxHeight) - { - FLog.warning("[CleanroomGenerator] Error, chunk height " + layer.length + " is greater than the world max height (" + maxHeight + "). Trimming to world max height."); - short[] newLayer = new short[maxHeight]; - arraycopy(layer, 0, newLayer, 0, maxHeight); - layer = newLayer; - } - short[][] result = new short[maxHeight / 16][]; // 16x16x16 chunks - for (int i = 0; i < layer.length; i += 16) - { - result[i >> 4] = new short[4096]; - for (int y = 0; y < Math.min(16, layer.length - i); y++) - { - Arrays.fill(result[i >> 4], y * 16 * 16, (y + 1) * 16 * 16, layer[i + y]); + materials = new Material[65]; + materials[0] = Material.BEDROCK; + Arrays.fill(materials, 1, 65, Material.STONE); } + } else { + materials = new Material[65]; + materials[0] = Material.BEDROCK; + Arrays.fill(materials, 1, 65, Material.STONE); } - - return result; } @Override - public List getDefaultPopulators(World world) - { - if (layerDataValues != null) - { - return Arrays.asList((BlockPopulator) new CleanroomBlockPopulator(layerDataValues)); + public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome) { + int maxHeight = world.getMaxHeight(); + if (materials.length > maxHeight) { + log.warning("[CleanroomGenerator] Error, chunk height " + materials.length + " is greater than the world max height (" + maxHeight + "). Trimming to world max height."); + Material[] newMaterials = new Material[maxHeight]; + arraycopy(materials, 0, newMaterials, 0, maxHeight); + materials = newMaterials; } - else - { - // This is the default, but just in case default populators change to stock minecraft populators by default... - return new ArrayList<>(); + + ChunkData result = createChunkData(world); + + for (int i = 0; i < materials.length; i++) { + result.setRegion(0, i, 0, 15, i, 15, materials[i]); } + + return result; } @Override diff --git a/src/main/java/me/totalfreedom/totalfreedommod/world/Flatlands.java b/src/main/java/me/totalfreedom/totalfreedommod/world/Flatlands.java index d151a671..4245f78b 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/world/Flatlands.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/world/Flatlands.java @@ -63,6 +63,8 @@ public class Flatlands extends CustomWorld return world; } + + public void wipeFlatlandsIfFlagged() { boolean doFlatlandsWipe = false; diff --git a/src/main/java/me/totalfreedom/totalfreedommod/world/WorldManager.java b/src/main/java/me/totalfreedom/totalfreedommod/world/WorldManager.java index 16544874..5850950c 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/world/WorldManager.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/world/WorldManager.java @@ -37,7 +37,7 @@ public class WorldManager extends FreedomService protected void onStart() { // Disabled temporarily - //flatlands.getWorld(); + flatlands.getWorld(); //adminworld.getWorld(); //masterBuilderWorld.getWorld();