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