mirror of
https://github.com/songoda/EpicFarming.git
synced 2024-11-15 15:15:17 +01:00
Merge branch 'development'
This commit is contained in:
commit
19d98c18fd
2
pom.xml
2
pom.xml
@ -2,7 +2,7 @@
|
|||||||
<groupId>com.songoda</groupId>
|
<groupId>com.songoda</groupId>
|
||||||
<artifactId>EpicFarming</artifactId>
|
<artifactId>EpicFarming</artifactId>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<version>3.0.21</version>
|
<version>3.0.22</version>
|
||||||
<build>
|
<build>
|
||||||
<defaultGoal>clean install</defaultGoal>
|
<defaultGoal>clean install</defaultGoal>
|
||||||
<finalName>EpicFarming-${project.version}</finalName>
|
<finalName>EpicFarming-${project.version}</finalName>
|
||||||
|
@ -24,10 +24,7 @@ import com.songoda.epicfarming.farming.levels.modules.Module;
|
|||||||
import com.songoda.epicfarming.farming.levels.modules.ModuleAutoBreeding;
|
import com.songoda.epicfarming.farming.levels.modules.ModuleAutoBreeding;
|
||||||
import com.songoda.epicfarming.farming.levels.modules.ModuleAutoButcher;
|
import com.songoda.epicfarming.farming.levels.modules.ModuleAutoButcher;
|
||||||
import com.songoda.epicfarming.farming.levels.modules.ModuleAutoCollect;
|
import com.songoda.epicfarming.farming.levels.modules.ModuleAutoCollect;
|
||||||
import com.songoda.epicfarming.listeners.BlockListeners;
|
import com.songoda.epicfarming.listeners.*;
|
||||||
import com.songoda.epicfarming.listeners.EntityListeners;
|
|
||||||
import com.songoda.epicfarming.listeners.InteractListeners;
|
|
||||||
import com.songoda.epicfarming.listeners.UnloadListeners;
|
|
||||||
import com.songoda.epicfarming.settings.Settings;
|
import com.songoda.epicfarming.settings.Settings;
|
||||||
import com.songoda.epicfarming.storage.Storage;
|
import com.songoda.epicfarming.storage.Storage;
|
||||||
import com.songoda.epicfarming.storage.StorageRow;
|
import com.songoda.epicfarming.storage.StorageRow;
|
||||||
@ -124,7 +121,7 @@ public class EpicFarming extends SongodaPlugin {
|
|||||||
|
|
||||||
this.loadLevelManager();
|
this.loadLevelManager();
|
||||||
|
|
||||||
this.farmManager = new FarmManager();
|
this.farmManager = new FarmManager(levelManager);
|
||||||
this.boostManager = new BoostManager();
|
this.boostManager = new BoostManager();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -192,6 +189,7 @@ public class EpicFarming extends SongodaPlugin {
|
|||||||
pluginManager.registerEvents(new BlockListeners(this), this);
|
pluginManager.registerEvents(new BlockListeners(this), this);
|
||||||
pluginManager.registerEvents(new InteractListeners(this), this);
|
pluginManager.registerEvents(new InteractListeners(this), this);
|
||||||
pluginManager.registerEvents(new UnloadListeners(this), this);
|
pluginManager.registerEvents(new UnloadListeners(this), this);
|
||||||
|
pluginManager.registerEvents(new InventoryListeners(), this);
|
||||||
|
|
||||||
if (pluginManager.isPluginEnabled("FabledSkyBlock")) {
|
if (pluginManager.isPluginEnabled("FabledSkyBlock")) {
|
||||||
try {
|
try {
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
package com.songoda.epicfarming.farming;
|
package com.songoda.epicfarming.farming;
|
||||||
|
|
||||||
|
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||||
|
import com.songoda.epicfarming.farming.levels.Level;
|
||||||
|
import com.songoda.epicfarming.farming.levels.LevelManager;
|
||||||
|
import com.songoda.epicfarming.settings.Settings;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -9,6 +14,12 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class FarmManager {
|
public class FarmManager {
|
||||||
|
|
||||||
|
private final LevelManager levelManager;
|
||||||
|
|
||||||
|
public FarmManager(LevelManager levelManager) {
|
||||||
|
this.levelManager = levelManager;
|
||||||
|
}
|
||||||
|
|
||||||
private final Map<Location, Farm> registeredFarms = new HashMap<>();
|
private final Map<Location, Farm> registeredFarms = new HashMap<>();
|
||||||
|
|
||||||
public void addFarm(Location location, Farm farm) {
|
public void addFarm(Location location, Farm farm) {
|
||||||
@ -27,6 +38,35 @@ public class FarmManager {
|
|||||||
return getFarm(block.getLocation());
|
return getFarm(block.getLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Farm checkForFarm(Location location) {
|
||||||
|
Material farmBlock = Settings.FARM_BLOCK_MATERIAL.getMaterial(CompatibleMaterial.END_ROD).getBlockMaterial();
|
||||||
|
|
||||||
|
|
||||||
|
Block block = location.getBlock();
|
||||||
|
for (Level level : levelManager.getLevels().values()) {
|
||||||
|
int radius = level.getRadius();
|
||||||
|
int bx = block.getX();
|
||||||
|
int by = block.getY();
|
||||||
|
int bz = block.getZ();
|
||||||
|
|
||||||
|
for (int fx = -radius; fx <= radius; fx++) {
|
||||||
|
for (int fy = -2; fy <= 2; fy++) {
|
||||||
|
for (int fz = -radius; fz <= radius; fz++) {
|
||||||
|
Block b2 = block.getWorld().getBlockAt(bx + fx, by + fy, bz + fz);
|
||||||
|
if (b2.getType() == farmBlock) {
|
||||||
|
Farm farm = getFarms().get(b2.getLocation());
|
||||||
|
if (farm == null) continue;
|
||||||
|
if (level.getRadius() != getFarm(b2.getLocation()).getLevel().getRadius())
|
||||||
|
continue;
|
||||||
|
return farm;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public Map<Location, Farm> getFarms() {
|
public Map<Location, Farm> getFarms() {
|
||||||
return Collections.unmodifiableMap(registeredFarms);
|
return Collections.unmodifiableMap(registeredFarms);
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ public class ModuleAutoCollect extends Module {
|
|||||||
BlockUtils.resetGrowthStage(block));
|
BlockUtils.resetGrowthStage(block));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
block.setType(Material.AIR);
|
Bukkit.getScheduler().runTask(plugin, () -> block.setType(Material.AIR));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,14 +35,14 @@ public class BlockListeners implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onBlockFade(BlockFadeEvent e) {
|
public void onBlockFade(BlockFadeEvent e) {
|
||||||
Farm farm = checkForFarm(e.getBlock().getLocation());
|
Farm farm = instance.getFarmManager().checkForFarm(e.getBlock().getLocation());
|
||||||
if (farm != null && farm.getFarmType() != FarmType.LIVESTOCK)
|
if (farm != null && farm.getFarmType() != FarmType.LIVESTOCK)
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onGrow(BlockGrowEvent e) {
|
public void onGrow(BlockGrowEvent e) {
|
||||||
Farm farm = checkForFarm(e.getBlock().getLocation());
|
Farm farm = instance.getFarmManager().checkForFarm(e.getBlock().getLocation());
|
||||||
if (farm != null && farm.getFarmType() != FarmType.LIVESTOCK)
|
if (farm != null && farm.getFarmType() != FarmType.LIVESTOCK)
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
}
|
}
|
||||||
@ -84,7 +84,7 @@ public class BlockListeners implements Listener {
|
|||||||
|
|
||||||
Location location = e.getBlock().getLocation();
|
Location location = e.getBlock().getLocation();
|
||||||
if (e.getBlockPlaced().getType().equals(Material.MELON_SEEDS) || e.getBlockPlaced().getType().equals(Material.PUMPKIN_SEEDS)) {
|
if (e.getBlockPlaced().getType().equals(Material.MELON_SEEDS) || e.getBlockPlaced().getType().equals(Material.PUMPKIN_SEEDS)) {
|
||||||
if (checkForFarm(location) != null) {
|
if (instance.getFarmManager().checkForFarm(location) != null) {
|
||||||
instance.getLocale().getMessage("event.warning.noauto").sendPrefixedMessage(e.getPlayer());
|
instance.getLocale().getMessage("event.warning.noauto").sendPrefixedMessage(e.getPlayer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -99,36 +99,6 @@ public class BlockListeners implements Listener {
|
|||||||
}, 1);
|
}, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Farm checkForFarm(Location location) {
|
|
||||||
Material farmBlock = Settings.FARM_BLOCK_MATERIAL.getMaterial(CompatibleMaterial.END_ROD).getBlockMaterial();
|
|
||||||
|
|
||||||
FarmManager farmManager = instance.getFarmManager();
|
|
||||||
|
|
||||||
Block block = location.getBlock();
|
|
||||||
for (Level level : instance.getLevelManager().getLevels().values()) {
|
|
||||||
int radius = level.getRadius();
|
|
||||||
int bx = block.getX();
|
|
||||||
int by = block.getY();
|
|
||||||
int bz = block.getZ();
|
|
||||||
|
|
||||||
for (int fx = -radius; fx <= radius; fx++) {
|
|
||||||
for (int fy = -2; fy <= 2; fy++) {
|
|
||||||
for (int fz = -radius; fz <= radius; fz++) {
|
|
||||||
Block b2 = block.getWorld().getBlockAt(bx + fx, by + fy, bz + fz);
|
|
||||||
if (b2.getType() == farmBlock) {
|
|
||||||
Farm farm = farmManager.getFarms().get(b2.getLocation());
|
|
||||||
if (farm == null) continue;
|
|
||||||
if (level.getRadius() != farmManager.getFarm(b2.getLocation()).getLevel().getRadius())
|
|
||||||
continue;
|
|
||||||
return farm;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onBlockBreak(BlockBreakEvent event) {
|
public void onBlockBreak(BlockBreakEvent event) {
|
||||||
if (event.getBlock().getType() != Settings.FARM_BLOCK_MATERIAL.getMaterial(CompatibleMaterial.END_ROD).getMaterial())
|
if (event.getBlock().getType() != Settings.FARM_BLOCK_MATERIAL.getMaterial(CompatibleMaterial.END_ROD).getMaterial())
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.songoda.epicfarming.listeners;
|
package com.songoda.epicfarming.listeners;
|
||||||
|
|
||||||
|
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||||
import com.songoda.epicfarming.EpicFarming;
|
import com.songoda.epicfarming.EpicFarming;
|
||||||
import com.songoda.epicfarming.settings.Settings;
|
import com.songoda.epicfarming.settings.Settings;
|
||||||
import com.songoda.skyblock.SkyBlock;
|
import com.songoda.skyblock.SkyBlock;
|
||||||
@ -24,8 +25,14 @@ public class InteractListeners implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void onBlockInteract(PlayerInteractEvent e) {
|
public void onBlockInteract(PlayerInteractEvent e) {
|
||||||
if (e.getClickedBlock() == null
|
if (e.getClickedBlock() == null) return;
|
||||||
|| e.getClickedBlock().getType() != Settings.FARM_BLOCK_MATERIAL.getMaterial().getMaterial())
|
Location location = e.getClickedBlock().getLocation();
|
||||||
|
|
||||||
|
if (e.getItem() != null && CompatibleMaterial.getMaterial(e.getItem()) == CompatibleMaterial.BONE_MEAL
|
||||||
|
&& instance.getFarmManager().checkForFarm(location) != null)
|
||||||
|
e.setCancelled(true);
|
||||||
|
|
||||||
|
if (e.getClickedBlock().getType() != Settings.FARM_BLOCK_MATERIAL.getMaterial().getMaterial())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||||
@ -40,8 +47,6 @@ public class InteractListeners implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Location location = e.getClickedBlock().getLocation();
|
|
||||||
|
|
||||||
if (instance.getFarmManager().getFarms().containsKey(location)) {
|
if (instance.getFarmManager().getFarms().containsKey(location)) {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
instance.getFarmManager().getFarm(location).view(e.getPlayer(), false);
|
instance.getFarmManager().getFarm(location).view(e.getPlayer(), false);
|
||||||
|
@ -0,0 +1,37 @@
|
|||||||
|
package com.songoda.epicfarming.listeners;
|
||||||
|
|
||||||
|
import com.songoda.epicfarming.settings.Settings;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.inventory.InventoryAction;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.bukkit.event.inventory.InventoryType;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by songoda on 3/14/2017.
|
||||||
|
*/
|
||||||
|
public class InventoryListeners implements Listener {
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onInventoryClick(InventoryClickEvent event) {
|
||||||
|
Player player = (Player) event.getWhoClicked();
|
||||||
|
if (event.getCurrentItem() == null) return;
|
||||||
|
|
||||||
|
if (event.getRawSlot() > event.getView().getTopInventory().getSize() - 1) return;
|
||||||
|
|
||||||
|
if (!event.getCurrentItem().hasItemMeta()) return;
|
||||||
|
|
||||||
|
if (event.getSlot() != 64537
|
||||||
|
&& event.getInventory().getType() == InventoryType.ANVIL
|
||||||
|
&& event.getAction() != InventoryAction.NOTHING
|
||||||
|
&& event.getCurrentItem().getType() != Material.AIR) {
|
||||||
|
ItemStack item = event.getCurrentItem();
|
||||||
|
if (item.getType() == Settings.FARM_BLOCK_MATERIAL.getMaterial().getMaterial()) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -114,9 +114,9 @@ public class Methods {
|
|||||||
if (location == null || location.getWorld() == null)
|
if (location == null || location.getWorld() == null)
|
||||||
return "";
|
return "";
|
||||||
String w = location.getWorld().getName();
|
String w = location.getWorld().getName();
|
||||||
double x = location.getX();
|
int x = location.getBlockX();
|
||||||
double y = location.getY();
|
int y = location.getBlockY();
|
||||||
double z = location.getZ();
|
int z = location.getBlockZ();
|
||||||
String str = w + ":" + x + ":" + y + ":" + z;
|
String str = w + ":" + x + ":" + y + ":" + z;
|
||||||
str = str.replace(".0", "").replace(".", "/");
|
str = str.replace(".0", "").replace(".", "/");
|
||||||
return str;
|
return str;
|
||||||
|
Loading…
Reference in New Issue
Block a user