Merge remote-tracking branch 'refs/remotes/origin/develop' into feature/gem-hunters

This commit is contained in:
Sam 2017-03-02 20:30:00 +00:00
commit 4211682ca2
16 changed files with 286 additions and 158 deletions

View File

@ -26,7 +26,7 @@ public class EnderchestWorldLoader
{
TimingManager.start(TIMINGS_PREFIX + "DownloadMap");
String fileName = mapType + "_map.zip";
File f = _webCall.getFile("map/" + mapType + "/random", fileName);
File f = _webCall.getFile("map/" + mapType + "/next", fileName);
TimingManager.stop(TIMINGS_PREFIX + "DownloadMap");
TimingManager.start(TIMINGS_PREFIX + "CreateFolders");

View File

@ -236,11 +236,11 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
if (event.getType() != UpdateType.TICK)
return;
_animation.itemClean();
if (!_enabled)
return;
_animation.itemClean();
if (!_animationRunning)
return;

View File

@ -170,7 +170,8 @@ public class PowerPlayClubButton implements GuiItem
public static boolean isAvailable(Player player, PowerPlayClubRepository repo)
{
return !repo.getCachedData(player).getUnclaimedMonths().isEmpty();
PowerPlayData data = repo.getCachedData(player);
return data != null && !data.getUnclaimedMonths().isEmpty();
}
}

View File

@ -146,11 +146,14 @@ public class Chat extends MiniPlugin
if (event.getMessage().toLowerCase().startsWith("/me ")
|| event.getMessage().toLowerCase().startsWith("/bukkit")
|| event.getMessage().toLowerCase().startsWith("/minecraft"))
{
if (!event.getPlayer().isOp())
{
event.getPlayer().sendMessage(F.main(getName(), "Nope, not allowed!"));
event.setCancelled(true);
}
}
}
@EventHandler
public void lagTest(PlayerCommandPreprocessEvent event)

View File

@ -169,8 +169,12 @@ public class PetManager extends MiniClientPlugin<PetClient>
if (player != null && player.isOnline())
{
getActivePet(playerName).setCustomNameVisible(true);
getActivePet(playerName).setCustomName(_petRenameQueue.get(playerName));
Creature activePet = getActivePet(playerName);
if (activePet != null)
{
activePet.setCustomNameVisible(true);
activePet.setCustomName(_petRenameQueue.get(playerName));
}
}
}

View File

