Latest changes

This commit is contained in:
mathias 2018-11-24 22:23:04 +02:00
parent 869ab8ad50
commit a327443f48
4 changed files with 235 additions and 254 deletions

View file

@ -45,7 +45,8 @@ class CommandClearChat implements CommandExecutor {
class CommandConsole implements CommandExecutor { class CommandConsole implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Player player = (Player)sender; Player player = (Player) sender;
if (args.length == 0) { if (args.length == 0) {
player.sendMessage(ChatColor.RED + "Usage: /" + label + " <message ..>"); player.sendMessage(ChatColor.RED + "Usage: /" + label + " <message ..>");
} else { } else {
@ -57,13 +58,12 @@ class CommandConsole implements CommandExecutor {
class CommandDestroyEntities implements CommandExecutor { class CommandDestroyEntities implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Player player = (Player)sender; Player player = (Player) sender;
for (World world : Bukkit.getServer().getWorlds()) { for (World world : Bukkit.getServer().getWorlds()) {
for (Chunk chunk : world.getLoadedChunks()) { for (Entity entity : world.getEntities()) {
for (Entity entity : chunk.getEntities()) { if (entity.getType() != EntityType.PLAYER) {
if (entity.getType() != EntityType.PLAYER) { entity.remove();
entity.remove();
}
} }
} }
} }
@ -72,19 +72,11 @@ class CommandDestroyEntities implements CommandExecutor {
} }
} }
class CommandDiscord implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Player player = (Player)sender;
player.sendMessage("Join the Kaboom.pw Discord server to chat with other users");
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "minecraft:tellraw " + player.getName() + " [\"\",{\"text\":\"https://discord.gg/UMGbMsU\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://discord.gg/UMGbMsU\"}}]");
return true;
}
}
class CommandEnchantAll implements CommandExecutor { class CommandEnchantAll implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Player player = (Player)sender; Player player = (Player) sender;
ItemStack item = player.getItemInHand(); ItemStack item = player.getItemInHand();
if (item.getType() == Material.AIR) { if (item.getType() == Material.AIR) {
player.sendMessage("Please hold an item in your hand to enchant it"); player.sendMessage("Please hold an item in your hand to enchant it");
} else { } else {
@ -101,7 +93,7 @@ class CommandEnchantAll implements CommandExecutor {
item.addUnsafeEnchantment(Enchantment.DURABILITY, 32767); item.addUnsafeEnchantment(Enchantment.DURABILITY, 32767);
item.addUnsafeEnchantment(Enchantment.FIRE_ASPECT, 32767); item.addUnsafeEnchantment(Enchantment.FIRE_ASPECT, 32767);
item.addUnsafeEnchantment(Enchantment.FROST_WALKER, 32767); item.addUnsafeEnchantment(Enchantment.FROST_WALKER, 32767);
/*item.addUnsafeEnchantment(Enchantment.KNOCKBACK, 32767);*/ item.addUnsafeEnchantment(Enchantment.KNOCKBACK, 32767);
item.addUnsafeEnchantment(Enchantment.LOOT_BONUS_BLOCKS, 32767); item.addUnsafeEnchantment(Enchantment.LOOT_BONUS_BLOCKS, 32767);
item.addUnsafeEnchantment(Enchantment.LOOT_BONUS_MOBS, 32767); item.addUnsafeEnchantment(Enchantment.LOOT_BONUS_MOBS, 32767);
item.addUnsafeEnchantment(Enchantment.LUCK, 32767); item.addUnsafeEnchantment(Enchantment.LUCK, 32767);
@ -133,12 +125,13 @@ class CommandJumpscare implements CommandExecutor {
} }
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Player player = (Player)sender; Player player = (Player) sender;
if (args.length == 0) { if (args.length == 0) {
player.sendMessage(ChatColor.RED + "Usage: /" + label + " <player>"); player.sendMessage(ChatColor.RED + "Usage: /" + label + " <player>");
} else { } else {
if (args[0].equals("*") || args[0].equals("**")) { if (args[0].equals("*") || args[0].equals("**")) {
for (Player p: Bukkit.getOnlinePlayers()) { for (Player p : Bukkit.getOnlinePlayers()) {
createJumpscare(p); createJumpscare(p);
} }
player.sendMessage("Successfully created jumpscare for every player"); player.sendMessage("Successfully created jumpscare for every player");
@ -163,7 +156,8 @@ class CommandPrefix implements CommandExecutor {
} }
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
Player player = (Player)sender; Player player = (Player) sender;
if (args.length == 0) { if (args.length == 0) {
player.sendMessage(ChatColor.RED + "Usage: /" + label + " <prefix|off>"); player.sendMessage(ChatColor.RED + "Usage: /" + label + " <prefix|off>");
} else if (args[0].equalsIgnoreCase("off")) { } else if (args[0].equalsIgnoreCase("off")) {
@ -180,43 +174,57 @@ class CommandPrefix implements CommandExecutor {
} }
class CommandSkin implements CommandExecutor { class CommandSkin implements CommandExecutor {
Main main;
CommandSkin(Main main) {
this.main = main;
}
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Player player = (Player)sender; Player player = (Player) sender;
if (args.length == 0) { if (args.length == 0) {
player.sendMessage(ChatColor.RED + "Usage: /" + label + " <username>"); player.sendMessage(ChatColor.RED + "Usage: /" + label + " <username>");
} else { } else {
try { Bukkit.getScheduler().runTaskAsynchronously(main, () -> {
String name = args[0]; try {
URL nameurl = new URL("https://api.mojang.com/users/profiles/minecraft/" + name); String name = args[0];
HttpURLConnection nameconnection = (HttpURLConnection) nameurl.openConnection(); URL nameurl = new URL("https://api.mojang.com/users/profiles/minecraft/" + name);
HttpURLConnection nameconnection = (HttpURLConnection) nameurl.openConnection();
if (nameconnection.getResponseCode() == 200) { if (nameconnection.getResponseCode() == 200) {
InputStreamReader namestream = new InputStreamReader(nameconnection.getInputStream()); InputStreamReader namestream = new InputStreamReader(nameconnection.getInputStream());
String uuid = new JsonParser().parse(namestream).getAsJsonObject().get("id").getAsString(); String uuid = new JsonParser().parse(namestream).getAsJsonObject().get("id").getAsString();
URL uuidurl = new URL("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid + "?unsigned=false"); URL uuidurl = new URL("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid + "?unsigned=false");
HttpURLConnection uuidconnection = (HttpURLConnection) uuidurl.openConnection(); HttpURLConnection uuidconnection = (HttpURLConnection) uuidurl.openConnection();
if (uuidconnection.getResponseCode() == 200) { if (uuidconnection.getResponseCode() == 200) {
InputStreamReader uuidstream = new InputStreamReader(uuidconnection.getInputStream()); InputStreamReader uuidstream = new InputStreamReader(uuidconnection.getInputStream());
JsonObject response = new JsonParser().parse(uuidstream).getAsJsonObject().get("properties").getAsJsonArray().get(0).getAsJsonObject(); JsonObject response = new JsonParser().parse(uuidstream).getAsJsonObject().get("properties").getAsJsonArray().get(0).getAsJsonObject();
String texture = response.get("value").getAsString(); String texture = response.get("value").getAsString();
String signature = response.get("signature").getAsString(); String signature = response.get("signature").getAsString();
PlayerProfile textureprofile = player.getPlayerProfile(); Bukkit.getScheduler().scheduleSyncDelayedTask(main, () -> {
textureprofile.setProperty(new ProfileProperty("textures", texture, signature)); PlayerProfile textureprofile = player.getPlayerProfile();
player.setPlayerProfile(textureprofile); textureprofile.setProperty(new ProfileProperty("textures", texture, signature));
player.sendMessage("Successfully set your skin to " + name + "'s"); player.setPlayerProfile(textureprofile);
player.sendMessage("Successfully set your skin to " + name + "'s");
});
} else {
Bukkit.getScheduler().scheduleSyncDelayedTask(main, () -> {
player.sendMessage("Failed to change skin. Try again later");
});
}
uuidconnection.disconnect();
} else { } else {
player.sendMessage("Failed to change skin. Try again later"); Bukkit.getScheduler().scheduleSyncDelayedTask(main, () -> {
player.sendMessage("A player with that username doesn't exist");
});
} }
uuidconnection.disconnect(); nameconnection.disconnect();
} else { } catch (Exception exception) {
player.sendMessage("A player with that username doesn't exist"); exception.printStackTrace();
} }
nameconnection.disconnect(); });
} catch (Exception exception) {
exception.printStackTrace();
}
} }
return true; return true;
} }
@ -224,7 +232,8 @@ class CommandSkin implements CommandExecutor {
class CommandSpawn implements CommandExecutor { class CommandSpawn implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Player player = (Player)sender; Player player = (Player) sender;
World world = Bukkit.getWorld("world"); World world = Bukkit.getWorld("world");
player.teleport(new Location(world, 0.5, 100, 0.5)); player.teleport(new Location(world, 0.5, 100, 0.5));
player.sendMessage("Successfully moved to the spawn"); player.sendMessage("Successfully moved to the spawn");
@ -234,7 +243,8 @@ class CommandSpawn implements CommandExecutor {
class CommandTellraw implements CommandExecutor { class CommandTellraw implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Player player = (Player)sender; Player player = (Player) sender;
if (args.length == 0) { if (args.length == 0) {
player.sendMessage(ChatColor.RED + "Usage: /" + label + " <message ..>"); player.sendMessage(ChatColor.RED + "Usage: /" + label + " <message ..>");
} else { } else {
@ -246,7 +256,8 @@ class CommandTellraw implements CommandExecutor {
class CommandUnloadChunks implements CommandExecutor { class CommandUnloadChunks implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Player player = (Player)sender; Player player = (Player) sender;
for (World world : Bukkit.getServer().getWorlds()) { for (World world : Bukkit.getServer().getWorlds()) {
for (Chunk chunk : world.getLoadedChunks()) { for (Chunk chunk : world.getLoadedChunks()) {
chunk.unload(true); chunk.unload(true);
@ -264,7 +275,8 @@ class CommandUsername implements CommandExecutor {
} }
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Player player = (Player)sender; Player player = (Player) sender;
if (args.length == 0) { if (args.length == 0) {
player.sendMessage(ChatColor.RED + "Usage: /" + label + " <username>"); player.sendMessage(ChatColor.RED + "Usage: /" + label + " <username>");
} else { } else {

View file

@ -7,11 +7,13 @@ import java.util.Iterator;
import com.boydti.fawe.FaweAPI; import com.boydti.fawe.FaweAPI;
import com.destroystokyo.paper.event.entity.EntityAddToWorldEvent; import com.destroystokyo.paper.event.entity.EntityAddToWorldEvent;
import com.destroystokyo.paper.event.entity.EntityKnockbackByEntityEvent;
import com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent; import com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.Color;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
@ -21,11 +23,14 @@ import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance; import org.bukkit.attribute.AttributeInstance;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.Container;
import org.bukkit.block.CreatureSpawner; import org.bukkit.block.CreatureSpawner;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.MagmaCube; import org.bukkit.entity.MagmaCube;
import org.bukkit.entity.Slime; import org.bukkit.entity.Slime;
@ -33,28 +38,25 @@ import org.bukkit.entity.Slime;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDispenseEvent;
import org.bukkit.event.block.BlockExplodeEvent; import org.bukkit.event.block.BlockExplodeEvent;
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.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntitySpawnEvent; import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.entity.ExplosionPrimeEvent; import org.bukkit.event.entity.ExplosionPrimeEvent;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.entity.LingeringPotionSplashEvent; import org.bukkit.event.entity.LingeringPotionSplashEvent;
import org.bukkit.event.entity.PotionSplashEvent; import org.bukkit.event.entity.PotionSplashEvent;
import org.bukkit.event.entity.SpawnerSpawnEvent; import org.bukkit.event.entity.SpawnerSpawnEvent;
import org.bukkit.event.hanging.HangingPlaceEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerKickEvent; import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerLoginEvent;
@ -62,9 +64,12 @@ import org.bukkit.event.player.PlayerLoginEvent.Result;
import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.server.ServerCommandEvent; import org.bukkit.event.server.ServerCommandEvent;
import org.bukkit.event.server.ServerListPingEvent;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
@ -82,19 +87,23 @@ class PasteSpawn extends BukkitRunnable {
} }
public void run() { public void run() {
boolean allowUndo = false;
boolean noAir = false;
Vector position = new Vector(0, 100, 0);
try { try {
boolean allowUndo = false;
boolean noAir = false;
Vector position = new Vector(0, 100, 0);
EditSession editSession = ClipboardFormat.findByFile(main.spawnSchematic).load(main.spawnSchematic).paste(FaweAPI.getWorld("world"), position, allowUndo, !noAir, (Transform) null); EditSession editSession = ClipboardFormat.findByFile(main.spawnSchematic).load(main.spawnSchematic).paste(FaweAPI.getWorld("world"), position, allowUndo, !noAir, (Transform) null);
} catch(Exception exception) { } catch (Exception exception) {
exception.printStackTrace(); exception.printStackTrace();
} }
} }
} }
class Tick extends BukkitRunnable { class TickAsync extends BukkitRunnable {
Main main;
TickAsync(Main main) {
this.main = main;
}
public void run() { public void run() {
for (World world : Bukkit.getServer().getWorlds()) { for (World world : Bukkit.getServer().getWorlds()) {
WorldBorder worldborder = world.getWorldBorder(); WorldBorder worldborder = world.getWorldBorder();
@ -104,16 +113,49 @@ class Tick extends BukkitRunnable {
worldborder.setCenter(0, 0); worldborder.setCenter(0, 0);
} }
if (world.isAutoSave() == false) {
world.setAutoSave(true);
}
for (Entity entity : world.getEntities()) { for (Entity entity : world.getEntities()) {
if (entity instanceof LivingEntity) { if (entity instanceof LivingEntity) {
LivingEntity mob = (LivingEntity) entity; LivingEntity mob = (LivingEntity) entity;
AttributeInstance followAttribute = mob.getAttribute(Attribute.GENERIC_FOLLOW_RANGE); AttributeInstance followAttribute = mob.getAttribute(Attribute.GENERIC_FOLLOW_RANGE);
if (followAttribute != null && followAttribute.getBaseValue() > 32) { if (followAttribute != null && followAttribute.getBaseValue() > 40) {
followAttribute.setBaseValue(32); followAttribute.setBaseValue(32);
} }
} }
} }
for (Chunk chunk : world.getLoadedChunks()) {
int sizeCount = 0;
for (BlockState block : chunk.getTileEntities()) {
if (block instanceof Container) {
Container container = (Container) block;
for (ItemStack item : container.getInventory().getContents()) {
if (item != null) {
try {
sizeCount = sizeCount + item.toString().length();
if (sizeCount > 200000) {
for (BlockState chunkBlock : chunk.getTileEntities()) {
if (chunkBlock instanceof Container) {
Bukkit.getScheduler().scheduleSyncDelayedTask(main, () -> {
chunkBlock.getBlock().getDrops().clear();
chunkBlock.getBlock().setType(Material.AIR);
});
}
}
}
} catch (Exception e) {
}
}
}
}
}
}
} }
} }
} }
@ -127,81 +169,34 @@ class Events implements Listener {
@EventHandler @EventHandler
void onAsyncPlayerChat(AsyncPlayerChatEvent event) { void onAsyncPlayerChat(AsyncPlayerChatEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
String message = event.getMessage().substring(0, Math.min(256, event.getMessage().length()));
if (main.getConfig().getString(player.getUniqueId().toString()) != null) { if (main.getConfig().getString(player.getUniqueId().toString()) != null) {
String prefix = ChatColor.translateAlternateColorCodes('&', main.getConfig().getString(player.getUniqueId().toString())); String prefix = ChatColor.translateAlternateColorCodes('&', main.getConfig().getString(player.getUniqueId().toString()));
event.setFormat(prefix + ChatColor.RESET + " " + player.getDisplayName().toString() + ChatColor.RESET + ": " + ChatColor.RESET + ChatColor.translateAlternateColorCodes('&', message)); event.setFormat(prefix + ChatColor.RESET + " " + player.getDisplayName().toString() + ChatColor.RESET + ": " + ChatColor.RESET + "%2$s");
} else if (event.getPlayer().isOp()) { } else if (event.getPlayer().isOp()) {
String prefix = ChatColor.translateAlternateColorCodes('&', "&4&l[&c&lOP&4&l]"); String prefix = ChatColor.translateAlternateColorCodes('&', "&4&l[&c&lOP&4&l]");
event.setFormat(prefix + ChatColor.RED + " " + player.getDisplayName().toString() + ChatColor.RESET + ": " + ChatColor.RESET + ChatColor.translateAlternateColorCodes('&', message)); event.setFormat(prefix + ChatColor.RED + " " + player.getDisplayName().toString() + ChatColor.RESET + ": " + ChatColor.RESET + "%2$s");
} else { } else {
String prefix = ChatColor.translateAlternateColorCodes('&', "&8&l[&7&lDeOP&8&l]"); String prefix = ChatColor.translateAlternateColorCodes('&', "&8&l[&7&lDeOP&8&l]");
event.setFormat(prefix + ChatColor.GRAY + " " + player.getDisplayName().toString() + ChatColor.RESET + ": " + ChatColor.RESET + ChatColor.translateAlternateColorCodes('&', message)); event.setFormat(prefix + ChatColor.GRAY + " " + player.getDisplayName().toString() + ChatColor.RESET + ": " + ChatColor.RESET + "%2$s");
} }
} event.setMessage(ChatColor.translateAlternateColorCodes('&', event.getMessage()));
@EventHandler
void onBlockBreak(BlockBreakEvent event) {
for (ItemStack item : event.getBlock().getDrops()) {
main.editMeta(item);
}
}
@EventHandler
void onBlockDispense(BlockDispenseEvent event) {
ItemStack item = event.getItem();
main.editMeta(item);
} }
@EventHandler @EventHandler
void onBlockExplode(BlockExplodeEvent event) { void onBlockExplode(BlockExplodeEvent event) {
Block block = event.getBlock();
double x = block.getLocation().getX();
double z = block.getLocation().getZ();
double tps = Bukkit.getServer().getTPS()[0]; double tps = Bukkit.getServer().getTPS()[0];
if (block.getWorld().getName().equals("world")) {
if ((x > -20 && x < 20) && (z > -20 && z < 20)) {
event.blockList().clear();
}
}
if (tps < 14) { if (tps < 14) {
event.setCancelled(true); event.setCancelled(true);
} }
event.setYield(0);
}
@EventHandler
void onBlockFromTo(BlockFromToEvent event) {
Block block = event.getBlock();
double x = block.getLocation().getX();
double z = block.getLocation().getZ();
if (block.getWorld().getName().equals("world")) {
if ((x > -20 && x < 20) && (z > -20 && z < 20)) {
event.setCancelled(true);
}
}
} }
@EventHandler @EventHandler
void onBlockPhysics(BlockPhysicsEvent event) { void onBlockPhysics(BlockPhysicsEvent event) {
Block block = event.getBlock(); Block block = event.getBlock();
double x = block.getLocation().getX();
double z = block.getLocation().getZ();
if (block.getWorld().getName().equals("world")) { if (block.getType() == Material.SOIL) {
if ((x > -20 && x < 20) && (z > -20 && z < 20)) {
event.setCancelled(true);
}
}
if (block.getType() == Material.SOIL ||
block.getType() == Material.LAVA ||
block.getType() == Material.WATER) {
event.setCancelled(true); event.setCancelled(true);
} }
} }
@ -222,46 +217,39 @@ class Events implements Listener {
} }
} }
@EventHandler
void onBlockSpread(BlockSpreadEvent event) {
double tps = Bukkit.getServer().getTPS()[0];
if (tps < 14) {
event.setCancelled(true);
}
}
@EventHandler @EventHandler
void onEntityAddToWorld(EntityAddToWorldEvent event) { void onEntityAddToWorld(EntityAddToWorldEvent event) {
Entity entity = event.getEntity(); Entity entity = event.getEntity();
Entity[] chunkEntities = entity.getLocation().getChunk().getEntities(); Entity[] chunkEntities = entity.getLocation().getChunk().getEntities();
double tps = Bukkit.getServer().getTPS()[0];
int onChunk = 0; int onChunk = 0;
for (Entity chunkEntity : chunkEntities) { for (Entity chunkEntity : chunkEntities) {
if (onChunk < 50 && !(chunkEntity instanceof Player)) { if (onChunk < 50 && chunkEntity.getType() != EntityType.PLAYER) {
onChunk++; onChunk++;
} }
} }
if (onChunk == 50 && !(entity instanceof LivingEntity)) { if (onChunk == 50 && !(entity instanceof LivingEntity) ||
tps < 14 && entity.getType() == EntityType.PRIMED_TNT) {
entity.remove(); entity.remove();
} }
if (entity instanceof MagmaCube) { if (entity instanceof LivingEntity) {
MagmaCube magmacube = (MagmaCube) entity; LivingEntity mob = (LivingEntity) entity;
if (magmacube.getSize() > 100) { AttributeInstance followAttribute = mob.getAttribute(Attribute.GENERIC_FOLLOW_RANGE);
magmacube.setSize(100);
}
}
if (entity instanceof Slime) { if (followAttribute != null && followAttribute.getBaseValue() > 40) {
Slime slime = (Slime) entity; followAttribute.setBaseValue(40);
if (slime.getSize() > 100) {
slime.setSize(100);
}
}
}
@EventHandler
void onEntityChangeBlockEvent(EntityChangeBlockEvent event) {
Block block = event.getBlock();
double x = block.getLocation().getX();
double z = block.getLocation().getZ();
if (block.getWorld().getName().equals("world")) {
if ((x > -20 && x < 20) && (z > -20 && z < 20)) {
event.setCancelled(true);
} }
} }
} }
@ -279,27 +267,12 @@ class Events implements Listener {
} }
@EventHandler @EventHandler
void onEntityExplode(EntityExplodeEvent event) { void onEntityKnockbackByEntity(EntityKnockbackByEntityEvent event) {
double tps = Bukkit.getServer().getTPS()[0]; Entity entity = event.getEntity();
Iterator<Block> iter = event.blockList().iterator(); if (event.getKnockbackStrength() > 100) {
while (iter.hasNext()) {
Block block = iter.next();
double x = block.getX();
double z = block.getZ();
if (block.getWorld().getName().equals("world")) {
if ((x > -20 && x < 20) && (z > -20 && z < 20)) {
iter.remove();
}
}
}
if (tps < 14) {
event.setCancelled(true); event.setCancelled(true);
} }
event.setYield(0);
} }
@EventHandler @EventHandler
@ -309,12 +282,12 @@ class Events implements Listener {
int onChunk = 0; int onChunk = 0;
for (Entity chunkEntity : chunkEntities) { for (Entity chunkEntity : chunkEntities) {
if (onChunk < 50 && !(chunkEntity instanceof Player)) { if (onChunk < 50 && chunkEntity.getType() != EntityType.PLAYER) {
onChunk++; onChunk++;
} }
} }
if (onChunk == 50 && !(entity instanceof Player)) { if (onChunk == 50 && entity.getType() != EntityType.PLAYER) {
event.setCancelled(true); event.setCancelled(true);
} }
@ -322,15 +295,53 @@ class Events implements Listener {
LivingEntity mob = (LivingEntity) entity; LivingEntity mob = (LivingEntity) entity;
AttributeInstance followAttribute = mob.getAttribute(Attribute.GENERIC_FOLLOW_RANGE); AttributeInstance followAttribute = mob.getAttribute(Attribute.GENERIC_FOLLOW_RANGE);
if (followAttribute != null && followAttribute.getBaseValue() > 32) { if (followAttribute != null && followAttribute.getBaseValue() > 40) {
followAttribute.setBaseValue(32); followAttribute.setBaseValue(40);
}
try {
mob.getEquipment().getArmorContents();
} catch (Exception e) {
mob.getEquipment().setArmorContents(
new ItemStack[] {
new ItemStack(Material.AIR),
new ItemStack(Material.AIR),
new ItemStack(Material.AIR),
new ItemStack(Material.AIR)
}
);
}
try {
mob.getEquipment().getItemInMainHand();
} catch (Exception e) {
mob.getEquipment().setItemInMainHand(new ItemStack(Material.AIR));
}
try {
mob.getEquipment().getItemInOffHand();
} catch (Exception e) {
mob.getEquipment().setItemInOffHand(new ItemStack(Material.AIR));
}
}
if (entity.getType() == EntityType.MAGMA_CUBE) {
MagmaCube magmacube = (MagmaCube) entity;
if (magmacube.getSize() > 100) {
magmacube.setSize(100);
}
}
if (entity.getType() == EntityType.SLIME) {
Slime slime = (Slime) entity;
if (slime.getSize() > 100) {
slime.setSize(100);
} }
} }
} }
@EventHandler @EventHandler
void onExplosionPrime(ExplosionPrimeEvent event) { void onExplosionPrime(ExplosionPrimeEvent event) {
Entity entity = event.getEntity();
double tps = Bukkit.getServer().getTPS()[0]; double tps = Bukkit.getServer().getTPS()[0];
if (tps < 14) { if (tps < 14) {
@ -342,6 +353,17 @@ class Events implements Listener {
} }
} }
@EventHandler
void onItemSpawn(ItemSpawnEvent event) {
ItemStack item = event.getEntity().getItemStack();
try {
item.getItemMeta();
} catch (Exception e) {
event.setCancelled(true);
}
}
@EventHandler @EventHandler
void onLingeringPotionSplash(LingeringPotionSplashEvent event) { void onLingeringPotionSplash(LingeringPotionSplashEvent event) {
Entity entity = event.getEntity(); Entity entity = event.getEntity();
@ -368,45 +390,23 @@ class Events implements Listener {
} }
} }
@EventHandler
void onHangingPlace(HangingPlaceEvent event) {
Entity entity = event.getEntity();
double x = entity.getLocation().getX();
double z = entity.getLocation().getZ();
if (entity.getWorld().getName().equals("world")) {
if ((x > -20 && x < 20) && (z > -20 && z < 20)) {
event.setCancelled(true);
}
}
}
@EventHandler @EventHandler
void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
String arr[] = event.getMessage().split(" "); String arr[] = event.getMessage().split(" ");
if (arr[0].toLowerCase().equals("//schem") || if (arr[0].toLowerCase().equals("/minecraft:gamerule") ||
arr[0].toLowerCase().equals("//schematic") ||
arr[0].toLowerCase().equals("/schem") ||
arr[0].toLowerCase().equals("/schematic") ||
arr[0].toLowerCase().equals("/worldedit:/schem") ||
arr[0].toLowerCase().equals("/worldedit:/schematic") ||
arr[0].toLowerCase().equals("/worldedit:schem") ||
arr[0].toLowerCase().equals("/worldedit:schematic")) {
if (arr[1].toLowerCase().equals("delete")) {
event.setCancelled(true);
}
} else if (arr[0].toLowerCase().equals("/minecraft:gamerule") ||
arr[0].toLowerCase().equals("/gamerule")) { arr[0].toLowerCase().equals("/gamerule")) {
if (arr[1] != null && arr[1].toLowerCase().equals("randomtickspeed")) { if (arr[1] != null && arr[1].toLowerCase().equals("randomtickspeed")) {
if (arr[2] != null && Integer.parseInt(arr[2]) > 6) { if (arr[2] != null && Integer.parseInt(arr[2]) > 6) {
event.setMessage(String.join(" ", arr[0], arr[1]) + " 6"); String gameruleArr[] = event.getMessage().split(" ", 2);
event.setMessage(gameruleArr[0] + " 6");
} }
} }
} else if (arr[0].toLowerCase().equals("/minecraft:particle") || } else if (arr[0].toLowerCase().equals("/minecraft:particle") ||
arr[0].toLowerCase().equals("/particle")) { arr[0].toLowerCase().equals("/particle")) {
if (arr[9] != null && Integer.parseInt(arr[9]) > 10) { if (arr[9] != null && Integer.parseInt(arr[9]) > 10) {
event.setMessage(String.join(" ", arr[0], arr[1], arr[2], arr[3], arr[4], arr[5], arr[6], arr[7], arr[8]) + " 10"); String particleArr[] = event.getMessage().split(" ", 11);
event.setMessage(particleArr[0].replaceAll(" [^ ]+$", "") + " 10 " + particleArr[1]);
} }
} }
} }
@ -415,14 +415,20 @@ class Events implements Listener {
void onPlayerJoin(PlayerJoinEvent event) { void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
/*if (player.getInventory().getContents() != null) { Bukkit.getScheduler().runTaskAsynchronously(main, () -> {
for (ItemStack item : player.getInventory().getContents()) { main.getSkin(player.getName(), player);
main.editMeta(item); });
}
}*/ for (ItemStack item : player.getInventory().getContents()) {
player.getInventory().clear(); if (item != null) {
try {
item.getItemMeta();
} catch (Exception e) {
player.getInventory().remove(item);
}
}
}
main.getSkin(player.getName(), player);
player.setOp(true); player.setOp(true);
player.sendTitle(ChatColor.GRAY + "Kaboom.pw", "Free OP • Anarchy • Creative", 10, 160, 5); player.sendTitle(ChatColor.GRAY + "Kaboom.pw", "Free OP • Anarchy • Creative", 10, 160, 5);
} }
@ -445,7 +451,6 @@ class Events implements Listener {
} else { } else {
event.allow(); event.allow();
} }
/*event.allow();*/
} }
@EventHandler @EventHandler
@ -488,42 +493,26 @@ class Events implements Listener {
if (main.consoleCommandBlacklist.contains(arr[0].toLowerCase())) { if (main.consoleCommandBlacklist.contains(arr[0].toLowerCase())) {
event.setCancelled(true); event.setCancelled(true);
} else if (arr[0].toLowerCase().equals("/schem") || } else if (arr[0].toLowerCase().equals("minecraft:gamerule") ||
arr[0].toLowerCase().equals("/schematic") || arr[0].toLowerCase().equals("gamerule")) {
arr[0].toLowerCase().equals("schem") ||
arr[0].toLowerCase().equals("schematic") ||
arr[0].toLowerCase().equals("worldedit:/schem") ||
arr[0].toLowerCase().equals("worldedit:/schematic") ||
arr[0].toLowerCase().equals("worldedit:schem") ||
arr[0].toLowerCase().equals("worldedit:schematic")) {
if (arr[1].toLowerCase().equals("delete")) {
event.setCancelled(true);
}
} else if (arr[0].toLowerCase().equals("/minecraft:gamerule") ||
arr[0].toLowerCase().equals("/gamerule")) {
if (arr[1] != null && arr[1].toLowerCase().equals("randomtickspeed")) { if (arr[1] != null && arr[1].toLowerCase().equals("randomtickspeed")) {
if (arr[2] != null && Integer.parseInt(arr[2]) > 6) { if (arr[2] != null && Integer.parseInt(arr[2]) > 6) {
event.setCommand(String.join(" ", arr[0], arr[1]) + " 6"); String gameruleArr[] = event.getCommand().split(" ", 3);
event.setCommand(gameruleArr[0] + " 6");
} }
} }
} else if (arr[0].toLowerCase().equals("minecraft:particle") || } else if (arr[0].toLowerCase().equals("minecraft:particle") ||
arr[0].toLowerCase().equals("particle")) { arr[0].toLowerCase().equals("particle")) {
if (arr[9] != null && Integer.parseInt(arr[9]) > 10) { if (arr[9] != null && Integer.parseInt(arr[9]) > 10) {
event.setCommand(String.join(" ", arr[0], arr[1], arr[2], arr[3], arr[4], arr[5], arr[6], arr[7], arr[8]) + " 10"); String particleArr[] = event.getCommand().split(" ", 11);
event.setCommand(particleArr[0].replaceAll(" [^ ]+$", "") + " 10 " + particleArr[1]);
} }
} }
} }
@EventHandler
void onServerListPing(ServerListPingEvent event) {
event.setMaxPlayers(event.getNumPlayers() + 1);
}
@EventHandler @EventHandler
void onSpawnerSpawn(SpawnerSpawnEvent event) { void onSpawnerSpawn(SpawnerSpawnEvent event) {
CreatureSpawner spawner = event.getSpawner(); CreatureSpawner spawner = event.getSpawner();
Entity entity = event.getEntity();
LivingEntity mob = (LivingEntity) entity;
if (spawner.getSpawnCount() > 200) { if (spawner.getSpawnCount() > 200) {
spawner.setSpawnCount(200); spawner.setSpawnCount(200);

View file

@ -13,15 +13,12 @@ import com.destroystokyo.paper.profile.ProfileProperty;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import org.bukkit.Bukkit;
import org.bukkit.Color; import org.bukkit.Color;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin { public class Main extends JavaPlugin {
@ -358,18 +355,17 @@ public class Main extends JavaPlugin {
this.getCommand("clearchat").setExecutor(new CommandClearChat()); this.getCommand("clearchat").setExecutor(new CommandClearChat());
this.getCommand("console").setExecutor(new CommandConsole()); this.getCommand("console").setExecutor(new CommandConsole());
this.getCommand("destroyentities").setExecutor(new CommandDestroyEntities()); this.getCommand("destroyentities").setExecutor(new CommandDestroyEntities());
this.getCommand("discord").setExecutor(new CommandDiscord());
this.getCommand("enchantall").setExecutor(new CommandEnchantAll()); this.getCommand("enchantall").setExecutor(new CommandEnchantAll());
this.getCommand("jumpscare").setExecutor(new CommandJumpscare()); this.getCommand("jumpscare").setExecutor(new CommandJumpscare());
this.getCommand("prefix").setExecutor(new CommandPrefix(this)); this.getCommand("prefix").setExecutor(new CommandPrefix(this));
this.getCommand("skin").setExecutor(new CommandSkin()); this.getCommand("skin").setExecutor(new CommandSkin(this));
this.getCommand("spawn").setExecutor(new CommandSpawn()); this.getCommand("spawn").setExecutor(new CommandSpawn());
this.getCommand("tellraw").setExecutor(new CommandTellraw()); this.getCommand("tellraw").setExecutor(new CommandTellraw());
this.getCommand("unloadchunks").setExecutor(new CommandUnloadChunks()); this.getCommand("unloadchunks").setExecutor(new CommandUnloadChunks());
this.getCommand("username").setExecutor(new CommandUsername(this)); this.getCommand("username").setExecutor(new CommandUsername(this));
new PasteSpawn(this).runTaskTimer(this, 0, 200); new PasteSpawn(this).runTaskTimerAsynchronously(this, 0, 10);
new Tick().runTaskTimer(this, 0, 1); new TickAsync(this).runTaskTimerAsynchronously(this, 0, 1);
this.getServer().getPluginManager().registerEvents(new Events(this), this); this.getServer().getPluginManager().registerEvents(new Events(this), this);
} }
@ -390,9 +386,11 @@ public class Main extends JavaPlugin {
String texture = response.get("value").getAsString(); String texture = response.get("value").getAsString();
String signature = response.get("signature").getAsString(); String signature = response.get("signature").getAsString();
PlayerProfile textureprofile = player.getPlayerProfile(); Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> {
textureprofile.setProperty(new ProfileProperty("textures", texture, signature)); PlayerProfile textureprofile = player.getPlayerProfile();
player.setPlayerProfile(textureprofile); textureprofile.setProperty(new ProfileProperty("textures", texture, signature));
player.setPlayerProfile(textureprofile);
});
} }
uuidconnection.disconnect(); uuidconnection.disconnect();
} }
@ -401,19 +399,4 @@ public class Main extends JavaPlugin {
exception.printStackTrace(); exception.printStackTrace();
} }
} }
public void editMeta(ItemStack item) {
if (item.getType() == Material.LINGERING_POTION ||
item.getType() == Material.POTION ||
item.getType() == Material.SPLASH_POTION) {
PotionMeta potion = (PotionMeta) item.getItemMeta();
potion.setColor(Color.WHITE);
} else if (item.getType() == Material.LEATHER_BOOTS ||
item.getType() == Material.LEATHER_CHESTPLATE ||
item.getType() == Material.LEATHER_HELMET ||
item.getType() == Material.LEATHER_LEGGINGS) {
LeatherArmorMeta armor = (LeatherArmorMeta) item.getItemMeta();
armor.setColor(Color.fromRGB(160,101,64));
}
}
} }

View file

@ -1,7 +1,7 @@
name: Extras name: Extras
main: pw.kaboom.extras.Main main: pw.kaboom.extras.Main
description: Plugin that adds extra functionality to the Kaboom.pw server. description: Plugin that adds extra functionality to the Kaboom.pw server.
depend: [WorldEdit] depend: [FastAsyncWorldEdit]
version: master version: master
commands: commands:
@ -15,9 +15,6 @@ commands:
destroyentities: destroyentities:
description: Destroys all entities in every world description: Destroys all entities in every world
permission: extras.destroyentities permission: extras.destroyentities
discord:
description: Join the Kaboom.pw Discord server
permission: extras.discord
enchantall: enchantall:
description: Adds every enchantment to a held item description: Adds every enchantment to a held item
permission: extras.enchantall permission: extras.enchantall