forked from kaboomserver/extras
Use spaces instead of tabs
This commit is contained in:
parent
e5c30e8195
commit
78067effe2
35 changed files with 1548 additions and 1549 deletions
96
pom.xml
96
pom.xml
|
@ -1,55 +1,55 @@
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>pw.kaboom</groupId>
|
<groupId>pw.kaboom</groupId>
|
||||||
<artifactId>Extras</artifactId>
|
<artifactId>Extras</artifactId>
|
||||||
<version>master</version>
|
<version>master</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
<maven.test.skip>true</maven.test.skip>
|
<maven.test.skip>true</maven.test.skip>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.destroystokyo.paper</groupId>
|
<groupId>com.destroystokyo.paper</groupId>
|
||||||
<artifactId>paper-api</artifactId>
|
<artifactId>paper-api</artifactId>
|
||||||
<version>1.16.5-R0.1-SNAPSHOT</version>
|
<version>1.16.5-R0.1-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
<id>papermc</id>
|
<id>papermc</id>
|
||||||
<url>https://papermc.io/repo/repository/maven-public/</url>
|
<url>https://papermc.io/repo/repository/maven-public/</url>
|
||||||
</repository>
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<finalName>${project.artifactId}</finalName>
|
<finalName>${project.artifactId}</finalName>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||||
<version>3.1.2</version>
|
<version>3.1.2</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>checkstyle</id>
|
<id>checkstyle</id>
|
||||||
<phase>validate</phase>
|
<phase>validate</phase>
|
||||||
<goals>
|
<goals>
|
||||||
<goal>check</goal>
|
<goal>check</goal>
|
||||||
</goals>
|
</goals>
|
||||||
<configuration>
|
<configuration>
|
||||||
<suppressionsLocation>
|
<suppressionsLocation>
|
||||||
suppressions.xml
|
suppressions.xml
|
||||||
</suppressionsLocation>
|
</suppressionsLocation>
|
||||||
<failOnViolation>true</failOnViolation>
|
<failOnViolation>true</failOnViolation>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
||||||
|
|
||||||
|
|
|
@ -41,70 +41,70 @@ import pw.kaboom.extras.modules.server.ServerTabComplete;
|
||||||
import pw.kaboom.extras.modules.server.ServerTick;
|
import pw.kaboom.extras.modules.server.ServerTick;
|
||||||
|
|
||||||
public final class Main extends JavaPlugin {
|
public final class Main extends JavaPlugin {
|
||||||
@Override
|
@Override
|
||||||
public void onLoad() {
|
public void onLoad() {
|
||||||
/* Fill lists */
|
/* Fill lists */
|
||||||
Collections.addAll(
|
Collections.addAll(
|
||||||
BlockPhysics.getBlockFaces(),
|
BlockPhysics.getBlockFaces(),
|
||||||
BlockFace.NORTH,
|
BlockFace.NORTH,
|
||||||
BlockFace.SOUTH,
|
BlockFace.SOUTH,
|
||||||
BlockFace.WEST,
|
BlockFace.WEST,
|
||||||
BlockFace.EAST,
|
BlockFace.EAST,
|
||||||
BlockFace.UP
|
BlockFace.UP
|
||||||
);
|
);
|
||||||
|
|
||||||
/* Load missing config.yml defaults */
|
/* Load missing config.yml defaults */
|
||||||
getConfig().options().copyDefaults(true);
|
getConfig().options().copyDefaults(true);
|
||||||
saveConfig();
|
saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
/* Commands */
|
/* Commands */
|
||||||
this.getCommand("broadcastvanilla").setExecutor(new CommandBroadcastVanilla());
|
this.getCommand("broadcastvanilla").setExecutor(new CommandBroadcastVanilla());
|
||||||
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("enchantall").setExecutor(new CommandEnchantAll());
|
this.getCommand("enchantall").setExecutor(new CommandEnchantAll());
|
||||||
this.getCommand("jumpscare").setExecutor(new CommandJumpscare());
|
this.getCommand("jumpscare").setExecutor(new CommandJumpscare());
|
||||||
this.getCommand("kaboom").setExecutor(new CommandKaboom());
|
this.getCommand("kaboom").setExecutor(new CommandKaboom());
|
||||||
this.getCommand("ping").setExecutor(new CommandPing());
|
this.getCommand("ping").setExecutor(new CommandPing());
|
||||||
this.getCommand("prefix").setExecutor(new CommandPrefix());
|
this.getCommand("prefix").setExecutor(new CommandPrefix());
|
||||||
this.getCommand("pumpkin").setExecutor(new CommandPumpkin());
|
this.getCommand("pumpkin").setExecutor(new CommandPumpkin());
|
||||||
this.getCommand("serverinfo").setExecutor(new CommandServerInfo());
|
this.getCommand("serverinfo").setExecutor(new CommandServerInfo());
|
||||||
this.getCommand("skin").setExecutor(new CommandSkin());
|
this.getCommand("skin").setExecutor(new CommandSkin());
|
||||||
this.getCommand("spawn").setExecutor(new CommandSpawn());
|
this.getCommand("spawn").setExecutor(new CommandSpawn());
|
||||||
this.getCommand("spidey").setExecutor(new CommandSpidey());
|
this.getCommand("spidey").setExecutor(new CommandSpidey());
|
||||||
this.getCommand("tellraw").setExecutor(new CommandTellraw());
|
this.getCommand("tellraw").setExecutor(new CommandTellraw());
|
||||||
this.getCommand("username").setExecutor(new CommandUsername());
|
this.getCommand("username").setExecutor(new CommandUsername());
|
||||||
|
|
||||||
/* Block-related modules */
|
/* Block-related modules */
|
||||||
this.getServer().getPluginManager().registerEvents(new BlockCheck(), this);
|
this.getServer().getPluginManager().registerEvents(new BlockCheck(), this);
|
||||||
this.getServer().getPluginManager().registerEvents(new BlockPhysics(), this);
|
this.getServer().getPluginManager().registerEvents(new BlockPhysics(), this);
|
||||||
|
|
||||||
/* Entity-related modules */
|
/* Entity-related modules */
|
||||||
this.getServer().getPluginManager().registerEvents(new EntityExplosion(), this);
|
this.getServer().getPluginManager().registerEvents(new EntityExplosion(), this);
|
||||||
this.getServer().getPluginManager().registerEvents(new EntityKnockback(), this);
|
this.getServer().getPluginManager().registerEvents(new EntityKnockback(), this);
|
||||||
this.getServer().getPluginManager().registerEvents(new EntitySpawn(), this);
|
this.getServer().getPluginManager().registerEvents(new EntitySpawn(), this);
|
||||||
this.getServer().getPluginManager().registerEvents(new EntityTeleport(), this);
|
this.getServer().getPluginManager().registerEvents(new EntityTeleport(), this);
|
||||||
|
|
||||||
/* Player-related modules */
|
/* Player-related modules */
|
||||||
this.getServer().getPluginManager().registerEvents(new PlayerChat(), this);
|
this.getServer().getPluginManager().registerEvents(new PlayerChat(), this);
|
||||||
this.getServer().getPluginManager().registerEvents(new PlayerCommand(), this);
|
this.getServer().getPluginManager().registerEvents(new PlayerCommand(), this);
|
||||||
this.getServer().getPluginManager().registerEvents(new PlayerConnection(), this);
|
this.getServer().getPluginManager().registerEvents(new PlayerConnection(), this);
|
||||||
this.getServer().getPluginManager().registerEvents(new PlayerDamage(), this);
|
this.getServer().getPluginManager().registerEvents(new PlayerDamage(), this);
|
||||||
this.getServer().getPluginManager().registerEvents(new PlayerInteract(), this);
|
this.getServer().getPluginManager().registerEvents(new PlayerInteract(), this);
|
||||||
this.getServer().getPluginManager().registerEvents(new PlayerRecipe(), this);
|
this.getServer().getPluginManager().registerEvents(new PlayerRecipe(), this);
|
||||||
this.getServer().getPluginManager().registerEvents(new PlayerTeleport(), this);
|
this.getServer().getPluginManager().registerEvents(new PlayerTeleport(), this);
|
||||||
|
|
||||||
/* Server-related modules */
|
/* Server-related modules */
|
||||||
this.getServer().getPluginManager().registerEvents(new ServerCommand(), this);
|
this.getServer().getPluginManager().registerEvents(new ServerCommand(), this);
|
||||||
this.getServer().getPluginManager().registerEvents(new ServerTabComplete(), this);
|
this.getServer().getPluginManager().registerEvents(new ServerTabComplete(), this);
|
||||||
this.getServer().getPluginManager().registerEvents(new ServerTick(), this);
|
this.getServer().getPluginManager().registerEvents(new ServerTick(), this);
|
||||||
|
|
||||||
/* Custom worlds */
|
/* Custom worlds */
|
||||||
this.getServer().createWorld(
|
this.getServer().createWorld(
|
||||||
new WorldCreator("world_flatlands").generateStructures(false).type(WorldType.FLAT)
|
new WorldCreator("world_flatlands").generateStructures(false).type(WorldType.FLAT)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,12 +7,12 @@ import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
public final class CommandBroadcastVanilla implements CommandExecutor {
|
public final class CommandBroadcastVanilla implements CommandExecutor {
|
||||||
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
|
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
sender.sendMessage(ChatColor.RED + "Usage: /" + label + " <message ..>");
|
sender.sendMessage(ChatColor.RED + "Usage: /" + label + " <message ..>");
|
||||||
} else {
|
} else {
|
||||||
Command.broadcastCommandMessage(sender, ChatColor.translateAlternateColorCodes('&', String.join(" ", args)));
|
Command.broadcastCommandMessage(sender, ChatColor.translateAlternateColorCodes('&', String.join(" ", args)));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,15 +10,15 @@ import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public final class CommandClearChat implements CommandExecutor {
|
public final class CommandClearChat implements CommandExecutor {
|
||||||
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
|
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
|
||||||
final int maxMessages = 100;
|
final int maxMessages = 100;
|
||||||
|
|
||||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||||
for (int i = 0; i < maxMessages; ++i) {
|
for (int i = 0; i < maxMessages; ++i) {
|
||||||
onlinePlayer.sendMessage("");
|
onlinePlayer.sendMessage("");
|
||||||
}
|
}
|
||||||
onlinePlayer.sendMessage(ChatColor.DARK_GREEN + "The chat has been cleared");
|
onlinePlayer.sendMessage(ChatColor.DARK_GREEN + "The chat has been cleared");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,15 +8,15 @@ import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
public final class CommandConsole implements CommandExecutor {
|
public final class CommandConsole implements CommandExecutor {
|
||||||
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
|
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
sender.sendMessage(ChatColor.RED + "Usage: /" + label + " <message ..>");
|
sender.sendMessage(ChatColor.RED + "Usage: /" + label + " <message ..>");
|
||||||
} else {
|
} else {
|
||||||
Bukkit.dispatchCommand(
|
Bukkit.dispatchCommand(
|
||||||
Bukkit.getConsoleSender(),
|
Bukkit.getConsoleSender(),
|
||||||
"minecraft:say " + ChatColor.translateAlternateColorCodes('&', String.join(" ", args))
|
"minecraft:say " + ChatColor.translateAlternateColorCodes('&', String.join(" ", args))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,22 +9,22 @@ import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
|
|
||||||
public final class CommandDestroyEntities implements CommandExecutor {
|
public final class CommandDestroyEntities implements CommandExecutor {
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
|
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
|
||||||
int entityCount = 0;
|
int entityCount = 0;
|
||||||
int worldCount = 0;
|
int worldCount = 0;
|
||||||
|
|
||||||
for (World world : Bukkit.getWorlds()) {
|
for (World world : Bukkit.getWorlds()) {
|
||||||
for (Entity entity : world.getEntities()) {
|
for (Entity entity : world.getEntities()) {
|
||||||
if (!EntityType.PLAYER.equals(entity.getType())) {
|
if (!EntityType.PLAYER.equals(entity.getType())) {
|
||||||
entity.remove();
|
entity.remove();
|
||||||
entityCount++;
|
entityCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
worldCount++;
|
worldCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
sender.sendMessage("Successfully destroyed " + entityCount + " entities in " + worldCount + " worlds");
|
sender.sendMessage("Successfully destroyed " + entityCount + " entities in " + worldCount + " worlds");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,22 +14,22 @@ import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
public final class CommandEnchantAll implements CommandExecutor {
|
public final class CommandEnchantAll implements CommandExecutor {
|
||||||
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
|
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
|
||||||
if (sender instanceof ConsoleCommandSender) {
|
if (sender instanceof ConsoleCommandSender) {
|
||||||
sender.sendMessage("Command has to be run by a player");
|
sender.sendMessage("Command has to be run by a player");
|
||||||
} else {
|
} else {
|
||||||
final Player player = (Player) sender;
|
final Player player = (Player) sender;
|
||||||
final ItemStack item = player.getInventory().getItemInMainHand();
|
final ItemStack item = player.getInventory().getItemInMainHand();
|
||||||
|
|
||||||
if (Material.AIR.equals(item.getType())) {
|
if (Material.AIR.equals(item.getType())) {
|
||||||
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 {
|
||||||
for (Enchantment enchantment : Enchantment.values()) {
|
for (Enchantment enchantment : Enchantment.values()) {
|
||||||
item.addUnsafeEnchantment(enchantment, Short.MAX_VALUE);
|
item.addUnsafeEnchantment(enchantment, Short.MAX_VALUE);
|
||||||
}
|
}
|
||||||
player.sendMessage("I killed Martin.");
|
player.sendMessage("I killed Martin.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,35 +12,35 @@ import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public final class CommandJumpscare implements CommandExecutor {
|
public final class CommandJumpscare implements CommandExecutor {
|
||||||
private void createJumpscare(final Player player) {
|
private void createJumpscare(final Player player) {
|
||||||
final int count = 4;
|
final int count = 4;
|
||||||
player.spawnParticle(Particle.MOB_APPEARANCE, player.getLocation(), count);
|
player.spawnParticle(Particle.MOB_APPEARANCE, player.getLocation(), count);
|
||||||
|
|
||||||
final int maxIterator = 10;
|
final int maxIterator = 10;
|
||||||
for (int i = 0; i <= maxIterator; i++) {
|
for (int i = 0; i <= maxIterator; i++) {
|
||||||
player.playSound(player.getLocation(), Sound.ENTITY_ENDERMAN_SCREAM, 1, 0);
|
player.playSound(player.getLocation(), Sound.ENTITY_ENDERMAN_SCREAM, 1, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
|
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
sender.sendMessage(ChatColor.RED + "Usage: /" + label + " <player>");
|
sender.sendMessage(ChatColor.RED + "Usage: /" + label + " <player>");
|
||||||
} else {
|
} else {
|
||||||
if (args[0].equals("*") || args[0].equals("**")) {
|
if (args[0].equals("*") || args[0].equals("**")) {
|
||||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||||
createJumpscare(onlinePlayer);
|
createJumpscare(onlinePlayer);
|
||||||
}
|
}
|
||||||
sender.sendMessage("Successfully created jumpscare for every player");
|
sender.sendMessage("Successfully created jumpscare for every player");
|
||||||
} else {
|
} else {
|
||||||
final Player target = Bukkit.getPlayer(args[0]);
|
final Player target = Bukkit.getPlayer(args[0]);
|
||||||
if (target != null) {
|
if (target != null) {
|
||||||
createJumpscare(target);
|
createJumpscare(target);
|
||||||
sender.sendMessage("Successfully created jumpscare for player \"" + target.getName() + "\"");
|
sender.sendMessage("Successfully created jumpscare for player \"" + target.getName() + "\"");
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage("Player \"" + args[0] + "\" not found");
|
sender.sendMessage("Player \"" + args[0] + "\" not found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,35 +15,35 @@ import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
public final class CommandKaboom implements CommandExecutor {
|
public final class CommandKaboom implements CommandExecutor {
|
||||||
|
|
||||||
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
|
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
|
||||||
final Player player = (Player) sender;
|
final Player player = (Player) sender;
|
||||||
boolean explode = ThreadLocalRandom.current().nextBoolean();
|
boolean explode = ThreadLocalRandom.current().nextBoolean();
|
||||||
|
|
||||||
if (explode) {
|
if (explode) {
|
||||||
final Location location = player.getLocation();
|
final Location location = player.getLocation();
|
||||||
final World world = player.getWorld();
|
final World world = player.getWorld();
|
||||||
final int explosionCount = 20;
|
final int explosionCount = 20;
|
||||||
final int power = 8;
|
final int power = 8;
|
||||||
|
|
||||||
world.createExplosion(location, power, true, true);
|
world.createExplosion(location, power, true, true);
|
||||||
|
|
||||||
for (int i = 0; i < explosionCount; i++) {
|
for (int i = 0; i < explosionCount; i++) {
|
||||||
final double posX = location.getX() + ThreadLocalRandom.current().nextInt(-15, 15);
|
final double posX = location.getX() + ThreadLocalRandom.current().nextInt(-15, 15);
|
||||||
final double posY = location.getY() + ThreadLocalRandom.current().nextInt(-6, 6);
|
final double posY = location.getY() + ThreadLocalRandom.current().nextInt(-6, 6);
|
||||||
final double posZ = location.getZ() + ThreadLocalRandom.current().nextInt(-15, 15);
|
final double posZ = location.getZ() + ThreadLocalRandom.current().nextInt(-15, 15);
|
||||||
|
|
||||||
final Location explodeLocation = new Location(world, posX, posY, posZ);
|
final Location explodeLocation = new Location(world, posX, posY, posZ);
|
||||||
final int power2 = 4;
|
final int power2 = 4;
|
||||||
|
|
||||||
world.createExplosion(explodeLocation, power2, true, true);
|
world.createExplosion(explodeLocation, power2, true, true);
|
||||||
explodeLocation.getBlock().setType(Material.LAVA);
|
explodeLocation.getBlock().setType(Material.LAVA);
|
||||||
}
|
}
|
||||||
|
|
||||||
player.sendMessage("Forgive me :c");
|
player.sendMessage("Forgive me :c");
|
||||||
} else {
|
} else {
|
||||||
player.getInventory().setItemInMainHand(new ItemStack(Material.CAKE));
|
player.getInventory().setItemInMainHand(new ItemStack(Material.CAKE));
|
||||||
player.sendMessage("Have a nice day :)");
|
player.sendMessage("Have a nice day :)");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,31 +19,31 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import pw.kaboom.extras.Main;
|
import pw.kaboom.extras.Main;
|
||||||
|
|
||||||
public final class CommandPrefix implements CommandExecutor {
|
public final class CommandPrefix implements CommandExecutor {
|
||||||
public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) {
|
public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) {
|
||||||
if (sender instanceof ConsoleCommandSender) {
|
if (sender instanceof ConsoleCommandSender) {
|
||||||
sender.sendMessage("Command has to be run by a player");
|
sender.sendMessage("Command has to be run by a player");
|
||||||
} else {
|
} else {
|
||||||
final Player player = (Player) sender;
|
final Player player = (Player) sender;
|
||||||
final File configFile = new File(JavaPlugin.getPlugin(Main.class).getDataFolder(), "prefixes.yml");
|
final File configFile = new File(JavaPlugin.getPlugin(Main.class).getDataFolder(), "prefixes.yml");
|
||||||
final FileConfiguration prefixConfig = YamlConfiguration.loadConfiguration(configFile);
|
final FileConfiguration prefixConfig = YamlConfiguration.loadConfiguration(configFile);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
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 ("off".equalsIgnoreCase(args[0])) {
|
} else if ("off".equalsIgnoreCase(args[0])) {
|
||||||
prefixConfig.set(player.getUniqueId().toString(), null);
|
prefixConfig.set(player.getUniqueId().toString(), null);
|
||||||
prefixConfig.save(configFile);
|
prefixConfig.save(configFile);
|
||||||
player.sendMessage("You no longer have a tag");
|
player.sendMessage("You no longer have a tag");
|
||||||
} else {
|
} else {
|
||||||
prefixConfig.set(player.getUniqueId().toString(), String.join(" ", args));
|
prefixConfig.set(player.getUniqueId().toString(), String.join(" ", args));
|
||||||
prefixConfig.save(configFile);
|
prefixConfig.save(configFile);
|
||||||
player.sendMessage("You now have the tag: " + ChatColor.translateAlternateColorCodes('&', String.join(" ", args)));
|
player.sendMessage("You now have the tag: " + ChatColor.translateAlternateColorCodes('&', String.join(" ", args)));
|
||||||
}
|
}
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
player.sendMessage("Something went wrong while saving the prefix. Please check console.");
|
player.sendMessage("Something went wrong while saving the prefix. Please check console.");
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,29 +13,29 @@ import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
public final class CommandPumpkin implements CommandExecutor {
|
public final class CommandPumpkin implements CommandExecutor {
|
||||||
private void placePumpkin(final Player player) {
|
private void placePumpkin(final Player player) {
|
||||||
player.getInventory().setHelmet(new ItemStack(Material.CARVED_PUMPKIN));
|
player.getInventory().setHelmet(new ItemStack(Material.CARVED_PUMPKIN));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
|
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
sender.sendMessage(ChatColor.RED + "Usage: /" + label + " <player>");
|
sender.sendMessage(ChatColor.RED + "Usage: /" + label + " <player>");
|
||||||
} else {
|
} else {
|
||||||
if (args[0].equals("*") || args[0].equals("**")) {
|
if (args[0].equals("*") || args[0].equals("**")) {
|
||||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||||
placePumpkin(onlinePlayer);
|
placePumpkin(onlinePlayer);
|
||||||
}
|
}
|
||||||
sender.sendMessage("Everyone is now a pumpkin");
|
sender.sendMessage("Everyone is now a pumpkin");
|
||||||
} else {
|
} else {
|
||||||
final Player target = Bukkit.getPlayer(args[0]);
|
final Player target = Bukkit.getPlayer(args[0]);
|
||||||
if (target != null) {
|
if (target != null) {
|
||||||
placePumpkin(target);
|
placePumpkin(target);
|
||||||
sender.sendMessage("Player \"" + target.getName() + "\" is now a pumpkin");
|
sender.sendMessage("Player \"" + target.getName() + "\" is now a pumpkin");
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage("Player \"" + args[0] + "\" not found");
|
sender.sendMessage("Player \"" + args[0] + "\" not found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,99 +13,99 @@ import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
public final class CommandServerInfo implements CommandExecutor {
|
public final class CommandServerInfo implements CommandExecutor {
|
||||||
private void sendInfoMessage(final CommandSender target, final String description, final String value) {
|
private void sendInfoMessage(final CommandSender target, final String description, final String value) {
|
||||||
target.sendMessage(
|
target.sendMessage(
|
||||||
ChatColor.GRAY + description + ": "
|
ChatColor.GRAY + description + ": "
|
||||||
+ ChatColor.WHITE + value
|
+ ChatColor.WHITE + value
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
|
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
|
||||||
try {
|
try {
|
||||||
sendInfoMessage(sender, "Hostname",
|
sendInfoMessage(sender, "Hostname",
|
||||||
InetAddress.getLocalHost().getHostName()
|
InetAddress.getLocalHost().getHostName()
|
||||||
);
|
);
|
||||||
sendInfoMessage(sender, "IP address",
|
sendInfoMessage(sender, "IP address",
|
||||||
InetAddress.getLocalHost().getHostAddress()
|
InetAddress.getLocalHost().getHostAddress()
|
||||||
);
|
);
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
|
|
||||||
sendInfoMessage(sender, "OS name",
|
sendInfoMessage(sender, "OS name",
|
||||||
ManagementFactory.getOperatingSystemMXBean().getName()
|
ManagementFactory.getOperatingSystemMXBean().getName()
|
||||||
);
|
);
|
||||||
sendInfoMessage(sender, "OS architecture",
|
sendInfoMessage(sender, "OS architecture",
|
||||||
ManagementFactory.getOperatingSystemMXBean().getArch()
|
ManagementFactory.getOperatingSystemMXBean().getArch()
|
||||||
);
|
);
|
||||||
sendInfoMessage(sender, "OS version",
|
sendInfoMessage(sender, "OS version",
|
||||||
ManagementFactory.getOperatingSystemMXBean().getVersion()
|
ManagementFactory.getOperatingSystemMXBean().getVersion()
|
||||||
);
|
);
|
||||||
sendInfoMessage(sender, "Java VM",
|
sendInfoMessage(sender, "Java VM",
|
||||||
ManagementFactory.getRuntimeMXBean().getVmName()
|
ManagementFactory.getRuntimeMXBean().getVmName()
|
||||||
);
|
);
|
||||||
sendInfoMessage(sender, "Java version",
|
sendInfoMessage(sender, "Java version",
|
||||||
ManagementFactory.getRuntimeMXBean().getSpecVersion()
|
ManagementFactory.getRuntimeMXBean().getSpecVersion()
|
||||||
+ " "
|
+ " "
|
||||||
+ ManagementFactory.getRuntimeMXBean().getVmVersion()
|
+ ManagementFactory.getRuntimeMXBean().getVmVersion()
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final String[] shCommand = {
|
final String[] shCommand = {
|
||||||
"/bin/sh",
|
"/bin/sh",
|
||||||
"-c",
|
"-c",
|
||||||
"cat /proc/cpuinfo | grep 'model name' | cut -f 2 -d ':' | awk '{$1=$1}1' | head -1"
|
"cat /proc/cpuinfo | grep 'model name' | cut -f 2 -d ':' | awk '{$1=$1}1' | head -1"
|
||||||
};
|
};
|
||||||
|
|
||||||
final Process process = Runtime.getRuntime().exec(shCommand);
|
final Process process = Runtime.getRuntime().exec(shCommand);
|
||||||
final InputStreamReader isr = new InputStreamReader(process.getInputStream());
|
final InputStreamReader isr = new InputStreamReader(process.getInputStream());
|
||||||
final BufferedReader br = new BufferedReader(isr);
|
final BufferedReader br = new BufferedReader(isr);
|
||||||
String line;
|
String line;
|
||||||
|
|
||||||
while ((line = br.readLine()) != null) {
|
while ((line = br.readLine()) != null) {
|
||||||
sendInfoMessage(sender, "CPU model",
|
sendInfoMessage(sender, "CPU model",
|
||||||
line
|
line
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
br.close();
|
br.close();
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
|
|
||||||
sendInfoMessage(sender, "CPU cores",
|
sendInfoMessage(sender, "CPU cores",
|
||||||
String.valueOf(Runtime.getRuntime().availableProcessors())
|
String.valueOf(Runtime.getRuntime().availableProcessors())
|
||||||
);
|
);
|
||||||
sendInfoMessage(sender, "CPU load",
|
sendInfoMessage(sender, "CPU load",
|
||||||
String.valueOf(ManagementFactory.getOperatingSystemMXBean().getSystemLoadAverage())
|
String.valueOf(ManagementFactory.getOperatingSystemMXBean().getSystemLoadAverage())
|
||||||
);
|
);
|
||||||
|
|
||||||
final long heapUsage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed();
|
final long heapUsage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed();
|
||||||
final long nonHeapUsage = ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage().getUsed();
|
final long nonHeapUsage = ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage().getUsed();
|
||||||
final long memoryMax = (
|
final long memoryMax = (
|
||||||
ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getMax()
|
ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getMax()
|
||||||
+ ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage().getMax()
|
+ ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage().getMax()
|
||||||
);
|
);
|
||||||
final long memoryUsage = (heapUsage + nonHeapUsage);
|
final long memoryUsage = (heapUsage + nonHeapUsage);
|
||||||
|
|
||||||
sendInfoMessage(sender, "Available memory",
|
sendInfoMessage(sender, "Available memory",
|
||||||
(memoryMax / 1024 / 1024) + " MB"
|
(memoryMax / 1024 / 1024) + " MB"
|
||||||
);
|
);
|
||||||
sendInfoMessage(sender, "Heap memory usage",
|
sendInfoMessage(sender, "Heap memory usage",
|
||||||
(heapUsage / 1024 / 1024) + " MB"
|
(heapUsage / 1024 / 1024) + " MB"
|
||||||
);
|
);
|
||||||
sendInfoMessage(sender, "Non-heap memory usage",
|
sendInfoMessage(sender, "Non-heap memory usage",
|
||||||
(nonHeapUsage / 1024 / 1024) + " MB"
|
(nonHeapUsage / 1024 / 1024) + " MB"
|
||||||
);
|
);
|
||||||
sendInfoMessage(sender, "Total memory usage",
|
sendInfoMessage(sender, "Total memory usage",
|
||||||
(memoryUsage / 1024 / 1024) + " MB"
|
(memoryUsage / 1024 / 1024) + " MB"
|
||||||
);
|
);
|
||||||
|
|
||||||
final long minutes = (ManagementFactory.getRuntimeMXBean().getUptime() / 1000) / 60;
|
final long minutes = (ManagementFactory.getRuntimeMXBean().getUptime() / 1000) / 60;
|
||||||
final long seconds = (ManagementFactory.getRuntimeMXBean().getUptime() / 1000) % 60;
|
final long seconds = (ManagementFactory.getRuntimeMXBean().getUptime() / 1000) % 60;
|
||||||
|
|
||||||
sendInfoMessage(sender, "Server uptime",
|
sendInfoMessage(sender, "Server uptime",
|
||||||
minutes + " minute(s) "
|
minutes + " minute(s) "
|
||||||
+ seconds + " second(s)"
|
+ seconds + " second(s)"
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,31 +10,31 @@ import org.bukkit.entity.Player;
|
||||||
import pw.kaboom.extras.helpers.SkinDownloader;
|
import pw.kaboom.extras.helpers.SkinDownloader;
|
||||||
|
|
||||||
public final class CommandSkin implements CommandExecutor {
|
public final class CommandSkin implements CommandExecutor {
|
||||||
private long millis;
|
private long millis;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
|
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
|
||||||
if (sender instanceof ConsoleCommandSender) {
|
if (sender instanceof ConsoleCommandSender) {
|
||||||
sender.sendMessage("Command has to be run by a player");
|
sender.sendMessage("Command has to be run by a player");
|
||||||
} else {
|
} else {
|
||||||
final Player player = (Player) sender;
|
final Player player = (Player) sender;
|
||||||
|
|
||||||
final long millisDifference = System.currentTimeMillis() - millis;
|
final long millisDifference = System.currentTimeMillis() - millis;
|
||||||
|
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
player.sendMessage(ChatColor.RED + "Usage: /" + label + " <username>");
|
player.sendMessage(ChatColor.RED + "Usage: /" + label + " <username>");
|
||||||
} else if (millisDifference <= 2000) {
|
} else if (millisDifference <= 2000) {
|
||||||
player.sendMessage("Please wait a few seconds before changing your skin");
|
player.sendMessage("Please wait a few seconds before changing your skin");
|
||||||
} else {
|
} else {
|
||||||
final String name = args[0];
|
final String name = args[0];
|
||||||
final boolean shouldSendMessage = true;
|
final boolean shouldSendMessage = true;
|
||||||
|
|
||||||
SkinDownloader skinDownloader = new SkinDownloader();
|
SkinDownloader skinDownloader = new SkinDownloader();
|
||||||
skinDownloader.applySkin(player, name, shouldSendMessage);
|
skinDownloader.applySkin(player, name, shouldSendMessage);
|
||||||
|
|
||||||
millis = System.currentTimeMillis();
|
millis = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,28 +15,28 @@ import org.bukkit.command.ConsoleCommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public final class CommandSpawn implements CommandExecutor {
|
public final class CommandSpawn implements CommandExecutor {
|
||||||
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
|
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
|
||||||
if (sender instanceof ConsoleCommandSender) {
|
if (sender instanceof ConsoleCommandSender) {
|
||||||
sender.sendMessage("Command has to be run by a player");
|
sender.sendMessage("Command has to be run by a player");
|
||||||
} else {
|
} else {
|
||||||
final Player player = (Player) sender;
|
final Player player = (Player) sender;
|
||||||
final World world = Bukkit.getWorld("world");
|
final World world = Bukkit.getWorld("world");
|
||||||
final Location spawnLocation = world.getSpawnLocation();
|
final Location spawnLocation = world.getSpawnLocation();
|
||||||
final int maxWorldHeight = 256;
|
final int maxWorldHeight = 256;
|
||||||
|
|
||||||
for (double y = spawnLocation.getY(); y <= maxWorldHeight; y++) {
|
for (double y = spawnLocation.getY(); y <= maxWorldHeight; y++) {
|
||||||
final Location yLocation = new Location(world, spawnLocation.getX(), y, spawnLocation.getZ());
|
final Location yLocation = new Location(world, spawnLocation.getX(), y, spawnLocation.getZ());
|
||||||
final Block coordBlock = world.getBlockAt(yLocation);
|
final Block coordBlock = world.getBlockAt(yLocation);
|
||||||
|
|
||||||
if (!coordBlock.getType().isSolid()
|
if (!coordBlock.getType().isSolid()
|
||||||
&& !coordBlock.getRelative(BlockFace.UP).getType().isSolid()) {
|
&& !coordBlock.getRelative(BlockFace.UP).getType().isSolid()) {
|
||||||
player.teleportAsync(yLocation);
|
player.teleportAsync(yLocation);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
player.sendMessage("Successfully moved to spawn");
|
player.sendMessage("Successfully moved to spawn");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,31 +14,31 @@ import org.bukkit.util.BlockIterator;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
public final class CommandSpidey implements CommandExecutor {
|
public final class CommandSpidey implements CommandExecutor {
|
||||||
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
|
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
|
||||||
if (sender instanceof ConsoleCommandSender) {
|
if (sender instanceof ConsoleCommandSender) {
|
||||||
sender.sendMessage("Command has to be run by a player");
|
sender.sendMessage("Command has to be run by a player");
|
||||||
} else {
|
} else {
|
||||||
final Player player = (Player) sender;
|
final Player player = (Player) sender;
|
||||||
final World world = player.getWorld();
|
final World world = player.getWorld();
|
||||||
final Vector start = player.getEyeLocation().toVector();
|
final Vector start = player.getEyeLocation().toVector();
|
||||||
final Vector direction = player.getEyeLocation().getDirection();
|
final Vector direction = player.getEyeLocation().getDirection();
|
||||||
final int yOffset = 0;
|
final int yOffset = 0;
|
||||||
final int distance = 50;
|
final int distance = 50;
|
||||||
|
|
||||||
final BlockIterator blockIterator = new BlockIterator(
|
final BlockIterator blockIterator = new BlockIterator(
|
||||||
world,
|
world,
|
||||||
start,
|
start,
|
||||||
direction,
|
direction,
|
||||||
yOffset,
|
yOffset,
|
||||||
distance
|
distance
|
||||||
);
|
);
|
||||||
|
|
||||||
while (blockIterator.hasNext()
|
while (blockIterator.hasNext()
|
||||||
&& (Material.AIR.equals(blockIterator.next().getType())
|
&& (Material.AIR.equals(blockIterator.next().getType())
|
||||||
|| Material.CAVE_AIR.equals(blockIterator.next().getType()))) {
|
|| Material.CAVE_AIR.equals(blockIterator.next().getType()))) {
|
||||||
blockIterator.next().setType(Material.COBWEB);
|
blockIterator.next().setType(Material.COBWEB);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,14 +10,14 @@ import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public final class CommandTellraw implements CommandExecutor {
|
public final class CommandTellraw implements CommandExecutor {
|
||||||
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
|
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
sender.sendMessage(ChatColor.RED + "Usage: /" + label + " <message ..>");
|
sender.sendMessage(ChatColor.RED + "Usage: /" + label + " <message ..>");
|
||||||
} else {
|
} else {
|
||||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||||
onlinePlayer.sendMessage(ChatColor.translateAlternateColorCodes('&', String.join(" ", args)));
|
onlinePlayer.sendMessage(ChatColor.translateAlternateColorCodes('&', String.join(" ", args)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,44 +11,44 @@ import org.bukkit.entity.Player;
|
||||||
import com.destroystokyo.paper.profile.PlayerProfile;
|
import com.destroystokyo.paper.profile.PlayerProfile;
|
||||||
|
|
||||||
public final class CommandUsername implements CommandExecutor {
|
public final class CommandUsername implements CommandExecutor {
|
||||||
private long millis;
|
private long millis;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
|
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
|
||||||
if (sender instanceof ConsoleCommandSender) {
|
if (sender instanceof ConsoleCommandSender) {
|
||||||
sender.sendMessage("Command has to be run by a player");
|
sender.sendMessage("Command has to be run by a player");
|
||||||
} else {
|
} else {
|
||||||
final Player player = (Player) sender;
|
final Player player = (Player) sender;
|
||||||
|
|
||||||
final String nameColor = ChatColor.translateAlternateColorCodes('&', String.join(" ", args));
|
final String nameColor = ChatColor.translateAlternateColorCodes('&', String.join(" ", args));
|
||||||
final String name = nameColor.substring(0, Math.min(16, nameColor.length()));
|
final String name = nameColor.substring(0, Math.min(16, nameColor.length()));
|
||||||
|
|
||||||
final long millisDifference = System.currentTimeMillis() - millis;
|
final long millisDifference = System.currentTimeMillis() - millis;
|
||||||
|
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
player.sendMessage(ChatColor.RED + "Usage: /" + label + " <username>");
|
player.sendMessage(ChatColor.RED + "Usage: /" + label + " <username>");
|
||||||
} else if (name.equals(player.getName())) {
|
} else if (name.equals(player.getName())) {
|
||||||
player.sendMessage("You already have the username \"" + name + "\"");
|
player.sendMessage("You already have the username \"" + name + "\"");
|
||||||
} else if (millisDifference <= 2000) {
|
} else if (millisDifference <= 2000) {
|
||||||
player.sendMessage("Please wait a few seconds before changing your username");
|
player.sendMessage("Please wait a few seconds before changing your username");
|
||||||
} else {
|
} else {
|
||||||
if (Bukkit.getPlayer(name) != null
|
if (Bukkit.getPlayer(name) != null
|
||||||
&& Bukkit.getPlayer(name).isOnline()) {
|
&& Bukkit.getPlayer(name).isOnline()) {
|
||||||
player.sendMessage("A player with that username is already logged in");
|
player.sendMessage("A player with that username is already logged in");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
final PlayerProfile profile = player.getPlayerProfile();
|
final PlayerProfile profile = player.getPlayerProfile();
|
||||||
|
|
||||||
profile.setName(name);
|
profile.setName(name);
|
||||||
|
|
||||||
player.setPlayerProfile(profile);
|
player.setPlayerProfile(profile);
|
||||||
|
|
||||||
millis = System.currentTimeMillis();
|
millis = System.currentTimeMillis();
|
||||||
|
|
||||||
player.sendMessage("Successfully set your username to \"" + name + "\"");
|
player.sendMessage("Successfully set your username to \"" + name + "\"");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,88 +20,88 @@ import com.google.gson.JsonParser;
|
||||||
import pw.kaboom.extras.Main;
|
import pw.kaboom.extras.Main;
|
||||||
|
|
||||||
public final class SkinDownloader {
|
public final class SkinDownloader {
|
||||||
private static HashMap<UUID, PlayerProfile> skinProfiles = new HashMap<UUID, PlayerProfile>();
|
private static HashMap<UUID, PlayerProfile> skinProfiles = new HashMap<UUID, PlayerProfile>();
|
||||||
|
|
||||||
private HttpsURLConnection skinConnection;
|
private HttpsURLConnection skinConnection;
|
||||||
private InputStreamReader skinStream;
|
private InputStreamReader skinStream;
|
||||||
|
|
||||||
private String texture;
|
private String texture;
|
||||||
private String signature;
|
private String signature;
|
||||||
|
|
||||||
public void applySkin(final Player player, final String name, final boolean shouldSendMessage) {
|
public void applySkin(final Player player, final String name, final boolean shouldSendMessage) {
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
final PlayerProfile profile = player.getPlayerProfile();
|
final PlayerProfile profile = player.getPlayerProfile();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fetchSkinData(name);
|
fetchSkinData(name);
|
||||||
profile.setProperty(new ProfileProperty("textures", texture, signature));
|
profile.setProperty(new ProfileProperty("textures", texture, signature));
|
||||||
|
|
||||||
if (shouldSendMessage) {
|
if (shouldSendMessage) {
|
||||||
player.sendMessage("Successfully set your skin to " + name + "'s");
|
player.sendMessage("Successfully set your skin to " + name + "'s");
|
||||||
}
|
}
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
try {
|
try {
|
||||||
skinStream.close();
|
skinStream.close();
|
||||||
skinConnection.disconnect();
|
skinConnection.disconnect();
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldSendMessage) {
|
if (shouldSendMessage) {
|
||||||
player.sendMessage("A player with that username doesn't exist");
|
player.sendMessage("A player with that username doesn't exist");
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
player.setPlayerProfile(profile);
|
player.setPlayerProfile(profile);
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.runTask(JavaPlugin.getPlugin(Main.class));
|
}.runTask(JavaPlugin.getPlugin(Main.class));
|
||||||
}
|
}
|
||||||
}.runTaskAsynchronously(JavaPlugin.getPlugin(Main.class));
|
}.runTaskAsynchronously(JavaPlugin.getPlugin(Main.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fillJoinProfile(final PlayerProfile profile, final String name, final UUID uuid) {
|
public void fillJoinProfile(final PlayerProfile profile, final String name, final UUID uuid) {
|
||||||
try {
|
try {
|
||||||
fetchSkinData(name);
|
fetchSkinData(name);
|
||||||
profile.setProperty(new ProfileProperty("textures", texture, signature));
|
profile.setProperty(new ProfileProperty("textures", texture, signature));
|
||||||
skinProfiles.put(uuid, profile);
|
skinProfiles.put(uuid, profile);
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
try {
|
try {
|
||||||
skinStream.close();
|
skinStream.close();
|
||||||
skinConnection.disconnect();
|
skinConnection.disconnect();
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fetchSkinData(final String playerName) throws IOException {
|
private void fetchSkinData(final String playerName) throws IOException {
|
||||||
final URL skinUrl = new URL("https://api.ashcon.app/mojang/v2/user/" + playerName);
|
final URL skinUrl = new URL("https://api.ashcon.app/mojang/v2/user/" + playerName);
|
||||||
skinConnection = (HttpsURLConnection) skinUrl.openConnection();
|
skinConnection = (HttpsURLConnection) skinUrl.openConnection();
|
||||||
skinConnection.setConnectTimeout(0);
|
skinConnection.setConnectTimeout(0);
|
||||||
|
|
||||||
skinStream = new InputStreamReader(skinConnection.getInputStream());
|
skinStream = new InputStreamReader(skinConnection.getInputStream());
|
||||||
final JsonObject responseJson = new JsonParser().parse(skinStream).getAsJsonObject();
|
final JsonObject responseJson = new JsonParser().parse(skinStream).getAsJsonObject();
|
||||||
final JsonObject rawSkin = responseJson.getAsJsonObject("textures").getAsJsonObject("raw");
|
final JsonObject rawSkin = responseJson.getAsJsonObject("textures").getAsJsonObject("raw");
|
||||||
texture = rawSkin.get("value").getAsString();
|
texture = rawSkin.get("value").getAsString();
|
||||||
signature = rawSkin.get("signature").getAsString();
|
signature = rawSkin.get("signature").getAsString();
|
||||||
|
|
||||||
skinStream.close();
|
skinStream.close();
|
||||||
skinConnection.disconnect();
|
skinConnection.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PlayerProfile getProfile(final UUID uuid) {
|
public static PlayerProfile getProfile(final UUID uuid) {
|
||||||
return skinProfiles.get(uuid);
|
return skinProfiles.get(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeProfile(final UUID uuid) {
|
public static void removeProfile(final UUID uuid) {
|
||||||
skinProfiles.remove(uuid);
|
skinProfiles.remove(uuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,27 +8,27 @@ import org.bukkit.event.block.SignChangeEvent;
|
||||||
import org.bukkit.event.world.ChunkUnloadEvent;
|
import org.bukkit.event.world.ChunkUnloadEvent;
|
||||||
|
|
||||||
public final class BlockCheck implements Listener {
|
public final class BlockCheck implements Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onBlockPlace(final BlockPlaceEvent event) {
|
void onBlockPlace(final BlockPlaceEvent event) {
|
||||||
try {
|
try {
|
||||||
final int maxItemStringLength = 3019;
|
final int maxItemStringLength = 3019;
|
||||||
|
|
||||||
if (event.getItemInHand().toString().length() > maxItemStringLength) {
|
if (event.getItemInHand().toString().length() > maxItemStringLength) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
event.getBlockPlaced().getState();
|
event.getBlockPlaced().getState();
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onChunkUnload(final ChunkUnloadEvent event) {
|
void onChunkUnload(final ChunkUnloadEvent event) {
|
||||||
for (Chunk chunk : event.getChunk().getWorld().getForceLoadedChunks()) {
|
for (Chunk chunk : event.getChunk().getWorld().getForceLoadedChunks()) {
|
||||||
chunk.setForceLoaded(false);
|
chunk.setForceLoaded(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onSignChange(final SignChangeEvent event) {
|
void onSignChange(final SignChangeEvent event) {
|
||||||
|
@ -38,4 +38,4 @@ public final class BlockCheck implements Listener {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,149 +19,149 @@ import com.destroystokyo.paper.event.block.BlockDestroyEvent;
|
||||||
|
|
||||||
public final class BlockPhysics implements Listener {
|
public final class BlockPhysics implements Listener {
|
||||||
|
|
||||||
// This class contains code to prevent large areas of non-solid blocks
|
// This class contains code to prevent large areas of non-solid blocks
|
||||||
// from crashing the server
|
// from crashing the server
|
||||||
|
|
||||||
private static HashSet<BlockFace> blockFaces = new HashSet<BlockFace>();
|
private static HashSet<BlockFace> blockFaces = new HashSet<BlockFace>();
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onBlockDestroy(final BlockDestroyEvent event) {
|
void onBlockDestroy(final BlockDestroyEvent event) {
|
||||||
try {
|
try {
|
||||||
if (!event.getBlock().getType().isSolid()) {
|
if (!event.getBlock().getType().isSolid()) {
|
||||||
for (BlockFace face : getBlockFaces()) {
|
for (BlockFace face : getBlockFaces()) {
|
||||||
if (event.getBlock().getRelative(face).getType() != event.getBlock().getType()) {
|
if (event.getBlock().getRelative(face).getType() != event.getBlock().getType()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!event.getBlock().getType().equals(Material.AIR)) {
|
if (!event.getBlock().getType().equals(Material.AIR)) {
|
||||||
event.getBlock().setType(Material.AIR, false);
|
event.getBlock().setType(Material.AIR, false);
|
||||||
}
|
}
|
||||||
if (!event.isCancelled()) {
|
if (!event.isCancelled()) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception | StackOverflowError e) {
|
} catch (Exception | StackOverflowError e) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onBlockFade(final BlockFadeEvent event) {
|
void onBlockFade(final BlockFadeEvent event) {
|
||||||
try {
|
try {
|
||||||
if (event.getBlock().getType() == Material.FIRE) {
|
if (event.getBlock().getType() == Material.FIRE) {
|
||||||
event.getBlock().setType(Material.AIR, false);
|
event.getBlock().setType(Material.AIR, false);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
} catch (Exception | StackOverflowError e) {
|
} catch (Exception | StackOverflowError e) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onBlockForm(final BlockFormEvent event) {
|
void onBlockForm(final BlockFormEvent event) {
|
||||||
try {
|
try {
|
||||||
if (event.getBlock().getType() == Material.LAVA
|
if (event.getBlock().getType() == Material.LAVA
|
||||||
|| event.getBlock().getType() == Material.WATER) {
|
|| event.getBlock().getType() == Material.WATER) {
|
||||||
for (BlockFace face : getBlockFaces()) {
|
for (BlockFace face : getBlockFaces()) {
|
||||||
if (event.getBlock().getRelative(face).getType() != Material.LAVA
|
if (event.getBlock().getRelative(face).getType() != Material.LAVA
|
||||||
&& event.getBlock().getRelative(face).getType() != Material.WATER) {
|
&& event.getBlock().getRelative(face).getType() != Material.WATER) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception | StackOverflowError e) {
|
} catch (Exception | StackOverflowError e) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onBlockFromTo(final BlockFromToEvent event) {
|
void onBlockFromTo(final BlockFromToEvent event) {
|
||||||
try {
|
try {
|
||||||
if (event.getBlock().getType() == Material.LAVA
|
if (event.getBlock().getType() == Material.LAVA
|
||||||
|| event.getBlock().getType() == Material.WATER) {
|
|| event.getBlock().getType() == Material.WATER) {
|
||||||
boolean lavaFound = false;
|
boolean lavaFound = false;
|
||||||
boolean waterFound = false;
|
boolean waterFound = false;
|
||||||
|
|
||||||
for (BlockFace face : getBlockFaces()) {
|
for (BlockFace face : getBlockFaces()) {
|
||||||
if (event.getBlock().getRelative(face).getType() == Material.LAVA && !lavaFound) {
|
if (event.getBlock().getRelative(face).getType() == Material.LAVA && !lavaFound) {
|
||||||
lavaFound = true;
|
lavaFound = true;
|
||||||
} else if (event.getBlock().getRelative(face).getType() == Material.WATER && !waterFound) {
|
} else if (event.getBlock().getRelative(face).getType() == Material.WATER && !waterFound) {
|
||||||
waterFound = true;
|
waterFound = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lavaFound && waterFound) {
|
if (lavaFound && waterFound) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception | StackOverflowError e) {
|
} catch (Exception | StackOverflowError e) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onBlockPhysics(final BlockPhysicsEvent event) {
|
void onBlockPhysics(final BlockPhysicsEvent event) {
|
||||||
try {
|
try {
|
||||||
switch (event.getChangedType()) {
|
switch (event.getChangedType()) {
|
||||||
case ACTIVATOR_RAIL:
|
case ACTIVATOR_RAIL:
|
||||||
case DETECTOR_RAIL:
|
case DETECTOR_RAIL:
|
||||||
case POWERED_RAIL:
|
case POWERED_RAIL:
|
||||||
case RAIL:
|
case RAIL:
|
||||||
case COMPARATOR:
|
case COMPARATOR:
|
||||||
case REDSTONE_TORCH:
|
case REDSTONE_TORCH:
|
||||||
case REDSTONE_WIRE:
|
case REDSTONE_WIRE:
|
||||||
case REPEATER:
|
case REPEATER:
|
||||||
case TRIPWIRE:
|
case TRIPWIRE:
|
||||||
if (!event.getBlock().getRelative(BlockFace.DOWN).getType().isSolid()
|
if (!event.getBlock().getRelative(BlockFace.DOWN).getType().isSolid()
|
||||||
&& !Material.AIR.equals(event.getBlock().getRelative(BlockFace.DOWN).getType())
|
&& !Material.AIR.equals(event.getBlock().getRelative(BlockFace.DOWN).getType())
|
||||||
&& !Material.CAVE_AIR.equals(event.getBlock().getRelative(BlockFace.DOWN).getType())) {
|
&& !Material.CAVE_AIR.equals(event.getBlock().getRelative(BlockFace.DOWN).getType())) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
case COMMAND_BLOCK:
|
case COMMAND_BLOCK:
|
||||||
case CHAIN_COMMAND_BLOCK:
|
case CHAIN_COMMAND_BLOCK:
|
||||||
case REPEATING_COMMAND_BLOCK:
|
case REPEATING_COMMAND_BLOCK:
|
||||||
if (Material.STRUCTURE_BLOCK.equals(event.getSourceBlock().getType())) {
|
if (Material.STRUCTURE_BLOCK.equals(event.getSourceBlock().getType())) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (Exception | StackOverflowError e) {
|
} catch (Exception | StackOverflowError e) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onBlockRedstone(final BlockRedstoneEvent event) {
|
void onBlockRedstone(final BlockRedstoneEvent event) {
|
||||||
final double tps = Bukkit.getServer().getTPS()[0];
|
final double tps = Bukkit.getServer().getTPS()[0];
|
||||||
final int maxTps = 10;
|
final int maxTps = 10;
|
||||||
|
|
||||||
if (tps < maxTps) {
|
if (tps < maxTps) {
|
||||||
event.setNewCurrent(0);
|
event.setNewCurrent(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int fallingBlockCount;
|
private int fallingBlockCount;
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onEntityChangeBlock(final EntityChangeBlockEvent event) {
|
void onEntityChangeBlock(final EntityChangeBlockEvent event) {
|
||||||
if (event.getEntityType() == EntityType.FALLING_BLOCK
|
if (event.getEntityType() == EntityType.FALLING_BLOCK
|
||||||
&& event.getTo() == Material.AIR) {
|
&& event.getTo() == Material.AIR) {
|
||||||
fallingBlockCount++;
|
fallingBlockCount++;
|
||||||
|
|
||||||
final int maxFallingBlockCount = 10;
|
final int maxFallingBlockCount = 10;
|
||||||
|
|
||||||
if (fallingBlockCount == maxFallingBlockCount) {
|
if (fallingBlockCount == maxFallingBlockCount) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
fallingBlockCount = 0;
|
fallingBlockCount = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HashSet<BlockFace> getBlockFaces() {
|
public static HashSet<BlockFace> getBlockFaces() {
|
||||||
return blockFaces;
|
return blockFaces;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,19 +8,19 @@ import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.ExplosionPrimeEvent;
|
import org.bukkit.event.entity.ExplosionPrimeEvent;
|
||||||
|
|
||||||
public final class EntityExplosion implements Listener {
|
public final class EntityExplosion implements Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onExplosionPrime(final ExplosionPrimeEvent event) {
|
void onExplosionPrime(final ExplosionPrimeEvent event) {
|
||||||
final int maxRadius = 20;
|
final int maxRadius = 20;
|
||||||
|
|
||||||
if (event.getRadius() > maxRadius) {
|
if (event.getRadius() > maxRadius) {
|
||||||
event.setRadius(maxRadius);
|
event.setRadius(maxRadius);
|
||||||
}
|
}
|
||||||
|
|
||||||
final int maxFireballCount = 30;
|
final int maxFireballCount = 30;
|
||||||
|
|
||||||
if (event.getEntity().getWorld().getEntitiesByClass(Fireball.class).size() > maxFireballCount
|
if (event.getEntity().getWorld().getEntitiesByClass(Fireball.class).size() > maxFireballCount
|
||||||
&& event.getRadius() > 1) {
|
&& event.getRadius() > 1) {
|
||||||
event.setRadius(1);
|
event.setRadius(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,27 +9,27 @@ import org.bukkit.event.entity.ProjectileHitEvent;
|
||||||
import com.destroystokyo.paper.event.entity.EntityKnockbackByEntityEvent;
|
import com.destroystokyo.paper.event.entity.EntityKnockbackByEntityEvent;
|
||||||
|
|
||||||
public final class EntityKnockback implements Listener {
|
public final class EntityKnockback implements Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onEntityKnockbackByEntity(final EntityKnockbackByEntityEvent event) {
|
void onEntityKnockbackByEntity(final EntityKnockbackByEntityEvent event) {
|
||||||
final int knockbackLimit = 60;
|
final int knockbackLimit = 60;
|
||||||
|
|
||||||
if (event.getKnockbackStrength() > knockbackLimit) {
|
if (event.getKnockbackStrength() > knockbackLimit) {
|
||||||
event.getAcceleration().multiply(
|
event.getAcceleration().multiply(
|
||||||
knockbackLimit / event.getKnockbackStrength()
|
knockbackLimit / event.getKnockbackStrength()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onProjectileHit(final ProjectileHitEvent event) {
|
void onProjectileHit(final ProjectileHitEvent event) {
|
||||||
if (event.getHitEntity() != null
|
if (event.getHitEntity() != null
|
||||||
&& EntityType.ARROW.equals(event.getEntityType())) {
|
&& EntityType.ARROW.equals(event.getEntityType())) {
|
||||||
final Arrow arrow = (Arrow) event.getEntity();
|
final Arrow arrow = (Arrow) event.getEntity();
|
||||||
final int knockbackLimit = 60;
|
final int knockbackLimit = 60;
|
||||||
|
|
||||||
if (arrow.getKnockbackStrength() > knockbackLimit) {
|
if (arrow.getKnockbackStrength() > knockbackLimit) {
|
||||||
arrow.setKnockbackStrength(knockbackLimit);
|
arrow.setKnockbackStrength(knockbackLimit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,270 +34,270 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import pw.kaboom.extras.Main;
|
import pw.kaboom.extras.Main;
|
||||||
|
|
||||||
public final class EntitySpawn implements Listener {
|
public final class EntitySpawn implements Listener {
|
||||||
private static final FileConfiguration CONFIG = JavaPlugin.getPlugin(Main.class).getConfig();
|
private static final FileConfiguration CONFIG = JavaPlugin.getPlugin(Main.class).getConfig();
|
||||||
private static final int MAX_ENTITIES_PER_CHUNK = CONFIG.getInt("maxEntitiesPerChunk");
|
private static final int MAX_ENTITIES_PER_CHUNK = CONFIG.getInt("maxEntitiesPerChunk");
|
||||||
|
|
||||||
private void applyEntityChanges(final Entity entity) {
|
private void applyEntityChanges(final Entity entity) {
|
||||||
switch (entity.getType()) {
|
switch (entity.getType()) {
|
||||||
case AREA_EFFECT_CLOUD:
|
case AREA_EFFECT_CLOUD:
|
||||||
final AreaEffectCloud cloud = (AreaEffectCloud) entity;
|
final AreaEffectCloud cloud = (AreaEffectCloud) entity;
|
||||||
|
|
||||||
limitAreaEffectCloudRadius(cloud);
|
limitAreaEffectCloudRadius(cloud);
|
||||||
return;
|
return;
|
||||||
case MAGMA_CUBE:
|
case MAGMA_CUBE:
|
||||||
case SLIME:
|
case SLIME:
|
||||||
final Slime slime = (Slime) entity;
|
final Slime slime = (Slime) entity;
|
||||||
|
|
||||||
limitSlimeSize(slime);
|
limitSlimeSize(slime);
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkShouldRemoveEntities(final World world) {
|
private boolean checkShouldRemoveEntities(final World world) {
|
||||||
final int worldEntityCount = world.getEntities().size();
|
final int worldEntityCount = world.getEntities().size();
|
||||||
|
|
||||||
if (worldEntityCount > 1024) {
|
if (worldEntityCount > 1024) {
|
||||||
for (Entity entity : world.getEntities()) {
|
for (Entity entity : world.getEntities()) {
|
||||||
if (!EntityType.PLAYER.equals(entity.getType())) {
|
if (!EntityType.PLAYER.equals(entity.getType())) {
|
||||||
entity.remove();
|
entity.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isEntityLimitReached(final EntityType entityType, final Chunk chunk, final World world) {
|
private boolean isEntityLimitReached(final EntityType entityType, final Chunk chunk, final World world) {
|
||||||
switch (entityType) {
|
switch (entityType) {
|
||||||
case ENDER_DRAGON:
|
case ENDER_DRAGON:
|
||||||
final int worldDragonCount = world.getEntitiesByClass(EnderDragon.class).size();
|
final int worldDragonCount = world.getEntitiesByClass(EnderDragon.class).size();
|
||||||
final int worldDragonCountLimit = 24;
|
final int worldDragonCountLimit = 24;
|
||||||
|
|
||||||
if (worldDragonCount >= worldDragonCountLimit) {
|
if (worldDragonCount >= worldDragonCountLimit) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case PRIMED_TNT:
|
case PRIMED_TNT:
|
||||||
final int worldTntCount = world.getEntitiesByClass(TNTPrimed.class).size();
|
final int worldTntCount = world.getEntitiesByClass(TNTPrimed.class).size();
|
||||||
final int worldTntCountLimit = 200;
|
final int worldTntCountLimit = 200;
|
||||||
|
|
||||||
if (worldTntCount >= worldTntCountLimit) {
|
if (worldTntCount >= worldTntCountLimit) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (!EntityType.PLAYER.equals(entityType)) {
|
if (!EntityType.PLAYER.equals(entityType)) {
|
||||||
final int chunkEntityCount = chunk.getEntities().length;
|
final int chunkEntityCount = chunk.getEntities().length;
|
||||||
|
|
||||||
if (chunkEntityCount >= MAX_ENTITIES_PER_CHUNK) {
|
if (chunkEntityCount >= MAX_ENTITIES_PER_CHUNK) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isOutsideBoundaries(final double x, final double y, final double z) {
|
private boolean isOutsideBoundaries(final double x, final double y, final double z) {
|
||||||
final int maxValue = 30000000;
|
final int maxValue = 30000000;
|
||||||
final int minValue = -30000000;
|
final int minValue = -30000000;
|
||||||
|
|
||||||
if (x > maxValue
|
if (x > maxValue
|
||||||
|| x < minValue
|
|| x < minValue
|
||||||
|| y > maxValue
|
|| y > maxValue
|
||||||
|| y < minValue
|
|| y < minValue
|
||||||
|| z > maxValue
|
|| z > maxValue
|
||||||
|| z < minValue) {
|
|| z < minValue) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void limitAreaEffectCloudRadius(final AreaEffectCloud cloud) {
|
private void limitAreaEffectCloudRadius(final AreaEffectCloud cloud) {
|
||||||
if (cloud.getRadius() > 40) {
|
if (cloud.getRadius() > 40) {
|
||||||
cloud.setRadius(40);
|
cloud.setRadius(40);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cloud.getRadiusOnUse() > 0.01f) {
|
if (cloud.getRadiusOnUse() > 0.01f) {
|
||||||
cloud.setRadiusOnUse(0.1f);
|
cloud.setRadiusOnUse(0.1f);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cloud.getRadiusPerTick() > 0) {
|
if (cloud.getRadiusPerTick() > 0) {
|
||||||
cloud.setRadiusPerTick(0);
|
cloud.setRadiusPerTick(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void limitSlimeSize(final Slime slime) {
|
private void limitSlimeSize(final Slime slime) {
|
||||||
if (slime.getSize() > 20) {
|
if (slime.getSize() > 20) {
|
||||||
slime.setSize(20);
|
slime.setSize(20);
|
||||||
|
|
||||||
} else if (slime.getSize() < -20) {
|
} else if (slime.getSize() < -20) {
|
||||||
slime.setSize(-20);
|
slime.setSize(-20);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void limitSpawner(final CreatureSpawner spawner) {
|
private void limitSpawner(final CreatureSpawner spawner) {
|
||||||
if (EntityType.MINECART_MOB_SPAWNER.equals(spawner.getSpawnedType())) {
|
if (EntityType.MINECART_MOB_SPAWNER.equals(spawner.getSpawnedType())) {
|
||||||
spawner.setSpawnedType(EntityType.MINECART);
|
spawner.setSpawnedType(EntityType.MINECART);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spawner.getDelay() > 100) {
|
if (spawner.getDelay() > 100) {
|
||||||
spawner.setMaxSpawnDelay(100);
|
spawner.setMaxSpawnDelay(100);
|
||||||
spawner.setDelay(100);
|
spawner.setDelay(100);
|
||||||
spawner.update();
|
spawner.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spawner.getSpawnCount() > 200) {
|
if (spawner.getSpawnCount() > 200) {
|
||||||
spawner.setSpawnCount(200);
|
spawner.setSpawnCount(200);
|
||||||
spawner.update();
|
spawner.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spawner.getSpawnRange() > 50) {
|
if (spawner.getSpawnRange() > 50) {
|
||||||
spawner.setSpawnRange(50);
|
spawner.setSpawnRange(50);
|
||||||
spawner.update();
|
spawner.update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onAreaEffectCloudApply(final AreaEffectCloudApplyEvent event) {
|
void onAreaEffectCloudApply(final AreaEffectCloudApplyEvent event) {
|
||||||
limitAreaEffectCloudRadius(event.getEntity());
|
limitAreaEffectCloudRadius(event.getEntity());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onExplosionPrime(final ExplosionPrimeEvent event) {
|
void onExplosionPrime(final ExplosionPrimeEvent event) {
|
||||||
if (EntityType.MINECART_TNT.equals(event.getEntityType())
|
if (EntityType.MINECART_TNT.equals(event.getEntityType())
|
||||||
&& event.getEntity().getWorld().getEntitiesByClass(ExplosiveMinecart.class).size() > 80) {
|
&& event.getEntity().getWorld().getEntitiesByClass(ExplosiveMinecart.class).size() > 80) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onEntitySpawn(final EntitySpawnEvent event) {
|
void onEntitySpawn(final EntitySpawnEvent event) {
|
||||||
final double x = event.getLocation().getX();
|
final double x = event.getLocation().getX();
|
||||||
final double y = event.getLocation().getY();
|
final double y = event.getLocation().getY();
|
||||||
final double z = event.getLocation().getZ();
|
final double z = event.getLocation().getZ();
|
||||||
|
|
||||||
if (isOutsideBoundaries(x, y, z)) {
|
if (isOutsideBoundaries(x, y, z)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final EntityType entityType = event.getEntityType();
|
final EntityType entityType = event.getEntityType();
|
||||||
final Chunk chunk = event.getLocation().getChunk();
|
final Chunk chunk = event.getLocation().getChunk();
|
||||||
final World world = event.getLocation().getWorld();
|
final World world = event.getLocation().getWorld();
|
||||||
|
|
||||||
if (isEntityLimitReached(entityType, chunk, world)) {
|
if (isEntityLimitReached(entityType, chunk, world)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (checkShouldRemoveEntities(world)) {
|
if (checkShouldRemoveEntities(world)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Entity entity = event.getEntity();
|
final Entity entity = event.getEntity();
|
||||||
applyEntityChanges(entity);
|
applyEntityChanges(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onItemSpawn(final ItemSpawnEvent event) {
|
void onItemSpawn(final ItemSpawnEvent event) {
|
||||||
try {
|
try {
|
||||||
event.getEntity().getItemStack().getItemMeta();
|
event.getEntity().getItemStack().getItemMeta();
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onLightningStrike(final LightningStrikeEvent event) {
|
void onLightningStrike(final LightningStrikeEvent event) {
|
||||||
final LightningStrike lightning = event.getLightning();
|
final LightningStrike lightning = event.getLightning();
|
||||||
final double x = lightning.getLocation().getX();
|
final double x = lightning.getLocation().getX();
|
||||||
final double y = lightning.getLocation().getY();
|
final double y = lightning.getLocation().getY();
|
||||||
final double z = lightning.getLocation().getZ();
|
final double z = lightning.getLocation().getZ();
|
||||||
|
|
||||||
if (isOutsideBoundaries(x, y, z)) {
|
if (isOutsideBoundaries(x, y, z)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final EntityType entityType = EntityType.LIGHTNING;
|
final EntityType entityType = EntityType.LIGHTNING;
|
||||||
final Chunk chunk = lightning.getChunk();
|
final Chunk chunk = lightning.getChunk();
|
||||||
final World world = event.getWorld();
|
final World world = event.getWorld();
|
||||||
|
|
||||||
if (isEntityLimitReached(entityType, chunk, world)) {
|
if (isEntityLimitReached(entityType, chunk, world)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onPreCreatureSpawn(final PreCreatureSpawnEvent event) {
|
void onPreCreatureSpawn(final PreCreatureSpawnEvent event) {
|
||||||
final EntityType mobType = event.getType();
|
final EntityType mobType = event.getType();
|
||||||
final Chunk chunk = event.getSpawnLocation().getChunk();
|
final Chunk chunk = event.getSpawnLocation().getChunk();
|
||||||
final World world = event.getSpawnLocation().getWorld();
|
final World world = event.getSpawnLocation().getWorld();
|
||||||
|
|
||||||
if (isEntityLimitReached(mobType, chunk, world)) {
|
if (isEntityLimitReached(mobType, chunk, world)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onPreSpawnerSpawn(final PreSpawnerSpawnEvent event) {
|
void onPreSpawnerSpawn(final PreSpawnerSpawnEvent event) {
|
||||||
try {
|
try {
|
||||||
limitSpawner((CreatureSpawner) event.getSpawnerLocation().getBlock().getState());
|
limitSpawner((CreatureSpawner) event.getSpawnerLocation().getBlock().getState());
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onSpawnerSpawn(final SpawnerSpawnEvent event) {
|
void onSpawnerSpawn(final SpawnerSpawnEvent event) {
|
||||||
if (EntityType.FALLING_BLOCK.equals(event.getEntityType())) {
|
if (EntityType.FALLING_BLOCK.equals(event.getEntityType())) {
|
||||||
if (((FallingBlock) event.getEntity()).getBlockData().getMaterial().equals(Material.SPAWNER)) {
|
if (((FallingBlock) event.getEntity()).getBlockData().getMaterial().equals(Material.SPAWNER)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
event.getSpawner().setSpawnedType(EntityType.FALLING_BLOCK);
|
event.getSpawner().setSpawnedType(EntityType.FALLING_BLOCK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onTNTPrime(final TNTPrimeEvent event) {
|
void onTNTPrime(final TNTPrimeEvent event) {
|
||||||
switch (event.getReason()) {
|
switch (event.getReason()) {
|
||||||
case EXPLOSION:
|
case EXPLOSION:
|
||||||
case FIRE:
|
case FIRE:
|
||||||
case REDSTONE:
|
case REDSTONE:
|
||||||
if (ThreadLocalRandom.current().nextBoolean()) {
|
if (ThreadLocalRandom.current().nextBoolean()) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onVehicleCreate(final VehicleCreateEvent event) {
|
void onVehicleCreate(final VehicleCreateEvent event) {
|
||||||
final Vehicle vehicle = event.getVehicle();
|
final Vehicle vehicle = event.getVehicle();
|
||||||
final double x = vehicle.getLocation().getX();
|
final double x = vehicle.getLocation().getX();
|
||||||
final double y = vehicle.getLocation().getY();
|
final double y = vehicle.getLocation().getY();
|
||||||
final double z = vehicle.getLocation().getZ();
|
final double z = vehicle.getLocation().getZ();
|
||||||
|
|
||||||
if (isOutsideBoundaries(x, y, z)) {
|
if (isOutsideBoundaries(x, y, z)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final EntityType entityType = vehicle.getType();
|
final EntityType entityType = vehicle.getType();
|
||||||
final Chunk chunk = vehicle.getChunk();
|
final Chunk chunk = vehicle.getChunk();
|
||||||
final World world = vehicle.getWorld();
|
final World world = vehicle.getWorld();
|
||||||
|
|
||||||
if (isEntityLimitReached(entityType, chunk, world)) {
|
if (isEntityLimitReached(entityType, chunk, world)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
checkShouldRemoveEntities(world);
|
checkShouldRemoveEntities(world);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,38 +6,38 @@ import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.EntityTeleportEvent;
|
import org.bukkit.event.entity.EntityTeleportEvent;
|
||||||
|
|
||||||
public final class EntityTeleport implements Listener {
|
public final class EntityTeleport implements Listener {
|
||||||
public static Location limitLocation(final Location location) {
|
public static Location limitLocation(final Location location) {
|
||||||
double x = location.getX();
|
double x = location.getX();
|
||||||
double y = location.getY();
|
double y = location.getY();
|
||||||
double z = location.getZ();
|
double z = location.getZ();
|
||||||
|
|
||||||
final int maxValue = 30000000;
|
final int maxValue = 30000000;
|
||||||
final int minValue = -30000000;
|
final int minValue = -30000000;
|
||||||
|
|
||||||
if (x > maxValue) {
|
if (x > maxValue) {
|
||||||
location.setX(maxValue);
|
location.setX(maxValue);
|
||||||
}
|
}
|
||||||
if (x < minValue) {
|
if (x < minValue) {
|
||||||
location.setX(minValue);
|
location.setX(minValue);
|
||||||
}
|
}
|
||||||
if (y > maxValue) {
|
if (y > maxValue) {
|
||||||
location.setY(maxValue);
|
location.setY(maxValue);
|
||||||
}
|
}
|
||||||
if (y < minValue) {
|
if (y < minValue) {
|
||||||
location.setY(minValue);
|
location.setY(minValue);
|
||||||
}
|
}
|
||||||
if (z > maxValue) {
|
if (z > maxValue) {
|
||||||
location.setZ(maxValue);
|
location.setZ(maxValue);
|
||||||
}
|
}
|
||||||
if (z < minValue) {
|
if (z < minValue) {
|
||||||
location.setZ(minValue);
|
location.setZ(minValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
return location;
|
return location;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onEntityTeleport(final EntityTeleportEvent event) {
|
void onEntityTeleport(final EntityTeleportEvent event) {
|
||||||
event.setTo(limitLocation(event.getTo()));
|
event.setTo(limitLocation(event.getTo()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,44 +20,44 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import pw.kaboom.extras.Main;
|
import pw.kaboom.extras.Main;
|
||||||
|
|
||||||
public final class PlayerChat implements Listener {
|
public final class PlayerChat implements Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onAsyncPlayerChat(final AsyncPlayerChatEvent event) {
|
void onAsyncPlayerChat(final AsyncPlayerChatEvent event) {
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
final UUID playerUuid = event.getPlayer().getUniqueId();
|
final UUID playerUuid = event.getPlayer().getUniqueId();
|
||||||
|
|
||||||
if (PlayerCommand.getCommandMillisList().get(playerUuid) != null) {
|
if (PlayerCommand.getCommandMillisList().get(playerUuid) != null) {
|
||||||
final long millisDifference = System.currentTimeMillis() - PlayerCommand.getCommandMillisList().get(playerUuid);
|
final long millisDifference = System.currentTimeMillis() - PlayerCommand.getCommandMillisList().get(playerUuid);
|
||||||
|
|
||||||
if (millisDifference < 50) {
|
if (millisDifference < 50) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerCommand.getCommandMillisList().put(playerUuid, System.currentTimeMillis());
|
PlayerCommand.getCommandMillisList().put(playerUuid, System.currentTimeMillis());
|
||||||
|
|
||||||
if (event.isCancelled()) {
|
if (event.isCancelled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final File configFile = new File(JavaPlugin.getPlugin(Main.class).getDataFolder(), "prefixes.yml");
|
final File configFile = new File(JavaPlugin.getPlugin(Main.class).getDataFolder(), "prefixes.yml");
|
||||||
final FileConfiguration prefixConfig = YamlConfiguration.loadConfiguration(configFile);
|
final FileConfiguration prefixConfig = YamlConfiguration.loadConfiguration(configFile);
|
||||||
final String prefix;
|
final String prefix;
|
||||||
final String name = player.getDisplayName().toString();
|
final String name = player.getDisplayName().toString();
|
||||||
|
|
||||||
if (prefixConfig.getString(player.getUniqueId().toString()) != null) {
|
if (prefixConfig.getString(player.getUniqueId().toString()) != null) {
|
||||||
prefix = ChatColor.translateAlternateColorCodes(
|
prefix = ChatColor.translateAlternateColorCodes(
|
||||||
'&',
|
'&',
|
||||||
prefixConfig.getString(player.getUniqueId().toString()) + " " + ChatColor.RESET
|
prefixConfig.getString(player.getUniqueId().toString()) + " " + ChatColor.RESET
|
||||||
);
|
);
|
||||||
} else if (event.getPlayer().isOp()) {
|
} else if (event.getPlayer().isOp()) {
|
||||||
prefix = JavaPlugin.getPlugin(Main.class).getConfig().getString("opTag");
|
prefix = JavaPlugin.getPlugin(Main.class).getConfig().getString("opTag");
|
||||||
} else {
|
} else {
|
||||||
prefix = JavaPlugin.getPlugin(Main.class).getConfig().getString("deOpTag");
|
prefix = JavaPlugin.getPlugin(Main.class).getConfig().getString("deOpTag");
|
||||||
}
|
}
|
||||||
|
|
||||||
event.setFormat(prefix + name + ChatColor.RESET + ": " + ChatColor.RESET + "%2$s");
|
event.setFormat(prefix + name + ChatColor.RESET + ": " + ChatColor.RESET + "%2$s");
|
||||||
event.setMessage(
|
event.setMessage(
|
||||||
ChatColor.translateAlternateColorCodes('&', event.getMessage())
|
ChatColor.translateAlternateColorCodes('&', event.getMessage())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,46 +11,46 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
import pw.kaboom.extras.modules.server.ServerCommand;
|
import pw.kaboom.extras.modules.server.ServerCommand;
|
||||||
|
|
||||||
public final class PlayerCommand implements Listener {
|
public final class PlayerCommand implements Listener {
|
||||||
private static HashMap<UUID, Long> commandMillisList = new HashMap<UUID, Long>();
|
private static HashMap<UUID, Long> commandMillisList = new HashMap<UUID, Long>();
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) {
|
void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) {
|
||||||
final UUID playerUuid = event.getPlayer().getUniqueId();
|
final UUID playerUuid = event.getPlayer().getUniqueId();
|
||||||
|
|
||||||
if (getCommandMillisList().get(playerUuid) != null) {
|
if (getCommandMillisList().get(playerUuid) != null) {
|
||||||
final long millisDifference = System.currentTimeMillis() - getCommandMillisList().get(playerUuid);
|
final long millisDifference = System.currentTimeMillis() - getCommandMillisList().get(playerUuid);
|
||||||
|
|
||||||
if (millisDifference < 75) {
|
if (millisDifference < 75) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getCommandMillisList().put(playerUuid, System.currentTimeMillis());
|
getCommandMillisList().put(playerUuid, System.currentTimeMillis());
|
||||||
|
|
||||||
if (event.isCancelled()) {
|
if (event.isCancelled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final CommandSender sender = event.getPlayer();
|
final CommandSender sender = event.getPlayer();
|
||||||
final String command = event.getMessage();
|
final String command = event.getMessage();
|
||||||
final boolean isConsoleCommand = false;
|
final boolean isConsoleCommand = false;
|
||||||
final String checkedCommand = ServerCommand.checkCommand(sender, command, isConsoleCommand);
|
final String checkedCommand = ServerCommand.checkCommand(sender, command, isConsoleCommand);
|
||||||
|
|
||||||
if (checkedCommand != null) {
|
if (checkedCommand != null) {
|
||||||
if ("cancel".equals(checkedCommand)) {
|
if ("cancel".equals(checkedCommand)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
} else {
|
} else {
|
||||||
event.setMessage(checkedCommand);
|
event.setMessage(checkedCommand);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*final MessageInterceptingCommandRunner cmdRunner = new MessageInterceptingCommandRunner(Bukkit.getConsoleSender());
|
/*final MessageInterceptingCommandRunner cmdRunner = new MessageInterceptingCommandRunner(Bukkit.getConsoleSender());
|
||||||
Bukkit.dispatchCommand(cmdRunner, event.getMessage().substring(1));
|
Bukkit.dispatchCommand(cmdRunner, event.getMessage().substring(1));
|
||||||
|
|
||||||
event.setCancelled(true);*/
|
event.setCancelled(true);*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HashMap<UUID, Long> getCommandMillisList() {
|
public static HashMap<UUID, Long> getCommandMillisList() {
|
||||||
return commandMillisList;
|
return commandMillisList;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,113 +29,113 @@ import pw.kaboom.extras.Main;
|
||||||
import pw.kaboom.extras.modules.server.ServerTabComplete;
|
import pw.kaboom.extras.modules.server.ServerTabComplete;
|
||||||
|
|
||||||
public final class PlayerConnection implements Listener {
|
public final class PlayerConnection implements Listener {
|
||||||
private static final FileConfiguration CONFIG = JavaPlugin.getPlugin(Main.class).getConfig();
|
private static final FileConfiguration CONFIG = JavaPlugin.getPlugin(Main.class).getConfig();
|
||||||
|
|
||||||
private static final String TITLE = CONFIG.getString("playerJoinTitle");
|
private static final String TITLE = CONFIG.getString("playerJoinTitle");
|
||||||
private static final String SUBTITLE = CONFIG.getString("playerJoinSubtitle");
|
private static final String SUBTITLE = CONFIG.getString("playerJoinSubtitle");
|
||||||
private static final int FADE_IN = 10;
|
private static final int FADE_IN = 10;
|
||||||
private static final int STAY = 160;
|
private static final int STAY = 160;
|
||||||
private static final int FADE_OUT = 5;
|
private static final int FADE_OUT = 5;
|
||||||
|
|
||||||
private static final boolean ENABLE_KICK = CONFIG.getBoolean("enableKick");
|
private static final boolean ENABLE_KICK = CONFIG.getBoolean("enableKick");
|
||||||
private static final boolean ENABLE_JOIN_RESTRICTIONS = CONFIG.getBoolean("enableJoinRestrictions");
|
private static final boolean ENABLE_JOIN_RESTRICTIONS = CONFIG.getBoolean("enableJoinRestrictions");
|
||||||
private static final boolean ALLOW_JOIN_ON_FULL_SERVER = CONFIG.getBoolean("allowJoinOnFullServer");
|
private static final boolean ALLOW_JOIN_ON_FULL_SERVER = CONFIG.getBoolean("allowJoinOnFullServer");
|
||||||
private static final boolean OP_ON_JOIN = CONFIG.getBoolean("opOnJoin");
|
private static final boolean OP_ON_JOIN = CONFIG.getBoolean("opOnJoin");
|
||||||
private static final boolean RANDOMIZE_SPAWN = CONFIG.getBoolean("randomizeSpawn");
|
private static final boolean RANDOMIZE_SPAWN = CONFIG.getBoolean("randomizeSpawn");
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onAsyncPlayerPreLogin(final AsyncPlayerPreLoginEvent event) {
|
void onAsyncPlayerPreLogin(final AsyncPlayerPreLoginEvent event) {
|
||||||
if (Bukkit.getPlayer(event.getName()) != null
|
if (Bukkit.getPlayer(event.getName()) != null
|
||||||
&& Bukkit.getPlayer(event.getName()).isOnline()) {
|
&& Bukkit.getPlayer(event.getName()).isOnline()) {
|
||||||
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, "A player with that username is already logged in");
|
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, "A player with that username is already logged in");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*try {
|
/*try {
|
||||||
final PlayerProfile profile = event.getPlayerProfile();
|
final PlayerProfile profile = event.getPlayerProfile();
|
||||||
|
|
||||||
UUID offlineUUID = UUID.nameUUIDFromBytes(("OfflinePlayer:" + event.getName()).getBytes(Charsets.UTF_8));
|
UUID offlineUUID = UUID.nameUUIDFromBytes(("OfflinePlayer:" + event.getName()).getBytes(Charsets.UTF_8));
|
||||||
|
|
||||||
profile.setId(offlineUUID);
|
profile.setId(offlineUUID);
|
||||||
|
|
||||||
SkinDownloader skinDownloader = new SkinDownloader();
|
SkinDownloader skinDownloader = new SkinDownloader();
|
||||||
skinDownloader.fillJoinProfile(profile, event.getName(), event.getUniqueId());
|
skinDownloader.fillJoinProfile(profile, event.getName(), event.getUniqueId());
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onPlayerJoin(final PlayerJoinEvent event) {
|
void onPlayerJoin(final PlayerJoinEvent event) {
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
|
|
||||||
if (TITLE != null
|
if (TITLE != null
|
||||||
|| SUBTITLE != null) {
|
|| SUBTITLE != null) {
|
||||||
player.sendTitle(
|
player.sendTitle(
|
||||||
TITLE,
|
TITLE,
|
||||||
SUBTITLE,
|
SUBTITLE,
|
||||||
FADE_IN,
|
FADE_IN,
|
||||||
STAY,
|
STAY,
|
||||||
FADE_OUT
|
FADE_OUT
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerTabComplete.getLoginNameList().put(player.getUniqueId(), player.getName());
|
ServerTabComplete.getLoginNameList().put(player.getUniqueId(), player.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onPlayerKick(final PlayerKickEvent event) {
|
void onPlayerKick(final PlayerKickEvent event) {
|
||||||
if (!ENABLE_KICK) {
|
if (!ENABLE_KICK) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onPlayerLogin(final PlayerLoginEvent event) {
|
void onPlayerLogin(final PlayerLoginEvent event) {
|
||||||
if (!ENABLE_JOIN_RESTRICTIONS) {
|
if (!ENABLE_JOIN_RESTRICTIONS) {
|
||||||
event.allow();
|
event.allow();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Result.KICK_FULL.equals(event.getResult()) && ALLOW_JOIN_ON_FULL_SERVER) {
|
if (Result.KICK_FULL.equals(event.getResult()) && ALLOW_JOIN_ON_FULL_SERVER) {
|
||||||
event.allow();
|
event.allow();
|
||||||
}
|
}
|
||||||
|
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
|
|
||||||
if (OP_ON_JOIN && !player.isOp()) {
|
if (OP_ON_JOIN && !player.isOp()) {
|
||||||
player.setOp(true);
|
player.setOp(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*try {
|
/*try {
|
||||||
player.setPlayerProfile(SkinDownloader.getProfile(player.getUniqueId()));
|
player.setPlayerProfile(SkinDownloader.getProfile(player.getUniqueId()));
|
||||||
SkinDownloader.removeProfile(player.getUniqueId());
|
SkinDownloader.removeProfile(player.getUniqueId());
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onPlayerSpawn(final PlayerSpawnLocationEvent event) {
|
void onPlayerSpawn(final PlayerSpawnLocationEvent event) {
|
||||||
if (RANDOMIZE_SPAWN && event.getPlayer().getBedSpawnLocation() != event.getSpawnLocation()) {
|
if (RANDOMIZE_SPAWN && event.getPlayer().getBedSpawnLocation() != event.getSpawnLocation()) {
|
||||||
final World world = event.getPlayer().getWorld();
|
final World world = event.getPlayer().getWorld();
|
||||||
final double x = ThreadLocalRandom.current().nextInt(-300000000, 30000000) + .5;
|
final double x = ThreadLocalRandom.current().nextInt(-300000000, 30000000) + .5;
|
||||||
final double y = 100;
|
final double y = 100;
|
||||||
final double z = ThreadLocalRandom.current().nextInt(-300000000, 30000000) + .5;
|
final double z = ThreadLocalRandom.current().nextInt(-300000000, 30000000) + .5;
|
||||||
|
|
||||||
event.setSpawnLocation(new Location(world, x, y, z));
|
event.setSpawnLocation(new Location(world, x, y, z));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onPlayerQuit(final PlayerQuitEvent event) {
|
void onPlayerQuit(final PlayerQuitEvent event) {
|
||||||
PlayerCommand.getCommandMillisList().remove(event.getPlayer().getUniqueId());
|
PlayerCommand.getCommandMillisList().remove(event.getPlayer().getUniqueId());
|
||||||
//PlayerInteract.interactMillisList.remove(event.getPlayer().getUniqueId());
|
//PlayerInteract.interactMillisList.remove(event.getPlayer().getUniqueId());
|
||||||
ServerTabComplete.getLoginNameList().remove(event.getPlayer().getUniqueId());
|
ServerTabComplete.getLoginNameList().remove(event.getPlayer().getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onPreLookupProfile(final PreLookupProfileEvent event) {
|
void onPreLookupProfile(final PreLookupProfileEvent event) {
|
||||||
// Disable Mojang API calls, we don't need them
|
// Disable Mojang API calls, we don't need them
|
||||||
UUID offlineUUID = UUID.nameUUIDFromBytes(("OfflinePlayer:" + event.getName()).getBytes(Charsets.UTF_8));
|
UUID offlineUUID = UUID.nameUUIDFromBytes(("OfflinePlayer:" + event.getName()).getBytes(Charsets.UTF_8));
|
||||||
event.setUUID(offlineUUID);
|
event.setUUID(offlineUUID);
|
||||||
|
|
||||||
event.setProfileProperties(new HashSet<ProfileProperty>());
|
event.setProfileProperties(new HashSet<ProfileProperty>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,83 +17,83 @@ import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
|
|
||||||
public final class PlayerDamage implements Listener {
|
public final class PlayerDamage implements Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onEntityDamage(final EntityDamageEvent event) {
|
void onEntityDamage(final EntityDamageEvent event) {
|
||||||
if (EntityType.PLAYER.equals(event.getEntityType())) {
|
if (EntityType.PLAYER.equals(event.getEntityType())) {
|
||||||
if (DamageCause.VOID.equals(event.getCause())
|
if (DamageCause.VOID.equals(event.getCause())
|
||||||
&& event.getDamage() == Float.MAX_VALUE) {
|
&& event.getDamage() == Float.MAX_VALUE) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onEntityRegainHealth(final EntityRegainHealthEvent event) {
|
void onEntityRegainHealth(final EntityRegainHealthEvent event) {
|
||||||
if (event.getAmount() < 0) {
|
if (event.getAmount() < 0) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onFoodLevelChange(final FoodLevelChangeEvent event) {
|
void onFoodLevelChange(final FoodLevelChangeEvent event) {
|
||||||
final HumanEntity player = event.getEntity();
|
final HumanEntity player = event.getEntity();
|
||||||
|
|
||||||
if (player.getMaxHealth() <= 0) {
|
if (player.getMaxHealth() <= 0) {
|
||||||
player.setMaxHealth(Double.POSITIVE_INFINITY);
|
player.setMaxHealth(Double.POSITIVE_INFINITY);
|
||||||
player.setHealth(20);
|
player.setHealth(20);
|
||||||
player.setMaxHealth(20);
|
player.setMaxHealth(20);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onPlayerDeath(final PlayerDeathEvent event) {
|
void onPlayerDeath(final PlayerDeathEvent event) {
|
||||||
final Player player = event.getEntity();
|
final Player player = event.getEntity();
|
||||||
|
|
||||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||||
onlinePlayer.sendMessage(event.getDeathMessage());
|
onlinePlayer.sendMessage(event.getDeathMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!event.getKeepInventory()) {
|
if (!event.getKeepInventory()) {
|
||||||
player.getInventory().clear();
|
player.getInventory().clear();
|
||||||
|
|
||||||
for (ItemStack item : event.getDrops()) {
|
for (ItemStack item : event.getDrops()) {
|
||||||
player.getWorld().dropItemNaturally(player.getLocation(), item);
|
player.getWorld().dropItemNaturally(player.getLocation(), item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.getDroppedExp() > 0) {
|
if (event.getDroppedExp() > 0) {
|
||||||
ExperienceOrb xp = player.getWorld().spawn(player.getLocation(), ExperienceOrb.class);
|
ExperienceOrb xp = player.getWorld().spawn(player.getLocation(), ExperienceOrb.class);
|
||||||
xp.setExperience(event.getDroppedExp());
|
xp.setExperience(event.getDroppedExp());
|
||||||
}
|
}
|
||||||
|
|
||||||
player.setMaxHealth(20);
|
player.setMaxHealth(20);
|
||||||
player.setHealth(20);
|
player.setHealth(20);
|
||||||
|
|
||||||
if (player.getBedSpawnLocation() != null) {
|
if (player.getBedSpawnLocation() != null) {
|
||||||
player.teleportAsync(player.getBedSpawnLocation());
|
player.teleportAsync(player.getBedSpawnLocation());
|
||||||
} else {
|
} else {
|
||||||
final World world = Bukkit.getWorld("world");
|
final World world = Bukkit.getWorld("world");
|
||||||
player.teleportAsync(world.getSpawnLocation());
|
player.teleportAsync(world.getSpawnLocation());
|
||||||
}
|
}
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
player.setMaxHealth(Double.POSITIVE_INFINITY);
|
player.setMaxHealth(Double.POSITIVE_INFINITY);
|
||||||
player.setHealth(20);
|
player.setHealth(20);
|
||||||
player.setMaxHealth(20);
|
player.setMaxHealth(20);
|
||||||
}
|
}
|
||||||
|
|
||||||
player.setExp(event.getNewExp());
|
player.setExp(event.getNewExp());
|
||||||
player.setLevel(event.getNewLevel());
|
player.setLevel(event.getNewLevel());
|
||||||
player.setFoodLevel(20);
|
player.setFoodLevel(20);
|
||||||
player.setFireTicks(0);
|
player.setFireTicks(0);
|
||||||
player.setRemainingAir(player.getMaximumAir());
|
player.setRemainingAir(player.getMaximumAir());
|
||||||
|
|
||||||
for (PotionEffect effect : player.getActivePotionEffects()) {
|
for (PotionEffect effect : player.getActivePotionEffects()) {
|
||||||
player.removePotionEffect(effect.getType());
|
player.removePotionEffect(effect.getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,48 +12,48 @@ import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
public final class PlayerInteract implements Listener {
|
public final class PlayerInteract implements Listener {
|
||||||
//static HashMap<UUID, Long> interactMillisList = new HashMap<UUID, Long>();
|
//static HashMap<UUID, Long> interactMillisList = new HashMap<UUID, Long>();
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onInventoryClick(final InventoryClickEvent event) {
|
void onInventoryClick(final InventoryClickEvent event) {
|
||||||
try {
|
try {
|
||||||
event.getSlot();
|
event.getSlot();
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onPlayerInteract(final PlayerInteractEvent event) {
|
void onPlayerInteract(final PlayerInteractEvent event) {
|
||||||
/*final UUID playerUuid = event.getPlayer().getUniqueId();
|
/*final UUID playerUuid = event.getPlayer().getUniqueId();
|
||||||
|
|
||||||
if (interactMillisList.get(playerUuid) != null) {
|
if (interactMillisList.get(playerUuid) != null) {
|
||||||
final long millisDifference = System.currentTimeMillis() - interactMillisList.get(playerUuid);
|
final long millisDifference = System.currentTimeMillis() - interactMillisList.get(playerUuid);
|
||||||
|
|
||||||
if (millisDifference < 150) {
|
if (millisDifference < 150) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interactMillisList.put(playerUuid, System.currentTimeMillis());*/
|
interactMillisList.put(playerUuid, System.currentTimeMillis());*/
|
||||||
|
|
||||||
final ItemStack item = event.getItem();
|
final ItemStack item = event.getItem();
|
||||||
|
|
||||||
if (item != null
|
if (item != null
|
||||||
&& Material.TRIDENT.equals(item.getType())) {
|
&& Material.TRIDENT.equals(item.getType())) {
|
||||||
final int riptideLimit = 20;
|
final int riptideLimit = 20;
|
||||||
|
|
||||||
if (item.getEnchantmentLevel(Enchantment.RIPTIDE) > riptideLimit) {
|
if (item.getEnchantmentLevel(Enchantment.RIPTIDE) > riptideLimit) {
|
||||||
item.addUnsafeEnchantment(Enchantment.RIPTIDE, riptideLimit);
|
item.addUnsafeEnchantment(Enchantment.RIPTIDE, riptideLimit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||||
final BlockState clickedBlock = event.getClickedBlock().getState();
|
final BlockState clickedBlock = event.getClickedBlock().getState();
|
||||||
|
|
||||||
if (clickedBlock instanceof Sign) {
|
if (clickedBlock instanceof Sign) {
|
||||||
clickedBlock.update();
|
clickedBlock.update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,16 +5,16 @@ import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerRecipeDiscoverEvent;
|
import org.bukkit.event.player.PlayerRecipeDiscoverEvent;
|
||||||
|
|
||||||
public final class PlayerRecipe implements Listener {
|
public final class PlayerRecipe implements Listener {
|
||||||
private long recipeMillis;
|
private long recipeMillis;
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onPlayerRecipeDiscover(final PlayerRecipeDiscoverEvent event) {
|
void onPlayerRecipeDiscover(final PlayerRecipeDiscoverEvent event) {
|
||||||
final long millisDifference = System.currentTimeMillis() - recipeMillis;
|
final long millisDifference = System.currentTimeMillis() - recipeMillis;
|
||||||
|
|
||||||
if (millisDifference < 75) {
|
if (millisDifference < 75) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
recipeMillis = System.currentTimeMillis();
|
recipeMillis = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,19 +9,19 @@ import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
import pw.kaboom.extras.modules.entity.EntityTeleport;
|
import pw.kaboom.extras.modules.entity.EntityTeleport;
|
||||||
|
|
||||||
public final class PlayerTeleport implements Listener {
|
public final class PlayerTeleport implements Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onPlayerChangedWorld(final PlayerChangedWorldEvent event) {
|
void onPlayerChangedWorld(final PlayerChangedWorldEvent event) {
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
|
|
||||||
if (player.getMaxHealth() <= 0) {
|
if (player.getMaxHealth() <= 0) {
|
||||||
player.setMaxHealth(Double.POSITIVE_INFINITY);
|
player.setMaxHealth(Double.POSITIVE_INFINITY);
|
||||||
player.setHealth(20);
|
player.setHealth(20);
|
||||||
player.setMaxHealth(20);
|
player.setMaxHealth(20);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onPlayerTeleport(final PlayerTeleportEvent event) {
|
void onPlayerTeleport(final PlayerTeleportEvent event) {
|
||||||
event.setTo(EntityTeleport.limitLocation(event.getTo()));
|
event.setTo(EntityTeleport.limitLocation(event.getTo()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,253 +18,253 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import pw.kaboom.extras.Main;
|
import pw.kaboom.extras.Main;
|
||||||
|
|
||||||
public final class ServerCommand implements Listener {
|
public final class ServerCommand implements Listener {
|
||||||
private static final Pattern AS_AT_PATTERN = Pattern.compile("\\b(as|at|facing entity) @[ae]\\b");
|
private static final Pattern AS_AT_PATTERN = Pattern.compile("\\b(as|at|facing entity) @[ae]\\b");
|
||||||
private static final Logger LOGGER = JavaPlugin.getPlugin(Main.class).getLogger();
|
private static final Logger LOGGER = JavaPlugin.getPlugin(Main.class).getLogger();
|
||||||
|
|
||||||
public static boolean checkExecuteCommand(final String cmd) {
|
public static boolean checkExecuteCommand(final String cmd) {
|
||||||
return ("execute".equalsIgnoreCase(cmd)
|
return ("execute".equalsIgnoreCase(cmd)
|
||||||
|| "clone".equalsIgnoreCase(cmd)
|
|| "clone".equalsIgnoreCase(cmd)
|
||||||
|| "fill".equalsIgnoreCase(cmd)
|
|| "fill".equalsIgnoreCase(cmd)
|
||||||
|| "forceload".equalsIgnoreCase(cmd)
|
|| "forceload".equalsIgnoreCase(cmd)
|
||||||
|| "kick".equalsIgnoreCase(cmd)
|
|| "kick".equalsIgnoreCase(cmd)
|
||||||
|| "locate".equalsIgnoreCase(cmd)
|
|| "locate".equalsIgnoreCase(cmd)
|
||||||
|| "locatebiome".equalsIgnoreCase(cmd)
|
|| "locatebiome".equalsIgnoreCase(cmd)
|
||||||
|| "me".equalsIgnoreCase(cmd)
|
|| "me".equalsIgnoreCase(cmd)
|
||||||
|| "msg".equalsIgnoreCase(cmd)
|
|| "msg".equalsIgnoreCase(cmd)
|
||||||
|| "reload".equalsIgnoreCase(cmd)
|
|| "reload".equalsIgnoreCase(cmd)
|
||||||
|| "save-all".equalsIgnoreCase(cmd)
|
|| "save-all".equalsIgnoreCase(cmd)
|
||||||
|| "say".equalsIgnoreCase(cmd)
|
|| "say".equalsIgnoreCase(cmd)
|
||||||
|| "spreadplayers".equalsIgnoreCase(cmd)
|
|| "spreadplayers".equalsIgnoreCase(cmd)
|
||||||
|| "stop".equalsIgnoreCase(cmd)
|
|| "stop".equalsIgnoreCase(cmd)
|
||||||
|| "summon".equalsIgnoreCase(cmd)
|
|| "summon".equalsIgnoreCase(cmd)
|
||||||
|| "teammsg".equalsIgnoreCase(cmd)
|
|| "teammsg".equalsIgnoreCase(cmd)
|
||||||
|| "teleport".equalsIgnoreCase(cmd)
|
|| "teleport".equalsIgnoreCase(cmd)
|
||||||
|| "tell".equalsIgnoreCase(cmd)
|
|| "tell".equalsIgnoreCase(cmd)
|
||||||
|| "tellraw".equalsIgnoreCase(cmd)
|
|| "tellraw".equalsIgnoreCase(cmd)
|
||||||
|| "tm".equalsIgnoreCase(cmd)
|
|| "tm".equalsIgnoreCase(cmd)
|
||||||
|| "tp".equalsIgnoreCase(cmd)
|
|| "tp".equalsIgnoreCase(cmd)
|
||||||
|| "w".equalsIgnoreCase(cmd)
|
|| "w".equalsIgnoreCase(cmd)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
public static String checkCommand(final CommandSender sender, final String command, final boolean isConsoleCommand) {
|
public static String checkCommand(final CommandSender sender, final String command, final boolean isConsoleCommand) {
|
||||||
final String[] arr = command.split(" ");
|
final String[] arr = command.split(" ");
|
||||||
String commandName = arr[0].toLowerCase();
|
String commandName = arr[0].toLowerCase();
|
||||||
|
|
||||||
if (isConsoleCommand) {
|
if (isConsoleCommand) {
|
||||||
commandName = "/" + commandName;
|
commandName = "/" + commandName;
|
||||||
} else if (arr.length >= 2 && commandName.equals("/")) {
|
} else if (arr.length >= 2 && commandName.equals("/")) {
|
||||||
// Command could contain spaces after the slash, e.g. "/ spawn"
|
// Command could contain spaces after the slash, e.g. "/ spawn"
|
||||||
commandName = "/" + arr[1].toLowerCase();
|
commandName = "/" + arr[1].toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 1; i < arr.length; i++) {
|
for (int i = 1; i < arr.length; i++) {
|
||||||
if (arr[i].matches("^[+-]?(?:\\d+\\.?\\d*|\\d*\\.?\\d+)[\\r\\n]*$")) {
|
if (arr[i].matches("^[+-]?(?:\\d+\\.?\\d*|\\d*\\.?\\d+)[\\r\\n]*$")) {
|
||||||
try {
|
try {
|
||||||
int integer = Integer.parseInt(arr[i]);
|
int integer = Integer.parseInt(arr[i]);
|
||||||
try {
|
try {
|
||||||
if (integer >= Integer.MAX_VALUE) {
|
if (integer >= Integer.MAX_VALUE) {
|
||||||
return "cancel";
|
return "cancel";
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return "cancel";
|
return "cancel";
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
// Ignore exception
|
// Ignore exception
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
switch (commandName) {
|
switch (commandName) {
|
||||||
case "/minecraft:execute":
|
case "/minecraft:execute":
|
||||||
case "/execute":
|
case "/execute":
|
||||||
if (arr.length >= 2) {
|
if (arr.length >= 2) {
|
||||||
int asAtCount = 0;
|
int asAtCount = 0;
|
||||||
Matcher asAtMatcher = AS_AT_PATTERN.matcher(command.toLowerCase());
|
Matcher asAtMatcher = AS_AT_PATTERN.matcher(command.toLowerCase());
|
||||||
while (asAtMatcher.find()) {
|
while (asAtMatcher.find()) {
|
||||||
asAtCount++;
|
asAtCount++;
|
||||||
}
|
}
|
||||||
if (asAtCount >= 2) {
|
if (asAtCount >= 2) {
|
||||||
return "cancel";
|
return "cancel";
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 1; i < arr.length; i++) {
|
for (int i = 1; i < arr.length; i++) {
|
||||||
if ("run".equalsIgnoreCase(arr[i])) {
|
if ("run".equalsIgnoreCase(arr[i])) {
|
||||||
if (i + 1 == arr.length) {
|
if (i + 1 == arr.length) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (checkExecuteCommand(arr[i + 1])) {
|
if (checkExecuteCommand(arr[i + 1])) {
|
||||||
return "cancel";
|
return "cancel";
|
||||||
} else {
|
} else {
|
||||||
final String[] executeCommand = Arrays.copyOfRange(arr, i + 1, arr.length);
|
final String[] executeCommand = Arrays.copyOfRange(arr, i + 1, arr.length);
|
||||||
String result = checkCommand(sender, String.join(" ", executeCommand), true);
|
String result = checkCommand(sender, String.join(" ", executeCommand), true);
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
switch (result) {
|
switch (result) {
|
||||||
case "cancel":
|
case "cancel":
|
||||||
return "cancel";
|
return "cancel";
|
||||||
default:
|
default:
|
||||||
String pureExecute = String.join(" ", Arrays.copyOfRange(arr, 0, i + 1));
|
String pureExecute = String.join(" ", Arrays.copyOfRange(arr, 0, i + 1));
|
||||||
return (pureExecute + " " + result);
|
return (pureExecute + " " + result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "/minecraft:fill":
|
case "/minecraft:fill":
|
||||||
case "/fill":
|
case "/fill":
|
||||||
if (command.contains("auto")) {
|
if (command.contains("auto")) {
|
||||||
return command.replace("auto", "[auto]");
|
return command.replace("auto", "[auto]");
|
||||||
}
|
}
|
||||||
if (command.contains("selector")) {
|
if (command.contains("selector")) {
|
||||||
return "cancel";
|
return "cancel";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "/minecraft:gamerule":
|
case "/minecraft:gamerule":
|
||||||
case "/gamerule":
|
case "/gamerule":
|
||||||
if (arr.length >= 3) {
|
if (arr.length >= 3) {
|
||||||
if ("randomTickSpeed".equalsIgnoreCase(arr[1])
|
if ("randomTickSpeed".equalsIgnoreCase(arr[1])
|
||||||
&& Double.parseDouble(arr[2]) > 6) {
|
&& Double.parseDouble(arr[2]) > 6) {
|
||||||
return command.replaceFirst(arr[2], "6");
|
return command.replaceFirst(arr[2], "6");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "/minecraft:give":
|
case "/minecraft:give":
|
||||||
case "/give":
|
case "/give":
|
||||||
if (Double.parseDouble(arr[arr.length - 1]) > 64) {
|
if (Double.parseDouble(arr[arr.length - 1]) > 64) {
|
||||||
// Limit item count
|
// Limit item count
|
||||||
arr[arr.length - 1] = "64";
|
arr[arr.length - 1] = "64";
|
||||||
return String.join(" ", arr);
|
return String.join(" ", arr);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "/minecraft:particle":
|
case "/minecraft:particle":
|
||||||
case "/particle":
|
case "/particle":
|
||||||
int[] numArgs = {14, 10};
|
int[] numArgs = {14, 10};
|
||||||
for (int i : numArgs) {
|
for (int i : numArgs) {
|
||||||
if (arr.length < i || arr.length > i + 2) {
|
if (arr.length < i || arr.length > i + 2) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (Double.parseDouble(arr[i - 1]) > 10) {
|
if (Double.parseDouble(arr[i - 1]) > 10) {
|
||||||
// Limit particle count
|
// Limit particle count
|
||||||
arr[i - 1] = "10";
|
arr[i - 1] = "10";
|
||||||
return String.join(" ", arr);
|
return String.join(" ", arr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "/minecraft:spreadplayers":
|
case "/minecraft:spreadplayers":
|
||||||
case "/spreadplayers":
|
case "/spreadplayers":
|
||||||
if (arr.length == 7 && (arr[6].contains("@e") || arr[6].contains("@a"))) {
|
if (arr.length == 7 && (arr[6].contains("@e") || arr[6].contains("@a"))) {
|
||||||
return "cancel";
|
return "cancel";
|
||||||
} else if (arr.length >= 5) {
|
} else if (arr.length >= 5) {
|
||||||
if (Double.parseDouble(arr[3]) > 0) {
|
if (Double.parseDouble(arr[3]) > 0) {
|
||||||
arr[3] = "0";
|
arr[3] = "0";
|
||||||
}
|
}
|
||||||
if (Double.parseDouble(arr[4]) < 8) {
|
if (Double.parseDouble(arr[4]) < 8) {
|
||||||
arr[4] = "8";
|
arr[4] = "8";
|
||||||
}
|
}
|
||||||
if (Double.parseDouble(arr[4]) > 50) {
|
if (Double.parseDouble(arr[4]) > 50) {
|
||||||
arr[4] = "50";
|
arr[4] = "50";
|
||||||
}
|
}
|
||||||
return String.join(" ", arr);
|
return String.join(" ", arr);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "/minecraft:bossbar":
|
case "/minecraft:bossbar":
|
||||||
case "/minecraft:setblock":
|
case "/minecraft:setblock":
|
||||||
case "/minecraft:tellraw":
|
case "/minecraft:tellraw":
|
||||||
case "/minecraft:title":
|
case "/minecraft:title":
|
||||||
case "/bossbar":
|
case "/bossbar":
|
||||||
case "/setblock":
|
case "/setblock":
|
||||||
case "/tellraw":
|
case "/tellraw":
|
||||||
case "/title":
|
case "/title":
|
||||||
final String charCommand = parseCharCodes(command);
|
final String charCommand = parseCharCodes(command);
|
||||||
if (charCommand.contains("selector")) {
|
if (charCommand.contains("selector")) {
|
||||||
return "cancel";
|
return "cancel";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "/viaversion:viaver":
|
case "/viaversion:viaver":
|
||||||
case "/viaversion:viaversion":
|
case "/viaversion:viaversion":
|
||||||
case "/viaversion:vvbukkit":
|
case "/viaversion:vvbukkit":
|
||||||
case "/viaver":
|
case "/viaver":
|
||||||
case "/viaversion":
|
case "/viaversion":
|
||||||
case "/vvbukkit":
|
case "/vvbukkit":
|
||||||
if (arr.length >= 2
|
if (arr.length >= 2
|
||||||
&& "debug".equalsIgnoreCase(arr[1])) {
|
&& "debug".equalsIgnoreCase(arr[1])) {
|
||||||
return "cancel";
|
return "cancel";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "/geyser-spigot:geyser":
|
case "/geyser-spigot:geyser":
|
||||||
case "/geyser":
|
case "/geyser":
|
||||||
if (arr.length >= 2
|
if (arr.length >= 2
|
||||||
&& "dump".equalsIgnoreCase(arr[1])) {
|
&& "dump".equalsIgnoreCase(arr[1])) {
|
||||||
return "cancel";
|
return "cancel";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException exception) {
|
} catch (NumberFormatException exception) {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command.contains("distance")) {
|
if (command.contains("distance")) {
|
||||||
return command.replace("distance=", "]").replace("\"distance\"=", "]").replace("'distance'=", "]");
|
return command.replace("distance=", "]").replace("\"distance\"=", "]").replace("'distance'=", "]");
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onServerCommand(final ServerCommandEvent event) {
|
void onServerCommand(final ServerCommandEvent event) {
|
||||||
final CommandSender sender = event.getSender();
|
final CommandSender sender = event.getSender();
|
||||||
|
|
||||||
if (sender instanceof BlockCommandSender) {
|
if (sender instanceof BlockCommandSender) {
|
||||||
final CommandBlock commandBlock = (CommandBlock) ((BlockCommandSender) sender).getBlock().getState();
|
final CommandBlock commandBlock = (CommandBlock) ((BlockCommandSender) sender).getBlock().getState();
|
||||||
|
|
||||||
commandBlock.setCommand("");
|
commandBlock.setCommand("");
|
||||||
commandBlock.update();
|
commandBlock.update();
|
||||||
} else if (sender instanceof CommandMinecart) {
|
} else if (sender instanceof CommandMinecart) {
|
||||||
final CommandMinecart commandMinecart = (CommandMinecart) sender;
|
final CommandMinecart commandMinecart = (CommandMinecart) sender;
|
||||||
|
|
||||||
commandMinecart.setCommand("");
|
commandMinecart.setCommand("");
|
||||||
}
|
}
|
||||||
|
|
||||||
final String command = event.getCommand();
|
final String command = event.getCommand();
|
||||||
final boolean isConsoleCommand = true;
|
final boolean isConsoleCommand = true;
|
||||||
final String checkedCommand = checkCommand(sender, command, isConsoleCommand);
|
final String checkedCommand = checkCommand(sender, command, isConsoleCommand);
|
||||||
|
|
||||||
if (checkedCommand != null) {
|
if (checkedCommand != null) {
|
||||||
if ("cancel".equals(checkedCommand)) {
|
if ("cancel".equals(checkedCommand)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
} else {
|
} else {
|
||||||
event.setCommand(checkedCommand);
|
event.setCommand(checkedCommand);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGGER.log(Level.INFO, "Console command: " + command);
|
LOGGER.log(Level.INFO, "Console command: " + command);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String parseCharCodes(final String input) {
|
public static String parseCharCodes(final String input) {
|
||||||
if (input.contains("\\u")) {
|
if (input.contains("\\u")) {
|
||||||
StringBuilder output = new StringBuilder();
|
StringBuilder output = new StringBuilder();
|
||||||
String[] split = input.split("\\\\u");
|
String[] split = input.split("\\\\u");
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (String item:split) {
|
for (String item:split) {
|
||||||
if (index == 0) {
|
if (index == 0) {
|
||||||
output.append(item);
|
output.append(item);
|
||||||
} else {
|
} else {
|
||||||
String charCode = item.substring(0, 4);
|
String charCode = item.substring(0, 4);
|
||||||
output.append((char) Integer.parseInt(charCode, 16));
|
output.append((char) Integer.parseInt(charCode, 16));
|
||||||
output.append(item.substring(4));
|
output.append(item.substring(4));
|
||||||
}
|
}
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
return output.toString();
|
return output.toString();
|
||||||
} else {
|
} else {
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,63 +13,63 @@ import org.bukkit.event.Listener;
|
||||||
import com.destroystokyo.paper.event.server.AsyncTabCompleteEvent;
|
import com.destroystokyo.paper.event.server.AsyncTabCompleteEvent;
|
||||||
|
|
||||||
public final class ServerTabComplete implements Listener {
|
public final class ServerTabComplete implements Listener {
|
||||||
private static HashMap<UUID, String> loginNameList = new HashMap<UUID, String>();
|
private static HashMap<UUID, String> loginNameList = new HashMap<UUID, String>();
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onAsyncTabComplete(final AsyncTabCompleteEvent event) {
|
void onAsyncTabComplete(final AsyncTabCompleteEvent event) {
|
||||||
final String[] arr = event.getBuffer().split(" ", 2);
|
final String[] arr = event.getBuffer().split(" ", 2);
|
||||||
|
|
||||||
// Vanilla clients will not send tab complete requests on the first word, but modified or bot clients may
|
// Vanilla clients will not send tab complete requests on the first word, but modified or bot clients may
|
||||||
if (arr.length < 2) {
|
if (arr.length < 2) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String command = arr[0];
|
String command = arr[0];
|
||||||
String argsFragment = arr[1];
|
String argsFragment = arr[1];
|
||||||
if (command.startsWith("/")) {
|
if (command.startsWith("/")) {
|
||||||
command = command.substring(1);
|
command = command.substring(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command.equalsIgnoreCase("op")) {
|
if (command.equalsIgnoreCase("op")) {
|
||||||
event.setCompletions(getOpCompletions(argsFragment));
|
event.setCompletions(getOpCompletions(argsFragment));
|
||||||
} else if (command.equalsIgnoreCase("deop")) {
|
} else if (command.equalsIgnoreCase("deop")) {
|
||||||
event.setCompletions(getDeopCompletions(argsFragment));
|
event.setCompletions(getDeopCompletions(argsFragment));
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.getCompletions().size() == 0) {
|
if (event.getCompletions().size() == 0) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static List<String> getOpCompletions(final String argsFragment) {
|
static List<String> getOpCompletions(final String argsFragment) {
|
||||||
ArrayList<String> deops = new ArrayList<String>();
|
ArrayList<String> deops = new ArrayList<String>();
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
if (!player.isOp()) {
|
if (!player.isOp()) {
|
||||||
String loginName = loginNameList.get(player.getUniqueId());
|
String loginName = loginNameList.get(player.getUniqueId());
|
||||||
if (loginName != null && loginName.startsWith(argsFragment)) {
|
if (loginName != null && loginName.startsWith(argsFragment)) {
|
||||||
deops.add(loginName);
|
deops.add(loginName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return deops;
|
return deops;
|
||||||
}
|
}
|
||||||
|
|
||||||
static List<String> getDeopCompletions(final String argsFragment) {
|
static List<String> getDeopCompletions(final String argsFragment) {
|
||||||
ArrayList<String> ops = new ArrayList<String>();
|
ArrayList<String> ops = new ArrayList<String>();
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
if (player.isOp()) {
|
if (player.isOp()) {
|
||||||
String loginName = loginNameList.get(player.getUniqueId());
|
String loginName = loginNameList.get(player.getUniqueId());
|
||||||
if (loginName != null && loginName.startsWith(argsFragment)) {
|
if (loginName != null && loginName.startsWith(argsFragment)) {
|
||||||
ops.add(loginName);
|
ops.add(loginName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ops;
|
return ops;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HashMap<UUID, String> getLoginNameList() {
|
public static HashMap<UUID, String> getLoginNameList() {
|
||||||
return loginNameList;
|
return loginNameList;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,25 +7,25 @@ import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerStatisticIncrementEvent;
|
import org.bukkit.event.player.PlayerStatisticIncrementEvent;
|
||||||
|
|
||||||
public final class ServerTick implements Listener {
|
public final class ServerTick implements Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onPlayerStatisticIncrement(final PlayerStatisticIncrementEvent event) {
|
void onPlayerStatisticIncrement(final PlayerStatisticIncrementEvent event) {
|
||||||
final World world = event.getPlayer().getWorld();
|
final World world = event.getPlayer().getWorld();
|
||||||
final Integer randomTickSpeed = world.getGameRuleValue(GameRule.RANDOM_TICK_SPEED);
|
final Integer randomTickSpeed = world.getGameRuleValue(GameRule.RANDOM_TICK_SPEED);
|
||||||
|
|
||||||
if (randomTickSpeed > 6) {
|
if (randomTickSpeed > 6) {
|
||||||
world.setGameRule(GameRule.RANDOM_TICK_SPEED, 6);
|
world.setGameRule(GameRule.RANDOM_TICK_SPEED, 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Integer spawnRadius = world.getGameRuleValue(GameRule.SPAWN_RADIUS);
|
final Integer spawnRadius = world.getGameRuleValue(GameRule.SPAWN_RADIUS);
|
||||||
|
|
||||||
if (spawnRadius > 100) {
|
if (spawnRadius > 100) {
|
||||||
world.setGameRule(GameRule.SPAWN_RADIUS, 100);
|
world.setGameRule(GameRule.SPAWN_RADIUS, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!world.isAutoSave()) {
|
if (!world.isAutoSave()) {
|
||||||
world.setAutoSave(true);
|
world.setAutoSave(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
|
|
||||||
<!DOCTYPE suppressions PUBLIC
|
<!DOCTYPE suppressions PUBLIC
|
||||||
"-//Puppy Crawl//DTD Suppressions 1.0//EN"
|
"-//Puppy Crawl//DTD Suppressions 1.0//EN"
|
||||||
"http://www.puppycrawl.com/dtds/suppressions_1_0.dtd">
|
"http://www.puppycrawl.com/dtds/suppressions_1_0.dtd">
|
||||||
|
|
||||||
<suppressions>
|
<suppressions>
|
||||||
<suppress checks="FileTabCharacter" files="."/>
|
<suppress checks="Javadoc" files="."/>
|
||||||
<suppress checks="Javadoc" files="."/>
|
<suppress checks="LineLength" files="."/>
|
||||||
<suppress checks="LineLength" files="."/>
|
<suppress checks="MagicNumber" files="."/>
|
||||||
<suppress checks="MagicNumber" files="."/>
|
<suppress checks="MethodLength" files="."/>
|
||||||
<suppress checks="MethodLength" files="."/>
|
|
||||||
</suppressions>
|
</suppressions>
|
||||||
|
|
Loading…
Reference in a new issue