This commit is contained in:
mathias 2019-07-16 15:56:19 +03:00
parent baff8a932a
commit 38265afa49
4 changed files with 98 additions and 27 deletions

View file

@ -36,6 +36,9 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.BlockIterator;
import org.bukkit.util.Vector;
class CommandClearChat implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
@ -178,6 +181,36 @@ class CommandPrefix implements CommandExecutor {
}
}
class CommandPumpkin implements CommandExecutor {
private void placePumpkin(Player player) {
player.getInventory().setHelmet(new ItemStack(Material.PUMPKIN));
}
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Player player = (Player) sender;
if (args.length == 0) {
player.sendMessage(ChatColor.RED + "Usage: /" + label + " <player>");
} else {
if (args[0].equals("*") || args[0].equals("**")) {
for (Player p : Bukkit.getOnlinePlayers()) {
placePumpkin(p);
}
player.sendMessage("Everyone is now a pumpkin");
} else {
Player target = Bukkit.getPlayer(args[0]);
if (target != null) {
placePumpkin(target);
player.sendMessage("Player \"" + target.getName() + "\" is now a pumpkin");
} else {
player.sendMessage("Player \"" + target.getName() + "\" not found");
}
}
}
return true;
}
}
class CommandSkin implements CommandExecutor {
Main main;
CommandSkin(Main main) {
@ -274,6 +307,27 @@ class CommandSpawn implements CommandExecutor {
}
}
class CommandSpidey implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Player player = (Player) sender;
Location eyePos = player.getEyeLocation();
Vector playerPos = new Vector(player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ());
Vector direction = eyePos.getDirection();
int distance = 50;
BlockIterator blockIterator = new BlockIterator(player.getWorld(), playerPos, direction, 0, distance);
while (blockIterator.hasNext()) {
if (blockIterator.next().getType() != Material.AIR) {
break;
}
blockIterator.next().setType(Material.WEB);
}
return true;
}
}
class CommandTellraw implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Player player = (Player) sender;

View file

@ -150,6 +150,29 @@ class TickAsync extends BukkitRunnable {
}
}
class TileEntityCheckAsync extends BukkitRunnable {
Main main;
TileEntityCheckAsync(Main main) {
this.main = main;
}
public void run() {
for (final World world : Bukkit.getServer().getWorlds()) {
for (final Chunk chunk : world.getLoadedChunks()) {
try {
chunk.getTileEntities();
} catch (Exception e) {
Bukkit.getScheduler().runTask(main, new Runnable() {
public void run() {
world.regenerateChunk(chunk.getX(), chunk.getZ());
}
});
}
}
}
}
}
/*class CommandSenderOutput implements CommandSender {
String lastOutput;
@Override
@ -601,25 +624,14 @@ class Events implements Listener {
event.setMessage(stringBuilder.toString());
}
} else if (arr[0].toLowerCase().equals("/minecraft:blockdata") ||
arr[0].toLowerCase().equals("/minecraft:clone") ||
arr[0].toLowerCase().equals("/minecraft:fill") ||
arr[0].toLowerCase().equals("/minecraft:setblock") ||
arr[0].toLowerCase().equals("/blockdata") ||
arr[0].toLowerCase().equals("/clone") ||
arr[0].toLowerCase().equals("/fill") ||
arr[0].toLowerCase().equals("/setblock")) {
if (event.getMessage().contains("translation.test.invalid")) {
event.setCancelled(true);
}
}
}
@EventHandler
void onPlayerDeath(PlayerDeathEvent event) {
Player player = event.getEntity();
final AttributeInstance maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
boolean maxHealthLow = false;
maxHealth.setBaseValue(20);
try {
@ -628,15 +640,22 @@ class Events implements Listener {
maxHealth.setBaseValue(Double.POSITIVE_INFINITY);
player.setHealth(20);
maxHealth.setBaseValue(20);
maxHealthLow = true;
}
player.setFoodLevel(20);
player.setFireTicks(0);
player.setRemainingAir(player.getMaximumAir());
player.getActivePotionEffects().clear();
event.setCancelled(true);
if (player.getLastDamageCause() != null &&
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
onlinePlayer.sendMessage(event.getDeathMessage());
}
if ((player.getLastDamageCause() != null &&
player.getLastDamageCause().getCause() == DamageCause.SUICIDE &&
player.getLastDamageCause().getDamage() == Float.MAX_VALUE) {
player.getLastDamageCause().getDamage() == Float.MAX_VALUE) ||
maxHealthLow == true) {
return;
}
@ -810,17 +829,6 @@ class Events implements Listener {
event.setCommand(stringBuilder.toString());
}
} else if (arr[0].toLowerCase().equals("minecraft:blockdata") ||
arr[0].toLowerCase().equals("minecraft:clone") ||
arr[0].toLowerCase().equals("minecraft:fill") ||
arr[0].toLowerCase().equals("minecraft:setblock") ||
arr[0].toLowerCase().equals("blockdata") ||
arr[0].toLowerCase().equals("clone") ||
arr[0].toLowerCase().equals("fill") ||
arr[0].toLowerCase().equals("setblock")) {
if (event.getCommand().contains("translation.test.invalid")) {
event.setCancelled(true);
}
}
}
@ -829,9 +837,9 @@ class Events implements Listener {
if (event.getClient().getProtocolVersion() != -1) {
event.setProtocolVersion(event.getClient().getProtocolVersion());
} else {
event.setProtocolVersion(485);
event.setProtocolVersion(490);
}
event.setVersion("1.14.2");
event.setVersion("1.14.3");
}
@EventHandler

View file

@ -443,14 +443,17 @@ public class Main extends JavaPlugin {
this.getCommand("enchantall").setExecutor(new CommandEnchantAll());
this.getCommand("jumpscare").setExecutor(new CommandJumpscare());
this.getCommand("prefix").setExecutor(new CommandPrefix(this));
this.getCommand("pumpkin").setExecutor(new CommandPumpkin());
this.getCommand("skin").setExecutor(new CommandSkin(this));
this.getCommand("spawn").setExecutor(new CommandSpawn());
this.getCommand("spidey").setExecutor(new CommandSpidey());
this.getCommand("tellraw").setExecutor(new CommandTellraw());
this.getCommand("unloadchunks").setExecutor(new CommandUnloadChunks());
this.getCommand("username").setExecutor(new CommandUsername(this));
new Tick(this).runTaskTimer(this, 0, 1);
new TickAsync(this).runTaskTimerAsynchronously(this, 0, 1);
new TileEntityCheckAsync(this).runTaskTimerAsynchronously(this, 0, 400);
this.getServer().getPluginManager().registerEvents(new Events(this), this);
}

View file

@ -25,12 +25,18 @@ commands:
aliases: [rank, tag]
description: Changes your tag
permission: extras.prefix
pumpkin:
description: Places a pumpkin on a player's head
permission: extras.pumpkin
skin:
description: Changes your skin
permission: extras.skin
spawn:
description: Teleports you to spawn
permission: extras.spawn
spidey:
description: Annoying little spider...
permission: extras.spidey
tellraw:
description: Broadcasts raw text to the server
permission: extras.tellraw