attack cooldown bypass

This commit is contained in:
ImproperIssues
2023-05-01 20:47:00 -07:00
parent 719ab132b1
commit 8b6a351ecf
13 changed files with 280 additions and 39 deletions

View File

@@ -1,7 +1,5 @@
package io.github.itzispyder.ogredupealias.events;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
@@ -11,15 +9,16 @@ public class BlockActionListener implements Listener {
@EventHandler
public void onPlace(BlockPlaceEvent e) {
final Player p = e.getPlayer();
final Block b = e.getBlockPlaced();
final Block f = e.getBlockAgainst();
try {
}
catch (Exception ignore) {}
}
public void onBreak(BlockBreakEvent e) {
final Player p = e.getPlayer();
final Block b = e.getBlock();
try {
}
catch (Exception ignore) {}
}
}

View File

@@ -10,6 +10,13 @@ public class ChatEventListener implements Listener {
@EventHandler
public void onChat(AsyncPlayerChatEvent e) {
try {
this.handleChatConstraints(e);
}
catch (Exception ignore) {}
}
private void handleChatConstraints(AsyncPlayerChatEvent e) {
final Player p = e.getPlayer();
final String msg = e.getMessage();
final ChatConstraints cc = new ChatConstraints(p,msg);

View File

@@ -32,6 +32,13 @@ public class CommandEventListener implements Listener {
@EventHandler
public void onPlayerCommand(PlayerCommandPreprocessEvent e) {
try {
this.handleChatCommands(e);
}
catch (Exception ignore) {}
}
private void handleChatCommands(PlayerCommandPreprocessEvent e) {
final String msg = e.getMessage();
final Player p = e.getPlayer();
final String[] words = msg.split(" ");

View File

@@ -9,31 +9,62 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.inventory.ItemStack;
public class EntityDamageListener implements Listener {
public static final RecipientList attackCooldownBypassers = new RecipientList();
public static final int DEFAULT_NO_DAMAGE_TICKS = 9;
public static final int DEFAULT_MAX_NO_DAMAGE_TICKS = 10;
public static final int NO_DAMAGE_TICKS = 1;
public static final int MAX_NO_DAMAGE_TICKS = 2;
@EventHandler
public void onDamageByEntity(EntityDamageByEntityEvent e) {
this.processPenisSword(e);
try {
this.handleBurstMelee(e);
}
catch (Exception ignore) {}
}
public void processPenisSword(EntityDamageByEntityEvent e) {
@EventHandler
public void onDamage(EntityDamageEvent e) {
try {
this.handleBurstMelee(e);
}
catch (Exception ignore) {}
}
public void handleBurstMelee(EntityDamageEvent e) {
final Entity ent = e.getEntity();
final EntityDamageEvent.DamageCause cause = e.getCause();
if (cause.name().contains("ENTITY")) return;
if (ent instanceof LivingEntity eLiving) {
eLiving.setNoDamageTicks(14);
eLiving.setMaximumNoDamageTicks(15);
}
}
public void handleBurstMelee(EntityDamageByEntityEvent e) {
final Entity victim = e.getEntity();
final Entity damager = e.getDamager();
final double dist = victim.getLocation().distance(damager.getLocation());
if (damager instanceof Player pDamager && victim instanceof LivingEntity vLiving) {
if (dist > 3.5) return;
if (pDamager.isDead() || victim.isDead()) return;
final ItemStack item = pDamager.getInventory().getItemInMainHand();
if (ItemUtils.nbtMatches(item, ItemPresets.TROLL_SWORD) || attackCooldownBypassers.isRecipient(pDamager)) {
vLiving.setNoDamageTicks(1);
vLiving.setMaximumNoDamageTicks(2);
vLiving.setNoDamageTicks(NO_DAMAGE_TICKS);
vLiving.setMaximumNoDamageTicks(MAX_NO_DAMAGE_TICKS);
}
else {
vLiving.setNoDamageTicks(19);
vLiving.setMaximumNoDamageTicks(20);
vLiving.setNoDamageTicks(DEFAULT_NO_DAMAGE_TICKS);
vLiving.setMaximumNoDamageTicks(DEFAULT_MAX_NO_DAMAGE_TICKS);
}
}
}

View File

@@ -1,7 +1,6 @@
package io.github.itzispyder.ogredupealias.events;
import io.github.itzispyder.ogredupealias.plugin.ItemPresets;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
@@ -15,9 +14,15 @@ public class EntityDeathListener implements Listener {
@EventHandler
public void onDeath(EntityDeathEvent e) {
try {
this.handleWardenDeath(e);
}
catch (Exception ignore) {}
}
private void handleWardenDeath(EntityDeathEvent e) {
final LivingEntity ent = e.getEntity();
final EntityType type = ent.getType();
final Location loc = ent.getLocation();
if (type == EntityType.WARDEN) {
e.getDrops().stream().filter(Objects::nonNull).filter(i -> i.getType() == Material.SCULK_CATALYST).forEach(i -> i.setItemMeta(ItemPresets.SCULK_CATALYST.getItemMeta()));

View File

@@ -6,27 +6,25 @@ import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
public class InteractionListener implements Listener {
@EventHandler
public void onClick(PlayerInteractEvent e) {
final Player p = e.getPlayer();
final Action a = e.getAction();
try {
this.processTable(e);
}
catch (Exception ignore) {}
}
private void processTable(PlayerInteractEvent e) {
final Player p = e.getPlayer();
final Block b = e.getClickedBlock();
final ItemStack item = e.getItem();
if (PlacedStructures.isCustomTable(b)) {
e.setCancelled(true);
p.openInventory(InventoryPresets.createCustomTable());
return;
}
}
catch (Exception ignore) {}
}
}

View File

@@ -12,24 +12,30 @@ public class InventoryActionListener implements Listener {
@EventHandler
public void onClick(InventoryClickEvent e) {
final Inventory inv = e.getClickedInventory();
final String title = e.getView().getTitle();
try {
if (inv == null) return;
if (title.equals(Text.color("&eForging Table"))) CustomTable.onInventoryAction(e);
this.handleForgeClick(e);
}
catch (Exception ignore) {}
}
@EventHandler
public void onClose(InventoryCloseEvent e) {
final String title = e.getView().getTitle();
try {
if (title.equals(Text.color("&eForging Table"))) CustomTable.onInventoryClose(e);
this.handleForgeClose(e);
}
catch (Exception ignore) {}
}
private void handleForgeClick(InventoryClickEvent e) {
final Inventory inv = e.getClickedInventory();
final String title = e.getView().getTitle();
if (inv == null) return;
if (title.equals(Text.color("&eForging Table"))) CustomTable.onInventoryAction(e);
}
private void handleForgeClose(InventoryCloseEvent e) {
final String title = e.getView().getTitle();
if (title.equals(Text.color("&eForging Table"))) CustomTable.onInventoryClose(e);
}
}

View File

@@ -0,0 +1,33 @@
package io.github.itzispyder.ogredupealias.utils;
import java.util.HashMap;
import java.util.Map;
public class Cooldown<T> {
private final Map<T,Long> timer;
public Cooldown() {
this.timer = new HashMap<>();
}
private <O> O getOrDefault(O value, O def) {
return value != null ? value : def;
}
public long getCooldown(T obj) {
return Math.max(getOrDefault(timer.get(obj), 0L) - System.currentTimeMillis(), 0L);
}
public boolean isOnCooldown(T obj) {
return getCooldown(obj) > 0L;
}
public void setCooldown(T obj, long millis) {
timer.put(obj, System.currentTimeMillis() + millis);
}
public void addCooldown(T obj, long millis) {
setCooldown(obj, getCooldown(obj) + millis);
}
}

View File

@@ -0,0 +1,21 @@
package io.github.itzispyder.ogredupealias.utils;
import java.io.File;
public final class FileValidationUtils {
public static boolean validate(File file) {
try {
if (!file.getParentFile().exists())
if (!file.getParentFile().mkdirs())
return false;
if (!file.exists())
if (!file.createNewFile())
return false;
return true;
}
catch (Exception ex) {
return false;
}
}
}

View File

@@ -0,0 +1,41 @@
package io.github.itzispyder.ogredupealias.utils;
import java.util.HashMap;
import java.util.Map;
/**
* Make a map manually
* @param <K> key
* @param <V> value
*/
public class ManualMap<K,V> {
public Map<K,V> map = new HashMap<>();
/**
* Manual map
* @param objects objects array
* @param <O> list of objects
*/
public <O extends Object> ManualMap (O... objects) {
if (objects.length % 2 != 0)
throw new IllegalArgumentException("objects amount must be even for each key to have a value pair!");
for (int i = 0; i < objects.length; i += 2) {
try {
map.put((K) objects[i],(V) objects[i + 1]);
}
catch (Exception ex) {
map.clear();
break;
}
}
}
/**
* Returns the map
* @return map
*/
public Map<K, V> getMap() {
return map;
}
}

View File

@@ -0,0 +1,21 @@
package io.github.itzispyder.ogredupealias.utils;
import java.util.*;
public final class MathUtils {
public static double avg(Integer... ints) {
final List<Integer> list = Arrays.stream(ints).filter(Objects::nonNull).toList();
return avg(list);
}
public static double avg(List<Integer> ints) {
double sum = 0.0;
for (Integer i : ints) sum += i;
return sum / ints.size();
}
public static double round(double value, int nthPlace) {
return Math.floor(value * nthPlace) / nthPlace;
}
}

View File

@@ -0,0 +1,68 @@
package io.github.itzispyder.ogredupealias.utils;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
/**
* Randomize items from a list
* @param <T> list of?
*/
public class Randomizer<T> {
private final List<T> array;
/**
* From array list
* @param array list
*/
public Randomizer(List<T> array) {
this.array = array;
}
/**
* From set
* @param array set
*/
public Randomizer(Set<T> array) {
this.array = new ArrayList<>(array);
}
/**
* From array
* @param array array
*/
public Randomizer(T[] array) {
this.array = List.of(array);
}
/**
* Pick random from the array
* @return random of list of?
*/
public T pickRand() {
return array.get(rand(array.size()) - 1);
}
/**
* Generates a random integer from 1 to (max)
* @param max max value
* @return random
*/
public static int rand(int max) {
if (max <= 0) throw new IllegalArgumentException("max cannot be less than 1!");
return (int) Math.ceil(Math.random() * max);
}
/**
* Generates a random integer from (min) to (max)
* @param min min value
* @param max max value
* @return random
*/
public static int rand(int min, int max) {
if (max <= 0 || min <= 0) throw new IllegalArgumentException("max or min cannot be less than 1!");
if (max <= min) throw new IllegalArgumentException("max cannot be less than or equal to min!");
return min + (int) Math.floor(Math.random() * (max - min + 1));
}
}

View File

@@ -1,6 +1,6 @@
package io.github.itzispyder.ogredupealias.utils;
import static io.github.itzispyder.ogredupealias.OgreDupeAlias.prefix;
import io.github.itzispyder.ogredupealias.data.Config;
public class Text {
@@ -8,6 +8,10 @@ public class Text {
return s;
}
public static String ofAll(String s) {
return builder(s).prefix().color().build();
}
/**
* Replaces all & with § to color the text
* @param s string
@@ -32,7 +36,7 @@ public class Text {
}
public static String prefixed(String s) {
return prefix() + s;
return Config.Plugin.prefix() + s;
}
public static TextBuilder builder(String s) {