@ -325,7 +325,8 @@ public class TreasureLocation implements Listener
event.setTo(newTo);
}
}
else
else if (event.getFrom().getWorld().equals(_currentTreasure.getCenterBlock().getWorld()) &&
event.getTo().getWorld().equals(_currentTreasure.getCenterBlock().getWorld()))
{
Location fromLocation = event.getFrom();
Location toLocation = event.getTo();

View File

@ -254,6 +254,9 @@ public class NewsManager extends MiniPlugin
if (event.getType() != UpdateType.FASTEST)
return;
if (_news.length == 0)
return;
String text = "";
double healthPercent = 1;

View File

@ -1,69 +1,138 @@
package nautilus.game.arcade.uhc;
import net.minecraft.server.v1_8_R3.BiomeBase;
import org.apache.commons.io.FileUtils;
import org.bukkit.Bukkit;
import org.bukkit.Difficulty;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.spigotmc.WatchdogThread;
import org.zeroturnaround.zip.ZipEntrySource;
import org.zeroturnaround.zip.ZipUtil;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;
import java.util.logging.Level;
import java.util.zip.ZipEntry;
public class WorldGen extends JavaPlugin implements Runnable, Listener
import net.minecraft.server.v1_8_R3.BiomeBase;
import org.apache.commons.io.FileUtils;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Difficulty;
import org.bukkit.World;
import org.bukkit.WorldBorder;
import org.bukkit.WorldCreator;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
import org.bukkit.entity.Entity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
import org.bukkit.event.world.ChunkUnloadEvent;
import org.bukkit.event.world.WorldInitEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.spigotmc.WatchdogThread;
import org.zeroturnaround.zip.ByteSource;
import org.zeroturnaround.zip.FileSource;
import org.zeroturnaround.zip.ZipEntrySource;
import org.zeroturnaround.zip.ZipUtil;
import org.zeroturnaround.zip.commons.IOUtils;
public class WorldGen extends JavaPlugin implements Listener
{
private static final int MIN_X = -1000;
private static final int MIN_Z = -1000;
private static final int MAX_X = 1000;
private static final int MAX_Z = 1000;
// The world will be -MAP_SIZE to MAP_SIZE large
private static final int MAP_SIZE = 1000;
private static final int VIEW_DISTANCE = 5;
private static final String API_HOST_FILE = "api-config.dat";
private static final Map<String, String> API_HOST_MAP = new HashMap<>();
static
{
try
{
File configFile = new File(API_HOST_FILE);
YamlConfiguration configuration = YamlConfiguration.loadConfiguration(configFile);
for (String key : configuration.getKeys(false))
{
String ip = configuration.getConfigurationSection(key).getString("ip");
// Use parseInt to catch non-ints instead of a 0
int port = Integer.parseInt(configuration.getConfigurationSection(key).getString("port"));
if (ip == null)
{
throw new NullPointerException();
}
API_HOST_MAP.put(key, ip + ":" + port);
}
}
catch (Throwable t)
{
t.printStackTrace();
}
}
@EventHandler
public void login(AsyncPlayerPreLoginEvent event)
{
event.setKickMessage("get out");
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
}
@EventHandler
public void unload(ChunkUnloadEvent event)
{
event.setCancelled(true);
}
@EventHandler
public void init(WorldInitEvent event)
{
// Prevent any eager generation
event.getWorld().setKeepSpawnInMemory(false);
}
@Override
public void onEnable()
{
getLogger().info("Cleaning up other worlds");
for (World world : getServer().getWorlds())
{
world.setKeepSpawnInMemory(false);
world.setSpawnFlags(false, false);
world.setAmbientSpawnLimit(0);
world.setAnimalSpawnLimit(0);
world.setMonsterSpawnLimit(0);
world.setWaterAnimalSpawnLimit(0);
world.getEntities().forEach(Entity::remove);
for (Chunk chunk : world.getLoadedChunks())
{
chunk.unload(false, false);
}
getServer().unloadWorld(world, false);
getLogger().info("Unloaded " + world.getName());
}
getLogger().info("Replacing biomes");
BiomeBase.getBiomes()[BiomeBase.OCEAN.id] = BiomeBase.PLAINS;
BiomeBase.getBiomes()[BiomeBase.DEEP_OCEAN.id] = BiomeBase.PLAINS;
BiomeBase.getBiomes()[BiomeBase.SWAMPLAND.id] = BiomeBase.PLAINS;
BiomeBase.getBiomes()[BiomeBase.RIVER.id] = BiomeBase.PLAINS;
getLogger().info("Forcing system GC");
System.gc();
WatchdogThread.doStop();
getServer().getScheduler().runTaskTimer(this, this, 20L, 20L * 5L);
getServer().getPluginManager().registerEvents(this, this);
}
@EventHandler
public void onJoin(AsyncPlayerPreLoginEvent event)
{
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
event.setKickMessage("Shoo, go away");
}
@Override
public void run()
{
File root = new File(".");
if (!root.exists())
{
getLogger().severe("Root folder does not exist. Aborting");
getServer().shutdown();
System.exit(0);
return;
}
@ -73,7 +142,7 @@ public class WorldGen extends JavaPlugin implements Runnable, Listener
if (!outputDirectory.mkdir())
{
getLogger().severe("Could not create output folder. Aborting");
getServer().shutdown();
System.exit(0);
return;
}
}
@ -85,6 +154,7 @@ public class WorldGen extends JavaPlugin implements Runnable, Listener
if (outputFile.exists())
{
getLogger().info("Seed " + seed + " has already been generated. Skipping");
System.exit(0);
return;
}
@ -93,30 +163,52 @@ public class WorldGen extends JavaPlugin implements Runnable, Listener
if (!outputFile.createNewFile())
{
getLogger().severe("Could not create new output file. Aborting");
getServer().shutdown();
System.exit(0);
return;
}
}
catch (IOException e)
{
getLogger().log(Level.SEVERE, "Could not create new output file. Aborting", e);
getServer().shutdown();
System.exit(0);
return;
}
File previousSession = new File("generating");
if (previousSession.exists())
{
if (!FileUtils.deleteQuietly(previousSession))
{
getLogger().severe("Could not delete previous generation session. Aborting");
System.exit(0);
return;
}
}
getLogger().info("Generating world seed " + seed);
World world = new WorldCreator("generating")
.environment(World.Environment.NORMAL)
.seed(seed)
.createWorld();
world.setDifficulty(Difficulty.HARD);
world.setKeepSpawnInMemory(false);
world.setDifficulty(Difficulty.HARD);
WorldBorder border = world.getWorldBorder();
border.setCenter(0.0, 0.0);
border.setSize(MAP_SIZE * 2);
int minChunkX = (MIN_X >> 4) - VIEW_DISTANCE;
int minChunkZ = (MIN_Z >> 4) - VIEW_DISTANCE;
int maxChunkX = (MAX_X >> 4) + VIEW_DISTANCE;
int maxChunkZ = (MAX_Z >> 4) + VIEW_DISTANCE;
int minChunkX = (-MAP_SIZE >> 4) - VIEW_DISTANCE;
int minChunkZ = (-MAP_SIZE >> 4) - VIEW_DISTANCE;
int maxChunkX = (MAP_SIZE >> 4) + VIEW_DISTANCE;
int maxChunkZ = (MAP_SIZE >> 4) + VIEW_DISTANCE;
net.minecraft.server.v1_8_R3.WorldServer nmsWorld = ((CraftWorld) world).getHandle();
//
// Field mfield = nmsWorld.getClass().getDeclaredField("M");
// mfield.setAccessible(true);
//
// HashTreeSet<NextTickListEntry> treeSet = ((HashTreeSet) mfield.get(nmsWorld));
for (int x = minChunkX; x <= maxChunkX; x++)
{
@ -124,7 +216,15 @@ public class WorldGen extends JavaPlugin implements Runnable, Listener
for (int z = minChunkZ; z <= maxChunkZ; z++)
{
world.getChunkAt(x, z).load(true);
nmsWorld.a(true);
// Manually tick blocks - this should be the equivalent of letting a full server tick run once
// between each chunk generation, except we cut out the extra useless stuff
}
// System.out.println("M: " + treeSet.size());
// System.out.println("E: " + nmsWorld.entityList.size());
// System.out.println("TE: " + nmsWorld.tileEntityList.size());
// System.out.println("C: " + nmsWorld.chunkProviderServer.chunks.size());
}
for (int x = minChunkX; x <= maxChunkX; x++)
@ -134,6 +234,11 @@ public class WorldGen extends JavaPlugin implements Runnable, Listener
{
world.getChunkAt(x, z).unload(true, false);
}
// System.out.println("M: " + treeSet.size());
// System.out.println("E: " + nmsWorld.entityList.size());
// System.out.println("TE: " + nmsWorld.tileEntityList.size());
// System.out.println("C: " + nmsWorld.chunkProviderServer.chunks.size());
}
getLogger().info("Unloading and saving world");
@ -145,10 +250,10 @@ public class WorldGen extends JavaPlugin implements Runnable, Listener
StringBuilder worldconfig = new StringBuilder();
worldconfig.append("MAP_NAME:UHC World").append(System.lineSeparator());
worldconfig.append("MAP_AUTHOR:Mineplex").append(System.lineSeparator());
worldconfig.append("MIN_X:").append(MIN_X).append(System.lineSeparator());
worldconfig.append("MIN_Z:").append(MIN_Z).append(System.lineSeparator());
worldconfig.append("MAX_X:").append(MAX_X).append(System.lineSeparator());
worldconfig.append("MAX_Z:").append(MAX_Z).append(System.lineSeparator());
worldconfig.append("MIN_X:").append(-MAP_SIZE).append(System.lineSeparator());
worldconfig.append("MIN_Z:").append(-MAP_SIZE).append(System.lineSeparator());
worldconfig.append("MAX_X:").append(MAP_SIZE).append(System.lineSeparator());
worldconfig.append("MAX_Z:").append(MAP_SIZE).append(System.lineSeparator());
for (int i = 1; i <= 60; i++)
{
worldconfig.append("TEAM_NAME:").append(i).append(System.lineSeparator());
@ -164,82 +269,68 @@ public class WorldGen extends JavaPlugin implements Runnable, Listener
if (regionFiles == null)
{
getLogger().severe("Unexpected null region files. Aborting");
getServer().shutdown();
System.exit(0);
return;
}
List<ZipEntrySource> zipEntrySourceList = new ArrayList<>();
zipEntrySourceList.add(new ZipEntrySource()
{
@Override
public String getPath()
{
return "WorldConfig.dat";
}
@Override
public ZipEntry getEntry()
{
return new ZipEntry(getPath());
}
@Override
public InputStream getInputStream() throws IOException
{
return new ByteArrayInputStream(worldconfig.toString().getBytes(StandardCharsets.UTF_8));
}
});
zipEntrySourceList.add(new ByteSource("WorldConfig.dat", worldconfig.toString().getBytes(StandardCharsets.UTF_8)));
for (File file : regionFiles)
{
zipEntrySourceList.add(new ZipEntrySource()
{
@Override
public String getPath()
{
return "region/" + file.getName();
zipEntrySourceList.add(new FileSource("region/" + file.getName(), file));
}
@Override
public ZipEntry getEntry()
{
return new ZipEntry(getPath());
}
@Override
public InputStream getInputStream() throws IOException
{
return new FileInputStream(file);
}
});
}
zipEntrySourceList.add(new ZipEntrySource()
{
@Override
public String getPath()
{
return "level.dat";
}
@Override
public ZipEntry getEntry()
{
return new ZipEntry(getPath());
}
@Override
public InputStream getInputStream() throws IOException
{
return new FileInputStream(new File(worldFolder, "level.dat"));
}
});
zipEntrySourceList.add(new FileSource("level.dat", new File(worldFolder, "level.dat")));
ZipUtil.pack(zipEntrySourceList.toArray(new ZipEntrySource[zipEntrySourceList.size()]), outputFile);
FileUtils.deleteQuietly(worldFolder);
try
{
getLogger().info("Uploading " + seed + "!");
URL url = new URL("http://" + API_HOST_MAP.get("ENDERCHEST") + "/map/uhc/upload?name=" + outputFile.getName());
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
IOUtils.copy(new FileInputStream(outputFile), connection.getOutputStream());
connection.connect();
if (connection.getResponseCode() != 200)
{
if (connection.getResponseCode() == 409)
{
getLogger().warning("Oops - Server rejected " + seed + " because it was already generated");
if (!outputFile.delete())
{
getLogger().warning("Could not clean up " + seed);
}
}
else
{
getLogger().severe("Failed to upload " + seed + ": " + connection.getResponseCode() + " " + connection.getResponseMessage());
}
}
else
{
getLogger().info("Uploaded " + seed + "!");
if (!outputFile.delete())
{
getLogger().warning("Could not clean up " + seed);
}
}
}
catch (IOException e)
{
getLogger().log(Level.SEVERE, "An error occurred while uploading " + seed + "!", e);
}
finally
{
getLogger().info("Finished generating world seed " + seed);
}
Bukkit.shutdown();
}
}

