mirror of
https://github.com/craftaro/EpicSpawners.git
synced 2025-01-08 11:37:51 +08:00
Heavy code style changes and slight refactoring
This commit is contained in:
parent
5a5c9df0ed
commit
14f3e9a247
@ -33,7 +33,7 @@
|
||||
<injections>
|
||||
<injection>
|
||||
<value>${project.version}</value>
|
||||
<pointCut>com.craftaro.epicspawners.api.EpicSpawnersAPI.getVersion</pointCut>
|
||||
<pointCut>com.craftaro.epicspawners.api.EpicSpawnersApi.getVersion</pointCut>
|
||||
</injection>
|
||||
</injections>
|
||||
</configuration>
|
||||
|
@ -7,21 +7,20 @@ import org.bukkit.plugin.Plugin;
|
||||
/**
|
||||
* The main class of the API
|
||||
* <p>
|
||||
* <b>!! {@link EpicSpawnersAPI#getVersion()} value is automatically replaced by maven don't change it !!</b>
|
||||
* <b>!! {@link EpicSpawnersApi#getVersion()} value is automatically replaced by maven don't change it !!</b>
|
||||
*/
|
||||
public class EpicSpawnersAPI {
|
||||
|
||||
public class EpicSpawnersApi {
|
||||
private static Plugin plugin;
|
||||
private static SpawnerDataBuilder spawnerDataBuilder;
|
||||
private static SpawnerTierBuilder spawnerTierBuilder;
|
||||
|
||||
public EpicSpawnersAPI(Plugin plugin, SpawnerDataBuilder spawnerDataBuilder, SpawnerTierBuilder spawnerTierBuilder) {
|
||||
if (EpicSpawnersAPI.plugin != null) {
|
||||
public EpicSpawnersApi(Plugin plugin, SpawnerDataBuilder spawnerDataBuilder, SpawnerTierBuilder spawnerTierBuilder) {
|
||||
if (EpicSpawnersApi.plugin != null) {
|
||||
throw new IllegalStateException("EpicSpawnersAPI has already been initialized!");
|
||||
}
|
||||
EpicSpawnersAPI.plugin = plugin;
|
||||
EpicSpawnersAPI.spawnerDataBuilder = spawnerDataBuilder;
|
||||
EpicSpawnersAPI.spawnerTierBuilder = spawnerTierBuilder;
|
||||
EpicSpawnersApi.plugin = plugin;
|
||||
EpicSpawnersApi.spawnerDataBuilder = spawnerDataBuilder;
|
||||
EpicSpawnersApi.spawnerTierBuilder = spawnerTierBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -47,6 +46,7 @@ public class EpicSpawnersAPI {
|
||||
|
||||
/**
|
||||
* Used to get the version of the plugin
|
||||
*
|
||||
* @return The version of the plugin
|
||||
*/
|
||||
public static String getVersion() {
|
@ -6,51 +6,55 @@ import com.craftaro.epicspawners.api.boosts.types.BoostedSpawner;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface BoostManager {
|
||||
|
||||
/**
|
||||
* Add a boost to the manager and save it to the database
|
||||
*
|
||||
* @param boosted The boost to add
|
||||
*/
|
||||
void addBoost(Boosted boosted);
|
||||
|
||||
/**
|
||||
* Remove a boost from the manager and delete it from the database
|
||||
*
|
||||
* @param boosted The boost to remove
|
||||
*/
|
||||
void removeBoost(Boosted boosted);
|
||||
|
||||
/**
|
||||
* Get all boosts
|
||||
*
|
||||
* @return All boosts
|
||||
*/
|
||||
Set<Boosted> getBoosts();
|
||||
|
||||
/**
|
||||
* Create a new boost for a player
|
||||
* @param playerUUID The UUID of the player
|
||||
* @param amtBoosted The amount boosted
|
||||
* @param endTime The time the boost ends
|
||||
*
|
||||
* @param playerUUID The UUID of the player
|
||||
* @param amtBoosted The amount boosted
|
||||
* @param endTime The time the boost ends
|
||||
*/
|
||||
BoostedPlayer createBoostedPlayer(UUID playerUUID, int amtBoosted, long endTime);
|
||||
|
||||
/**
|
||||
* Create a new boost for a player
|
||||
* @param player The player
|
||||
* @param amtBoosted The amount boosted
|
||||
* @param endTime The time the boost ends
|
||||
*
|
||||
* @param player The player
|
||||
* @param amtBoosted The amount boosted
|
||||
* @param endTime The time the boost ends
|
||||
*/
|
||||
BoostedPlayer createBoostedPlayer(Player player, int amtBoosted, long endTime);
|
||||
|
||||
/**
|
||||
* Create a new boost for a spawner
|
||||
* @param location The location of the spawner
|
||||
* @param amtBoosted The amount boosted
|
||||
* @param endTime The time the boost ends
|
||||
*
|
||||
* @param location The location of the spawner
|
||||
* @param amtBoosted The amount boosted
|
||||
* @param endTime The time the boost ends
|
||||
*/
|
||||
BoostedSpawner createBoostedSpawner(Location location, int amtBoosted, long endTime);
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package com.craftaro.epicspawners.api.boosts.types;
|
||||
import com.craftaro.core.database.Data;
|
||||
|
||||
public interface Boosted extends Data {
|
||||
|
||||
int getAmountBoosted();
|
||||
|
||||
long getEndTime();
|
||||
|
@ -1,9 +1,7 @@
|
||||
package com.craftaro.epicspawners.api.boosts.types;
|
||||
|
||||
import com.craftaro.core.database.Data;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
public interface BoostedPlayer extends Boosted {
|
||||
|
||||
OfflinePlayer getPlayer();
|
||||
}
|
||||
|
@ -6,16 +6,25 @@ import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
/**
|
||||
* Called when someone attempts to access a spawner. Can be cancelled.
|
||||
* Called when someone attempts to access a spawner.
|
||||
*/
|
||||
public class SpawnerAccessEvent extends SpawnerEvent implements Cancellable {
|
||||
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
|
||||
private boolean cancelled = false;
|
||||
|
||||
public SpawnerAccessEvent(Player player, PlacedSpawner spawner) {
|
||||
super(player, spawner);
|
||||
public SpawnerAccessEvent(Player who, PlacedSpawner spawner) {
|
||||
super(who, spawner);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return this.cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancelled = cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -26,14 +35,4 @@ public class SpawnerAccessEvent extends SpawnerEvent implements Cancellable {
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean canceled) {
|
||||
this.cancelled = canceled;
|
||||
}
|
||||
}
|
||||
|
@ -9,13 +9,22 @@ import org.bukkit.event.HandlerList;
|
||||
* Called when a spawner has been broken in the world
|
||||
*/
|
||||
public class SpawnerBreakEvent extends SpawnerEvent implements Cancellable {
|
||||
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
|
||||
private boolean cancelled = false;
|
||||
|
||||
public SpawnerBreakEvent(Player player, PlacedSpawner spawner) {
|
||||
super(player, spawner);
|
||||
public SpawnerBreakEvent(Player who, PlacedSpawner spawner) {
|
||||
super(who, spawner);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return this.cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancelled = cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -26,15 +35,4 @@ public class SpawnerBreakEvent extends SpawnerEvent implements Cancellable {
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean canceled) {
|
||||
this.cancelled = canceled;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,11 +11,10 @@ import org.bukkit.event.HandlerList;
|
||||
* well as a change in {@link SpawnerTier}
|
||||
*/
|
||||
public class SpawnerChangeEvent extends SpawnerEvent implements Cancellable {
|
||||
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
|
||||
public enum ChangeType {
|
||||
STACK_SIZE, SPAWNER_DATA;
|
||||
STACK_SIZE, SPAWNER_DATA
|
||||
}
|
||||
|
||||
private boolean canceled = false;
|
||||
@ -24,21 +23,21 @@ public class SpawnerChangeEvent extends SpawnerEvent implements Cancellable {
|
||||
private final SpawnerTier spawnerTier, oldSpawnerTier;
|
||||
private final ChangeType type;
|
||||
|
||||
public SpawnerChangeEvent(Player player, PlacedSpawner spawner, int stackSize, int oldStackSize) {
|
||||
super(player, spawner);
|
||||
public SpawnerChangeEvent(Player who, PlacedSpawner spawner, int stackSize, int oldStackSize) {
|
||||
super(who, spawner);
|
||||
|
||||
this.stackSize = stackSize;
|
||||
this.oldStackSize = oldStackSize;
|
||||
this.spawnerTier = oldSpawnerTier = null;
|
||||
this.spawnerTier = this.oldSpawnerTier = null;
|
||||
this.type = ChangeType.STACK_SIZE;
|
||||
}
|
||||
|
||||
public SpawnerChangeEvent(Player player, PlacedSpawner spawner, SpawnerTier data, SpawnerTier oldSpawnerTier) {
|
||||
super(player, spawner);
|
||||
public SpawnerChangeEvent(Player who, PlacedSpawner spawner, SpawnerTier data, SpawnerTier oldSpawnerTier) {
|
||||
super(who, spawner);
|
||||
|
||||
this.spawnerTier = data;
|
||||
this.oldSpawnerTier = oldSpawnerTier;
|
||||
this.stackSize = oldStackSize = spawner.getStackSize();
|
||||
this.stackSize = this.oldStackSize = spawner.getStackSize();
|
||||
this.type = ChangeType.SPAWNER_DATA;
|
||||
}
|
||||
|
||||
@ -50,7 +49,7 @@ public class SpawnerChangeEvent extends SpawnerEvent implements Cancellable {
|
||||
* @return the new stack size
|
||||
*/
|
||||
public int getStackSize() {
|
||||
return stackSize;
|
||||
return this.stackSize;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -61,7 +60,7 @@ public class SpawnerChangeEvent extends SpawnerEvent implements Cancellable {
|
||||
* @return the old stack size
|
||||
*/
|
||||
public int getOldStackSize() {
|
||||
return oldStackSize;
|
||||
return this.oldStackSize;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -71,7 +70,7 @@ public class SpawnerChangeEvent extends SpawnerEvent implements Cancellable {
|
||||
* @return the new spawner data
|
||||
*/
|
||||
public SpawnerTier getSpawnerTier() {
|
||||
return spawnerTier;
|
||||
return this.spawnerTier;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -81,7 +80,7 @@ public class SpawnerChangeEvent extends SpawnerEvent implements Cancellable {
|
||||
* @return the old spawner data
|
||||
*/
|
||||
public SpawnerTier getOldSpawnerTier() {
|
||||
return oldSpawnerTier;
|
||||
return this.oldSpawnerTier;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -90,7 +89,7 @@ public class SpawnerChangeEvent extends SpawnerEvent implements Cancellable {
|
||||
* @return the change type
|
||||
*/
|
||||
public ChangeType getChange() {
|
||||
return type;
|
||||
return this.type;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -104,12 +103,12 @@ public class SpawnerChangeEvent extends SpawnerEvent implements Cancellable {
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return canceled;
|
||||
return this.canceled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean canceled) {
|
||||
this.canceled = canceled;
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.canceled = cancel;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -120,7 +119,7 @@ public class SpawnerChangeEvent extends SpawnerEvent implements Cancellable {
|
||||
*/
|
||||
@Deprecated
|
||||
public int getCurrentMulti() {
|
||||
return stackSize;
|
||||
return this.stackSize;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -131,7 +130,7 @@ public class SpawnerChangeEvent extends SpawnerEvent implements Cancellable {
|
||||
*/
|
||||
@Deprecated
|
||||
public int getOldMulti() {
|
||||
return oldStackSize;
|
||||
return this.oldStackSize;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -142,7 +141,7 @@ public class SpawnerChangeEvent extends SpawnerEvent implements Cancellable {
|
||||
*/
|
||||
@Deprecated
|
||||
public String getType() {
|
||||
return spawnerTier.getIdentifyingName();
|
||||
return this.spawnerTier.getIdentifyingName();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -153,7 +152,6 @@ public class SpawnerChangeEvent extends SpawnerEvent implements Cancellable {
|
||||
*/
|
||||
@Deprecated
|
||||
public String getOldType() {
|
||||
return oldSpawnerTier.getIdentifyingName();
|
||||
return this.oldSpawnerTier.getIdentifyingName();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,13 +10,22 @@ import org.bukkit.event.HandlerList;
|
||||
* Called when a spawner has been dropped in the world after being broken
|
||||
*/
|
||||
public class SpawnerDropEvent extends SpawnerEvent implements Cancellable {
|
||||
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
|
||||
private boolean canceled = false;
|
||||
|
||||
public SpawnerDropEvent(Player player, PlacedSpawner spawner) {
|
||||
super(player, spawner);
|
||||
public SpawnerDropEvent(Player who, PlacedSpawner spawner) {
|
||||
super(who, spawner);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return this.canceled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.canceled = cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -27,15 +36,4 @@ public class SpawnerDropEvent extends SpawnerEvent implements Cancellable {
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return canceled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean canceled) {
|
||||
this.canceled = canceled;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ import org.bukkit.event.player.PlayerEvent;
|
||||
* Represents an abstract {@link Event} given a {@link Player} and {@link PlacedSpawner} instance
|
||||
*/
|
||||
public abstract class SpawnerEvent extends PlayerEvent {
|
||||
|
||||
protected final PlacedSpawner spawner;
|
||||
|
||||
public SpawnerEvent(Player who, PlacedSpawner spawner) {
|
||||
@ -23,7 +22,6 @@ public abstract class SpawnerEvent extends PlayerEvent {
|
||||
* @return the broken spawner
|
||||
*/
|
||||
public PlacedSpawner getSpawner() {
|
||||
return spawner;
|
||||
return this.spawner;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -9,13 +9,22 @@ import org.bukkit.event.HandlerList;
|
||||
* Called when a spawner has been placed in the world
|
||||
*/
|
||||
public class SpawnerPlaceEvent extends SpawnerEvent implements Cancellable {
|
||||
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
|
||||
private boolean canceled = false;
|
||||
|
||||
public SpawnerPlaceEvent(Player player, PlacedSpawner spawner) {
|
||||
super(player, spawner);
|
||||
public SpawnerPlaceEvent(Player who, PlacedSpawner spawner) {
|
||||
super(who, spawner);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return this.canceled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.canceled = cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -26,14 +35,4 @@ public class SpawnerPlaceEvent extends SpawnerEvent implements Cancellable {
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return canceled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean canceled) {
|
||||
this.canceled = canceled;
|
||||
}
|
||||
}
|
||||
|
@ -10,20 +10,28 @@ import org.bukkit.event.entity.EntityEvent;
|
||||
* Called when a spawner spawns an entity.
|
||||
*/
|
||||
public class SpawnerSpawnEvent extends EntityEvent implements Cancellable {
|
||||
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
|
||||
private boolean canceled = false;
|
||||
|
||||
private final PlacedSpawner spawner;
|
||||
|
||||
public SpawnerSpawnEvent(Entity entity, PlacedSpawner spawner) {
|
||||
super(entity);
|
||||
public SpawnerSpawnEvent(Entity what, PlacedSpawner spawner) {
|
||||
super(what);
|
||||
this.spawner = spawner;
|
||||
}
|
||||
|
||||
public PlacedSpawner getSpawner() {
|
||||
return spawner;
|
||||
return this.spawner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return this.canceled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.canceled = cancel;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
@ -33,15 +41,4 @@ public class SpawnerSpawnEvent extends EntityEvent implements Cancellable {
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return canceled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean canceled) {
|
||||
this.canceled = canceled;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -4,20 +4,19 @@ package com.craftaro.epicspawners.api.particles;
|
||||
* The density of a particle effect displayed by EpicSpawners
|
||||
*/
|
||||
public enum ParticleDensity {
|
||||
|
||||
/**
|
||||
* Very light particle effects. The lowest possible density
|
||||
*/
|
||||
LIGHT(8, 2, 1),
|
||||
|
||||
/**
|
||||
* A medium density. The third highest density with average performance
|
||||
* A medium density. The third-highest density with average performance
|
||||
*/
|
||||
NORMAL(15, 5, 3),
|
||||
|
||||
/**
|
||||
* An excessive amount of particles. The second highest density with
|
||||
* questionable performance
|
||||
* An excessive amount of particles.
|
||||
* The second-highest density with questionable performance
|
||||
*/
|
||||
EXCESSIVE(21, 9, 7),
|
||||
|
||||
@ -27,11 +26,11 @@ public enum ParticleDensity {
|
||||
*/
|
||||
MAD(30, 13, 15);
|
||||
|
||||
private int spawnerSpawn;
|
||||
private int entitySpawn;
|
||||
private int effect;
|
||||
private final int spawnerSpawn;
|
||||
private final int entitySpawn;
|
||||
private final int effect;
|
||||
|
||||
private ParticleDensity(int spawnerSpawn, int entitySpawn, int effect) {
|
||||
ParticleDensity(int spawnerSpawn, int entitySpawn, int effect) {
|
||||
this.spawnerSpawn = spawnerSpawn;
|
||||
this.entitySpawn = entitySpawn;
|
||||
this.effect = effect;
|
||||
@ -44,7 +43,7 @@ public enum ParticleDensity {
|
||||
* @return the amount of particles
|
||||
*/
|
||||
public int getSpawnerSpawn() {
|
||||
return spawnerSpawn;
|
||||
return this.spawnerSpawn;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -54,7 +53,7 @@ public enum ParticleDensity {
|
||||
* @return the amount of particles
|
||||
*/
|
||||
public int getEntitySpawn() {
|
||||
return entitySpawn;
|
||||
return this.entitySpawn;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -65,6 +64,6 @@ public enum ParticleDensity {
|
||||
* @see ParticleEffect
|
||||
*/
|
||||
public int getEffect() {
|
||||
return effect;
|
||||
return this.effect;
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ package com.craftaro.epicspawners.api.particles;
|
||||
* All possible types of particle patterns to be displayed around a spawner
|
||||
*/
|
||||
public enum ParticleEffect {
|
||||
|
||||
/**
|
||||
* No particle effect
|
||||
*/
|
||||
@ -20,5 +19,4 @@ public enum ParticleEffect {
|
||||
* small circle)
|
||||
*/
|
||||
TARGET
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ package com.craftaro.epicspawners.api.particles;
|
||||
* All possible types of particles supported by EpicSpawners
|
||||
*/
|
||||
public enum ParticleType {
|
||||
|
||||
/**
|
||||
* A small explosion effect. Not to be confused with the smoke particle
|
||||
* effect. This is a poorly named constant. This constant's true particle
|
||||
@ -31,7 +30,7 @@ public enum ParticleType {
|
||||
|
||||
private final String effect;
|
||||
|
||||
private ParticleType(String effect) {
|
||||
ParticleType(String effect) {
|
||||
this.effect = effect;
|
||||
}
|
||||
|
||||
@ -41,8 +40,6 @@ public enum ParticleType {
|
||||
* @return the particle name
|
||||
*/
|
||||
public String getEffect() {
|
||||
return effect;
|
||||
return this.effect;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,6 @@ import org.bukkit.entity.EntityType;
|
||||
import java.util.Map;
|
||||
|
||||
public interface PlayerData {
|
||||
|
||||
void save();
|
||||
|
||||
OfflinePlayer getPlayer();
|
||||
|
@ -6,7 +6,6 @@ import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface PlayerDataManager {
|
||||
|
||||
PlayerData getPlayerData(UUID uuid);
|
||||
|
||||
PlayerData getPlayerData(Player player);
|
||||
|
@ -10,7 +10,6 @@ import java.util.function.Predicate;
|
||||
* be permitted to perform a spawn or not.
|
||||
*/
|
||||
public interface SpawnCondition {
|
||||
|
||||
/**
|
||||
* Get the name of this spawn condition.
|
||||
*
|
||||
@ -42,5 +41,4 @@ public interface SpawnCondition {
|
||||
default Predicate<PlacedSpawner> asPredicate() {
|
||||
return this::isMet;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
package com.craftaro.epicspawners.api.spawners.spawner;
|
||||
|
||||
import com.craftaro.core.compatibility.CompatibleHand;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.database.Data;
|
||||
import com.craftaro.core.nms.world.SpawnedEntity;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.epicspawners.api.boosts.types.Boosted;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
@ -17,7 +17,6 @@ import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface PlacedSpawner extends Data {
|
||||
|
||||
int spawn(int amountToSpawn, String particle, Set<XMaterial> canSpawnOn, SpawnedEntity spawned, EntityType... types);
|
||||
|
||||
SpawnerStack addSpawnerStack(SpawnerStack spawnerStack);
|
||||
|
@ -6,7 +6,6 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public interface SpawnerData {
|
||||
|
||||
String getIdentifyingName();
|
||||
|
||||
boolean isCraftable();
|
||||
|
@ -5,7 +5,6 @@ import com.craftaro.epicspawners.api.utils.CostType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface SpawnerStack extends Data {
|
||||
|
||||
PlacedSpawner getSpawner();
|
||||
|
||||
int getStackSize();
|
||||
|
@ -5,9 +5,7 @@ import com.craftaro.epicspawners.api.spawners.spawner.SpawnerStack;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerTier;
|
||||
|
||||
public interface SpawnOption {
|
||||
|
||||
void spawn(SpawnerTier data, SpawnerStack stack, PlacedSpawner spawner);
|
||||
|
||||
SpawnOptionType getType();
|
||||
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ package com.craftaro.epicspawners.api.utils;
|
||||
* Represents a cost type when making a purchase from EpicSpawners
|
||||
*/
|
||||
public enum CostType {
|
||||
|
||||
/**
|
||||
* A purchase made with an economy balance (generally an implementation of Vault)
|
||||
*/
|
||||
@ -14,5 +13,4 @@ public enum CostType {
|
||||
* A purchase made with a player's experience levels
|
||||
*/
|
||||
LEVELS
|
||||
|
||||
}
|
||||
|
@ -1,10 +1,6 @@
|
||||
package com.craftaro.epicspawners.api.utils;
|
||||
|
||||
/**
|
||||
* Created by songoda on 3/20/2017.
|
||||
*/
|
||||
public enum HeadType {
|
||||
|
||||
BAT("978862a56119227aaad4b7c246c8b2256db985db0951f55b0a1f8616c191f"),
|
||||
BLAZE("b78ef2e4cf2c41a2d14bfde9caff10219f5b1bf5b35a49eb51c6467882cb5f0"),
|
||||
CHICKEN("1638469a599ceef7207537603248a9ab11ff591fd378bea4735b346a7fae893"),
|
||||
@ -88,14 +84,21 @@ public enum HeadType {
|
||||
CAMEL("3642c9f71131b5df4a8c21c8c6f10684f22abafb8cd68a1d55ac4bf263a53a31"),
|
||||
SNIFFER("87ad920a66e38cc3426a5bff084667e8772116915e298098567c139f222e2c42");
|
||||
|
||||
private final String url;
|
||||
private final String urlHash;
|
||||
|
||||
private HeadType(String url) {
|
||||
this.url = url;
|
||||
HeadType(String urlHash) {
|
||||
this.urlHash = urlHash;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #getUrlHash()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public String getUrl() {
|
||||
return url;
|
||||
return this.urlHash;
|
||||
}
|
||||
|
||||
public String getUrlHash() {
|
||||
return this.urlHash;
|
||||
}
|
||||
}
|
||||
|
@ -1,31 +1,21 @@
|
||||
package com.craftaro.epicspawners.api.utils;
|
||||
|
||||
import com.craftaro.core.utils.ItemUtils;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.SkullUtils;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerData;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerTier;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by songoda on 3/19/2017.
|
||||
*/
|
||||
public class HeadUtils {
|
||||
|
||||
private static final Map<HeadType, String> textureURL = new EnumMap<>(HeadType.class);
|
||||
private static final Map<HeadType, String> TEXTURE_HASHES = new EnumMap<>(HeadType.class);
|
||||
|
||||
static {
|
||||
for (HeadType type : HeadType.values()) {
|
||||
textureURL.put(type, type.getUrl());
|
||||
}
|
||||
}
|
||||
|
||||
private static HeadType getHeadTypeOrDefault(String name) {
|
||||
try {
|
||||
return HeadType.valueOf(name);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return HeadType.DROPPED_ITEM;
|
||||
TEXTURE_HASHES.put(type, type.getUrlHash());
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,10 +24,29 @@ public class HeadUtils {
|
||||
}
|
||||
|
||||
public static ItemStack getTexturedSkull(SpawnerData spawnerData) {
|
||||
return ItemUtils.getCustomHead(textureURL.get(getHeadTypeOrDefault(spawnerData.getIdentifyingName().toUpperCase().replace(" ", "_"))));
|
||||
HeadType headType = getHeadTypeOrDefault(spawnerData.getIdentifyingName().toUpperCase().replace(" ", "_"));
|
||||
return createSkullForSkinHash(TEXTURE_HASHES.get(headType));
|
||||
}
|
||||
|
||||
public static ItemStack getTexturedSkull(HeadType headType) {
|
||||
return ItemUtils.getCustomHead(headType.getUrl());
|
||||
return createSkullForSkinHash(headType.getUrlHash());
|
||||
}
|
||||
}
|
||||
|
||||
private static ItemStack createSkullForSkinHash(String textureHash) {
|
||||
ItemStack head = XMaterial.PLAYER_HEAD.parseItem();
|
||||
|
||||
SkullMeta meta = (SkullMeta) head.getItemMeta();
|
||||
SkullUtils.applySkin(meta, textureHash);
|
||||
head.setItemMeta(meta);
|
||||
|
||||
return head;
|
||||
}
|
||||
|
||||
private static HeadType getHeadTypeOrDefault(String name) {
|
||||
try {
|
||||
return HeadType.valueOf(name);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
return HeadType.DROPPED_ITEM;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,11 +5,6 @@ import com.craftaro.epicspawners.api.spawners.spawner.SpawnerData;
|
||||
import java.util.List;
|
||||
|
||||
public interface SpawnerDataBuilder {
|
||||
|
||||
/**
|
||||
* Creates a new SpawnerDataBuilder
|
||||
* @return a new SpawnerDataBuilder
|
||||
*/
|
||||
SpawnerDataBuilder newBuilder(String identifier);
|
||||
|
||||
SpawnerDataBuilder setCustom(boolean custom);
|
||||
@ -37,4 +32,4 @@ public interface SpawnerDataBuilder {
|
||||
SpawnerDataBuilder shopPrice(double shopPrice);
|
||||
|
||||
SpawnerData build();
|
||||
}
|
||||
}
|
||||
|
@ -11,14 +11,10 @@ import org.bukkit.inventory.ItemStack;
|
||||
import java.util.List;
|
||||
|
||||
public interface SpawnerTierBuilder {
|
||||
|
||||
/**
|
||||
* Creates a new SpawnerDataBuilder
|
||||
* @return a new SpawnerDataBuilder
|
||||
*/
|
||||
SpawnerTierBuilder newBuilder(String identifier);
|
||||
|
||||
SpawnerTierBuilder setDisplayName(String name);
|
||||
|
||||
SpawnerTierBuilder displayItem(XMaterial material);
|
||||
|
||||
SpawnerTierBuilder setEntities(List<EntityType> entities);
|
||||
@ -36,6 +32,7 @@ public interface SpawnerTierBuilder {
|
||||
SpawnerTierBuilder setPickupCost(double pickupCost);
|
||||
|
||||
SpawnerTierBuilder setPickDamage(short pickDamage);
|
||||
|
||||
SpawnerTierBuilder setCostEconomy(double costEconomy);
|
||||
|
||||
SpawnerTierBuilder setCostLevels(int levels);
|
||||
@ -57,4 +54,4 @@ public interface SpawnerTierBuilder {
|
||||
SpawnerTierBuilder setSpawnLimit(int spawnLimit);
|
||||
|
||||
SpawnerTier build();
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package com.craftaro.epicspawners;
|
||||
import com.craftaro.core.SongodaCore;
|
||||
import com.craftaro.core.SongodaPlugin;
|
||||
import com.craftaro.core.commands.CommandManager;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.configuration.Config;
|
||||
import com.craftaro.core.database.DataManager;
|
||||
import com.craftaro.core.gui.GuiManager;
|
||||
@ -11,12 +10,12 @@ import com.craftaro.core.hooks.EconomyManager;
|
||||
import com.craftaro.core.hooks.EntityStackerManager;
|
||||
import com.craftaro.core.hooks.HologramManager;
|
||||
import com.craftaro.core.hooks.ProtectionManager;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.third_party.org.jooq.Record;
|
||||
import com.craftaro.core.third_party.org.jooq.Result;
|
||||
import com.craftaro.core.third_party.org.jooq.impl.DSL;
|
||||
import com.craftaro.epicspawners.api.EpicSpawnersAPI;
|
||||
import com.craftaro.epicspawners.api.EpicSpawnersApi;
|
||||
import com.craftaro.epicspawners.api.boosts.types.Boosted;
|
||||
import com.craftaro.epicspawners.api.boosts.types.BoostedPlayer;
|
||||
import com.craftaro.epicspawners.api.player.PlayerData;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.PlacedSpawner;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerData;
|
||||
@ -44,7 +43,6 @@ import com.craftaro.epicspawners.listeners.InventoryListeners;
|
||||
import com.craftaro.epicspawners.listeners.SpawnerListeners;
|
||||
import com.craftaro.epicspawners.listeners.WorldListeners;
|
||||
import com.craftaro.epicspawners.lootables.LootablesManager;
|
||||
import com.craftaro.epicspawners.player.PlayerDataImpl;
|
||||
import com.craftaro.epicspawners.player.PlayerDataManagerImpl;
|
||||
import com.craftaro.epicspawners.settings.Settings;
|
||||
import com.craftaro.epicspawners.spawners.SpawnManager;
|
||||
@ -73,9 +71,6 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class EpicSpawners extends SongodaPlugin {
|
||||
|
||||
private static EpicSpawners INSTANCE;
|
||||
|
||||
private final GuiManager guiManager = new GuiManager(this);
|
||||
private SpawnManager spawnManager;
|
||||
private PlayerDataManagerImpl playerActionManager;
|
||||
@ -90,19 +85,23 @@ public class EpicSpawners extends SongodaPlugin {
|
||||
private SpawnerParticleTask particleTask;
|
||||
private SpawnerSpawnTask spawnerCustomSpawnTask;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link org.bukkit.plugin.java.JavaPlugin#getPlugin(Class)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public static EpicSpawners getInstance() {
|
||||
return INSTANCE;
|
||||
return getPlugin(EpicSpawners.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPluginLoad() {
|
||||
INSTANCE = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPluginDisable() {
|
||||
if (!spawnerManager.wasConfigModified())
|
||||
if (!this.spawnerManager.wasConfigModified()) {
|
||||
this.saveToFile();
|
||||
}
|
||||
this.particleTask.cancel();
|
||||
this.spawnerCustomSpawnTask.cancel();
|
||||
HologramManager.removeAllHolograms();
|
||||
@ -158,12 +157,12 @@ public class EpicSpawners extends SongodaPlugin {
|
||||
PluginManager pluginManager = Bukkit.getPluginManager();
|
||||
|
||||
// Listeners
|
||||
guiManager.init();
|
||||
this.guiManager.init();
|
||||
pluginManager.registerEvents(new BlockListeners(this), this);
|
||||
pluginManager.registerEvents(new EntityListeners(this), this);
|
||||
pluginManager.registerEvents(new InteractListeners(this), this);
|
||||
pluginManager.registerEvents(new InventoryListeners(), this);
|
||||
pluginManager.registerEvents(new SpawnerListeners(this), this);
|
||||
pluginManager.registerEvents(new SpawnerListeners(), this);
|
||||
pluginManager.registerEvents(new WorldListeners(this), this);
|
||||
|
||||
int timeout = Settings.AUTOSAVE.getInt() * 60 * 20;
|
||||
@ -175,13 +174,13 @@ public class EpicSpawners extends SongodaPlugin {
|
||||
this.appearanceTask = AppearanceTask.startTask(this);
|
||||
|
||||
initDatabase(Arrays.asList(new _1_InitialMigration(), new _2_AddTiers()));
|
||||
new EpicSpawnersAPI(this, new SpawnerDataBuilderImpl(""), new SpawnerTierBuilderImpl());
|
||||
new EpicSpawnersApi(this, new SpawnerDataBuilderImpl(""), new SpawnerTierBuilderImpl());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataLoad() {
|
||||
DataManager dataManager = getDataManager();
|
||||
spawnerManager.addSpawners(dataManager.loadBatch(PlacedSpawnerImpl.class, "placed_spawners"));
|
||||
this.spawnerManager.addSpawners(dataManager.loadBatch(PlacedSpawnerImpl.class, "placed_spawners"));
|
||||
//Need to load the SpawnerStacks to the loaded spawners now.
|
||||
List<SpawnerStack> stacks = dataManager.loadBatch(SpawnerStackImpl.class, "spawner_stacks");
|
||||
loadHolograms();
|
||||
@ -189,7 +188,7 @@ public class EpicSpawners extends SongodaPlugin {
|
||||
List<Boosted> boosted = new ArrayList<>();
|
||||
String prefix = dataManager.getTablePrefix();
|
||||
dataManager.getDatabaseConnector().connectDSL(dslContext -> {
|
||||
dslContext.select().from(DSL.table(prefix+"boosted_players")).fetch().forEach(record -> {
|
||||
dslContext.select().from(DSL.table(prefix + "boosted_players")).fetch().forEach(record -> {
|
||||
boosted.add(new BoostedPlayerImpl(
|
||||
UUID.fromString(record.get("player").toString()),
|
||||
Integer.parseInt(record.get("amount").toString()),
|
||||
@ -197,7 +196,7 @@ public class EpicSpawners extends SongodaPlugin {
|
||||
));
|
||||
});
|
||||
|
||||
dslContext.select().from(DSL.table(prefix+"boosted_spawners")).fetch().forEach(record -> {
|
||||
dslContext.select().from(DSL.table(prefix + "boosted_spawners")).fetch().forEach(record -> {
|
||||
Location location = new Location(
|
||||
Bukkit.getWorld(record.get("world").toString()),
|
||||
Double.parseDouble(record.get("x").toString()),
|
||||
@ -210,7 +209,7 @@ public class EpicSpawners extends SongodaPlugin {
|
||||
));
|
||||
});
|
||||
});
|
||||
boostManager.addBoosts(boosted);
|
||||
this.boostManager.addBoosts(boosted);
|
||||
|
||||
//Load entity kills
|
||||
dataManager.getDatabaseConnector().connectDSL(dslContext -> {
|
||||
@ -219,7 +218,7 @@ public class EpicSpawners extends SongodaPlugin {
|
||||
UUID uuid = UUID.fromString(record.get("player").toString());
|
||||
EntityType entityType = EntityType.valueOf(record.get("entity_type").toString());
|
||||
int amount = Integer.parseInt(record.get("count").toString());
|
||||
PlayerData playerData = playerActionManager.getPlayerData(uuid);
|
||||
PlayerData playerData = this.playerActionManager.getPlayerData(uuid);
|
||||
playerData.addKilledEntity(entityType, amount);
|
||||
});
|
||||
});
|
||||
@ -230,21 +229,26 @@ public class EpicSpawners extends SongodaPlugin {
|
||||
this.setLocale(Settings.LANGUGE_MODE.getString(), true);
|
||||
this.locale.reloadMessages();
|
||||
this.blacklistHandler.reload();
|
||||
if (spawnerManager.wasConfigModified())
|
||||
if (this.spawnerManager.wasConfigModified()) {
|
||||
this.spawnerManager.reloadFromFile();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Config> getExtraConfig() {
|
||||
return Arrays.asList(spawnerManager.getSpawnerConfig(), blacklistHandler.getBlackConfig());
|
||||
return Arrays.asList(this.spawnerManager.getSpawnerConfig(), this.blacklistHandler.getBlackConfig());
|
||||
}
|
||||
|
||||
private void loadHolograms() {
|
||||
Collection<PlacedSpawner> spawners = getSpawnerManager().getSpawners();
|
||||
if (spawners.size() == 0) return;
|
||||
if (spawners.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (PlacedSpawner spawner : spawners) {
|
||||
if (spawner.getWorld() == null) continue;
|
||||
if (spawner.getWorld() == null) {
|
||||
continue;
|
||||
}
|
||||
createHologram(spawner);
|
||||
}
|
||||
}
|
||||
@ -255,7 +259,9 @@ public class EpicSpawners extends SongodaPlugin {
|
||||
|
||||
public void createHologram(PlacedSpawner spawner) {
|
||||
// are holograms enabled?
|
||||
if (!Settings.SPAWNER_HOLOGRAMS.getBoolean() || !HologramManager.getManager().isEnabled()) return;
|
||||
if (!Settings.SPAWNER_HOLOGRAMS.getBoolean() || !HologramManager.getManager().isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// create the hologram
|
||||
HologramManager.createHologram(spawner.getHologramId(), spawner.getLocation(), getHologramName(spawner));
|
||||
@ -263,12 +269,18 @@ public class EpicSpawners extends SongodaPlugin {
|
||||
|
||||
public void updateHologram(PlacedSpawner spawner) {
|
||||
// are holograms enabled?
|
||||
if (!Settings.SPAWNER_HOLOGRAMS.getBoolean() || !HologramManager.getManager().isEnabled()) return;
|
||||
if (!Settings.SPAWNER_HOLOGRAMS.getBoolean() || !HologramManager.getManager().isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (spawner.getSpawnerStacks().isEmpty()) return;
|
||||
if (spawner.getSpawnerStacks().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// check if it is created
|
||||
if (!HologramManager.isHologramLoaded(spawner.getHologramId())) return;
|
||||
if (!HologramManager.isHologramLoaded(spawner.getHologramId())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// create the hologram
|
||||
HologramManager.updateHologram(spawner.getHologramId(), getHologramName(spawner));
|
||||
@ -276,13 +288,16 @@ public class EpicSpawners extends SongodaPlugin {
|
||||
|
||||
public String getHologramName(PlacedSpawner spawner) {
|
||||
int stackSize = spawner.getStackSize();
|
||||
if (spawner.getSpawnerStacks().isEmpty()) return null;
|
||||
if (spawner.getSpawnerStacks().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return spawner.getFirstTier().getCompiledDisplayName(spawner.getSpawnerStacks().size() > 1, stackSize).trim();
|
||||
}
|
||||
|
||||
public void processChange(Block block) {
|
||||
if (block.getType() != XMaterial.SPAWNER.parseMaterial())
|
||||
if (block.getType() != XMaterial.SPAWNER.parseMaterial()) {
|
||||
return;
|
||||
}
|
||||
PlacedSpawner spawner = getSpawnerManager().getSpawnerFromWorld(block.getLocation());
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, () ->
|
||||
updateHologram(spawner), 1L);
|
||||
@ -294,8 +309,10 @@ public class EpicSpawners extends SongodaPlugin {
|
||||
|
||||
private void enabledRecipe() {
|
||||
top:
|
||||
for (SpawnerData spawnerData : spawnerManager.getAllSpawnerData()) {
|
||||
if (!spawnerData.isCraftable()) continue;
|
||||
for (SpawnerData spawnerData : this.spawnerManager.getAllSpawnerData()) {
|
||||
if (!spawnerData.isCraftable()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String recipe = spawnerData.getRecipe();
|
||||
|
||||
@ -303,7 +320,9 @@ public class EpicSpawners extends SongodaPlugin {
|
||||
|
||||
ShapedRecipe spawnerRecipe = new ShapedRecipe(new NamespacedKey(this, "SPAWNER_RECIPE_" + type), spawnerData.getFirstTier().toItemStack());
|
||||
|
||||
if (recipe.length() != 9) continue;
|
||||
if (recipe.length() != 9) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int arrayLength = (int) Math.ceil(((recipe.length() / (double) 3)));
|
||||
String[] result = new String[arrayLength];
|
||||
@ -320,11 +339,15 @@ public class EpicSpawners extends SongodaPlugin {
|
||||
|
||||
List<String> ingredients = spawnerData.getRecipeIngredients();
|
||||
|
||||
if (ingredients.isEmpty()) continue;
|
||||
if (ingredients.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (String ingredient : ingredients) {
|
||||
try {
|
||||
if (!ingredient.contains(",")) continue top;
|
||||
if (!ingredient.contains(",")) {
|
||||
continue top;
|
||||
}
|
||||
String[] s = ingredient.split(",");
|
||||
char letter = s[0].trim().toCharArray()[0];
|
||||
String materialStr = s[1].trim();
|
||||
@ -342,8 +365,8 @@ public class EpicSpawners extends SongodaPlugin {
|
||||
}
|
||||
|
||||
spawnerRecipe.setIngredient(letter, material);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
getServer().addRecipe(spawnerRecipe);
|
||||
@ -351,38 +374,38 @@ public class EpicSpawners extends SongodaPlugin {
|
||||
}
|
||||
|
||||
public SpawnManager getSpawnManager() {
|
||||
return spawnManager;
|
||||
return this.spawnManager;
|
||||
}
|
||||
|
||||
public CommandManager getCommandManager() {
|
||||
return commandManager;
|
||||
return this.commandManager;
|
||||
}
|
||||
|
||||
public BoostManagerImpl getBoostManager() {
|
||||
return boostManager;
|
||||
return this.boostManager;
|
||||
}
|
||||
|
||||
public PlayerDataManagerImpl getPlayerDataManager() {
|
||||
return playerActionManager;
|
||||
return this.playerActionManager;
|
||||
}
|
||||
|
||||
public BlacklistHandler getBlacklistHandler() {
|
||||
return blacklistHandler;
|
||||
return this.blacklistHandler;
|
||||
}
|
||||
|
||||
public SpawnerManager getSpawnerManager() {
|
||||
return spawnerManager;
|
||||
return this.spawnerManager;
|
||||
}
|
||||
|
||||
public AppearanceTask getAppearanceTask() {
|
||||
return appearanceTask;
|
||||
return this.appearanceTask;
|
||||
}
|
||||
|
||||
public GuiManager getGuiManager() {
|
||||
return guiManager;
|
||||
return this.guiManager;
|
||||
}
|
||||
|
||||
public LootablesManager getLootablesManager() {
|
||||
return lootablesManager;
|
||||
return this.lootablesManager;
|
||||
}
|
||||
}
|
||||
|
@ -10,11 +10,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Created by songoda on 2/25/2017.
|
||||
*/
|
||||
public class BlacklistHandler {
|
||||
|
||||
private final Config blackConfig = new Config(EpicSpawners.getInstance(), "blacklist.yml");
|
||||
private final List<String> list;
|
||||
|
||||
@ -27,8 +23,9 @@ public class BlacklistHandler {
|
||||
|
||||
public boolean isBlacklisted(Player player, boolean notify) {
|
||||
if (list.contains(player.getWorld().getName().toLowerCase())) {
|
||||
if (notify)
|
||||
if (notify) {
|
||||
EpicSpawners.getInstance().getLocale().getMessage("event.block.blacklisted").sendPrefixedMessage(player);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -54,4 +51,4 @@ public class BlacklistHandler {
|
||||
blackConfig.load();
|
||||
loadBlacklistFile();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.craftaro.epicspawners.boost;
|
||||
|
||||
import com.craftaro.epicspawners.EpicSpawners;
|
||||
import com.craftaro.epicspawners.api.boosts.BoostManager;
|
||||
import com.craftaro.epicspawners.api.boosts.types.Boosted;
|
||||
import com.craftaro.epicspawners.api.boosts.types.BoostedPlayer;
|
||||
@ -17,7 +16,6 @@ import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class BoostManagerImpl implements BoostManager {
|
||||
|
||||
private final Set<Boosted> registeredBoosts = new HashSet<>();
|
||||
|
||||
@Override
|
||||
|
@ -1,12 +1,8 @@
|
||||
package com.craftaro.epicspawners.boost.types;
|
||||
|
||||
import com.craftaro.core.database.Data;
|
||||
import com.craftaro.epicspawners.api.boosts.types.Boosted;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class BoostedImpl implements Boosted {
|
||||
|
||||
private final int amountBoosted;
|
||||
private final long endTime;
|
||||
|
||||
@ -24,5 +20,4 @@ public abstract class BoostedImpl implements Boosted {
|
||||
public long getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class BoostedPlayerImpl extends BoostedImpl implements BoostedPlayer {
|
||||
|
||||
private final UUID player;
|
||||
|
||||
/**
|
||||
|
@ -4,16 +4,12 @@ import com.craftaro.core.database.Data;
|
||||
import com.craftaro.core.database.SerializedLocation;
|
||||
import com.craftaro.epicspawners.EpicSpawners;
|
||||
import com.craftaro.epicspawners.api.boosts.types.BoostedSpawner;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.PlacedSpawner;
|
||||
import com.craftaro.epicspawners.spawners.spawner.PlacedSpawnerImpl;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class BoostedSpawnerImpl extends BoostedImpl implements BoostedSpawner {
|
||||
|
||||
private final Location location;
|
||||
|
||||
/**
|
||||
|
@ -16,7 +16,6 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CommandBoost extends AbstractCommand {
|
||||
|
||||
private final EpicSpawners plugin;
|
||||
|
||||
public CommandBoost(EpicSpawners plugin) {
|
||||
|
@ -5,8 +5,6 @@ import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.epicspawners.EpicSpawners;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.PlacedSpawner;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerData;
|
||||
import com.craftaro.epicspawners.spawners.spawner.PlacedSpawnerImpl;
|
||||
import com.craftaro.epicspawners.spawners.spawner.SpawnerDataImpl;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -16,7 +14,6 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CommandChange extends AbstractCommand {
|
||||
|
||||
private final EpicSpawners plugin;
|
||||
|
||||
public CommandChange(EpicSpawners plugin) {
|
||||
@ -26,7 +23,9 @@ public class CommandChange extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
if (args.length != 1) return ReturnType.SYNTAX_ERROR;
|
||||
if (args.length != 1) {
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
}
|
||||
if (!sender.hasPermission("epicspawners.admin") && !sender.hasPermission("epicspawners.change.*") && !sender.hasPermission("epicspawners.change." + args[0].toUpperCase())) {
|
||||
plugin.getLocale().getMessage("event.general.nopermission").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
@ -50,8 +49,9 @@ public class CommandChange extends AbstractCommand {
|
||||
for (SpawnerData spawnerData : plugin.getSpawnerManager().getAllSpawnerData()) {
|
||||
String input = args[0].toUpperCase().replace("_", "").replace(" ", "");
|
||||
String compare = spawnerData.getIdentifyingName().toUpperCase().replace("_", "").replace(" ", "");
|
||||
if (input.equals(compare))
|
||||
if (input.equals(compare)) {
|
||||
data = spawnerData;
|
||||
}
|
||||
}
|
||||
|
||||
if (data == null) {
|
||||
|
@ -10,7 +10,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandEditor extends AbstractCommand {
|
||||
|
||||
private final EpicSpawners plugin;
|
||||
|
||||
public CommandEditor(EpicSpawners plugin) {
|
||||
|
@ -1,14 +1,13 @@
|
||||
package com.craftaro.epicspawners.commands;
|
||||
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerData;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerTier;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.craftaro.core.commands.AbstractCommand;
|
||||
import com.craftaro.core.utils.NumberUtils;
|
||||
import com.craftaro.core.utils.TextUtils;
|
||||
import com.craftaro.epicspawners.EpicSpawners;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerData;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerTier;
|
||||
import com.craftaro.epicspawners.settings.Settings;
|
||||
import com.craftaro.epicspawners.spawners.spawner.SpawnerDataImpl;
|
||||
import com.google.common.collect.Iterables;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -23,7 +22,6 @@ import java.util.Random;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CommandGive extends AbstractCommand {
|
||||
|
||||
private final EpicSpawners plugin;
|
||||
|
||||
public CommandGive(EpicSpawners plugin) {
|
||||
@ -46,16 +44,18 @@ public class CommandGive extends AbstractCommand {
|
||||
for (SpawnerData spawnerData : plugin.getSpawnerManager().getAllSpawnerData()) {
|
||||
String input = args[1].toUpperCase().replace("_", "").replace(" ", "");
|
||||
String compare = spawnerData.getIdentifyingName().toUpperCase().replace("_", "").replace(" ", "");
|
||||
if (input.equals(compare))
|
||||
if (input.equals(compare)) {
|
||||
data = spawnerData;
|
||||
}
|
||||
}
|
||||
|
||||
if (data == null && !args[1].equalsIgnoreCase("random")) {
|
||||
plugin.getLocale().newMessage("&7The entity Type &6" + args[1] + " &7does not exist. Try one of these:").sendPrefixedMessage(sender);
|
||||
StringBuilder list = new StringBuilder();
|
||||
|
||||
for (SpawnerData spawnerData : plugin.getSpawnerManager().getAllSpawnerData())
|
||||
for (SpawnerData spawnerData : plugin.getSpawnerManager().getAllSpawnerData()) {
|
||||
list.append(spawnerData.getIdentifyingName().toUpperCase().replace(" ", "_")).append("&7, &6");
|
||||
}
|
||||
|
||||
sender.sendMessage(TextUtils.formatText("&6" + list));
|
||||
return ReturnType.FAILURE;
|
||||
@ -74,8 +74,9 @@ public class CommandGive extends AbstractCommand {
|
||||
|
||||
SpawnerTier tier = data.getFirstTier();
|
||||
SpawnerTier foundTier = data.getTier(args[2].trim());
|
||||
if (foundTier != null)
|
||||
if (foundTier != null) {
|
||||
tier = foundTier;
|
||||
}
|
||||
|
||||
if (args.length == 3) {
|
||||
giveSpawner(args[0], tier, 1, 1);
|
||||
@ -85,20 +86,21 @@ public class CommandGive extends AbstractCommand {
|
||||
int amount;
|
||||
int stackSize = 1;
|
||||
|
||||
if (!NumberUtils.isInt(args[3])) {
|
||||
plugin.getLocale().newMessage("&6" + args[3] + "&7 is not a number.").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
} else {
|
||||
amount = Integer.parseInt(args[3]);
|
||||
}
|
||||
if (!NumberUtils.isInt(args[3])) {
|
||||
plugin.getLocale().newMessage("&6" + args[3] + "&7 is not a number.").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
} else {
|
||||
amount = Integer.parseInt(args[3]);
|
||||
}
|
||||
|
||||
if (args.length > 4)
|
||||
if (args.length > 4) {
|
||||
if (!NumberUtils.isInt(args[4])) {
|
||||
plugin.getLocale().newMessage("&6" + args[4] + "&7 is not a number.").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
} else {
|
||||
stackSize = Integer.parseInt(args[4]);
|
||||
}
|
||||
}
|
||||
|
||||
if (stackSize > Settings.SPAWNERS_MAX.getInt()) {
|
||||
plugin.getLocale().newMessage("&7The stack size &6" + stackSize + "&7 is above this spawner types maximum.").sendPrefixedMessage(sender);
|
||||
@ -141,11 +143,14 @@ public class CommandGive extends AbstractCommand {
|
||||
for (SpawnerData spawnerData : plugin.getSpawnerManager().getAllSpawnerData()) {
|
||||
String input = args[1].toUpperCase().replace("_", "").replace(" ", "");
|
||||
String compare = spawnerData.getIdentifyingName().toUpperCase().replace("_", "").replace(" ", "");
|
||||
if (input.equals(compare))
|
||||
if (input.equals(compare)) {
|
||||
data = spawnerData;
|
||||
}
|
||||
}
|
||||
|
||||
if (data == null) return Collections.emptyList();
|
||||
if (data == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return data.getTiers().stream()
|
||||
.map(spawnerTier -> spawnerTier.getIdentifyingName().replace(" ", "_"))
|
||||
.collect(Collectors.toList());
|
||||
|
@ -8,7 +8,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandReload extends AbstractCommand {
|
||||
|
||||
private final EpicSpawners plugin;
|
||||
|
||||
public CommandReload(EpicSpawners plugin) {
|
||||
|
@ -10,7 +10,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandSettings extends AbstractCommand {
|
||||
|
||||
private final EpicSpawners plugin;
|
||||
|
||||
public CommandSettings(EpicSpawners plugin) {
|
||||
|
@ -11,7 +11,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandSpawn extends AbstractCommand {
|
||||
|
||||
private final EpicSpawners plugin;
|
||||
|
||||
public CommandSpawn(EpicSpawners plugin) {
|
||||
@ -26,12 +25,12 @@ public class CommandSpawn extends AbstractCommand {
|
||||
Block block = player.getTargetBlock(null, 200);
|
||||
|
||||
if (XMaterial.matchXMaterial(block.getType().name()).get() != XMaterial.SPAWNER) {
|
||||
plugin.getLocale().newMessage("&cThat is not a spawner...").sendPrefixedMessage(player);
|
||||
this.plugin.getLocale().newMessage("&cThat is not a spawner...").sendPrefixedMessage(player);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
plugin.getSpawnerManager().getSpawnerFromWorld(block.getLocation()).spawn();
|
||||
plugin.getLocale().newMessage("&aSpawning successful.").sendPrefixedMessage(player);
|
||||
this.plugin.getSpawnerManager().getSpawnerFromWorld(block.getLocation()).spawn();
|
||||
this.plugin.getLocale().newMessage("&aSpawning successful.").sendPrefixedMessage(player);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandSpawnerShop extends AbstractCommand {
|
||||
|
||||
private final EpicSpawners plugin;
|
||||
|
||||
public CommandSpawnerShop(EpicSpawners plugin) {
|
||||
@ -20,7 +19,7 @@ public class CommandSpawnerShop extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
plugin.getGuiManager().showGUI((Player) sender, new SpawnerShopGui(plugin, (Player) sender));
|
||||
this.plugin.getGuiManager().showGUI((Player) sender, new SpawnerShopGui(this.plugin, (Player) sender));
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandSpawnerStats extends AbstractCommand {
|
||||
|
||||
private final EpicSpawners plugin;
|
||||
|
||||
public CommandSpawnerStats(EpicSpawners plugin) {
|
||||
@ -22,12 +21,12 @@ public class CommandSpawnerStats extends AbstractCommand {
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
Player player = (Player) sender;
|
||||
|
||||
if (plugin.getPlayerDataManager().getPlayerData(player).getEntityKills().size() == 0) {
|
||||
plugin.getLocale().getMessage("interface.spawnerstats.nokills").sendPrefixedMessage(player);
|
||||
if (this.plugin.getPlayerDataManager().getPlayerData(player).getEntityKills().isEmpty()) {
|
||||
this.plugin.getLocale().getMessage("interface.spawnerstats.nokills").sendPrefixedMessage(player);
|
||||
return AbstractCommand.ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
plugin.getGuiManager().showGUI(player, new SpawnerStatsGui(plugin, player));
|
||||
this.plugin.getGuiManager().showGUI(player, new SpawnerStatsGui(this.plugin, player));
|
||||
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
@ -2,22 +2,18 @@ package com.craftaro.epicspawners.database.migrations;
|
||||
|
||||
import com.craftaro.core.database.DataMigration;
|
||||
import com.craftaro.core.database.DatabaseConnector;
|
||||
import com.craftaro.core.database.MySQLConnector;
|
||||
import com.craftaro.epicspawners.EpicSpawners;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
public class _1_InitialMigration extends DataMigration {
|
||||
|
||||
public _1_InitialMigration() {
|
||||
super(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void migrate(DatabaseConnector databaseConnector, String tablePrefix) throws SQLException {
|
||||
|
||||
Connection connection = databaseConnector.getConnection();
|
||||
|
||||
// Create spawners table
|
||||
@ -74,5 +70,4 @@ public class _1_InitialMigration extends DataMigration {
|
||||
|
||||
connection.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package com.craftaro.epicspawners.database.migrations;
|
||||
import com.craftaro.core.database.DataMigration;
|
||||
import com.craftaro.core.database.DatabaseConnector;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
|
@ -1,19 +1,18 @@
|
||||
package com.craftaro.epicspawners.gui;
|
||||
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.gui.Gui;
|
||||
import com.craftaro.core.gui.GuiUtils;
|
||||
import com.craftaro.core.lootables.gui.GuiLootableEditor;
|
||||
import com.craftaro.core.lootables.loot.LootManager;
|
||||
import com.craftaro.core.lootables.loot.Lootable;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.utils.ItemUtils;
|
||||
import com.craftaro.epicspawners.EpicSpawners;
|
||||
import com.craftaro.epicspawners.settings.Settings;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerTier;
|
||||
import com.craftaro.epicspawners.settings.Settings;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class EditorDropsGui extends Gui {
|
||||
|
||||
private final EpicSpawners plugin;
|
||||
private final SpawnerTier spawnerTier;
|
||||
|
||||
@ -38,30 +37,31 @@ public class EditorDropsGui extends Gui {
|
||||
setTitle(spawnerTier.getGuiTitle());
|
||||
|
||||
setButton(8, GuiUtils.createButtonItem(ItemUtils.getCustomHead("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23"),
|
||||
plugin.getLocale().getMessage("general.nametag.back").getMessage()),
|
||||
(event) -> guiManager.showGUI(event.player, back));
|
||||
plugin.getLocale().getMessage("general.nametag.back").getMessage()),
|
||||
(event) -> this.guiManager.showGUI(event.player, back));
|
||||
|
||||
paint();
|
||||
}
|
||||
|
||||
public void paint() {
|
||||
LootManager lootManager = plugin.getLootablesManager().getLootManager();
|
||||
LootManager lootManager = this.plugin.getLootablesManager().getLootManager();
|
||||
|
||||
setButton(1, 3, GuiUtils.createButtonItem(XMaterial.BARRIER, "Remove & Reset Custom Drops"),
|
||||
(event) -> {
|
||||
lootManager.removeLootable(spawnerTier.getFullyIdentifyingName());
|
||||
lootManager.removeLootable(this.spawnerTier.getFullyIdentifyingName());
|
||||
paint();
|
||||
});
|
||||
|
||||
boolean dropExists = lootManager.getRegisteredLootables().containsKey(spawnerTier.getFullyIdentifyingName());
|
||||
boolean dropExists = lootManager.getRegisteredLootables().containsKey(this.spawnerTier.getFullyIdentifyingName());
|
||||
|
||||
setButton(1, 5, GuiUtils.createButtonItem(XMaterial.LIME_DYE, dropExists ? "Edit Drops" : "Create & Enable Custom Drops"),
|
||||
(event) -> {
|
||||
if (!dropExists)
|
||||
lootManager.addLootable(new Lootable(spawnerTier.getFullyIdentifyingName()));
|
||||
Lootable lootable = lootManager.getRegisteredLootables().get(spawnerTier.getFullyIdentifyingName());
|
||||
plugin.getGuiManager().showGUI(event.player,
|
||||
new GuiLootableEditor(plugin.getLootablesManager().getLootManager(), lootable, this));
|
||||
if (!dropExists) {
|
||||
lootManager.addLootable(new Lootable(this.spawnerTier.getFullyIdentifyingName()));
|
||||
}
|
||||
Lootable lootable = lootManager.getRegisteredLootables().get(this.spawnerTier.getFullyIdentifyingName());
|
||||
this.plugin.getGuiManager().showGUI(event.player,
|
||||
new GuiLootableEditor(this.plugin.getLootablesManager().getLootManager(), lootable, this));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,16 @@
|
||||
package com.craftaro.epicspawners.gui;
|
||||
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.gui.AnvilGui;
|
||||
import com.craftaro.core.gui.Gui;
|
||||
import com.craftaro.core.gui.GuiUtils;
|
||||
import com.craftaro.core.input.ChatPrompt;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.utils.PlayerUtils;
|
||||
import com.craftaro.core.utils.TextUtils;
|
||||
import com.craftaro.epicspawners.EpicSpawners;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerTier;
|
||||
import com.craftaro.epicspawners.settings.Settings;
|
||||
import com.craftaro.epicspawners.api.utils.HeadUtils;
|
||||
import com.craftaro.epicspawners.settings.Settings;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
@ -23,12 +23,11 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class EditorEditGui extends Gui {
|
||||
|
||||
private final EpicSpawners plugin;
|
||||
private final EditType editType;
|
||||
|
||||
private final Gui back;
|
||||
private SpawnerTier spawnerTier;
|
||||
private final SpawnerTier spawnerTier;
|
||||
|
||||
public EditorEditGui(EpicSpawners plugin, Gui back, SpawnerTier spawnerTier, EditType editType) {
|
||||
super(6);
|
||||
@ -46,10 +45,11 @@ public class EditorEditGui extends Gui {
|
||||
|
||||
public void paint() {
|
||||
reset();
|
||||
if (editType == EditType.ITEM || editType == EditType.BLOCK)
|
||||
if (this.editType == EditType.ITEM || this.editType == EditType.BLOCK) {
|
||||
setUnlockedRange(10, 25);
|
||||
unlockedCells.remove(17);
|
||||
unlockedCells.remove(27);
|
||||
}
|
||||
this.unlockedCells.remove(17);
|
||||
this.unlockedCells.remove(27);
|
||||
|
||||
// decorate the edges
|
||||
ItemStack glass2 = GuiUtils.getBorderItem(Settings.GLASS_TYPE_2.getMaterial(XMaterial.BLUE_STAINED_GLASS_PANE));
|
||||
@ -76,50 +76,51 @@ public class EditorEditGui extends Gui {
|
||||
setItem(52, glass2);
|
||||
setItem(53, glass2);
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(plugin, () -> {
|
||||
Bukkit.getScheduler().runTaskLater(this.plugin, () -> {
|
||||
int num = 9;
|
||||
for (int i = 0; i < 14; i++) {
|
||||
num++;
|
||||
if (num == 17)
|
||||
if (num == 17) {
|
||||
num = num + 2;
|
||||
}
|
||||
|
||||
switch (editType) {
|
||||
switch (this.editType) {
|
||||
case ITEM:
|
||||
if (i >= spawnerTier.getItems().size()) {
|
||||
if (i >= this.spawnerTier.getItems().size()) {
|
||||
setItem(num, null);
|
||||
continue;
|
||||
}
|
||||
setItem(num, spawnerTier.getItems().get(i));
|
||||
setItem(num, this.spawnerTier.getItems().get(i));
|
||||
break;
|
||||
case BLOCK:
|
||||
if (i >= spawnerTier.getBlocks().size()) {
|
||||
if (i >= this.spawnerTier.getBlocks().size()) {
|
||||
setItem(num, null);
|
||||
continue;
|
||||
}
|
||||
setItem(num, spawnerTier.getBlocks().get(i).parseItem());
|
||||
setItem(num, this.spawnerTier.getBlocks().get(i).parseItem());
|
||||
break;
|
||||
case ENTITY: {
|
||||
if (i >= spawnerTier.getEntities().size()) {
|
||||
if (i >= this.spawnerTier.getEntities().size()) {
|
||||
setItem(num, null);
|
||||
continue;
|
||||
}
|
||||
ItemStack item = HeadUtils.getTexturedSkull(
|
||||
plugin.getSpawnerManager().getSpawnerData(spawnerTier.getEntities().get(i)));
|
||||
this.plugin.getSpawnerManager().getSpawnerData(this.spawnerTier.getEntities().get(i)));
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(TextUtils.formatText("&e" + spawnerTier.getEntities().get(i).name()));
|
||||
meta.setDisplayName(TextUtils.formatText("&e" + this.spawnerTier.getEntities().get(i).name()));
|
||||
item.setItemMeta(meta);
|
||||
int numFinal = num;
|
||||
setButton(num, item, event -> setItem(numFinal, null));
|
||||
}
|
||||
break;
|
||||
case COMMAND: {
|
||||
if (i >= spawnerTier.getCommands().size()) {
|
||||
if (i >= this.spawnerTier.getCommands().size()) {
|
||||
setItem(num, null);
|
||||
continue;
|
||||
}
|
||||
ItemStack parseStack = new ItemStack(Material.PAPER, 1);
|
||||
ItemMeta meta = parseStack.getItemMeta();
|
||||
meta.setDisplayName(TextUtils.formatText("&a/" + spawnerTier.getCommands().get(i)));
|
||||
meta.setDisplayName(TextUtils.formatText("&a/" + this.spawnerTier.getCommands().get(i)));
|
||||
parseStack.setItemMeta(meta);
|
||||
int numFinal = num;
|
||||
setButton(num, parseStack, event -> setItem(numFinal, null));
|
||||
@ -133,13 +134,13 @@ public class EditorEditGui extends Gui {
|
||||
}, 1L);
|
||||
|
||||
setButton(0, GuiUtils.createButtonItem(XMaterial.OAK_DOOR,
|
||||
TextUtils.formatText(plugin.getLocale().getMessage("general.nametag.back").getMessage())),
|
||||
(event) -> guiManager.showGUI(event.player, back));
|
||||
TextUtils.formatText(this.plugin.getLocale().getMessage("general.nametag.back").getMessage())),
|
||||
(event) -> this.guiManager.showGUI(event.player, this.back));
|
||||
|
||||
if (editType != EditType.ITEM && editType != EditType.BLOCK) {
|
||||
if (this.editType != EditType.ITEM && this.editType != EditType.BLOCK) {
|
||||
ItemStack add;
|
||||
String addName;
|
||||
if (editType == EditType.COMMAND) {
|
||||
if (this.editType == EditType.COMMAND) {
|
||||
add = new ItemStack(Material.PAPER);
|
||||
addName = "&6Add Command";
|
||||
} else {
|
||||
@ -149,19 +150,19 @@ public class EditorEditGui extends Gui {
|
||||
|
||||
setButton(39, GuiUtils.createButtonItem(add, TextUtils.formatText(addName)), event -> {
|
||||
Player player = event.player;
|
||||
if (editType == EditType.COMMAND) {
|
||||
if (this.editType == EditType.COMMAND) {
|
||||
PlayerUtils.sendMessages(player, TextUtils.formatText("&7Please Type a command. Example: &6eco give @p 1000&7.",
|
||||
"&7You can use @X @Y and @Z for random X Y and Z coordinates around the spawner.",
|
||||
"&7If you need the world name, you can use @W for the current world.",
|
||||
"&7@n will execute the command for the person who originally placed the spawner.",
|
||||
"&7If you're getting command output try &6/gamerule sendCommandFeedback false&7.",
|
||||
"&7do not include a &a/"));
|
||||
ChatPrompt.showPrompt(plugin, player, evnt -> {
|
||||
List<String> commands = new ArrayList<>(spawnerTier.getCommands());
|
||||
commands.add(evnt.getMessage());
|
||||
spawnerTier.setCommands(commands);
|
||||
paint();
|
||||
}).setOnClose(() -> guiManager.showGUI(player, this))
|
||||
ChatPrompt.showPrompt(this.plugin, player, evnt -> {
|
||||
List<String> commands = new ArrayList<>(this.spawnerTier.getCommands());
|
||||
commands.add(evnt.getMessage());
|
||||
this.spawnerTier.setCommands(commands);
|
||||
paint();
|
||||
}).setOnClose(() -> this.guiManager.showGUI(player, this))
|
||||
.setTimeOut(player, 20L * 15L);
|
||||
} else {
|
||||
AnvilGui gui = new AnvilGui(player, this);
|
||||
@ -169,70 +170,69 @@ public class EditorEditGui extends Gui {
|
||||
gui.setAction(evnt -> {
|
||||
try {
|
||||
EntityType eType = EntityType.valueOf(gui.getInputText().trim().toUpperCase());
|
||||
List<EntityType> entities = new ArrayList<>(spawnerTier.getEntities());
|
||||
List<EntityType> entities = new ArrayList<>(this.spawnerTier.getEntities());
|
||||
entities.add(eType);
|
||||
spawnerTier.setEntities(entities);
|
||||
this.spawnerTier.setEntities(entities);
|
||||
player.closeInventory();
|
||||
} catch (Exception ex) {
|
||||
player.sendMessage("That is not a correct EntityType. Please try again..");
|
||||
}
|
||||
}).setOnClose(e -> paint());
|
||||
plugin.getGuiManager().showGUI(player, gui);
|
||||
this.plugin.getGuiManager().showGUI(player, gui);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
setButton(editType != EditType.ITEM ? 41 : 49,
|
||||
setButton(this.editType != EditType.ITEM ? 41 : 49,
|
||||
GuiUtils.createButtonItem(XMaterial.REDSTONE, TextUtils.formatText("&aSave")),
|
||||
event -> save(event.player, getItems(event.player)));
|
||||
|
||||
}
|
||||
|
||||
private List<ItemStack> getItems(Player player) {
|
||||
ItemStack[] items2 = player.getOpenInventory().getTopInventory().getContents();
|
||||
//items2 = Arrays.copyOf(items2, items2.length - 9);
|
||||
|
||||
List<ItemStack> items = new ArrayList<>();
|
||||
|
||||
int num = 9;
|
||||
for (int i = 0; i < 14; i++) {
|
||||
num++;
|
||||
if (num == 17)
|
||||
if (num == 17) {
|
||||
num = num + 2;
|
||||
}
|
||||
ItemStack item = getItem(num);
|
||||
if (item != null)
|
||||
if (item != null) {
|
||||
items.add(getItem(num));
|
||||
}
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
private void save(Player player, List<ItemStack> items) {
|
||||
if (editType == EditType.ITEM) {
|
||||
spawnerTier.setItems(items);
|
||||
} else if (editType == EditType.BLOCK) {
|
||||
if (this.editType == EditType.ITEM) {
|
||||
this.spawnerTier.setItems(items);
|
||||
} else if (this.editType == EditType.BLOCK) {
|
||||
List<XMaterial> list = new ArrayList<>();
|
||||
for (ItemStack item : items) {
|
||||
XMaterial material = XMaterial.matchXMaterial(item);
|
||||
list.add(material);
|
||||
}
|
||||
spawnerTier.setBlocks(list);
|
||||
} else if (editType == EditType.ENTITY) {
|
||||
this.spawnerTier.setBlocks(list);
|
||||
} else if (this.editType == EditType.ENTITY) {
|
||||
List<EntityType> list = new ArrayList<>();
|
||||
for (ItemStack item : items) {
|
||||
EntityType entityType = EntityType.valueOf(ChatColor.stripColor(item.getItemMeta().getDisplayName()).toUpperCase().replace(" ", "_"));
|
||||
list.add(entityType);
|
||||
}
|
||||
spawnerTier.setEntities(list);
|
||||
} else if (editType == EditType.COMMAND) {
|
||||
this.spawnerTier.setEntities(list);
|
||||
} else if (this.editType == EditType.COMMAND) {
|
||||
List<String> list = new ArrayList<>();
|
||||
for (ItemStack item : items) {
|
||||
String name = ChatColor.stripColor(item.getItemMeta().getDisplayName()).substring(1);
|
||||
list.add(name);
|
||||
}
|
||||
spawnerTier.setCommands(list);
|
||||
this.spawnerTier.setCommands(list);
|
||||
}
|
||||
plugin.getLocale().newMessage("&7Spawner Saved.").sendPrefixedMessage(player);
|
||||
spawnerTier.reloadSpawnMethods();
|
||||
this.plugin.getLocale().newMessage("&7Spawner Saved.").sendPrefixedMessage(player);
|
||||
this.spawnerTier.reloadSpawnMethods();
|
||||
}
|
||||
|
||||
public enum EditType {
|
||||
@ -248,8 +248,7 @@ public class EditorEditGui extends Gui {
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,20 +1,19 @@
|
||||
package com.craftaro.epicspawners.gui;
|
||||
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.gui.AnvilGui;
|
||||
import com.craftaro.core.gui.Gui;
|
||||
import com.craftaro.core.gui.GuiUtils;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.utils.NumberUtils;
|
||||
import com.craftaro.core.utils.PlayerUtils;
|
||||
import com.craftaro.core.utils.TextUtils;
|
||||
import com.craftaro.epicspawners.EpicSpawners;
|
||||
import com.craftaro.epicspawners.settings.Settings;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerTier;
|
||||
import com.craftaro.epicspawners.settings.Settings;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class EditorGeneralGui extends Gui {
|
||||
|
||||
private final EpicSpawners plugin;
|
||||
private final Gui back;
|
||||
private final SpawnerTier spawnerTier;
|
||||
@ -49,22 +48,22 @@ public class EditorGeneralGui extends Gui {
|
||||
mirrorFill(0, 1, true, true, glass2);
|
||||
|
||||
setButton(0, GuiUtils.createButtonItem(XMaterial.OAK_DOOR,
|
||||
plugin.getLocale().getMessage("general.nametag.back").getMessage()),
|
||||
(event) -> guiManager.showGUI(event.player, back));
|
||||
this.plugin.getLocale().getMessage("general.nametag.back").getMessage()),
|
||||
(event) -> this.guiManager.showGUI(event.player, this.back));
|
||||
|
||||
setButton(22, GuiUtils.createButtonItem(XMaterial.FIRE_CHARGE, TextUtils.formatText("&c&lSpawn On Fire",
|
||||
"&7Currently: &a" + spawnerTier.isSpawnOnFire(),
|
||||
"&7If this is true this spawner",
|
||||
"&7will spawn entities on fire.")),
|
||||
"&7Currently: &a" + this.spawnerTier.isSpawnOnFire(),
|
||||
"&7If this is true this spawner",
|
||||
"&7will spawn entities on fire.")),
|
||||
event -> {
|
||||
spawnerTier.setSpawnOnFire(!spawnerTier.isSpawnOnFire());
|
||||
this.spawnerTier.setSpawnOnFire(!this.spawnerTier.isSpawnOnFire());
|
||||
paint();
|
||||
});
|
||||
|
||||
setButton(20, GuiUtils.createButtonItem(XMaterial.SUNFLOWER, TextUtils.formatText("&6&lEconomy cost",
|
||||
"&7Currently: &a" + spawnerTier.getCostEconomy(),
|
||||
"&7This is the economy cost",
|
||||
"&7to upgrade or sell this spawner.")),
|
||||
"&7Currently: &a" + this.spawnerTier.getCostEconomy(),
|
||||
"&7This is the economy cost",
|
||||
"&7to upgrade or sell this spawner.")),
|
||||
event -> {
|
||||
Player player = event.player;
|
||||
AnvilGui gui = new AnvilGui(player, this);
|
||||
@ -72,23 +71,23 @@ public class EditorGeneralGui extends Gui {
|
||||
gui.setAction(evnt -> {
|
||||
String msg = gui.getInputText().trim();
|
||||
if (NumberUtils.isNumeric(msg)) {
|
||||
spawnerTier.setCostEconomy(Double.parseDouble(msg));
|
||||
this.spawnerTier.setCostEconomy(Double.parseDouble(msg));
|
||||
player.closeInventory();
|
||||
} else {
|
||||
player.sendMessage(TextUtils.formatText("&CYou must enter a number."));
|
||||
}
|
||||
}).setOnClose(e -> paint());
|
||||
guiManager.showGUI(player, gui);
|
||||
this.guiManager.showGUI(player, gui);
|
||||
|
||||
PlayerUtils.sendMessages(player, TextUtils.formatText("&7Enter a custom eco cost for " + spawnerTier.getIdentifyingName() + "&7.",
|
||||
PlayerUtils.sendMessages(player, TextUtils.formatText("&7Enter a custom eco cost for " + this.spawnerTier.getIdentifyingName() + "&7.",
|
||||
"&7Use &60 &7to use the default cost.",
|
||||
"&7Example: &619.99&7."));
|
||||
});
|
||||
|
||||
setButton(24, GuiUtils.createButtonItem(XMaterial.EXPERIENCE_BOTTLE, TextUtils.formatText("&5&lLevels cost",
|
||||
"&7Currently: &a" + spawnerTier.getCostLevels(),
|
||||
"&7This is the custom levels cost",
|
||||
"&7to upgrade this spawner.")),
|
||||
"&7Currently: &a" + this.spawnerTier.getCostLevels(),
|
||||
"&7This is the custom levels cost",
|
||||
"&7to upgrade this spawner.")),
|
||||
event -> {
|
||||
Player player = event.player;
|
||||
AnvilGui gui = new AnvilGui(player, this);
|
||||
@ -96,24 +95,24 @@ public class EditorGeneralGui extends Gui {
|
||||
gui.setAction(evnt -> {
|
||||
String msg = gui.getInputText().trim();
|
||||
if (NumberUtils.isInt(msg)) {
|
||||
spawnerTier.setCostLevels(Integer.parseInt(msg));
|
||||
this.spawnerTier.setCostLevels(Integer.parseInt(msg));
|
||||
player.closeInventory();
|
||||
} else {
|
||||
player.sendMessage(TextUtils.formatText("&CYou must enter a number."));
|
||||
}
|
||||
}).setOnClose(e -> paint());
|
||||
plugin.getGuiManager().showGUI(player, gui);
|
||||
this.plugin.getGuiManager().showGUI(player, gui);
|
||||
|
||||
PlayerUtils.sendMessages(player, TextUtils.formatText("&7Enter a custom levels cost for " + spawnerTier.getIdentifyingName() + "&7.",
|
||||
PlayerUtils.sendMessages(player, TextUtils.formatText("&7Enter a custom levels cost for " + this.spawnerTier.getIdentifyingName() + "&7.",
|
||||
"&7Use &60 &7to use the default cost.",
|
||||
"&7Example: &625&7."));
|
||||
});
|
||||
|
||||
setButton(30, GuiUtils.createButtonItem(XMaterial.EXPERIENCE_BOTTLE, TextUtils.formatText("&5&lKill Drop Goal",
|
||||
"&7Currently: &a" + spawnerTier.getSpawnerData().getKillDropGoal(),
|
||||
"&7If this is set to anything",
|
||||
"&7but 0 the default kill goal",
|
||||
"&7will be adjusted for this spawner.")),
|
||||
"&7Currently: &a" + this.spawnerTier.getSpawnerData().getKillDropGoal(),
|
||||
"&7If this is set to anything",
|
||||
"&7but 0 the default kill goal",
|
||||
"&7will be adjusted for this spawner.")),
|
||||
event -> {
|
||||
Player player = event.player;
|
||||
AnvilGui gui = new AnvilGui(player, this);
|
||||
@ -121,24 +120,24 @@ public class EditorGeneralGui extends Gui {
|
||||
gui.setAction(evnt -> {
|
||||
String msg = gui.getInputText().trim();
|
||||
if (NumberUtils.isInt(msg)) {
|
||||
spawnerTier.getSpawnerData().setKillDropGoal(Integer.parseInt(msg));
|
||||
this.spawnerTier.getSpawnerData().setKillDropGoal(Integer.parseInt(msg));
|
||||
player.closeInventory();
|
||||
} else {
|
||||
player.sendMessage(TextUtils.formatText("&CYou must enter a number."));
|
||||
}
|
||||
}).setOnClose(e -> paint());
|
||||
plugin.getGuiManager().showGUI(player, gui);
|
||||
this.plugin.getGuiManager().showGUI(player, gui);
|
||||
|
||||
PlayerUtils.sendMessages(player, TextUtils.formatText("&7Enter a custom goal for " + spawnerTier.getIdentifyingName() + "&7.",
|
||||
PlayerUtils.sendMessages(player, TextUtils.formatText("&7Enter a custom goal for " + this.spawnerTier.getIdentifyingName() + "&7.",
|
||||
"&7Use &60 &7to use the default price.",
|
||||
"&7Example: &35&6."));
|
||||
});
|
||||
|
||||
setButton(31, GuiUtils.createButtonItem(XMaterial.EXPERIENCE_BOTTLE, TextUtils.formatText("&5&lKill Drop Chance",
|
||||
"&7Currently: &a" + spawnerTier.getSpawnerData().getKillDropGoal(),
|
||||
"&7If this is set to anything",
|
||||
"&7but 0 the default kill chance",
|
||||
"&7will be adjusted for this spawner.")),
|
||||
"&7Currently: &a" + this.spawnerTier.getSpawnerData().getKillDropGoal(),
|
||||
"&7If this is set to anything",
|
||||
"&7but 0 the default kill chance",
|
||||
"&7will be adjusted for this spawner.")),
|
||||
event -> {
|
||||
Player player = event.player;
|
||||
AnvilGui gui = new AnvilGui(player, this);
|
||||
@ -146,24 +145,24 @@ public class EditorGeneralGui extends Gui {
|
||||
gui.setAction(evnt -> {
|
||||
String msg = gui.getInputText().trim();
|
||||
if (NumberUtils.isInt(msg)) {
|
||||
spawnerTier.getSpawnerData().setKillDropGoal(Integer.parseInt(msg));
|
||||
this.spawnerTier.getSpawnerData().setKillDropGoal(Integer.parseInt(msg));
|
||||
player.closeInventory();
|
||||
} else {
|
||||
player.sendMessage(TextUtils.formatText("&CYou must enter a number."));
|
||||
}
|
||||
}).setOnClose(e -> paint());
|
||||
plugin.getGuiManager().showGUI(player, gui);
|
||||
this.plugin.getGuiManager().showGUI(player, gui);
|
||||
|
||||
PlayerUtils.sendMessages(player, TextUtils.formatText("&7Enter a custom goal for " + spawnerTier.getIdentifyingName() + "&7.",
|
||||
PlayerUtils.sendMessages(player, TextUtils.formatText("&7Enter a custom goal for " + this.spawnerTier.getIdentifyingName() + "&7.",
|
||||
"&7Use &60 &7to use the default price.",
|
||||
"&7Example: &35&6."));
|
||||
});
|
||||
|
||||
setButton(32, GuiUtils.createButtonItem(XMaterial.DIAMOND, TextUtils.formatText("&b&lPickup Cost",
|
||||
"&7Currently: &a" + spawnerTier.getPickupCost(),
|
||||
"&7Setting this to anything but 0",
|
||||
"&7will allow you to charge players",
|
||||
"&7for breaking this type of spawner.")),
|
||||
"&7Currently: &a" + this.spawnerTier.getPickupCost(),
|
||||
"&7Setting this to anything but 0",
|
||||
"&7will allow you to charge players",
|
||||
"&7for breaking this type of spawner.")),
|
||||
event -> {
|
||||
Player player = event.player;
|
||||
AnvilGui gui = new AnvilGui(player, this);
|
||||
@ -171,36 +170,36 @@ public class EditorGeneralGui extends Gui {
|
||||
gui.setAction(evnt -> {
|
||||
String msg = gui.getInputText().trim();
|
||||
if (NumberUtils.isNumeric(msg)) {
|
||||
spawnerTier.setPickupCost(Double.parseDouble(msg));
|
||||
this.spawnerTier.setPickupCost(Double.parseDouble(msg));
|
||||
player.closeInventory();
|
||||
} else {
|
||||
player.sendMessage(TextUtils.formatText("&CYou must enter a number."));
|
||||
}
|
||||
}).setOnClose(e -> paint());
|
||||
plugin.getGuiManager().showGUI(player, gui);
|
||||
this.plugin.getGuiManager().showGUI(player, gui);
|
||||
|
||||
PlayerUtils.sendMessages(player, TextUtils.formatText("&7Enter a pickup cost for " + spawnerTier.getIdentifyingName() + "&7.",
|
||||
PlayerUtils.sendMessages(player, TextUtils.formatText("&7Enter a pickup cost for " + this.spawnerTier.getIdentifyingName() + "&7.",
|
||||
"&7Use &60 &7to disable.",
|
||||
"&7Example: &719.99&6.",
|
||||
"&7Example: &625&7."));
|
||||
});
|
||||
|
||||
setButton(40, GuiUtils.createButtonItem(XMaterial.CLOCK, TextUtils.formatText("&6&lTick Rate",
|
||||
"&7Currently: &a" + spawnerTier.getTickRate(),
|
||||
"&7This is the default tick rate",
|
||||
"&7that your spawner will use",
|
||||
"&7to create its delay with.")),
|
||||
"&7Currently: &a" + this.spawnerTier.getTickRate(),
|
||||
"&7This is the default tick rate",
|
||||
"&7that your spawner will use",
|
||||
"&7to create its delay with.")),
|
||||
event -> {
|
||||
Player player = event.player;
|
||||
AnvilGui gui = new AnvilGui(player, this);
|
||||
gui.setTitle("Goal: Ex. 800:200");
|
||||
gui.setAction(evnt -> {
|
||||
spawnerTier.setTickRate(gui.getInputText().trim());
|
||||
this.spawnerTier.setTickRate(gui.getInputText().trim());
|
||||
player.closeInventory();
|
||||
}).setOnClose(e -> paint());
|
||||
plugin.getGuiManager().showGUI(player, gui);
|
||||
this.plugin.getGuiManager().showGUI(player, gui);
|
||||
|
||||
PlayerUtils.sendMessages(player, TextUtils.formatText("&7Enter a tick rate min and max for " + spawnerTier.getIdentifyingName() + "&7.",
|
||||
PlayerUtils.sendMessages(player, TextUtils.formatText("&7Enter a tick rate min and max for " + this.spawnerTier.getIdentifyingName() + "&7.",
|
||||
"&7Example: &3800:200&6."));
|
||||
});
|
||||
}
|
||||
|
@ -1,18 +1,17 @@
|
||||
package com.craftaro.epicspawners.gui;
|
||||
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.gui.AnvilGui;
|
||||
import com.craftaro.core.gui.Gui;
|
||||
import com.craftaro.core.gui.GuiUtils;
|
||||
import com.craftaro.core.input.ChatPrompt;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.utils.TextUtils;
|
||||
import com.craftaro.epicspawners.EpicSpawners;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerData;
|
||||
import com.craftaro.epicspawners.settings.Settings;
|
||||
import com.craftaro.epicspawners.spawners.spawner.SpawnerDataImpl;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerTier;
|
||||
import com.craftaro.epicspawners.api.utils.HeadType;
|
||||
import com.craftaro.epicspawners.api.utils.HeadUtils;
|
||||
import com.craftaro.epicspawners.settings.Settings;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -21,7 +20,6 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class EditorOverviewGui extends Gui {
|
||||
|
||||
private final EpicSpawners plugin;
|
||||
private final Player player;
|
||||
private final SpawnerTier spawnerTier;
|
||||
@ -84,12 +82,13 @@ public class EditorOverviewGui extends Gui {
|
||||
setItem(53, glass3);
|
||||
|
||||
setButton(8, GuiUtils.createButtonItem(XMaterial.OAK_DOOR,
|
||||
plugin.getLocale().getMessage("general.nametag.back").getMessage()),
|
||||
(event) -> EditorTiersGui.openTiersInReverse(plugin, player, spawnerTier));
|
||||
this.plugin.getLocale().getMessage("general.nametag.back").getMessage()),
|
||||
(event) -> EditorTiersGui.openTiersInReverse(this.plugin, this.player, this.spawnerTier));
|
||||
|
||||
ItemStack item = HeadUtils.getTexturedSkull(spawnerTier);
|
||||
if (spawnerTier.getDisplayItem() != null && !spawnerTier.getDisplayItem().equals(XMaterial.AIR))
|
||||
item = spawnerTier.getDisplayItem().parseItem();
|
||||
ItemStack item = HeadUtils.getTexturedSkull(this.spawnerTier);
|
||||
if (this.spawnerTier.getDisplayItem() != null && !this.spawnerTier.getDisplayItem().equals(XMaterial.AIR)) {
|
||||
item = this.spawnerTier.getDisplayItem().parseItem();
|
||||
}
|
||||
|
||||
ItemMeta itemmeta = item.getItemMeta();
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
@ -97,81 +96,85 @@ public class EditorOverviewGui extends Gui {
|
||||
lore.add(TextUtils.formatText("&7Right-Click to &bChange Tier Display Item&7."));
|
||||
lore.add(TextUtils.formatText("&6-----------------------------"));
|
||||
|
||||
lore.add(TextUtils.formatText("&6Display Name: &7" + spawnerTier.getDisplayName() + "&7."));
|
||||
if (spawnerTier.getDisplayItem() != null) {
|
||||
lore.add(TextUtils.formatText("&6Display Item: &7" + spawnerTier.getDisplayItem().name() + "&7."));
|
||||
lore.add(TextUtils.formatText("&6Display Name: &7" + this.spawnerTier.getDisplayName() + "&7."));
|
||||
if (this.spawnerTier.getDisplayItem() != null) {
|
||||
lore.add(TextUtils.formatText("&6Display Item: &7" + this.spawnerTier.getDisplayItem().name() + "&7."));
|
||||
} else {
|
||||
if (!spawnerData.isCustom()) {
|
||||
if (!this.spawnerData.isCustom()) {
|
||||
lore.add(TextUtils.formatText("&6Display Item: &7Unavailable&7."));
|
||||
} else {
|
||||
lore.add(TextUtils.formatText("&6Display Item: &7Dirt&7."));
|
||||
}
|
||||
}
|
||||
lore.add(TextUtils.formatText("&6Config Name: &7" + spawnerTier.getIdentifyingName() + "&7."));
|
||||
lore.add(TextUtils.formatText("&6Config Name: &7" + this.spawnerTier.getIdentifyingName() + "&7."));
|
||||
itemmeta.setLore(lore);
|
||||
itemmeta.setDisplayName(spawnerTier.getCompiledDisplayName());
|
||||
itemmeta.setDisplayName(this.spawnerTier.getCompiledDisplayName());
|
||||
item.setItemMeta(itemmeta);
|
||||
setButton(11, item, event -> {
|
||||
if (event.clickType == ClickType.RIGHT) {
|
||||
spawnerTier.setDisplayItem(XMaterial.matchXMaterial(player.getInventory().getItemInHand()));
|
||||
plugin.getLocale().newMessage("&7Display Item for &6" + spawnerTier.getIdentifyingName() + " &7set to &6" + player.getInventory().getItemInHand().getType().toString() + "&7.")
|
||||
.sendPrefixedMessage(player);
|
||||
this.spawnerTier.setDisplayItem(XMaterial.matchXMaterial(this.player.getInventory().getItemInHand()));
|
||||
this.plugin.getLocale().newMessage("&7Display Item for &6" + this.spawnerTier.getIdentifyingName() + " &7set to &6" + this.player.getInventory().getItemInHand().getType() + "&7.")
|
||||
.sendPrefixedMessage(this.player);
|
||||
paint();
|
||||
} else if (event.clickType == ClickType.LEFT) {
|
||||
AnvilGui gui = new AnvilGui(player, this);
|
||||
AnvilGui gui = new AnvilGui(this.player, this);
|
||||
gui.setTitle("Enter a display name.");
|
||||
gui.setAction(evnt -> {
|
||||
spawnerTier.setDisplayName(gui.getInputText().trim());
|
||||
player.closeInventory();
|
||||
}).setOnClose(e -> setTitle(spawnerTier.getGuiTitle()));
|
||||
this.spawnerTier.setDisplayName(gui.getInputText().trim());
|
||||
this.player.closeInventory();
|
||||
}).setOnClose(e -> setTitle(this.spawnerTier.getGuiTitle()));
|
||||
|
||||
plugin.getGuiManager().showGUI(player, gui);
|
||||
this.plugin.getGuiManager().showGUI(this.player, gui);
|
||||
}
|
||||
});
|
||||
|
||||
if (spawnerData.getTiers().size() != 1 || spawnerData.isCustom())
|
||||
if (this.spawnerData.getTiers().size() != 1 || this.spawnerData.isCustom()) {
|
||||
setButton(29, GuiUtils.createButtonItem(XMaterial.TNT, TextUtils.formatText("&7Click to: &cDestroy This Tier")),
|
||||
(event) -> {
|
||||
player.sendMessage("Type \"yes\" to confirm this action.");
|
||||
ChatPrompt.showPrompt(plugin, player, evnt -> {
|
||||
this.player.sendMessage("Type \"yes\" to confirm this action.");
|
||||
ChatPrompt.showPrompt(this.plugin, this.player, evnt -> {
|
||||
if (evnt.getMessage().equalsIgnoreCase("yes")) {
|
||||
player.sendMessage(TextUtils.formatText("&6" + spawnerTier.getIdentifyingName() + " Spawner &7 has been destroyed successfully"));
|
||||
spawnerData.removeTier(spawnerTier);
|
||||
if (spawnerData.getTiers().isEmpty())
|
||||
plugin.getSpawnerManager().removeSpawnerData(spawnerData.getIdentifyingName());
|
||||
plugin.getLootablesManager().getLootManager().removeLootable(spawnerTier.getFullyIdentifyingName());
|
||||
this.player.sendMessage(TextUtils.formatText("&6" + this.spawnerTier.getIdentifyingName() + " Spawner &7 has been destroyed successfully"));
|
||||
this.spawnerData.removeTier(this.spawnerTier);
|
||||
if (this.spawnerData.getTiers().isEmpty()) {
|
||||
this.plugin.getSpawnerManager().removeSpawnerData(this.spawnerData.getIdentifyingName());
|
||||
}
|
||||
this.plugin.getLootablesManager().getLootManager().removeLootable(this.spawnerTier.getFullyIdentifyingName());
|
||||
}
|
||||
}).setOnClose(() -> {
|
||||
if (plugin.getSpawnerManager().isSpawnerData(spawnerData.getIdentifyingName()))
|
||||
plugin.getGuiManager().showGUI(player, new EditorTiersGui(plugin, player, spawnerData));
|
||||
else
|
||||
plugin.getGuiManager().showGUI(player, new EditorSelectorGui(plugin, player));
|
||||
}).setTimeOut(player, 20L * 15L);
|
||||
if (this.plugin.getSpawnerManager().isSpawnerData(this.spawnerData.getIdentifyingName())) {
|
||||
this.plugin.getGuiManager().showGUI(this.player, new EditorTiersGui(this.plugin, this.player, this.spawnerData));
|
||||
} else {
|
||||
this.plugin.getGuiManager().showGUI(this.player, new EditorSelectorGui(this.plugin, this.player));
|
||||
}
|
||||
}).setTimeOut(this.player, 20L * 15L);
|
||||
});
|
||||
}
|
||||
|
||||
setButton(23, GuiUtils.createButtonItem(XMaterial.LEVER, TextUtils.formatText("&9&lGeneral Settings")),
|
||||
event -> guiManager.showGUI(player, new EditorGeneralGui(plugin, this, spawnerTier)));
|
||||
event -> this.guiManager.showGUI(this.player, new EditorGeneralGui(this.plugin, this, this.spawnerTier)));
|
||||
|
||||
setButton(24, GuiUtils.createButtonItem(XMaterial.BONE, TextUtils.formatText("&e&lDrop Settings")),
|
||||
event -> plugin.getGuiManager().showGUI(player, new EditorDropsGui(plugin, spawnerTier, this)));
|
||||
event -> this.plugin.getGuiManager().showGUI(this.player, new EditorDropsGui(this.plugin, this.spawnerTier, this)));
|
||||
|
||||
setButton(25, GuiUtils.createButtonItem(HeadUtils.getTexturedSkull(HeadType.OMNI), TextUtils.formatText("&a&lEntity Settings")),
|
||||
event -> guiManager.showGUI(player, new EditorEditGui(plugin, this, spawnerTier, EditorEditGui.EditType.ENTITY)));
|
||||
event -> this.guiManager.showGUI(this.player, new EditorEditGui(this.plugin, this, this.spawnerTier, EditorEditGui.EditType.ENTITY)));
|
||||
|
||||
setButton(41, GuiUtils.createButtonItem(XMaterial.CHEST, TextUtils.formatText("&5&lItem Settings")),
|
||||
event -> guiManager.showGUI(player, new EditorEditGui(plugin, this, spawnerTier, EditorEditGui.EditType.ITEM)));
|
||||
event -> this.guiManager.showGUI(this.player, new EditorEditGui(this.plugin, this, this.spawnerTier, EditorEditGui.EditType.ITEM)));
|
||||
|
||||
setButton(32, GuiUtils.createButtonItem(XMaterial.GOLD_BLOCK, TextUtils.formatText("&c&lBlock Settings")),
|
||||
event -> guiManager.showGUI(player, new EditorEditGui(plugin, this, spawnerTier, EditorEditGui.EditType.BLOCK)));
|
||||
event -> this.guiManager.showGUI(this.player, new EditorEditGui(this.plugin, this, this.spawnerTier, EditorEditGui.EditType.BLOCK)));
|
||||
|
||||
setButton(34, GuiUtils.createButtonItem(XMaterial.FIREWORK_ROCKET, TextUtils.formatText("&b&lParticle Settings")),
|
||||
event -> guiManager.showGUI(player, new EditorParticleGui(plugin, this, spawnerTier)));
|
||||
event -> this.guiManager.showGUI(this.player, new EditorParticleGui(this.plugin, this, this.spawnerTier)));
|
||||
|
||||
setButton(43, GuiUtils.createButtonItem(XMaterial.PAPER, TextUtils.formatText("&6&lCommand Settings")),
|
||||
event -> guiManager.showGUI(player, new EditorEditGui(plugin, this, spawnerTier, EditorEditGui.EditType.COMMAND)));
|
||||
event -> this.guiManager.showGUI(this.player, new EditorEditGui(this.plugin, this, this.spawnerTier, EditorEditGui.EditType.COMMAND)));
|
||||
|
||||
if (spawnerData.getTiers().size() == 1)
|
||||
if (this.spawnerData.getTiers().size() == 1) {
|
||||
setButton(5, 0, GuiUtils.createButtonItem(XMaterial.FIRE_CHARGE, TextUtils.formatText("&6Go to tiered view.")),
|
||||
event -> EditorTiersGui.openTiers(plugin, player, spawnerData, true));
|
||||
event -> EditorTiersGui.openTiers(this.plugin, this.player, this.spawnerData, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,19 @@
|
||||
package com.craftaro.epicspawners.gui;
|
||||
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.gui.Gui;
|
||||
import com.craftaro.core.gui.GuiUtils;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.utils.TextUtils;
|
||||
import com.craftaro.epicspawners.EpicSpawners;
|
||||
import com.craftaro.epicspawners.api.particles.ParticleDensity;
|
||||
import com.craftaro.epicspawners.api.particles.ParticleEffect;
|
||||
import com.craftaro.epicspawners.api.particles.ParticleType;
|
||||
import com.craftaro.epicspawners.settings.Settings;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerTier;
|
||||
import com.craftaro.epicspawners.settings.Settings;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class EditorParticleGui extends Gui {
|
||||
|
||||
private final EpicSpawners plugin;
|
||||
private final Gui back;
|
||||
private final SpawnerTier spawnerTier;
|
||||
@ -60,25 +59,25 @@ public class EditorParticleGui extends Gui {
|
||||
setItem(44, glass2);
|
||||
|
||||
setButton(0, GuiUtils.createButtonItem(XMaterial.OAK_DOOR,
|
||||
plugin.getLocale().getMessage("general.nametag.back").getMessage()),
|
||||
(event) -> guiManager.showGUI(event.player, back));
|
||||
this.plugin.getLocale().getMessage("general.nametag.back").getMessage()),
|
||||
(event) -> this.guiManager.showGUI(event.player, this.back));
|
||||
|
||||
setButton(20, GuiUtils.createButtonItem(XMaterial.ENDER_PEARL, TextUtils.formatText("&5&lParticle Types",
|
||||
"&7Entity Spawn Particle: &a" + spawnerTier.getEntitySpawnParticle().name(),
|
||||
"&7Entity Spawn Particle: &a" + this.spawnerTier.getEntitySpawnParticle().name(),
|
||||
"&cLeft-Click to change.",
|
||||
"&7Spawner Spawn Particle: &a" + spawnerTier.getSpawnerSpawnParticle().name(),
|
||||
"&7Spawner Spawn Particle: &a" + this.spawnerTier.getSpawnerSpawnParticle().name(),
|
||||
"&cMiddle-Click to change.",
|
||||
"&7Effect Particle: &a" + spawnerTier.getSpawnEffectParticle().name(),
|
||||
"&7Effect Particle: &a" + this.spawnerTier.getSpawnEffectParticle().name(),
|
||||
"&cRight-Click to change.")), event -> {
|
||||
|
||||
ClickType type = event.clickType;
|
||||
ParticleType currentParticleType;
|
||||
if (type == ClickType.LEFT) {
|
||||
currentParticleType = spawnerTier.getEntitySpawnParticle();
|
||||
currentParticleType = this.spawnerTier.getEntitySpawnParticle();
|
||||
} else if (type == ClickType.RIGHT) {
|
||||
currentParticleType = spawnerTier.getSpawnEffectParticle();
|
||||
currentParticleType = this.spawnerTier.getSpawnEffectParticle();
|
||||
} else {
|
||||
currentParticleType = spawnerTier.getSpawnerSpawnParticle();
|
||||
currentParticleType = this.spawnerTier.getSpawnerSpawnParticle();
|
||||
}
|
||||
|
||||
boolean next = false;
|
||||
@ -96,20 +95,20 @@ public class EditorParticleGui extends Gui {
|
||||
|
||||
|
||||
if (type == ClickType.LEFT) {
|
||||
spawnerTier.setEntitySpawnParticle(currentParticleType);
|
||||
this.spawnerTier.setEntitySpawnParticle(currentParticleType);
|
||||
} else if (type == ClickType.RIGHT) {
|
||||
spawnerTier.setSpawnEffectParticle(currentParticleType);
|
||||
this.spawnerTier.setSpawnEffectParticle(currentParticleType);
|
||||
} else {
|
||||
spawnerTier.setSpawnerSpawnParticle(currentParticleType);
|
||||
this.spawnerTier.setSpawnerSpawnParticle(currentParticleType);
|
||||
}
|
||||
}).setOnClose(event -> paint());
|
||||
|
||||
setButton(22, GuiUtils.createButtonItem(XMaterial.FIREWORK_ROCKET, TextUtils.formatText("&6&lSpawner Effect",
|
||||
"&7Particle Effect: &a" + spawnerTier.getParticleEffect().name(),
|
||||
"&7Particle Effect: &a" + this.spawnerTier.getParticleEffect().name(),
|
||||
"&cLeft-Click to change.",
|
||||
"&7Particle Effect For Boosted Only: &a" + spawnerTier.isParticleEffectBoostedOnly(),
|
||||
"&7Particle Effect For Boosted Only: &a" + this.spawnerTier.isParticleEffectBoostedOnly(),
|
||||
"&cRight-Click to change.")), event -> {
|
||||
ParticleEffect currentParticleEffect = spawnerTier.getParticleEffect();
|
||||
ParticleEffect currentParticleEffect = this.spawnerTier.getParticleEffect();
|
||||
ClickType type = event.clickType;
|
||||
if (type == ClickType.LEFT) {
|
||||
boolean next = false;
|
||||
@ -124,16 +123,16 @@ public class EditorParticleGui extends Gui {
|
||||
if (next) {
|
||||
currentParticleEffect = ParticleEffect.values()[0];
|
||||
}
|
||||
spawnerTier.setParticleEffect(currentParticleEffect);
|
||||
this.spawnerTier.setParticleEffect(currentParticleEffect);
|
||||
} else if (type == ClickType.RIGHT) {
|
||||
spawnerTier.setParticleEffectBoostedOnly(!spawnerTier.isParticleEffectBoostedOnly());
|
||||
this.spawnerTier.setParticleEffectBoostedOnly(!this.spawnerTier.isParticleEffectBoostedOnly());
|
||||
}
|
||||
}).setOnClose(event -> paint());
|
||||
|
||||
setButton(24, GuiUtils.createButtonItem(XMaterial.COMPARATOR, TextUtils.formatText("&6&lPerformance",
|
||||
"&7Currently: &a" + spawnerTier.getParticleDensity().name() + " &cClick to change.")),
|
||||
"&7Currently: &a" + this.spawnerTier.getParticleDensity().name() + " &cClick to change.")),
|
||||
event -> {
|
||||
ParticleDensity currentParticleDensity = spawnerTier.getParticleDensity();
|
||||
ParticleDensity currentParticleDensity = this.spawnerTier.getParticleDensity();
|
||||
|
||||
boolean next = false;
|
||||
for (ParticleDensity particleDensity : ParticleDensity.values()) {
|
||||
@ -147,8 +146,7 @@ public class EditorParticleGui extends Gui {
|
||||
if (next) {
|
||||
currentParticleDensity = ParticleDensity.values()[0];
|
||||
}
|
||||
spawnerTier.setParticleDensity(currentParticleDensity);
|
||||
this.spawnerTier.setParticleDensity(currentParticleDensity);
|
||||
}).setOnClose(event -> paint());
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,13 @@
|
||||
package com.craftaro.epicspawners.gui;
|
||||
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.gui.Gui;
|
||||
import com.craftaro.core.gui.GuiUtils;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.utils.TextUtils;
|
||||
import com.craftaro.epicspawners.EpicSpawners;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerData;
|
||||
import com.craftaro.epicspawners.settings.Settings;
|
||||
import com.craftaro.epicspawners.spawners.spawner.SpawnerDataImpl;
|
||||
import com.craftaro.epicspawners.api.utils.HeadUtils;
|
||||
import com.craftaro.epicspawners.settings.Settings;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@ -17,7 +16,6 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class EditorSelectorGui extends Gui {
|
||||
|
||||
private final EpicSpawners plugin;
|
||||
private final Player player;
|
||||
private Type shownType = Type.BOTH;
|
||||
@ -28,7 +26,7 @@ public class EditorSelectorGui extends Gui {
|
||||
this.plugin = plugin;
|
||||
this.player = player;
|
||||
|
||||
entities.addAll(plugin.getSpawnerManager().getAllEnabledSpawnerData());
|
||||
this.entities.addAll(plugin.getSpawnerManager().getAllEnabledSpawnerData());
|
||||
setTitle("Spawner Selector");
|
||||
|
||||
showPage();
|
||||
@ -50,20 +48,20 @@ public class EditorSelectorGui extends Gui {
|
||||
mirrorFill(1, 0, true, true, glass2);
|
||||
mirrorFill(0, 1, true, true, glass2);
|
||||
|
||||
pages = (int) Math.max(1, Math.ceil(entities.size() / ((double) 28)));
|
||||
this.pages = (int) Math.max(1, Math.ceil(this.entities.size() / ((double) 28)));
|
||||
|
||||
// enable page event
|
||||
setNextPage(5, 7, GuiUtils.createButtonItem(XMaterial.ARROW, plugin.getLocale().getMessage("general.nametag.next").getMessage()));
|
||||
setPrevPage(5, 1, GuiUtils.createButtonItem(XMaterial.ARROW, plugin.getLocale().getMessage("general.nametag.back").getMessage()));
|
||||
setNextPage(5, 7, GuiUtils.createButtonItem(XMaterial.ARROW, this.plugin.getLocale().getMessage("general.nametag.next").getMessage()));
|
||||
setPrevPage(5, 1, GuiUtils.createButtonItem(XMaterial.ARROW, this.plugin.getLocale().getMessage("general.nametag.back").getMessage()));
|
||||
setOnPage((event) -> showPage());
|
||||
|
||||
List<SpawnerData> data = entities.stream()
|
||||
.filter(s -> shownType == Type.BOTH
|
||||
|| shownType == Type.DEFAULT && !s.isCustom()
|
||||
|| shownType == Type.CUSTOM && s.isCustom()).skip((page - 1) * 28).limit(28).collect(Collectors.toList());
|
||||
List<SpawnerData> data = this.entities.stream()
|
||||
.filter(s -> this.shownType == Type.BOTH
|
||||
|| this.shownType == Type.DEFAULT && !s.isCustom()
|
||||
|| this.shownType == Type.CUSTOM && s.isCustom()).skip((this.page - 1) * 28).limit(28).collect(Collectors.toList());
|
||||
|
||||
setButton(8, GuiUtils.createButtonItem(XMaterial.OAK_DOOR,
|
||||
plugin.getLocale().getMessage("general.nametag.exit").getMessage()), (event) -> close());
|
||||
this.plugin.getLocale().getMessage("general.nametag.exit").getMessage()), (event) -> close());
|
||||
|
||||
int num = 10;
|
||||
for (int i = 0; i < 28; i++) {
|
||||
@ -78,28 +76,24 @@ public class EditorSelectorGui extends Gui {
|
||||
}
|
||||
XMaterial mat = spawnerData.getDisplayItem();
|
||||
setButton(num, GuiUtils.createButtonItem(mat != null && !mat.equals(XMaterial.AIR) ? spawnerData.getDisplayItem().parseItem() : HeadUtils.getTexturedSkull(spawnerData),
|
||||
TextUtils.formatText("&6&l" + spawnerData.getIdentifyingName()), TextUtils.formatText("&7Click to &a&lEdit&7.")),
|
||||
(event) -> EditorTiersGui.openTiers(plugin, player, spawnerData));
|
||||
TextUtils.formatText("&6&l" + spawnerData.getIdentifyingName()), TextUtils.formatText("&7Click to &a&lEdit&7.")),
|
||||
(event) -> EditorTiersGui.openTiers(this.plugin, this.player, spawnerData));
|
||||
}
|
||||
|
||||
setButton(5, 5, GuiUtils.createButtonItem(XMaterial.COMPASS, TextUtils.formatText("&5&lShow: &7" + shownType.name())),
|
||||
setButton(5, 5, GuiUtils.createButtonItem(XMaterial.COMPASS, TextUtils.formatText("&5&lShow: &7" + this.shownType.name())),
|
||||
(event) -> {
|
||||
shownType = shownType.next();
|
||||
this.shownType = this.shownType.next();
|
||||
showPage();
|
||||
});
|
||||
setButton(5, 6, GuiUtils.createButtonItem(XMaterial.PAPER, TextUtils.formatText("&9&lNew Spawner")),
|
||||
(event) -> EditorTiersGui.openTiers(plugin, player, null));
|
||||
(event) -> EditorTiersGui.openTiers(this.plugin, this.player, null));
|
||||
}
|
||||
|
||||
private enum Type {
|
||||
|
||||
BOTH, CUSTOM, DEFAULT;
|
||||
|
||||
private static Type[] vals = values();
|
||||
|
||||
public Type next() {
|
||||
return vals[(this.ordinal() != vals.length - 1 ? this.ordinal() + 1 : 0)];
|
||||
return values()[(this.ordinal() != values().length - 1 ? this.ordinal() + 1 : 0)];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,21 +1,19 @@
|
||||
package com.craftaro.epicspawners.gui;
|
||||
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.gui.AnvilGui;
|
||||
import com.craftaro.core.gui.Gui;
|
||||
import com.craftaro.core.gui.GuiUtils;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.utils.NumberUtils;
|
||||
import com.craftaro.core.utils.PlayerUtils;
|
||||
import com.craftaro.core.utils.TextUtils;
|
||||
import com.craftaro.epicspawners.EpicSpawners;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerData;
|
||||
import com.craftaro.epicspawners.settings.Settings;
|
||||
import com.craftaro.epicspawners.spawners.spawner.SpawnerDataImpl;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class EditorTierGeneralGui extends Gui {
|
||||
|
||||
private final EpicSpawners plugin;
|
||||
private final Gui back;
|
||||
private final SpawnerData spawnerData;
|
||||
@ -47,21 +45,21 @@ public class EditorTierGeneralGui extends Gui {
|
||||
mirrorFill(1, 1, false, true, glass3);
|
||||
|
||||
setButton(0, GuiUtils.createButtonItem(XMaterial.OAK_DOOR,
|
||||
plugin.getLocale().getMessage("general.nametag.back").getMessage()),
|
||||
(event) -> guiManager.showGUI(event.player, back));
|
||||
this.plugin.getLocale().getMessage("general.nametag.back").getMessage()),
|
||||
(event) -> this.guiManager.showGUI(event.player, this.back));
|
||||
|
||||
setButton(10, GuiUtils.createButtonItem(XMaterial.SUNFLOWER, TextUtils.formatText("&6&lIn Shop",
|
||||
"&7Currently: &a" + spawnerData.isInShop(),
|
||||
"&7If this is true this spawner",
|
||||
"&7will show up in the shop GUI.")),
|
||||
"&7Currently: &a" + this.spawnerData.isInShop(),
|
||||
"&7If this is true this spawner",
|
||||
"&7will show up in the shop GUI.")),
|
||||
event -> {
|
||||
spawnerData.setInShop(!spawnerData.isInShop());
|
||||
this.spawnerData.setInShop(!this.spawnerData.isInShop());
|
||||
paint();
|
||||
});
|
||||
|
||||
setButton(16, GuiUtils.createButtonItem(XMaterial.FIRE_CHARGE, TextUtils.formatText("&a&lShop Price",
|
||||
"&7Currently: &a" + spawnerData.getShopPrice(),
|
||||
"&7This is the shop cost")),
|
||||
"&7Currently: &a" + this.spawnerData.getShopPrice(),
|
||||
"&7This is the shop cost")),
|
||||
event -> {
|
||||
Player player = event.player;
|
||||
AnvilGui gui = new AnvilGui(player, this);
|
||||
@ -69,23 +67,23 @@ public class EditorTierGeneralGui extends Gui {
|
||||
gui.setAction(evnt -> {
|
||||
String msg = gui.getInputText().trim();
|
||||
if (NumberUtils.isNumeric(msg)) {
|
||||
spawnerData.setShopPrice(Double.parseDouble(msg));
|
||||
this.spawnerData.setShopPrice(Double.parseDouble(msg));
|
||||
player.closeInventory();
|
||||
} else {
|
||||
player.sendMessage(TextUtils.formatText("&CYou must enter a number."));
|
||||
}
|
||||
}).setOnClose(e -> paint());
|
||||
guiManager.showGUI(player, gui);
|
||||
this.guiManager.showGUI(player, gui);
|
||||
|
||||
PlayerUtils.sendMessages(player, TextUtils.formatText("&7Enter a custom shop cost for " + spawnerData.getIdentifyingName() + "&7.",
|
||||
PlayerUtils.sendMessages(player, TextUtils.formatText("&7Enter a custom shop cost for " + this.spawnerData.getIdentifyingName() + "&7.",
|
||||
"&7Use &60 &7to use the default cost.",
|
||||
"&7Example: &619.99&7."));
|
||||
});
|
||||
|
||||
setButton(14, GuiUtils.createButtonItem(XMaterial.FIRE_CHARGE, TextUtils.formatText("&c&lCustom Kill Goal",
|
||||
"&7Currently: &a" + spawnerData.getShopPrice(),
|
||||
"&7This is the amount of kills",
|
||||
"of this tiers ")),
|
||||
"&7Currently: &a" + this.spawnerData.getShopPrice(),
|
||||
"&7This is the amount of kills",
|
||||
"of this tiers ")),
|
||||
event -> {
|
||||
Player player = event.player;
|
||||
AnvilGui gui = new AnvilGui(player, this);
|
||||
@ -93,15 +91,15 @@ public class EditorTierGeneralGui extends Gui {
|
||||
gui.setAction(evnt -> {
|
||||
String msg = gui.getInputText().trim();
|
||||
if (NumberUtils.isNumeric(msg)) {
|
||||
spawnerData.setShopPrice(Double.parseDouble(msg));
|
||||
this.spawnerData.setShopPrice(Double.parseDouble(msg));
|
||||
player.closeInventory();
|
||||
} else {
|
||||
player.sendMessage(TextUtils.formatText("&CYou must enter a number."));
|
||||
}
|
||||
}).setOnClose(e -> paint());
|
||||
guiManager.showGUI(player, gui);
|
||||
this.guiManager.showGUI(player, gui);
|
||||
|
||||
PlayerUtils.sendMessages(player, TextUtils.formatText("&7Enter a custom shop cost for " + spawnerData.getIdentifyingName() + "&7.",
|
||||
PlayerUtils.sendMessages(player, TextUtils.formatText("&7Enter a custom shop cost for " + this.spawnerData.getIdentifyingName() + "&7.",
|
||||
"&7Use &60 &7to use the default cost.",
|
||||
"&7Example: &619.99&7."));
|
||||
});
|
||||
|
@ -1,19 +1,17 @@
|
||||
package com.craftaro.epicspawners.gui;
|
||||
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.gui.Gui;
|
||||
import com.craftaro.core.gui.GuiUtils;
|
||||
import com.craftaro.core.input.ChatPrompt;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.utils.TextUtils;
|
||||
import com.craftaro.epicspawners.EpicSpawners;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.PlacedSpawner;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerData;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerStack;
|
||||
import com.craftaro.epicspawners.settings.Settings;
|
||||
import com.craftaro.epicspawners.spawners.spawner.PlacedSpawnerImpl;
|
||||
import com.craftaro.epicspawners.spawners.spawner.SpawnerDataImpl;
|
||||
import com.craftaro.epicspawners.spawners.spawner.SpawnerStackImpl;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerTier;
|
||||
import com.craftaro.epicspawners.settings.Settings;
|
||||
import com.craftaro.epicspawners.spawners.spawner.SpawnerDataImpl;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -25,7 +23,6 @@ import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class EditorTiersGui extends Gui {
|
||||
|
||||
private final EpicSpawners plugin;
|
||||
private final Player player;
|
||||
private final SpawnerData spawnerData;
|
||||
@ -60,32 +57,33 @@ public class EditorTiersGui extends Gui {
|
||||
mirrorFill(0, 1, true, true, glass2);
|
||||
|
||||
setButton(8, GuiUtils.createButtonItem(XMaterial.OAK_DOOR, "Back to Selector"),
|
||||
(event) -> plugin.getGuiManager().showGUI(player, new EditorSelectorGui(plugin, player)));
|
||||
(event) -> this.plugin.getGuiManager().showGUI(this.player, new EditorSelectorGui(this.plugin, this.player)));
|
||||
|
||||
List<SpawnerTier> tiersSource = spawnerData.getTiers();
|
||||
List<SpawnerTier> tiersSource = this.spawnerData.getTiers();
|
||||
|
||||
pages = (int) Math.max(1, Math.ceil(tiersSource.size() / ((double) 28)));
|
||||
this.pages = (int) Math.max(1, Math.ceil(tiersSource.size() / ((double) 28)));
|
||||
|
||||
// enable page event
|
||||
setNextPage(5, 7, GuiUtils.createButtonItem(XMaterial.ARROW, plugin.getLocale().getMessage("general.nametag.next").getMessage()));
|
||||
setPrevPage(5, 1, GuiUtils.createButtonItem(XMaterial.ARROW, plugin.getLocale().getMessage("general.nametag.back").getMessage()));
|
||||
setNextPage(5, 7, GuiUtils.createButtonItem(XMaterial.ARROW, this.plugin.getLocale().getMessage("general.nametag.next").getMessage()));
|
||||
setPrevPage(5, 1, GuiUtils.createButtonItem(XMaterial.ARROW, this.plugin.getLocale().getMessage("general.nametag.back").getMessage()));
|
||||
setOnPage((event) -> showPage());
|
||||
|
||||
List<SpawnerTier> tiers = tiersSource.stream().skip((page - 1) * 28).limit(28).collect(Collectors.toList());
|
||||
List<SpawnerTier> tiers = tiersSource.stream().skip((this.page - 1) * 28).limit(28).collect(Collectors.toList());
|
||||
|
||||
int num = 10;
|
||||
for (int i = 0; i < 28; i++) {
|
||||
num++;
|
||||
SpawnerTier tier = i < tiers.size() ? tiers.get(i) : null;
|
||||
if (num == 16 || num == 36)
|
||||
if (num == 16 || num == 36) {
|
||||
num = num + 2;
|
||||
}
|
||||
|
||||
if (tier == null) {
|
||||
setItem(num, null);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (acceptsItems) {
|
||||
if (this.acceptsItems) {
|
||||
setItem(num, GuiUtils.createButtonItem(tier.getDisplayItem() == XMaterial.AIR ? XMaterial.DIRT : tier.getDisplayItem(),
|
||||
tier.getIdentifyingName()));
|
||||
} else {
|
||||
@ -93,25 +91,26 @@ public class EditorTiersGui extends Gui {
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add(TextUtils.formatText("&6&l" + tier.getDisplayName() + " &7(" + tier.getIdentifyingName() + ")"));
|
||||
lore.add(TextUtils.formatText("&7Left Click to &a&lEdit&7."));
|
||||
boolean canDelete = spawnerData.getTiers().size() != 1 || spawnerData.isCustom();
|
||||
if (canDelete)
|
||||
boolean canDelete = this.spawnerData.getTiers().size() != 1 || this.spawnerData.isCustom();
|
||||
if (canDelete) {
|
||||
lore.add(TextUtils.formatText("&7Right Click to &c&lDestroy&7."));
|
||||
}
|
||||
|
||||
|
||||
setButton(num, GuiUtils.createButtonItem(tier.getDisplayItem() == XMaterial.AIR ? XMaterial.DIRT : tier.getDisplayItem(),
|
||||
lore),
|
||||
lore),
|
||||
(event) -> {
|
||||
if (event.clickType == ClickType.LEFT)
|
||||
guiManager.showGUI(player, new EditorOverviewGui(plugin, player, tier));
|
||||
else if (canDelete) {
|
||||
player.sendMessage("Type \"yes\" to confirm this action.");
|
||||
ChatPrompt.showPrompt(plugin, player, evnt -> {
|
||||
if (event.clickType == ClickType.LEFT) {
|
||||
this.guiManager.showGUI(this.player, new EditorOverviewGui(this.plugin, this.player, tier));
|
||||
} else if (canDelete) {
|
||||
this.player.sendMessage("Type \"yes\" to confirm this action.");
|
||||
ChatPrompt.showPrompt(this.plugin, this.player, evnt -> {
|
||||
if (evnt.getMessage().equalsIgnoreCase("yes")) {
|
||||
player.sendMessage(TextUtils.formatText("&6" + tier.getIdentifyingName() + " &7 has been destroyed successfully"));
|
||||
spawnerData.removeTier(tier);
|
||||
plugin.getLootablesManager().getLootManager().removeLootable(tier.getFullyIdentifyingName());
|
||||
this.player.sendMessage(TextUtils.formatText("&6" + tier.getIdentifyingName() + " &7 has been destroyed successfully"));
|
||||
this.spawnerData.removeTier(tier);
|
||||
this.plugin.getLootablesManager().getLootManager().removeLootable(tier.getFullyIdentifyingName());
|
||||
}
|
||||
plugin.getGuiManager().showGUI(player, new EditorTiersGui(plugin, player, spawnerData));
|
||||
this.plugin.getGuiManager().showGUI(this.player, new EditorTiersGui(this.plugin, this.player, this.spawnerData));
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -119,68 +118,75 @@ public class EditorTiersGui extends Gui {
|
||||
}
|
||||
|
||||
setButton(5, 3, GuiUtils.createButtonItem(XMaterial.FIRE_CHARGE, TextUtils.formatText("&9&lEdit Settings")),
|
||||
(event) -> guiManager.showGUI(player, new EditorTierGeneralGui(plugin, this, spawnerData)));
|
||||
(event) -> this.guiManager.showGUI(this.player, new EditorTierGeneralGui(this.plugin, this, this.spawnerData)));
|
||||
|
||||
if (pages == 1)
|
||||
if (this.pages == 1) {
|
||||
setButton(5, 4, GuiUtils.createButtonItem(XMaterial.CHEST, TextUtils.formatText("&a&lUnlock Tiers",
|
||||
"&7Currently: " + (acceptsItems ? "&aUnlocked" : "&cLocked") + "&7.",
|
||||
"&7Re-lock to save changed.")),
|
||||
"&7Currently: " + (this.acceptsItems ? "&aUnlocked" : "&cLocked") + "&7.",
|
||||
"&7Re-lock to save changed.")),
|
||||
(event) -> {
|
||||
if (acceptsItems) {
|
||||
if (this.acceptsItems) {
|
||||
Map<String, SpawnerTier> newTiers = new LinkedHashMap<>();
|
||||
|
||||
int slot = 10;
|
||||
for (int i = 0; i < 28; i++) {
|
||||
slot++;
|
||||
if (slot == 16 || slot == 36)
|
||||
if (slot == 16 || slot == 36) {
|
||||
slot = slot + 2;
|
||||
}
|
||||
|
||||
int finalSlot = slot;
|
||||
SpawnerTier tier = getItem(slot) != null ?
|
||||
tiers.stream().filter(t -> t.getIdentifyingName().equals(getItem(finalSlot).getItemMeta().getDisplayName())).findFirst().orElseGet(null) : null;
|
||||
|
||||
if (tier != null)
|
||||
if (tier != null) {
|
||||
newTiers.put("Tier_" + (newTiers.size() + 1), tier);
|
||||
}
|
||||
}
|
||||
|
||||
for (PlacedSpawner spawner : plugin.getSpawnerManager().getSpawners()) {
|
||||
for (PlacedSpawner spawner : this.plugin.getSpawnerManager().getSpawners()) {
|
||||
boolean modified = false;
|
||||
for (SpawnerStack stack : spawner.getSpawnerStacks()) {
|
||||
if (stack.getSpawnerData() != spawnerData)
|
||||
if (stack.getSpawnerData() != this.spawnerData) {
|
||||
continue;
|
||||
}
|
||||
|
||||
modified = true;
|
||||
|
||||
stack.setTier(newTiers.get(stack.getCurrentTier().getIdentifyingName()));
|
||||
}
|
||||
if (modified) {
|
||||
plugin.updateHologram(spawner);
|
||||
plugin.getDataManager().save(spawner);
|
||||
this.plugin.updateHologram(spawner);
|
||||
this.plugin.getDataManager().save(spawner);
|
||||
}
|
||||
}
|
||||
|
||||
for (Map.Entry<String, SpawnerTier> entry : newTiers.entrySet())
|
||||
for (Map.Entry<String, SpawnerTier> entry : newTiers.entrySet()) {
|
||||
entry.getValue().setIdentifyingName(entry.getKey());
|
||||
}
|
||||
|
||||
if (newTiers.size() == tiers.size())
|
||||
spawnerData.replaceTiers(newTiers.values());
|
||||
if (newTiers.size() == tiers.size()) {
|
||||
this.spawnerData.replaceTiers(newTiers.values());
|
||||
}
|
||||
|
||||
unlockedCells.clear();
|
||||
this.unlockedCells.clear();
|
||||
} else {
|
||||
setUnlockedRange(11, 38);
|
||||
unlockedCells.remove(16);
|
||||
unlockedCells.remove(17);
|
||||
unlockedCells.remove(26);
|
||||
unlockedCells.remove(27);
|
||||
this.unlockedCells.remove(16);
|
||||
this.unlockedCells.remove(17);
|
||||
this.unlockedCells.remove(26);
|
||||
this.unlockedCells.remove(27);
|
||||
}
|
||||
setAcceptsItems(!acceptsItems);
|
||||
setAcceptsItems(!this.acceptsItems);
|
||||
showPage();
|
||||
});
|
||||
else setItem(5, 4, null);
|
||||
} else {
|
||||
setItem(5, 4, null);
|
||||
}
|
||||
|
||||
setButton(5, 5, GuiUtils.createButtonItem(XMaterial.PAPER, TextUtils.formatText("&9&lNew Tier")),
|
||||
(event) -> {
|
||||
spawnerData.addDefaultTier();
|
||||
this.spawnerData.addDefaultTier();
|
||||
showPage();
|
||||
});
|
||||
}
|
||||
@ -206,27 +212,29 @@ public class EditorTiersGui extends Gui {
|
||||
}
|
||||
|
||||
int tierCount = spawnerData.getTiers().size();
|
||||
if (tierCount == 0)
|
||||
if (tierCount == 0) {
|
||||
spawnerData.addDefaultTier();
|
||||
}
|
||||
|
||||
if (tierCount == 1 && !forced)
|
||||
if (tierCount == 1 && !forced) {
|
||||
plugin.getGuiManager().showGUI(player, new EditorOverviewGui(plugin, player, spawnerData.getFirstTier()));
|
||||
else
|
||||
} else {
|
||||
plugin.getGuiManager().showGUI(player, new EditorTiersGui(plugin, player, spawnerData));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void openTiersInReverse(EpicSpawners plugin, Player player, SpawnerTier tier) {
|
||||
SpawnerData spawnerData = tier.getSpawnerData();
|
||||
int tierCount = spawnerData.getTiers().size();
|
||||
if (tierCount == 0)
|
||||
if (tierCount == 0) {
|
||||
spawnerData.addDefaultTier();
|
||||
}
|
||||
|
||||
if (tierCount == 1)
|
||||
if (tierCount == 1) {
|
||||
plugin.getGuiManager().showGUI(player, new EditorSelectorGui(plugin, player));
|
||||
else
|
||||
} else {
|
||||
plugin.getGuiManager().showGUI(player, new EditorTiersGui(plugin, player, spawnerData));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,11 +1,10 @@
|
||||
package com.craftaro.epicspawners.gui;
|
||||
|
||||
import com.craftaro.core.database.DataManager;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.compatibility.CompatibleSound;
|
||||
import com.craftaro.core.gui.CustomizableGui;
|
||||
import com.craftaro.core.gui.GuiUtils;
|
||||
import com.craftaro.core.hooks.EconomyManager;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XSound;
|
||||
import com.craftaro.core.third_party.org.apache.commons.lang3.math.NumberUtils;
|
||||
import com.craftaro.core.third_party.org.apache.commons.text.WordUtils;
|
||||
@ -16,10 +15,8 @@ import com.craftaro.core.utils.ItemUtils;
|
||||
import com.craftaro.core.utils.TextUtils;
|
||||
import com.craftaro.epicspawners.EpicSpawners;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.PlacedSpawner;
|
||||
import com.craftaro.epicspawners.boost.types.BoostedImpl;
|
||||
import com.craftaro.epicspawners.boost.types.BoostedSpawnerImpl;
|
||||
import com.craftaro.epicspawners.settings.Settings;
|
||||
import com.craftaro.epicspawners.spawners.spawner.PlacedSpawnerImpl;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -29,7 +26,6 @@ import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
public class SpawnerBoostGui extends CustomizableGui {
|
||||
|
||||
private final EpicSpawners plugin;
|
||||
private final PlacedSpawner spawner;
|
||||
private final Player player;
|
||||
@ -46,15 +42,15 @@ public class SpawnerBoostGui extends CustomizableGui {
|
||||
}
|
||||
|
||||
private void setUp() {
|
||||
if (amount > Settings.MAX_PLAYER_BOOST.getInt()) {
|
||||
amount = Settings.MAX_PLAYER_BOOST.getInt();
|
||||
if (this.amount > Settings.MAX_PLAYER_BOOST.getInt()) {
|
||||
this.amount = Settings.MAX_PLAYER_BOOST.getInt();
|
||||
return;
|
||||
} else if (amount < 1) {
|
||||
amount = 1;
|
||||
} else if (this.amount < 1) {
|
||||
this.amount = 1;
|
||||
}
|
||||
setTitle(plugin.getLocale().getMessage("interface.boost.title")
|
||||
.processPlaceholder("spawner", spawner.getFirstTier().getCompiledDisplayName())
|
||||
.processPlaceholder("amount", amount).getMessage());
|
||||
setTitle(this.plugin.getLocale().getMessage("interface.boost.title")
|
||||
.processPlaceholder("spawner", this.spawner.getFirstTier().getCompiledDisplayName())
|
||||
.processPlaceholder("amount", this.amount).getMessage());
|
||||
}
|
||||
|
||||
public void paint() {
|
||||
@ -72,55 +68,55 @@ public class SpawnerBoostGui extends CustomizableGui {
|
||||
mirrorFill("mirrorfill_4", 1, 0, false, true, glass2);
|
||||
mirrorFill("mirrorfill_5", 1, 1, false, true, glass3);
|
||||
|
||||
setButton("boost5", 10, GuiUtils.createButtonItem(XMaterial.COAL, plugin.getLocale().getMessage("interface.boost.boostfor")
|
||||
.processPlaceholder("amount", "5").getMessage(),
|
||||
plugin.getLocale().getMessage("interface.boost.cost")
|
||||
.processPlaceholder("cost", getBoostCost(5, amount)).getMessage()),
|
||||
event -> purchaseBoost(player, 5, amount));
|
||||
setButton("boost5", 10, GuiUtils.createButtonItem(XMaterial.COAL, this.plugin.getLocale().getMessage("interface.boost.boostfor")
|
||||
.processPlaceholder("amount", "5").getMessage(),
|
||||
this.plugin.getLocale().getMessage("interface.boost.cost")
|
||||
.processPlaceholder("cost", getBoostCost(5, this.amount)).getMessage()),
|
||||
event -> purchaseBoost(this.player, 5, this.amount));
|
||||
|
||||
setButton("boost15", 12, GuiUtils.createButtonItem(XMaterial.IRON_INGOT, plugin.getLocale().getMessage("interface.boost.boostfor")
|
||||
.processPlaceholder("amount", "15").getMessage(),
|
||||
plugin.getLocale().getMessage("interface.boost.cost")
|
||||
.processPlaceholder("cost", getBoostCost(15, amount)).getMessage()),
|
||||
event -> purchaseBoost(player, 15, amount));
|
||||
setButton("boost15", 12, GuiUtils.createButtonItem(XMaterial.IRON_INGOT, this.plugin.getLocale().getMessage("interface.boost.boostfor")
|
||||
.processPlaceholder("amount", "15").getMessage(),
|
||||
this.plugin.getLocale().getMessage("interface.boost.cost")
|
||||
.processPlaceholder("cost", getBoostCost(15, this.amount)).getMessage()),
|
||||
event -> purchaseBoost(this.player, 15, this.amount));
|
||||
|
||||
setButton("boost30", 14, GuiUtils.createButtonItem(XMaterial.DIAMOND, plugin.getLocale().getMessage("interface.boost.boostfor")
|
||||
.processPlaceholder("amount", "30").getMessage(),
|
||||
plugin.getLocale().getMessage("interface.boost.cost")
|
||||
.processPlaceholder("cost", getBoostCost(30, amount)).getMessage()),
|
||||
event -> purchaseBoost(player, 30, amount));
|
||||
setButton("boost30", 14, GuiUtils.createButtonItem(XMaterial.DIAMOND, this.plugin.getLocale().getMessage("interface.boost.boostfor")
|
||||
.processPlaceholder("amount", "30").getMessage(),
|
||||
this.plugin.getLocale().getMessage("interface.boost.cost")
|
||||
.processPlaceholder("cost", getBoostCost(30, this.amount)).getMessage()),
|
||||
event -> purchaseBoost(this.player, 30, this.amount));
|
||||
|
||||
setButton("boost60", 16, GuiUtils.createButtonItem(XMaterial.EMERALD, plugin.getLocale().getMessage("interface.boost.boostfor")
|
||||
.processPlaceholder("amount", "60").getMessage(),
|
||||
plugin.getLocale().getMessage("interface.boost.cost")
|
||||
.processPlaceholder("cost", getBoostCost(60, amount)).getMessage()),
|
||||
event -> purchaseBoost(player, 60, amount));
|
||||
setButton("boost60", 16, GuiUtils.createButtonItem(XMaterial.EMERALD, this.plugin.getLocale().getMessage("interface.boost.boostfor")
|
||||
.processPlaceholder("amount", "60").getMessage(),
|
||||
this.plugin.getLocale().getMessage("interface.boost.cost")
|
||||
.processPlaceholder("cost", getBoostCost(60, this.amount)).getMessage()),
|
||||
event -> purchaseBoost(this.player, 60, this.amount));
|
||||
|
||||
setButton("back", 4, GuiUtils.createButtonItem(Settings.EXIT_ICON.getMaterial(),
|
||||
plugin.getLocale().getMessage("general.nametag.back").getMessage()),
|
||||
event -> spawner.overview(player));
|
||||
this.plugin.getLocale().getMessage("general.nametag.back").getMessage()),
|
||||
event -> this.spawner.overview(this.player));
|
||||
|
||||
if (amount != 1)
|
||||
if (this.amount != 1)
|
||||
setButton("minus1", 0, GuiUtils.createButtonItem(ItemUtils.getCustomHead("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23"),
|
||||
TextUtils.formatText("&6&l-1")), event -> {
|
||||
amount--;
|
||||
this.amount--;
|
||||
setUp();
|
||||
paint();
|
||||
});
|
||||
|
||||
if (amount < Settings.MAX_PLAYER_BOOST.getInt())
|
||||
if (this.amount < Settings.MAX_PLAYER_BOOST.getInt())
|
||||
setButton("plus1", 8, GuiUtils.createButtonItem(ItemUtils.getCustomHead("1b6f1a25b6bc199946472aedb370522584ff6f4e83221e5946bd2e41b5ca13b"),
|
||||
TextUtils.formatText("&6&l+1")), event -> {
|
||||
amount++;
|
||||
this.amount++;
|
||||
setUp();
|
||||
paint();
|
||||
});
|
||||
}
|
||||
|
||||
private void purchaseBoost(Player player, int time, int amt) {
|
||||
Location location = spawner.getLocation();
|
||||
Location location = this.spawner.getLocation();
|
||||
player.closeInventory();
|
||||
EpicSpawners instance = plugin;
|
||||
EpicSpawners instance = this.plugin;
|
||||
|
||||
String un = Settings.BOOST_COST.getString();
|
||||
|
||||
@ -134,7 +130,7 @@ public class SpawnerBoostGui extends CustomizableGui {
|
||||
if (EconomyManager.hasBalance(player, cost)) {
|
||||
EconomyManager.withdrawBalance(player, cost);
|
||||
} else {
|
||||
plugin.getLocale().getMessage("event.upgrade.cannotafford").sendPrefixedMessage(player);
|
||||
this.plugin.getLocale().getMessage("event.upgrade.cannotafford").sendPrefixedMessage(player);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
@ -146,7 +142,7 @@ public class SpawnerBoostGui extends CustomizableGui {
|
||||
if (player.getGameMode() != GameMode.CREATIVE || Settings.CHARGE_FOR_CREATIVE.getBoolean())
|
||||
player.setLevel(player.getLevel() - cost);
|
||||
} else {
|
||||
plugin.getLocale().getMessage("event.upgrade.cannotafford").sendPrefixedMessage(player);
|
||||
this.plugin.getLocale().getMessage("event.upgrade.cannotafford").sendPrefixedMessage(player);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
@ -155,7 +151,7 @@ public class SpawnerBoostGui extends CustomizableGui {
|
||||
stack.setAmount(cost);
|
||||
player.getInventory().removeItem(stack);
|
||||
} else {
|
||||
plugin.getLocale().getMessage("event.upgrade.cannotafford").sendPrefixedMessage(player);
|
||||
this.plugin.getLocale().getMessage("event.upgrade.cannotafford").sendPrefixedMessage(player);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -171,19 +167,19 @@ public class SpawnerBoostGui extends CustomizableGui {
|
||||
dataManager.getAsyncPool().execute(() -> {
|
||||
dataManager.getDatabaseConnector().connectDSL(context -> {
|
||||
|
||||
Result<Record> result = context.select().from(DSL.table(dataManager.getTablePrefix()+"boosted_spawners"))
|
||||
Result<Record> result = context.select().from(DSL.table(dataManager.getTablePrefix() + "boosted_spawners"))
|
||||
.where(DSL.field("world").eq(boost.getLocation().getWorld().getName()))
|
||||
.and(DSL.field("x").eq(boost.getLocation().getX()))
|
||||
.and(DSL.field("y").eq(boost.getLocation().getY()))
|
||||
.and(DSL.field("z").eq(boost.getLocation().getZ()))
|
||||
.fetch();
|
||||
|
||||
if (result.size() == 0) {
|
||||
context.insertInto(DSL.table(dataManager.getTablePrefix()+"boosted_spawners"))
|
||||
if (result.isEmpty()) {
|
||||
context.insertInto(DSL.table(dataManager.getTablePrefix() + "boosted_spawners"))
|
||||
.set(boost.serialize())
|
||||
.execute();
|
||||
} else {
|
||||
context.update(DSL.table(dataManager.getTablePrefix()+"boosted_spawners"))
|
||||
context.update(DSL.table(dataManager.getTablePrefix() + "boosted_spawners"))
|
||||
.set(boost.serialize())
|
||||
.where(DSL.field("world").eq(boost.getLocation().getWorld().getName()))
|
||||
.and(DSL.field("x").eq(boost.getLocation().getX()))
|
||||
@ -193,7 +189,7 @@ public class SpawnerBoostGui extends CustomizableGui {
|
||||
}
|
||||
});
|
||||
});
|
||||
plugin.getLocale().getMessage("event.boost.applied").sendPrefixedMessage(player);
|
||||
this.plugin.getLocale().getMessage("event.boost.applied").sendPrefixedMessage(player);
|
||||
XSound.ENTITY_VILLAGER_YES.play(player, 1.0f, 1.0f);
|
||||
}
|
||||
|
||||
@ -223,5 +219,4 @@ public class SpawnerBoostGui extends CustomizableGui {
|
||||
public int boostCost(String multi, int time, int amt) {
|
||||
return (int) Math.ceil(NumberUtils.toDouble(multi, 1) * time * amt);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,16 +1,14 @@
|
||||
package com.craftaro.epicspawners.gui;
|
||||
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.gui.CustomizableGui;
|
||||
import com.craftaro.core.gui.GuiUtils;
|
||||
import com.craftaro.core.hooks.EconomyManager;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.epicspawners.EpicSpawners;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerData;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerStack;
|
||||
import com.craftaro.epicspawners.settings.Settings;
|
||||
import com.craftaro.epicspawners.spawners.spawner.SpawnerDataImpl;
|
||||
import com.craftaro.epicspawners.spawners.spawner.SpawnerStackImpl;
|
||||
import com.craftaro.epicspawners.api.utils.HeadUtils;
|
||||
import com.craftaro.epicspawners.settings.Settings;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -22,7 +20,6 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class SpawnerConvertGui extends CustomizableGui {
|
||||
|
||||
private final EpicSpawners plugin;
|
||||
private final SpawnerStack stack;
|
||||
private final Player player;
|
||||
@ -38,9 +35,10 @@ public class SpawnerConvertGui extends CustomizableGui {
|
||||
for (SpawnerData spawnerData : plugin.getSpawnerManager().getAllSpawnerData()) {
|
||||
if (!spawnerData.isConvertible()
|
||||
|| !spawnerData.isActive()
|
||||
|| !player.hasPermission("epicspawners.convert." + spawnerData.getIdentifyingName().replace(" ", "_")))
|
||||
|| !player.hasPermission("epicspawners.convert." + spawnerData.getIdentifyingName().replace(" ", "_"))) {
|
||||
continue;
|
||||
entities.add(spawnerData);
|
||||
}
|
||||
this.entities.add(spawnerData);
|
||||
}
|
||||
|
||||
setTitle(plugin.getLocale().getMessage("interface.convert.title").getMessage());
|
||||
@ -61,31 +59,33 @@ public class SpawnerConvertGui extends CustomizableGui {
|
||||
// decorate corners with type 2
|
||||
mirrorFill("mirrorfill_3", 0, 0, true, true, glass2);
|
||||
mirrorFill("mirrorfill_4", 1, 0, true, true, glass2);
|
||||
mirrorFill("mirrorfill_5",0, 1, true, true, glass2);
|
||||
mirrorFill("mirrorfill_5", 0, 1, true, true, glass2);
|
||||
|
||||
pages = (int) Math.max(1, Math.ceil(entities.size() / ((double) 28)));
|
||||
this.pages = (int) Math.max(1, Math.ceil(this.entities.size() / ((double) 28)));
|
||||
|
||||
// enable page event
|
||||
setNextPage(5, 7, GuiUtils.createButtonItem(XMaterial.ARROW, plugin.getLocale().getMessage("general.nametag.next").getMessage()));
|
||||
setPrevPage(5, 1, GuiUtils.createButtonItem(XMaterial.ARROW, plugin.getLocale().getMessage("general.nametag.back").getMessage()));
|
||||
setNextPage(5, 7, GuiUtils.createButtonItem(XMaterial.ARROW, this.plugin.getLocale().getMessage("general.nametag.next").getMessage()));
|
||||
setPrevPage(5, 1, GuiUtils.createButtonItem(XMaterial.ARROW, this.plugin.getLocale().getMessage("general.nametag.back").getMessage()));
|
||||
setOnPage((event) -> showPage());
|
||||
|
||||
// Sort entities by their shopOrder val
|
||||
entities.sort(Comparator.comparingInt(SpawnerData::getShopOrder));
|
||||
this.entities.sort(Comparator.comparingInt(SpawnerData::getShopOrder));
|
||||
|
||||
List<SpawnerData> data = entities.stream().skip((page - 1) * 28).limit(28).collect(Collectors.toList());
|
||||
List<SpawnerData> data = this.entities.stream().skip((this.page - 1) * 28).limit(28).collect(Collectors.toList());
|
||||
|
||||
int num = 11;
|
||||
for (SpawnerData spawnerData : data) {
|
||||
if (num == 16 || num == 36)
|
||||
if (num == 16 || num == 36) {
|
||||
num = num + 2;
|
||||
}
|
||||
|
||||
ItemStack item = HeadUtils.getTexturedSkull(spawnerData);
|
||||
|
||||
if (spawnerData.getDisplayItem() != null) {
|
||||
XMaterial mat = spawnerData.getDisplayItem();
|
||||
if (!mat.equals(XMaterial.AIR))
|
||||
if (!mat.equals(XMaterial.AIR)) {
|
||||
item = mat.parseItem();
|
||||
}
|
||||
}
|
||||
|
||||
ItemMeta itemmeta = item.getItemMeta();
|
||||
@ -93,22 +93,22 @@ public class SpawnerConvertGui extends CustomizableGui {
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
double price = spawnerData.getConvertPrice();
|
||||
|
||||
lore.add(plugin.getLocale().getMessage("interface.shop.buyprice").processPlaceholder("cost", EconomyManager.formatEconomy(price)).getMessage());
|
||||
String loreString = plugin.getLocale().getMessage("interface.convert.lore").getMessage();
|
||||
lore.add(this.plugin.getLocale().getMessage("interface.shop.buyprice").processPlaceholder("cost", EconomyManager.formatEconomy(price)).getMessage());
|
||||
String loreString = this.plugin.getLocale().getMessage("interface.convert.lore").getMessage();
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
|
||||
loreString = me.clip.placeholderapi.PlaceholderAPI.setPlaceholders(player, loreString.replace(" ", "_")).replace("_", " ");
|
||||
loreString = me.clip.placeholderapi.PlaceholderAPI.setPlaceholders(this.player, loreString.replace(" ", "_")).replace("_", " ");
|
||||
}
|
||||
lore.add(loreString);
|
||||
itemmeta.setLore(lore);
|
||||
itemmeta.setDisplayName(name);
|
||||
item.setItemMeta(itemmeta);
|
||||
setButton(num, item, event ->
|
||||
stack.convert(spawnerData, player, false));
|
||||
this.stack.convert(spawnerData, this.player, false));
|
||||
num++;
|
||||
}
|
||||
|
||||
setButton("back", 8, GuiUtils.createButtonItem(Settings.EXIT_ICON.getMaterial(),
|
||||
plugin.getLocale().getMessage("general.nametag.back").getMessage()),
|
||||
event -> guiManager.showGUI(player, new SpawnerOverviewGui(plugin, stack, player)));
|
||||
this.plugin.getLocale().getMessage("general.nametag.back").getMessage()),
|
||||
event -> this.guiManager.showGUI(this.player, new SpawnerOverviewGui(this.plugin, this.stack, this.player)));
|
||||
}
|
||||
}
|
||||
|
@ -1,23 +1,20 @@
|
||||
package com.craftaro.epicspawners.gui;
|
||||
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.gui.CustomizableGui;
|
||||
import com.craftaro.core.hooks.EconomyManager;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.utils.NumberUtils;
|
||||
import com.craftaro.core.utils.TextUtils;
|
||||
import com.craftaro.epicspawners.EpicSpawners;
|
||||
import com.craftaro.epicspawners.api.spawners.condition.SpawnCondition;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.PlacedSpawner;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerData;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerStack;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerTier;
|
||||
import com.craftaro.epicspawners.settings.Settings;
|
||||
import com.craftaro.epicspawners.api.spawners.condition.SpawnCondition;
|
||||
import com.craftaro.epicspawners.spawners.spawner.PlacedSpawnerImpl;
|
||||
import com.craftaro.epicspawners.spawners.spawner.SpawnerDataImpl;
|
||||
import com.craftaro.epicspawners.spawners.spawner.SpawnerStackImpl;
|
||||
import com.craftaro.epicspawners.api.utils.CostType;
|
||||
import com.craftaro.epicspawners.utils.GuiUtils;
|
||||
import com.craftaro.epicspawners.api.utils.HeadUtils;
|
||||
import com.craftaro.epicspawners.settings.Settings;
|
||||
import com.craftaro.epicspawners.utils.GuiUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -31,7 +28,6 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class SpawnerOverviewGui extends CustomizableGui {
|
||||
|
||||
private static final Pattern REGEX = Pattern.compile("(.{1,28}(?:\\s|$))|(.{0,28})", Pattern.DOTALL);
|
||||
|
||||
private final PlacedSpawner spawner;
|
||||
@ -51,18 +47,18 @@ public class SpawnerOverviewGui extends CustomizableGui {
|
||||
super(plugin, "overview");
|
||||
setRows(3);
|
||||
this.stack = stack;
|
||||
spawner = stack.getSpawner();
|
||||
tier = stack.getCurrentTier();
|
||||
data = tier.getSpawnerData();
|
||||
nextTier = data.getNextTier(tier);
|
||||
onlyOneTier = tier.getSpawnerData().getTiers().size() == 1;
|
||||
this.spawner = stack.getSpawner();
|
||||
this.tier = stack.getCurrentTier();
|
||||
this.data = this.tier.getSpawnerData();
|
||||
this.nextTier = this.data.getNextTier(this.tier);
|
||||
this.onlyOneTier = this.tier.getSpawnerData().getTiers().size() == 1;
|
||||
this.player = player;
|
||||
this.plugin = plugin;
|
||||
|
||||
setTitle(tier.getCompiledDisplayName(false, stack.getStackSize()));
|
||||
setTitle(this.tier.getCompiledDisplayName(false, stack.getStackSize()));
|
||||
runTask();
|
||||
|
||||
setOnClose(event -> Bukkit.getScheduler().cancelTask(task));
|
||||
setOnClose(event -> Bukkit.getScheduler().cancelTask(this.task));
|
||||
|
||||
paint();
|
||||
}
|
||||
@ -82,25 +78,27 @@ public class SpawnerOverviewGui extends CustomizableGui {
|
||||
mirrorFill("mirrorfill_4", 1, 0, false, true, glass2);
|
||||
mirrorFill("mirrorfill_5", 1, 1, false, true, glass3);
|
||||
|
||||
if (spawner.getSpawnerStacks().size() != 1)
|
||||
if (this.spawner.getSpawnerStacks().size() != 1) {
|
||||
setButton("back", 0, com.craftaro.core.gui.GuiUtils.createButtonItem(Settings.EXIT_ICON.getMaterial(),
|
||||
plugin.getLocale().getMessage("general.nametag.back").getMessage()),
|
||||
(event) -> guiManager.showGUI(event.player, new SpawnerTiersGui(plugin, player, spawner)));
|
||||
this.plugin.getLocale().getMessage("general.nametag.back").getMessage()),
|
||||
(event) -> this.guiManager.showGUI(event.player, new SpawnerTiersGui(this.plugin, this.player, this.spawner)));
|
||||
}
|
||||
|
||||
int showAmt = stack.getStackSize();
|
||||
if (showAmt > 64)
|
||||
int showAmt = this.stack.getStackSize();
|
||||
if (showAmt > 64) {
|
||||
showAmt = 1;
|
||||
else if (showAmt == 0)
|
||||
} else if (showAmt == 0) {
|
||||
showAmt = 1;
|
||||
}
|
||||
|
||||
ItemStack spawnerItem;
|
||||
|
||||
XMaterial displayItem = tier.getDisplayItem();
|
||||
XMaterial displayItem = this.tier.getDisplayItem();
|
||||
if (displayItem != null && !displayItem.equals(XMaterial.AIR)) {
|
||||
spawnerItem = displayItem.parseItem();
|
||||
} else {
|
||||
try {
|
||||
spawnerItem = HeadUtils.getTexturedSkull(data);
|
||||
spawnerItem = HeadUtils.getTexturedSkull(this.data);
|
||||
} catch (Exception e) {
|
||||
spawnerItem = XMaterial.SPAWNER.parseItem();
|
||||
spawnerItem.setAmount(showAmt);
|
||||
@ -108,102 +106,110 @@ public class SpawnerOverviewGui extends CustomizableGui {
|
||||
}
|
||||
|
||||
ItemMeta itemmeta = spawnerItem.getItemMeta();
|
||||
itemmeta.setDisplayName(plugin.getLocale().getMessage("interface.spawner.statstitle").getMessage());
|
||||
itemmeta.setDisplayName(this.plugin.getLocale().getMessage("interface.spawner.statstitle").getMessage());
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
|
||||
List<XMaterial> blocks = tier.getSpawnBlocksList();
|
||||
List<XMaterial> blocks = this.tier.getSpawnBlocksList();
|
||||
|
||||
if (blocks.isEmpty() || blocks.get(0) == null) blocks = Collections.singletonList(XMaterial.AIR);
|
||||
if (blocks.isEmpty() || blocks.get(0) == null) {
|
||||
blocks = Collections.singletonList(XMaterial.AIR);
|
||||
}
|
||||
|
||||
StringBuilder only = new StringBuilder(blocks.get(0).name());
|
||||
|
||||
int num = 1;
|
||||
for (XMaterial block : blocks) {
|
||||
if (num != 1)
|
||||
if (num != 1) {
|
||||
only.append("&8, &a").append(block.name());
|
||||
}
|
||||
num++;
|
||||
}
|
||||
|
||||
String onlyStr = plugin.getLocale().getMessage("interface.spawner.onlyspawnson")
|
||||
String onlyStr = this.plugin.getLocale().getMessage("interface.spawner.onlyspawnson")
|
||||
.processPlaceholder("block", only.toString()).getMessage();
|
||||
|
||||
lore.addAll(TextUtils.wrap("7", onlyStr));
|
||||
|
||||
boolean met = true;
|
||||
for (SpawnCondition condition : tier.getConditions()) {
|
||||
if (!condition.isMet(spawner)) {
|
||||
for (SpawnCondition condition : this.tier.getConditions()) {
|
||||
if (!condition.isMet(this.spawner)) {
|
||||
if (met) {
|
||||
met = false;
|
||||
lore.add("");
|
||||
lore.add(plugin.getLocale().getMessage("interface.spawner.paused").getMessage());
|
||||
lore.add(this.plugin.getLocale().getMessage("interface.spawner.paused").getMessage());
|
||||
}
|
||||
lore.addAll(TextUtils.wrap("7", " » " + condition.getDescription()));
|
||||
}
|
||||
}
|
||||
|
||||
if (spawner.getSpawnerStacks().size() == 1) {
|
||||
if (this.spawner.getSpawnerStacks().size() == 1) {
|
||||
lore.add("");
|
||||
lore.add(plugin.getLocale().getMessage("interface.spawner.stats")
|
||||
.processPlaceholder("amount", NumberUtils.formatNumber(spawner.getSpawnCount())).getMessage());
|
||||
lore.add(this.plugin.getLocale().getMessage("interface.spawner.stats")
|
||||
.processPlaceholder("amount", NumberUtils.formatNumber(this.spawner.getSpawnCount())).getMessage());
|
||||
}
|
||||
|
||||
|
||||
itemmeta.setLore(lore);
|
||||
spawnerItem.setItemMeta(itemmeta);
|
||||
|
||||
double levelsCost = nextTier == null ? -1 : nextTier.getUpgradeCost(CostType.LEVELS);
|
||||
double economyCost = nextTier == null ? -1 : nextTier.getUpgradeCost(CostType.ECONOMY);
|
||||
double levelsCost = this.nextTier == null ? -1 : this.nextTier.getUpgradeCost(CostType.LEVELS);
|
||||
double economyCost = this.nextTier == null ? -1 : this.nextTier.getUpgradeCost(CostType.ECONOMY);
|
||||
|
||||
ItemStack itemLevels = Settings.XP_ICON.getMaterial().parseItem();
|
||||
ItemMeta itemmetaXP = itemLevels.getItemMeta();
|
||||
itemmetaXP.setDisplayName(plugin.getLocale().getMessage("interface.spawner.upgradewithlevels").getMessage());
|
||||
itemmetaXP.setDisplayName(this.plugin.getLocale().getMessage("interface.spawner.upgradewithlevels").getMessage());
|
||||
ArrayList<String> loreXP = new ArrayList<>();
|
||||
if (nextTier != null)
|
||||
loreXP.add(plugin.getLocale().getMessage("interface.spawner.upgradewithlevelslore")
|
||||
if (this.nextTier != null) {
|
||||
loreXP.add(this.plugin.getLocale().getMessage("interface.spawner.upgradewithlevelslore")
|
||||
.processPlaceholder("cost", Double.toString(levelsCost)).getMessage());
|
||||
else
|
||||
loreXP.add(plugin.getLocale().getMessage("event.upgrade.maxed").getMessage());
|
||||
} else {
|
||||
loreXP.add(this.plugin.getLocale().getMessage("event.upgrade.maxed").getMessage());
|
||||
}
|
||||
itemmetaXP.setLore(loreXP);
|
||||
itemLevels.setItemMeta(itemmetaXP);
|
||||
|
||||
ItemStack itemECO = Settings.ECO_ICON.getMaterial().parseItem();
|
||||
ItemMeta itemmetaECO = itemECO.getItemMeta();
|
||||
itemmetaECO.setDisplayName(plugin.getLocale().getMessage("interface.spawner.upgradewitheconomy").getMessage());
|
||||
itemmetaECO.setDisplayName(this.plugin.getLocale().getMessage("interface.spawner.upgradewitheconomy").getMessage());
|
||||
ArrayList<String> loreECO = new ArrayList<>();
|
||||
if (nextTier != null)
|
||||
loreECO.add(plugin.getLocale().getMessage("interface.spawner.upgradewitheconomylore")
|
||||
if (this.nextTier != null) {
|
||||
loreECO.add(this.plugin.getLocale().getMessage("interface.spawner.upgradewitheconomylore")
|
||||
.processPlaceholder("cost", EconomyManager.formatEconomy(economyCost)).getMessage());
|
||||
else
|
||||
loreECO.add(plugin.getLocale().getMessage("event.upgrade.maxed").getMessage());
|
||||
} else {
|
||||
loreECO.add(this.plugin.getLocale().getMessage("event.upgrade.maxed").getMessage());
|
||||
}
|
||||
itemmetaECO.setLore(loreECO);
|
||||
itemECO.setItemMeta(itemmetaECO);
|
||||
|
||||
setItem("spawner",13, spawnerItem);
|
||||
setItem("spawner", 13, spawnerItem);
|
||||
|
||||
if (player.hasPermission("epicspawners.convert") && data.isConvertible()) {
|
||||
if (this.player.hasPermission("epicspawners.convert") && this.data.isConvertible()) {
|
||||
setButton("convert", 4, GuiUtils.createButtonItem(Settings.CONVERT_ICON.getMaterial(),
|
||||
plugin.getLocale().getMessage("interface.spawner.convert").getMessage()),
|
||||
(event) -> guiManager.showGUI(player, new SpawnerConvertGui(plugin, stack, player)));
|
||||
this.plugin.getLocale().getMessage("interface.spawner.convert").getMessage()),
|
||||
(event) -> this.guiManager.showGUI(this.player, new SpawnerConvertGui(this.plugin, this.stack, this.player)));
|
||||
}
|
||||
|
||||
if (spawner.getSpawnerStacks().size() == 1)
|
||||
GuiUtils.applyBoosted(22, this, plugin, player, spawner);
|
||||
if (this.spawner.getSpawnerStacks().size() == 1) {
|
||||
GuiUtils.applyBoosted(22, this, this.plugin, this.player, this.spawner);
|
||||
}
|
||||
|
||||
if (Settings.DISPLAY_HELP_BUTTON.getBoolean()) {
|
||||
ItemStack itemO = new ItemStack(Material.PAPER, 1);
|
||||
ItemMeta itemmetaO = itemO.getItemMeta();
|
||||
itemmetaO.setDisplayName(plugin.getLocale().getMessage("interface.spawner.tutorialtitle").getMessage());
|
||||
itemmetaO.setDisplayName(this.plugin.getLocale().getMessage("interface.spawner.tutorialtitle").getMessage());
|
||||
ArrayList<String> loreO = new ArrayList<>();
|
||||
String text = plugin.getLocale().getMessage("interface.spawner.tutorial").getMessage();
|
||||
String text = this.plugin.getLocale().getMessage("interface.spawner.tutorial").getMessage();
|
||||
|
||||
int start = (14 * infoPage) - 14;
|
||||
int start = (14 * this.infoPage) - 14;
|
||||
int li = 1; // 12
|
||||
int added = 0;
|
||||
boolean max = false;
|
||||
|
||||
String[] parts = text.split("\\|");
|
||||
for (String line : parts) {
|
||||
line = compileHow(player, line);
|
||||
if (line.equals(".") || line.isEmpty()) continue;
|
||||
line = compileHow(this.player, line);
|
||||
if (line.equals(".") || line.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Matcher m = REGEX.matcher(line);
|
||||
while (m.find()) {
|
||||
@ -226,56 +232,61 @@ public class SpawnerOverviewGui extends CustomizableGui {
|
||||
}
|
||||
|
||||
if (max) {
|
||||
loreO.add(plugin.getLocale().getMessage("interface.spawner.howtonext").getMessage());
|
||||
loreO.add(this.plugin.getLocale().getMessage("interface.spawner.howtonext").getMessage());
|
||||
} else {
|
||||
loreO.add(plugin.getLocale().getMessage("interface.spawner.howtoback").getMessage());
|
||||
loreO.add(this.plugin.getLocale().getMessage("interface.spawner.howtoback").getMessage());
|
||||
}
|
||||
|
||||
itemmetaO.setLore(loreO);
|
||||
itemO.setItemMeta(itemmetaO);
|
||||
setButton("info",8, itemO,
|
||||
setButton("info", 8, itemO,
|
||||
event -> {
|
||||
this.infoPage++;
|
||||
addInfo();
|
||||
});
|
||||
}
|
||||
if (!onlyOneTier) {
|
||||
if (Settings.UPGRADE_WITH_LEVELS_ENABLED.getBoolean())
|
||||
if (!this.onlyOneTier) {
|
||||
if (Settings.UPGRADE_WITH_LEVELS_ENABLED.getBoolean()) {
|
||||
setButton("levels", 11, itemLevels, event -> {
|
||||
stack.upgrade(player, CostType.LEVELS);
|
||||
spawner.overview(player);
|
||||
this.stack.upgrade(this.player, CostType.LEVELS);
|
||||
this.spawner.overview(this.player);
|
||||
});
|
||||
if (Settings.UPGRADE_WITH_ECONOMY_ENABLED.getBoolean())
|
||||
}
|
||||
if (Settings.UPGRADE_WITH_ECONOMY_ENABLED.getBoolean()) {
|
||||
setButton("economy", 15, itemECO, event -> {
|
||||
stack.upgrade(player, CostType.ECONOMY);
|
||||
spawner.overview(player);
|
||||
this.stack.upgrade(this.player, CostType.ECONOMY);
|
||||
this.spawner.overview(this.player);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void runTask() {
|
||||
task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, () -> {
|
||||
if (inventory != null && inventory.getViewers().size() != 0)
|
||||
this.task = Bukkit.getScheduler().scheduleSyncRepeatingTask(this.plugin, () -> {
|
||||
if (this.inventory != null && !this.inventory.getViewers().isEmpty()) {
|
||||
paint();
|
||||
}
|
||||
}, 5L, 5L);
|
||||
}
|
||||
|
||||
private void addInfo() {
|
||||
ItemStack itemO = new ItemStack(Material.PAPER, 1);
|
||||
ItemMeta itemmetaO = itemO.getItemMeta();
|
||||
itemmetaO.setDisplayName(plugin.getLocale().getMessage("interface.spawner.tutorialtitle").getMessage());
|
||||
itemmetaO.setDisplayName(this.plugin.getLocale().getMessage("interface.spawner.tutorialtitle").getMessage());
|
||||
List<String> loreO = new ArrayList<>();
|
||||
String text = plugin.getLocale().getMessage("interface.spawner.tutorial").getMessage();
|
||||
String text = this.plugin.getLocale().getMessage("interface.spawner.tutorial").getMessage();
|
||||
|
||||
int start = (14 * infoPage) - 14;
|
||||
int start = (14 * this.infoPage) - 14;
|
||||
int li = 1; // 12
|
||||
int added = 0;
|
||||
boolean max = false;
|
||||
|
||||
String[] parts = text.split("\\|");
|
||||
for (String line : parts) {
|
||||
line = compileHow(player, line);
|
||||
if (line.equals(".") || line.isEmpty()) continue;
|
||||
line = compileHow(this.player, line);
|
||||
if (line.equals(".") || line.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Matcher m = REGEX.matcher(line);
|
||||
while (m.find()) {
|
||||
@ -298,9 +309,9 @@ public class SpawnerOverviewGui extends CustomizableGui {
|
||||
}
|
||||
|
||||
if (max) {
|
||||
loreO.add(plugin.getLocale().getMessage("interface.spawner.howtonext").getMessage());
|
||||
loreO.add(this.plugin.getLocale().getMessage("interface.spawner.howtonext").getMessage());
|
||||
} else {
|
||||
loreO.add(plugin.getLocale().getMessage("interface.spawner.howtoback").getMessage());
|
||||
loreO.add(this.plugin.getLocale().getMessage("interface.spawner.howtoback").getMessage());
|
||||
}
|
||||
|
||||
itemmetaO.setLore(loreO);
|
||||
@ -323,7 +334,7 @@ public class SpawnerOverviewGui extends CustomizableGui {
|
||||
switch (type) {
|
||||
case "LEVELUP":
|
||||
if (nu == 1) {
|
||||
if (!p.hasPermission("epicspawners.combine." + data.getIdentifyingName()) && !p.hasPermission("epicspawners.combine." + data.getIdentifyingName())) {
|
||||
if (!p.hasPermission("epicspawners.combine." + this.data.getIdentifyingName()) && !p.hasPermission("epicspawners.combine." + this.data.getIdentifyingName())) {
|
||||
text = text.replace(mi.group(), "");
|
||||
} else {
|
||||
text = text.replace(mi.group(), a(a, mi.group()));
|
||||
@ -376,12 +387,13 @@ public class SpawnerOverviewGui extends CustomizableGui {
|
||||
if (!Settings.MOB_KILLING_COUNT.getBoolean() || !p.hasPermission("epicspawners.Killcounter")) {
|
||||
text = "";
|
||||
} else {
|
||||
text = text.replace("<TYPE>", tier.getDisplayName().toLowerCase());
|
||||
stack.getSpawnerData().getKillDropGoal();
|
||||
if (stack.getSpawnerData().getKillDropGoal() != 0)
|
||||
text = text.replace("<AMT>", Integer.toString(stack.getSpawnerData().getKillDropGoal()));
|
||||
else
|
||||
text = text.replace("<TYPE>", this.tier.getDisplayName().toLowerCase());
|
||||
this.stack.getSpawnerData().getKillDropGoal();
|
||||
if (this.stack.getSpawnerData().getKillDropGoal() != 0) {
|
||||
text = text.replace("<AMT>", Integer.toString(this.stack.getSpawnerData().getKillDropGoal()));
|
||||
} else {
|
||||
text = text.replace("<AMT>", Integer.toString(Settings.KILL_DROP_GOAL.getInt()));
|
||||
}
|
||||
}
|
||||
if (nu == 1) {
|
||||
if (Settings.COUNT_UNNATURAL_KILLS.getBoolean()) {
|
||||
@ -403,5 +415,4 @@ public class SpawnerOverviewGui extends CustomizableGui {
|
||||
private String a(int a, String text) {
|
||||
return (a != 0 ? ", " : "") + text;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,14 @@
|
||||
package com.craftaro.epicspawners.gui;
|
||||
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.gui.CustomizableGui;
|
||||
import com.craftaro.core.gui.GuiUtils;
|
||||
import com.craftaro.core.hooks.EconomyManager;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.utils.TextUtils;
|
||||
import com.craftaro.epicspawners.EpicSpawners;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerData;
|
||||
import com.craftaro.epicspawners.settings.Settings;
|
||||
import com.craftaro.epicspawners.spawners.spawner.SpawnerDataImpl;
|
||||
import com.craftaro.epicspawners.api.utils.HeadUtils;
|
||||
import com.craftaro.epicspawners.settings.Settings;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -21,7 +20,6 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class SpawnerShopGui extends CustomizableGui {
|
||||
|
||||
private final EpicSpawners plugin;
|
||||
private final Player player;
|
||||
private final List<SpawnerData> entities = new ArrayList<>();
|
||||
@ -35,9 +33,10 @@ public class SpawnerShopGui extends CustomizableGui {
|
||||
for (SpawnerData spawnerData : plugin.getSpawnerManager().getAllSpawnerData()) {
|
||||
if (!spawnerData.isInShop()
|
||||
|| !spawnerData.isActive()
|
||||
|| !player.hasPermission("epicspawners.shop." + spawnerData.getIdentifyingName().replace(" ", "_")))
|
||||
|| !player.hasPermission("epicspawners.shop." + spawnerData.getIdentifyingName().replace(" ", "_"))) {
|
||||
continue;
|
||||
entities.add(spawnerData);
|
||||
}
|
||||
this.entities.add(spawnerData);
|
||||
}
|
||||
|
||||
setTitle(plugin.getLocale().getMessage("interface.shop.title").getMessage());
|
||||
@ -60,52 +59,54 @@ public class SpawnerShopGui extends CustomizableGui {
|
||||
mirrorFill("mirrorfill_4", 1, 0, true, true, glass2);
|
||||
mirrorFill("mirrorfill_5", 0, 1, true, true, glass2);
|
||||
|
||||
pages = (int) Math.max(1, Math.ceil(entities.size() / ((double) 28)));
|
||||
this.pages = (int) Math.max(1, Math.ceil(this.entities.size() / ((double) 28)));
|
||||
|
||||
// enable page event
|
||||
setNextPage(5, 7, GuiUtils.createButtonItem(XMaterial.ARROW, plugin.getLocale().getMessage("general.nametag.next").getMessage()));
|
||||
setPrevPage(5, 1, GuiUtils.createButtonItem(XMaterial.ARROW, plugin.getLocale().getMessage("general.nametag.back").getMessage()));
|
||||
setNextPage(5, 7, GuiUtils.createButtonItem(XMaterial.ARROW, this.plugin.getLocale().getMessage("general.nametag.next").getMessage()));
|
||||
setPrevPage(5, 1, GuiUtils.createButtonItem(XMaterial.ARROW, this.plugin.getLocale().getMessage("general.nametag.back").getMessage()));
|
||||
setOnPage((event) -> showPage());
|
||||
|
||||
// Sort entities by their shopOrder val
|
||||
entities.sort(Comparator.comparingInt(SpawnerData::getShopOrder));
|
||||
this.entities.sort(Comparator.comparingInt(SpawnerData::getShopOrder));
|
||||
|
||||
List<SpawnerData> data = entities.stream().skip((page - 1) * 28).limit(28).collect(Collectors.toList());
|
||||
List<SpawnerData> data = this.entities.stream().skip((this.page - 1) * 28).limit(28).collect(Collectors.toList());
|
||||
|
||||
int num = 11;
|
||||
for (SpawnerData spawnerData : data) {
|
||||
if (num == 16 || num == 36)
|
||||
if (num == 16 || num == 36) {
|
||||
num = num + 2;
|
||||
}
|
||||
|
||||
ItemStack item = HeadUtils.getTexturedSkull(spawnerData);
|
||||
|
||||
if (spawnerData.getDisplayItem() != null) {
|
||||
XMaterial mat = spawnerData.getDisplayItem();
|
||||
if (!mat.equals(XMaterial.AIR))
|
||||
if (mat != XMaterial.AIR) {
|
||||
item = mat.parseItem();
|
||||
}
|
||||
}
|
||||
|
||||
ItemMeta itemmeta = item.getItemMeta();
|
||||
String name = spawnerData.getFirstTier().getCompiledDisplayName();
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
double price = spawnerData.getShopPrice();
|
||||
lore.add(TextUtils.formatText(plugin.getLocale().getMessage("interface.shop.buyprice")
|
||||
lore.add(TextUtils.formatText(this.plugin.getLocale().getMessage("interface.shop.buyprice")
|
||||
.processPlaceholder("cost", EconomyManager.formatEconomy(price)).getMessage()));
|
||||
String loreString = plugin.getLocale().getMessage("interface.shop.lore").getMessage();
|
||||
String loreString = this.plugin.getLocale().getMessage("interface.shop.lore").getMessage();
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
|
||||
loreString = me.clip.placeholderapi.PlaceholderAPI.setPlaceholders(player, loreString.replace(" ", "_")).replace("_", " ");
|
||||
loreString = me.clip.placeholderapi.PlaceholderAPI.setPlaceholders(this.player, loreString.replace(" ", "_")).replace("_", " ");
|
||||
}
|
||||
lore.add(loreString);
|
||||
itemmeta.setLore(lore);
|
||||
itemmeta.setDisplayName(name);
|
||||
item.setItemMeta(itemmeta);
|
||||
setButton(num, item, event ->
|
||||
guiManager.showGUI(player, new SpawnerShopItemGui(plugin, spawnerData.getFirstTier(), this)));
|
||||
this.guiManager.showGUI(this.player, new SpawnerShopItemGui(this.plugin, spawnerData.getFirstTier(), this)));
|
||||
num++;
|
||||
}
|
||||
|
||||
setButton("exit", 8, GuiUtils.createButtonItem(Settings.EXIT_ICON.getMaterial(),
|
||||
plugin.getLocale().getMessage("general.nametag.exit").getMessage()),
|
||||
event -> player.closeInventory());
|
||||
this.plugin.getLocale().getMessage("general.nametag.exit").getMessage()),
|
||||
event -> this.player.closeInventory());
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,16 @@
|
||||
package com.craftaro.epicspawners.gui;
|
||||
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.gui.CustomizableGui;
|
||||
import com.craftaro.core.gui.Gui;
|
||||
import com.craftaro.core.gui.GuiUtils;
|
||||
import com.craftaro.core.hooks.EconomyManager;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.utils.ItemUtils;
|
||||
import com.craftaro.epicspawners.EpicSpawners;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerData;
|
||||
import com.craftaro.epicspawners.settings.Settings;
|
||||
import com.craftaro.epicspawners.spawners.spawner.SpawnerDataImpl;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerTier;
|
||||
import com.craftaro.epicspawners.api.utils.HeadUtils;
|
||||
import com.craftaro.epicspawners.settings.Settings;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
@ -20,7 +19,6 @@ import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
public class SpawnerShopItemGui extends CustomizableGui {
|
||||
|
||||
private final EpicSpawners plugin;
|
||||
private final SpawnerTier spawnerTier;
|
||||
private final SpawnerData spawnerData;
|
||||
@ -58,52 +56,52 @@ public class SpawnerShopItemGui extends CustomizableGui {
|
||||
mirrorFill("mirrorfill_4", 1, 0, true, true, glass2);
|
||||
mirrorFill("mirrorfill_5", 0, 1, true, true, glass2);
|
||||
|
||||
double price = spawnerData.getShopPrice() * amount;
|
||||
double price = this.spawnerData.getShopPrice() * this.amount;
|
||||
|
||||
ItemStack item = HeadUtils.getTexturedSkull(spawnerData);
|
||||
ItemStack item = HeadUtils.getTexturedSkull(this.spawnerData);
|
||||
|
||||
if (spawnerData.getDisplayItem() != null) {
|
||||
XMaterial mat = spawnerData.getDisplayItem();
|
||||
if (this.spawnerData.getDisplayItem() != null) {
|
||||
XMaterial mat = this.spawnerData.getDisplayItem();
|
||||
if (!mat.equals(XMaterial.AIR))
|
||||
item = mat.parseItem();
|
||||
}
|
||||
|
||||
item.setAmount(amount);
|
||||
item.setAmount(this.amount);
|
||||
ItemMeta itemmeta = item.getItemMeta();
|
||||
String name = spawnerData.getFirstTier().getCompiledDisplayName();
|
||||
String name = this.spawnerData.getFirstTier().getCompiledDisplayName();
|
||||
itemmeta.setDisplayName(name);
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
lore.add(plugin.getLocale().getMessage("interface.shop.buyprice")
|
||||
lore.add(this.plugin.getLocale().getMessage("interface.shop.buyprice")
|
||||
.processPlaceholder("cost", EconomyManager.formatEconomy(price)).getMessage());
|
||||
itemmeta.setLore(lore);
|
||||
item.setItemMeta(itemmeta);
|
||||
setItem("spawner",22, item);
|
||||
setItem("spawner", 22, item);
|
||||
|
||||
ItemStack plus = XMaterial.LIME_STAINED_GLASS_PANE.parseItem();
|
||||
ItemMeta plusmeta = plus.getItemMeta();
|
||||
plusmeta.setDisplayName(plugin.getLocale().getMessage("interface.shop.add1").getMessage());
|
||||
plusmeta.setDisplayName(this.plugin.getLocale().getMessage("interface.shop.add1").getMessage());
|
||||
plus.setItemMeta(plusmeta);
|
||||
if (item.getAmount() + 1 <= 64) {
|
||||
setButton("add1", 15, plus, event -> {
|
||||
this.amount = amount + 1;
|
||||
this.amount = this.amount + 1;
|
||||
paint();
|
||||
});
|
||||
}
|
||||
|
||||
plus = XMaterial.LIME_STAINED_GLASS_PANE.parseItem();
|
||||
plus.setAmount(10);
|
||||
plusmeta.setDisplayName(plugin.getLocale().getMessage("interface.shop.add10").getMessage());
|
||||
plusmeta.setDisplayName(this.plugin.getLocale().getMessage("interface.shop.add10").getMessage());
|
||||
plus.setItemMeta(plusmeta);
|
||||
if (item.getAmount() + 10 <= 64) {
|
||||
setButton("add10", 33, plus, event -> {
|
||||
this.amount = amount + 10;
|
||||
this.amount = this.amount + 10;
|
||||
paint();
|
||||
});
|
||||
}
|
||||
|
||||
plus = XMaterial.LIME_STAINED_GLASS_PANE.parseItem();
|
||||
plus.setAmount(64);
|
||||
plusmeta.setDisplayName(plugin.getLocale().getMessage("interface.shop.set64").getMessage());
|
||||
plusmeta.setDisplayName(this.plugin.getLocale().getMessage("interface.shop.set64").getMessage());
|
||||
plus.setItemMeta(plusmeta);
|
||||
if (item.getAmount() != 64) {
|
||||
setButton("set64", 25, plus, event -> {
|
||||
@ -115,29 +113,29 @@ public class SpawnerShopItemGui extends CustomizableGui {
|
||||
ItemStack minus = XMaterial.RED_STAINED_GLASS_PANE.parseItem();
|
||||
minus.setAmount(1);
|
||||
ItemMeta minusmeta = minus.getItemMeta();
|
||||
minusmeta.setDisplayName(plugin.getLocale().getMessage("interface.shop.remove1").getMessage());
|
||||
minusmeta.setDisplayName(this.plugin.getLocale().getMessage("interface.shop.remove1").getMessage());
|
||||
minus.setItemMeta(minusmeta);
|
||||
if (item.getAmount() != 1) {
|
||||
setButton("remove1", 11, minus, event -> {
|
||||
this.amount = amount - 1;
|
||||
this.amount = this.amount - 1;
|
||||
paint();
|
||||
});
|
||||
}
|
||||
|
||||
minus = XMaterial.RED_STAINED_GLASS_PANE.parseItem();
|
||||
minus.setAmount(10);
|
||||
minusmeta.setDisplayName(plugin.getLocale().getMessage("interface.shop.remove10").getMessage());
|
||||
minusmeta.setDisplayName(this.plugin.getLocale().getMessage("interface.shop.remove10").getMessage());
|
||||
minus.setItemMeta(minusmeta);
|
||||
if (item.getAmount() - 10 >= 0) {
|
||||
setButton("remove10", 29, minus, event -> {
|
||||
this.amount = amount - 10;
|
||||
this.amount = this.amount - 10;
|
||||
paint();
|
||||
});
|
||||
}
|
||||
|
||||
minus = XMaterial.RED_STAINED_GLASS_PANE.parseItem();
|
||||
minus.setAmount(1);
|
||||
minusmeta.setDisplayName(plugin.getLocale().getMessage("interface.shop.set1").getMessage());
|
||||
minusmeta.setDisplayName(this.plugin.getLocale().getMessage("interface.shop.set1").getMessage());
|
||||
minus.setItemMeta(minusmeta);
|
||||
if (item.getAmount() != 1) {
|
||||
setButton("set1", 19, minus, event -> {
|
||||
@ -147,16 +145,16 @@ public class SpawnerShopItemGui extends CustomizableGui {
|
||||
}
|
||||
|
||||
setButton("exit", 8, GuiUtils.createButtonItem(Settings.EXIT_ICON.getMaterial(),
|
||||
plugin.getLocale().getMessage("general.nametag.exit").getMessage()), event -> event.player.closeInventory());
|
||||
this.plugin.getLocale().getMessage("general.nametag.exit").getMessage()), event -> event.player.closeInventory());
|
||||
|
||||
setButton("back", 0, GuiUtils.createButtonItem(ItemUtils.getCustomHead("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23"),
|
||||
plugin.getLocale().getMessage("general.nametag.back").getMessage()),
|
||||
event -> guiManager.showGUI(event.player, back));
|
||||
this.plugin.getLocale().getMessage("general.nametag.back").getMessage()),
|
||||
event -> this.guiManager.showGUI(event.player, this.back));
|
||||
|
||||
setButton("buy", 40, GuiUtils.createButtonItem(Settings.BUY_ICON.getMaterial(),
|
||||
plugin.getLocale().getMessage("general.nametag.confirm").getMessage()), event -> {
|
||||
this.plugin.getLocale().getMessage("general.nametag.confirm").getMessage()), event -> {
|
||||
Player player = event.player;
|
||||
confirm(player, amount);
|
||||
confirm(player, this.amount);
|
||||
player.closeInventory();
|
||||
}
|
||||
);
|
||||
@ -168,18 +166,18 @@ public class SpawnerShopItemGui extends CustomizableGui {
|
||||
return;
|
||||
}
|
||||
|
||||
double price = spawnerData.getShopPrice() * amount;
|
||||
double price = this.spawnerData.getShopPrice() * amount;
|
||||
if (!EconomyManager.hasBalance(player, price)) {
|
||||
plugin.getLocale().getMessage("event.shop.cannotafford").sendPrefixedMessage(player);
|
||||
this.plugin.getLocale().getMessage("event.shop.cannotafford").sendPrefixedMessage(player);
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack item = spawnerTier.toItemStack(amount);
|
||||
ItemStack item = this.spawnerTier.toItemStack(amount);
|
||||
Map<Integer, ItemStack> overfilled = player.getInventory().addItem(item);
|
||||
for (ItemStack item2 : overfilled.values()) {
|
||||
player.getWorld().dropItemNaturally(player.getLocation(), item2);
|
||||
}
|
||||
plugin.getLocale().getMessage("event.shop.purchasesuccess").sendPrefixedMessage(player);
|
||||
this.plugin.getLocale().getMessage("event.shop.purchasesuccess").sendPrefixedMessage(player);
|
||||
EconomyManager.withdrawBalance(player, price);
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,13 @@
|
||||
package com.craftaro.epicspawners.gui;
|
||||
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.gui.CustomizableGui;
|
||||
import com.craftaro.core.gui.GuiUtils;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.utils.TextUtils;
|
||||
import com.craftaro.epicspawners.EpicSpawners;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerData;
|
||||
import com.craftaro.epicspawners.settings.Settings;
|
||||
import com.craftaro.epicspawners.spawners.spawner.SpawnerDataImpl;
|
||||
import com.craftaro.epicspawners.api.utils.HeadUtils;
|
||||
import com.craftaro.epicspawners.settings.Settings;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -21,7 +20,6 @@ import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class SpawnerStatsGui extends CustomizableGui {
|
||||
|
||||
private final EpicSpawners plugin;
|
||||
private final Player player;
|
||||
private final Map<SpawnerData, Integer> entities = new HashMap<>();
|
||||
@ -34,8 +32,9 @@ public class SpawnerStatsGui extends CustomizableGui {
|
||||
|
||||
for (Map.Entry<EntityType, Integer> entry : plugin.getPlayerDataManager().getPlayerData(player).getEntityKills().entrySet()) {
|
||||
SpawnerData data = plugin.getSpawnerManager().getSpawnerData(entry.getKey());
|
||||
if (data.isActive())
|
||||
entities.put(data, entry.getValue());
|
||||
if (data.isActive()) {
|
||||
this.entities.put(data, entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
setTitle(plugin.getLocale().getMessage("interface.spawnerstats.title").getMessage());
|
||||
@ -58,30 +57,33 @@ public class SpawnerStatsGui extends CustomizableGui {
|
||||
mirrorFill("mirrorfill_4", 1, 0, true, true, glass2);
|
||||
mirrorFill("mirrorfill_5", 0, 1, true, true, glass2);
|
||||
|
||||
pages = (int) Math.max(1, Math.ceil(entities.size() / ((double) 28)));
|
||||
this.pages = (int) Math.max(1, Math.ceil(this.entities.size() / ((double) 28)));
|
||||
|
||||
// enable page event
|
||||
setNextPage(5, 7, GuiUtils.createButtonItem(XMaterial.ARROW, plugin.getLocale().getMessage("general.nametag.next").getMessage()));
|
||||
setPrevPage(5, 1, GuiUtils.createButtonItem(XMaterial.ARROW, plugin.getLocale().getMessage("general.nametag.back").getMessage()));
|
||||
setNextPage(5, 7, GuiUtils.createButtonItem(XMaterial.ARROW, this.plugin.getLocale().getMessage("general.nametag.next").getMessage()));
|
||||
setPrevPage(5, 1, GuiUtils.createButtonItem(XMaterial.ARROW, this.plugin.getLocale().getMessage("general.nametag.back").getMessage()));
|
||||
setOnPage((event) -> showPage());
|
||||
|
||||
setButton("exit", 8, GuiUtils.createButtonItem(XMaterial.valueOf(plugin.getConfig().getString("Interfaces.Exit Icon")),
|
||||
plugin.getLocale().getMessage("general.nametag.exit").getMessage()), (event) -> player.closeInventory());
|
||||
setButton("exit", 8, GuiUtils.createButtonItem(XMaterial.valueOf(this.plugin.getConfig().getString("Interfaces.Exit Icon")),
|
||||
this.plugin.getLocale().getMessage("general.nametag.exit").getMessage()), (event) -> this.player.closeInventory());
|
||||
|
||||
Set<Map.Entry<SpawnerData, Integer>> entries = entities.entrySet().stream().skip((page - 1) * 28).limit(28)
|
||||
Set<Map.Entry<SpawnerData, Integer>> entries = this.entities.entrySet().stream().skip((this.page - 1) * 28).limit(28)
|
||||
.sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).collect(Collectors.toCollection(LinkedHashSet::new));
|
||||
|
||||
int num = 11;
|
||||
for (Map.Entry<SpawnerData, Integer> entry : entries) {
|
||||
if (num == 16 || num == 36)
|
||||
if (num == 16 || num == 36) {
|
||||
num = num + 2;
|
||||
}
|
||||
|
||||
int goal = Settings.KILL_DROP_GOAL.getInt();
|
||||
|
||||
SpawnerData spawnerData = entry.getKey();
|
||||
|
||||
int customGoal = spawnerData.getKillDropGoal();
|
||||
if (customGoal != 0) goal = customGoal;
|
||||
if (customGoal != 0) {
|
||||
goal = customGoal;
|
||||
}
|
||||
|
||||
setItem(num, GuiUtils.createButtonItem(HeadUtils.getTexturedSkull(spawnerData),
|
||||
TextUtils.formatText("&6" + spawnerData.getIdentifyingName() + "&7: &e" + entry.getValue() + "&7/&e" + goal)));
|
||||
|
@ -1,18 +1,17 @@
|
||||
package com.craftaro.epicspawners.gui;
|
||||
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.gui.CustomizableGui;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.utils.NumberUtils;
|
||||
import com.craftaro.core.utils.TextUtils;
|
||||
import com.craftaro.epicspawners.EpicSpawners;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.PlacedSpawner;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerStack;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerTier;
|
||||
import com.craftaro.epicspawners.api.utils.HeadUtils;
|
||||
import com.craftaro.epicspawners.settings.Settings;
|
||||
import com.craftaro.epicspawners.spawners.spawner.PlacedSpawnerImpl;
|
||||
import com.craftaro.epicspawners.spawners.spawner.SpawnerStackImpl;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerTier;
|
||||
import com.craftaro.epicspawners.utils.GuiUtils;
|
||||
import com.craftaro.epicspawners.api.utils.HeadUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -20,7 +19,6 @@ import org.bukkit.inventory.ItemStack;
|
||||
import java.util.List;
|
||||
|
||||
public class SpawnerTiersGui extends CustomizableGui {
|
||||
|
||||
private final EpicSpawners plugin;
|
||||
private final Player player;
|
||||
private final PlacedSpawner spawner;
|
||||
@ -36,7 +34,7 @@ public class SpawnerTiersGui extends CustomizableGui {
|
||||
|
||||
setTitle(plugin.getLocale().getMessage("interface.tiers.title").getMessage());
|
||||
setOnClose(event -> {
|
||||
Bukkit.getScheduler().cancelTask(task);
|
||||
Bukkit.getScheduler().cancelTask(this.task);
|
||||
plugin.getSpawnerManager().saveSpawnerDataToFile();
|
||||
});
|
||||
setDefaultItem(null);
|
||||
@ -61,49 +59,52 @@ public class SpawnerTiersGui extends CustomizableGui {
|
||||
mirrorFill("mirrorfill_4", 1, 0, true, true, glass2);
|
||||
mirrorFill("mirrorfill_5", 0, 1, true, true, glass2);
|
||||
|
||||
List<SpawnerStack> stacks = spawner.getSpawnerStacks();
|
||||
List<SpawnerStack> stacks = this.spawner.getSpawnerStacks();
|
||||
|
||||
int num = 10;
|
||||
for (int i = 0; i < 28; i++) {
|
||||
num++;
|
||||
SpawnerTier tier = i < stacks.size() ? stacks.get(i).getCurrentTier() : null;
|
||||
if (num == 16 || num == 36)
|
||||
if (num == 16 || num == 36) {
|
||||
num = num + 2;
|
||||
}
|
||||
|
||||
if (tier == null)
|
||||
if (tier == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (acceptsItems) {
|
||||
if (this.acceptsItems) {
|
||||
setItem(num, GuiUtils.createButtonItem(tier.getDisplayItem() == XMaterial.AIR ? XMaterial.DIRT : tier.getDisplayItem(),
|
||||
tier.getIdentifyingName()));
|
||||
} else {
|
||||
SpawnerStack stack = stacks.get(i);
|
||||
XMaterial material = tier.getDisplayItem();
|
||||
setButton(num, GuiUtils.createButtonItem(material == null || material.equals(XMaterial.AIR) ? HeadUtils.getTexturedSkull(tier) : tier.getDisplayItem().parseItem(),
|
||||
TextUtils.formatText(tier.getCompiledDisplayName(false, stack.getStackSize()))),
|
||||
(event) -> plugin.getGuiManager().showGUI(player, new SpawnerOverviewGui(plugin, stack, player)));
|
||||
setButton(num, GuiUtils.createButtonItem(material == null || material == XMaterial.AIR ? HeadUtils.getTexturedSkull(tier) : tier.getDisplayItem().parseItem(),
|
||||
TextUtils.formatText(tier.getCompiledDisplayName(false, stack.getStackSize()))),
|
||||
(event) -> this.plugin.getGuiManager().showGUI(this.player, new SpawnerOverviewGui(this.plugin, stack, this.player)));
|
||||
}
|
||||
}
|
||||
|
||||
GuiUtils.applyBoosted(5, this, plugin, player, spawner);
|
||||
GuiUtils.applyBoosted(5, this, this.plugin, this.player, this.spawner);
|
||||
|
||||
setItem("stats", 3, GuiUtils.createButtonItem(XMaterial.PAPER, plugin.getLocale().getMessage("interface.spawner.statstitle").getMessage(),
|
||||
plugin.getLocale().getMessage("interface.spawner.stats")
|
||||
.processPlaceholder("amount", NumberUtils.formatNumber(spawner.getSpawnCount())).getMessage()));
|
||||
setItem("stats", 3, GuiUtils.createButtonItem(XMaterial.PAPER, this.plugin.getLocale().getMessage("interface.spawner.statstitle").getMessage(),
|
||||
this.plugin.getLocale().getMessage("interface.spawner.stats")
|
||||
.processPlaceholder("amount", NumberUtils.formatNumber(this.spawner.getSpawnCount())).getMessage()));
|
||||
}
|
||||
|
||||
private void runTask() {
|
||||
task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, () -> {
|
||||
if (inventory != null && inventory.getViewers().size() != 0)
|
||||
this.task = Bukkit.getScheduler().scheduleSyncRepeatingTask(this.plugin, () -> {
|
||||
if (this.inventory != null && !this.inventory.getViewers().isEmpty()) {
|
||||
paint();
|
||||
}
|
||||
}, 5L, 5L);
|
||||
}
|
||||
|
||||
public static void openTiers(EpicSpawners plugin, Player player, PlacedSpawnerImpl spawner) {
|
||||
if (spawner.getSpawnerStacks().size() == 1)
|
||||
if (spawner.getSpawnerStacks().size() == 1) {
|
||||
plugin.getGuiManager().showGUI(player, new SpawnerOverviewGui(plugin, spawner.getFirstStack(), player));
|
||||
else
|
||||
} else {
|
||||
plugin.getGuiManager().showGUI(player, new SpawnerTiersGui(plugin, player, spawner));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
package com.craftaro.epicspawners.listeners;
|
||||
|
||||
import com.craftaro.core.compatibility.CompatibleHand;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.compatibility.ServerVersion;
|
||||
import com.craftaro.core.hooks.EconomyManager;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.utils.ItemUtils;
|
||||
import com.craftaro.core.utils.PlayerUtils;
|
||||
import com.craftaro.core.world.SItemStack;
|
||||
@ -32,11 +32,7 @@ import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockFromToEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
|
||||
/**
|
||||
* Created by songoda on 2/25/2017.
|
||||
*/
|
||||
public class BlockListeners implements Listener {
|
||||
|
||||
private final EpicSpawners plugin;
|
||||
|
||||
public BlockListeners(EpicSpawners plugin) {
|
||||
@ -46,13 +42,19 @@ public class BlockListeners implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockFromTo(BlockFromToEvent e) {
|
||||
if (doLiquidRepel(e.getBlock(), false)) e.setCancelled(true);
|
||||
if (doLiquidRepel(e.getBlock(), false)) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean doLiquidRepel(Block block, boolean from) {
|
||||
int radius = Settings.LIQUID_REPEL_RADIUS.getInt();
|
||||
if (radius == 0) return false;
|
||||
if (!from) radius++;
|
||||
if (radius == 0) {
|
||||
return false;
|
||||
}
|
||||
if (!from) {
|
||||
radius++;
|
||||
}
|
||||
int bx = block.getX();
|
||||
int by = block.getY();
|
||||
int bz = block.getZ();
|
||||
@ -62,12 +64,13 @@ public class BlockListeners implements Listener {
|
||||
Block foundBlock = block.getWorld().getBlockAt(bx + fx, by + fy, bz + fz);
|
||||
|
||||
if (from) {
|
||||
if ((foundBlock.getType().equals(Material.LAVA) || foundBlock.getType().equals(Material.LAVA))
|
||||
|| (foundBlock.getType().equals(Material.WATER) || foundBlock.getType().equals(Material.WATER))) {
|
||||
if ((foundBlock.getType() == Material.LAVA || foundBlock.getType() == Material.LAVA)
|
||||
|| (foundBlock.getType() == Material.WATER || foundBlock.getType() == Material.WATER)) {
|
||||
foundBlock.setType(Material.AIR);
|
||||
}
|
||||
} else if (XMaterial.matchXMaterial(foundBlock.getType().name()).get() == XMaterial.SPAWNER)
|
||||
} else if (XMaterial.matchXMaterial(foundBlock.getType().name()).get() == XMaterial.SPAWNER) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -76,9 +79,11 @@ public class BlockListeners implements Listener {
|
||||
|
||||
private boolean doForceCombine(Player player, PlacedSpawnerImpl placedSpawner, BlockPlaceEvent event) {
|
||||
int forceCombineRadius = Settings.FORCE_COMBINE_RADIUS.getInt();
|
||||
if (forceCombineRadius == 0) return false;
|
||||
if (forceCombineRadius == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (PlacedSpawner spawner : plugin.getSpawnerManager().getSpawners()) {
|
||||
for (PlacedSpawner spawner : this.plugin.getSpawnerManager().getSpawners()) {
|
||||
if (spawner.getLocation().getWorld() == null
|
||||
|| spawner.getLocation().getWorld() != placedSpawner.getLocation().getWorld()
|
||||
|| spawner.getLocation() == placedSpawner.getLocation()
|
||||
@ -88,12 +93,13 @@ public class BlockListeners implements Listener {
|
||||
}
|
||||
|
||||
CompatibleHand hand = CompatibleHand.getHand(event);
|
||||
if (Settings.FORCE_COMBINE_DENY.getBoolean())
|
||||
plugin.getLocale().getMessage("event.block.forcedeny").sendPrefixedMessage(player);
|
||||
else if (spawner.stack(player, plugin.getSpawnerManager().getSpawnerTier(hand.getItem(player)), placedSpawner.getStackSize(), hand)) {
|
||||
plugin.getLocale().getMessage("event.block.mergedistance").sendPrefixedMessage(player);
|
||||
if (hand == CompatibleHand.OFF_HAND)
|
||||
if (Settings.FORCE_COMBINE_DENY.getBoolean()) {
|
||||
this.plugin.getLocale().getMessage("event.block.forcedeny").sendPrefixedMessage(player);
|
||||
} else if (spawner.stack(player, this.plugin.getSpawnerManager().getSpawnerTier(hand.getItem(player)), placedSpawner.getStackSize(), hand)) {
|
||||
this.plugin.getLocale().getMessage("event.block.mergedistance").sendPrefixedMessage(player);
|
||||
if (hand == CompatibleHand.OFF_HAND) {
|
||||
ItemUtils.takeActiveItem(player, hand);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -104,10 +110,12 @@ public class BlockListeners implements Listener {
|
||||
int amountFound = 0;
|
||||
int chunkX = spawnerBlock.getX() >> 4;
|
||||
int chunkZ = spawnerBlock.getZ() >> 4;
|
||||
for (PlacedSpawner spawner : plugin.getSpawnerManager().getSpawners()) {
|
||||
for (PlacedSpawner spawner : this.plugin.getSpawnerManager().getSpawners()) {
|
||||
if (spawner.getWorld() != spawnerBlock.getWorld()
|
||||
|| spawner.getX() >> 4 != chunkX
|
||||
|| spawner.getZ() >> 4 != chunkZ) continue;
|
||||
|| spawner.getZ() >> 4 != chunkZ) {
|
||||
continue;
|
||||
}
|
||||
amountFound++;
|
||||
}
|
||||
return amountFound;
|
||||
@ -119,13 +127,17 @@ public class BlockListeners implements Listener {
|
||||
if (!event.isCancelled()) {
|
||||
Block block = event.getBlock();
|
||||
if (XMaterial.matchXMaterial(block.getType().name()).get() != XMaterial.SPAWNER
|
||||
|| ((CreatureSpawner) block.getState()).getSpawnedType() == EntityType.FIREWORK) return;
|
||||
|| ((CreatureSpawner) block.getState()).getSpawnedType() == EntityType.FIREWORK) {
|
||||
return;
|
||||
}
|
||||
|
||||
Location location = block.getLocation();
|
||||
PlacedSpawnerImpl spawner = new PlacedSpawnerImpl(block.getLocation());
|
||||
|
||||
SpawnerTier spawnerTier = plugin.getSpawnerManager().getSpawnerTier(event.getItemInHand());
|
||||
if (spawnerTier == null) return;
|
||||
SpawnerTier spawnerTier = this.plugin.getSpawnerManager().getSpawnerTier(event.getItemInHand());
|
||||
if (spawnerTier == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int spawnerStackSize = spawnerTier.getStackSize(event.getItemInHand());
|
||||
SpawnerStack stack = new SpawnerStackImpl(spawner, spawnerTier, spawnerStackSize);
|
||||
@ -136,7 +148,7 @@ public class BlockListeners implements Listener {
|
||||
|
||||
doLiquidRepel(block, true);
|
||||
|
||||
if (plugin.getBlacklistHandler().isBlacklisted(player, true)
|
||||
if (this.plugin.getBlacklistHandler().isBlacklisted(player, true)
|
||||
|| !player.hasPermission("epicspawners.place." + spawnerTier.getSpawnerData().getIdentifyingName().replace(" ", "_"))
|
||||
|| doForceCombine(player, spawner, event)) {
|
||||
event.setCancelled(true);
|
||||
@ -145,25 +157,27 @@ public class BlockListeners implements Listener {
|
||||
|
||||
int maxPerChunk = Settings.MAX_SPAWNERS_PER_CHUNK.getInt();
|
||||
if (maxPerChunk != -1 && getAmountInChunk(block) >= maxPerChunk) {
|
||||
plugin.getLocale().getMessage("event.block.chunklimit")
|
||||
this.plugin.getLocale().getMessage("event.block.chunklimit")
|
||||
.processPlaceholder("amount", maxPerChunk)
|
||||
.sendPrefixedMessage(player);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
int amountPlaced = plugin.getSpawnerManager().getAmountPlaced(player);
|
||||
int amountPlaced = this.plugin.getSpawnerManager().getAmountPlaced(player);
|
||||
int maxSpawners = PlayerUtils.getNumberFromPermission(player, "epicspawners.limit", Settings.MAX_SPAWNERS.getInt());
|
||||
|
||||
if (maxSpawners != -1 && amountPlaced > maxSpawners) {
|
||||
player.sendMessage(plugin.getLocale().getMessage("event.spawner.toomany")
|
||||
player.sendMessage(this.plugin.getLocale().getMessage("event.spawner.toomany")
|
||||
.processPlaceholder("amount", maxSpawners).getMessage());
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
CreatureSpawner creatureSpawner = spawner.getCreatureSpawner();
|
||||
if (creatureSpawner == null) return;
|
||||
if (creatureSpawner == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
SpawnerPlaceEvent placeEvent = new SpawnerPlaceEvent(player, spawner);
|
||||
Bukkit.getPluginManager().callEvent(placeEvent);
|
||||
@ -173,15 +187,17 @@ public class BlockListeners implements Listener {
|
||||
}
|
||||
|
||||
|
||||
plugin.getSpawnerManager().addSpawnerToWorld(location, spawner);
|
||||
this.plugin.getSpawnerManager().addSpawnerToWorld(location, spawner);
|
||||
|
||||
if (Settings.ALERT_PLACE_BREAK.getBoolean())
|
||||
plugin.getLocale().getMessage("event.block.place")
|
||||
if (Settings.ALERT_PLACE_BREAK.getBoolean()) {
|
||||
this.plugin.getLocale().getMessage("event.block.place")
|
||||
.processPlaceholder("type", spawnerTier.getCompiledDisplayName(false, spawner.getFirstStack().getStackSize()))
|
||||
.sendPrefixedMessage(player);
|
||||
}
|
||||
|
||||
if (player.getGameMode() == GameMode.CREATIVE && Settings.CHARGE_FOR_CREATIVE.getBoolean())
|
||||
if (player.getGameMode() == GameMode.CREATIVE && Settings.CHARGE_FOR_CREATIVE.getBoolean()) {
|
||||
ItemUtils.takeActiveItem(player, CompatibleHand.getHand(event), 1);
|
||||
}
|
||||
|
||||
try {
|
||||
creatureSpawner.setSpawnedType(spawnerTier.getEntities().get(0));
|
||||
@ -193,16 +209,16 @@ public class BlockListeners implements Listener {
|
||||
spawner.setPlacedBy(player);
|
||||
EpicSpawners.getInstance().getDataManager().save(spawner);
|
||||
|
||||
plugin.processChange(block);
|
||||
plugin.createHologram(spawner);
|
||||
plugin.getAppearanceTask().updateDisplayItem(spawner, spawnerTier);
|
||||
this.plugin.processChange(block);
|
||||
this.plugin.createHologram(spawner);
|
||||
this.plugin.getAppearanceTask().updateDisplayItem(spawner, spawnerTier);
|
||||
return;
|
||||
}
|
||||
|
||||
//ToDo: Probably remove this.
|
||||
Bukkit.getServer().
|
||||
getScheduler().
|
||||
scheduleSyncDelayedTask(plugin, () -> plugin.processChange(event.getBlock()), 10L);
|
||||
scheduleSyncDelayedTask(this.plugin, () -> this.plugin.processChange(event.getBlock()), 10L);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
@ -214,16 +230,18 @@ public class BlockListeners implements Listener {
|
||||
//We are ignoring canceled inside the event so that it will still remove holograms when the event is canceled.
|
||||
if (!event.isCancelled()) {
|
||||
if (XMaterial.matchXMaterial(block.getType().name()).get() != XMaterial.SPAWNER
|
||||
|| ((CreatureSpawner) block.getState()).getSpawnedType() == EntityType.FIREWORK) return;
|
||||
|| ((CreatureSpawner) block.getState()).getSpawnedType() == EntityType.FIREWORK) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.getBlacklistHandler().isBlacklisted(event.getPlayer(), true)) {
|
||||
if (this.plugin.getBlacklistHandler().isBlacklisted(event.getPlayer(), true)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
Location location = block.getLocation();
|
||||
|
||||
if (!plugin.getSpawnerManager().isSpawner(location)) {
|
||||
if (!this.plugin.getSpawnerManager().isSpawner(location)) {
|
||||
//Fixme: Why we want to handle non player placed spawners?
|
||||
// PlacedSpawnerImpl spawner = new PlacedSpawnerImpl(location);
|
||||
//
|
||||
@ -236,12 +254,12 @@ public class BlockListeners implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
PlacedSpawner spawner = plugin.getSpawnerManager().getSpawnerFromWorld(location);
|
||||
PlacedSpawner spawner = this.plugin.getSpawnerManager().getSpawnerFromWorld(location);
|
||||
|
||||
if (spawner.getFirstStack().getSpawnerData() == null) {
|
||||
if (Settings.REMOVE_CORRUPTED_SPAWNERS.getBoolean()) {
|
||||
block.setType(Material.AIR);
|
||||
plugin.getLogger().warning("A corrupted spawner has been removed as its Type no longer exists.");
|
||||
this.plugin.getLogger().warning("A corrupted spawner has been removed as its Type no longer exists.");
|
||||
spawner.destroy();
|
||||
}
|
||||
return;
|
||||
@ -269,22 +287,22 @@ public class BlockListeners implements Listener {
|
||||
|
||||
double cost = spawner.getFirstStack().getCurrentTier().getPickupCost();
|
||||
if (cost != 0.0 && (!naturalOnly || spawner.getPlacedBy() == null)) {
|
||||
if (!plugin.getSpawnerManager().hasCooldown(spawner)) {
|
||||
plugin.getLocale().getMessage("event.block.chargebreak")
|
||||
if (!this.plugin.getSpawnerManager().hasCooldown(spawner)) {
|
||||
this.plugin.getLocale().getMessage("event.block.chargebreak")
|
||||
.processPlaceholder("cost", EconomyManager.formatEconomy(spawner.getFirstStack().getCurrentTier().getPickupCost()))
|
||||
.sendPrefixedMessage(player);
|
||||
plugin.getSpawnerManager().addCooldown(spawner);
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> plugin.getSpawnerManager().removeCooldown(spawner), 300L);
|
||||
this.plugin.getSpawnerManager().addCooldown(spawner);
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, () -> this.plugin.getSpawnerManager().removeCooldown(spawner), 300L);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getSpawnerManager().removeCooldown(spawner);
|
||||
this.plugin.getSpawnerManager().removeCooldown(spawner);
|
||||
|
||||
if (EconomyManager.hasBalance(player, cost)) {
|
||||
EconomyManager.withdrawBalance(player, cost);
|
||||
} else {
|
||||
plugin.getLocale().getMessage("event.block.cannotbreak").sendPrefixedMessage(player);
|
||||
this.plugin.getLocale().getMessage("event.block.cannotbreak").sendPrefixedMessage(player);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -301,10 +319,10 @@ public class BlockListeners implements Listener {
|
||||
}
|
||||
|
||||
if (Settings.ALERT_PLACE_BREAK.getBoolean()) {
|
||||
if (spawner.getSpawnerStacks().size() != 0) {
|
||||
plugin.getLocale().getMessage("event.downgrade.success").processPlaceholder("size", Integer.toString(spawner.getStackSize())).sendPrefixedMessage(player);
|
||||
if (!spawner.getSpawnerStacks().isEmpty()) {
|
||||
this.plugin.getLocale().getMessage("event.downgrade.success").processPlaceholder("size", Integer.toString(spawner.getStackSize())).sendPrefixedMessage(player);
|
||||
} else {
|
||||
plugin.getLocale().getMessage("event.block.break").processPlaceholder("type", firstTier.getCompiledDisplayName(false, currentStackSize)).sendPrefixedMessage(player);
|
||||
this.plugin.getLocale().getMessage("event.block.break").processPlaceholder("type", firstTier.getCompiledDisplayName(false, currentStackSize)).sendPrefixedMessage(player);
|
||||
}
|
||||
}
|
||||
|
||||
@ -313,13 +331,13 @@ public class BlockListeners implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
plugin.updateHologram(spawner);
|
||||
plugin.getAppearanceTask().removeDisplayItem(spawner);
|
||||
this.plugin.updateHologram(spawner);
|
||||
this.plugin.getAppearanceTask().removeDisplayItem(spawner);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//ToDo: Probably remove this.
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> plugin.processChange(block), 10L);
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, () -> this.plugin.processChange(block), 10L);
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ import com.craftaro.epicspawners.api.spawners.spawner.PlacedSpawner;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerData;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerStack;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerTier;
|
||||
import com.craftaro.epicspawners.player.PlayerDataImpl;
|
||||
import com.craftaro.epicspawners.player.PlayerDataManagerImpl;
|
||||
import com.craftaro.epicspawners.settings.Settings;
|
||||
import com.craftaro.ultimatestacker.api.UltimateStackerApi;
|
||||
@ -37,11 +36,7 @@ import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by songoda on 2/25/2017.
|
||||
*/
|
||||
public class EntityListeners implements Listener {
|
||||
|
||||
private final EpicSpawners plugin;
|
||||
|
||||
public EntityListeners(EpicSpawners plugin) {
|
||||
@ -55,22 +50,23 @@ public class EntityListeners implements Listener {
|
||||
List<Block> toCancel = new ArrayList<>();
|
||||
while (it.hasNext()) {
|
||||
Block block = it.next();
|
||||
if (block.getType() != (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.SPAWNER : Material.valueOf("MOB_SPAWNER")))
|
||||
if (block.getType() != (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.SPAWNER : Material.valueOf("MOB_SPAWNER"))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Location spawnLocation = block.getLocation();
|
||||
|
||||
PlacedSpawner spawner = plugin.getSpawnerManager().getSpawnerFromWorld(block.getLocation());
|
||||
PlacedSpawner spawner = this.plugin.getSpawnerManager().getSpawnerFromWorld(block.getLocation());
|
||||
|
||||
if (Settings.SPAWNERS_DONT_EXPLODE.getBoolean())
|
||||
if (Settings.SPAWNERS_DONT_EXPLODE.getBoolean()) {
|
||||
toCancel.add(block);
|
||||
else {
|
||||
|
||||
} else {
|
||||
String chance = "";
|
||||
if (event.getEntity() instanceof Creeper)
|
||||
if (event.getEntity() instanceof Creeper) {
|
||||
chance = Settings.EXPLOSION_DROP_CHANCE_CREEPER.getString();
|
||||
else if (event.getEntity() instanceof TNTPrimed)
|
||||
} else if (event.getEntity() instanceof TNTPrimed) {
|
||||
chance = Settings.EXPLOSION_DROP_CHANCE_TNT.getString();
|
||||
}
|
||||
int ch = Integer.parseInt(chance.replace("%", ""));
|
||||
double rand = Math.random() * 100;
|
||||
if (rand - ch < 0 || ch == 100) {
|
||||
@ -101,38 +97,49 @@ public class EntityListeners implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onDeath(EntityDeathEvent event) {
|
||||
if (event.getEntity().getType() == EntityType.PLAYER) return;
|
||||
if (event.getEntity().getType() == EntityType.PLAYER) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getEntity().hasMetadata("ESData")) {
|
||||
List<MetadataValue> values = event.getEntity().getMetadata("ESData");
|
||||
List<MetadataValue> values2 = event.getEntity().getMetadata("ESTier");
|
||||
if (!values.isEmpty()) {
|
||||
SpawnerData spawnerData = plugin.getSpawnerManager().getSpawnerData(values.get(0).asString());
|
||||
SpawnerData spawnerData = this.plugin.getSpawnerManager().getSpawnerData(values.get(0).asString());
|
||||
SpawnerTier spawnerTier = spawnerData.getTier(values2.get(0).asString());
|
||||
if (plugin.getLootablesManager().getLootManager().getRegisteredLootables().containsKey(spawnerTier.getFullyIdentifyingName())) {
|
||||
List<Drop> drops = plugin.getLootablesManager().getDrops(event.getEntity(), spawnerTier);
|
||||
if (this.plugin.getLootablesManager().getLootManager().getRegisteredLootables().containsKey(spawnerTier.getFullyIdentifyingName())) {
|
||||
List<Drop> drops = this.plugin.getLootablesManager().getDrops(event.getEntity(), spawnerTier);
|
||||
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)
|
||||
&& !event.getEntity().getWorld().getGameRuleValue(GameRule.DO_MOB_LOOT))
|
||||
&& !event.getEntity().getWorld().getGameRuleValue(GameRule.DO_MOB_LOOT)) {
|
||||
drops.clear();
|
||||
}
|
||||
|
||||
DropUtils.processStackedDrop(event.getEntity(), drops, event);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (event.getEntity().getKiller() == null) return;
|
||||
if (event.getEntity().getKiller() == null) {
|
||||
return;
|
||||
}
|
||||
Player player = event.getEntity().getKiller();
|
||||
if (!player.hasPermission("epicspawners.Killcounter") || !Settings.MOB_KILLING_COUNT.getBoolean())
|
||||
if (!player.hasPermission("epicspawners.Killcounter") || !Settings.MOB_KILLING_COUNT.getBoolean()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!plugin.getSpawnManager().isNaturalSpawn(event.getEntity().getUniqueId()) && !Settings.COUNT_UNNATURAL_KILLS.getBoolean())
|
||||
if (!this.plugin.getSpawnManager().isNaturalSpawn(event.getEntity().getUniqueId()) && !Settings.COUNT_UNNATURAL_KILLS.getBoolean()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!plugin.getSpawnerManager().getSpawnerData(event.getEntityType()).isActive()) return;
|
||||
if (!this.plugin.getSpawnerManager().getSpawnerData(event.getEntityType()).isActive()) {
|
||||
return;
|
||||
}
|
||||
|
||||
SpawnerTier spawnerTier = plugin.getSpawnerManager().getSpawnerData(event.getEntityType()).getFirstTier();
|
||||
SpawnerTier spawnerTier = this.plugin.getSpawnerManager().getSpawnerData(event.getEntityType()).getFirstTier();
|
||||
|
||||
if (!spawnerTier.getSpawnerData().isActive()) return;
|
||||
if (!spawnerTier.getSpawnerData().isActive()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int amount = 1;
|
||||
|
||||
@ -142,7 +149,7 @@ public class EntityListeners implements Listener {
|
||||
amount = UltimateStackerApi.getEntityStackManager().getStackedEntity(event.getEntity().getUniqueId()).getAmount();
|
||||
}
|
||||
}
|
||||
PlayerDataManagerImpl playerDataManager = plugin.getPlayerDataManager();
|
||||
PlayerDataManagerImpl playerDataManager = this.plugin.getPlayerDataManager();
|
||||
|
||||
PlayerData playerData = playerDataManager.getPlayerData(player);
|
||||
int amt = playerData.addKilledEntity(event.getEntityType(), amount);
|
||||
@ -151,22 +158,27 @@ public class EntityListeners implements Listener {
|
||||
double chance = Settings.KILL_DROP_CHANCE.getDouble();
|
||||
|
||||
int customGoal = spawnerTier.getSpawnerData().getKillDropGoal();
|
||||
if (customGoal != 0) goal = customGoal;
|
||||
if (customGoal != 0) {
|
||||
goal = customGoal;
|
||||
}
|
||||
|
||||
double customChance = spawnerTier.getSpawnerData().getKillDropChance();
|
||||
if (customChance != 0) chance = customChance;
|
||||
if (customChance != 0) {
|
||||
chance = customChance;
|
||||
}
|
||||
|
||||
if (Settings.ALERT_INTERVAL.getInt() != 0
|
||||
&& amt % Settings.ALERT_INTERVAL.getInt() == 0
|
||||
&& amt != goal) {
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9))
|
||||
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(plugin.getLocale().getMessage("event.goal.alert")
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9)) {
|
||||
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(this.plugin.getLocale().getMessage("event.goal.alert")
|
||||
.processPlaceholder("goal", goal - amt)
|
||||
.processPlaceholder("type", spawnerTier.getDisplayName()).getMessage()));
|
||||
else
|
||||
player.sendTitle("", plugin.getLocale().getMessage("event.goal.alert")
|
||||
} else {
|
||||
player.sendTitle("", this.plugin.getLocale().getMessage("event.goal.alert")
|
||||
.processPlaceholder("goal", goal - amt)
|
||||
.processPlaceholder("type", spawnerTier.getDisplayName()).getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
double rand = Math.random() * 100;
|
||||
@ -174,21 +186,22 @@ public class EntityListeners implements Listener {
|
||||
if (goalReached || rand - chance < 0 || chance == 100) {
|
||||
ItemStack item = spawnerTier.toItemStack();
|
||||
|
||||
if (Settings.SPAWNERS_TO_INVENTORY.getBoolean() && player.getInventory().firstEmpty() != -1)
|
||||
if (Settings.SPAWNERS_TO_INVENTORY.getBoolean() && player.getInventory().firstEmpty() != -1) {
|
||||
player.getInventory().addItem(item);
|
||||
else
|
||||
} else {
|
||||
event.getEntity().getLocation().getWorld().dropItemNaturally(event.getEntity().getLocation(), item);
|
||||
}
|
||||
|
||||
if (goalReached) {
|
||||
plugin.getPlayerDataManager().getPlayerData(player).removeEntity(event.getEntityType());
|
||||
this.plugin.getPlayerDataManager().getPlayerData(player).removeEntity(event.getEntityType());
|
||||
playerData.deleteEntityKills(event.getEntityType());
|
||||
playerData.save();
|
||||
}
|
||||
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9))
|
||||
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(plugin.getLocale().getMessage("event.goal.reached")
|
||||
.processPlaceholder("type", spawnerTier.getIdentifyingName()).getMessage()));;
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9)) {
|
||||
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(this.plugin.getLocale().getMessage("event.goal.reached")
|
||||
.processPlaceholder("type", spawnerTier.getIdentifyingName()).getMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,9 +2,9 @@ package com.craftaro.epicspawners.listeners;
|
||||
|
||||
import com.craftaro.core.compatibility.CompatibleHand;
|
||||
import com.craftaro.core.compatibility.CompatibleMaterial;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.compatibility.ServerVersion;
|
||||
import com.craftaro.core.hooks.ProtectionManager;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.utils.ItemUtils;
|
||||
import com.craftaro.epicspawners.EpicSpawners;
|
||||
import com.craftaro.epicspawners.api.events.SpawnerAccessEvent;
|
||||
@ -13,9 +13,7 @@ import com.craftaro.epicspawners.api.spawners.spawner.PlacedSpawner;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerStack;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerTier;
|
||||
import com.craftaro.epicspawners.settings.Settings;
|
||||
import com.craftaro.epicspawners.spawners.spawner.PlacedSpawnerImpl;
|
||||
import com.craftaro.epicspawners.spawners.spawner.SpawnerManager;
|
||||
import com.craftaro.epicspawners.spawners.spawner.SpawnerStackImpl;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -35,11 +33,7 @@ import org.bukkit.material.SpawnEgg;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Created by songoda on 2/25/2017.
|
||||
*/
|
||||
public class InteractListeners implements Listener {
|
||||
|
||||
private final EpicSpawners plugin;
|
||||
|
||||
public InteractListeners(EpicSpawners plugin) {
|
||||
@ -48,7 +42,7 @@ public class InteractListeners implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void playerInteractEventEgg(PlayerInteractEvent event) {
|
||||
if (!event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
|
||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
|
||||
return;
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
@ -57,7 +51,7 @@ public class InteractListeners implements Listener {
|
||||
|
||||
int radius = Settings.LIQUID_REPEL_RADIUS.getInt();
|
||||
if (item != null
|
||||
&& item.getType().equals(Material.WATER_BUCKET)
|
||||
&& item.getType() == Material.WATER_BUCKET
|
||||
&& radius != 0) {
|
||||
int bx = block.getX();
|
||||
int by = block.getY();
|
||||
@ -74,9 +68,13 @@ public class InteractListeners implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
if (item == null || item.getType() == Material.AIR) return;
|
||||
if (item == null || item.getType() == Material.AIR) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (block == null || block.getType() != XMaterial.SPAWNER.parseMaterial()) return;
|
||||
if (block == null || block.getType() != XMaterial.SPAWNER.parseMaterial()) {
|
||||
return;
|
||||
}
|
||||
|
||||
//Check if the item is a spawn egg
|
||||
try {
|
||||
@ -87,12 +85,14 @@ public class InteractListeners implements Listener {
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
if (plugin.getBlacklistHandler().isBlacklisted(player, true)) return;
|
||||
if (this.plugin.getBlacklistHandler().isBlacklisted(player, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
SpawnerManager spawnerManager = plugin.getSpawnerManager();
|
||||
SpawnerManager spawnerManager = this.plugin.getSpawnerManager();
|
||||
|
||||
//Fixme: Why we want to handle non player placed spawners?
|
||||
if (!plugin.getSpawnerManager().isSpawner(block.getLocation())) {
|
||||
if (!this.plugin.getSpawnerManager().isSpawner(block.getLocation())) {
|
||||
//createMissingSpawner(block.getLocation(), player);
|
||||
return;
|
||||
}
|
||||
@ -120,14 +120,14 @@ public class InteractListeners implements Listener {
|
||||
itype = ((SpawnEgg) item.getData()).getSpawnedType();
|
||||
}
|
||||
|
||||
SpawnerTier itemType = plugin.getSpawnerManager().getSpawnerData(itype).getFirstTier();
|
||||
SpawnerTier itemType = this.plugin.getSpawnerManager().getSpawnerData(itype).getFirstTier();
|
||||
|
||||
if (!player.hasPermission("epicspawners.egg." + itype) && !player.hasPermission("epicspawners.egg.*")) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (amt < bmulti) {
|
||||
plugin.getLocale().getMessage("event.egg.needmore")
|
||||
this.plugin.getLocale().getMessage("event.egg.needmore")
|
||||
.processPlaceholder("amount", bmulti).sendPrefixedMessage(player);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
@ -139,12 +139,12 @@ public class InteractListeners implements Listener {
|
||||
}
|
||||
|
||||
if (Settings.USE_PROTECTION_PLUGINS.getBoolean() && !ProtectionManager.canInteract(player, block.getLocation())) {
|
||||
player.sendMessage(plugin.getLocale().getMessage("event.general.protected").getPrefixedMessage());
|
||||
player.sendMessage(this.plugin.getLocale().getMessage("event.general.protected").getPrefixedMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
if (blockType.equals(itemType)) {
|
||||
plugin.getLocale().getMessage("event.egg.sametype")
|
||||
this.plugin.getLocale().getMessage("event.egg.sametype")
|
||||
.processPlaceholder("type", blockType.getIdentifyingName()).sendPrefixedMessage(player);
|
||||
return;
|
||||
}
|
||||
@ -156,40 +156,44 @@ public class InteractListeners implements Listener {
|
||||
oldEgg.ifPresent(xMaterial -> player.getInventory().addItem(xMaterial.parseItem()));
|
||||
}
|
||||
|
||||
SpawnerStack stack = spawner.getFirstStack().setTier(plugin.getSpawnerManager().getSpawnerData(itype).getFirstTier());
|
||||
plugin.getDataManager().save(stack);
|
||||
SpawnerStack stack = spawner.getFirstStack().setTier(this.plugin.getSpawnerManager().getSpawnerData(itype).getFirstTier());
|
||||
this.plugin.getDataManager().save(stack);
|
||||
try {
|
||||
spawner.getCreatureSpawner().setSpawnedType(EntityType.valueOf(plugin.getSpawnerManager().getSpawnerData(itype).getIdentifyingName().toUpperCase()));
|
||||
spawner.getCreatureSpawner().setSpawnedType(EntityType.valueOf(this.plugin.getSpawnerManager().getSpawnerData(itype).getIdentifyingName().toUpperCase()));
|
||||
} catch (Exception e2) {
|
||||
spawner.getCreatureSpawner().setSpawnedType(EntityType.DROPPED_ITEM);
|
||||
}
|
||||
spawner.getCreatureSpawner().update();
|
||||
|
||||
plugin.processChange(block);
|
||||
|
||||
this.plugin.processChange(block);
|
||||
ItemUtils.takeActiveItem(player, CompatibleHand.getHand(event), bmulti);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void playerInteractEvent(PlayerArmorStandManipulateEvent event) {
|
||||
if (plugin.getSpawnerManager().isSpawner(event.getRightClicked().getLocation().getBlock().getRelative(BlockFace.UP).getLocation())) {
|
||||
if (this.plugin.getSpawnerManager().isSpawner(event.getRightClicked().getLocation().getBlock().getRelative(BlockFace.UP).getLocation())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void playerInteractEvent(PlayerInteractEvent event) {
|
||||
if (CompatibleHand.getHand(event) == CompatibleHand.OFF_HAND) return;
|
||||
if (CompatibleHand.getHand(event) == CompatibleHand.OFF_HAND) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
Block block = event.getClickedBlock();
|
||||
if (block == null) return;
|
||||
if (block == null) {
|
||||
return;
|
||||
}
|
||||
Location location = block.getLocation();
|
||||
ItemStack item = event.getItem();
|
||||
|
||||
boolean isSpawner = block.getType() == XMaterial.SPAWNER.parseMaterial();
|
||||
|
||||
//Fixme: Why we want to handle non player placed spawners?
|
||||
if (!isSpawner && !plugin.getSpawnerManager().isSpawner(location)) {
|
||||
if (!isSpawner && !this.plugin.getSpawnerManager().isSpawner(location)) {
|
||||
//createMissingSpawner(location, player);
|
||||
return;
|
||||
}
|
||||
@ -202,28 +206,32 @@ public class InteractListeners implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isSpawner && item != null && XMaterial.SPAWNER.equals(XMaterial.matchXMaterial(item))) {
|
||||
PlacedSpawner spawner = plugin.getSpawnerManager().getSpawnerFromWorld(location);
|
||||
if (isSpawner && item != null && XMaterial.SPAWNER == XMaterial.matchXMaterial(item)) {
|
||||
PlacedSpawner spawner = this.plugin.getSpawnerManager().getSpawnerFromWorld(location);
|
||||
|
||||
if (spawner.getPlacedBy() == null && Settings.DISABLE_NATURAL_SPAWNERS.getBoolean()) return;
|
||||
if (spawner.getPlacedBy() == null && Settings.DISABLE_NATURAL_SPAWNERS.getBoolean()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!player.isSneaking()) {
|
||||
SpawnerTier spawnerTier = plugin.getSpawnerManager().getSpawnerTier(item);
|
||||
SpawnerTier spawnerTier = this.plugin.getSpawnerManager().getSpawnerTier(item);
|
||||
if (player.hasPermission("epicspawners.stack." + spawnerTier.getIdentifyingName()) || player.hasPermission("epicspawners.stack.*")) {
|
||||
if (Settings.USE_PROTECTION_PLUGINS.getBoolean() && !ProtectionManager.canInteract(player, block.getLocation())) {
|
||||
player.sendMessage(plugin.getLocale().getMessage("event.general.protected").getPrefixedMessage());
|
||||
player.sendMessage(this.plugin.getLocale().getMessage("event.general.protected").getPrefixedMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
spawner.stack(player, spawnerTier, spawnerTier.getStackSize(item), CompatibleHand.getHand(event));
|
||||
plugin.updateHologram(spawner);
|
||||
this.plugin.updateHologram(spawner);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
} else if (isSpawner && !plugin.getBlacklistHandler().isBlacklisted(player, false)) {
|
||||
PlacedSpawner spawner = plugin.getSpawnerManager().getSpawnerFromWorld(location);
|
||||
} else if (isSpawner && !this.plugin.getBlacklistHandler().isBlacklisted(player, false)) {
|
||||
PlacedSpawner spawner = this.plugin.getSpawnerManager().getSpawnerFromWorld(location);
|
||||
if (!player.isSneaking() && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
if ((spawner == null ||spawner.getPlacedBy() == null) && Settings.DISABLE_NATURAL_SPAWNERS.getBoolean()) return;
|
||||
if ((spawner == null || spawner.getPlacedBy() == null) && Settings.DISABLE_NATURAL_SPAWNERS.getBoolean()) {
|
||||
return;
|
||||
}
|
||||
|
||||
SpawnerAccessEvent accessEvent = new SpawnerAccessEvent(player, spawner);
|
||||
Bukkit.getPluginManager().callEvent(accessEvent);
|
||||
@ -232,12 +240,12 @@ public class InteractListeners implements Listener {
|
||||
}
|
||||
|
||||
if (Settings.USE_PROTECTION_PLUGINS.getBoolean() && !ProtectionManager.canInteract(player, block.getLocation())) {
|
||||
player.sendMessage(plugin.getLocale().getMessage("event.general.protected").getPrefixedMessage());
|
||||
player.sendMessage(this.plugin.getLocale().getMessage("event.general.protected").getPrefixedMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
spawner.overview(player);
|
||||
plugin.processChange(block);
|
||||
this.plugin.processChange(block);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
@ -9,14 +9,12 @@ import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
* Created by songoda on 2/25/2017.
|
||||
*/
|
||||
public class InventoryListeners implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
if (event.getCurrentItem() == null) return;
|
||||
if (event.getCurrentItem() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getSlot() != 64537 &&
|
||||
event.getInventory().getType() == InventoryType.ANVIL &&
|
||||
|
@ -1,13 +1,7 @@
|
||||
package com.craftaro.epicspawners.listeners;
|
||||
|
||||
import com.craftaro.core.compatibility.ServerVersion;
|
||||
import com.craftaro.epicspawners.EpicSpawners;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerData;
|
||||
import com.craftaro.epicspawners.settings.Settings;
|
||||
import com.craftaro.epicspawners.spawners.spawner.PlacedSpawnerImpl;
|
||||
import com.craftaro.epicspawners.spawners.spawner.SpawnerDataImpl;
|
||||
import com.craftaro.epicspawners.spawners.spawner.SpawnerStackImpl;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -16,28 +10,20 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
|
||||
import org.bukkit.event.entity.SpawnerSpawnEvent;
|
||||
|
||||
/**
|
||||
* Created by songoda on 2/25/2017.
|
||||
*/
|
||||
public class SpawnerListeners implements Listener {
|
||||
|
||||
private final EpicSpawners plugin;
|
||||
|
||||
public SpawnerListeners(EpicSpawners plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onSpawn(SpawnerSpawnEvent event) {
|
||||
Entity entity = event.getEntity();
|
||||
if (entity.getType() == EntityType.FIREWORK) return;
|
||||
if (entity.getType() == EntityType.FIREWORK) {
|
||||
return;
|
||||
}
|
||||
if (entity.getVehicle() != null) {
|
||||
entity.getVehicle().remove();
|
||||
entity.remove();
|
||||
}
|
||||
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_11)) {
|
||||
if (entity.getPassengers().size() != 0) {
|
||||
if (!entity.getPassengers().isEmpty()) {
|
||||
for (Entity e : entity.getPassengers()) {
|
||||
e.remove();
|
||||
}
|
||||
@ -45,26 +31,17 @@ public class SpawnerListeners implements Listener {
|
||||
}
|
||||
}
|
||||
entity.remove();
|
||||
|
||||
// Location location = event.getSpawner().getLocation();
|
||||
//
|
||||
// //FIXME: Why we handle non player placed spawners here?
|
||||
// //Causes errors when saving the data since placedBy is null
|
||||
// if (!plugin.getSpawnerManager().isSpawner(location)) {
|
||||
// PlacedSpawnerImpl spawner = new PlacedSpawnerImpl(location);
|
||||
// plugin.getSpawnerManager().addSpawnerToWorld(location, spawner);
|
||||
// SpawnerData spawnerData = plugin.getSpawnerManager().getSpawnerData(event.getEntityType().name());
|
||||
// if (spawnerData == null) return;
|
||||
// spawner.addSpawnerStack(new SpawnerStackImpl(spawner, spawnerData.getFirstTier(), 1));
|
||||
// EpicSpawners.getInstance().getDataManager().save(spawner);
|
||||
// }
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onTarget(EntityTargetLivingEntityEvent event) {
|
||||
if (!Settings.HOSTILE_MOBS_ATTACK_SECOND.getBoolean()) return;
|
||||
if (event.getEntity().getLastDamageCause() != null && event.getEntity().getLastDamageCause().getCause().name().equals("ENTITY_ATTACK"))
|
||||
if (!Settings.HOSTILE_MOBS_ATTACK_SECOND.getBoolean()) {
|
||||
return;
|
||||
}
|
||||
if (event.getEntity().getLastDamageCause() != null && event.getEntity().getLastDamageCause().getCause().name().equals("ENTITY_ATTACK")) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
@ -2,47 +2,24 @@ package com.craftaro.epicspawners.listeners;
|
||||
|
||||
import com.craftaro.epicspawners.EpicSpawners;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.PlacedSpawner;
|
||||
import com.craftaro.epicspawners.spawners.spawner.PlacedSpawnerImpl;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.world.WorldLoadEvent;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Created by noahvdaa on 5/09/2021.
|
||||
*/
|
||||
public class WorldListeners implements Listener {
|
||||
private final EpicSpawners plugin;
|
||||
|
||||
private final EpicSpawners plugin;
|
||||
|
||||
public WorldListeners(EpicSpawners plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onWorldLoad(WorldLoadEvent e) {
|
||||
// Unload previous spawners belonging to this world.
|
||||
for (PlacedSpawner ps : plugin.getSpawnerManager().getSpawners()) {
|
||||
if (e.getWorld().getName().equals(ps.getWorld().getName())) {
|
||||
plugin.getSpawnerManager().removeSpawnerFromWorld(ps);
|
||||
}
|
||||
}
|
||||
|
||||
//Todo fix it
|
||||
// Load spawners back in.
|
||||
// plugin.getDataManager().getSpawners(new Consumer<Map<Location, PlacedSpawner>>() {
|
||||
// @Override
|
||||
// public void accept(Map<Location, PlacedSpawner> locationPlacedSpawnerMap) {
|
||||
// for(PlacedSpawner ps : locationPlacedSpawnerMap.values()){
|
||||
// if (e.getWorld().getName().equals(ps.getWorld().getName())) {
|
||||
// plugin.getSpawnerManager().addSpawnerToWorld(ps.getLocation(), ps);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
}
|
||||
public WorldListeners(EpicSpawners plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onWorldLoad(WorldLoadEvent e) {
|
||||
// Unload previous spawners belonging to this world.
|
||||
for (PlacedSpawner ps : this.plugin.getSpawnerManager().getSpawners()) {
|
||||
if (e.getWorld().getName().equals(ps.getWorld().getName())) {
|
||||
this.plugin.getSpawnerManager().removeSpawnerFromWorld(ps);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.craftaro.epicspawners.lootables;
|
||||
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.compatibility.ServerVersion;
|
||||
import com.craftaro.core.lootables.Lootables;
|
||||
import com.craftaro.core.lootables.Modify;
|
||||
@ -8,6 +7,7 @@ import com.craftaro.core.lootables.loot.Drop;
|
||||
import com.craftaro.core.lootables.loot.Loot;
|
||||
import com.craftaro.core.lootables.loot.LootManager;
|
||||
import com.craftaro.core.lootables.loot.Lootable;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.epicspawners.EpicSpawners;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerTier;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
@ -26,14 +26,12 @@ import java.util.List;
|
||||
|
||||
public class LootablesManager {
|
||||
|
||||
private final Lootables lootables;
|
||||
|
||||
private final LootManager lootManager;
|
||||
|
||||
private final String lootablesDir = EpicSpawners.getInstance().getDataFolder() + File.separator + "lootables";
|
||||
|
||||
public LootablesManager() {
|
||||
this.lootables = new Lootables(lootablesDir);
|
||||
Lootables lootables = new Lootables(this.lootablesDir);
|
||||
this.lootManager = new LootManager(lootables);
|
||||
}
|
||||
|
||||
@ -41,9 +39,11 @@ public class LootablesManager {
|
||||
List<Drop> toDrop = new ArrayList<>();
|
||||
|
||||
if (entity instanceof Ageable && !((Ageable) entity).isAdult()
|
||||
|| !lootManager.getRegisteredLootables().containsKey(spawnerTier.getFullyIdentifyingName())) return toDrop;
|
||||
|| !this.lootManager.getRegisteredLootables().containsKey(spawnerTier.getFullyIdentifyingName())) {
|
||||
return toDrop;
|
||||
}
|
||||
|
||||
Lootable lootable = lootManager.getRegisteredLootables().get(spawnerTier.getFullyIdentifyingName());
|
||||
Lootable lootable = this.lootManager.getRegisteredLootables().get(spawnerTier.getFullyIdentifyingName());
|
||||
int looting = entity.getKiller() != null
|
||||
&& entity.getKiller().getItemInHand().containsEnchantment(Enchantment.LOOT_BONUS_MOBS)
|
||||
? entity.getKiller().getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_MOBS)
|
||||
@ -51,8 +51,9 @@ public class LootablesManager {
|
||||
|
||||
int rerollChance = looting / (looting + 1);
|
||||
|
||||
for (Loot loot : lootable.getRegisteredLoot())
|
||||
for (Loot loot : lootable.getRegisteredLoot()) {
|
||||
toDrop.addAll(runLoot(entity, loot, rerollChance, looting));
|
||||
}
|
||||
|
||||
return toDrop;
|
||||
}
|
||||
@ -63,9 +64,12 @@ public class LootablesManager {
|
||||
modify = (Loot loot2) -> {
|
||||
XMaterial material = loot2.getMaterial();
|
||||
if (material.name().contains("WOOL") && ((Sheep) entity).getColor() != null) {
|
||||
if (((Sheep) entity).isSheared()) return null;
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13))
|
||||
if (((Sheep) entity).isSheared()) {
|
||||
return null;
|
||||
}
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) {
|
||||
loot2.setMaterial(XMaterial.valueOf(((Sheep) entity).getColor() + "_WOOL"));
|
||||
}
|
||||
|
||||
}
|
||||
return loot2;
|
||||
@ -83,7 +87,7 @@ public class LootablesManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
return lootManager.runLoot(modify,
|
||||
return this.lootManager.runLoot(modify,
|
||||
entity.getFireTicks() > 0,
|
||||
entity instanceof Creeper && ((Creeper) entity).isPowered(),
|
||||
entity.getKiller() != null ? entity.getKiller().getItemInHand() : null,
|
||||
@ -94,6 +98,6 @@ public class LootablesManager {
|
||||
}
|
||||
|
||||
public LootManager getLootManager() {
|
||||
return lootManager;
|
||||
return this.lootManager;
|
||||
}
|
||||
}
|
||||
|
@ -10,15 +10,11 @@ import org.bukkit.entity.EntityType;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerDataImpl implements PlayerData {
|
||||
|
||||
private final UUID playerUUID;
|
||||
|
||||
private final Map<EntityType, Integer> entityKills;
|
||||
@ -30,36 +26,36 @@ public class PlayerDataImpl implements PlayerData {
|
||||
|
||||
@Override
|
||||
public OfflinePlayer getPlayer() {
|
||||
return Bukkit.getOfflinePlayer(playerUUID);
|
||||
return Bukkit.getOfflinePlayer(this.playerUUID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int addKilledEntity(EntityType type, int amount) {
|
||||
return entityKills.merge(type, amount, Integer::sum);
|
||||
return this.entityKills.merge(type, amount, Integer::sum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeEntity(EntityType entity) {
|
||||
entityKills.remove(entity);
|
||||
this.entityKills.remove(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<EntityType, Integer> getEntityKills() {
|
||||
return Collections.unmodifiableMap(entityKills);
|
||||
return Collections.unmodifiableMap(this.entityKills);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteEntityKills(EntityType entityType) {
|
||||
entityKills.remove(entityType);
|
||||
this.entityKills.remove(entityType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
DataManager dataManager = EpicSpawners.getInstance().getDataManager();
|
||||
dataManager.getDatabaseConnector().connectDSL(context -> {
|
||||
for (Map.Entry<EntityType, Integer> entry : entityKills.entrySet()) {
|
||||
for (Map.Entry<EntityType, Integer> entry : this.entityKills.entrySet()) {
|
||||
context.insertInto(DSL.table(dataManager.getTablePrefix() + "entity_kills"))
|
||||
.set(DSL.field("player"), playerUUID.toString())
|
||||
.set(DSL.field("player"), this.playerUUID.toString())
|
||||
.set(DSL.field("entity_type"), entry.getKey().name())
|
||||
.set(DSL.field("count"), entry.getValue())
|
||||
.onDuplicateKeyUpdate()
|
||||
@ -71,15 +67,19 @@ public class PlayerDataImpl implements PlayerData {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 31 * (playerUUID == null ? 0 : playerUUID.hashCode());
|
||||
return 31 * (this.playerUUID == null ? 0 : this.playerUUID.hashCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof PlayerDataImpl)) return false;
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof PlayerDataImpl)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
PlayerDataImpl other = (PlayerDataImpl) obj;
|
||||
return Objects.equals(playerUUID, other.playerUUID);
|
||||
return Objects.equals(this.playerUUID, other.playerUUID);
|
||||
}
|
||||
}
|
||||
|
@ -11,12 +11,11 @@ import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerDataManagerImpl implements PlayerDataManager {
|
||||
|
||||
private final Map<UUID, PlayerDataImpl> registeredPlayers = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public PlayerDataImpl getPlayerData(UUID uuid) {
|
||||
return (uuid != null) ? registeredPlayers.computeIfAbsent(uuid, PlayerDataImpl::new) : null;
|
||||
return (uuid != null) ? this.registeredPlayers.computeIfAbsent(uuid, PlayerDataImpl::new) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -26,12 +25,11 @@ public class PlayerDataManagerImpl implements PlayerDataManager {
|
||||
|
||||
@Override
|
||||
public boolean isPlayerData(Player player) {
|
||||
return registeredPlayers.containsKey(player.getUniqueId());
|
||||
return this.registeredPlayers.containsKey(player.getUniqueId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<PlayerData> getRegisteredPlayers() {
|
||||
return Collections.unmodifiableCollection(registeredPlayers.values());
|
||||
return Collections.unmodifiableCollection(this.registeredPlayers.values());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,15 @@
|
||||
package com.craftaro.epicspawners.settings;
|
||||
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.configuration.Config;
|
||||
import com.craftaro.core.configuration.ConfigSetting;
|
||||
import com.craftaro.core.hooks.EconomyManager;
|
||||
import com.craftaro.core.hooks.HologramManager;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.epicspawners.EpicSpawners;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Settings {
|
||||
|
||||
private static final Config config = EpicSpawners.getInstance().getCoreConfig();
|
||||
|
||||
public static final ConfigSetting SPAWNERS_MAX = new ConfigSetting(config, "Main.Spawner Max Stack", 5,
|
||||
@ -102,7 +101,7 @@ public class Settings {
|
||||
public static final ConfigSetting MAX_SPAWNERS = new ConfigSetting(config, "Main.Max Spawners Per Player", -1,
|
||||
"The maximum amount of spawners a player can place. Set to -1 to allow unlimited",
|
||||
"spawner placement.");
|
||||
|
||||
|
||||
public static final ConfigSetting GIVE_OLD_EGG = new ConfigSetting(config, "Main.Give Previous Mob as Egg when replacing mob", true,
|
||||
"Should the previous mob of the spawner be given as an egg when changing the spawner's mob?");
|
||||
|
||||
|
@ -5,15 +5,13 @@ import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class SpawnManager {
|
||||
|
||||
private Set<UUID> unnaturalSpawns = new HashSet<>();
|
||||
private final Set<UUID> unnaturalSpawns = new HashSet<>();
|
||||
|
||||
public boolean isNaturalSpawn(UUID uuid) {
|
||||
return !unnaturalSpawns.contains(uuid);
|
||||
return !this.unnaturalSpawns.contains(uuid);
|
||||
}
|
||||
|
||||
public void addUnnaturalSpawn(UUID uuid) {
|
||||
this.unnaturalSpawns.add(uuid);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,18 +1,16 @@
|
||||
package com.craftaro.epicspawners.spawners.condition;
|
||||
|
||||
import com.craftaro.core.third_party.org.apache.commons.text.WordUtils;
|
||||
import com.craftaro.epicspawners.EpicSpawners;
|
||||
import com.craftaro.epicspawners.api.spawners.condition.SpawnCondition;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.PlacedSpawner;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.craftaro.core.third_party.org.apache.commons.text.WordUtils;
|
||||
import com.craftaro.epicspawners.EpicSpawners;
|
||||
import com.craftaro.epicspawners.spawners.spawner.PlacedSpawnerImpl;
|
||||
import org.bukkit.block.Biome;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class SpawnConditionBiome implements SpawnCondition {
|
||||
|
||||
private final Set<Biome> biomes;
|
||||
|
||||
public SpawnConditionBiome(Biome... biomes) {
|
||||
@ -30,7 +28,7 @@ public class SpawnConditionBiome implements SpawnCondition {
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return (biomes.size() == 1)
|
||||
return (this.biomes.size() == 1)
|
||||
? EpicSpawners.getInstance().getLocale().getMessage("interface.spawner.conditionBiome1")
|
||||
.processPlaceholder("biome", getFriendlyBiomeName()).getMessage()
|
||||
: EpicSpawners.getInstance().getLocale().getMessage("interface.spawner.conditionBiome2")
|
||||
@ -39,14 +37,14 @@ public class SpawnConditionBiome implements SpawnCondition {
|
||||
|
||||
@Override
|
||||
public boolean isMet(PlacedSpawner spawner) {
|
||||
return biomes.contains(spawner.getLocation().getBlock().getBiome());
|
||||
return this.biomes.contains(spawner.getLocation().getBlock().getBiome());
|
||||
}
|
||||
|
||||
private String getFriendlyBiomeName() {
|
||||
return WordUtils.capitalizeFully(Iterables.get(biomes, 0).name().replace("_", " "));
|
||||
return WordUtils.capitalizeFully(Iterables.get(this.biomes, 0).name().replace("_", " "));
|
||||
}
|
||||
|
||||
public Set<Biome> getBiomes() {
|
||||
return biomes;
|
||||
return this.biomes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,10 +3,8 @@ package com.craftaro.epicspawners.spawners.condition;
|
||||
import com.craftaro.epicspawners.EpicSpawners;
|
||||
import com.craftaro.epicspawners.api.spawners.condition.SpawnCondition;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.PlacedSpawner;
|
||||
import com.craftaro.epicspawners.spawners.spawner.PlacedSpawnerImpl;
|
||||
|
||||
public class SpawnConditionHeight implements SpawnCondition {
|
||||
|
||||
private final int min, max;
|
||||
|
||||
public SpawnConditionHeight(int min, int max) {
|
||||
@ -22,22 +20,22 @@ public class SpawnConditionHeight implements SpawnCondition {
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return EpicSpawners.getInstance().getLocale().getMessage("interface.spawner.conditionHeight")
|
||||
.processPlaceholder("min", min)
|
||||
.processPlaceholder("max", max)
|
||||
.processPlaceholder("min", this.min)
|
||||
.processPlaceholder("max", this.max)
|
||||
.getMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMet(PlacedSpawner spawner) {
|
||||
double y = spawner.getLocation().getY();
|
||||
return y >= min && y <= max;
|
||||
return y >= this.min && y <= this.max;
|
||||
}
|
||||
|
||||
public int getMin() {
|
||||
return min;
|
||||
return this.min;
|
||||
}
|
||||
|
||||
public int getMax() {
|
||||
return max;
|
||||
return this.max;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,11 +3,9 @@ package com.craftaro.epicspawners.spawners.condition;
|
||||
import com.craftaro.epicspawners.EpicSpawners;
|
||||
import com.craftaro.epicspawners.api.spawners.condition.SpawnCondition;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.PlacedSpawner;
|
||||
import com.craftaro.epicspawners.spawners.spawner.PlacedSpawnerImpl;
|
||||
import org.bukkit.Location;
|
||||
|
||||
public class SpawnConditionLightDark implements SpawnCondition {
|
||||
|
||||
private final Type lightDark;
|
||||
|
||||
public SpawnConditionLightDark(Type lightDark) {
|
||||
@ -21,7 +19,7 @@ public class SpawnConditionLightDark implements SpawnCondition {
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
switch (lightDark) {
|
||||
switch (this.lightDark) {
|
||||
case LIGHT:
|
||||
return EpicSpawners.getInstance().getLocale().getMessage("interface.spawner.conditionLight").getMessage();
|
||||
case DARK:
|
||||
@ -34,7 +32,7 @@ public class SpawnConditionLightDark implements SpawnCondition {
|
||||
@Override
|
||||
public boolean isMet(PlacedSpawner spawner) {
|
||||
Location location = spawner.getLocation();
|
||||
switch (lightDark) {
|
||||
switch (this.lightDark) {
|
||||
case LIGHT:
|
||||
return !isDark(location);
|
||||
case DARK:
|
||||
@ -48,7 +46,7 @@ public class SpawnConditionLightDark implements SpawnCondition {
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return lightDark;
|
||||
return this.lightDark;
|
||||
}
|
||||
|
||||
public enum Type {LIGHT, DARK, BOTH}
|
||||
|
@ -6,7 +6,6 @@ import com.craftaro.epicspawners.EpicSpawners;
|
||||
import com.craftaro.epicspawners.api.spawners.condition.SpawnCondition;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.PlacedSpawner;
|
||||
import com.craftaro.epicspawners.settings.Settings;
|
||||
import com.craftaro.epicspawners.spawners.spawner.PlacedSpawnerImpl;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
@ -15,7 +14,6 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class SpawnConditionNearbyEntities implements SpawnCondition {
|
||||
|
||||
private final int max;
|
||||
|
||||
private static Map<Location, Integer> cachedAmounts = new HashMap<>();
|
||||
@ -32,17 +30,18 @@ public class SpawnConditionNearbyEntities implements SpawnCondition {
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return EpicSpawners.getInstance().getLocale().getMessage("interface.spawner.conditionNearbyEntities")
|
||||
.processPlaceholder("max", max).getMessage();
|
||||
.processPlaceholder("max", this.max).getMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMet(PlacedSpawner spawner) {
|
||||
|
||||
// Should we skip the max entity amount on first spawn?
|
||||
if (spawner.getSpawnCount() == 0 && Settings.IGNORE_MAX_ON_FIRST_SPAWN.getBoolean())
|
||||
if (spawner.getSpawnCount() == 0 && Settings.IGNORE_MAX_ON_FIRST_SPAWN.getBoolean()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return getEntitiesAroundSpawner(spawner.getLocation().add(0.5, 0.5, 0.5), false) < max;
|
||||
return getEntitiesAroundSpawner(spawner.getLocation().add(0.5, 0.5, 0.5), false) < this.max;
|
||||
}
|
||||
|
||||
public static int getEntitiesAroundSpawner(Location location, boolean cached) {
|
||||
@ -57,7 +56,7 @@ public class SpawnConditionNearbyEntities implements SpawnCondition {
|
||||
|
||||
if (arr.length == 1) {
|
||||
if (NumberUtils.isNumeric(arr[0])) {
|
||||
arr = new String[] {arr[0], arr[0], arr[0]};
|
||||
arr = new String[]{arr[0], arr[0], arr[0]};
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,7 +72,9 @@ public class SpawnConditionNearbyEntities implements SpawnCondition {
|
||||
e.getType() != EntityType.PLAYER &&
|
||||
e.getType() != EntityType.ARMOR_STAND)
|
||||
.mapToInt(e -> {
|
||||
if (EntityStackerManager.getStacker() == null) return 1;
|
||||
if (EntityStackerManager.getStacker() == null) {
|
||||
return 1;
|
||||
}
|
||||
return EntityStackerManager.getStacker().getSize((LivingEntity) e);
|
||||
}).sum();
|
||||
|
||||
@ -82,6 +83,6 @@ public class SpawnConditionNearbyEntities implements SpawnCondition {
|
||||
}
|
||||
|
||||
public int getMax() {
|
||||
return max;
|
||||
return this.max;
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,8 @@ package com.craftaro.epicspawners.spawners.condition;
|
||||
|
||||
import com.craftaro.epicspawners.api.spawners.condition.SpawnCondition;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.PlacedSpawner;
|
||||
import com.craftaro.epicspawners.spawners.spawner.PlacedSpawnerImpl;
|
||||
|
||||
public class SpawnConditionStorm implements SpawnCondition {
|
||||
|
||||
private final boolean stormOnly;
|
||||
|
||||
public SpawnConditionStorm(boolean stormOnly) {
|
||||
@ -24,10 +22,10 @@ public class SpawnConditionStorm implements SpawnCondition {
|
||||
|
||||
@Override
|
||||
public boolean isMet(PlacedSpawner spawner) {
|
||||
return !stormOnly || spawner.getLocation().getWorld().hasStorm();
|
||||
return !this.stormOnly || spawner.getLocation().getWorld().hasStorm();
|
||||
}
|
||||
|
||||
public boolean isStormOnly() {
|
||||
return stormOnly;
|
||||
return this.stormOnly;
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,12 @@
|
||||
package com.craftaro.epicspawners.spawners.spawner;
|
||||
|
||||
import com.craftaro.core.compatibility.CompatibleHand;
|
||||
import com.craftaro.core.database.DataManager;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.compatibility.CompatibleParticleHandler;
|
||||
import com.craftaro.core.compatibility.CompatibleSound;
|
||||
import com.craftaro.core.compatibility.ServerVersion;
|
||||
import com.craftaro.core.database.Data;
|
||||
import com.craftaro.core.database.DataManager;
|
||||
import com.craftaro.core.database.SerializedLocation;
|
||||
import com.craftaro.core.nms.world.SpawnedEntity;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XSound;
|
||||
import com.craftaro.core.third_party.org.jooq.impl.DSL;
|
||||
import com.craftaro.core.utils.PlayerUtils;
|
||||
@ -17,21 +15,20 @@ import com.craftaro.epicspawners.EpicSpawners;
|
||||
import com.craftaro.epicspawners.api.boosts.types.Boosted;
|
||||
import com.craftaro.epicspawners.api.events.SpawnerChangeEvent;
|
||||
import com.craftaro.epicspawners.api.events.SpawnerDropEvent;
|
||||
import com.craftaro.epicspawners.api.particles.ParticleType;
|
||||
import com.craftaro.epicspawners.api.spawners.condition.SpawnCondition;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.PlacedSpawner;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerStack;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerTier;
|
||||
import com.craftaro.epicspawners.boost.types.BoostedPlayerImpl;
|
||||
import com.craftaro.epicspawners.boost.types.BoostedSpawnerImpl;
|
||||
import com.craftaro.epicspawners.gui.SpawnerTiersGui;
|
||||
import com.craftaro.epicspawners.api.particles.ParticleType;
|
||||
import com.craftaro.epicspawners.settings.Settings;
|
||||
import com.craftaro.epicspawners.api.spawners.condition.SpawnCondition;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
@ -50,10 +47,8 @@ import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class PlacedSpawnerImpl implements PlacedSpawner {
|
||||
|
||||
// This is the unique identifier for this hologram.
|
||||
// It is reset on every plugin load.
|
||||
// Used for holograms.
|
||||
@ -105,7 +100,7 @@ public class PlacedSpawnerImpl implements PlacedSpawner {
|
||||
/**
|
||||
* Constructor used for creating new spawners.
|
||||
*
|
||||
* @param location The location of the spawner
|
||||
* @param location The location of the spawner
|
||||
*/
|
||||
public PlacedSpawnerImpl(Location location) {
|
||||
this.location = location;
|
||||
@ -115,24 +110,29 @@ public class PlacedSpawnerImpl implements PlacedSpawner {
|
||||
|
||||
@Override
|
||||
public boolean spawn() {
|
||||
if (getFirstStack().getCurrentTier() == null) return false;
|
||||
if (getFirstStack().getCurrentTier() == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
EpicSpawners instance = EpicSpawners.getInstance();
|
||||
|
||||
displaySpawnParticles();
|
||||
|
||||
if (!isRedstonePowered()) return false;
|
||||
if (!isRedstonePowered()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (SpawnerStack stack : getSpawnerStacks())
|
||||
for (SpawnerStack stack : getSpawnerStacks()) {
|
||||
stack.getCurrentTier().spawn(this, stack);
|
||||
}
|
||||
|
||||
//ToDo: This is bad.
|
||||
if (getFirstTier().getSpawnLimit() != -1 && spawnCount * spawnerStacks.size() > getFirstTier().getSpawnLimit()) {
|
||||
location.getBlock().setType(Material.AIR);
|
||||
if (getFirstTier().getSpawnLimit() != -1 && this.spawnCount * this.spawnerStacks.size() > getFirstTier().getSpawnLimit()) {
|
||||
this.location.getBlock().setType(Material.AIR);
|
||||
|
||||
CompatibleParticleHandler.spawnParticles(CompatibleParticleHandler.ParticleType.LAVA,
|
||||
location.clone().add(.5, .5, .5), 5, 0, 0, 0, 5);
|
||||
XSound.ENTITY_GENERIC_EXPLODE.play(location, 10, 10);
|
||||
this.location.clone().add(.5, .5, .5), 5, 0, 0, 0, 5);
|
||||
XSound.ENTITY_GENERIC_EXPLODE.play(this.location, 10, 10);
|
||||
|
||||
instance.getSpawnerManager().removeSpawnerFromWorld(this);
|
||||
EpicSpawners.getInstance().getDataManager().delete(this);
|
||||
@ -147,9 +147,9 @@ public class PlacedSpawnerImpl implements PlacedSpawner {
|
||||
|
||||
@Override
|
||||
public void displaySpawnParticles() {
|
||||
Location particleLocation = location.clone();
|
||||
Location particleLocation = this.location.clone();
|
||||
particleLocation.add(.5, .5, .5);
|
||||
for (SpawnerStack spawnerStack : spawnerStacks) {
|
||||
for (SpawnerStack spawnerStack : this.spawnerStacks) {
|
||||
SpawnerTier spawnerTier = spawnerStack.getCurrentTier();
|
||||
ParticleType particleType = spawnerTier.getSpawnerSpawnParticle();
|
||||
if (particleType != ParticleType.NONE) {
|
||||
@ -164,7 +164,7 @@ public class PlacedSpawnerImpl implements PlacedSpawner {
|
||||
|
||||
@Override
|
||||
public int spawn(int amountToSpawn, String particle, Set<XMaterial> canSpawnOn, SpawnedEntity spawned, EntityType... types) {
|
||||
return sSpawner.spawn(amountToSpawn, particle, canSpawnOn, spawned, types);
|
||||
return this.sSpawner.spawn(amountToSpawn, particle, canSpawnOn, spawned, types);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -176,54 +176,57 @@ public class PlacedSpawnerImpl implements PlacedSpawner {
|
||||
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return location.clone();
|
||||
return this.location.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getX() {
|
||||
return location.getBlockX();
|
||||
return this.location.getBlockX();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getY() {
|
||||
return location.getBlockY();
|
||||
return this.location.getBlockY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getZ() {
|
||||
return location.getBlockZ();
|
||||
return this.location.getBlockZ();
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld() {
|
||||
return location.getWorld();
|
||||
return this.location.getWorld();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CreatureSpawner getCreatureSpawner() {
|
||||
if (!getWorld().isChunkLoaded(getX() >> 4, getZ() >> 4))
|
||||
if (!getWorld().isChunkLoaded(getX() >> 4, getZ() >> 4)) {
|
||||
return null;
|
||||
if (creatureSpawner == null) {
|
||||
if (location.getBlock().getType() != XMaterial.SPAWNER.parseMaterial()) {
|
||||
}
|
||||
if (this.creatureSpawner == null) {
|
||||
if (this.location.getBlock().getType() != XMaterial.SPAWNER.parseMaterial()) {
|
||||
EpicSpawners.getInstance().getSpawnerManager().removeSpawnerFromWorld(this);
|
||||
EpicSpawners.getInstance().getDataManager().delete(this);
|
||||
return null;
|
||||
}
|
||||
this.creatureSpawner = (CreatureSpawner) location.getBlock().getState();
|
||||
this.creatureSpawner = (CreatureSpawner) this.location.getBlock().getState();
|
||||
}
|
||||
return creatureSpawner;
|
||||
return this.creatureSpawner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpawnerStack getFirstStack() {
|
||||
if (spawnerStacks.size() == 0) return null;
|
||||
return spawnerStacks.getFirst();
|
||||
if (this.spawnerStacks.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return this.spawnerStacks.getFirst();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStackSize() {
|
||||
int multi = 0;
|
||||
for (SpawnerStack stack : spawnerStacks) {
|
||||
for (SpawnerStack stack : this.spawnerStacks) {
|
||||
multi += stack.getStackSize();
|
||||
}
|
||||
return multi;
|
||||
@ -231,19 +234,24 @@ public class PlacedSpawnerImpl implements PlacedSpawner {
|
||||
|
||||
@Override
|
||||
public boolean checkConditions() {
|
||||
for (SpawnerStack stack : spawnerStacks) {
|
||||
for (SpawnerStack stack : this.spawnerStacks) {
|
||||
SpawnerTier tier = stack.getCurrentTier();
|
||||
if (tier == null) continue;
|
||||
for (SpawnCondition spawnCondition : tier.getConditions())
|
||||
if (!spawnCondition.isMet(this)) return false;
|
||||
if (tier == null) {
|
||||
continue;
|
||||
}
|
||||
for (SpawnCondition spawnCondition : tier.getConditions()) {
|
||||
if (!spawnCondition.isMet(this)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRedstonePowered() {
|
||||
return (!location.getBlock().isBlockPowered()
|
||||
&& !location.getBlock().isBlockIndirectlyPowered())
|
||||
return (!this.location.getBlock().isBlockPowered()
|
||||
&& !this.location.getBlock().isBlockIndirectlyPowered())
|
||||
|| !Settings.REDSTONE_ACTIVATE.getBoolean();
|
||||
}
|
||||
|
||||
@ -251,7 +259,9 @@ public class PlacedSpawnerImpl implements PlacedSpawner {
|
||||
public void overview(Player player) {
|
||||
EpicSpawners plugin = EpicSpawners.getInstance();
|
||||
if (!player.hasPermission("epicspawners.overview")
|
||||
|| (getPlacedBy() == null && Settings.DISABLE_NATURAL_SPAWNERS.getBoolean())) return;
|
||||
|| (getPlacedBy() == null && Settings.DISABLE_NATURAL_SPAWNERS.getBoolean())) {
|
||||
return;
|
||||
}
|
||||
SpawnerTiersGui.openTiers(plugin, player, this);
|
||||
}
|
||||
|
||||
@ -259,7 +269,9 @@ public class PlacedSpawnerImpl implements PlacedSpawner {
|
||||
public boolean unstack(Player player, CompatibleHand hand) {
|
||||
EpicSpawners instance = EpicSpawners.getInstance();
|
||||
SpawnerStack stack = getFirstStack();
|
||||
if (stack == null || stack.getSpawner().getId() == -1) return false; //Not a stack
|
||||
if (stack == null || stack.getSpawner().getId() == -1) {
|
||||
return false; //Not a stack
|
||||
}
|
||||
|
||||
int stackSize = 1;
|
||||
|
||||
@ -292,8 +304,8 @@ public class PlacedSpawnerImpl implements PlacedSpawner {
|
||||
for (ItemStack itemStack : leftOver) {
|
||||
player.getWorld().dropItemNaturally(player.getLocation(), itemStack);
|
||||
}
|
||||
} else if (!Settings.ONLY_DROP_PLACED.getBoolean() || placedBy != null) {
|
||||
int ch = Integer.parseInt((placedBy != null
|
||||
} else if (!Settings.ONLY_DROP_PLACED.getBoolean() || this.placedBy != null) {
|
||||
int ch = Integer.parseInt((this.placedBy != null
|
||||
? Settings.SILKTOUCH_PLACED_SPAWNER_DROP_CHANCE.getString() : Settings.SILKTOUCH_NATURAL_SPAWNER_DROP_CHANCE.getString()).replace("%", ""));
|
||||
|
||||
double rand = Math.random() * 100;
|
||||
@ -305,10 +317,11 @@ public class PlacedSpawnerImpl implements PlacedSpawner {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Settings.SPAWNERS_TO_INVENTORY.getBoolean() && player.getInventory().firstEmpty() != -1)
|
||||
if (Settings.SPAWNERS_TO_INVENTORY.getBoolean() && player.getInventory().firstEmpty() != -1) {
|
||||
player.getInventory().addItem(item);
|
||||
else
|
||||
location.getWorld().dropItemNaturally(location.clone().add(.5, 0, .5), item);
|
||||
} else {
|
||||
this.location.getWorld().dropItemNaturally(this.location.clone().add(.5, 0, .5), item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -319,12 +332,14 @@ public class PlacedSpawnerImpl implements PlacedSpawner {
|
||||
return true;
|
||||
}
|
||||
|
||||
spawnerStacks.remove(stack);
|
||||
this.spawnerStacks.remove(stack);
|
||||
EpicSpawners.getInstance().getDataManager().delete(stack);
|
||||
|
||||
if (spawnerStacks.size() != 0) return true;
|
||||
if (this.spawnerStacks.size() != 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
location.getBlock().setType(Material.AIR);
|
||||
this.location.getBlock().setType(Material.AIR);
|
||||
EpicSpawners.getInstance().getSpawnerManager().removeSpawnerFromWorld(this);
|
||||
EpicSpawners.getInstance().getDataManager().delete(this);
|
||||
instance.clearHologram(this);
|
||||
@ -344,20 +359,25 @@ public class PlacedSpawnerImpl implements PlacedSpawner {
|
||||
}
|
||||
|
||||
if (tier != getFirstTier()
|
||||
&& (!Settings.OMNI_SPAWNERS.getBoolean() || !player.hasPermission("epicspawners.omni")))
|
||||
&& (!Settings.OMNI_SPAWNERS.getBoolean() || !player.hasPermission("epicspawners.omni"))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SpawnerChangeEvent event = new SpawnerChangeEvent(player, this, currentStackSize + amount, currentStackSize);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) return false;
|
||||
if (event.isCancelled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((getStackSize() + amount) > max) {
|
||||
PlayerUtils.giveItem(player, tier.toItemStack(1, (getStackSize() + amount) - max));
|
||||
amount = max - currentStackSize;
|
||||
}
|
||||
|
||||
for (SpawnerStack spawnerStack: spawnerStacks) {
|
||||
if (!spawnerStack.getCurrentTier().equals(tier)) continue;
|
||||
for (SpawnerStack spawnerStack : this.spawnerStacks) {
|
||||
if (!spawnerStack.getCurrentTier().equals(tier)) {
|
||||
continue;
|
||||
}
|
||||
spawnerStack.setStackSize(spawnerStack.getStackSize() + amount);
|
||||
//plugin.getDataManager().saveSync(spawnerStack, "spawner_id", spawnerStack.getSpawner().getId());
|
||||
// Not sure why this is not working. Maybe no key defined?
|
||||
@ -378,7 +398,6 @@ public class PlacedSpawnerImpl implements PlacedSpawner {
|
||||
});
|
||||
|
||||
|
||||
|
||||
upgradeEffects(player, tier, true);
|
||||
|
||||
if (player.getGameMode() != GameMode.CREATIVE || Settings.CHARGE_FOR_CREATIVE.getBoolean()) {
|
||||
@ -391,15 +410,16 @@ public class PlacedSpawnerImpl implements PlacedSpawner {
|
||||
addSpawnerStack(stack);
|
||||
plugin.getDataManager().save(stack, "spawner_id", stack.getSpawner().getId());
|
||||
|
||||
if (player.getGameMode() != GameMode.CREATIVE || Settings.CHARGE_FOR_CREATIVE.getBoolean())
|
||||
if (player.getGameMode() != GameMode.CREATIVE || Settings.CHARGE_FOR_CREATIVE.getBoolean()) {
|
||||
hand.takeItem(player);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpawnerTier getFirstTier() {
|
||||
return spawnerStacks.getFirst().getCurrentTier();
|
||||
return this.spawnerStacks.getFirst().getCurrentTier();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -407,17 +427,19 @@ public class PlacedSpawnerImpl implements PlacedSpawner {
|
||||
EpicSpawners plugin = EpicSpawners.getInstance();
|
||||
int currentStackSize = getStackSize();
|
||||
|
||||
if (stacked)
|
||||
if (getStackSize() != Settings.SPAWNERS_MAX.getInt())
|
||||
if (stacked) {
|
||||
if (getStackSize() != Settings.SPAWNERS_MAX.getInt()) {
|
||||
plugin.getLocale().getMessage("event.upgrade.success")
|
||||
.processPlaceholder("size", currentStackSize).sendPrefixedMessage(player);
|
||||
else
|
||||
} else {
|
||||
plugin.getLocale().getMessage("event.upgrade.successmaxed")
|
||||
.processPlaceholder("size", currentStackSize).sendPrefixedMessage(player);
|
||||
else
|
||||
}
|
||||
} else {
|
||||
plugin.getLocale().getMessage("event.tierup.success").processPlaceholder("tier", tier.getCompiledDisplayName());
|
||||
}
|
||||
|
||||
Location loc = location.clone();
|
||||
Location loc = this.location.clone();
|
||||
loc.setX(loc.getX() + .5);
|
||||
loc.setY(loc.getY() + .5);
|
||||
loc.setZ(loc.getZ() + .5);
|
||||
@ -449,7 +471,9 @@ public class PlacedSpawnerImpl implements PlacedSpawner {
|
||||
|
||||
List<Boosted> found = new ArrayList<>();
|
||||
for (Boosted boost : new ArrayList<>(boosts)) {
|
||||
if (boost instanceof BoostedPlayerImpl && placedBy == null) continue;
|
||||
if (boost instanceof BoostedPlayerImpl && this.placedBy == null) {
|
||||
continue;
|
||||
}
|
||||
BoostedSpawnerImpl boostedSpawner = (BoostedSpawnerImpl) boost;
|
||||
if (System.currentTimeMillis() >= boost.getEndTime()) {
|
||||
instance.getBoostManager().removeBoost(boost);
|
||||
@ -467,9 +491,13 @@ public class PlacedSpawnerImpl implements PlacedSpawner {
|
||||
}
|
||||
|
||||
if (boost instanceof BoostedSpawnerImpl) {
|
||||
if (!location.equals(((BoostedSpawnerImpl) boost).getLocation())) continue;
|
||||
if (!this.location.equals(((BoostedSpawnerImpl) boost).getLocation())) {
|
||||
continue;
|
||||
}
|
||||
} else if (boost instanceof BoostedPlayerImpl) {
|
||||
if (!placedBy.equals(((BoostedPlayerImpl) boost).getPlayer().getUniqueId())) continue;
|
||||
if (!this.placedBy.equals(((BoostedPlayerImpl) boost).getPlayer().getUniqueId())) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
found.add(boost);
|
||||
}
|
||||
@ -480,7 +508,7 @@ public class PlacedSpawnerImpl implements PlacedSpawner {
|
||||
public int updateDelay() {
|
||||
int max = 0;
|
||||
int min = 0;
|
||||
for (SpawnerStack stack : spawnerStacks) {
|
||||
for (SpawnerStack stack : this.spawnerStacks) {
|
||||
String tickRate = stack.getCurrentTier().getTickRate();
|
||||
|
||||
String[] tick = tickRate.contains(":") ? tickRate.split(":") : new String[]{tickRate, tickRate};
|
||||
@ -499,7 +527,9 @@ public class PlacedSpawnerImpl implements PlacedSpawner {
|
||||
}
|
||||
int extraTicks = Settings.EXTRA_SPAWN_TICKS.getInt();
|
||||
|
||||
if (getStackSize() == 0) return 0;
|
||||
if (getStackSize() == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int delay = (int) (Math.random() * (max - min)) + min + extraTicks;
|
||||
|
||||
@ -511,43 +541,46 @@ public class PlacedSpawnerImpl implements PlacedSpawner {
|
||||
|
||||
@Override
|
||||
public String getIdentifyingName() {
|
||||
String name = spawnerStacks.getFirst().getSpawnerData().getIdentifyingName();
|
||||
String name = this.spawnerStacks.getFirst().getSpawnerData().getIdentifyingName();
|
||||
|
||||
if (spawnerStacks.size() > 1)
|
||||
if (this.spawnerStacks.size() > 1) {
|
||||
name = EpicSpawners.getInstance().getSpawnerManager().getSpawnerData("omni").getIdentifyingName();
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SpawnerStack> getSpawnerStacks() {
|
||||
return new LinkedList<>(spawnerStacks);
|
||||
return new LinkedList<>(this.spawnerStacks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replaceStacks(List<SpawnerStack> stacks) {
|
||||
spawnerStacks.clear();
|
||||
spawnerStacks.addAll(stacks);
|
||||
this.spawnerStacks.clear();
|
||||
this.spawnerStacks.addAll(stacks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfflinePlayer getPlacedBy() {
|
||||
if (placedBy == null) return null;
|
||||
return Bukkit.getOfflinePlayer(placedBy);
|
||||
if (this.placedBy == null) {
|
||||
return null;
|
||||
}
|
||||
return Bukkit.getOfflinePlayer(this.placedBy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return id;
|
||||
return this.id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> serialize() {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("id", id);
|
||||
map.put("spawn_count", spawnCount);
|
||||
map.put("placed_by", placedBy.toString());
|
||||
map.putAll(SerializedLocation.of(location));
|
||||
map.put("id", this.id);
|
||||
map.put("spawn_count", this.spawnCount);
|
||||
map.put("placed_by", this.placedBy.toString());
|
||||
map.putAll(SerializedLocation.of(this.location));
|
||||
return map;
|
||||
}
|
||||
|
||||
@ -582,7 +615,7 @@ public class PlacedSpawnerImpl implements PlacedSpawner {
|
||||
|
||||
@Override
|
||||
public int getSpawnCount() {
|
||||
return spawnCount;
|
||||
return this.spawnCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -592,7 +625,7 @@ public class PlacedSpawnerImpl implements PlacedSpawner {
|
||||
|
||||
@Override
|
||||
public String getOmniState() {
|
||||
return omniState;
|
||||
return this.omniState;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -611,7 +644,7 @@ public class PlacedSpawnerImpl implements PlacedSpawner {
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return !spawnerStacks.isEmpty()
|
||||
return !this.spawnerStacks.isEmpty()
|
||||
&& getFirstStack() != null
|
||||
&& getFirstStack().getCurrentTier() != null
|
||||
&& getFirstStack().getSpawnerData() != null;
|
||||
@ -625,12 +658,14 @@ public class PlacedSpawnerImpl implements PlacedSpawner {
|
||||
|
||||
for (SpawnerStack stack : getSpawnerStacks()) {
|
||||
if (stack == toMerge
|
||||
|| !stack.getCurrentTier().equals(toMerge.getCurrentTier())) continue;
|
||||
|| !stack.getCurrentTier().equals(toMerge.getCurrentTier())) {
|
||||
continue;
|
||||
}
|
||||
stack.setStackSize(toMerge.getStackSize() + stack.getStackSize());
|
||||
spawnerStacks.remove(toMerge);
|
||||
this.spawnerStacks.remove(toMerge);
|
||||
plugin.getDataManager().getDatabaseConnector().connectDSL(dslContext -> {
|
||||
//Delete the old stack
|
||||
dslContext.update(DSL.table(tablePrefix+"spawner_stacks"))
|
||||
dslContext.update(DSL.table(tablePrefix + "spawner_stacks"))
|
||||
.set(toMerge.serialize())
|
||||
.where(DSL.field("spawner_id").eq(getId()))
|
||||
.and(DSL.field("data_type").eq(oldTier.getSpawnerData().getIdentifyingName()))
|
||||
@ -649,36 +684,40 @@ public class PlacedSpawnerImpl implements PlacedSpawner {
|
||||
|
||||
@Override
|
||||
public String getHologramId() {
|
||||
return "EpicSpawners-" + uniqueHologramId;
|
||||
return "EpicSpawners-" + this.uniqueHologramId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = 31 * (location == null ? 0 : location.hashCode());
|
||||
result = 31 * result + (placedBy == null ? 0 : placedBy.hashCode());
|
||||
int result = 31 * (this.location == null ? 0 : this.location.hashCode());
|
||||
result = 31 * result + (this.placedBy == null ? 0 : this.placedBy.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof PlacedSpawnerImpl)) return false;
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof PlacedSpawnerImpl)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
PlacedSpawnerImpl other = (PlacedSpawnerImpl) obj;
|
||||
return Objects.equals(location, other.location) && Objects.equals(placedBy, other.placedBy);
|
||||
return Objects.equals(this.location, other.location) && Objects.equals(this.placedBy, other.placedBy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Spawner:{"
|
||||
+ "Owner:\"" + placedBy + "\","
|
||||
+ "Owner:\"" + this.placedBy + "\","
|
||||
+ "Location:{"
|
||||
+ "World:\"" + location.getWorld().getName() + "\","
|
||||
+ "X:" + location.getBlockX() + ","
|
||||
+ "Y:" + location.getBlockY() + ","
|
||||
+ "Z:" + location.getBlockZ()
|
||||
+ "World:\"" + this.location.getWorld().getName() + "\","
|
||||
+ "X:" + this.location.getBlockX() + ","
|
||||
+ "Y:" + this.location.getBlockY() + ","
|
||||
+ "Z:" + this.location.getBlockZ()
|
||||
+ "},"
|
||||
+ "StackCount:" + spawnerStacks.size()
|
||||
+ "StackCount:" + this.spawnerStacks.size()
|
||||
+ "}";
|
||||
}
|
||||
}
|
||||
|
@ -19,15 +19,16 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class SpawnerDataImpl implements SpawnerData {
|
||||
|
||||
private final String identifyingName;
|
||||
|
||||
private boolean custom = false, active = true,
|
||||
inShop = true, convertible = true;
|
||||
private boolean custom = false;
|
||||
private boolean active = true;
|
||||
private boolean inShop = true;
|
||||
private boolean convertible = true;
|
||||
|
||||
private String convertRatio = "45%";
|
||||
private int killDropGoal = 0,
|
||||
shopOrder = 0;
|
||||
private int killDropGoal = 0;
|
||||
private int shopOrder = 0;
|
||||
|
||||
private double shopPrice = 1000, killDropChance = 0;
|
||||
|
||||
@ -43,12 +44,12 @@ public class SpawnerDataImpl implements SpawnerData {
|
||||
|
||||
@Override
|
||||
public String getIdentifyingName() {
|
||||
return identifyingName;
|
||||
return this.identifyingName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCraftable() {
|
||||
return craftable;
|
||||
return this.craftable;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -58,7 +59,7 @@ public class SpawnerDataImpl implements SpawnerData {
|
||||
|
||||
@Override
|
||||
public String getRecipe() {
|
||||
return recipe;
|
||||
return this.recipe;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -68,7 +69,7 @@ public class SpawnerDataImpl implements SpawnerData {
|
||||
|
||||
@Override
|
||||
public List<String> getRecipeIngredients() {
|
||||
return recipeIngredients;
|
||||
return this.recipeIngredients;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -78,7 +79,7 @@ public class SpawnerDataImpl implements SpawnerData {
|
||||
|
||||
@Override
|
||||
public boolean isCustom() {
|
||||
return custom;
|
||||
return this.custom;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -88,7 +89,7 @@ public class SpawnerDataImpl implements SpawnerData {
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
return this.active;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -98,7 +99,7 @@ public class SpawnerDataImpl implements SpawnerData {
|
||||
|
||||
@Override
|
||||
public boolean isInShop() {
|
||||
return inShop;
|
||||
return this.inShop;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -108,7 +109,7 @@ public class SpawnerDataImpl implements SpawnerData {
|
||||
|
||||
@Override
|
||||
public double getShopPrice() {
|
||||
return shopPrice;
|
||||
return this.shopPrice;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -118,7 +119,7 @@ public class SpawnerDataImpl implements SpawnerData {
|
||||
|
||||
@Override
|
||||
public boolean isConvertible() {
|
||||
return convertible;
|
||||
return this.convertible;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -128,7 +129,7 @@ public class SpawnerDataImpl implements SpawnerData {
|
||||
|
||||
@Override
|
||||
public String getConvertRatio() {
|
||||
return convertRatio;
|
||||
return this.convertRatio;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -138,12 +139,12 @@ public class SpawnerDataImpl implements SpawnerData {
|
||||
|
||||
@Override
|
||||
public double getConvertPrice() {
|
||||
return getFirstTier().getCostEconomy() * (Double.parseDouble(convertRatio.substring(0, convertRatio.length() - 1)) / 100.0f);
|
||||
return getFirstTier().getCostEconomy() * (Double.parseDouble(this.convertRatio.substring(0, this.convertRatio.length() - 1)) / 100.0f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getKillDropGoal() {
|
||||
return killDropGoal;
|
||||
return this.killDropGoal;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -153,7 +154,7 @@ public class SpawnerDataImpl implements SpawnerData {
|
||||
|
||||
@Override
|
||||
public double getKillDropChance() {
|
||||
return killDropChance;
|
||||
return this.killDropChance;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -163,7 +164,7 @@ public class SpawnerDataImpl implements SpawnerData {
|
||||
|
||||
@Override
|
||||
public int getShopOrder() {
|
||||
return shopOrder;
|
||||
return this.shopOrder;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -173,14 +174,14 @@ public class SpawnerDataImpl implements SpawnerData {
|
||||
|
||||
@Override
|
||||
public List<SpawnerTier> getTiers() {
|
||||
return Collections.unmodifiableList(spawnerTiers);
|
||||
return Collections.unmodifiableList(this.spawnerTiers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpawnerTier getTier(String tierName) {
|
||||
tierName = tierName.replace(" ", "_");
|
||||
final String finalTierName = tierName;
|
||||
return spawnerTiers.stream().filter(tier -> tier.getIdentifyingName().replace(" ", "_")
|
||||
return this.spawnerTiers.stream().filter(tier -> tier.getIdentifyingName().replace(" ", "_")
|
||||
.equalsIgnoreCase(finalTierName)).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
@ -192,30 +193,33 @@ public class SpawnerDataImpl implements SpawnerData {
|
||||
|
||||
@Override
|
||||
public SpawnerTier getFirstTier() {
|
||||
return spawnerTiers.get(0);
|
||||
return this.spawnerTiers.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpawnerTier getNextTier(SpawnerTier tier) {
|
||||
int idx = spawnerTiers.indexOf(tier);
|
||||
if (idx < 0 || idx + 1 == spawnerTiers.size()) return null;
|
||||
return spawnerTiers.get(idx + 1);
|
||||
int idx = this.spawnerTiers.indexOf(tier);
|
||||
|
||||
if (idx < 0 || idx + 1 == this.spawnerTiers.size()) {
|
||||
return null;
|
||||
}
|
||||
return this.spawnerTiers.get(idx + 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTier(SpawnerTier tier) {
|
||||
spawnerTiers.add(tier);
|
||||
this.spawnerTiers.add(tier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeTier(SpawnerTier tier) {
|
||||
spawnerTiers.remove(tier);
|
||||
this.spawnerTiers.remove(tier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replaceTiers(Collection<SpawnerTier> newTiers) {
|
||||
spawnerTiers.clear();
|
||||
spawnerTiers.addAll(newTiers);
|
||||
this.spawnerTiers.clear();
|
||||
this.spawnerTiers.addAll(newTiers);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -225,8 +229,9 @@ public class SpawnerDataImpl implements SpawnerData {
|
||||
|
||||
@Override
|
||||
public void reloadSpawnMethods() {
|
||||
for (SpawnerTier spawnerTier : spawnerTiers)
|
||||
for (SpawnerTier spawnerTier : this.spawnerTiers) {
|
||||
spawnerTier.reloadSpawnMethods();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -238,20 +243,23 @@ public class SpawnerDataImpl implements SpawnerData {
|
||||
tier.addCondition(new SpawnConditionLightDark(SpawnConditionLightDark.Type.BOTH));
|
||||
tier.addCondition(new SpawnConditionStorm(false));
|
||||
tier.addCondition(new SpawnConditionNearbyEntities(6));
|
||||
spawnerTiers.add(tier);
|
||||
this.spawnerTiers.add(tier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
SpawnerDataImpl that = (SpawnerDataImpl) o;
|
||||
return identifyingName.equals(that.identifyingName);
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null || getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
return this.identifyingName.equals(((SpawnerDataImpl) obj).identifyingName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(identifyingName);
|
||||
return Objects.hash(this.identifyingName);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,27 +1,27 @@
|
||||
package com.craftaro.epicspawners.spawners.spawner;
|
||||
|
||||
import com.craftaro.core.compatibility.CompatibleBiome;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.configuration.Config;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.third_party.de.tr7zw.nbtapi.NBTItem;
|
||||
import com.craftaro.core.third_party.org.apache.commons.text.WordUtils;
|
||||
import com.craftaro.core.utils.EntityUtils;
|
||||
import com.craftaro.epicspawners.EpicSpawners;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.PlacedSpawner;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerData;
|
||||
import com.craftaro.epicspawners.api.particles.ParticleDensity;
|
||||
import com.craftaro.epicspawners.api.particles.ParticleEffect;
|
||||
import com.craftaro.epicspawners.api.particles.ParticleType;
|
||||
import com.craftaro.epicspawners.api.spawners.condition.SpawnCondition;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.PlacedSpawner;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerData;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerStack;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerTier;
|
||||
import com.craftaro.epicspawners.api.utils.SpawnerTierBuilder;
|
||||
import com.craftaro.epicspawners.spawners.condition.SpawnConditionBiome;
|
||||
import com.craftaro.epicspawners.spawners.condition.SpawnConditionHeight;
|
||||
import com.craftaro.epicspawners.spawners.condition.SpawnConditionLightDark;
|
||||
import com.craftaro.epicspawners.spawners.condition.SpawnConditionNearbyEntities;
|
||||
import com.craftaro.epicspawners.spawners.condition.SpawnConditionNearbyPlayers;
|
||||
import com.craftaro.epicspawners.spawners.condition.SpawnConditionStorm;
|
||||
import com.craftaro.epicspawners.api.utils.SpawnerTierBuilder;
|
||||
import com.craftaro.epicspawners.utils.SpawnerDataBuilderImpl;
|
||||
import com.craftaro.epicspawners.utils.SpawnerTierBuilderImpl;
|
||||
import org.bukkit.Location;
|
||||
@ -50,7 +50,6 @@ import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class SpawnerManager {
|
||||
|
||||
private final EpicSpawners plugin;
|
||||
|
||||
// These are the spawner types loaded into memory.
|
||||
@ -68,7 +67,7 @@ public class SpawnerManager {
|
||||
|
||||
public SpawnerManager(EpicSpawners plugin) {
|
||||
this.plugin = plugin;
|
||||
spawnerConfig.load();
|
||||
this.spawnerConfig.load();
|
||||
Arrays.stream(EntityType.values()).filter(entityType -> entityType.isSpawnable()
|
||||
&& entityType.isAlive()
|
||||
&& entityType != EntityType.ARMOR_STAND).forEach(this::processDefaultSpawner);
|
||||
@ -79,8 +78,11 @@ public class SpawnerManager {
|
||||
}
|
||||
|
||||
public SpawnerData getSpawnerData(String name) {
|
||||
return registeredSpawnerData.values().stream().filter(spawnerData -> spawnerData.getIdentifyingName()
|
||||
.equalsIgnoreCase(name)).findFirst().orElse(null);
|
||||
return this.registeredSpawnerData.values()
|
||||
.stream()
|
||||
.filter(spawnerData -> spawnerData.getIdentifyingName().equalsIgnoreCase(name))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
public SpawnerData getSpawnerData(EntityType type) {
|
||||
@ -88,14 +90,17 @@ public class SpawnerManager {
|
||||
}
|
||||
|
||||
public SpawnerTier getSpawnerTier(ItemStack item) {
|
||||
if (item == null) return null;
|
||||
if (item == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
NBTItem nbtItem = new NBTItem(item);
|
||||
if (nbtItem.hasKey("data")) {
|
||||
if (nbtItem.hasTag("data")) {
|
||||
String type = nbtItem.getString("data");
|
||||
SpawnerData data = getSpawnerData(type);
|
||||
if (data != null && nbtItem.hasKey("tier"))
|
||||
if (data != null && nbtItem.hasTag("tier")) {
|
||||
return data.getTierOrFirst(nbtItem.getString("tier"));
|
||||
}
|
||||
}
|
||||
|
||||
BlockStateMeta bsm = (BlockStateMeta) item.getItemMeta();
|
||||
@ -103,78 +108,78 @@ public class SpawnerManager {
|
||||
return getSpawnerData(cs.getSpawnedType()).getFirstTier();
|
||||
}
|
||||
|
||||
public SpawnerData addSpawnerData(String name, SpawnerData SpawnerData) {
|
||||
this.registeredSpawnerData.put(name.toLowerCase(), SpawnerData);
|
||||
SpawnerData.reloadSpawnMethods();
|
||||
return SpawnerData;
|
||||
public SpawnerData addSpawnerData(String name, SpawnerData spawnerData) {
|
||||
this.registeredSpawnerData.put(name.toLowerCase(), spawnerData);
|
||||
spawnerData.reloadSpawnMethods();
|
||||
return spawnerData;
|
||||
}
|
||||
|
||||
public void addSpawnerData(SpawnerData SpawnerData) {
|
||||
this.registeredSpawnerData.put(SpawnerData.getIdentifyingName().toLowerCase(), SpawnerData);
|
||||
public void addSpawnerData(SpawnerData spawnerData) {
|
||||
this.registeredSpawnerData.put(spawnerData.getIdentifyingName().toLowerCase(), spawnerData);
|
||||
}
|
||||
|
||||
public void removeSpawnerData(String name) {
|
||||
registeredSpawnerData.remove(name.toLowerCase());
|
||||
this.registeredSpawnerData.remove(name.toLowerCase());
|
||||
}
|
||||
|
||||
public Collection<SpawnerData> getAllSpawnerData() {
|
||||
return Collections.unmodifiableCollection(registeredSpawnerData.values());
|
||||
return Collections.unmodifiableCollection(this.registeredSpawnerData.values());
|
||||
}
|
||||
|
||||
public Collection<SpawnerData> getAllEnabledSpawnerData() {
|
||||
return registeredSpawnerData.values().stream().filter(SpawnerData::isActive).collect(Collectors.toList());
|
||||
return this.registeredSpawnerData.values().stream().filter(SpawnerData::isActive).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public boolean isSpawner(Location location) {
|
||||
return spawnersInWorld.containsKey(location);
|
||||
return this.spawnersInWorld.containsKey(location);
|
||||
}
|
||||
|
||||
public boolean isSpawnerData(String type) {
|
||||
return registeredSpawnerData.containsKey(type.toLowerCase());
|
||||
return this.registeredSpawnerData.containsKey(type.toLowerCase());
|
||||
}
|
||||
|
||||
public PlacedSpawner getSpawnerFromWorld(Location location) {
|
||||
return spawnersInWorld.get(location);
|
||||
return this.spawnersInWorld.get(location);
|
||||
}
|
||||
|
||||
public void addSpawnerToWorld(Location location, PlacedSpawner spawner) {
|
||||
spawnersInWorld.put(location, spawner);
|
||||
this.spawnersInWorld.put(location, spawner);
|
||||
}
|
||||
|
||||
public PlacedSpawner removeSpawnerFromWorld(Location location) {
|
||||
return spawnersInWorld.remove(location);
|
||||
return this.spawnersInWorld.remove(location);
|
||||
}
|
||||
|
||||
public PlacedSpawner removeSpawnerFromWorld(PlacedSpawner spawner) {
|
||||
return spawnersInWorld.remove(spawner.getLocation());
|
||||
return this.spawnersInWorld.remove(spawner.getLocation());
|
||||
}
|
||||
|
||||
public Collection<PlacedSpawner> getSpawners() {
|
||||
return Collections.unmodifiableCollection(spawnersInWorld.values());
|
||||
return Collections.unmodifiableCollection(this.spawnersInWorld.values());
|
||||
}
|
||||
|
||||
public void addSpawners(Map<Location, PlacedSpawner> spawners) {
|
||||
spawnersInWorld.putAll(spawners);
|
||||
this.spawnersInWorld.putAll(spawners);
|
||||
}
|
||||
|
||||
public void addSpawners(List<PlacedSpawner> spawners) {
|
||||
spawners.forEach(spawner -> spawnersInWorld.put(spawner.getLocation(), (PlacedSpawnerImpl) spawner));
|
||||
spawners.forEach(spawner -> this.spawnersInWorld.put(spawner.getLocation(), (PlacedSpawnerImpl) spawner));
|
||||
}
|
||||
|
||||
public void addCooldown(PlacedSpawner spawner) {
|
||||
pickingUp.add(spawner);
|
||||
this.pickingUp.add(spawner);
|
||||
}
|
||||
|
||||
public void removeCooldown(PlacedSpawner spawner) {
|
||||
pickingUp.remove(spawner);
|
||||
this.pickingUp.remove(spawner);
|
||||
}
|
||||
|
||||
public boolean hasCooldown(PlacedSpawner spawner) {
|
||||
return pickingUp.contains(spawner);
|
||||
return this.pickingUp.contains(spawner);
|
||||
}
|
||||
|
||||
public int getAmountPlaced(Player player) {
|
||||
return Math.toIntExact(spawnersInWorld.values().stream().filter(spawner -> spawner.getPlacedBy() != null
|
||||
return Math.toIntExact(this.spawnersInWorld.values().stream().filter(spawner -> spawner.getPlacedBy() != null
|
||||
&& player.getUniqueId().equals(spawner.getPlacedBy().getUniqueId())).count()) + 1;
|
||||
}
|
||||
|
||||
@ -182,8 +187,9 @@ public class SpawnerManager {
|
||||
String typeString = type.name();
|
||||
FileConfiguration spawnerConfig = this.spawnerConfig.getFileConfig();
|
||||
|
||||
if (spawnerConfig.isConfigurationSection("Spawners." + typeString))
|
||||
if (spawnerConfig.isConfigurationSection("Spawners." + typeString)) {
|
||||
return;
|
||||
}
|
||||
|
||||
SpawnerData spawnerData = new SpawnerDataBuilderImpl(typeString).setCustom(false)
|
||||
.setActive(true)
|
||||
@ -243,18 +249,20 @@ public class SpawnerManager {
|
||||
|
||||
spawnerData.addTier(tier);
|
||||
|
||||
registeredSpawnerData.put(typeString, spawnerData);
|
||||
this.registeredSpawnerData.put(typeString, spawnerData);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void loadSpawnerDataFromFile() {
|
||||
registeredSpawnerData.clear();
|
||||
this.registeredSpawnerData.clear();
|
||||
// Register spawner data into SpawnerRegistry from configuration.
|
||||
FileConfiguration spawnerConfig = this.spawnerConfig.getFileConfig();
|
||||
|
||||
lastLoad = spawnerConfig.saveToString();
|
||||
this.lastLoad = spawnerConfig.saveToString();
|
||||
|
||||
if (!spawnerConfig.contains("Spawners")) return;
|
||||
if (!spawnerConfig.contains("Spawners")) {
|
||||
return;
|
||||
}
|
||||
for (String key : spawnerConfig.getConfigurationSection("Spawners").getKeys(false)) {
|
||||
ConfigurationSection currentSection = spawnerConfig.getConfigurationSection("Spawners." + key);
|
||||
|
||||
@ -320,13 +328,14 @@ public class SpawnerManager {
|
||||
if (currentSection2.contains("Conditions")) {
|
||||
String biomeString = currentSection2.getString("Conditions.Biomes");
|
||||
Set<Biome> biomes;
|
||||
if (biomeString.toUpperCase().equals("ALL"))
|
||||
if ("ALL".equalsIgnoreCase(biomeString)) {
|
||||
biomes = EnumSet.allOf(Biome.class);
|
||||
else {
|
||||
} else {
|
||||
biomes = new HashSet<>();
|
||||
for (String string : biomeString.split(", ")) {
|
||||
if (!string.trim().equals(""))
|
||||
if (!string.trim().isEmpty()) {
|
||||
biomes.add(CompatibleBiome.getBiome(string).getBiome());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -349,11 +358,11 @@ public class SpawnerManager {
|
||||
}
|
||||
|
||||
public void reloadSpawnerData() {
|
||||
for (PlacedSpawner spawner : spawnersInWorld.values()) {
|
||||
for (PlacedSpawner spawner : this.spawnersInWorld.values()) {
|
||||
for (SpawnerStack stack : spawner.getSpawnerStacks()) {
|
||||
stack.setTier(registeredSpawnerData.get(stack.getSpawnerData().getIdentifyingName().toLowerCase())
|
||||
stack.setTier(this.registeredSpawnerData.get(stack.getSpawnerData().getIdentifyingName().toLowerCase())
|
||||
.getTierOrFirst(stack.getCurrentTier().getIdentifyingName()));
|
||||
plugin.getDataManager().save(stack);
|
||||
this.plugin.getDataManager().save(stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -364,11 +373,13 @@ public class SpawnerManager {
|
||||
|
||||
ConfigurationSection spawnersSection = spawnerConfig.createSection("Spawners");
|
||||
|
||||
if (spawnerConfig.contains("Spawners"))
|
||||
if (spawnerConfig.contains("Spawners")) {
|
||||
for (String spawnerName : spawnersSection.getKeys(false)) {
|
||||
if (registeredSpawnerData.containsKey(spawnerName))
|
||||
if (this.registeredSpawnerData.containsKey(spawnerName)) {
|
||||
spawnersSection.set(spawnerName, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (SpawnerData spawnerData : getAllSpawnerData()) {
|
||||
@ -422,16 +433,21 @@ public class SpawnerManager {
|
||||
currentSection2.set("Conditions.Biomes", String.join(", ", ((SpawnConditionBiome) spawnCondition).getBiomes().stream().map(Enum::name).collect(Collectors.toSet())));
|
||||
}
|
||||
}
|
||||
if (spawnCondition instanceof SpawnConditionHeight)
|
||||
if (spawnCondition instanceof SpawnConditionHeight) {
|
||||
currentSection2.set("Conditions.Height", ((SpawnConditionHeight) spawnCondition).getMin() + ":" + ((SpawnConditionHeight) spawnCondition).getMax());
|
||||
if (spawnCondition instanceof SpawnConditionLightDark)
|
||||
}
|
||||
if (spawnCondition instanceof SpawnConditionLightDark) {
|
||||
currentSection2.set("Conditions.Light", ((SpawnConditionLightDark) spawnCondition).getType().name());
|
||||
if (spawnCondition instanceof SpawnConditionStorm)
|
||||
}
|
||||
if (spawnCondition instanceof SpawnConditionStorm) {
|
||||
currentSection2.set("Conditions.Storm Only", ((SpawnConditionStorm) spawnCondition).isStormOnly());
|
||||
if (spawnCondition instanceof SpawnConditionNearbyEntities)
|
||||
}
|
||||
if (spawnCondition instanceof SpawnConditionNearbyEntities) {
|
||||
currentSection2.set("Conditions.Max Entities Around Spawner", ((SpawnConditionNearbyEntities) spawnCondition).getMax());
|
||||
if (spawnCondition instanceof SpawnConditionNearbyPlayers)
|
||||
}
|
||||
if (spawnCondition instanceof SpawnConditionNearbyPlayers) {
|
||||
currentSection2.set("Conditions.Required Player Distance And Amount", ((SpawnConditionNearbyPlayers) spawnCondition).getDistance() + ":" + ((SpawnConditionNearbyPlayers) spawnCondition).getAmount());
|
||||
}
|
||||
}
|
||||
|
||||
if (spawnerTier.getDisplayItem() != null) {
|
||||
@ -444,11 +460,11 @@ public class SpawnerManager {
|
||||
|
||||
public boolean wasConfigModified() {
|
||||
getSpawnerConfig().load();
|
||||
return !this.spawnerConfig.getFileConfig().saveToString().equals(lastLoad);
|
||||
return !this.spawnerConfig.getFileConfig().saveToString().equals(this.lastLoad);
|
||||
}
|
||||
|
||||
public Config getSpawnerConfig() {
|
||||
return spawnerConfig;
|
||||
return this.spawnerConfig;
|
||||
}
|
||||
|
||||
public void reloadFromFile() {
|
||||
@ -457,10 +473,10 @@ public class SpawnerManager {
|
||||
}
|
||||
|
||||
public PlacedSpawner getSpawner(int id) {
|
||||
return spawnersInWorld.values().stream().filter(spawner -> spawner.getId() == id).findFirst().orElse(null);
|
||||
return this.spawnersInWorld.values().stream().filter(spawner -> spawner.getId() == id).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public PlacedSpawner getSpawner(Location location) {
|
||||
return spawnersInWorld.get(location);
|
||||
return this.spawnersInWorld.get(location);
|
||||
}
|
||||
}
|
||||
|
@ -8,19 +8,17 @@ import com.craftaro.epicspawners.api.events.SpawnerChangeEvent;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerData;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerStack;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerTier;
|
||||
import com.craftaro.epicspawners.settings.Settings;
|
||||
import com.craftaro.epicspawners.api.utils.CostType;
|
||||
import com.craftaro.epicspawners.settings.Settings;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class SpawnerStackImpl implements SpawnerStack {
|
||||
|
||||
private PlacedSpawnerImpl spawner;
|
||||
private int stackSize;
|
||||
|
||||
@ -58,14 +56,15 @@ public class SpawnerStackImpl implements SpawnerStack {
|
||||
|
||||
public SpawnerStackImpl(PlacedSpawnerImpl spawner, SpawnerTier tier, int stackSize) {
|
||||
this.spawner = spawner;
|
||||
if (tier != null)
|
||||
if (tier != null) {
|
||||
this.currentTier = tier;
|
||||
}
|
||||
this.stackSize = stackSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlacedSpawnerImpl getSpawner() {
|
||||
return spawner;
|
||||
return this.spawner;
|
||||
}
|
||||
|
||||
public void setSpawner(PlacedSpawnerImpl spawner) {
|
||||
@ -74,7 +73,7 @@ public class SpawnerStackImpl implements SpawnerStack {
|
||||
|
||||
@Override
|
||||
public int getStackSize() {
|
||||
return stackSize;
|
||||
return this.stackSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -84,12 +83,12 @@ public class SpawnerStackImpl implements SpawnerStack {
|
||||
|
||||
@Override
|
||||
public SpawnerTier getCurrentTier() {
|
||||
return currentTier;
|
||||
return this.currentTier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpawnerData getSpawnerData() {
|
||||
return currentTier.getSpawnerData();
|
||||
return this.currentTier.getSpawnerData();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -102,16 +101,16 @@ public class SpawnerStackImpl implements SpawnerStack {
|
||||
public void upgrade(Player player, CostType type) {
|
||||
EpicSpawners plugin = EpicSpawners.getInstance();
|
||||
|
||||
if (getSpawnerData().getNextTier(currentTier) == null) {
|
||||
if (getSpawnerData().getNextTier(this.currentTier) == null) {
|
||||
plugin.getLocale().getMessage("event.upgrade.maxed").sendPrefixedMessage(player);
|
||||
return;
|
||||
}
|
||||
|
||||
SpawnerTier tier = getSpawnerData().getNextTier(currentTier);
|
||||
SpawnerChangeEvent event = new SpawnerChangeEvent(player, spawner, tier, currentTier);
|
||||
SpawnerTier tier = getSpawnerData().getNextTier(this.currentTier);
|
||||
SpawnerChangeEvent event = new SpawnerChangeEvent(player, this.spawner, tier, this.currentTier);
|
||||
|
||||
double cost = tier.getUpgradeCost(type);
|
||||
SpawnerTier oldTier = currentTier;
|
||||
SpawnerTier oldTier = this.currentTier;
|
||||
|
||||
if (type == CostType.ECONOMY) {
|
||||
if (!EconomyManager.isEnabled()) {
|
||||
@ -124,27 +123,33 @@ public class SpawnerStackImpl implements SpawnerStack {
|
||||
}
|
||||
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) return;
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!player.isOp())
|
||||
if (!player.isOp()) {
|
||||
EconomyManager.withdrawBalance(player, cost);
|
||||
}
|
||||
|
||||
currentTier = tier;
|
||||
this.currentTier = tier;
|
||||
} else if (type == CostType.LEVELS) {
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) return;
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.getLevel() >= cost || player.getGameMode() == GameMode.CREATIVE && !Settings.CHARGE_FOR_CREATIVE.getBoolean()) {
|
||||
if (player.getGameMode() != GameMode.CREATIVE || Settings.CHARGE_FOR_CREATIVE.getBoolean())
|
||||
if (player.getGameMode() != GameMode.CREATIVE || Settings.CHARGE_FOR_CREATIVE.getBoolean()) {
|
||||
player.setLevel(player.getLevel() - Math.toIntExact(Math.round(cost)));
|
||||
}
|
||||
|
||||
currentTier = tier;
|
||||
spawner.upgradeEffects(player, tier, false);
|
||||
this.currentTier = tier;
|
||||
this.spawner.upgradeEffects(player, tier, false);
|
||||
} else {
|
||||
plugin.getLocale().getMessage("event.upgrade.cannotafford").sendPrefixedMessage(player);
|
||||
}
|
||||
}
|
||||
if (!spawner.merge(this, oldTier)) {
|
||||
if (!this.spawner.merge(this, oldTier)) {
|
||||
plugin.getDataManager().getDatabaseConnector().connectDSL(dslContext -> {
|
||||
//Update tier
|
||||
dslContext.update(DSL.table(plugin.getDataManager().getTablePrefix() + "spawner_stacks"))
|
||||
@ -160,7 +165,7 @@ public class SpawnerStackImpl implements SpawnerStack {
|
||||
@Override
|
||||
public void convert(SpawnerData data, Player player, boolean forced) {
|
||||
EpicSpawners plugin = EpicSpawners.getInstance();
|
||||
SpawnerTier oldTier = currentTier;
|
||||
SpawnerTier oldTier = this.currentTier;
|
||||
|
||||
if (!EconomyManager.isEnabled()) {
|
||||
player.sendMessage("Economy not enabled.");
|
||||
@ -173,30 +178,31 @@ public class SpawnerStackImpl implements SpawnerStack {
|
||||
return;
|
||||
}
|
||||
|
||||
SpawnerChangeEvent event = new SpawnerChangeEvent(player, spawner, currentTier, data.getFirstTier());
|
||||
SpawnerChangeEvent event = new SpawnerChangeEvent(player, this.spawner, this.currentTier, data.getFirstTier());
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentTier = data.getFirstTier();
|
||||
if (!spawner.merge(this, oldTier)) {
|
||||
plugin.getDataManager().save(this, "spawner_id", spawner.getId());
|
||||
this.currentTier = data.getFirstTier();
|
||||
if (!this.spawner.merge(this, oldTier)) {
|
||||
plugin.getDataManager().save(this, "spawner_id", this.spawner.getId());
|
||||
}
|
||||
try {
|
||||
spawner.getCreatureSpawner().setSpawnedType(EntityType.valueOf(data.getIdentifyingName().toUpperCase()));
|
||||
this.spawner.getCreatureSpawner().setSpawnedType(EntityType.valueOf(data.getIdentifyingName().toUpperCase()));
|
||||
} catch (Exception e) {
|
||||
spawner.getCreatureSpawner().setSpawnedType(EntityType.DROPPED_ITEM);
|
||||
this.spawner.getCreatureSpawner().setSpawnedType(EntityType.DROPPED_ITEM);
|
||||
}
|
||||
spawner.getCreatureSpawner().update();
|
||||
this.spawner.getCreatureSpawner().update();
|
||||
|
||||
plugin.getLocale().getMessage("event.convert.success").sendPrefixedMessage(player);
|
||||
|
||||
plugin.updateHologram(spawner);
|
||||
plugin.getAppearanceTask().updateDisplayItem(spawner, currentTier);
|
||||
plugin.updateHologram(this.spawner);
|
||||
plugin.getAppearanceTask().updateDisplayItem(this.spawner, this.currentTier);
|
||||
player.closeInventory();
|
||||
if (!forced)
|
||||
if (!forced) {
|
||||
EconomyManager.withdrawBalance(player, price);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -222,4 +228,4 @@ public class SpawnerStackImpl implements SpawnerStack {
|
||||
public String getTableName() {
|
||||
return "spawner_stacks";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,26 +1,26 @@
|
||||
package com.craftaro.epicspawners.spawners.spawner;
|
||||
|
||||
import com.craftaro.core.gui.GuiUtils;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.third_party.de.tr7zw.nbtapi.NBTItem;
|
||||
import com.craftaro.core.utils.TextUtils;
|
||||
import com.craftaro.epicspawners.EpicSpawners;
|
||||
import com.craftaro.epicspawners.api.particles.ParticleDensity;
|
||||
import com.craftaro.epicspawners.api.particles.ParticleEffect;
|
||||
import com.craftaro.epicspawners.api.particles.ParticleType;
|
||||
import com.craftaro.epicspawners.api.spawners.condition.SpawnCondition;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.PlacedSpawner;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerData;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerStack;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerTier;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.option.SpawnOption;
|
||||
import com.craftaro.epicspawners.api.utils.CostType;
|
||||
import com.craftaro.epicspawners.settings.Settings;
|
||||
import com.craftaro.epicspawners.spawners.spawner.option.SpawnOptionBlock;
|
||||
import com.craftaro.epicspawners.spawners.spawner.option.SpawnOptionCommand;
|
||||
import com.craftaro.epicspawners.spawners.spawner.option.SpawnOptionEntity;
|
||||
import com.craftaro.epicspawners.spawners.spawner.option.SpawnOptionItem;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.gui.GuiUtils;
|
||||
import com.craftaro.core.third_party.de.tr7zw.nbtapi.NBTItem;
|
||||
import com.craftaro.core.utils.TextUtils;
|
||||
import com.craftaro.epicspawners.api.spawners.condition.SpawnCondition;
|
||||
import com.craftaro.epicspawners.api.utils.CostType;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -33,7 +33,6 @@ import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
public class SpawnerTierImpl implements SpawnerTier {
|
||||
|
||||
private final SpawnerData spawnerData;
|
||||
private String identifyingName;
|
||||
private String displayName;
|
||||
@ -75,22 +74,30 @@ public class SpawnerTierImpl implements SpawnerTier {
|
||||
this.identifyingName = "Tier_" + (tiers.isEmpty() ? "1" : Integer.parseInt(tiers.get(tiers.size() - 1).getIdentifyingName().split("_")[1]) + 1);
|
||||
this.spawnerData = spawnerData;
|
||||
|
||||
this.displayName = identifyingName;
|
||||
this.displayName = this.identifyingName;
|
||||
reloadSpawnMethods();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reloadSpawnMethods() {
|
||||
spawnOptions.clear();
|
||||
if (!entities.isEmpty()) spawnOptions.add(new SpawnOptionEntity(entities));
|
||||
if (!blocks.isEmpty()) spawnOptions.add(new SpawnOptionBlock(blocks));
|
||||
if (!items.isEmpty()) spawnOptions.add(new SpawnOptionItem(items));
|
||||
if (!commands.isEmpty()) spawnOptions.add(new SpawnOptionCommand(commands));
|
||||
this.spawnOptions.clear();
|
||||
if (!this.entities.isEmpty()) {
|
||||
this.spawnOptions.add(new SpawnOptionEntity(this.entities));
|
||||
}
|
||||
if (!this.blocks.isEmpty()) {
|
||||
this.spawnOptions.add(new SpawnOptionBlock(this.blocks));
|
||||
}
|
||||
if (!this.items.isEmpty()) {
|
||||
this.spawnOptions.add(new SpawnOptionItem(this.items));
|
||||
}
|
||||
if (!this.commands.isEmpty()) {
|
||||
this.spawnOptions.add(new SpawnOptionCommand(this.commands));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawn(PlacedSpawner spawner, SpawnerStack stack) {
|
||||
for (SpawnOption spawnOption : spawnOptions) {
|
||||
for (SpawnOption spawnOption : this.spawnOptions) {
|
||||
spawnOption.spawn(this, stack, spawner);
|
||||
}
|
||||
}
|
||||
@ -113,8 +120,8 @@ public class SpawnerTierImpl implements SpawnerTier {
|
||||
item.setAmount(amount);
|
||||
|
||||
NBTItem nbtItem = new NBTItem(item);
|
||||
nbtItem.setString("data", spawnerData.getIdentifyingName());
|
||||
nbtItem.setString("tier", identifyingName);
|
||||
nbtItem.setString("data", this.spawnerData.getIdentifyingName());
|
||||
nbtItem.setString("tier", this.identifyingName);
|
||||
nbtItem.setInteger("size", stackSize);
|
||||
|
||||
return nbtItem.getItem();
|
||||
@ -122,12 +129,12 @@ public class SpawnerTierImpl implements SpawnerTier {
|
||||
|
||||
@Override
|
||||
public String getIdentifyingName() {
|
||||
return identifyingName;
|
||||
return this.identifyingName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFullyIdentifyingName() {
|
||||
return spawnerData.getIdentifyingName() + identifyingName;
|
||||
return this.spawnerData.getIdentifyingName() + this.identifyingName;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -137,7 +144,7 @@ public class SpawnerTierImpl implements SpawnerTier {
|
||||
|
||||
@Override
|
||||
public double getPickupCost() {
|
||||
return pickupCost;
|
||||
return this.pickupCost;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -147,7 +154,7 @@ public class SpawnerTierImpl implements SpawnerTier {
|
||||
|
||||
@Override
|
||||
public XMaterial[] getSpawnBlocks() {
|
||||
return spawnBlocks.toArray(new XMaterial[spawnBlocks.size()]);
|
||||
return this.spawnBlocks.toArray(new XMaterial[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -157,12 +164,12 @@ public class SpawnerTierImpl implements SpawnerTier {
|
||||
|
||||
@Override
|
||||
public List<XMaterial> getSpawnBlocksList() {
|
||||
return Collections.unmodifiableList(spawnBlocks);
|
||||
return Collections.unmodifiableList(this.spawnBlocks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSpawnOnFire() {
|
||||
return spawnOnFire;
|
||||
return this.spawnOnFire;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -172,7 +179,7 @@ public class SpawnerTierImpl implements SpawnerTier {
|
||||
|
||||
@Override
|
||||
public double getCostEconomy() {
|
||||
return costEconomy;
|
||||
return this.costEconomy;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -182,7 +189,7 @@ public class SpawnerTierImpl implements SpawnerTier {
|
||||
|
||||
@Override
|
||||
public int getCostLevels() {
|
||||
return CostLevels;
|
||||
return this.CostLevels;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -193,16 +200,17 @@ public class SpawnerTierImpl implements SpawnerTier {
|
||||
@Override
|
||||
public double getUpgradeCost(CostType type) {
|
||||
double cost = 0;
|
||||
if (type == CostType.ECONOMY)
|
||||
if (type == CostType.ECONOMY) {
|
||||
cost = getCostEconomy();
|
||||
else if (type == CostType.LEVELS)
|
||||
} else if (type == CostType.LEVELS) {
|
||||
cost = getCostLevels();
|
||||
}
|
||||
return cost;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
return this.displayName;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -240,7 +248,7 @@ public class SpawnerTierImpl implements SpawnerTier {
|
||||
|
||||
@Override
|
||||
public XMaterial getDisplayItem() {
|
||||
return displayItem == null ? XMaterial.AIR : displayItem;
|
||||
return this.displayItem == null ? XMaterial.AIR : this.displayItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -250,7 +258,7 @@ public class SpawnerTierImpl implements SpawnerTier {
|
||||
|
||||
@Override
|
||||
public List<EntityType> getEntities() {
|
||||
return Collections.unmodifiableList(entities);
|
||||
return Collections.unmodifiableList(this.entities);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -260,7 +268,7 @@ public class SpawnerTierImpl implements SpawnerTier {
|
||||
|
||||
@Override
|
||||
public List<XMaterial> getBlocks() {
|
||||
return Collections.unmodifiableList(blocks);
|
||||
return Collections.unmodifiableList(this.blocks);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -270,7 +278,7 @@ public class SpawnerTierImpl implements SpawnerTier {
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getItems() {
|
||||
return Collections.unmodifiableList(items);
|
||||
return Collections.unmodifiableList(this.items);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -280,7 +288,7 @@ public class SpawnerTierImpl implements SpawnerTier {
|
||||
|
||||
@Override
|
||||
public List<String> getCommands() {
|
||||
return Collections.unmodifiableList(commands);
|
||||
return Collections.unmodifiableList(this.commands);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -290,7 +298,7 @@ public class SpawnerTierImpl implements SpawnerTier {
|
||||
|
||||
@Override
|
||||
public short getPickDamage() {
|
||||
return pickDamage;
|
||||
return this.pickDamage;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -300,7 +308,7 @@ public class SpawnerTierImpl implements SpawnerTier {
|
||||
|
||||
@Override
|
||||
public String getTickRate() {
|
||||
return tickRate;
|
||||
return this.tickRate;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -310,7 +318,7 @@ public class SpawnerTierImpl implements SpawnerTier {
|
||||
|
||||
@Override
|
||||
public ParticleEffect getParticleEffect() {
|
||||
return particleEffect;
|
||||
return this.particleEffect;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -320,7 +328,7 @@ public class SpawnerTierImpl implements SpawnerTier {
|
||||
|
||||
@Override
|
||||
public ParticleType getSpawnEffectParticle() {
|
||||
return spawnEffectParticle;
|
||||
return this.spawnEffectParticle;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -335,12 +343,12 @@ public class SpawnerTierImpl implements SpawnerTier {
|
||||
|
||||
@Override
|
||||
public int getSpawnLimit() {
|
||||
return spawnLimit;
|
||||
return this.spawnLimit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParticleType getEntitySpawnParticle() {
|
||||
return entitySpawnParticle;
|
||||
return this.entitySpawnParticle;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -350,7 +358,7 @@ public class SpawnerTierImpl implements SpawnerTier {
|
||||
|
||||
@Override
|
||||
public ParticleType getSpawnerSpawnParticle() {
|
||||
return spawnerSpawnParticle;
|
||||
return this.spawnerSpawnParticle;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -360,7 +368,7 @@ public class SpawnerTierImpl implements SpawnerTier {
|
||||
|
||||
@Override
|
||||
public ParticleDensity getParticleDensity() {
|
||||
return particleDensity;
|
||||
return this.particleDensity;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -370,7 +378,7 @@ public class SpawnerTierImpl implements SpawnerTier {
|
||||
|
||||
@Override
|
||||
public boolean isParticleEffectBoostedOnly() {
|
||||
return particleEffectBoostedOnly;
|
||||
return this.particleEffectBoostedOnly;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -380,22 +388,22 @@ public class SpawnerTierImpl implements SpawnerTier {
|
||||
|
||||
@Override
|
||||
public void addCondition(SpawnCondition spawnCondition) {
|
||||
spawnConditions.add(spawnCondition);
|
||||
this.spawnConditions.add(spawnCondition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeCondition(SpawnCondition spawnCondition) {
|
||||
spawnConditions.remove(spawnCondition);
|
||||
this.spawnConditions.remove(spawnCondition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SpawnCondition> getConditions() {
|
||||
return Collections.unmodifiableList(spawnConditions);
|
||||
return Collections.unmodifiableList(this.spawnConditions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SpawnerData:{Name:\"" + identifyingName + "\"}";
|
||||
return "SpawnerData:{Name:\"" + this.identifyingName + "\"}";
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -403,14 +411,19 @@ public class SpawnerTierImpl implements SpawnerTier {
|
||||
Preconditions.checkNotNull(item, "Cannot get stack size of null item");
|
||||
NBTItem nbtItem = new NBTItem(item);
|
||||
|
||||
if (nbtItem.hasKey("size"))
|
||||
if (nbtItem.hasTag("size")) {
|
||||
return nbtItem.getInteger("size");
|
||||
}
|
||||
|
||||
// Legacy
|
||||
if (!item.hasItemMeta() && !item.getItemMeta().hasDisplayName()) return 1;
|
||||
if (!item.hasItemMeta() && !item.getItemMeta().hasDisplayName()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
String name = item.getItemMeta().getDisplayName();
|
||||
if (!name.contains(":")) return 1;
|
||||
if (!name.contains(":")) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
String amount = name.replace(String.valueOf(ChatColor.COLOR_CHAR), "").replace(";", "").split(":")[1];
|
||||
if (amount == null) {
|
||||
@ -422,28 +435,33 @@ public class SpawnerTierImpl implements SpawnerTier {
|
||||
|
||||
@Override
|
||||
public String getGuiTitle() {
|
||||
if (spawnerData.getTiers().size() == 1)
|
||||
return TextUtils.formatText("&e" + displayName);
|
||||
else
|
||||
return TextUtils.formatText("&e" + spawnerData.getIdentifyingName() + " &8(" + displayName + ")");
|
||||
if (this.spawnerData.getTiers().size() == 1) {
|
||||
return TextUtils.formatText("&e" + this.displayName);
|
||||
} else {
|
||||
return TextUtils.formatText("&e" + this.spawnerData.getIdentifyingName() + " &8(" + this.displayName + ")");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpawnerData getSpawnerData() {
|
||||
return spawnerData;
|
||||
return this.spawnerData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
SpawnerTierImpl tier = (SpawnerTierImpl) o;
|
||||
return Objects.equals(spawnerData, tier.spawnerData) &&
|
||||
Objects.equals(identifyingName, tier.identifyingName);
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null || getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
SpawnerTierImpl tier = (SpawnerTierImpl) obj;
|
||||
return Objects.equals(this.spawnerData, tier.spawnerData) &&
|
||||
Objects.equals(this.identifyingName, tier.identifyingName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(spawnerData, identifyingName);
|
||||
return Objects.hash(this.spawnerData, this.identifyingName);
|
||||
}
|
||||
}
|
||||
|
@ -9,9 +9,6 @@ import com.craftaro.epicspawners.api.spawners.spawner.SpawnerStack;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerTier;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.option.SpawnOption;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.option.SpawnOptionType;
|
||||
import com.craftaro.epicspawners.boost.types.BoostedImpl;
|
||||
import com.craftaro.epicspawners.spawners.spawner.PlacedSpawnerImpl;
|
||||
import com.craftaro.epicspawners.spawners.spawner.SpawnerStackImpl;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
@ -21,7 +18,6 @@ import java.util.Collection;
|
||||
import java.util.Random;
|
||||
|
||||
public class SpawnOptionBlock implements SpawnOption {
|
||||
|
||||
private static final int MAX_SEARCH_COUNT = 250;
|
||||
private static final int SPAWN_RADIUS = 3;
|
||||
|
||||
@ -34,24 +30,26 @@ public class SpawnOptionBlock implements SpawnOption {
|
||||
}
|
||||
|
||||
public SpawnOptionBlock(Collection<XMaterial> blocks) {
|
||||
this(blocks.toArray(new XMaterial[blocks.size()]));
|
||||
this(blocks.toArray(new XMaterial[0]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawn(SpawnerTier data, SpawnerStack stack, PlacedSpawner spawner) {
|
||||
Location location = spawner.getLocation();
|
||||
if (location == null || location.getWorld() == null) return;
|
||||
if (location == null || location.getWorld() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int spawnerBoost = spawner.getBoosts().stream().mapToInt(Boosted::getAmountBoosted).sum();
|
||||
for (int i = 0; i < stack.getStackSize() + spawnerBoost; i++) {
|
||||
for (XMaterial material : blocks) {
|
||||
for (XMaterial material : this.blocks) {
|
||||
int searchIndex = 0;
|
||||
while (searchIndex++ <= MAX_SEARCH_COUNT) {
|
||||
spawner.setSpawnCount(spawner.getSpawnCount() + 1);
|
||||
EpicSpawners.getInstance().getDataManager().save(spawner);
|
||||
double xOffset = random.nextInt((SPAWN_RADIUS * 2) + 1) - SPAWN_RADIUS;
|
||||
double yOffset = random.nextInt((SPAWN_RADIUS * 2) + 1) - SPAWN_RADIUS;
|
||||
double zOffset = random.nextInt((SPAWN_RADIUS * 2) + 1) - SPAWN_RADIUS;
|
||||
double xOffset = this.random.nextInt((SPAWN_RADIUS * 2) + 1) - SPAWN_RADIUS;
|
||||
double yOffset = this.random.nextInt((SPAWN_RADIUS * 2) + 1) - SPAWN_RADIUS;
|
||||
double zOffset = this.random.nextInt((SPAWN_RADIUS * 2) + 1) - SPAWN_RADIUS;
|
||||
|
||||
// Get block at offset
|
||||
location.add(xOffset, yOffset, zOffset);
|
||||
@ -59,7 +57,9 @@ public class SpawnOptionBlock implements SpawnOption {
|
||||
location.subtract(xOffset, yOffset, zOffset);
|
||||
|
||||
// If block isn't air, try for another block
|
||||
if (spawnBlock.getType() != Material.AIR) continue;
|
||||
if (spawnBlock.getType() != Material.AIR) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Set Type and data for valid air block
|
||||
XBlock.setType(spawnBlock, material, true);
|
||||
@ -76,16 +76,19 @@ public class SpawnOptionBlock implements SpawnOption {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 31 * (blocks != null ? blocks.hashCode() : 0);
|
||||
return 31 * (this.blocks != null ? Arrays.hashCode(this.blocks) : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
if (object == this) return true;
|
||||
if (!(object instanceof SpawnOptionBlock)) return false;
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof SpawnOptionBlock)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SpawnOptionBlock other = (SpawnOptionBlock) object;
|
||||
return Arrays.equals(blocks, other.blocks);
|
||||
SpawnOptionBlock other = (SpawnOptionBlock) obj;
|
||||
return Arrays.equals(this.blocks, other.blocks);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,6 @@ import java.util.Collection;
|
||||
import java.util.Random;
|
||||
|
||||
public class SpawnOptionCommand implements SpawnOption {
|
||||
|
||||
private static final int MAX_SEARCH_COUNT = 150;
|
||||
private static final int SPAWN_RADIUS = 3;
|
||||
|
||||
@ -32,18 +31,20 @@ public class SpawnOptionCommand implements SpawnOption {
|
||||
}
|
||||
|
||||
public SpawnOptionCommand(Collection<String> commands) {
|
||||
this(commands.toArray(new String[commands.size()]));
|
||||
this(commands.toArray(new String[0]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawn(SpawnerTier data, SpawnerStack stack, PlacedSpawner spawner) {
|
||||
Location location = spawner.getLocation();
|
||||
if (location == null || location.getWorld() == null) return;
|
||||
if (location == null || location.getWorld() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int spawnerBoost = spawner.getBoosts().stream().mapToInt(Boosted::getAmountBoosted).sum();
|
||||
|
||||
for (int i = 0; i < stack.getStackSize() + spawnerBoost; i++) {
|
||||
for (String command : commands) {
|
||||
for (String command : this.commands) {
|
||||
String finalCommand = command;
|
||||
String lowercaseCommand = finalCommand.toLowerCase();
|
||||
|
||||
@ -53,9 +54,9 @@ public class SpawnOptionCommand implements SpawnOption {
|
||||
while (searchIndex++ <= MAX_SEARCH_COUNT) {
|
||||
spawner.setSpawnCount(spawner.getSpawnCount() + 1);
|
||||
EpicSpawners.getInstance().getDataManager().save(spawner);
|
||||
double xOffset = random.nextInt((SPAWN_RADIUS * 2) + 1) - SPAWN_RADIUS;
|
||||
double yOffset = random.nextInt((SPAWN_RADIUS * 2) + 1) - SPAWN_RADIUS;
|
||||
double zOffset = random.nextInt((SPAWN_RADIUS * 2) + 1) - SPAWN_RADIUS;
|
||||
double xOffset = this.random.nextInt((SPAWN_RADIUS * 2) + 1) - SPAWN_RADIUS;
|
||||
double yOffset = this.random.nextInt((SPAWN_RADIUS * 2) + 1) - SPAWN_RADIUS;
|
||||
double zOffset = this.random.nextInt((SPAWN_RADIUS * 2) + 1) - SPAWN_RADIUS;
|
||||
|
||||
location.add(xOffset, yOffset, zOffset);
|
||||
finalCommand = finalCommand.replaceAll("@[xX]", String.valueOf(location.getX()))
|
||||
@ -73,7 +74,9 @@ public class SpawnOptionCommand implements SpawnOption {
|
||||
// Get nearest player if @p is present in command
|
||||
if (lowercaseCommand.contains("@p")) {
|
||||
Player nearbyPlayer = getNearestPlayer(location);
|
||||
if (nearbyPlayer == null) continue;
|
||||
if (nearbyPlayer == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
finalCommand = finalCommand.replaceAll("@[pP]", nearbyPlayer.getName());
|
||||
}
|
||||
@ -95,9 +98,10 @@ public class SpawnOptionCommand implements SpawnOption {
|
||||
}
|
||||
|
||||
private Player getNearestPlayer(Location location) {
|
||||
|
||||
String[] playerRadius = EpicSpawners.getInstance().getConfig().getString("Main.Radius To Search Around Spawners").split("x");
|
||||
if (playerRadius.length != 3) return null;
|
||||
if (playerRadius.length != 3) {
|
||||
return null;
|
||||
}
|
||||
|
||||
double xRadius = NumberUtils.toDouble(playerRadius[0], 8);
|
||||
double yRadius = NumberUtils.toDouble(playerRadius[1], 4);
|
||||
@ -109,16 +113,19 @@ public class SpawnOptionCommand implements SpawnOption {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 31 * (commands != null ? commands.hashCode() : 0);
|
||||
return 31 * (this.commands != null ? Arrays.hashCode(this.commands) : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
if (object == this) return true;
|
||||
if (!(object instanceof SpawnOptionCommand)) return false;
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof SpawnOptionCommand)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SpawnOptionCommand other = (SpawnOptionCommand) object;
|
||||
return Arrays.equals(commands, other.commands);
|
||||
SpawnOptionCommand other = (SpawnOptionCommand) obj;
|
||||
return Arrays.equals(this.commands, other.commands);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -5,19 +5,17 @@ import com.craftaro.core.utils.EntityUtils;
|
||||
import com.craftaro.epicspawners.EpicSpawners;
|
||||
import com.craftaro.epicspawners.api.boosts.types.Boosted;
|
||||
import com.craftaro.epicspawners.api.events.SpawnerSpawnEvent;
|
||||
import com.craftaro.epicspawners.api.particles.ParticleType;
|
||||
import com.craftaro.epicspawners.api.spawners.condition.SpawnCondition;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.PlacedSpawner;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerStack;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerTier;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.option.SpawnOption;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.option.SpawnOptionType;
|
||||
import com.craftaro.epicspawners.boost.types.BoostedImpl;
|
||||
import com.craftaro.epicspawners.api.particles.ParticleType;
|
||||
import com.craftaro.epicspawners.settings.Settings;
|
||||
import com.craftaro.epicspawners.api.spawners.condition.SpawnCondition;
|
||||
import com.craftaro.epicspawners.spawners.condition.SpawnConditionNearbyEntities;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
|
||||
@ -27,7 +25,6 @@ import java.util.HashSet;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class SpawnOptionEntity implements SpawnOption {
|
||||
|
||||
private final EntityType[] types;
|
||||
|
||||
private final EpicSpawners plugin = EpicSpawners.getInstance();
|
||||
@ -46,7 +43,9 @@ public class SpawnOptionEntity implements SpawnOption {
|
||||
public void spawn(SpawnerTier data, SpawnerStack stack, PlacedSpawner spawner) {
|
||||
Location location = spawner.getLocation();
|
||||
location.add(.5, .5, .5);
|
||||
if (location.getWorld() == null) return;
|
||||
if (location.getWorld() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String highLow = Settings.RANDOM_LOW_HIGH.getString();
|
||||
String[] randomLowHigh = highLow.split(":");
|
||||
@ -63,20 +62,21 @@ public class SpawnOptionEntity implements SpawnOption {
|
||||
equation = equation.replace("{RAND}", Integer.toString(randomAmt));
|
||||
equation = equation.replace("{STACK_SIZE}", Integer.toString(stack.getStackSize()));
|
||||
|
||||
spawnCount += MathUtils.eval(equation,
|
||||
"EpicSpawners (Mobs Spawned Per Single Spawn) Equation");
|
||||
spawnCount += MathUtils.eval(equation, "EpicSpawners (Mobs Spawned Per Single Spawn) Equation");
|
||||
}
|
||||
|
||||
// Get the max entities allowed around a spawner.
|
||||
int maxEntitiesAllowed = 0;
|
||||
for (SpawnCondition spawnCondition : data.getConditions()) {
|
||||
if (spawnCondition instanceof SpawnConditionNearbyEntities)
|
||||
if (spawnCondition instanceof SpawnConditionNearbyEntities) {
|
||||
maxEntitiesAllowed = ((SpawnConditionNearbyEntities) spawnCondition).getMax();
|
||||
}
|
||||
}
|
||||
|
||||
// Should we skip the max entity amount on first spawn?
|
||||
if (spawner.getSpawnCount() == 0 && Settings.IGNORE_MAX_ON_FIRST_SPAWN.getBoolean())
|
||||
if (spawner.getSpawnCount() == 0 && Settings.IGNORE_MAX_ON_FIRST_SPAWN.getBoolean()) {
|
||||
maxEntitiesAllowed = Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
// Get the amount of entities around the spawner.
|
||||
int size = SpawnConditionNearbyEntities.getEntitiesAroundSpawner(location, true);
|
||||
@ -95,20 +95,24 @@ public class SpawnOptionEntity implements SpawnOption {
|
||||
entity.remove();
|
||||
return false;
|
||||
}
|
||||
if (data.isSpawnOnFire()) entity.setFireTicks(160);
|
||||
if (data.isSpawnOnFire()) {
|
||||
entity.setFireTicks(160);
|
||||
}
|
||||
|
||||
entity.setMetadata("ESData", new FixedMetadataValue(plugin, data.getSpawnerData().getIdentifyingName()));
|
||||
entity.setMetadata("ESTier", new FixedMetadataValue(plugin, data.getIdentifyingName()));
|
||||
entity.setMetadata("ESData", new FixedMetadataValue(this.plugin, data.getSpawnerData().getIdentifyingName()));
|
||||
entity.setMetadata("ESTier", new FixedMetadataValue(this.plugin, data.getIdentifyingName()));
|
||||
|
||||
if (mcmmo)
|
||||
entity.setMetadata("mcMMO: Spawned Entity", new FixedMetadataValue(plugin, true));
|
||||
if (mcmmo) {
|
||||
entity.setMetadata("mcMMO: Spawned Entity", new FixedMetadataValue(this.plugin, true));
|
||||
}
|
||||
|
||||
if (Settings.NO_AI.getBoolean())
|
||||
if (Settings.NO_AI.getBoolean()) {
|
||||
EntityUtils.setUnaware(entity);
|
||||
}
|
||||
|
||||
plugin.getSpawnManager().addUnnaturalSpawn(entity.getUniqueId());
|
||||
this.plugin.getSpawnManager().addUnnaturalSpawn(entity.getUniqueId());
|
||||
return true;
|
||||
}, types);
|
||||
}, this.types);
|
||||
|
||||
spawner.setSpawnCount(spawner.getSpawnCount() + amountSpawned);
|
||||
EpicSpawners.getInstance().getDataManager().save(spawner);
|
||||
@ -121,15 +125,18 @@ public class SpawnOptionEntity implements SpawnOption {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 31 * (types != null ? Arrays.hashCode(types) : 0);
|
||||
return 31 * (this.types != null ? Arrays.hashCode(this.types) : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
if (object == this) return true;
|
||||
if (!(object instanceof SpawnOptionEntity)) return false;
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof SpawnOptionEntity)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SpawnOptionEntity other = (SpawnOptionEntity) object;
|
||||
return Arrays.equals(types, other.types);
|
||||
return Arrays.equals(this.types, ((SpawnOptionEntity) obj).types);
|
||||
}
|
||||
}
|
||||
|
@ -9,12 +9,8 @@ import com.craftaro.epicspawners.api.spawners.spawner.SpawnerStack;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerTier;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.option.SpawnOption;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.option.SpawnOptionType;
|
||||
import com.craftaro.epicspawners.boost.types.BoostedImpl;
|
||||
import com.craftaro.epicspawners.spawners.spawner.PlacedSpawnerImpl;
|
||||
import com.craftaro.epicspawners.spawners.spawner.SpawnerStackImpl;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -25,7 +21,6 @@ import java.util.Collection;
|
||||
import java.util.Random;
|
||||
|
||||
public class SpawnOptionItem implements SpawnOption {
|
||||
|
||||
private final Random random;
|
||||
private final ItemStack[] items;
|
||||
|
||||
@ -35,13 +30,15 @@ public class SpawnOptionItem implements SpawnOption {
|
||||
}
|
||||
|
||||
public SpawnOptionItem(Collection<ItemStack> items) {
|
||||
this(items.toArray(new ItemStack[items.size()]));
|
||||
this(items.toArray(new ItemStack[0]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawn(SpawnerTier data, SpawnerStack stack, PlacedSpawner spawner) {
|
||||
Location location = spawner.getLocation();
|
||||
if (location == null || location.getWorld() == null) return;
|
||||
if (location == null || location.getWorld() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
World world = location.getWorld();
|
||||
Location spawnLocation = location.clone().add(0.5, 0.9, 0.5);
|
||||
@ -53,15 +50,17 @@ public class SpawnOptionItem implements SpawnOption {
|
||||
|
||||
int spawnerBoost = spawner.getBoosts().stream().mapToInt(Boosted::getAmountBoosted).sum();
|
||||
for (int i = 0; i < stack.getStackSize() + spawnerBoost; i++) {
|
||||
for (ItemStack item : items) {
|
||||
if (item == null || item.getType() == Material.AIR) continue;
|
||||
for (ItemStack item : this.items) {
|
||||
if (item == null || item.getType() == Material.AIR) {
|
||||
continue;
|
||||
}
|
||||
Item droppedItem = world.dropItem(spawnLocation, item);
|
||||
spawner.setSpawnCount(spawner.getSpawnCount() + 1);
|
||||
EpicSpawners.getInstance().getDataManager().save(spawner);
|
||||
|
||||
double dx = -.2 + (.2 - -.2) * random.nextDouble();
|
||||
double dy = 0 + (.5 - 0) * random.nextDouble();
|
||||
double dz = -.2 + (.2 - -.2) * random.nextDouble();
|
||||
double dx = -.2 + (.2 - -.2) * this.random.nextDouble();
|
||||
double dy = 0 + (.5 - 0) * this.random.nextDouble();
|
||||
double dz = -.2 + (.2 - -.2) * this.random.nextDouble();
|
||||
|
||||
droppedItem.setVelocity(new Vector(dx, dy, dz));
|
||||
}
|
||||
@ -73,15 +72,18 @@ public class SpawnOptionItem implements SpawnOption {
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return 31 * (items != null ? items.hashCode() : 0);
|
||||
return 31 * (this.items != null ? Arrays.hashCode(this.items) : 0);
|
||||
}
|
||||
|
||||
public boolean equals(Object object) {
|
||||
if (object == this) return true;
|
||||
if (!(object instanceof SpawnOptionItem)) return false;
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof SpawnOptionItem)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SpawnOptionItem other = (SpawnOptionItem) object;
|
||||
return Arrays.equals(items, other.items);
|
||||
SpawnOptionItem other = (SpawnOptionItem) obj;
|
||||
return Arrays.equals(this.items, other.items);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,12 @@
|
||||
package com.craftaro.epicspawners.tasks;
|
||||
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.compatibility.ServerVersion;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.epicspawners.EpicSpawners;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.PlacedSpawner;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerStack;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerTier;
|
||||
import com.craftaro.epicspawners.settings.Settings;
|
||||
import com.craftaro.epicspawners.spawners.spawner.PlacedSpawnerImpl;
|
||||
import com.craftaro.epicspawners.spawners.spawner.SpawnerStackImpl;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
@ -22,7 +20,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AppearanceTask extends BukkitRunnable {
|
||||
|
||||
private static AppearanceTask instance;
|
||||
|
||||
private AppearanceTask() {
|
||||
@ -43,21 +40,26 @@ public class AppearanceTask extends BukkitRunnable {
|
||||
|
||||
for (PlacedSpawner spawner : new ArrayList<>(instance.getSpawnerManager().getSpawners())) {
|
||||
Location location = spawner.getLocation();
|
||||
if (location == null || location.getWorld() == null) continue;
|
||||
if (location == null || location.getWorld() == null) {
|
||||
continue;
|
||||
}
|
||||
int destx = location.getBlockX() >> 4;
|
||||
int destz = location.getBlockZ() >> 4;
|
||||
if (!location.getWorld().isChunkLoaded(destx, destz)) {
|
||||
continue;
|
||||
}
|
||||
if (XMaterial.matchXMaterial(location.getBlock().getType().name()).get() != XMaterial.SPAWNER)
|
||||
if (XMaterial.matchXMaterial(location.getBlock().getType().name()).get() != XMaterial.SPAWNER) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (spawner.getSpawnerStacks().size() <= 1) {
|
||||
updateDisplayItem(spawner, spawner.getFirstStack().getCurrentTier());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!Settings.OMNI_SPAWNERS.getBoolean()) continue;
|
||||
if (!Settings.OMNI_SPAWNERS.getBoolean()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String last = null;
|
||||
SpawnerTier next = null;
|
||||
@ -69,14 +71,17 @@ public class AppearanceTask extends BukkitRunnable {
|
||||
next = stack.getCurrentTier();
|
||||
}
|
||||
}
|
||||
if (next == null)
|
||||
if (next == null) {
|
||||
next = spawner.getFirstTier();
|
||||
}
|
||||
|
||||
updateDisplayItem(spawner, next);
|
||||
spawner.setOmniState(next.getIdentifyingName());
|
||||
|
||||
CreatureSpawner creatureSpawner = spawner.getCreatureSpawner();
|
||||
if (creatureSpawner == null) continue;
|
||||
if (creatureSpawner == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
creatureSpawner.update();
|
||||
}
|
||||
@ -92,8 +97,9 @@ public class AppearanceTask extends BukkitRunnable {
|
||||
location.add(.5, -.4, .5);
|
||||
|
||||
ItemStack itemStack = new ItemStack(Material.DIRT);
|
||||
if (spawnerTier.getDisplayItem() != null)
|
||||
if (spawnerTier.getDisplayItem() != null) {
|
||||
itemStack = spawnerTier.getDisplayItem().parseItem();
|
||||
}
|
||||
|
||||
List<Entity> entities = getDisplayItem(spawner);
|
||||
|
||||
@ -103,7 +109,9 @@ public class AppearanceTask extends BukkitRunnable {
|
||||
entities.remove(entity);
|
||||
continue;
|
||||
}
|
||||
if (((ArmorStand) entity).getHelmet().getType() == itemStack.getType()) return;
|
||||
if (((ArmorStand) entity).getHelmet().getType() == itemStack.getType()) {
|
||||
return;
|
||||
}
|
||||
entity.remove();
|
||||
}
|
||||
}
|
||||
@ -113,7 +121,9 @@ public class AppearanceTask extends BukkitRunnable {
|
||||
spawner.getCreatureSpawner().setSpawnedType(next);
|
||||
} catch (Exception failure) {
|
||||
spawner.getCreatureSpawner().setSpawnedType(ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9) ? EntityType.EGG : EntityType.DROPPED_ITEM);
|
||||
if (itemStack.getType() == Material.AIR) return;
|
||||
if (itemStack.getType() == Material.AIR) {
|
||||
return;
|
||||
}
|
||||
location.setPitch(-360);
|
||||
ArmorStand as = (ArmorStand) location.getWorld().spawnEntity(location, EntityType.ARMOR_STAND);
|
||||
as.setSmall(true);
|
||||
@ -129,7 +139,9 @@ public class AppearanceTask extends BukkitRunnable {
|
||||
|
||||
public void removeDisplayItem(PlacedSpawner spawner) {
|
||||
List<Entity> entites = getDisplayItem(spawner);
|
||||
if (entites == null) return;
|
||||
if (entites == null) {
|
||||
return;
|
||||
}
|
||||
for (Entity entity : entites) {
|
||||
entity.remove();
|
||||
}
|
||||
@ -141,7 +153,7 @@ public class AppearanceTask extends BukkitRunnable {
|
||||
|
||||
List<Entity> near = (List<Entity>) location.getWorld().getNearbyEntities(location, .1, .1, .1);
|
||||
near.removeIf(entity -> entity == null || entity.getType() != EntityType.ARMOR_STAND || entity.getCustomName() == null || !entity.getCustomName().equalsIgnoreCase("EpicSpawners-Display"));
|
||||
if (near.size() != 0) {
|
||||
if (!near.isEmpty()) {
|
||||
return near;
|
||||
}
|
||||
return null;
|
||||
|
@ -8,7 +8,6 @@ import com.craftaro.epicspawners.api.particles.ParticleEffect;
|
||||
import com.craftaro.epicspawners.api.particles.ParticleType;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.PlacedSpawner;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.SpawnerTier;
|
||||
import com.craftaro.epicspawners.spawners.spawner.PlacedSpawnerImpl;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
@ -17,7 +16,6 @@ import org.bukkit.scheduler.BukkitRunnable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class SpawnerParticleTask extends BukkitRunnable {
|
||||
|
||||
private static final double THETA_INCREMENT = Math.PI / 18.0; // 10 degrees
|
||||
private static final int HALO_RADIUS = 1;
|
||||
|
||||
@ -40,29 +38,37 @@ public class SpawnerParticleTask extends BukkitRunnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (PlacedSpawner spawner : new ArrayList<>(plugin.getSpawnerManager().getSpawners())) {
|
||||
for (PlacedSpawner spawner : new ArrayList<>(this.plugin.getSpawnerManager().getSpawners())) {
|
||||
if (spawner == null || spawner.getLocation() == null ||
|
||||
spawner.getStackSize() == 0 || spawner.getFirstStack().getSpawnerData() == null)
|
||||
spawner.getStackSize() == 0 || spawner.getFirstStack().getSpawnerData() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
SpawnerTier data = spawner.getFirstStack().getCurrentTier();
|
||||
if (data == null) continue;
|
||||
if (data == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ParticleEffect effect = data.getParticleEffect();
|
||||
if (effect == null || effect == ParticleEffect.NONE || (data.isParticleEffectBoostedOnly() && spawner.getBoosts().isEmpty()))
|
||||
if (effect == null || effect == ParticleEffect.NONE || (data.isParticleEffectBoostedOnly() && spawner.getBoosts().isEmpty())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Location centre = spawner.getLocation().add(0.5, 0.5, 0.5);
|
||||
|
||||
ParticleType particle = data.getSpawnEffectParticle();
|
||||
if (particle == null || particle.getEffect() == null) continue;
|
||||
if (particle == null || particle.getEffect() == null) {
|
||||
continue;
|
||||
}
|
||||
ParticleDensity density = data.getParticleDensity();
|
||||
if (density == null) continue;
|
||||
if (density == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Particle effects
|
||||
if (effect == ParticleEffect.HALO) {
|
||||
double x = HALO_RADIUS * Math.cos(theta);
|
||||
double z = HALO_RADIUS * Math.sin(theta);
|
||||
double x = HALO_RADIUS * Math.cos(this.theta);
|
||||
double z = HALO_RADIUS * Math.sin(this.theta);
|
||||
|
||||
centre.add(x, 0.2, z);
|
||||
spawnParticles(centre, particle, density);
|
||||
@ -90,7 +96,7 @@ public class SpawnerParticleTask extends BukkitRunnable {
|
||||
}
|
||||
}
|
||||
|
||||
if ((theta += THETA_INCREMENT) > 360) {
|
||||
if ((this.theta += THETA_INCREMENT) > 360) {
|
||||
this.theta = 0;
|
||||
}
|
||||
}
|
||||
@ -105,4 +111,4 @@ public class SpawnerParticleTask extends BukkitRunnable {
|
||||
location, density.getEffect(), 0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,14 +2,13 @@ package com.craftaro.epicspawners.tasks;
|
||||
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.epicspawners.EpicSpawners;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.PlacedSpawner;
|
||||
import com.craftaro.epicspawners.settings.Settings;
|
||||
import com.craftaro.epicspawners.spawners.spawner.PlacedSpawnerImpl;
|
||||
import com.craftaro.epicspawners.spawners.spawner.SpawnerManager;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class SpawnerSpawnTask extends BukkitRunnable {
|
||||
|
||||
private static SpawnerSpawnTask instance;
|
||||
private static EpicSpawners plugin;
|
||||
|
||||
@ -32,11 +31,13 @@ public class SpawnerSpawnTask extends BukkitRunnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (PlacedSpawnerImpl spawner : manager.getSpawners().toArray(new PlacedSpawnerImpl[0])) {
|
||||
for (PlacedSpawner spawner : this.manager.getSpawners().toArray(new PlacedSpawner[0])) {
|
||||
try {
|
||||
if (spawner.getWorld() == null
|
||||
|| plugin.getBlacklistHandler().isBlacklisted(spawner.getWorld())
|
||||
|| !spawner.getWorld().isChunkLoaded(spawner.getX() >> 4, spawner.getZ() >> 4)) continue;
|
||||
|| !spawner.getWorld().isChunkLoaded(spawner.getX() >> 4, spawner.getZ() >> 4)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (spawner.getLocation().getBlock().getType() != XMaterial.SPAWNER.parseMaterial()
|
||||
|| !spawner.isValid()) {
|
||||
@ -46,14 +47,20 @@ public class SpawnerSpawnTask extends BukkitRunnable {
|
||||
|
||||
if (spawner.getStackSize() == 0
|
||||
|| (spawner.getPlacedBy() == null && Settings.DISABLE_NATURAL_SPAWNERS.getBoolean())
|
||||
|| !spawner.checkConditions()) continue;
|
||||
|| !spawner.checkConditions()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
CreatureSpawner cSpawner = spawner.getCreatureSpawner();
|
||||
if (cSpawner == null) continue;
|
||||
if (cSpawner == null) {
|
||||
continue;
|
||||
}
|
||||
int delay = spawner.getCreatureSpawner().getDelay();
|
||||
delay = delay - Settings.CUSTOM_SPAWNER_TICK_RATE.getInt();
|
||||
spawner.getCreatureSpawner().setDelay(delay);
|
||||
if (delay >= 0) continue;
|
||||
if (delay >= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!spawner.spawn()) {
|
||||
spawner.updateDelay();
|
||||
|
@ -6,48 +6,48 @@ import com.craftaro.core.utils.TimeUtils;
|
||||
import com.craftaro.epicspawners.EpicSpawners;
|
||||
import com.craftaro.epicspawners.api.boosts.types.Boosted;
|
||||
import com.craftaro.epicspawners.api.spawners.spawner.PlacedSpawner;
|
||||
import com.craftaro.epicspawners.boost.types.BoostedImpl;
|
||||
import com.craftaro.epicspawners.gui.SpawnerBoostGui;
|
||||
import com.craftaro.epicspawners.settings.Settings;
|
||||
import com.craftaro.epicspawners.spawners.spawner.PlacedSpawnerImpl;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GuiUtils extends com.craftaro.core.gui.GuiUtils {
|
||||
|
||||
public static void applyBoosted(int slot, CustomizableGui gui, EpicSpawners plugin, Player player, PlacedSpawner spawner) {
|
||||
if (!player.hasPermission("epicspawners.canboost")) return;
|
||||
if (!player.hasPermission("epicspawners.canboost")) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
|
||||
List<Boosted> boosts = spawner.getBoosts();
|
||||
int boostTotal = boosts.stream().mapToInt(Boosted::getAmountBoosted).sum();
|
||||
long boostEnd = 0;
|
||||
for (Boosted boost : boosts)
|
||||
if (boost.getEndTime() > boostEnd)
|
||||
boostEnd = boost.getEndTime();
|
||||
|
||||
if (!boosts.isEmpty()) {
|
||||
|
||||
// ToDo: Make it display all boosts.
|
||||
String[] parts = plugin.getLocale().getMessage("interface.spawner.boostedstats")
|
||||
.processPlaceholder("amount", Integer.toString(boostTotal))
|
||||
.processPlaceholder("time", boostEnd == Long.MAX_VALUE
|
||||
? plugin.getLocale().getMessage("interface.spawner.boostednever")
|
||||
: TimeUtils.makeReadable(boostEnd - System.currentTimeMillis()))
|
||||
.getMessage().split("\\|");
|
||||
|
||||
lore.addAll(TextUtils.formatText(parts));
|
||||
|
||||
gui.setItem("boost", slot, createButtonItem(Settings.BOOST_ICON.getMaterial(), lore));
|
||||
} else
|
||||
gui.setButton("boost", slot, createButtonItem(Settings.BOOST_ICON.getMaterial(),
|
||||
spawner.getBoosts().stream().mapToInt(Boosted::getAmountBoosted).sum() == 0
|
||||
? plugin.getLocale().getMessage("interface.spawner.boost").getMessage()
|
||||
: plugin.getLocale().getMessage("interface.spawner.cantboost").getMessage(), lore), event ->
|
||||
plugin.getGuiManager().showGUI(player, new SpawnerBoostGui(plugin, spawner, player)));
|
||||
|
||||
List<Boosted> boosts = spawner.getBoosts();
|
||||
int boostTotal = boosts.stream().mapToInt(Boosted::getAmountBoosted).sum();
|
||||
long boostEnd = 0;
|
||||
for (Boosted boost : boosts) {
|
||||
if (boost.getEndTime() > boostEnd) {
|
||||
boostEnd = boost.getEndTime();
|
||||
}
|
||||
}
|
||||
|
||||
if (!boosts.isEmpty()) {
|
||||
// ToDo: Make it display all boosts.
|
||||
String[] parts = plugin.getLocale().getMessage("interface.spawner.boostedstats")
|
||||
.processPlaceholder("amount", Integer.toString(boostTotal))
|
||||
.processPlaceholder("time", boostEnd == Long.MAX_VALUE
|
||||
? plugin.getLocale().getMessage("interface.spawner.boostednever")
|
||||
: TimeUtils.makeReadable(boostEnd - System.currentTimeMillis()))
|
||||
.getMessage().split("\\|");
|
||||
|
||||
lore.addAll(TextUtils.formatText(parts));
|
||||
|
||||
gui.setItem("boost", slot, createButtonItem(Settings.BOOST_ICON.getMaterial(), lore));
|
||||
} else {
|
||||
gui.setButton("boost", slot, createButtonItem(Settings.BOOST_ICON.getMaterial(),
|
||||
spawner.getBoosts().stream().mapToInt(Boosted::getAmountBoosted).sum() == 0
|
||||
? plugin.getLocale().getMessage("interface.spawner.boost").getMessage()
|
||||
: plugin.getLocale().getMessage("interface.spawner.cantboost").getMessage(), lore), event ->
|
||||
plugin.getGuiManager().showGUI(player, new SpawnerBoostGui(plugin, spawner, player)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,12 +7,11 @@ import com.craftaro.epicspawners.spawners.spawner.SpawnerDataImpl;
|
||||
import java.util.List;
|
||||
|
||||
public final class SpawnerDataBuilderImpl implements SpawnerDataBuilder {
|
||||
|
||||
private final SpawnerData spawnerData;
|
||||
|
||||
public SpawnerDataBuilderImpl(String identifier) {
|
||||
this.spawnerData = new SpawnerDataImpl(identifier);
|
||||
spawnerData.reloadSpawnMethods();
|
||||
this.spawnerData.reloadSpawnMethods();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -81,7 +80,6 @@ public final class SpawnerDataBuilderImpl implements SpawnerDataBuilder {
|
||||
}
|
||||
|
||||
public SpawnerData build() {
|
||||
return spawnerData;
|
||||
return this.spawnerData;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ import org.bukkit.inventory.ItemStack;
|
||||
import java.util.List;
|
||||
|
||||
public final class SpawnerTierBuilderImpl implements SpawnerTierBuilder {
|
||||
|
||||
private final SpawnerTier spawnerTier;
|
||||
|
||||
public SpawnerTierBuilderImpl() {
|
||||
@ -24,7 +23,7 @@ public final class SpawnerTierBuilderImpl implements SpawnerTierBuilder {
|
||||
|
||||
public SpawnerTierBuilderImpl(SpawnerData data) {
|
||||
this.spawnerTier = new SpawnerTierImpl(data);
|
||||
spawnerTier.reloadSpawnMethods();
|
||||
this.spawnerTier.reloadSpawnMethods();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -154,6 +153,6 @@ public final class SpawnerTierBuilderImpl implements SpawnerTierBuilder {
|
||||
|
||||
@Override
|
||||
public SpawnerTier build() {
|
||||
return spawnerTier;
|
||||
return this.spawnerTier;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user