More 1.13 things

This commit is contained in:
ZeroEpoch1969 2018-07-25 14:23:23 -07:00
parent 113ab62f0b
commit 38e1769f0d
No known key found for this signature in database
GPG Key ID: A7BAB4E14F089CF3
7 changed files with 79 additions and 209 deletions

View File

@ -17,6 +17,7 @@ import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;

View File

@ -24,10 +24,12 @@ import me.totalfreedom.totalfreedommod.rollback.RollbackManager;
import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
import me.totalfreedom.totalfreedommod.util.MethodTimer; import me.totalfreedom.totalfreedommod.util.MethodTimer;
import me.totalfreedom.totalfreedommod.world.CleanroomChunkGenerator;
import me.totalfreedom.totalfreedommod.world.WorldManager; import me.totalfreedom.totalfreedommod.world.WorldManager;
import net.pravian.aero.component.service.ServiceManager; import net.pravian.aero.component.service.ServiceManager;
import net.pravian.aero.plugin.AeroPlugin; import net.pravian.aero.plugin.AeroPlugin;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import org.mcstats.Metrics; import org.mcstats.Metrics;
@ -341,4 +343,10 @@ public class TotalFreedomMod extends AeroPlugin<TotalFreedomMod>
return null; return null;
} }
@Override
public ChunkGenerator getDefaultWorldGenerator(String worldName, String id)
{
return new CleanroomChunkGenerator(id);
}
} }

View File

@ -8,20 +8,20 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.SENIOR_ADMIN, source = SourceType.BOTH, blockHostConsole = true) @CommandPermissions(level = Rank.SENIOR_ADMIN, source = SourceType.BOTH, blockHostConsole = true)
@CommandParameters(description = "Kick all non-superadmins on server.", usage = "/<command>") @CommandParameters(description = "Kick all non-admins on server.", usage = "/<command>")
public class Command_kicknoob extends FreedomCommand public class Command_kicknoob extends FreedomCommand
{ {
@Override @Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) 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()) for (Player player : server.getOnlinePlayers())
{ {
if (!plugin.al.isAdmin(player)) 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() + ".");
} }
} }

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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);
}
}
}
}
}
}

View File