View File

@ -414,6 +414,12 @@ public class Minestrike extends TeamGame
int amount;
String gunType = (String) event.GetLog().GetLastDamager().GetDamage().getFirst().getMetadata().get("gunType");
if (gunType == null)
{
amount = 300;
}
else
{
switch (gunType)
{
case "AWP":
@ -431,6 +437,7 @@ public class Minestrike extends TeamGame
default:
amount = 300;
}
}
_shopManager.addMoney(killer, amount, "kill with " + event.GetLog().GetLastDamager().GetReason());

View File

@ -193,7 +193,7 @@ public class PerkBoneRush extends SmashPerk implements IThrown
return;
}
if (!(target instanceof Player || data.getThrower() instanceof Player))
if (!(target instanceof Player) || !(data.getThrower() instanceof Player))
{
return;
}

View File

@ -102,11 +102,6 @@ public class PerkFishFlurry extends SmashPerk implements IThrown
return;
}
if (!Recharge.Instance.use(player, GetName(), COOLDOWN, true, true))
{
return;
}
event.setCancelled(true);
Set<Block> blocks = new HashSet<>();
@ -131,11 +126,19 @@ public class PerkFishFlurry extends SmashPerk implements IThrown
blocks.add(cur);
}
if (!blocks.isEmpty())
{
if (!Recharge.Instance.use(player, GetName(), COOLDOWN, true, true))
{
return;
}
_active.add(new DataSquidGeyser(player, blocks));
// Inform
UtilPlayer.message(player, F.main("Game", "You used " + F.skill(GetName()) + "."));
}
}
@EventHandler
public void update(UpdateEvent event)

