mirror of
https://github.com/kaboomserver/extras.git
synced 2024-11-27 09:55:36 -05:00
Tweak TPS check
This commit is contained in:
parent
f984ac411a
commit
3a0946054d
3 changed files with 24 additions and 35 deletions
|
@ -29,6 +29,8 @@ import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
import org.bukkit.util.BlockIterator;
|
import org.bukkit.util.BlockIterator;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
@ -267,7 +269,7 @@ class CommandSkin implements CommandExecutor {
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
player.sendMessage(ChatColor.RED + "Usage: /" + label + " <username>");
|
player.sendMessage(ChatColor.RED + "Usage: /" + label + " <username>");
|
||||||
} else {
|
} else {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(main, new Runnable() {
|
new BukkitRunnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
final String name = args[0];
|
final String name = args[0];
|
||||||
|
@ -295,35 +297,35 @@ class CommandSkin implements CommandExecutor {
|
||||||
textureProfile.clearProperties();
|
textureProfile.clearProperties();
|
||||||
textureProfile.setProperty(new ProfileProperty("textures", texture, signature));
|
textureProfile.setProperty(new ProfileProperty("textures", texture, signature));
|
||||||
|
|
||||||
Bukkit.getScheduler().runTask(main, new Runnable() {
|
new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
player.setPlayerProfile(textureProfile);
|
player.setPlayerProfile(textureProfile);
|
||||||
player.sendMessage("Successfully set your skin to " + name + "'s");
|
player.sendMessage("Successfully set your skin to " + name + "'s");
|
||||||
}
|
}
|
||||||
});
|
}.runTask(main);
|
||||||
} else {
|
} else {
|
||||||
uuidConnection.disconnect();
|
uuidConnection.disconnect();
|
||||||
Bukkit.getScheduler().runTask(main, new Runnable() {
|
new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
player.sendMessage("Failed to change skin. Try again later");
|
player.sendMessage("Failed to change skin. Try again later");
|
||||||
}
|
}
|
||||||
});
|
}.runTask(main);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
nameConnection.disconnect();
|
nameConnection.disconnect();
|
||||||
Bukkit.getScheduler().runTask(main, new Runnable() {
|
new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
player.sendMessage("A player with that username doesn't exist");
|
player.sendMessage("A player with that username doesn't exist");
|
||||||
}
|
}
|
||||||
});
|
}.runTask(main);
|
||||||
}
|
}
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}.runTaskAsynchronously(main);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -414,7 +416,7 @@ class CommandUsername implements CommandExecutor {
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
player.sendMessage(ChatColor.RED + "Usage: /" + label + " <username>");
|
player.sendMessage(ChatColor.RED + "Usage: /" + label + " <username>");
|
||||||
} else {
|
} else {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(main, new Runnable() {
|
new BukkitRunnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
String texture = "";
|
String texture = "";
|
||||||
|
@ -457,17 +459,17 @@ class CommandUsername implements CommandExecutor {
|
||||||
profile.setProperty(new ProfileProperty("textures", texture, signature));
|
profile.setProperty(new ProfileProperty("textures", texture, signature));
|
||||||
}
|
}
|
||||||
|
|
||||||
Bukkit.getScheduler().runTask(main, new Runnable() {
|
new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
player.setPlayerProfile(profile);
|
player.setPlayerProfile(profile);
|
||||||
player.sendMessage("Successfully set your username to \"" + name + "\"");
|
player.sendMessage("Successfully set your username to \"" + name + "\"");
|
||||||
}
|
}
|
||||||
});
|
}.runTask(main);
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}.runTaskAsynchronously(main);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import javax.net.ssl.HttpsURLConnection;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
@ -36,7 +37,6 @@ import org.bukkit.event.block.BlockFromToEvent;
|
||||||
import org.bukkit.event.block.BlockPhysicsEvent;
|
import org.bukkit.event.block.BlockPhysicsEvent;
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
import org.bukkit.event.block.BlockRedstoneEvent;
|
import org.bukkit.event.block.BlockRedstoneEvent;
|
||||||
import org.bukkit.event.block.BlockSpreadEvent;
|
|
||||||
import org.bukkit.event.block.SignChangeEvent;
|
import org.bukkit.event.block.SignChangeEvent;
|
||||||
|
|
||||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||||
|
@ -87,9 +87,9 @@ class AutosaveCheck extends BukkitRunnable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*class TileEntityCheckAsync extends BukkitRunnable {
|
class TileEntityCheck extends BukkitRunnable {
|
||||||
Main main;
|
Main main;
|
||||||
TileEntityCheckAsync(Main main) {
|
TileEntityCheck(Main main) {
|
||||||
this.main = main;
|
this.main = main;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,16 +99,16 @@ class AutosaveCheck extends BukkitRunnable {
|
||||||
try {
|
try {
|
||||||
chunk.getTileEntities();
|
chunk.getTileEntities();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Bukkit.getScheduler().runTask(main, new Runnable() {
|
new BukkitRunnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
world.regenerateChunk(chunk.getX(), chunk.getZ());
|
world.regenerateChunk(chunk.getX(), chunk.getZ());
|
||||||
}
|
}
|
||||||
});
|
}.runTask(main);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
|
|
||||||
class Events implements Listener {
|
class Events implements Listener {
|
||||||
Main main;
|
Main main;
|
||||||
|
@ -291,20 +291,11 @@ class Events implements Listener {
|
||||||
void onBlockRedstone(BlockRedstoneEvent event) {
|
void onBlockRedstone(BlockRedstoneEvent event) {
|
||||||
final double tps = Bukkit.getServer().getTPS()[0];
|
final double tps = Bukkit.getServer().getTPS()[0];
|
||||||
|
|
||||||
if (tps < 14) {
|
if (tps < 10) {
|
||||||
event.setNewCurrent(0);
|
event.setNewCurrent(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
void onBlockSpread(BlockSpreadEvent event) {
|
|
||||||
final double tps = Bukkit.getServer().getTPS()[0];
|
|
||||||
|
|
||||||
if (tps < 14) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onCreatureSpawn(CreatureSpawnEvent event) {
|
void onCreatureSpawn(CreatureSpawnEvent event) {
|
||||||
if (event.getSpawnReason() == SpawnReason.CUSTOM ||
|
if (event.getSpawnReason() == SpawnReason.CUSTOM ||
|
||||||
|
@ -425,11 +416,7 @@ class Events implements Listener {
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onExplosionPrime(ExplosionPrimeEvent event) {
|
void onExplosionPrime(ExplosionPrimeEvent event) {
|
||||||
final double tps = Bukkit.getServer().getTPS()[0];
|
if (event.getRadius() > 20) {
|
||||||
|
|
||||||
if (tps < 14) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
} else if (event.getRadius() > 20) {
|
|
||||||
event.setRadius(20);
|
event.setRadius(20);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -709,7 +696,7 @@ class Events implements Listener {
|
||||||
void onTNTPrime(TNTPrimeEvent event) {
|
void onTNTPrime(TNTPrimeEvent event) {
|
||||||
final double tps = Bukkit.getServer().getTPS()[0];
|
final double tps = Bukkit.getServer().getTPS()[0];
|
||||||
|
|
||||||
if (tps < 14) {
|
if (tps < 10) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -580,7 +580,7 @@ public class Main extends JavaPlugin {
|
||||||
this.getCommand("username").setExecutor(new CommandUsername(this));
|
this.getCommand("username").setExecutor(new CommandUsername(this));
|
||||||
|
|
||||||
new AutosaveCheck().runTaskTimerAsynchronously(this, 0, 20);
|
new AutosaveCheck().runTaskTimerAsynchronously(this, 0, 20);
|
||||||
/*new TileEntityCheckAsync(this).runTaskTimerAsynchronously(this, 0, 400);*/
|
new TileEntityCheck(this).runTaskTimerAsynchronously(this, 0, 400);
|
||||||
this.getServer().getPluginManager().registerEvents(new Events(this), this);
|
this.getServer().getPluginManager().registerEvents(new Events(this), this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue