Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

Commit

Permalink
Few code tweaks (#107)
Browse files Browse the repository at this point in the history
* Add DAMAGE_SOURCE ENUM & Change to Switch (Compiler improvements)

* Change forEach loop

* Remove useless parsing

* Remove unused variable

* Change from Random to FastRandom

* Fix wrong @param name

* Add/Remove throw

* Remove unused imports

* Redundant call to String.format()

* Replace if

* Variable type too weak, which leads to cast

* Update TimingData.java
  • Loading branch information
rektbydead authored Aug 2, 2022
1 parent e0686a4 commit 400d8ac
Show file tree
Hide file tree
Showing 68 changed files with 201 additions and 167 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginLoader;
import org.bukkit.plugin.RegisteredListener;
import org.bukkit.plugin.TimedRegisteredListener;
import org.bukkit.plugin.UnknownDependencyException;
import org.yaml.snakeyaml.error.YAMLException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.google.common.collect.Sets;
import com.google.common.util.concurrent.ThreadFactoryBuilder;

import co.aikar.timings.Timings;
import ga.windpvp.windspigot.async.AsyncUtil;
import ga.windpvp.windspigot.async.pathsearch.SearchHandler;
import ga.windpvp.windspigot.async.thread.CombatThread;
Expand All @@ -27,7 +26,6 @@
import ga.windpvp.windspigot.protocol.MovementListener;
import ga.windpvp.windspigot.protocol.PacketListener;
import ga.windpvp.windspigot.statistics.StatisticsClient;
import net.md_5.bungee.api.ChatColor;
import net.minecraft.server.MinecraftServer;
import xyz.sculas.nacho.anticrash.AntiCrash;
import xyz.sculas.nacho.async.AsyncExplosions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,29 @@ public Spigot404Write(Channel channel) {
}

public static void writeThenFlush(Channel channel, Packet<?> value, GenericFutureListener<? extends Future<? super Void>>[] listener) {

Spigot404Write writer = new Spigot404Write(channel);
packetsQueue.add(new PacketQueue(value, listener));
if (tasks.addTask()) {
try {
channel.pipeline().lastContext().executor().execute(writer::writeQueueAndFlush);
} catch (NullPointerException ignored) {} // The player might leave right before the packet is sent
}
if (!tasks.addTask())
return;

try {
Spigot404Write writer = new Spigot404Write(channel);
channel.pipeline().lastContext().executor().execute(writer::writeQueueAndFlush);
} catch (NullPointerException ignored) {

} // The player might leave right before the packet is sent
}

public void writeQueueAndFlush() {
while (tasks.fetchTask()) {
while (packetsQueue.size() > 0) {
PacketQueue messages = packetsQueue.poll();
if (messages == null) continue;

ChannelFuture future = this.channel.write(messages.getPacket());
if (messages.getListener() != null) {
future.addListeners(messages.getListener());
}

future.addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ public void loop() {
if (catchupTime < 2E6) {
wait += Math.abs(catchupTime);
} else if (wait < catchupTime) {
catchupTime -= wait;
//catchupTime -= wait;
wait = 0;
} else {
wait -= catchupTime;
catchupTime = 0;
//catchupTime = 0;
}

try {
Expand All @@ -61,7 +61,7 @@ public void loop() {
} catch (InterruptedException e) {
e.printStackTrace();
}
curTime = System.nanoTime();
//curTime = System.nanoTime();
catchupTime = 0L;
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public synchronized long getSeed() {
* two instances of the same random class, starting with the same seed, produce
* the same results, if the same methods are called.
*
* @param s the new seed
* @param seed the new seed
*/
public synchronized void setSeed(long seed) {
this.seed = seed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class StatisticsClient {
public boolean isConnected;

// Connects to the statistics server
public void start(String ip, int port) throws UnknownHostException, IOException {
public void start(String ip, int port) throws IOException {
this.socket = new Socket(ip, port);
this.out = new PrintWriter(socket.getOutputStream(), true);
this.in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import com.google.common.base.Throwables;

import ga.windpvp.windspigot.WindSpigot;
import ga.windpvp.windspigot.commons.FileUtils;
import ga.windpvp.windspigot.config.WindSpigotConfig;

public class NachoConfig {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Random;
import java.util.Set;

import ga.windpvp.windspigot.random.FastRandom;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand Down Expand Up @@ -457,8 +458,8 @@ public static BiomeBase getBiome(int i, BiomeBase biomebase) {
BiomeBase.n.remove(BiomeBase.SKY);
BiomeBase.n.remove(BiomeBase.FROZEN_OCEAN);
BiomeBase.n.remove(BiomeBase.SMALL_MOUNTAINS);
ae = new NoiseGenerator3(new Random(1234L), 1);
af = new NoiseGenerator3(new Random(2345L), 1);
ae = new NoiseGenerator3(new FastRandom(1234L), 1);
af = new NoiseGenerator3(new FastRandom(2345L), 1);
ag = new WorldGenTallPlant();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.minecraft.server;

import ga.windpvp.windspigot.random.FastRandom;

import java.util.Arrays;
import java.util.Random;

Expand Down Expand Up @@ -51,7 +53,7 @@ public void a(World world, Random random, ChunkSnapshot chunksnapshot, int i, in
}

if (this.aF == null || this.aG == null || this.aE != world.getSeed()) {
Random random1 = new Random(this.aE);
Random random1 = new FastRandom(this.aE);

this.aF = new NoiseGenerator3(random1, 4);
this.aG = new NoiseGenerator3(random1, 1);
Expand Down Expand Up @@ -175,7 +177,7 @@ public void a(World world, Random random, ChunkSnapshot chunksnapshot, int i, in
private void a(long i) {
this.aD = new IBlockData[64];
Arrays.fill(this.aD, Blocks.HARDENED_CLAY.getBlockData());
Random random = new Random(i);
Random random = new FastRandom(i);

this.aH = new NoiseGenerator3(random, 1);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.minecraft.server;

import ga.windpvp.windspigot.random.FastRandom;

import java.util.Random;

public class BlockDispenser extends BlockContainer {
Expand All @@ -8,7 +10,7 @@ public class BlockDispenser extends BlockContainer {
public static final BlockStateBoolean TRIGGERED = BlockStateBoolean.of("triggered");
public static final RegistryDefault<Item, IDispenseBehavior> REGISTRY = new RegistryDefault(
new DispenseBehaviorItem());
protected Random O = new Random();
protected Random O = new FastRandom();
public static boolean eventFired = false; // CraftBukkit

protected BlockDispenser() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.bukkit.craftbukkit.util.CraftMagicNumbers;

import ga.windpvp.windspigot.config.WindSpigotConfig;
import me.elier.nachospigot.config.NachoConfig;

public class BlockFalling extends Block {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private TileEntityFlowerPot f(World world, BlockPosition blockposition) {

@Override
public TileEntity a(World world, int i) {
Object object = null;
Block object = null;
int j = 0;

switch (i) {
Expand Down Expand Up @@ -209,7 +209,7 @@ public TileEntity a(World world, int i) {
j = BlockWood.EnumLogVariant.DARK_OAK.a();
}

return new TileEntityFlowerPot(Item.getItemOf((Block) object), j);
return new TileEntityFlowerPot(Item.getItemOf(object), j);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.bukkit.event.block.LeavesDecayEvent; // CraftBukkit

import ga.windpvp.windspigot.config.WindSpigotConfig;
import me.elier.nachospigot.config.NachoConfig;

public abstract class BlockLeaves extends BlockTransparent {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void e(World world, BlockPosition blockposition, IBlockData iblockdata, R
// CraftBukkit start - Turn ternary operator into if statement to set treeType
// Object object = random.nextInt(10) == 0 ? new WorldGenBigTree(true) : new
// WorldGenTrees(true);
Object object;
WorldGenerator object;
if (random.nextInt(10) == 0) {
treeType = TreeType.BIG_TREE;
object = new WorldGenBigTree(true);
Expand Down Expand Up @@ -181,7 +181,7 @@ public void e(World world, BlockPosition blockposition, IBlockData iblockdata, R
world.setTypeAndData(blockposition, iblockdata1, 4);
}

if (!((WorldGenerator) object).generate(world, random, blockposition.a(i, 0, j))) {
if (!object.generate(world, random, blockposition.a(i, 0, j))) {
if (flag) {
world.setTypeAndData(blockposition.a(i, 0, j), iblockdata, 4);
world.setTypeAndData(blockposition.a(i + 1, 0, j), iblockdata, 4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicInteger; // PaperSpigot

import ga.windpvp.windspigot.random.FastRandom;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.bukkit.Bukkit; // CraftBukkit
Expand Down Expand Up @@ -1218,7 +1219,7 @@ public boolean a(boolean flag) {
}

public Random a(long i) {
return new Random(this.world.getSeed() + this.locX * this.locX * 4987142 + this.locX * 5947611
return new FastRandom(this.world.getSeed() + this.locX * this.locX * 4987142 + this.locX * 5947611
+ this.locZ * this.locZ * 4392871L + this.locZ * 389711 ^ i);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Random;

import com.google.common.collect.Lists;
import ga.windpvp.windspigot.random.FastRandom;

public class ChunkProviderFlat implements IChunkProvider {

Expand All @@ -21,7 +22,7 @@ public class ChunkProviderFlat implements IChunkProvider {

public ChunkProviderFlat(World world, long i, boolean flag, String s) {
this.a = world;
this.b = new Random(i);
this.b = new FastRandom(i);
this.d = WorldGenFlatInfo.a(s);
if (flag) {
Map map = this.d.b();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.minecraft.server;

import ga.windpvp.windspigot.random.FastRandom;

import java.util.List;
import java.util.Random;

Expand Down Expand Up @@ -47,7 +49,7 @@ public ChunkProviderGenerate(World world, long i, boolean flag, String s) {
this.m = world;
this.n = flag;
this.o = world.getWorldData().getType();
this.h = new Random(i);
this.h = new FastRandom(i);
this.i = new NoiseGeneratorOctaves(this.h, 16);
this.j = new NoiseGeneratorOctaves(this.h, 16);
this.k = new NoiseGeneratorOctaves(this.h, 8);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.minecraft.server;

import ga.windpvp.windspigot.random.FastRandom;

import java.util.List;
import java.util.Random;

Expand Down Expand Up @@ -45,7 +47,7 @@ public ChunkProviderHell(World world, boolean flag, long i) {
this.C = new WorldGenCavesHell();
this.h = world;
this.i = flag;
this.j = new Random(i);
this.j = new FastRandom(i);
this.o = new NoiseGeneratorOctaves(this.j, 16);
this.p = new NoiseGeneratorOctaves(this.j, 16);
this.q = new NoiseGeneratorOctaves(this.j, 8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// CraftBukkit start
import java.util.Random;

import ga.windpvp.windspigot.random.FastRandom;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.bukkit.Server;
Expand Down Expand Up @@ -342,7 +343,7 @@ public void getChunkAt(IChunkProvider ichunkprovider, int i, int j) {

// CraftBukkit start
BlockFalling.instaFall = true;
Random random = new Random();
Random random = new FastRandom();
random.setSeed(world.getSeed());
long xRand = random.nextLong() / 2L * 2L + 1L;
long zRand = random.nextLong() / 2L * 2L + 1L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public static int executeCommand(ICommandListener sender, org.bukkit.command.Com
exception);
} else {
MinecraftServer.getServer().server.getLogger().log(Level.WARNING,
String.format("Unknown CommandBlock failed to handle command"), exception);
"Unknown CommandBlock failed to handle command", exception);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import ga.windpvp.windspigot.random.FastRandom;

public class CommandSpreadPlayers extends CommandAbstract {

Expand Down Expand Up @@ -86,7 +87,7 @@ public void execute(ICommandListener icommandlistener, String[] astring) throws
private void a(ICommandListener icommandlistener, List<Entity> list,
CommandSpreadPlayers.Location2D commandspreadplayers_location2d, double d0, double d1, World world,
boolean flag) throws CommandException {
Random random = new Random();
Random random = new FastRandom();
double d2 = commandspreadplayers_location2d.a - d1;
double d3 = commandspreadplayers_location2d.b - d1;
double d4 = commandspreadplayers_location2d.a + d1;
Expand Down
Loading

0 comments on commit 400d8ac

Please sign in to comment.