Pull Request Fixes / Changes, config changes
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
package com.willfp.eco.core.drops;
|
||||
|
||||
import com.willfp.eco.core.Eco;
|
||||
import com.willfp.eco.core.events.DropQueuePushEvent;
|
||||
import com.willfp.eco.core.integrations.antigrief.AntigriefManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -21,11 +18,6 @@ import java.util.Collection;
|
||||
* @see com.willfp.eco.util.TelekinesisUtils
|
||||
*/
|
||||
public class DropQueue {
|
||||
|
||||
private Location location;
|
||||
private boolean forceTelekinesis = false;
|
||||
private final Player player;
|
||||
|
||||
/**
|
||||
* The internally used {@link DropQueue}.
|
||||
*/
|
||||
@@ -36,7 +28,6 @@ public class DropQueue {
|
||||
*/
|
||||
public DropQueue(@NotNull final Player player) {
|
||||
handle = Eco.getHandler().getDropQueueFactory().create(player);
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,7 +71,6 @@ public class DropQueue {
|
||||
*/
|
||||
public DropQueue setLocation(@NotNull final Location location) {
|
||||
handle.setLocation(location);
|
||||
this.location = location;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -91,7 +81,6 @@ public class DropQueue {
|
||||
*/
|
||||
public DropQueue forceTelekinesis() {
|
||||
handle.forceTelekinesis();
|
||||
this.forceTelekinesis = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -99,11 +88,6 @@ public class DropQueue {
|
||||
* Push the queue.
|
||||
*/
|
||||
public void push() {
|
||||
if (!AntigriefManager.canPickupItem(this.player, this.location)) return;
|
||||
DropQueuePushEvent event = new DropQueuePushEvent(this.player, this.handle, this, this.forceTelekinesis);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
handle.push();
|
||||
}
|
||||
handle.push();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,34 +1,40 @@
|
||||
package com.willfp.eco.core.events;
|
||||
|
||||
import com.willfp.eco.core.drops.DropQueue;
|
||||
import com.willfp.eco.core.drops.InternalDropQueue;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class DropQueuePushEvent extends PlayerEvent implements Cancellable {
|
||||
|
||||
/**
|
||||
* Queue handle.
|
||||
*/
|
||||
private final InternalDropQueue handle;
|
||||
|
||||
/**
|
||||
* Queue itself.
|
||||
*/
|
||||
private final DropQueue queue;
|
||||
|
||||
/**
|
||||
* Cancel state.
|
||||
*/
|
||||
private boolean cancelled;
|
||||
|
||||
/**
|
||||
* Force telekinesis state
|
||||
* If telekinetic.
|
||||
*/
|
||||
private final boolean forceTelekinesis;
|
||||
private final boolean isTelekinetic;
|
||||
|
||||
/**
|
||||
* The items.
|
||||
*/
|
||||
private final Collection<? extends ItemStack> items;
|
||||
|
||||
/**
|
||||
* The xp.
|
||||
*/
|
||||
private final int xp;
|
||||
|
||||
/**
|
||||
* The location.
|
||||
*/
|
||||
private final Location location;
|
||||
|
||||
/**
|
||||
* Bukkit parity.
|
||||
@@ -36,15 +42,24 @@ public class DropQueuePushEvent extends PlayerEvent implements Cancellable {
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
|
||||
/**
|
||||
* Create a new ArmorEquipEvent.
|
||||
* Create a new DropQueuePushEvent.
|
||||
*
|
||||
* @param player The player.
|
||||
* @param player The player.
|
||||
* @param items The items.
|
||||
* @param location The location.
|
||||
* @param xp The xp.
|
||||
* @param isTelekinetic If the event is telekinetic.
|
||||
*/
|
||||
public DropQueuePushEvent(@NotNull final Player player, @NotNull final InternalDropQueue handle, @NotNull final DropQueue queue, final boolean forceTelekinesis) {
|
||||
public DropQueuePushEvent(@NotNull final Player player,
|
||||
@NotNull final Collection<? extends ItemStack> items,
|
||||
@NotNull final Location location,
|
||||
final int xp,
|
||||
final boolean isTelekinetic) {
|
||||
super(player);
|
||||
this.handle = handle;
|
||||
this.queue = queue;
|
||||
this.forceTelekinesis = forceTelekinesis;
|
||||
this.items = items;
|
||||
this.location = location;
|
||||
this.xp = xp;
|
||||
this.isTelekinetic = isTelekinetic;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,29 +95,38 @@ public class DropQueuePushEvent extends PlayerEvent implements Cancellable {
|
||||
/**
|
||||
* Set cancel state.
|
||||
*
|
||||
* @param b The state.
|
||||
* @param cancelled If cancelled.
|
||||
*/
|
||||
@Override
|
||||
public void setCancelled(boolean b) {
|
||||
this.cancelled = b;
|
||||
public void setCancelled(final boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get queue handle.
|
||||
* Get the items to be dropped.
|
||||
*
|
||||
* @return The handle.
|
||||
* @return The items.
|
||||
*/
|
||||
public InternalDropQueue getHandle() {
|
||||
return handle;
|
||||
public Collection<? extends ItemStack> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get queue.
|
||||
* Get the xp to be dropped.
|
||||
*
|
||||
* @return The queue.
|
||||
* @return The xp.
|
||||
*/
|
||||
public DropQueue getQueue() {
|
||||
return queue;
|
||||
public int getXp() {
|
||||
return xp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the location.
|
||||
*
|
||||
* @return The location.
|
||||
*/
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -110,8 +134,7 @@ public class DropQueuePushEvent extends PlayerEvent implements Cancellable {
|
||||
*
|
||||
* @return The force telekinesis state.
|
||||
*/
|
||||
public boolean isForceTelekinesis() {
|
||||
return this.forceTelekinesis;
|
||||
public boolean isTelekinetic() {
|
||||
return this.isTelekinetic;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.willfp.eco.core.integrations.antigrief;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -57,7 +56,7 @@ public final class AntigriefManager {
|
||||
* @return If player can break block.
|
||||
*/
|
||||
public static boolean canBreakBlock(@NotNull final Player player,
|
||||
@NotNull final Block block) {
|
||||
@NotNull final Block block) {
|
||||
return REGISTERED.stream().allMatch(antigriefWrapper -> antigriefWrapper.canBreakBlock(player, block));
|
||||
}
|
||||
|
||||
@@ -69,7 +68,7 @@ public final class AntigriefManager {
|
||||
* @return If player can create explosion.
|
||||
*/
|
||||
public static boolean canCreateExplosion(@NotNull final Player player,
|
||||
@NotNull final Location location) {
|
||||
@NotNull final Location location) {
|
||||
return REGISTERED.stream().allMatch(antigriefWrapper -> antigriefWrapper.canCreateExplosion(player, location));
|
||||
}
|
||||
|
||||
@@ -81,7 +80,7 @@ public final class AntigriefManager {
|
||||
* @return If player can place block.
|
||||
*/
|
||||
public static boolean canPlaceBlock(@NotNull final Player player,
|
||||
@NotNull final Block block) {
|
||||
@NotNull final Block block) {
|
||||
return REGISTERED.stream().allMatch(antigriefWrapper -> antigriefWrapper.canPlaceBlock(player, block));
|
||||
}
|
||||
|
||||
@@ -93,7 +92,7 @@ public final class AntigriefManager {
|
||||
* @return If player can injure.
|
||||
*/
|
||||
public static boolean canInjure(@NotNull final Player player,
|
||||
@NotNull final LivingEntity victim) {
|
||||
@NotNull final LivingEntity victim) {
|
||||
return REGISTERED.stream().allMatch(antigriefWrapper -> antigriefWrapper.canInjure(player, victim));
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ public interface AntigriefWrapper extends Integration {
|
||||
* @param block The block.
|
||||
* @return If player can break block.
|
||||
*/
|
||||
boolean canBreakBlock(Player player, Block block);
|
||||
boolean canBreakBlock(@NotNull Player player, @NotNull Block block);
|
||||
|
||||
/**
|
||||
* Can player create explosion at location.
|
||||
@@ -27,7 +27,7 @@ public interface AntigriefWrapper extends Integration {
|
||||
* @param location The location.
|
||||
* @return If player can create explosion.
|
||||
*/
|
||||
boolean canCreateExplosion(Player player, Location location);
|
||||
boolean canCreateExplosion(@NotNull Player player, @NotNull Location location);
|
||||
|
||||
/**
|
||||
* Can player place block.
|
||||
@@ -36,7 +36,7 @@ public interface AntigriefWrapper extends Integration {
|
||||
* @param block The block.
|
||||
* @return If player can place block.
|
||||
*/
|
||||
boolean canPlaceBlock(Player player, Block block);
|
||||
boolean canPlaceBlock(@NotNull Player player, @NotNull Block block);
|
||||
|
||||
/**
|
||||
* Can player injure living entity.
|
||||
@@ -45,7 +45,7 @@ public interface AntigriefWrapper extends Integration {
|
||||
* @param victim The victim.
|
||||
* @return If player can injure.
|
||||
*/
|
||||
boolean canInjure(Player player, LivingEntity victim);
|
||||
boolean canInjure(@NotNull Player player, @NotNull LivingEntity victim);
|
||||
|
||||
/**
|
||||
* Can player pick up item.
|
||||
@@ -54,6 +54,6 @@ public interface AntigriefWrapper extends Integration {
|
||||
* @param location The location.
|
||||
* @return If player can pick up item.
|
||||
*/
|
||||
boolean canPickupItem(@NotNull final Player player, @NotNull final Location location);
|
||||
boolean canPickupItem(@NotNull Player player, @NotNull Location location);
|
||||
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public final class Items {
|
||||
* @param item The item.
|
||||
*/
|
||||
public static void registerCustomItem(@NotNull final NamespacedKey key,
|
||||
@NotNull final TestableItem item) {
|
||||
@NotNull final TestableItem item) {
|
||||
REGISTRY.put(key, item);
|
||||
}
|
||||
|
||||
@@ -104,6 +104,7 @@ public final class Items {
|
||||
* @param key The lookup string.
|
||||
* @return The testable item, or an {@link EmptyTestableItem}.
|
||||
*/
|
||||
@NotNull
|
||||
public static TestableItem lookup(@NotNull final String key) {
|
||||
if (key.contains("?")) {
|
||||
String[] options = key.split("\\?");
|
||||
@@ -236,16 +237,32 @@ public final class Items {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get TestableItem from ItemStack
|
||||
* Get a Testable Item from an ItemStack.
|
||||
* <p>
|
||||
* Will search for registered items first. If there are no matches in the registry,
|
||||
* then it will return a {@link MaterialTestableItem} matching the item type.
|
||||
* <p>
|
||||
* Does not account for modifiers (arg parser data).
|
||||
*
|
||||
* @param item The item
|
||||
* @return TestableItem
|
||||
* @param item The ItemStack.
|
||||
* @return The found Testable Item.
|
||||
*/
|
||||
@NotNull
|
||||
public static TestableItem getItem(@Nullable final ItemStack item) {
|
||||
if (item == null || item.getType().isAir()) return new EmptyTestableItem();
|
||||
if (isCustomItem(item)) return getCustomItem(item);
|
||||
for (TestableItem value : REGISTRY.values()) {
|
||||
if (value.matches(item)) return value;
|
||||
if (item == null || item.getType().isAir()) {
|
||||
return new EmptyTestableItem();
|
||||
}
|
||||
|
||||
CustomItem customItem = getCustomItem(item);
|
||||
|
||||
if (customItem != null) {
|
||||
return customItem;
|
||||
}
|
||||
|
||||
for (TestableItem known : REGISTRY.values()) {
|
||||
if (known.matches(item)) {
|
||||
return known;
|
||||
}
|
||||
}
|
||||
return new MaterialTestableItem(item.getType());
|
||||
}
|
||||
@@ -299,6 +316,7 @@ public final class Items {
|
||||
* @param item The item.
|
||||
* @return The CustomItem.
|
||||
*/
|
||||
@NotNull
|
||||
public static CustomItem getOrWrap(@NotNull final TestableItem item) {
|
||||
if (item instanceof CustomItem) {
|
||||
return (CustomItem) item;
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
package com.willfp.eco.core.items.args;
|
||||
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class LeatherArmorColorArgParser implements LookupArgParser {
|
||||
@Override
|
||||
public @Nullable Predicate<ItemStack> parseArguments(@NotNull String[] args, @NotNull ItemMeta meta) {
|
||||
|
||||
if (!(meta instanceof LeatherArmorMeta)) return pred -> false;
|
||||
|
||||
for (String arg : args) {
|
||||
String[] argSplit = arg.split(":");
|
||||
if (!argSplit[0].equalsIgnoreCase("color")) {
|
||||
continue;
|
||||
}
|
||||
if (argSplit.length < 2) {
|
||||
continue;
|
||||
}
|
||||
String asString = argSplit[1];
|
||||
|
||||
LeatherArmorMeta lMeta = (LeatherArmorMeta) meta;
|
||||
|
||||
lMeta.setColor(fromString(asString));
|
||||
|
||||
return pred -> true;
|
||||
}
|
||||
|
||||
return pred -> false;
|
||||
|
||||
}
|
||||
|
||||
private Color fromString(String color) {
|
||||
|
||||
if (color.contains(",")) {
|
||||
|
||||
String[] split = color.split(",");
|
||||
|
||||
int red = 0;
|
||||
int green = 0;
|
||||
int blue = 0;
|
||||
|
||||
if (split.length > 0) {
|
||||
red = Integer.parseInt(split[0]);
|
||||
}
|
||||
if (split.length > 1) {
|
||||
green = Integer.parseInt(split[1]);
|
||||
}
|
||||
if (split.length > 2) {
|
||||
blue = Integer.parseInt(split[2]);
|
||||
}
|
||||
|
||||
return Color.fromRGB(red, green, blue);
|
||||
|
||||
} else if (color.startsWith("#")) {
|
||||
|
||||
java.awt.Color from = java.awt.Color.decode(color);
|
||||
|
||||
return Color.fromRGB(from.getRed(), from.getGreen(), from.getBlue());
|
||||
|
||||
} else {
|
||||
return fromString("#"+color);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,7 +14,7 @@ import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.Color;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
Reference in New Issue
Block a user