attack cooldown bypass
This commit is contained in:
@@ -41,6 +41,7 @@ public final class OgreDupeAlias extends JavaPlugin {
|
||||
pm.registerEvents(new EntityDeathListener(),this);
|
||||
pm.registerEvents(new InteractionListener(),this);
|
||||
pm.registerEvents(new InventoryActionListener(),this);
|
||||
pm.registerEvents(new EntityDamageListener(),this);
|
||||
|
||||
// Commands
|
||||
getCommand("config").setExecutor(new ConfigCommand());
|
||||
@@ -59,6 +60,8 @@ public final class OgreDupeAlias extends JavaPlugin {
|
||||
getCommand("irepair").setTabCompleter(new IRepairCommand());
|
||||
getCommand("message").setExecutor(new MessageCommand());
|
||||
getCommand("message").setTabCompleter(new MessageCommand());
|
||||
getCommand("attackcooldown").setExecutor(new AttackCooldownCommand());
|
||||
getCommand("attackcooldown").setTabCompleter(new AttackCooldownCommand());
|
||||
}
|
||||
|
||||
public void initConfig() {
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package io.github.itzispyder.ogredupealias.commands.commands;
|
||||
|
||||
import io.github.itzispyder.ogredupealias.commands.CmdExHandler;
|
||||
import io.github.itzispyder.ogredupealias.events.EntityDamageListener;
|
||||
import io.github.itzispyder.ogredupealias.utils.Text;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AttackCooldownCommand implements TabExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
try {
|
||||
Player p = (Player) sender;
|
||||
boolean isRecipient = EntityDamageListener.attackCooldownBypassers.isRecipient(p);
|
||||
if (isRecipient) EntityDamageListener.attackCooldownBypassers.removeRecipient(p);
|
||||
else EntityDamageListener.attackCooldownBypassers.addRecipient(p);
|
||||
isRecipient = EntityDamageListener.attackCooldownBypassers.isRecipient(p);
|
||||
|
||||
sender.sendMessage(Text.builder()
|
||||
.message("&7[&bAttackCooldown&7] &8>> &3You are " + (isRecipient ? "&anow" : "&cno longer") + " &3a an attack cooldown bypasser!")
|
||||
.prefix()
|
||||
.color()
|
||||
.build());
|
||||
}
|
||||
catch (Exception ex) {
|
||||
CmdExHandler handler = new CmdExHandler(ex,command);
|
||||
sender.sendMessage(handler.getHelp());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package io.github.itzispyder.ogredupealias.events;
|
||||
|
||||
import io.github.itzispyder.ogredupealias.plugin.ItemPresets;
|
||||
import io.github.itzispyder.ogredupealias.plugin.RecipientList;
|
||||
import io.github.itzispyder.ogredupealias.utils.ItemUtils;
|
||||
import io.github.itzispyder.ogredupealias.utils.SoundPlayer;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class EntityDamageListener implements Listener {
|
||||
|
||||
public static final RecipientList attackCooldownBypassers = new RecipientList();
|
||||
|
||||
@EventHandler
|
||||
public void onDamageByEntity(EntityDamageByEntityEvent e) {
|
||||
this.processPenisSword(e);
|
||||
}
|
||||
|
||||
public void processPenisSword(EntityDamageByEntityEvent e) {
|
||||
final Entity victim = e.getEntity();
|
||||
final Entity damager = e.getDamager();
|
||||
|
||||
if (damager instanceof Player pDamager && victim instanceof LivingEntity vLiving) {
|
||||
final ItemStack item = pDamager.getInventory().getItemInMainHand();
|
||||
final SoundPlayer sticky = new SoundPlayer(vLiving.getLocation(), Sound.BLOCK_SLIME_BLOCK_BREAK, 1, 10);
|
||||
|
||||
if (ItemUtils.nbtMatches(item, ItemPresets.TROLL_SWORD) || attackCooldownBypassers.isRecipient(pDamager)) {
|
||||
vLiving.setNoDamageTicks(1);
|
||||
vLiving.setMaximumNoDamageTicks(2);
|
||||
sticky.playWithinAt(100);
|
||||
}
|
||||
else {
|
||||
vLiving.setNoDamageTicks(19);
|
||||
vLiving.setMaximumNoDamageTicks(20);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
package io.github.itzispyder.ogredupealias.utils;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import static io.github.itzispyder.ogredupealias.OgreDupeAlias.instance;
|
||||
|
||||
public class SoundPlayer {
|
||||
|
||||
private Location location;
|
||||
private Sound sound;
|
||||
private float volume;
|
||||
private float pitch;
|
||||
|
||||
/**
|
||||
* Constructs a new sound, this aims to add more methods to
|
||||
* the Bukkit APIs Sound class, as they don't have many
|
||||
* methods to use.
|
||||
*
|
||||
* @param location Location
|
||||
* @param sound Sound
|
||||
* @param volume float
|
||||
* @param pitch float
|
||||
*/
|
||||
public SoundPlayer(Location location, Sound sound, float volume, float pitch) {
|
||||
this.location = location;
|
||||
this.sound = sound;
|
||||
this.pitch = pitch;
|
||||
this.volume = volume;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Plays a sound to a player but at the store location
|
||||
*
|
||||
* @param player Player
|
||||
*/
|
||||
public void play(Player player) {
|
||||
player.playSound(this.location,this.sound,this.volume,this.pitch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Plays a sound to a player but at the player's location
|
||||
*
|
||||
* @param player Player
|
||||
*/
|
||||
public void playAt(Player player) {
|
||||
player.playSound(player.getLocation(),this.sound,this.volume,this.pitch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Plays the sound to all players within a distance, but at the stored location.
|
||||
*
|
||||
* @param distance double
|
||||
*/
|
||||
public void playWithin(double distance) {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
if (p != null && p.getWorld() == this.location.getWorld() && p.getLocation().distanceSquared(this.location) < distance) {
|
||||
p.playSound(this.location,this.sound,this.volume,this.pitch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Plays the sound to all players within a distance, but at the players' location.
|
||||
*
|
||||
* @param distance double
|
||||
*/
|
||||
public void playWithinAt(double distance) {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
if (p != null && p.getWorld() == this.location.getWorld() && p.getLocation().distanceSquared(this.location) < distance) {
|
||||
p.playSound(p.getLocation(),this.sound,this.volume,this.pitch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Plays the sound to all players on the server, but at the stored location.
|
||||
*/
|
||||
public void playAll() {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) p.playSound(this.location,this.sound,this.volume,this.pitch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Plays the sound to all players on the server, but at the players' location.
|
||||
*/
|
||||
public void playAllAt() {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) p.playSound(p.getLocation(),this.sound,this.volume,this.pitch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Repeats a sound to a player, but at the stored location.
|
||||
*
|
||||
* @param player Player
|
||||
* @param times int
|
||||
* @param tickDelay int
|
||||
*/
|
||||
public void repeat(Player player, int times, int tickDelay) {
|
||||
new BukkitRunnable() {
|
||||
int i = 0;
|
||||
@Override
|
||||
public void run() {
|
||||
if (i < times) {
|
||||
play(player);
|
||||
i ++;
|
||||
} else {
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(instance,0,tickDelay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Repeats a sound to a player, but at the player's location.
|
||||
*
|
||||
* @param player Player
|
||||
* @param times int
|
||||
* @param tickDelay int
|
||||
*/
|
||||
public void repeatAt(Player player, int times, int tickDelay) {
|
||||
new BukkitRunnable() {
|
||||
int i = 0;
|
||||
@Override
|
||||
public void run() {
|
||||
if (i < times) {
|
||||
playAt(player);
|
||||
i ++;
|
||||
} else {
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(instance,0,tickDelay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Repeats a sound to all players on the server, but at the stored location.
|
||||
*
|
||||
* @param times int
|
||||
* @param tickDelay int
|
||||
*/
|
||||
public void repeatAll(int times, int tickDelay) {
|
||||
new BukkitRunnable() {
|
||||
int i = 0;
|
||||
@Override
|
||||
public void run() {
|
||||
if (i < times) {
|
||||
playAll();
|
||||
i ++;
|
||||
} else {
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(instance,0,tickDelay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Repeats a sound to all players on the server, but at the players' location.
|
||||
*
|
||||
* @param times int
|
||||
* @param tickDelay int
|
||||
*/
|
||||
public void repeatAllAt(int times, int tickDelay) {
|
||||
new BukkitRunnable() {
|
||||
int i = 0;
|
||||
@Override
|
||||
public void run() {
|
||||
if (i < times) {
|
||||
playAllAt();
|
||||
i ++;
|
||||
} else {
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(instance,0,tickDelay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Repeats a sound to all players within a radius, but at the stored location.
|
||||
*
|
||||
* @param radius double
|
||||
* @param times int
|
||||
* @param tickDelay int
|
||||
*/
|
||||
public void repeatAll(double radius,int times, int tickDelay) {
|
||||
new BukkitRunnable() {
|
||||
int i = 0;
|
||||
@Override
|
||||
public void run() {
|
||||
if (i < times) {
|
||||
playWithin(radius);
|
||||
i ++;
|
||||
} else {
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(instance,0,tickDelay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Repeats a sound to all players within a radius, but at the players' location.
|
||||
*
|
||||
* @param distance double
|
||||
* @param times int
|
||||
* @param tickDelay int
|
||||
*/
|
||||
public void repeatAllAt(double distance, int times, int tickDelay) {
|
||||
new BukkitRunnable() {
|
||||
int i = 0;
|
||||
@Override
|
||||
public void run() {
|
||||
if (i < times) {
|
||||
playWithinAt(distance);
|
||||
i ++;
|
||||
} else {
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(instance,0,tickDelay);
|
||||
}
|
||||
|
||||
public Sound getSound() {
|
||||
return sound;
|
||||
}
|
||||
|
||||
public float getPitch() {
|
||||
return pitch;
|
||||
}
|
||||
|
||||
public float getVolume() {
|
||||
return volume;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setPitch(float pitch) {
|
||||
this.pitch = pitch;
|
||||
}
|
||||
|
||||
public void setVolume(float volume) {
|
||||
this.volume = volume;
|
||||
}
|
||||
|
||||
public void setSound(Sound sound) {
|
||||
this.sound = sound;
|
||||
}
|
||||
|
||||
public void setLocation(Location location) {
|
||||
this.location = location;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package io.github.itzispyder.ipearlpvp.util;
|
||||
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class SoundUtils {
|
||||
|
||||
private static final Map<String,Long> cooldown = new HashMap<>();
|
||||
|
||||
/**
|
||||
* For the parameters, use the format: "sound-name/sound-volume/sound-pitch"
|
||||
* @param listener the player listening for the sounds
|
||||
* @param p simplified parameters
|
||||
*/
|
||||
public static void play(Player listener, String p) {
|
||||
if (cooldown.containsKey(listener.getName()) && cooldown.get(listener.getName()) > System.currentTimeMillis()) return;
|
||||
cooldown.put(listener.getName(),System.currentTimeMillis() + 50);
|
||||
try {
|
||||
String[] params = p.split("/");
|
||||
Sound sound = Sound.valueOf(params[0].toUpperCase());
|
||||
float volume = Float.parseFloat(params[1]);
|
||||
float pitch = Float.parseFloat(params[2]);
|
||||
listener.playSound(listener.getLocation(),sound,volume,pitch);
|
||||
}
|
||||
catch (Exception ignore) {}
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,9 @@ permissions:
|
||||
oda.commands.irepair:
|
||||
description: Access to irepair.
|
||||
default: op
|
||||
oda.commands.attackcooldown:
|
||||
description: Access to attackcooldown.
|
||||
default: op
|
||||
oda.chat.bypass:
|
||||
description: Bypass chat restrictions
|
||||
default: op
|
||||
@@ -104,4 +107,9 @@ commands:
|
||||
- tell
|
||||
- whisper
|
||||
- w
|
||||
- message
|
||||
- message
|
||||
attackcooldown:
|
||||
description: Attack cooldown bypass for entities.
|
||||
usage: /attackcooldown
|
||||
aliases:
|
||||
- atkcool
|
||||
Reference in New Issue
Block a user