Handle tridents

This commit is contained in:
mathiascode 2020-02-26 22:20:13 +02:00
parent 398f066b0d
commit 78f105fd2b
7 changed files with 86 additions and 44 deletions

View file

@ -417,6 +417,7 @@ public final class Main extends JavaPlugin {
@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());

View file

@ -0,0 +1,18 @@
package pw.kaboom.extras.commands;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
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;
}
}

View file

@ -1,7 +1,10 @@
package pw.kaboom.extras.modules.entity;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.EntityType;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.ProjectileHitEvent;
import com.destroystokyo.paper.event.entity.EntityKnockbackByEntityEvent;
@ -16,4 +19,17 @@ public final class EntityKnockback implements Listener {
);
}
}
@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);
}
}
}
}

View file

@ -1,26 +1,34 @@
package pw.kaboom.extras.modules.player;
import com.destroystokyo.paper.event.profile.PreLookupProfileEvent;
import com.destroystokyo.paper.profile.PlayerProfile;
import com.google.common.base.Charsets;
import java.io.File;
import java.io.IOException;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.GameRule;
import org.bukkit.World;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.*;
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerLoginEvent.Result;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerStatisticIncrementEvent;
import org.bukkit.plugin.java.JavaPlugin;
import com.destroystokyo.paper.event.profile.PreLookupProfileEvent;
import com.destroystokyo.paper.profile.PlayerProfile;
import com.google.common.base.Charsets;
import pw.kaboom.extras.Main;
import pw.kaboom.extras.helpers.SkinDownloader;
import java.io.File;
import java.io.IOException;
import java.util.UUID;
public final class PlayerConnection implements Listener {
private long connectionMillis;
@ -53,6 +61,12 @@ public final class PlayerConnection implements Listener {
}
}
final Integer spawnRadius = Bukkit.getWorld("world").getGameRuleValue(GameRule.SPAWN_RADIUS);
if (spawnRadius > 100) {
Bukkit.getWorld("world").setGameRule(GameRule.SPAWN_RADIUS, 100);
}
try {
final PlayerProfile profile = event.getPlayerProfile();
@ -85,6 +99,17 @@ public final class PlayerConnection implements Listener {
@EventHandler
void onPlayerCommandSend2(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 (!world.isAutoSave()) {
world.setAutoSave(true);
}
//if (event.getPlayer().isOnline()) {
event.setCancelled(true);
//}

View file

@ -3,10 +3,13 @@ package pw.kaboom.extras.modules.player;
import java.util.HashMap;
import java.util.UUID;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
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>();
@ -33,5 +36,16 @@ public final class PlayerInteract implements Listener {
}
interactMillisList.put(playerUuid, System.currentTimeMillis());
final ItemStack item = event.getItem();
if (item != null &&
Material.TRIDENT.equals(item.getType())) {
final int riptideLimit = 20;
if (item.getEnchantmentLevel(Enchantment.RIPTIDE) > riptideLimit) {
item.addUnsafeEnchantment(Enchantment.RIPTIDE, riptideLimit);
}
}
}
}

View file

@ -35,7 +35,6 @@ public final class ServerCommand implements Listener {
|| "clone".equalsIgnoreCase(arr[i + 1])
|| "fill".equalsIgnoreCase(arr[i + 1])
|| "particle".equalsIgnoreCase(arr[i + 1])
|| "save-off".equalsIgnoreCase(arr[i + 1])
|| "say".equalsIgnoreCase(arr[i + 1])
|| "spreadplayers".equalsIgnoreCase(arr[i + 1])
|| "stop".equalsIgnoreCase(arr[i + 1])
@ -79,9 +78,6 @@ public final class ServerCommand implements Listener {
if ("randomTickSpeed".equalsIgnoreCase(arr[1])
&& Double.parseDouble(arr[2]) > 6) {
return command.replaceFirst(arr[2], "6");
} else if ("spawnRadius".equalsIgnoreCase(arr[1])
&& Double.parseDouble(arr[2]) > 100) {
return command.replaceFirst(arr[2], "100");
}
}
break;
@ -100,32 +96,6 @@ public final class ServerCommand implements Listener {
return String.join(" ", arr);
}
break;
case "/bukkit:reload":
case "/bukkit:rl":
case "/reload":
case "/rl":
if (sender.hasPermission("bukkit.command.reload")
&& arr.length >= 2
&& "confirm".equalsIgnoreCase(arr[1])) {
Command.broadcastCommandMessage(sender, ChatColor.RED + "Please note that this command is not supported and may cause issues when using some plugins.");
Command.broadcastCommandMessage(sender, ChatColor.RED + "If you encounter any issues please use the /stop command to restart your server.");
Command.broadcastCommandMessage(sender, ChatColor.GREEN + "Reload complete.");
return "cancel";
}
break;
case "/spigot:restart":
case "/restart":
if (sender.hasPermission("bukkit.command.restart")) {
return "cancel";
}
break;
case "/minecraft:save-off":
case "/save-off":
if (sender.hasPermission("minecraft.command.save.disable")) {
Command.broadcastCommandMessage(sender, "Automatic saving is now disabled");
return "cancel";
}
break;
case "/minecraft:spreadplayers":
case "/spreadplayers":
if (arr.length >= 5) {
@ -142,12 +112,6 @@ public final class ServerCommand implements Listener {
return String.join(" ", arr);
}
break;
case "/minecraft:stop":
case "/stop":
if (sender.hasPermission("minecraft.command.stop")) {
Command.broadcastCommandMessage(sender, "Stopping the server");
return "cancel";
}
default:
break;
}

View file

@ -10,6 +10,10 @@ commands:
aliases: [bcraw, tellraw]
description: Broadcasts raw text to the server
permission: extras.broadcastraw
broadcastvanilla:
aliases: [bcv]
description: Broadcasts text in vanilla style
permission: extras.broadcastvanilla
clearchat:
aliases: cc
description: Clears messages from the chat