@ -15,206 +15,127 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package me.totalfreedom.totalfreedommod.world; package me.totalfreedom.totalfreedommod.world;
import me.totalfreedom.totalfreedommod.util.FLog;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.generator.BlockPopulator;
import org.bukkit.generator.ChunkGenerator; import org.bukkit.generator.ChunkGenerator;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import java.util.Random; import java.util.Random;
import java.util.logging.Logger;
import static java.lang.System.arraycopy; import static java.lang.System.arraycopy;
@SuppressWarnings("deprecation")
public class CleanroomChunkGenerator extends ChunkGenerator public class CleanroomChunkGenerator extends ChunkGenerator
{ {
private short[] layer; private Logger log = Logger.getLogger("Minecraft");
private byte[] layerDataValues;
private Material[] materials;
public CleanroomChunkGenerator() public CleanroomChunkGenerator()
{ {
this("64,stone"); this("64,stone");
} }
public CleanroomChunkGenerator(String id) public CleanroomChunkGenerator(String id) {
{ if (id != null) {
if (id != null) try {
{
try
{
int y = 0; int y = 0;
layer = new short[128]; // Default to 128, will be resized later if required materials = new Material[128]; // Default to 128, will be resized later if required
layerDataValues = null;
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 . id = id.substring(1); // Skip bedrock then and remove the .
} } else {
else // Guess not, bedrock at layer0 it is then. // Guess not, bedrock at layer0 it is then.
{ materials[y++] = Material.BEDROCK;
layer[y++] = (short) Material.BEDROCK.getId();
} }
if (id.length() > 0) if (id.length() > 0) {
{
String tokens[] = id.split("[,]"); String tokens[] = id.split("[,]");
if ((tokens.length % 2) != 0) if ((tokens.length % 2) != 0) throw new Exception();
{
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]); int height = Integer.parseInt(tokens[i]);
if (height <= 0) if (height <= 0) {
{ log.warning("[CleanroomGenerator] Invalid height '" + tokens[i] + "'. Using 64 instead.");
FLog.warning("[CleanroomGenerator] Invalid height '" + tokens[i] + "'. Using 64 instead.");
height = 64; height = 64;
} }
String materialTokens[] = tokens[i + 1].split("[:]", 2); String materialTokens[] = tokens[i + 1].split("[:]", 2);
byte dataValue = 0;
if (materialTokens.length == 2) if (materialTokens.length == 2) {
{ log.warning("[CleanroomGenerator] Data values are no longer supported in 1.13. Defaulting to the base material for " + materialTokens[0]);
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;
}
} }
log.warning(materialTokens[0]);
Material mat = Material.matchMaterial(materialTokens[0]); Material mat = Material.matchMaterial(materialTokens[0]);
if (mat == null) if (mat == null) {
{ log.warning("[CleanroomGenerator] Invalid Block ID '" + materialTokens[0] + "'. Defaulting to stone. (Integer IDs were removed in 1.13)");
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.");
mat = Material.STONE; mat = Material.STONE;
} }
if (y + height > layer.length) if (!mat.isBlock()) {
{ log.warning("[CleanroomGenerator] Error, '" + materialTokens[0] + "' is not a block. Defaulting to stone.");
short[] newLayer = new short[Math.max(y + height, layer.length * 2)]; mat = Material.STONE;
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;
}
} }
Arrays.fill(layer, y, y + height, (short) mat.getId()); if (y + height > materials.length) {
if (dataValue != 0) Material[] newMaterials = new Material[Math.max(y + height, materials.length * 2)];
{
if (layerDataValues == null) arraycopy(materials, 0, newMaterials, 0, y);
{ materials = newMaterials;
layerDataValues = new byte[layer.length];
}
Arrays.fill(layerDataValues, y, y + height, dataValue);
} }
Arrays.fill(materials, y, y + height, mat);
y += height; y += height;
} }
} }
// Trim to size // Trim to size
if (layer.length > y) if (materials.length > y) {
{ Material[] newMaterials = new Material[y];
short[] newLayer = new short[y]; arraycopy(materials, 0, newMaterials, 0, y);
arraycopy(layer, 0, newLayer, 0, y); materials = newMaterials;
layer = newLayer;
} }
if (layerDataValues != null && layerDataValues.length > y) } catch (Exception e) {
{ log.severe("[CleanroomGenerator] Error parsing CleanroomGenerator ID '" + id + "'. using defaults '64,1': " + e.toString());
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());
e.printStackTrace(); 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) materials = new Material[65];
{ materials[0] = Material.BEDROCK;
int maxHeight = world.getMaxHeight(); Arrays.fill(materials, 1, 65, Material.STONE);
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]);
} }
} else {
materials = new Material[65];
materials[0] = Material.BEDROCK;
Arrays.fill(materials, 1, 65, Material.STONE);
} }
return result;
} }
@Override @Override
public List<BlockPopulator> getDefaultPopulators(World world) public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome) {
{ int maxHeight = world.getMaxHeight();
if (layerDataValues != null) 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.");
return Arrays.asList((BlockPopulator) new CleanroomBlockPopulator(layerDataValues)); Material[] newMaterials = new Material[maxHeight];
arraycopy(materials, 0, newMaterials, 0, maxHeight);
materials = newMaterials;
} }
else
{ ChunkData result = createChunkData(world);
// This is the default, but just in case default populators change to stock minecraft populators by default...
return new ArrayList<>(); for (int i = 0; i < materials.length; i++) {
result.setRegion(0, i, 0, 15, i, 15, materials[i]);
} }
return result;
} }
@Override @Override

View File

@ -63,6 +63,8 @@ public class Flatlands extends CustomWorld
return world; return world;
} }
public void wipeFlatlandsIfFlagged() public void wipeFlatlandsIfFlagged()
{ {
boolean doFlatlandsWipe = false; boolean doFlatlandsWipe = false;

View File

@ -37,7 +37,7 @@ public class WorldManager extends FreedomService
protected void onStart() protected void onStart()
{ {
// Disabled temporarily // Disabled temporarily
//flatlands.getWorld(); flatlands.getWorld();
//adminworld.getWorld(); //adminworld.getWorld();
//masterBuilderWorld.getWorld(); //masterBuilderWorld.getWorld();