View File

@ -169,7 +169,7 @@ public class PerkWitherImage extends SmashPerk
}
}
if (event.getTarget() != null && _skeletons.get(event.getTarget().getUniqueId()).equals(event.getEntity()))
if (event.getTarget() != null && event.getEntity().equals(_skeletons.get(event.getTarget().getUniqueId())))
{
event.setCancelled(true);
}

View File

@ -503,6 +503,12 @@ public class PerkWolf extends SmashPerk
UUID uuid = playerIterator.next();
Player player = UtilPlayer.searchExact(uuid);
if (player == null)
{
playerIterator.remove();
continue;
}
Iterator<Long> timeIterator = _repeat.get(uuid).iterator();
while (timeIterator.hasNext())

View File

@ -365,17 +365,19 @@ public abstract class UHC extends Game
UtilPlayer.message(caller, F.main("Debug", "World info for " + targetWorld.getName()));
UtilPlayer.message(caller, F.desc("Chunks", String.valueOf(chunks.length)));
UtilPlayer.message(caller, F.desc("Entities", String.valueOf(targetWorld.getEntities().size())));
UtilPlayer.message(caller, F.desc("Tile Entities", String.valueOf(Arrays.stream(chunks).map(Chunk::getTileEntities).map(Arrays::asList).flatMap(Collection::stream)
.count())));
UtilPlayer.message(caller, F.desc("Tile Entities", String.valueOf(Arrays.stream(chunks).map(Chunk::getTileEntities).map(Arrays::asList).mapToLong(Collection::size).sum())));
UtilPlayer.message(caller, F.desc("View Distance", String.valueOf(nmsWorld.spigotConfig.viewDistance)));
UtilPlayer.message(caller, F.desc("Unload queue size", String.valueOf(nmsWorld.chunkProviderServer.unloadQueue.size())));
try
{
HashTreeSet<NextTickListEntry> m = (HashTreeSet<NextTickListEntry>) nmsWorld.getClass().getField("M").get(nmsWorld);
Field f = nmsWorld.getClass().getDeclaredField("M");
f.setAccessible(true);
HashTreeSet<NextTickListEntry> m = (HashTreeSet<NextTickListEntry>) f.get(nmsWorld);
UtilPlayer.message(caller, F.desc("Pending tick", String.valueOf(m.size())));
}
catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e)
catch (ReflectiveOperationException e)
{
e.printStackTrace();
}
@ -571,7 +573,7 @@ public abstract class UHC extends Game
}
}
});
registerDebugCommand(new DebugCommand("uhccallchunks", Rank.DEVELOPER)
registerDebugCommand(new DebugCommand("uhcallchunks", Rank.DEVELOPER)
{
@Override

View File

@ -255,6 +255,9 @@ public class WitherGame extends TeamGame implements IBlockRestorer
if (GetState() == GameState.Recruit || GetState() == GameState.Prepare)
{
Projectile proj = event.getEntity();
if (proj instanceof WitherSkull)
{
WitherSkull ws = (WitherSkull) proj;
if (ws.getShooter() instanceof Wither)
@ -263,6 +266,7 @@ public class WitherGame extends TeamGame implements IBlockRestorer
}
}
}
}
@EventHandler
public void handleCustomBlockPlace(BlockPlaceEvent event)

View File

@ -156,6 +156,8 @@ public class ProgressingKitManager implements Listener
PlayerKit playerKit = _manager.getKitProgressionManager().getDataManager().get(player.getUniqueId());
try
{
if (_manager.GetGame() != null)
{
for (Kit kit : _manager.GetGame().GetKits())
{
@ -166,6 +168,7 @@ public class ProgressingKitManager implements Listener
}
}
}
}
finally
{
_manager.getKitProgressionManager().getDataManager().remove(playerKit);