Cleaned up instance system.

Removed listeners from main class.
Added better location methods for hoppers.
Incremented version.
Started work on a real API
Removed sc alias for the main command.
This commit is contained in:
Brianna O'Keefe 2018-08-09 22:59:44 -04:00
parent 470b19ade2
commit c46972e3d3
49 changed files with 3982 additions and 3593 deletions

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="minecraft" name="Minecraft">
<configuration>
<autoDetectTypes>
<platformType>SPIGOT</platformType>
</autoDetectTypes>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager">
<output url="file://$MODULE_DIR$/../target/classes" />
<output-test url="file://$MODULE_DIR$/../target/classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Lib1" level="project" />
<orderEntry type="library" name="spigot-1.132" level="project" />
</component>
</module>

View File

@ -0,0 +1,31 @@
package com.songoda.epichoppers.api;
import com.songoda.epichoppers.api.hopper.HopperManager;
import com.songoda.epichoppers.api.hopper.Level;
import com.songoda.epichoppers.api.hopper.LevelManager;
import org.bukkit.inventory.ItemStack;
/**
* The main API class for the EpicHoppers plugin. This class will provide various
* methods to access important features of the plugin's API. For static method
* wrappers to all methods in this interface, see the {@link EpicHoppersAPI} class
*/
public interface EpicHoppers {
Level getLevelFromItem(ItemStack item);
/**
* Get an instance of the {@link LevelManager}
*
* @return the level manager
*/
LevelManager getLevelManager();
/**
* Get an instance of the {@link HopperManager}
*
* @return the hopper manager
*/
HopperManager getHopperManager();
}

View File

@ -0,0 +1,48 @@
package com.songoda.epichoppers.api;
import org.bukkit.ChatColor;
/**
* The access point of the EpicHoppersAPI, a class acting as a bridge between API
* and plugin implementation. It is from here where developers should access the
* important and core methods in the API. All static methods in this class will
* call directly upon the implementation at hand (in most cases this will be the
* EpicHoppers plugin itself), therefore a call to {@link #getImplementation()} is
* not required and redundant in most situations. Method calls from this class are
* preferred the majority of time, though an instance of {@link EpicHoppers} may
* be passed if absolutely necessary.
*
* @see EpicHoppers
* @since 3.0.0
*/
public class EpicHoppersAPI {
private static EpicHoppers implementation;
/**
* Set the EpicHoppers implementation. Once called for the first time, this
* method will throw an exception on any subsequent invocations. The implementation
* may only be set a single time, presumably by the EpicHoppers plugin
*
* @param implementation the implementation to set
*/
public static void setImplementation(EpicHoppers implementation) {
if (EpicHoppersAPI.implementation != null) {
throw new IllegalArgumentException("Cannot set API implementation twice");
}
EpicHoppersAPI.implementation = implementation;
}
/**
* Get the EpicHoppers implementation. This method may be redundant in most
* situations as all methods present in {@link EpicHoppers} will be mirrored
* with static modifiers in the {@link EpicHoppersAPI} class
*
* @return the EpicHoppers implementation
*/
public static EpicHoppers getImplementation() {
return implementation;
}
}

View File

@ -0,0 +1,24 @@
package com.songoda.epichoppers.api.hopper;
import org.bukkit.block.Block;
import org.bukkit.inventory.ItemStack;
import java.util.List;
public interface Filter {
List<ItemStack> getWhiteList();
void setWhiteList(List<ItemStack> whiteList);
List<ItemStack> getBlackList();
void setBlackList(List<ItemStack> blackList);
List<ItemStack> getVoidList();
void setVoidList(List<ItemStack> voidList);
Block getEndPoint();
void setEndPoint(Block endPoint);
}

View File

@ -0,0 +1,33 @@
package com.songoda.epichoppers.api.hopper;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import java.util.UUID;
public interface Hopper {
void sync(Block toSync, boolean filtered, Player player);
Location getLocation();
int getX();
int getY();
int getZ();
Level getLevel();
UUID getLastPlayer();
boolean isWalkOnTeleport();
void setWalkOnTeleport(boolean walkOnTeleport);
Block getSyncedBlock();
void setSyncedBlock(Block syncedBlock);
Filter getFilter();
}

View File

@ -0,0 +1,21 @@
package com.songoda.epichoppers.api.hopper;
import org.bukkit.Location;
import org.bukkit.block.Block;
import java.util.Map;
public interface HopperManager {
void addHopper(Location location, Hopper hopper);
Hopper removeHopper(Location location);
Hopper getHopper(Location location);
Hopper getHopper(Block block);
boolean isHopper(Location location);
Map<Location, Hopper> getHoppers();
}

View File

@ -0,0 +1,21 @@
package com.songoda.epichoppers.api.hopper;
import java.util.List;
public interface Level {
List<String> getDescription();
int getLevel();
int getRange();
int getAmount();
int getBlockBreak();
int getSuction();
int getCostExperience();
int getCostEconomy();
}

View File

@ -0,0 +1,15 @@
package com.songoda.epichoppers.api.hopper;
import java.util.Map;
public interface LevelManager {
void addLevel(int level, int costExperiance, int costEconomy, int range, int amount, int suction, int blockBreak);
Level getLevel(int level);
Level getLowestLevel();
Level getHighestLevel();
Map<Integer, Level> getLevels();
}

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="minecraft" name="Minecraft">
<configuration>
<autoDetectTypes>
<platformType>SPIGOT</platformType>
</autoDetectTypes>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager">
<output url="file://$MODULE_DIR$/../target/classes" />
<output-test url="file://$MODULE_DIR$/../target/classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Lib1" level="project" />
<orderEntry type="library" name="spigot-1.131" level="project" />
<orderEntry type="library" name="spigot-1.132" level="project" />
<orderEntry type="module" module-name="EpicHoppers-API" />
</component>
</module>

View File

@ -1,282 +1,291 @@
package com.songoda.epichoppers;
import com.songoda.arconix.api.mcupdate.MCUpdate;
import com.songoda.arconix.api.utils.ConfigWrapper;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.epichoppers.API.EpicHoppersAPI;
import com.songoda.epichoppers.Events.*;
import com.songoda.epichoppers.Handlers.*;
import com.songoda.epichoppers.Hopper.Filter;
import com.songoda.epichoppers.Hopper.Hopper;
import com.songoda.epichoppers.Hopper.HopperManager;
import com.songoda.epichoppers.Hopper.LevelManager;
import com.songoda.epichoppers.Utils.SettingsManager;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.*;
public final class EpicHoppers extends JavaPlugin implements Listener {
public static CommandSender console = Bukkit.getConsoleSender();
public Map<UUID, Hopper> inShow = new HashMap<>();
public Map<UUID, Hopper> inFilter = new HashMap<>();
public HookHandler hooks;
public SettingsManager sm;
public References references = null;
public ConfigWrapper dataFile = new ConfigWrapper(this, "", "data.yml");
public Map<Player, Block> sync = new HashMap<>();
public Map<Player, Block> bsync = new HashMap<>();
public Map<Player, Date> lastTp = new HashMap<>();
public Map<Player, Block> lastBlock = new HashMap<>();
public EnchantmentHandler enchant;
private Locale locale;
private HopperManager hopperManager;
private LevelManager levelManager;
private TeleportHandler teleportHandler;
private EpicHoppersAPI api;
public void onEnable() {
Arconix.pl().hook(this);
console.sendMessage(Arconix.pl().getApi().format().formatText("&a============================="));
console.sendMessage(Arconix.pl().getApi().format().formatText("&7EpicHoppers " + this.getDescription().getVersion() + " by &5Brianna <3&7!"));
console.sendMessage(Arconix.pl().getApi().format().formatText("&7Action: &aEnabling&7..."));
Bukkit.getPluginManager().registerEvents(this, this);
api = new EpicHoppersAPI();
sm = new SettingsManager(this);
setupConfig();
loadDataFile();
enchant = new EnchantmentHandler();
// Locales
Locale.init(this);
Locale.saveDefaultLocale("en_US");
this.locale = Locale.getLocale(this.getConfig().getString("Locale", "en_US"));
loadLevelManager();
hopperManager = new HopperManager();
/*
* Register hoppers into HopperManger from configuration
*/
Bukkit.getScheduler().runTaskLater(this, () -> {
if (dataFile.getConfig().contains("data.sync")) {
for (String locationStr : dataFile.getConfig().getConfigurationSection("data.sync").getKeys(false)) {
Location location = Arconix.pl().getApi().serialize().unserializeLocation(locationStr);
if (location == null || location.getBlock() == null) return;
int level = dataFile.getConfig().getInt("data.sync." + locationStr + ".level");
String blockLoc = dataFile.getConfig().getString("data.sync." + locationStr + ".block");
Block block = blockLoc == null ? null : Arconix.pl().getApi().serialize().unserializeLocation(dataFile.getConfig().getString("data.sync." + locationStr + ".block")).getBlock();
boolean walkOnTeleport = dataFile.getConfig().getBoolean("data.sync." + locationStr + ".walkOnTeleport");
String playerStr = dataFile.getConfig().getString("data.sync." + locationStr + ".player");
UUID player = playerStr == null ? null : UUID.fromString(playerStr);
List<ItemStack> whiteList = (ArrayList<ItemStack>)dataFile.getConfig().getList("data.sync." + locationStr + ".whitelist");
List<ItemStack> blackList = (ArrayList<ItemStack>)dataFile.getConfig().getList("data.sync." + locationStr + ".blacklist");
List<ItemStack> voidList = (ArrayList<ItemStack>)dataFile.getConfig().getList("data.sync." + locationStr + ".void");
String blackLoc = dataFile.getConfig().getString("data.sync." + locationStr + ".black");
Block black = blackLoc == null ? null : Arconix.pl().getApi().serialize().unserializeLocation(dataFile.getConfig().getString("data.sync." + locationStr + ".black")).getBlock();
Filter filter = new Filter();
filter.setWhiteList(whiteList);
filter.setBlackList(blackList);
filter.setVoidList(voidList);
filter.setEndPoint(black);
Hopper hopper = new Hopper(location, levelManager.getLevel(level), player, block, filter, walkOnTeleport);
hopperManager.addHopper(location, hopper);
}
}
}, 10);
references = new References();
hooks = new HookHandler();
hooks.hook();
new HopHandler(this);
teleportHandler = new TeleportHandler(this);
new MCUpdate(this, true);
//new MassiveStats(this, 9000);
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, this::saveToFile, 6000, 6000);
this.getCommand("EpicHoppers").setExecutor(new CommandHandler(this));
getServer().getPluginManager().registerEvents(new HopperListeners(this), this);
getServer().getPluginManager().registerEvents(new BlockListeners(this), this);
getServer().getPluginManager().registerEvents(new InteractListeners(this), this);
getServer().getPluginManager().registerEvents(new InventoryListeners(this), this);
getServer().getPluginManager().registerEvents(new LoginListeners(this), this);
console.sendMessage(Arconix.pl().getApi().format().formatText("&a============================="));
}
public void onDisable() {
saveToFile();
console.sendMessage(Arconix.pl().getApi().format().formatText("&a============================="));
console.sendMessage(Arconix.pl().getApi().format().formatText("&7EpicHoppers " + this.getDescription().getVersion() + " by &5Brianna <3!"));
console.sendMessage(Arconix.pl().getApi().format().formatText("&7Action: &cDisabling&7..."));
console.sendMessage(Arconix.pl().getApi().format().formatText("&a============================="));
dataFile.saveConfig();
}
/*
* Saves registered hopper to file.
*/
private void saveToFile() {
// Wipe old hopper information
dataFile.getConfig().set("data.sync", null);
/*
* Dump HopperManager to file.
*/
for (Hopper hopper : hopperManager.getHoppers().values()) {
if (hopper.getLevel() == null || hopper.getLocation() == null || hopper.getLocation().getChunk() == null) continue;
String locationStr = Arconix.pl().getApi().serialize().serializeLocation(hopper.getLocation());
dataFile.getConfig().set("data.sync." + locationStr + ".level", hopper.getLevel().getLevel());
dataFile.getConfig().set("data.sync." + locationStr + ".block", hopper.getSyncedBlock() == null ? null : Arconix.pl().getApi().serialize().serializeLocation(hopper.getSyncedBlock().getLocation()));
dataFile.getConfig().set("data.sync." + locationStr + ".player", hopper.getLastPlayer() == null ? null : hopper.getLastPlayer().toString());
dataFile.getConfig().set("data.sync." + locationStr + ".walkOnTeleport", hopper.isWalkOnTeleport());
dataFile.getConfig().set("data.sync." + locationStr + ".whitelist", hopper.getFilter().getWhiteList());
dataFile.getConfig().set("data.sync." + locationStr + ".blacklist", hopper.getFilter().getBlackList());
dataFile.getConfig().set("data.sync." + locationStr + ".void", hopper.getFilter().getVoidList());
dataFile.getConfig().set("data.sync." + locationStr + ".black", hopper.getFilter().getEndPoint() == null ? null : Arconix.pl().getApi().serialize().serializeLocation(hopper.getFilter().getEndPoint().getLocation()));
}
//Save to file
dataFile.saveConfig();
}
private void loadLevelManager() {
// Load an instance of LevelManager
levelManager = new LevelManager();
/*
* Register Levels into LevelManager from configuration.
*/
levelManager.clear();
for (String levelName : getConfig().getConfigurationSection("settings.levels").getKeys(false)) {
int level = Integer.valueOf(levelName.split("-")[1]);
int radius = getConfig().getInt("settings.levels." + levelName + ".Range");
int amount = getConfig().getInt("settings.levels." + levelName + ".Amount");
int suction = getConfig().getInt("settings.levels." + levelName + ".Suction");
int blockBreak = getConfig().getInt("settings.levels." + levelName + ".BlockBreak");
int costExperiance = getConfig().getInt("settings.levels." + levelName + ".Cost-xp");
int costEconomy = getConfig().getInt("settings.levels." + levelName + ".Cost-eco");
levelManager.addLevel(level, costExperiance, costEconomy, radius, amount, suction, blockBreak);
}
}
private void setupConfig() {
sm.updateSettings();
if (!getConfig().contains("settings.levels.Level-1")) {
getConfig().addDefault("settings.levels.Level-1.Range", 10);
getConfig().addDefault("settings.levels.Level-1.Amount", 1);
getConfig().addDefault("settings.levels.Level-1.Cost-xp", 20);
getConfig().addDefault("settings.levels.Level-1.Cost-eco", 5000);
getConfig().addDefault("settings.levels.Level-2.Range", 20);
getConfig().addDefault("settings.levels.Level-2.Amount", 2);
getConfig().addDefault("settings.levels.Level-2.Cost-xp", 25);
getConfig().addDefault("settings.levels.Level-2.Cost-eco", 7500);
getConfig().addDefault("settings.levels.Level-3.Range", 30);
getConfig().addDefault("settings.levels.Level-3.Amount", 3);
getConfig().addDefault("settings.levels.Level-3.Suction", 1);
getConfig().addDefault("settings.levels.Level-3.Cost-xp", 30);
getConfig().addDefault("settings.levels.Level-3.Cost-eco", 10000);
getConfig().addDefault("settings.levels.Level-4.Range", 40);
getConfig().addDefault("settings.levels.Level-4.Amount", 4);
getConfig().addDefault("settings.levels.Level-4.Suction", 2);
getConfig().addDefault("settings.levels.Level-4.BlockBreak", 4);
getConfig().addDefault("settings.levels.Level-4.Cost-xp", 35);
getConfig().addDefault("settings.levels.Level-4.Cost-eco", 12000);
getConfig().addDefault("settings.levels.Level-5.Range", 50);
getConfig().addDefault("settings.levels.Level-5.Amount", 5);
getConfig().addDefault("settings.levels.Level-5.Suction", 3);
getConfig().addDefault("settings.levels.Level-5.BlockBreak", 2);
getConfig().addDefault("settings.levels.Level-5.Cost-xp", 40);
getConfig().addDefault("settings.levels.Level-5.Cost-eco", 15000);
}
getConfig().options().copyDefaults(true);
saveConfig();
}
private void loadDataFile() {
dataFile.getConfig().options().copyDefaults(true);
dataFile.saveConfig();
}
public void reload() {
locale.reloadMessages();
hooks.hooksFile.createNewFile("Loading hooks File", "EpicSpawners Spawners File");
hooks = new HookHandler();
hooks.hook();
references = new References();
reloadConfig();
saveConfig();
loadLevelManager();
}
public Locale getLocale() {
return locale;
}
public TeleportHandler getTeleportHandler() {
return teleportHandler;
}
public LevelManager getLevelManager() {
return levelManager;
}
public HopperManager getHopperManager() {
return hopperManager;
}
public static EpicHoppers getInstance() {
return (EpicHoppers) Bukkit.getServer().getPluginManager().getPlugin("EpicHoppers");
}
public EpicHoppersAPI getApi() {
return api;
}
}
package com.songoda.epichoppers;
import com.songoda.arconix.api.mcupdate.MCUpdate;
import com.songoda.arconix.api.utils.ConfigWrapper;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.epichoppers.api.EpicHoppers;
import com.songoda.epichoppers.api.EpicHoppersAPI;
import com.songoda.epichoppers.api.hopper.Hopper;
import com.songoda.epichoppers.api.hopper.HopperManager;
import com.songoda.epichoppers.api.hopper.Level;
import com.songoda.epichoppers.api.hopper.LevelManager;
import com.songoda.epichoppers.events.*;
import com.songoda.epichoppers.handlers.*;
import com.songoda.epichoppers.hopper.EFilter;
import com.songoda.epichoppers.hopper.EHopper;
import com.songoda.epichoppers.hopper.EHopperManager;
import com.songoda.epichoppers.hopper.ELevelManager;
import com.songoda.epichoppers.player.PlayerDataManager;
import com.songoda.epichoppers.utils.SettingsManager;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.command.CommandSender;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.*;
public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers {
public static CommandSender console = Bukkit.getConsoleSender();
private static EpicHoppersPlugin INSTANCE;
public HookHandler hooks;
public SettingsManager settingsManager;
public References references = null;
public ConfigWrapper dataFile = new ConfigWrapper(this, "", "data.yml");
public EnchantmentHandler enchantmentHandler;
private Locale locale;
private HopperManager hopperManager;
private LevelManager levelManager;
private PlayerDataManager playerDataManager;
private TeleportHandler teleportHandler;
public void onEnable() {
INSTANCE = this;
EpicHoppersAPI.setImplementation(this);
Arconix.pl().hook(this);
console.sendMessage(Arconix.pl().getApi().format().formatText("&a============================="));
console.sendMessage(Arconix.pl().getApi().format().formatText("&7EpicHoppers " + this.getDescription().getVersion() + " by &5Brianna <3&7!"));
console.sendMessage(Arconix.pl().getApi().format().formatText("&7Action: &aEnabling&7..."));
settingsManager = new SettingsManager(this);
setupConfig();
loadDataFile();
enchantmentHandler = new EnchantmentHandler();
playerDataManager = new PlayerDataManager();
// Locales
Locale.init(this);
Locale.saveDefaultLocale("en_US");
this.locale = Locale.getLocale(this.getConfig().getString("Locale", "en_US"));
loadLevelManager();
hopperManager = new EHopperManager();
/*
* Register hoppers into HopperManger from configuration
*/
Bukkit.getScheduler().runTaskLater(this, () -> {
if (dataFile.getConfig().contains("data.sync")) {
for (String locationStr : dataFile.getConfig().getConfigurationSection("data.sync").getKeys(false)) {
Location location = Arconix.pl().getApi().serialize().unserializeLocation(locationStr);
if (location == null || location.getBlock() == null) return;
int level = dataFile.getConfig().getInt("data.sync." + locationStr + ".level");
String blockLoc = dataFile.getConfig().getString("data.sync." + locationStr + ".block");
Block block = blockLoc == null ? null : Arconix.pl().getApi().serialize().unserializeLocation(dataFile.getConfig().getString("data.sync." + locationStr + ".block")).getBlock();
boolean walkOnTeleport = dataFile.getConfig().getBoolean("data.sync." + locationStr + ".walkOnTeleport");
String playerStr = dataFile.getConfig().getString("data.sync." + locationStr + ".player");
UUID player = playerStr == null ? null : UUID.fromString(playerStr);
List<ItemStack> whiteList = (ArrayList<ItemStack>)dataFile.getConfig().getList("data.sync." + locationStr + ".whitelist");
List<ItemStack> blackList = (ArrayList<ItemStack>)dataFile.getConfig().getList("data.sync." + locationStr + ".blacklist");
List<ItemStack> voidList = (ArrayList<ItemStack>)dataFile.getConfig().getList("data.sync." + locationStr + ".void");
String blackLoc = dataFile.getConfig().getString("data.sync." + locationStr + ".black");
Block black = blackLoc == null ? null : Arconix.pl().getApi().serialize().unserializeLocation(dataFile.getConfig().getString("data.sync." + locationStr + ".black")).getBlock();
EFilter filter = new EFilter();
filter.setWhiteList(whiteList);
filter.setBlackList(blackList);
filter.setVoidList(voidList);
filter.setEndPoint(black);
EHopper hopper = new EHopper(location, levelManager.getLevel(level), player, block, filter, walkOnTeleport);
hopperManager.addHopper(location, hopper);
}
}
}, 10);
references = new References();
hooks = new HookHandler();
hooks.hook();
new HopHandler(this);
teleportHandler = new TeleportHandler(this);
new MCUpdate(this, true);
//new MassiveStats(this, 9000);
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, this::saveToFile, 6000, 6000);
this.getCommand("EpicHoppers").setExecutor(new CommandHandler(this));
getServer().getPluginManager().registerEvents(new HopperListeners(this), this);
getServer().getPluginManager().registerEvents(new BlockListeners(this), this);
getServer().getPluginManager().registerEvents(new InteractListeners(this), this);
getServer().getPluginManager().registerEvents(new InventoryListeners(this), this);
getServer().getPluginManager().registerEvents(new LoginListeners(this), this);
console.sendMessage(Arconix.pl().getApi().format().formatText("&a============================="));
}
public void onDisable() {
saveToFile();
console.sendMessage(Arconix.pl().getApi().format().formatText("&a============================="));
console.sendMessage(Arconix.pl().getApi().format().formatText("&7EpicHoppers " + this.getDescription().getVersion() + " by &5Brianna <3!"));
console.sendMessage(Arconix.pl().getApi().format().formatText("&7Action: &cDisabling&7..."));
console.sendMessage(Arconix.pl().getApi().format().formatText("&a============================="));
dataFile.saveConfig();
}
/*
* Saves registered hopper to file.
*/
private void saveToFile() {
// Wipe old hopper information
dataFile.getConfig().set("data.sync", null);
/*
* Dump HopperManager to file.
*/
for (Hopper hopper : hopperManager.getHoppers().values()) {
if (hopper.getLevel() == null || hopper.getLocation() == null || hopper.getLocation().getChunk() == null) continue;
String locationStr = Arconix.pl().getApi().serialize().serializeLocation(hopper.getLocation());
dataFile.getConfig().set("data.sync." + locationStr + ".level", hopper.getLevel().getLevel());
dataFile.getConfig().set("data.sync." + locationStr + ".block", hopper.getSyncedBlock() == null ? null : Arconix.pl().getApi().serialize().serializeLocation(hopper.getSyncedBlock().getLocation()));
dataFile.getConfig().set("data.sync." + locationStr + ".player", hopper.getLastPlayer() == null ? null : hopper.getLastPlayer().toString());
dataFile.getConfig().set("data.sync." + locationStr + ".walkOnTeleport", hopper.isWalkOnTeleport());
dataFile.getConfig().set("data.sync." + locationStr + ".whitelist", hopper.getFilter().getWhiteList());
dataFile.getConfig().set("data.sync." + locationStr + ".blacklist", hopper.getFilter().getBlackList());
dataFile.getConfig().set("data.sync." + locationStr + ".void", hopper.getFilter().getVoidList());
dataFile.getConfig().set("data.sync." + locationStr + ".black", hopper.getFilter().getEndPoint() == null ? null : Arconix.pl().getApi().serialize().serializeLocation(hopper.getFilter().getEndPoint().getLocation()));
}
//Save to file
dataFile.saveConfig();
}
private void loadLevelManager() {
// Load an instance of LevelManager
levelManager = new ELevelManager();
/*
* Register Levels into LevelManager from configuration.
*/
((ELevelManager)levelManager).clear();
for (String levelName : getConfig().getConfigurationSection("settings.levels").getKeys(false)) {
int level = Integer.valueOf(levelName.split("-")[1]);
int radius = getConfig().getInt("settings.levels." + levelName + ".Range");
int amount = getConfig().getInt("settings.levels." + levelName + ".Amount");
int suction = getConfig().getInt("settings.levels." + levelName + ".Suction");
int blockBreak = getConfig().getInt("settings.levels." + levelName + ".BlockBreak");
int costExperiance = getConfig().getInt("settings.levels." + levelName + ".Cost-xp");
int costEconomy = getConfig().getInt("settings.levels." + levelName + ".Cost-eco");
levelManager.addLevel(level, costExperiance, costEconomy, radius, amount, suction, blockBreak);
}
}
private void setupConfig() {
settingsManager.updateSettings();
if (!getConfig().contains("settings.levels.Level-1")) {
getConfig().addDefault("settings.levels.Level-1.Range", 10);
getConfig().addDefault("settings.levels.Level-1.Amount", 1);
getConfig().addDefault("settings.levels.Level-1.Cost-xp", 20);
getConfig().addDefault("settings.levels.Level-1.Cost-eco", 5000);
getConfig().addDefault("settings.levels.Level-2.Range", 20);
getConfig().addDefault("settings.levels.Level-2.Amount", 2);
getConfig().addDefault("settings.levels.Level-2.Cost-xp", 25);
getConfig().addDefault("settings.levels.Level-2.Cost-eco", 7500);
getConfig().addDefault("settings.levels.Level-3.Range", 30);
getConfig().addDefault("settings.levels.Level-3.Amount", 3);
getConfig().addDefault("settings.levels.Level-3.Suction", 1);
getConfig().addDefault("settings.levels.Level-3.Cost-xp", 30);
getConfig().addDefault("settings.levels.Level-3.Cost-eco", 10000);
getConfig().addDefault("settings.levels.Level-4.Range", 40);
getConfig().addDefault("settings.levels.Level-4.Amount", 4);
getConfig().addDefault("settings.levels.Level-4.Suction", 2);
getConfig().addDefault("settings.levels.Level-4.BlockBreak", 4);
getConfig().addDefault("settings.levels.Level-4.Cost-xp", 35);
getConfig().addDefault("settings.levels.Level-4.Cost-eco", 12000);
getConfig().addDefault("settings.levels.Level-5.Range", 50);
getConfig().addDefault("settings.levels.Level-5.Amount", 5);
getConfig().addDefault("settings.levels.Level-5.Suction", 3);
getConfig().addDefault("settings.levels.Level-5.BlockBreak", 2);
getConfig().addDefault("settings.levels.Level-5.Cost-xp", 40);
getConfig().addDefault("settings.levels.Level-5.Cost-eco", 15000);
}
getConfig().options().copyDefaults(true);
saveConfig();
}
private void loadDataFile() {
dataFile.getConfig().options().copyDefaults(true);
dataFile.saveConfig();
}
public void reload() {
locale.reloadMessages();
hooks.hooksFile.createNewFile("Loading hooks File", "EpicSpawners Spawners File");
hooks = new HookHandler();
hooks.hook();
references = new References();
reloadConfig();
saveConfig();
loadLevelManager();
}
@Override
public Level getLevelFromItem(ItemStack item) {
if (item.getItemMeta().getDisplayName().contains(":")) {
String arr[] = item.getItemMeta().getDisplayName().replace("§", "").split(":");
return getLevelManager().getLevel(Integer.parseInt(arr[0]));
} else {
return getLevelManager().getLowestLevel();
}
}
public Locale getLocale() {
return locale;
}
public TeleportHandler getTeleportHandler() {
return teleportHandler;
}
@Override
public LevelManager getLevelManager() {
return levelManager;
}
@Override
public HopperManager getHopperManager() {
return hopperManager;
}
public PlayerDataManager getPlayerDataManager() {
return playerDataManager;
}
public static EpicHoppersPlugin getInstance() {
return INSTANCE;
}
}

View File

@ -1,365 +1,365 @@
package com.songoda.epichoppers;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import org.apache.commons.io.IOUtils;
import org.bukkit.ChatColor;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
* Assists in the creation of multiple localizations and languages,
* as well as the generation of default .lang files
*
* @author Parker Hawke - 2008Choco
*/
public class Locale {
private static JavaPlugin plugin;
private static final List<Locale> LOCALES = Lists.newArrayList();
private static final Pattern NODE_PATTERN = Pattern.compile("(\\w+(?:\\.\\w+)*)\\s*=\\s*\"(.*)\"");
private static final String FILE_EXTENSION = ".lang";
private static File localeFolder;
private static String defaultLocale;
private final Map<String, String> nodes = new HashMap<>();
private final File file;
private final String name, region;
private Locale(String name, String region) {
if (plugin == null)
throw new IllegalStateException("Cannot generate locales without first initializing the class (Locale#init(JavaPlugin))");
this.name = name.toLowerCase();
this.region = region.toUpperCase();
String fileName = name + "_" + region + FILE_EXTENSION;
this.file = new File(localeFolder, fileName);
if (this.reloadMessages()) return;
plugin.getLogger().info("Loaded locale " + fileName);
}
/**
* Get the name of the language that this locale is based on.
* (i.e. "en" for English, or "fr" for French)
*
* @return the name of the language
*/
public String getName() {
return name;
}
/**
* Get the name of the region that this locale is from.
* (i.e. "US" for United States or "CA" for Canada)
*
* @return the name of the region
*/
public String getRegion() {
return region;
}
/**
* Return the entire locale tag (i.e. "en_US")
*
* @return the language tag
*/
public String getLanguageTag() {
return name + "_" + region;
}
/**
* Get the file that represents this locale
*
* @return the locale file (.lang)
*/
public File getFile() {
return file;
}
/**
* Get a message set for a specific node
*
* @param node the node to get
* @return the message for the specified node
*/
public String getMessage(String node) {
return ChatColor.translateAlternateColorCodes('&', this.getMessageOrDefault(node, node));
}
/**
* Get a message set for a specific node and replace its params with a supplied arguments.
*
* @param node the node to get
* @param args the replacement arguments
* @return the message for the specified node
*/
public String getMessage(String node, Object... args) {
String message = getMessage(node);
for (Object arg : args) {
message = message.replaceFirst("%.*?%", arg.toString());
}
return message;
}
/**
* Get a message set for a specific node
*
* @param node the node to get
* @param defaultValue the default value given that a value for the node was not found
*
* @return the message for the specified node. Default if none found
*/
public String getMessageOrDefault(String node, String defaultValue) {
return this.nodes.getOrDefault(node, defaultValue);
}
/**
* Get the key-value map of nodes to messages
*
* @return node-message map
*/
public Map<String, String> getMessageNodeMap() {
return ImmutableMap.copyOf(nodes);
}
/**
* Clear the previous message cache and load new messages directly from file
*
* @return reload messages from file
*/
public boolean reloadMessages() {
if (!this.file.exists()) {
plugin.getLogger().warning("Could not find file for locale " + this.name);
return false;
}
this.nodes.clear(); // Clear previous data (if any)
try(BufferedReader reader = new BufferedReader(new FileReader(file))) {
String line;
for (int lineNumber = 0; (line = reader.readLine()) != null; lineNumber++) {
if (line.isEmpty() || line.startsWith("#") /* Comment */) continue;
Matcher matcher = NODE_PATTERN.matcher(line);
if (!matcher.find()) {
System.err.println("Invalid locale syntax at (line=" + lineNumber + ")");
continue;
}
nodes.put(matcher.group(1), matcher.group(2));
}
} catch (IOException e) {
e.printStackTrace();
return false;
}
return true;
}
/**
* Initialize the locale class to generate information and search for localizations.
* This must be called before any other methods in the Locale class can be invoked.
* Note that this will also call {@link #searchForLocales()}, so there is no need to
* invoke it for yourself after the initialization
*
* @param plugin the plugin instance
*/
public static void init(JavaPlugin plugin) {
Locale.plugin = plugin;
if (localeFolder == null) {
localeFolder = new File(plugin.getDataFolder(), "locales/");
}
localeFolder.mkdirs();
Locale.searchForLocales();
}
/**
* Find all .lang file locales under the "locales" folder
*/
public static void searchForLocales() {
if (!localeFolder.exists()) localeFolder.mkdirs();
for (File file : localeFolder.listFiles()) {
String name = file.getName();
if (!name.endsWith(".lang")) continue;
String fileName = name.substring(0, name.lastIndexOf('.'));
String[] localeValues = fileName.split("_");
if (localeValues.length != 2) continue;
if (localeExists(localeValues[0] + "_" + localeValues[1])) continue;
LOCALES.add(new Locale(localeValues[0], localeValues[1]));
plugin.getLogger().info("Found and loaded locale \"" + fileName + "\"");
}
}
/**
* Get a locale by its entire proper name (i.e. "en_US")
*
* @param name the full name of the locale
* @return locale of the specified name
*/
public static Locale getLocale(String name) {
for (Locale locale : LOCALES)
if (locale.getLanguageTag().equalsIgnoreCase(name)) return locale;
return null;
}
/**
* Get a locale from the cache by its name (i.e. "en" from "en_US")
*
* @param name the name of the language
* @return locale of the specified language. Null if not cached
*/
public static Locale getLocaleByName(String name) {
for (Locale locale : LOCALES)
if (locale.getName().equalsIgnoreCase(name)) return locale;
return null;
}
/**
* Get a locale from the cache by its region (i.e. "US" from "en_US")
*
* @param region the name of the region
* @return locale of the specified region. Null if not cached
*/
public static Locale getLocaleByRegion(String region) {
for (Locale locale : LOCALES)
if (locale.getRegion().equalsIgnoreCase(region)) return locale;
return null;
}
/**
* Check whether a locale exists and is registered or not
*
* @param name the whole language tag (i.e. "en_US")
* @return true if it exists
*/
public static boolean localeExists(String name) {
for (Locale locale : LOCALES)
if (locale.getLanguageTag().equals(name)) return true;
return false;
}
/**
* Get an immutable list of all currently loaded locales
*
* @return list of all locales
*/
public static List<Locale> getLocales() {
return ImmutableList.copyOf(LOCALES);
}
/**
* Save a default locale file from the project source directory, to the locale folder
*
* @param path the path to the file to save
* @param fileName the name of the file to save
*
* @return true if the operation was successful, false otherwise
*/
public static boolean saveDefaultLocale(String path, String fileName) {
if (!localeFolder.exists()) localeFolder.mkdirs();
if (!fileName.endsWith(FILE_EXTENSION))
fileName = (fileName.lastIndexOf(".") == -1 ? fileName : fileName.substring(0, fileName.lastIndexOf('.'))) + FILE_EXTENSION;
File destinationFile = new File(localeFolder, fileName);
if (destinationFile.exists()) {
return compareFiles(plugin.getResource(fileName), destinationFile);
}
try (OutputStream outputStream = new FileOutputStream(destinationFile)) {
IOUtils.copy(plugin.getResource(fileName), outputStream);
fileName = fileName.substring(0, fileName.lastIndexOf('.'));
String[] localeValues = fileName.split("_");
if (localeValues.length != 2) return false;
LOCALES.add(new Locale(localeValues[0], localeValues[1]));
if (defaultLocale == null) defaultLocale = fileName;
return true;
} catch (IOException e) {
return false;
}
}
/**
* Save a default locale file from the project source directory, to the locale folder
*
* @param fileName the name of the file to save
* @return true if the operation was successful, false otherwise
*/
public static boolean saveDefaultLocale(String fileName) {
return saveDefaultLocale("", fileName);
}
/**
* Clear all current locale data
*/
public static void clearLocaleData() {
for (Locale locale : LOCALES)
locale.nodes.clear();
LOCALES.clear();
}
// Write new changes to existing files, if any at all
private static boolean compareFiles(InputStream defaultFile, File existingFile) {
// Look for default
if (defaultFile == null) {
defaultFile = plugin.getResource(defaultLocale != null ? defaultLocale : "en_US");
if (defaultFile == null) return false; // No default at all
}
boolean changed = false;
List<String> defaultLines, existingLines;
try (BufferedReader defaultReader = new BufferedReader(new InputStreamReader(defaultFile));
BufferedReader existingReader = new BufferedReader(new FileReader(existingFile));
BufferedWriter writer = new BufferedWriter(new FileWriter(existingFile, true))) {
defaultLines = defaultReader.lines().collect(Collectors.toList());
existingLines = existingReader.lines().map(s -> s.split("\\s*=")[0]).collect(Collectors.toList());
for (String defaultValue : defaultLines) {
if (defaultValue.isEmpty() || defaultValue.startsWith("#")) continue;
String key = defaultValue.split("\\s*=")[0];
if (!existingLines.contains(key)) {
if (!changed) {
writer.newLine(); writer.newLine();
writer.write("# New messages for " + plugin.getName() + " v" + plugin.getDescription().getVersion());
}
writer.newLine();
writer.write(defaultValue);
changed = true;
}
}
} catch (IOException e) {
return false;
}
return changed;
}
package com.songoda.epichoppers;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import org.apache.commons.io.IOUtils;
import org.bukkit.ChatColor;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
* Assists in the creation of multiple localizations and languages,
* as well as the generation of default .lang files
*
* @author Parker Hawke - 2008Choco
*/
public class Locale {
private static JavaPlugin plugin;
private static final List<Locale> LOCALES = Lists.newArrayList();
private static final Pattern NODE_PATTERN = Pattern.compile("(\\w+(?:\\.\\w+)*)\\s*=\\s*\"(.*)\"");
private static final String FILE_EXTENSION = ".lang";
private static File localeFolder;
private static String defaultLocale;
private final Map<String, String> nodes = new HashMap<>();
private final File file;
private final String name, region;
private Locale(String name, String region) {
if (plugin == null)
throw new IllegalStateException("Cannot generate locales without first initializing the class (Locale#init(JavaPlugin))");
this.name = name.toLowerCase();
this.region = region.toUpperCase();
String fileName = name + "_" + region + FILE_EXTENSION;
this.file = new File(localeFolder, fileName);
if (this.reloadMessages()) return;
plugin.getLogger().info("Loaded locale " + fileName);
}
/**
* Get the name of the language that this locale is based on.
* (i.e. "en" for English, or "fr" for French)
*
* @return the name of the language
*/
public String getName() {
return name;
}
/**
* Get the name of the region that this locale is from.
* (i.e. "US" for United States or "CA" for Canada)
*
* @return the name of the region
*/
public String getRegion() {
return region;
}
/**
* Return the entire locale tag (i.e. "en_US")
*
* @return the language tag
*/
public String getLanguageTag() {
return name + "_" + region;
}
/**
* Get the file that represents this locale
*
* @return the locale file (.lang)
*/
public File getFile() {
return file;
}
/**
* Get a message set for a specific node
*
* @param node the node to get
* @return the message for the specified node
*/
public String getMessage(String node) {
return ChatColor.translateAlternateColorCodes('&', this.getMessageOrDefault(node, node));
}
/**
* Get a message set for a specific node and replace its params with a supplied arguments.
*
* @param node the node to get
* @param args the replacement arguments
* @return the message for the specified node
*/
public String getMessage(String node, Object... args) {
String message = getMessage(node);
for (Object arg : args) {
message = message.replaceFirst("%.*?%", arg.toString());
}
return message;
}
/**
* Get a message set for a specific node
*
* @param node the node to get
* @param defaultValue the default value given that a value for the node was not found
*
* @return the message for the specified node. Default if none found
*/
public String getMessageOrDefault(String node, String defaultValue) {
return this.nodes.getOrDefault(node, defaultValue);
}
/**
* Get the key-value map of nodes to messages
*
* @return node-message map
*/
public Map<String, String> getMessageNodeMap() {
return ImmutableMap.copyOf(nodes);
}
/**
* Clear the previous message cache and load new messages directly from file
*
* @return reload messages from file
*/
public boolean reloadMessages() {
if (!this.file.exists()) {
plugin.getLogger().warning("Could not find file for locale " + this.name);
return false;
}
this.nodes.clear(); // Clear previous data (if any)
try(BufferedReader reader = new BufferedReader(new FileReader(file))) {
String line;
for (int lineNumber = 0; (line = reader.readLine()) != null; lineNumber++) {
if (line.isEmpty() || line.startsWith("#") /* Comment */) continue;
Matcher matcher = NODE_PATTERN.matcher(line);
if (!matcher.find()) {
System.err.println("Invalid locale syntax at (line=" + lineNumber + ")");
continue;
}
nodes.put(matcher.group(1), matcher.group(2));
}
} catch (IOException e) {
e.printStackTrace();
return false;
}
return true;
}
/**
* Initialize the locale class to generate information and search for localizations.
* This must be called before any other methods in the Locale class can be invoked.
* Note that this will also call {@link #searchForLocales()}, so there is no need to
* invoke it for yourself after the initialization
*
* @param plugin the plugin instance
*/
public static void init(JavaPlugin plugin) {
Locale.plugin = plugin;
if (localeFolder == null) {
localeFolder = new File(plugin.getDataFolder(), "locales/");
}
localeFolder.mkdirs();
Locale.searchForLocales();
}
/**
* Find all .lang file locales under the "locales" folder
*/
public static void searchForLocales() {
if (!localeFolder.exists()) localeFolder.mkdirs();
for (File file : localeFolder.listFiles()) {
String name = file.getName();
if (!name.endsWith(".lang")) continue;
String fileName = name.substring(0, name.lastIndexOf('.'));
String[] localeValues = fileName.split("_");
if (localeValues.length != 2) continue;
if (localeExists(localeValues[0] + "_" + localeValues[1])) continue;
LOCALES.add(new Locale(localeValues[0], localeValues[1]));
plugin.getLogger().info("Found and loaded locale \"" + fileName + "\"");
}
}
/**
* Get a locale by its entire proper name (i.e. "en_US")
*
* @param name the full name of the locale
* @return locale of the specified name
*/
public static Locale getLocale(String name) {
for (Locale locale : LOCALES)
if (locale.getLanguageTag().equalsIgnoreCase(name)) return locale;
return null;
}
/**
* Get a locale from the cache by its name (i.e. "en" from "en_US")
*
* @param name the name of the language
* @return locale of the specified language. Null if not cached
*/
public static Locale getLocaleByName(String name) {
for (Locale locale : LOCALES)
if (locale.getName().equalsIgnoreCase(name)) return locale;
return null;
}
/**
* Get a locale from the cache by its region (i.e. "US" from "en_US")
*
* @param region the name of the region
* @return locale of the specified region. Null if not cached
*/
public static Locale getLocaleByRegion(String region) {
for (Locale locale : LOCALES)
if (locale.getRegion().equalsIgnoreCase(region)) return locale;
return null;
}
/**
* Check whether a locale exists and is registered or not
*
* @param name the whole language tag (i.e. "en_US")
* @return true if it exists
*/
public static boolean localeExists(String name) {
for (Locale locale : LOCALES)
if (locale.getLanguageTag().equals(name)) return true;
return false;
}
/**
* Get an immutable list of all currently loaded locales
*
* @return list of all locales
*/
public static List<Locale> getLocales() {
return ImmutableList.copyOf(LOCALES);
}
/**
* Save a default locale file from the project source directory, to the locale folder
*
* @param path the path to the file to save
* @param fileName the name of the file to save
*
* @return true if the operation was successful, false otherwise
*/
public static boolean saveDefaultLocale(String path, String fileName) {
if (!localeFolder.exists()) localeFolder.mkdirs();
if (!fileName.endsWith(FILE_EXTENSION))
fileName = (fileName.lastIndexOf(".") == -1 ? fileName : fileName.substring(0, fileName.lastIndexOf('.'))) + FILE_EXTENSION;
File destinationFile = new File(localeFolder, fileName);
if (destinationFile.exists()) {
return compareFiles(plugin.getResource(fileName), destinationFile);
}
try (OutputStream outputStream = new FileOutputStream(destinationFile)) {
IOUtils.copy(plugin.getResource(fileName), outputStream);
fileName = fileName.substring(0, fileName.lastIndexOf('.'));
String[] localeValues = fileName.split("_");
if (localeValues.length != 2) return false;
LOCALES.add(new Locale(localeValues[0], localeValues[1]));
if (defaultLocale == null) defaultLocale = fileName;
return true;
} catch (IOException e) {
return false;
}
}
/**
* Save a default locale file from the project source directory, to the locale folder
*
* @param fileName the name of the file to save
* @return true if the operation was successful, false otherwise
*/
public static boolean saveDefaultLocale(String fileName) {
return saveDefaultLocale("", fileName);
}
/**
* Clear all current locale data
*/
public static void clearLocaleData() {
for (Locale locale : LOCALES)
locale.nodes.clear();
LOCALES.clear();
}
// Write new changes to existing files, if any at all
private static boolean compareFiles(InputStream defaultFile, File existingFile) {
// Look for default
if (defaultFile == null) {
defaultFile = plugin.getResource(defaultLocale != null ? defaultLocale : "en_US");
if (defaultFile == null) return false; // No default at all
}
boolean changed = false;
List<String> defaultLines, existingLines;
try (BufferedReader defaultReader = new BufferedReader(new InputStreamReader(defaultFile));
BufferedReader existingReader = new BufferedReader(new FileReader(existingFile));
BufferedWriter writer = new BufferedWriter(new FileWriter(existingFile, true))) {
defaultLines = defaultReader.lines().collect(Collectors.toList());
existingLines = existingReader.lines().map(s -> s.split("\\s*=")[0]).collect(Collectors.toList());
for (String defaultValue : defaultLines) {
if (defaultValue.isEmpty() || defaultValue.startsWith("#")) continue;
String key = defaultValue.split("\\s*=")[0];
if (!existingLines.contains(key)) {
if (!changed) {
writer.newLine(); writer.newLine();
writer.write("# New messages for " + plugin.getName() + " v" + plugin.getDescription().getVersion());
}
writer.newLine();
writer.write(defaultValue);
changed = true;
}
}
} catch (IOException e) {
return false;
}
return changed;
}
}

View File

@ -1,14 +1,14 @@
package com.songoda.epichoppers;
public class References {
private String prefix;
public References() {
prefix = EpicHoppers.getInstance().getLocale().getMessage("general.nametag.prefix") + " ";
}
public String getPrefix() {
return this.prefix;
}
}
package com.songoda.epichoppers;
public class References {
private String prefix;
public References() {
prefix = EpicHoppersPlugin.getInstance().getLocale().getMessage("general.nametag.prefix") + " ";
}
public String getPrefix() {
return this.prefix;
}
}

View File

@ -1,171 +1,165 @@
package com.songoda.epichoppers.Events;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.epichoppers.EpicHoppers;
import com.songoda.epichoppers.Hopper.Filter;
import com.songoda.epichoppers.Hopper.Hopper;
import com.songoda.epichoppers.Utils.Debugger;
import com.songoda.epichoppers.Utils.Methods;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.ExperienceOrb;
import org.bukkit.entity.Item;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.Collection;
/**
* Created by songoda on 3/14/2017.
*/
public class BlockListeners implements Listener {
private EpicHoppers instance;
public BlockListeners(EpicHoppers instance) {
this.instance = instance;
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent e) {
try {
if (e.getBlock().getType().equals(Material.ENDER_CHEST)) {
instance.dataFile.getConfig().set("data.enderTracker." + Arconix.pl().getApi().serialize().serializeLocation(e.getBlock()), e.getPlayer().getUniqueId().toString());
return;
}
if (e.getBlock().getType() != Material.HOPPER) return;
int amt = count(e.getBlock().getChunk());
if (amt >= instance.getConfig().getInt("Main.Max Hoppers Per Chunk") && instance.getConfig().getInt("Main.Max Hoppers Per Chunk") != -1) {
e.getPlayer().sendMessage(instance.getLocale().getMessage("event.hopper.toomany"));
e.setCancelled(true);
return;
}
if (!e.getItemInHand().getItemMeta().hasDisplayName()) return;
ItemStack item = e.getItemInHand().clone();
e.getBlock().setType(Material.AIR);
e.getBlock().getLocation().getBlock().setType(Material.HOPPER);
instance.getHopperManager().addHopper(e.getBlock().getLocation(), new Hopper(e.getBlock(), instance.getLevelManager().getLevel(instance.getApi().getILevel(item)), e.getPlayer().getUniqueId(), null, new Filter(), false));
} catch (Exception ee) {
Debugger.runReport(ee);
}
}
public int count(Chunk c) {
try {
int count = 0;
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
for (int y = 0; y < c.getWorld().getMaxHeight(); y++) {
if (c.getBlock(x, y, z).getType() == Material.HOPPER) count++;
}
}
}
return count;
} catch (Exception e) {
Debugger.runReport(e);
}
return 9999;
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
try {
if (event.getBlock().getType().equals(Material.ENDER_CHEST)) {
instance.dataFile.getConfig().set("data.enderTracker." + Arconix.pl().getApi().serialize().serializeLocation(event.getBlock()), null);
}
Block block = event.getBlock();
if (event.getPlayer().getItemInHand() == null) return;
handleSyncTouch(event);
if (event.getBlock().getType() != Material.HOPPER) return;
Hopper hopper = instance.getHopperManager().getHopper(block);
int level = hopper.getLevel().getLevel();
if (level != 0) {
event.setCancelled(true);
ItemStack item = new ItemStack(Material.HOPPER, 1);
ItemMeta itemmeta = item.getItemMeta();
itemmeta.setDisplayName(Arconix.pl().getApi().format().formatText(Methods.formatName(level, true)));
item.setItemMeta(itemmeta);
event.getBlock().setType(Material.AIR);
event.getBlock().getLocation().getWorld().dropItemNaturally(event.getBlock().getLocation(), item);
}
for (ItemStack i : hopper.getFilter().getWhiteList()) {
if (i != null)
event.getBlock().getLocation().getWorld().dropItemNaturally(event.getBlock().getLocation(), i);
}
for (ItemStack i : hopper.getFilter().getBlackList()) {
if (i != null)
event.getBlock().getLocation().getWorld().dropItemNaturally(event.getBlock().getLocation(), i);
}
for (ItemStack i : hopper.getFilter().getVoidList()) {
if (i != null)
event.getBlock().getLocation().getWorld().dropItemNaturally(event.getBlock().getLocation(), i);
}
instance.getHopperManager().removeHopper(block.getLocation());
instance.sync.remove(event.getPlayer());
} catch (Exception ee) {
Debugger.runReport(ee);
}
}
private void handleSyncTouch(BlockBreakEvent e) {
if (!Methods.isSync(e.getPlayer())) return;
ItemStack tool = e.getPlayer().getItemInHand();
ItemMeta meta = tool.getItemMeta();
if (tool.getItemMeta().getLore().size() != 2) return;
Location location = Arconix.pl().getApi().serialize().unserializeLocation(meta.getLore().get(1).replaceAll("§", ""));
if (location.getBlock().getType() != Material.CHEST) return;
if (e.getBlock().getType() == Material.SPAWNER || e.getBlock().getType() == Material.HOPPER || e.getBlock().getType() == Material.DISPENSER) return;
try {
if (e.getBlock().getType().name().contains("SHULKER") && e.getBlock().getType() != Material.SHULKER_SHELL) return;
} catch (Exception ee) {
}
InventoryHolder ih = (InventoryHolder) location.getBlock().getState();
if (e.getPlayer().getItemInHand().getItemMeta().hasEnchant(Enchantment.SILK_TOUCH)) {
ih.getInventory().addItem(new ItemStack(e.getBlock().getType(),1, e.getBlock().getData()));
} else {
for (ItemStack is : e.getBlock().getDrops())
ih.getInventory().addItem(is);
}
e.setDropItems(false);
return;
}
package com.songoda.epichoppers.events;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.epichoppers.EpicHoppersPlugin;
import com.songoda.epichoppers.api.hopper.Hopper;
import com.songoda.epichoppers.hopper.EFilter;
import com.songoda.epichoppers.hopper.EHopper;
import com.songoda.epichoppers.utils.Debugger;
import com.songoda.epichoppers.utils.Methods;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
/**
* Created by songoda on 3/14/2017.
*/
public class BlockListeners implements Listener {
private EpicHoppersPlugin instance;
public BlockListeners(EpicHoppersPlugin instance) {
this.instance = instance;
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent e) {
try {
if (e.getBlock().getType().equals(Material.ENDER_CHEST)) {
instance.dataFile.getConfig().set("data.enderTracker." + Arconix.pl().getApi().serialize().serializeLocation(e.getBlock()), e.getPlayer().getUniqueId().toString());
return;
}
if (e.getBlock().getType() != Material.HOPPER) return;
int amt = count(e.getBlock().getChunk());
if (amt >= instance.getConfig().getInt("Main.Max Hoppers Per Chunk") && instance.getConfig().getInt("Main.Max Hoppers Per Chunk") != -1) {
e.getPlayer().sendMessage(instance.getLocale().getMessage("event.hopper.toomany"));
e.setCancelled(true);
return;
}
if (!e.getItemInHand().getItemMeta().hasDisplayName()) return;
ItemStack item = e.getItemInHand().clone();
e.getBlock().setType(Material.AIR);
e.getBlock().getLocation().getBlock().setType(Material.HOPPER);
instance.getHopperManager().addHopper(e.getBlock().getLocation(), new EHopper(e.getBlock(), instance.getLevelFromItem(item), e.getPlayer().getUniqueId(), null, new EFilter(), false));
} catch (Exception ee) {
Debugger.runReport(ee);
}
}
public int count(Chunk c) {
try {
int count = 0;
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
for (int y = 0; y < c.getWorld().getMaxHeight(); y++) {
if (c.getBlock(x, y, z).getType() == Material.HOPPER) count++;
}
}
}
return count;
} catch (Exception e) {
Debugger.runReport(e);
}
return 9999;
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
try {
if (event.getBlock().getType().equals(Material.ENDER_CHEST)) {
instance.dataFile.getConfig().set("data.enderTracker." + Arconix.pl().getApi().serialize().serializeLocation(event.getBlock()), null);
}
Block block = event.getBlock();
Player player = event.getPlayer();
if (player.getInventory().getItemInMainHand() == null) return;
handleSyncTouch(event);
if (event.getBlock().getType() != Material.HOPPER) return;
Hopper hopper = instance.getHopperManager().getHopper(block);
int level = hopper.getLevel().getLevel();
if (level != 0) {
event.setCancelled(true);
ItemStack item = new ItemStack(Material.HOPPER, 1);
ItemMeta itemmeta = item.getItemMeta();
itemmeta.setDisplayName(Arconix.pl().getApi().format().formatText(Methods.formatName(level, true)));
item.setItemMeta(itemmeta);
event.getBlock().setType(Material.AIR);
event.getBlock().getLocation().getWorld().dropItemNaturally(event.getBlock().getLocation(), item);
}
for (ItemStack i : hopper.getFilter().getWhiteList()) {
if (i != null)
event.getBlock().getLocation().getWorld().dropItemNaturally(event.getBlock().getLocation(), i);
}
for (ItemStack i : hopper.getFilter().getBlackList()) {
if (i != null)
event.getBlock().getLocation().getWorld().dropItemNaturally(event.getBlock().getLocation(), i);
}
for (ItemStack i : hopper.getFilter().getVoidList()) {
if (i != null)
event.getBlock().getLocation().getWorld().dropItemNaturally(event.getBlock().getLocation(), i);
}
instance.getHopperManager().removeHopper(block.getLocation());
instance.getPlayerDataManager().getPlayerData(player).setSyncType(null);
} catch (Exception ee) {
Debugger.runReport(ee);
}
}
private void handleSyncTouch(BlockBreakEvent e) {
if (!Methods.isSync(e.getPlayer())) return;
ItemStack tool = e.getPlayer().getInventory().getItemInMainHand();
ItemMeta meta = tool.getItemMeta();
if (tool.getItemMeta().getLore().size() != 2) return;
Location location = Arconix.pl().getApi().serialize().unserializeLocation(meta.getLore().get(1).replaceAll("§", ""));
if (location.getBlock().getType() != Material.CHEST) return;
if (e.getBlock().getType() == Material.SHULKER_BOX
|| e.getBlock().getType() == Material.SPAWNER
|| e.getBlock().getType() == Material.HOPPER
|| e.getBlock().getType() == Material.DISPENSER) {
return;
}
InventoryHolder ih = (InventoryHolder) location.getBlock().getState();
if (e.getPlayer().getInventory().getItemInMainHand().getItemMeta().hasEnchant(Enchantment.SILK_TOUCH)) {
ih.getInventory().addItem(new ItemStack(e.getBlock().getType(), 1, e.getBlock().getData()));
} else {
for (ItemStack is : e.getBlock().getDrops())
ih.getInventory().addItem(is);
}
e.setDropItems(false);
}
}

View File

@ -1,107 +1,108 @@
package com.songoda.epichoppers.Events;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.epichoppers.EpicHoppers;
import com.songoda.epichoppers.Utils.Debugger;
import com.songoda.epichoppers.Utils.Methods;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Hopper;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
/**
* Created by songoda on 4/18/2017.
*/
public class HopperListeners implements Listener {
private EpicHoppers instance;
public HopperListeners(EpicHoppers instance) {
this.instance = instance;
}
@EventHandler(ignoreCancelled = true)
public void onHop(InventoryMoveItemEvent e) {
try {
Inventory source = e.getSource();
if (!instance.getHopperManager().isHopper(e.getSource().getLocation())) return;
com.songoda.epichoppers.Hopper.Hopper hopper = instance.getHopperManager().getHopper(e.getSource().getLocation());
if (source.getHolder() instanceof Hopper && hopper.getSyncedBlock() != null) {
e.setCancelled(true);
}
} catch (Exception ee) {
Debugger.runReport(ee);
}
}
private Map<UUID, Player> ents = new HashMap<>();
@EventHandler
public void onDed(EntityDamageByEntityEvent e) {
try {
if (e.getDamager() instanceof Player) {
Player p = (Player) e.getDamager();
if (Methods.isSync(p)) {
double d = ((LivingEntity) e.getEntity()).getHealth() - e.getDamage();
if (d < 1) {
ents.put(e.getEntity().getUniqueId(), p);
}
}
}
} catch (Exception ee) {
Debugger.runReport(ee);
}
}
@EventHandler
public void onDrop(EntityDeathEvent e) {
try {
if (ents.containsKey(e.getEntity().getUniqueId())) {
Player p = ents.get(e.getEntity().getUniqueId());
ItemStack item = p.getItemInHand();
ItemMeta meta = item.getItemMeta();
Location location = Arconix.pl().getApi().serialize().unserializeLocation(meta.getLore().get(1).replaceAll("§", ""));
if (location.getBlock().getType() == Material.CHEST) {
InventoryHolder ih = (InventoryHolder) location.getBlock().getState();
for (ItemStack is : e.getDrops()) {
ih.getInventory().addItem(is);
}
e.getDrops().clear();
}
}
} catch (Exception ee) {
Debugger.runReport(ee);
}
}
private int getItemCount(Inventory inventory, ItemStack item) {
int amount = 0;
for (ItemStack inventoryItem : inventory) {
if (!item.isSimilar(inventoryItem)) continue;
amount += inventoryItem.getAmount();
}
return amount;
}
}
package com.songoda.epichoppers.events;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.epichoppers.EpicHoppersPlugin;
import com.songoda.epichoppers.api.hopper.Hopper;
import com.songoda.epichoppers.hopper.EHopper;
import com.songoda.epichoppers.utils.Debugger;
import com.songoda.epichoppers.utils.Methods;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
/**
* Created by songoda on 4/18/2017.
*/
public class HopperListeners implements Listener {
private EpicHoppersPlugin instance;
public HopperListeners(EpicHoppersPlugin instance) {
this.instance = instance;
}
@EventHandler(ignoreCancelled = true)
public void onHop(InventoryMoveItemEvent e) {
try {
Inventory source = e.getSource();
if (!instance.getHopperManager().isHopper(e.getSource().getLocation())) return;
Hopper hopper = instance.getHopperManager().getHopper(e.getSource().getLocation());
if (source.getHolder() instanceof Hopper && hopper.getSyncedBlock() != null) {
e.setCancelled(true);
}
} catch (Exception ee) {
Debugger.runReport(ee);
}
}
private Map<UUID, Player> ents = new HashMap<>();
@EventHandler
public void onDed(EntityDamageByEntityEvent e) {
try {
if (e.getDamager() instanceof Player) {
Player p = (Player) e.getDamager();
if (Methods.isSync(p)) {
double d = ((LivingEntity) e.getEntity()).getHealth() - e.getDamage();
if (d < 1) {
ents.put(e.getEntity().getUniqueId(), p);
}
}
}
} catch (Exception ee) {
Debugger.runReport(ee);
}
}
@EventHandler
public void onDrop(EntityDeathEvent e) {
try {
if (ents.containsKey(e.getEntity().getUniqueId())) {
Player p = ents.get(e.getEntity().getUniqueId());
ItemStack item = p.getItemInHand();
ItemMeta meta = item.getItemMeta();
Location location = Arconix.pl().getApi().serialize().unserializeLocation(meta.getLore().get(1).replaceAll("§", ""));
if (location.getBlock().getType() == Material.CHEST) {
InventoryHolder ih = (InventoryHolder) location.getBlock().getState();
for (ItemStack is : e.getDrops()) {
ih.getInventory().addItem(is);
}
e.getDrops().clear();
}
}
} catch (Exception ee) {
Debugger.runReport(ee);
}
}
private int getItemCount(Inventory inventory, ItemStack item) {
int amount = 0;
for (ItemStack inventoryItem : inventory) {
if (!item.isSimilar(inventoryItem)) continue;
amount += inventoryItem.getAmount();
}
return amount;
}
}

View File

@ -1,100 +1,96 @@
package com.songoda.epichoppers.Events;
import com.songoda.epichoppers.EpicHoppers;
import com.songoda.epichoppers.Hopper.Hopper;
import com.songoda.epichoppers.Utils.Debugger;
import com.songoda.epichoppers.Utils.Methods;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
/**
* Created by songoda on 3/14/2017.
*/
public class InteractListeners implements Listener {
private EpicHoppers instance;
public InteractListeners(EpicHoppers instance) {
this.instance = instance;
}
@EventHandler
public void onBlockInteract(PlayerInteractEvent e) {
try {
Player player = e.getPlayer();
if (e.getAction() != Action.LEFT_CLICK_BLOCK
|| e.getClickedBlock() == null
|| player.isSneaking()
|| !player.hasPermission("EpicHoppers.overview")
|| !instance.hooks.canBuild(player, e.getClickedBlock().getLocation())
|| !(e.getClickedBlock().getState() instanceof InventoryHolder || e.getClickedBlock().getType().equals(Material.ENDER_CHEST))) {
return;
}
if (e.getClickedBlock().getType() == Material.CHEST && Methods.isSync(player)) {
ItemStack item = e.getPlayer().getInventory().getItemInMainHand();
if (item.getItemMeta().getLore().size() == 2) {
player.sendMessage(instance.getLocale().getMessage("event.hopper.desyncchest", item.getType().toString()));
instance.enchant.createSyncTouch(item, null);
} else {
player.sendMessage(instance.getLocale().getMessage("event.hopper.syncchest", item.getType().toString()));
instance.enchant.createSyncTouch(item, e.getClickedBlock());
}
e.setCancelled(true);
return;
}
if (!instance.sync.containsKey(player) && !instance.bsync.containsKey(player)) {
if (e.getClickedBlock().getType() == Material.HOPPER) {
instance.lastBlock.put(player, e.getClickedBlock());
Hopper hopper = instance.getHopperManager().getHopper(e.getClickedBlock());
if (instance.getConfig().getBoolean("Main.Allow Hopper Upgrading")) {
if (!player.getInventory().getItemInMainHand().getType().name().contains("PICKAXE")) {
hopper.overview(player);
e.setCancelled(true);
}
} else { //ToDO: What is this?
if (player.hasPermission("EpicHoppers.Admin")) {
instance.sync.put(player, instance.lastBlock.get(player));
player.sendMessage(instance.getLocale().getMessage("event.hopper.syncnext"));
hopper.timeout(player);
player.closeInventory();
}
e.setCancelled(true);
}
}
return;
}
if (e.getClickedBlock().getType() == Material.BREWING_STAND) return;
if (e.getClickedBlock().getState() instanceof InventoryHolder || e.getClickedBlock().getType().equals(Material.ENDER_CHEST) && instance.getConfig().getBoolean("Main.Support Enderchests")) {
if (instance.sync.containsKey(player) && instance.sync.get(player).equals(e.getClickedBlock()) || instance.bsync.containsKey(player) && instance.bsync.get(player).equals(e.getClickedBlock())) {
player.sendMessage(instance.getLocale().getMessage("event.hopper.syncself"));
} else {
if (instance.sync.containsKey(player)) {
Hopper hopper = instance.getHopperManager().getHopper(instance.sync.get(player));
hopper.sync(e.getClickedBlock(), false, player);
} else if (instance.bsync.containsKey(player)) {
Hopper hopper = instance.getHopperManager().getHopper(instance.bsync.get(player));
hopper.sync(e.getClickedBlock(), true, player);
}
}
e.setCancelled(true);
instance.sync.remove(player);
instance.bsync.remove(player);
}
} catch (Exception ee) {
Debugger.runReport(ee);
}
}
}
package com.songoda.epichoppers.events;
import com.songoda.epichoppers.EpicHoppersPlugin;
import com.songoda.epichoppers.api.hopper.Hopper;
import com.songoda.epichoppers.hopper.EHopper;
import com.songoda.epichoppers.player.PlayerData;
import com.songoda.epichoppers.player.SyncType;
import com.songoda.epichoppers.utils.Debugger;
import com.songoda.epichoppers.utils.Methods;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
/**
* Created by songoda on 3/14/2017.
*/
public class InteractListeners implements Listener {
private EpicHoppersPlugin instance;
public InteractListeners(EpicHoppersPlugin instance) {
this.instance = instance;
}
@EventHandler
public void onBlockInteract(PlayerInteractEvent e) {
try {
Player player = e.getPlayer();
if (e.getAction() != Action.LEFT_CLICK_BLOCK
|| e.getClickedBlock() == null
|| player.isSneaking()
|| !player.hasPermission("EpicHoppers.overview")
|| !instance.hooks.canBuild(player, e.getClickedBlock().getLocation())
|| !(e.getClickedBlock().getState() instanceof InventoryHolder || e.getClickedBlock().getType().equals(Material.ENDER_CHEST))) {
return;
}
if (e.getClickedBlock().getType() == Material.CHEST && Methods.isSync(player)) {
ItemStack item = e.getPlayer().getInventory().getItemInMainHand();
if (item.getItemMeta().getLore().size() == 2) {
player.sendMessage(instance.getLocale().getMessage("event.hopper.desyncchest", item.getType().toString()));
instance.enchantmentHandler.createSyncTouch(item, null);
} else {
player.sendMessage(instance.getLocale().getMessage("event.hopper.syncchest", item.getType().toString()));
instance.enchantmentHandler.createSyncTouch(item, e.getClickedBlock());
}
e.setCancelled(true);
return;
}
PlayerData playerData = instance.getPlayerDataManager().getPlayerData(player);
if (playerData.getSyncType() == null) {
if (e.getClickedBlock().getType() == Material.HOPPER) {
Hopper hopper = instance.getHopperManager().getHopper(e.getClickedBlock());
playerData.setLastHopper(hopper);
if (instance.getConfig().getBoolean("Main.Allow hopper Upgrading")
&& !player.getInventory().getItemInMainHand().getType().name().contains("PICKAXE")) {
((EHopper)hopper).overview(player);
e.setCancelled(true);
return;
}
//ToDO: What is this?
if (player.hasPermission("EpicHoppers.Admin")) {
playerData.setLastHopper(hopper);
player.sendMessage(instance.getLocale().getMessage("event.hopper.syncnext"));
((EHopper)hopper).timeout(player);
player.closeInventory();
}
e.setCancelled(true);
}
return;
}
if (e.getClickedBlock().getType() == Material.BREWING_STAND) return;
if (e.getClickedBlock().getState() instanceof InventoryHolder || e.getClickedBlock().getType().equals(Material.ENDER_CHEST) && instance.getConfig().getBoolean("Main.Support Enderchests")) {
if (playerData.getSyncType() != null && e.getClickedBlock().getLocation().equals(playerData.getLastHopper().getLocation())) {
player.sendMessage(instance.getLocale().getMessage("event.hopper.syncself"));
} else if (playerData.getSyncType() != null) {
playerData.getLastHopper().sync(e.getClickedBlock(), playerData.getSyncType() == SyncType.FILTERED, player);
}
e.setCancelled(true);
playerData.setSyncType(null);
}
} catch (Exception ee) {
Debugger.runReport(ee);
}
}
}

View File

@ -1,212 +1,220 @@
package com.songoda.epichoppers.Events;
import com.songoda.epichoppers.EpicHoppers;
import com.songoda.epichoppers.Hopper.Hopper;
import com.songoda.epichoppers.Utils.Debugger;
import com.songoda.epichoppers.Utils.Methods;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.*;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
/**
* Created by songoda on 3/14/2017.
*/
public class InventoryListeners implements Listener {
private EpicHoppers instance;
public InventoryListeners(EpicHoppers instance) {
this.instance = instance;
}
@EventHandler
public void onInventoryClick(InventoryClickEvent e) {
try {
Inventory inv = e.getInventory();
Player player = (Player) e.getWhoClicked();
if (inv == null || e.getCurrentItem() == null) return;
if (e.getCursor() != null && e.getCurrentItem() != null) {
ItemStack c = e.getCursor();
ItemStack item = e.getCurrentItem();
if (c.hasItemMeta()
&& c.getItemMeta().hasLore()
&& c.getType() == Material.ENCHANTED_BOOK
&& (item.getType().name().toUpperCase().contains("AXE") || item.getType().name().toUpperCase().contains("SPADE") || item.getType().name().toUpperCase().contains("SWORD"))
&& c.getItemMeta().getLore().equals(instance.enchant.getbook().getItemMeta().getLore())) {
instance.enchant.createSyncTouch(item, null);
e.setCancelled(true);
player.setItemOnCursor(new ItemStack(Material.AIR));
player.updateInventory();
}
}
if (!e.getCurrentItem().hasItemMeta()) return;
if (doFilter(e)) return;
if (e.getSlot() != 64537
&& e.getInventory().getType() == InventoryType.ANVIL
&& e.getAction() != InventoryAction.NOTHING
&& e.getCurrentItem().getType() != Material.AIR) {
ItemStack item = e.getCurrentItem();
if (item.getType() == Material.HOPPER) {
e.setCancelled(true);
}
}
if (!instance.inShow.containsKey(player.getUniqueId()) || instance.inFilter.containsKey(player.getUniqueId())) {
return;
}
e.setCancelled(true);
Hopper hopper = instance.getHopperManager().getHopper(instance.lastBlock.get(player));
if (e.getCurrentItem().getItemMeta().hasDisplayName()
&& e.getCurrentItem().getItemMeta().getDisplayName().equals(instance.getLocale().getMessage("interface.hopper.perltitle"))
&& (instance.getConfig().getBoolean("Main.Allow Players To Teleport Through Hoppers") || player.hasPermission("EpicHoppers.Teleport"))) {
if (e.isLeftClick()) {
if (hopper.getSyncedBlock() != null) {
instance.getTeleportHandler().tpPlayer(player, hopper);
}
} else {
if (!hopper.isWalkOnTeleport()) {
player.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.hopper.walkteleenabled"));
hopper.setWalkOnTeleport(true);
} else {
player.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.hopper.walkteledisabled"));
hopper.setWalkOnTeleport(false);
}
}
player.closeInventory();
} else if (e.getCurrentItem().getItemMeta().hasDisplayName() && e.getCurrentItem().getItemMeta().getDisplayName().equals(instance.getLocale().getMessage("interface.hopper.filtertitle")) && player.hasPermission("EpicHoppers.Filter")) {
if (!e.getCurrentItem().getItemMeta().getDisplayName().equals("§l")) {
hopper.filter(player);
}
} else if (e.getSlot() == 11 && player.hasPermission("EpicHoppers.Upgrade.XP")) {
if (!e.getCurrentItem().getItemMeta().getDisplayName().equals("§l")) {
hopper.upgrade("XP", player);
player.closeInventory();
}
} else if (e.getSlot() == 15 && player.hasPermission("EpicHoppers.Upgrade.ECO")) {
if (!e.getCurrentItem().getItemMeta().getDisplayName().equals("§l")) {
hopper.upgrade("ECO", player);
player.closeInventory();
}
} else if (e.getSlot() == 22) {
if (e.isRightClick()) {
player.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.hopper.desync"));
hopper.setSyncedBlock(null);
} else {
boolean can = true;
if (hopper.getLastPlayer() != null) {
if (!hopper.getLastPlayer().equals(player.getUniqueId())) {
player.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.hopper.syncdidnotplace"));
can = false;
}
}
if (can) {
instance.sync.put(player, instance.lastBlock.get(player));
player.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.hopper.syncnext"));
hopper.timeout(player);
}
}
player.closeInventory();
}
} catch (Exception ee) {
Debugger.runReport(ee);
}
}
private boolean doFilter(InventoryClickEvent e) {
Player player = (Player) e.getWhoClicked();
if (!instance.inFilter.containsKey(player.getUniqueId())
|| e.getInventory() == null
|| !e.getInventory().equals(player.getOpenInventory().getTopInventory())) {
return false;
}
if (e.getClick().equals(ClickType.SHIFT_LEFT)) {
e.setCancelled(true);
return true;
}
Hopper hopper = instance.getHopperManager().getHopper(instance.lastBlock.get(player));
hopper.compile(player);
if (e.getSlot() == 40) {
instance.bsync.put(player, instance.lastBlock.get(player));
player.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.hopper.syncnext"));
hopper.timeout(player);
player.closeInventory();
return true;
}
int[] a = {0, 1, 9, 10, 18, 19, 27, 28, 36, 37, 45, 46, 7, 8, 16, 17, 25, 26, 34, 35, 43, 44, 52, 53};
e.setCancelled(true);
for (int aa : a) {
if (aa != e.getSlot()) continue;
String name = "";
if (e.getCurrentItem().hasItemMeta() && e.getCurrentItem().getItemMeta().hasDisplayName())
name = e.getCurrentItem().getItemMeta().getDisplayName();
if (!name.equals(instance.getLocale().getMessage("interface.filter.whitelist")) &&
!name.equals(instance.getLocale().getMessage("interface.filter.blacklist")) &&
!name.equals(instance.getLocale().getMessage("interface.filter.void"))) {
e.setCancelled(false);
return true;
}
if (e.getCursor().getType().equals(Material.AIR)) return true;
if (e.getCursor().getAmount() != 1) {
e.setCancelled(true);
player.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.hopper.onlyone"));
return true;
}
e.setCancelled(false);
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> player.setItemOnCursor(new ItemStack(Material.AIR)), 1L);
return true;
}
return true;
}
@EventHandler
public void onDrop(PlayerDropItemEvent e) {
ItemStack item = e.getItemDrop().getItemStack();
if (!item.hasItemMeta() || !item.getItemMeta().hasDisplayName()) {
return;
}
String name = item.getItemMeta().getDisplayName();
if (!name.equals(instance.getLocale().getMessage("interface.filter.whitelist")) &&
!name.equals(instance.getLocale().getMessage("interface.filter.blacklist")) &&
!name.equals(instance.getLocale().getMessage("interface.filter.void"))) {
return;
}
e.getItemDrop().remove();
}
@EventHandler
public void onClose(InventoryCloseEvent event) {
try {
final Player player = (Player) event.getPlayer();
instance.inShow.remove(player.getUniqueId());
if (instance.inFilter.containsKey(player.getUniqueId())) {
instance.getHopperManager().getHopper(instance.lastBlock.get(player)).compile(player);
instance.inFilter.remove(player.getUniqueId());
}
} catch (Exception e) {
Debugger.runReport(e);
}
}
package com.songoda.epichoppers.events;
import com.songoda.epichoppers.EpicHoppersPlugin;
import com.songoda.epichoppers.api.hopper.Hopper;
import com.songoda.epichoppers.hopper.EHopper;
import com.songoda.epichoppers.player.MenuType;
import com.songoda.epichoppers.player.PlayerData;
import com.songoda.epichoppers.player.SyncType;
import com.songoda.epichoppers.utils.Debugger;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.*;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
/**
* Created by songoda on 3/14/2017.
*/
public class InventoryListeners implements Listener {
private EpicHoppersPlugin instance;
public InventoryListeners(EpicHoppersPlugin instance) {
this.instance = instance;
}
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
try {
Inventory inv = event.getInventory();
Player player = (Player) event.getWhoClicked();
if (inv == null || event.getCurrentItem() == null) return;
if (event.getRawSlot() > event.getView().getTopInventory().getSize() - 1) return;
if (event.getCursor() != null && event.getCurrentItem() != null) {
ItemStack c = event.getCursor();
ItemStack item = event.getCurrentItem();
if (c.hasItemMeta()
&& c.getItemMeta().hasLore()
&& c.getType() == Material.ENCHANTED_BOOK
&& (item.getType().name().toUpperCase().contains("AXE") || item.getType().name().toUpperCase().contains("SPADE") || item.getType().name().toUpperCase().contains("SWORD"))
&& c.getItemMeta().getLore().equals(instance.enchantmentHandler.getbook().getItemMeta().getLore())) {
instance.enchantmentHandler.createSyncTouch(item, null);
event.setCancelled(true);
player.setItemOnCursor(new ItemStack(Material.AIR));
player.updateInventory();
}
}
if (!event.getCurrentItem().hasItemMeta()) return;
if (doFilter(event)) 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() == Material.HOPPER) {
event.setCancelled(true);
}
}
PlayerData playerData = instance.getPlayerDataManager().getPlayerData(player);
if (playerData.getInMenu() != MenuType.OVERVIEW) return;
event.setCancelled(true);
Hopper hopper = playerData.getLastHopper();
if (event.getCurrentItem().getItemMeta().hasDisplayName()
&& event.getCurrentItem().getItemMeta().getDisplayName().equals(instance.getLocale().getMessage("interface.hopper.perltitle"))
&& (instance.getConfig().getBoolean("Main.Allow Players To Teleport Through Hoppers") || player.hasPermission("EpicHoppers.Teleport"))) {
if (event.isLeftClick()) {
if (hopper.getSyncedBlock() != null) {
instance.getTeleportHandler().tpPlayer(player, hopper);
}
} else {
if (!hopper.isWalkOnTeleport()) {
player.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.hopper.walkteleenabled"));
hopper.setWalkOnTeleport(true);
} else {
player.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.hopper.walkteledisabled"));
hopper.setWalkOnTeleport(false);
}
}
player.closeInventory();
} else if (event.getCurrentItem().getItemMeta().hasDisplayName() && event.getCurrentItem().getItemMeta().getDisplayName().equals(instance.getLocale().getMessage("interface.hopper.filtertitle")) && player.hasPermission("EpicHoppers.Filter")) {
if (!event.getCurrentItem().getItemMeta().getDisplayName().equals("§l")) {
((EHopper)hopper).filter(player);
}
} else if (event.getSlot() == 11 && player.hasPermission("EpicHoppers.Upgrade.XP")) {
if (!event.getCurrentItem().getItemMeta().getDisplayName().equals("§l")) {
((EHopper)hopper).upgrade("XP", player);
player.closeInventory();
}
} else if (event.getSlot() == 15 && player.hasPermission("EpicHoppers.Upgrade.ECO")) {
if (!event.getCurrentItem().getItemMeta().getDisplayName().equals("§l")) {
((EHopper)hopper).upgrade("ECO", player);
player.closeInventory();
}
} else if (event.getSlot() == 22) {
if (event.isRightClick()) {
player.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.hopper.desync"));
hopper.setSyncedBlock(null);
} else {
boolean can = true;
if (hopper.getLastPlayer() != null) {
if (!hopper.getLastPlayer().equals(player.getUniqueId())) {
player.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.hopper.syncdidnotplace"));
can = false;
}
}
if (can) {
playerData.setSyncType(SyncType.REGULAR);
player.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.hopper.syncnext"));
((EHopper)hopper).timeout(player);
}
}
player.closeInventory();
}
} catch (Exception ee) {
Debugger.runReport(ee);
}
}
private boolean doFilter(InventoryClickEvent e) {
Player player = (Player) e.getWhoClicked();
PlayerData playerData = instance.getPlayerDataManager().getPlayerData(player);
if (playerData.getInMenu() != MenuType.FILTER
|| e.getInventory() == null
|| !e.getInventory().equals(player.getOpenInventory().getTopInventory())) {
return false;
}
if (e.getClick().equals(ClickType.SHIFT_LEFT)) {
e.setCancelled(true);
return true;
}
Hopper hopper = playerData.getLastHopper();
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> {
((EHopper)hopper).compile(player);
}, 1);
if (e.getSlot() == 40) {
playerData.setSyncType(SyncType.FILTERED);
player.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.hopper.syncnext"));
((EHopper)hopper).timeout(player);
player.closeInventory();
return true;
}
int[] a = {0, 1, 9, 10, 18, 19, 27, 28, 36, 37, 45, 46, 7, 8, 16, 17, 25, 26, 34, 35, 43, 44, 52, 53};
e.setCancelled(true);
for (int aa : a) {
if (aa != e.getSlot()) continue;
String name = "";
if (e.getCurrentItem().hasItemMeta() && e.getCurrentItem().getItemMeta().hasDisplayName())
name = e.getCurrentItem().getItemMeta().getDisplayName();
if (!name.equals(instance.getLocale().getMessage("interface.filter.whitelist")) &&
!name.equals(instance.getLocale().getMessage("interface.filter.blacklist")) &&
!name.equals(instance.getLocale().getMessage("interface.filter.void"))) {
e.setCancelled(false);
return true;
}
if (e.getCursor().getType().equals(Material.AIR)) return true;
if (e.getCursor().getAmount() != 1) {
e.setCancelled(true);
player.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.hopper.onlyone"));
return true;
}
e.setCancelled(false);
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> player.setItemOnCursor(new ItemStack(Material.AIR)), 1L);
return true;
}
return true;
}
@EventHandler
public void onDrop(PlayerDropItemEvent e) {
ItemStack item = e.getItemDrop().getItemStack();
if (!item.hasItemMeta() || !item.getItemMeta().hasDisplayName()) {
return;
}
String name = item.getItemMeta().getDisplayName();
if (!name.equals(instance.getLocale().getMessage("interface.filter.whitelist")) &&
!name.equals(instance.getLocale().getMessage("interface.filter.blacklist")) &&
!name.equals(instance.getLocale().getMessage("interface.filter.void"))) {
return;
}
e.getItemDrop().remove();
}
@EventHandler
public void onClose(InventoryCloseEvent event) {
try {
PlayerData playerData = instance.getPlayerDataManager().getPlayerData((Player)event.getPlayer());
playerData.setInMenu(MenuType.NOT_IN);
if (playerData.getSyncType() == SyncType.FILTERED) {
((EHopper)playerData.getLastHopper()).compile((Player)event.getPlayer());
}
} catch (Exception e) {
Debugger.runReport(e);
}
}
}

View File

@ -1,45 +1,45 @@
package com.songoda.epichoppers.Events;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.epichoppers.EpicHoppers;
import com.songoda.epichoppers.Utils.Debugger;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
/**
* Created by songoda on 3/14/2017.
*/
public class LoginListeners implements Listener {
private EpicHoppers instance;
public LoginListeners(EpicHoppers instance) {
this.instance = instance;
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent e) {
try {
Player p = e.getPlayer();
if (p.isOp() && instance.getConfig().getBoolean("Main.Display Helpful Tips For Operators")) {
if (instance.getServer().getPluginManager().getPlugin("Factions") != null && instance.hooks.FactionsHook == null) {
p.sendMessage("");
p.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&7Here's the deal,"));
p.sendMessage(Arconix.pl().getApi().format().formatText("&7Because you're not using the official versions of &6Factions"));
p.sendMessage(Arconix.pl().getApi().format().formatText("&7I cannot give you full support out of the box."));
p.sendMessage(Arconix.pl().getApi().format().formatText("&7Things will work without it but if you wan't a flawless"));
p.sendMessage(Arconix.pl().getApi().format().formatText("&7experience you need to download"));
p.sendMessage(Arconix.pl().getApi().format().formatText("&7&6https://www.spigotmc.org/resources/54337/&7."));
p.sendMessage(Arconix.pl().getApi().format().formatText("&7If you don't care and don't want to see this message again"));
p.sendMessage(Arconix.pl().getApi().format().formatText("&7turn &6Helpful-Tips &7off in the config."));
p.sendMessage("");
}
}
} catch (Exception ee) {
Debugger.runReport(ee);
}
}
package com.songoda.epichoppers.events;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.epichoppers.EpicHoppersPlugin;
import com.songoda.epichoppers.utils.Debugger;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
/**
* Created by songoda on 3/14/2017.
*/
public class LoginListeners implements Listener {
private EpicHoppersPlugin instance;
public LoginListeners(EpicHoppersPlugin instance) {
this.instance = instance;
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent e) {
try {
Player p = e.getPlayer();
if (p.isOp() && instance.getConfig().getBoolean("Main.Display Helpful Tips For Operators")) {
if (instance.getServer().getPluginManager().getPlugin("Factions") != null && instance.hooks.FactionsHook == null) {
p.sendMessage("");
p.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&7Here's the deal,"));
p.sendMessage(Arconix.pl().getApi().format().formatText("&7Because you're not using the official versions of &6Factions"));
p.sendMessage(Arconix.pl().getApi().format().formatText("&7I cannot give you full support out of the box."));
p.sendMessage(Arconix.pl().getApi().format().formatText("&7Things will work without it but if you wan't a flawless"));
p.sendMessage(Arconix.pl().getApi().format().formatText("&7experience you need to download"));
p.sendMessage(Arconix.pl().getApi().format().formatText("&7&6https://www.spigotmc.org/resources/54337/&7."));
p.sendMessage(Arconix.pl().getApi().format().formatText("&7If you don't care and don't want to see this message again"));
p.sendMessage(Arconix.pl().getApi().format().formatText("&7turn &6Helpful-Tips &7off in the config."));
p.sendMessage("");
}
}
} catch (Exception ee) {
Debugger.runReport(ee);
}
}
}

View File

@ -1,70 +1,70 @@
package com.songoda.epichoppers.Handlers;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.epichoppers.EpicHoppers;
import com.songoda.epichoppers.Utils.Debugger;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
* Created by songoda on 3/14/2017.
*/
public class CommandHandler implements CommandExecutor {
private final EpicHoppers plugin;
public CommandHandler(final EpicHoppers plugin) {
this.plugin = plugin;
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
try {
if (args.length == 0 || args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("?")) {
sender.sendMessage("");
sender.sendMessage(Arconix.pl().getApi().format().formatText(plugin.references.getPrefix() + "&7" + plugin.getDescription().getVersion() + " Created by &5&l&oBrianna"));
sender.sendMessage(Arconix.pl().getApi().format().formatText(" &8- &aEH help &7Displays this page."));
sender.sendMessage(Arconix.pl().getApi().format().formatText(" &8- &aEH book [player] &7Gives Sync Touch book to you or a player."));
sender.sendMessage(Arconix.pl().getApi().format().formatText(" &8- &aEH settings &7Edit the EpicHoppers Settings."));
sender.sendMessage(Arconix.pl().getApi().format().formatText(" &8- &aEH reload &7Reloads Configuration and Language files."));
sender.sendMessage("");
} else if (args[0].equalsIgnoreCase("book")) {
if (!sender.hasPermission("synccraft.admin") && !sender.hasPermission("epichoppers.admin")) {
sender.sendMessage(plugin.references.getPrefix() + plugin.getLocale().getMessage("event.general.nopermission"));
} else {
if (args.length == 1) {
if (sender instanceof Player)
((Player) sender).getInventory().addItem(plugin.enchant.getbook());
} else if (Bukkit.getPlayerExact(args[1]) == null) {
sender.sendMessage(plugin.references.getPrefix() + Arconix.pl().getApi().format().formatText("&cThat username does not exist, or the user is not online!"));
} else {
Bukkit.getPlayerExact(args[1]).getInventory().addItem(plugin.enchant.getbook());
}
}
} else if (args[0].equalsIgnoreCase("reload")) {
if (!sender.hasPermission("synccraft.admin") && !sender.hasPermission("epichoppers.admin")) {
sender.sendMessage(plugin.references.getPrefix() + plugin.getLocale().getMessage("event.general.nopermission"));
} else {
plugin.reload();
sender.sendMessage(Arconix.pl().getApi().format().formatText(plugin.references.getPrefix() + "&8Configuration and Language files reloaded."));
}
} else if (sender instanceof Player) {
if (args[0].equalsIgnoreCase("settings")) {
if (!sender.hasPermission("synccraft.admin") && !sender.hasPermission("epichoppers.admin")) {
sender.sendMessage(plugin.references.getPrefix() + plugin.getLocale().getMessage("event.general.nopermission"));
} else {
Player p = (Player) sender;
plugin.sm.openSettingsManager(p);
}
}
}
} catch (Exception e) {
Debugger.runReport(e);
}
return true;
}
package com.songoda.epichoppers.handlers;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.epichoppers.EpicHoppersPlugin;
import com.songoda.epichoppers.utils.Debugger;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
* Created by songoda on 3/14/2017.
*/
public class CommandHandler implements CommandExecutor {
private final EpicHoppersPlugin plugin;
public CommandHandler(final EpicHoppersPlugin plugin) {
this.plugin = plugin;
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
try {
if (args.length == 0 || args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("?")) {
sender.sendMessage("");
sender.sendMessage(Arconix.pl().getApi().format().formatText(plugin.references.getPrefix() + "&7" + plugin.getDescription().getVersion() + " Created by &5&l&oBrianna"));
sender.sendMessage(Arconix.pl().getApi().format().formatText(" &8- &aEH help &7Displays this page."));
sender.sendMessage(Arconix.pl().getApi().format().formatText(" &8- &aEH book [player] &7Gives Sync Touch book to you or a player."));
sender.sendMessage(Arconix.pl().getApi().format().formatText(" &8- &aEH settings &7Edit the EpicHoppers Settings."));
sender.sendMessage(Arconix.pl().getApi().format().formatText(" &8- &aEH reload &7Reloads Configuration and Language files."));
sender.sendMessage("");
} else if (args[0].equalsIgnoreCase("book")) {
if (!sender.hasPermission("synccraft.admin") && !sender.hasPermission("epichoppers.admin")) {
sender.sendMessage(plugin.references.getPrefix() + plugin.getLocale().getMessage("event.general.nopermission"));
} else {
if (args.length == 1) {
if (sender instanceof Player)
((Player) sender).getInventory().addItem(plugin.enchantmentHandler.getbook());
} else if (Bukkit.getPlayerExact(args[1]) == null) {
sender.sendMessage(plugin.references.getPrefix() + Arconix.pl().getApi().format().formatText("&cThat username does not exist, or the user is not online!"));
} else {
Bukkit.getPlayerExact(args[1]).getInventory().addItem(plugin.enchantmentHandler.getbook());
}
}
} else if (args[0].equalsIgnoreCase("reload")) {
if (!sender.hasPermission("synccraft.admin") && !sender.hasPermission("epichoppers.admin")) {
sender.sendMessage(plugin.references.getPrefix() + plugin.getLocale().getMessage("event.general.nopermission"));
} else {
plugin.reload();
sender.sendMessage(Arconix.pl().getApi().format().formatText(plugin.references.getPrefix() + "&8Configuration and Language files reloaded."));
}
} else if (sender instanceof Player) {
if (args[0].equalsIgnoreCase("settings")) {
if (!sender.hasPermission("synccraft.admin") && !sender.hasPermission("epichoppers.admin")) {
sender.sendMessage(plugin.references.getPrefix() + plugin.getLocale().getMessage("event.general.nopermission"));
} else {
Player p = (Player) sender;
plugin.settingsManager.openSettingsManager(p);
}
}
}
} catch (Exception e) {
Debugger.runReport(e);
}
return true;
}
}

View File

@ -1,83 +1,83 @@
package com.songoda.epichoppers.Handlers;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.epichoppers.EpicHoppers;
import com.songoda.epichoppers.Utils.Debugger;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
/**
* Created by songoda on 3/22/2017.
*/
public class EnchantmentHandler {
private EpicHoppers instance;
public EnchantmentHandler(EpicHoppers instance) {
this.instance = instance;
}
public EnchantmentHandler() {
}
public ItemStack createSyncTouch(ItemStack item, Block b) {
try {
ItemMeta itemmeta = item.getItemMeta();
ArrayList<String> lore = new ArrayList<String>();
if (b != null) {
lore.add(Arconix.pl().getApi().format().formatText("&aSync Touch"));
lore.add(Arconix.pl().getApi().format().convertToInvisibleString(Arconix.pl().getApi().serialize().serializeLocation(b)));
} else {
lore.add(Arconix.pl().getApi().format().formatText("&7Sync Touch"));
}
itemmeta.setLore(lore);
item.setItemMeta(itemmeta);
return item;
} catch (Exception e) {
Debugger.runReport(e);
}
return null;
}
public void giveSyncTouchBook(Player p) {
try {
boolean isEmpty = false;
for (ItemStack item : p.getInventory().getContents()) {
if (item == null) {
isEmpty = true;
}
}
if (!isEmpty) {
p.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.inventory.noroom"));
} else {
ItemStack book = getbook();
p.getInventory().addItem(book);
}
} catch (Exception e) {
Debugger.runReport(e);
}
}
public ItemStack getbook() {
try {
ItemStack book = new ItemStack(Material.ENCHANTED_BOOK);
ItemMeta meta = book.getItemMeta();
meta.setDisplayName(Arconix.pl().getApi().format().formatText("&eEnchanted Book"));
ArrayList<String> lore = new ArrayList<>();
lore.add(Arconix.pl().getApi().format().formatText("&7Sync Touch"));
meta.setLore(lore);
book.setItemMeta(meta);
return book;
} catch (Exception e) {
Debugger.runReport(e);
}
return null;
}
package com.songoda.epichoppers.handlers;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.epichoppers.EpicHoppersPlugin;
import com.songoda.epichoppers.utils.Debugger;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
/**
* Created by songoda on 3/22/2017.
*/
public class EnchantmentHandler {
private EpicHoppersPlugin instance;
public EnchantmentHandler(EpicHoppersPlugin instance) {
this.instance = instance;
}
public EnchantmentHandler() {
}
public ItemStack createSyncTouch(ItemStack item, Block b) {
try {
ItemMeta itemmeta = item.getItemMeta();
ArrayList<String> lore = new ArrayList<String>();
if (b != null) {
lore.add(Arconix.pl().getApi().format().formatText("&aSync Touch"));
lore.add(Arconix.pl().getApi().format().convertToInvisibleString(Arconix.pl().getApi().serialize().serializeLocation(b)));
} else {
lore.add(Arconix.pl().getApi().format().formatText("&7Sync Touch"));
}
itemmeta.setLore(lore);
item.setItemMeta(itemmeta);
return item;
} catch (Exception e) {
Debugger.runReport(e);
}
return null;
}
public void giveSyncTouchBook(Player p) {
try {
boolean isEmpty = false;
for (ItemStack item : p.getInventory().getContents()) {
if (item == null) {
isEmpty = true;
}
}
if (!isEmpty) {
p.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.inventory.noroom"));
} else {
ItemStack book = getbook();
p.getInventory().addItem(book);
}
} catch (Exception e) {
Debugger.runReport(e);
}
}
public ItemStack getbook() {
try {
ItemStack book = new ItemStack(Material.ENCHANTED_BOOK);
ItemMeta meta = book.getItemMeta();
meta.setDisplayName(Arconix.pl().getApi().format().formatText("&eEnchanted Book"));
ArrayList<String> lore = new ArrayList<>();
lore.add(Arconix.pl().getApi().format().formatText("&7Sync Touch"));
meta.setLore(lore);
book.setItemMeta(meta);
return book;
} catch (Exception e) {
Debugger.runReport(e);
}
return null;
}
}

View File

@ -1,114 +1,114 @@
package com.songoda.epichoppers.Handlers;
import com.songoda.arconix.api.utils.ConfigWrapper;
import com.songoda.epichoppers.EpicHoppers;
import com.songoda.epichoppers.Hooks.*;
import com.songoda.epichoppers.Utils.Debugger;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
/**
* Created by songoda on 3/17/2017.
*/
public class HookHandler {
public Hook FactionsHook = null, RedProtectHook = null, ASkyBlockHook = null, USkyBlockHook = null,
WorldGuardHook = null, GriefPreventionHook = null, PlotSquaredHook = null, KingdomsHook = null,
TownyHook = null;
public ConfigWrapper hooksFile = new ConfigWrapper(EpicHoppers.getInstance(), "", "hooks.yml");
public HookHandler() {
}
public void hook() {
try {
hooksFile.createNewFile("Loading hooks File", EpicHoppers.getInstance().getDescription().getName() + " hooks File");
new FactionsHook();
new RedProtectHook();
new GriefPreventionHook();
new ASkyBlockHook();
new USkyBlockHook();
new WorldGuardHook();
new PlotSquaredHook();
new KingdomsHook();
new TownyHook();
hooksFile.getConfig().options().copyDefaults(true);
hooksFile.saveConfig();
} catch (Exception e) {
Debugger.runReport(e);
}
}
public boolean isInFaction(String name, Location l) {
if (FactionsHook != null) {
return FactionsHook.isInClaim(name, l);
}
return false;
}
public String getFactionId(String name) {
if (FactionsHook != null) {
return FactionsHook.getClaimId(name);
}
return null;
}
public boolean isInTown(String name, Location l) {
if (TownyHook != null) {
return TownyHook.isInClaim(name, l);
}
return false;
}
public String getTownId(String name) {
if (TownyHook != null) {
return TownyHook.getClaimId(name);
}
return null;
}
public boolean isInIsland(String name, Location l) {
if (USkyBlockHook != null)
return USkyBlockHook.isInClaim(name, l);
else if (ASkyBlockHook != null)
return ASkyBlockHook.isInClaim(name, l);
else
return false;
}
public String getIslandId(String name) {
try {
return Bukkit.getOfflinePlayer(name).getUniqueId().toString();
} catch (Exception ignore) {
}
return null;
}
public boolean canBuild(Player p, Location l) {
boolean result = true;
if (WorldGuardHook != null)
result = WorldGuardHook.canBuild(p, l);
if (RedProtectHook != null && result)
result = RedProtectHook.canBuild(p, l);
if (FactionsHook != null && result)
result = FactionsHook.canBuild(p, l);
if (ASkyBlockHook != null && result)
result = ASkyBlockHook.canBuild(p, l);
if (USkyBlockHook != null && result)
result = USkyBlockHook.canBuild(p, l);
if (GriefPreventionHook != null && result)
result = GriefPreventionHook.canBuild(p, l);
if (PlotSquaredHook != null && result)
result = PlotSquaredHook.canBuild(p, l);
if (KingdomsHook != null && result)
result = KingdomsHook.canBuild(p, l);
if (TownyHook != null && result)
result = TownyHook.canBuild(p, l);
return result;
}
package com.songoda.epichoppers.handlers;
import com.songoda.arconix.api.utils.ConfigWrapper;
import com.songoda.epichoppers.EpicHoppersPlugin;
import com.songoda.epichoppers.hooks.*;
import com.songoda.epichoppers.utils.Debugger;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
/**
* Created by songoda on 3/17/2017.
*/
public class HookHandler {
public Hook FactionsHook = null, RedProtectHook = null, ASkyBlockHook = null, USkyBlockHook = null,
WorldGuardHook = null, GriefPreventionHook = null, PlotSquaredHook = null, KingdomsHook = null,
TownyHook = null;
public ConfigWrapper hooksFile = new ConfigWrapper(EpicHoppersPlugin.getInstance(), "", "hooks.yml");
public HookHandler() {
}
public void hook() {
try {
hooksFile.createNewFile("Loading hooks File", EpicHoppersPlugin.getInstance().getDescription().getName() + " hooks File");
new FactionsHook();
new RedProtectHook();
new GriefPreventionHook();
new ASkyBlockHook();
new USkyBlockHook();
new WorldGuardHook();
new PlotSquaredHook();
new KingdomsHook();
new TownyHook();
hooksFile.getConfig().options().copyDefaults(true);
hooksFile.saveConfig();
} catch (Exception e) {
Debugger.runReport(e);
}
}
public boolean isInFaction(String name, Location l) {
if (FactionsHook != null) {
return FactionsHook.isInClaim(name, l);
}
return false;
}
public String getFactionId(String name) {
if (FactionsHook != null) {
return FactionsHook.getClaimId(name);
}
return null;
}
public boolean isInTown(String name, Location l) {
if (TownyHook != null) {
return TownyHook.isInClaim(name, l);
}
return false;
}
public String getTownId(String name) {
if (TownyHook != null) {
return TownyHook.getClaimId(name);
}
return null;
}
public boolean isInIsland(String name, Location l) {
if (USkyBlockHook != null)
return USkyBlockHook.isInClaim(name, l);
else if (ASkyBlockHook != null)
return ASkyBlockHook.isInClaim(name, l);
else
return false;
}
public String getIslandId(String name) {
try {
return Bukkit.getOfflinePlayer(name).getUniqueId().toString();
} catch (Exception ignore) {
}
return null;
}
public boolean canBuild(Player p, Location l) {
boolean result = true;
if (WorldGuardHook != null)
result = WorldGuardHook.canBuild(p, l);
if (RedProtectHook != null && result)
result = RedProtectHook.canBuild(p, l);
if (FactionsHook != null && result)
result = FactionsHook.canBuild(p, l);
if (ASkyBlockHook != null && result)
result = ASkyBlockHook.canBuild(p, l);
if (USkyBlockHook != null && result)
result = USkyBlockHook.canBuild(p, l);
if (GriefPreventionHook != null && result)
result = GriefPreventionHook.canBuild(p, l);
if (PlotSquaredHook != null && result)
result = PlotSquaredHook.canBuild(p, l);
if (KingdomsHook != null && result)
result = KingdomsHook.canBuild(p, l);
if (TownyHook != null && result)
result = TownyHook.canBuild(p, l);
return result;
}
}

View File

@ -1,344 +1,344 @@
package com.songoda.epichoppers.Handlers;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.epichoppers.EpicHoppers;
import com.songoda.epichoppers.Utils.Debugger;
import com.songoda.epichoppers.Utils.Methods;
import org.apache.commons.lang.StringUtils;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.block.Hopper;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item;
import org.bukkit.inventory.FurnaceInventory;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import java.util.*;
/**
* Created by songoda on 3/14/2017.
*/
public class HopHandler {
private EpicHoppers instance;
public HopHandler(EpicHoppers instance) {
try {
this.instance = instance;
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> {
hopperCleaner();
Bukkit.getScheduler().scheduleSyncRepeatingTask(instance, this::hopperRunner, 0, instance.getConfig().getLong("Main.Amount of Ticks Between Hops"));
}, 40L);
} catch (Exception e) {
Debugger.runReport(e);
}
}
private void hopperCleaner() {
try {
if (instance.dataFile.getConfig().contains("data.sync")) {
ConfigurationSection cs = instance.dataFile.getConfig().getConfigurationSection("data.sync");
for (String key : cs.getKeys(false)) {
if (Arconix.pl().getApi().serialize().unserializeLocation(key).getWorld() != null) {
Block b = Arconix.pl().getApi().serialize().unserializeLocation(key).getBlock();
if (b == null || !(b.getState() instanceof Hopper)) {
instance.dataFile.getConfig().getConfigurationSection("data.sync").set(key, null);
instance.getLogger().info("EpicHoppers Removing non-hopper entry: " + key);
}
}
}
}
} catch (Exception e) {
Debugger.runReport(e);
}
}
public Map<Block, Integer> blockTick = new HashMap<>();
private void hopperRunner() {
try {
Set<Entity> metaItems = new HashSet<>();
for (com.songoda.epichoppers.Hopper.Hopper hopper : instance.getHopperManager().getHoppers().values()) {
Location location = hopper.getLocation();
int x = location.getBlockX() >> 4;
int z = location.getBlockZ() >> 4;
try {
if (!location.getWorld().isChunkLoaded(x, z)) {
continue;
}
} catch (Exception e) {
continue;
}
Block block = location.getBlock();
if (block == null || !(block.getState() instanceof Hopper)) {
instance.getHopperManager().removeHopper(location);
instance.getLogger().info("EpicHoppers Removing non-hopper entry: " + location.toString());
}
org.bukkit.block.Hopper hopperBlock = (org.bukkit.block.Hopper) (block != null ? block.getState() : null);
if (hopper.getLevel().getBlockBreak() != 0) {
int amt = hopper.getLevel().getBlockBreak();
if (!blockTick.containsKey(block)) {
blockTick.put(block, 1);
} else {
int tick = blockTick.get(block);
int put = tick + 1;
blockTick.put(block, put);
if (tick >= amt) {
Block above = block.getRelative(0, 1, 0);
if (above.getType() != Material.AIR && !instance.getConfig().getStringList("Main.BlockBreak Blacklisted Blocks").contains(above.getType().name())) {
above.getWorld().playSound(above.getLocation(), Sound.BLOCK_STONE_BREAK, 1F, 1F);
Location locationAbove = above.getLocation();
locationAbove.add(.5, .5, .5);
float ox = (float) (0 + (Math.random() * .5));
float oy = (float) (0 + (Math.random() * .5));
float oz = (float) (0 + (Math.random() * .5));
Arconix.pl().getApi().packetLibrary.getParticleManager().broadcastParticle(locationAbove, ox, oy, oz, 0, instance.getConfig().getString("Main.BlockBreak Particle Type"), 15);
above.breakNaturally();
}
blockTick.remove(block);
}
}
}
if (hopper.getLevel().getSuction() != 0) {
int suck = hopper.getLevel().getSuction();
double radius = suck + .5;
Collection<Entity> nearbyEntite = block.getLocation().getWorld().getNearbyEntities(block.getLocation().add(0.5, 0.5, 0.5), radius, radius, radius);
for (Entity e : nearbyEntite) {
if (!(e instanceof Item) || e.getTicksLived() < 10 || e.getLocation().getBlock().getType() == Material.HOPPER) {
continue;
}
ItemStack hopItem = ((Item) e).getItemStack().clone();
if (hopItem.getType().name().contains("SHULKER_BOX"))
continue;
if (hopItem.hasItemMeta() && hopItem.getItemMeta().hasDisplayName() &&
StringUtils.substring(hopItem.getItemMeta().getDisplayName(), 0, 3).equals("***")) {
continue; //Compatibility with Shop instance: https://www.spigotmc.org/resources/shop-a-simple-intuitive-shop-instance.9628/
}
if (e.hasMetadata("grabbed"))
continue;
ItemStack item = ((Item) e).getItemStack();
if (!canHop(hopperBlock.getInventory(), item, 1)) {
continue;
}
((Item) e).setPickupDelay(999);
e.setMetadata("grabbed", new FixedMetadataValue(instance, ""));
metaItems.add(e);
if (!e.isOnGround())
continue;
float xx = (float) (0 + (Math.random() * .3));
float yy = (float) (0 + (Math.random() * .3));
float zz = (float) (0 + (Math.random() * .3));
Arconix.pl().getApi().packetLibrary.getParticleManager().broadcastParticle(e.getLocation(), xx, yy, zz, 0, "FLAME", 5);
e.remove();
hopperBlock.getInventory().addItem(hopItem);
break;
}
}
if (hopper.getSyncedBlock() == null) continue;
Location dest = hopper.getSyncedBlock().getLocation();
if (dest == null) {
hopper.setSyncedBlock(null);
continue;
}
int destx = location.getBlockX() >> 4;
int destz = location.getBlockZ() >> 4;
if (!dest.getWorld().isChunkLoaded(destx, destz)) {
continue;
}
Block b2 = dest.getBlock();
if (!b2.getType().equals(Material.HOPPER) && !b2.getType().equals(Material.CHEST) && !b2.getType().equals(Material.TRAPPED_CHEST) && !(b2.getType().equals(Material.ENDER_CHEST))) {
hopper.setSyncedBlock(null);
continue;
}
int amt = hopper.getLevel().getAmount();
ItemStack[] is = hopperBlock.getInventory().getContents();
List<ItemStack> whiteList = hopper.getFilter().getWhiteList();
List<ItemStack> blackList = hopper.getFilter().getBlackList();
int num = 0;
while (num != 5) {
ItemStack it = null;
if (is[num] != null) {
it = is[num].clone();
it.setAmount(1);
}
if (is[num] != null
&& !whiteList.isEmpty()
&& !whiteList.contains(it)) {
doBlacklist(hopperBlock, hopper, is[num].clone(), is, amt, num);
} else if (is[num] != null && !blackList.contains(it)) {
int numm = addItem(hopperBlock, hopper, b2, is[num], is, amt, num);
if (numm != 10)
num = numm;
} else if (is[num] != null && blackList.contains(it)) {
doBlacklist(hopperBlock, hopper, is[num].clone(), is, amt, num);
}
num++;
}
}
} catch (Exception e) {
Debugger.runReport(e);
}
}
private void doBlacklist(Hopper hopperBlock, com.songoda.epichoppers.Hopper.Hopper hopper, ItemStack item, ItemStack[] isS, int amt, int place) {
try {
Location loc = hopperBlock.getLocation();
Block b = loc.getBlock();
if (hopper.getFilter().getEndPoint() != null
&& b != null && b.getState() instanceof Hopper) {
Location dest = hopper.getFilter().getEndPoint().getLocation();
int destx = loc.getBlockX() >> 4;
int destz = loc.getBlockZ() >> 4;
if (!dest.getWorld().isChunkLoaded(destx, destz)) {
return;
}
Block b2 = dest.getBlock();
addItem(hopperBlock, hopper, b2, item, isS, amt, place);
}
} catch (Exception e) {
Debugger.runReport(e);
}
}
private int addItem(Hopper hopperBlock, com.songoda.epichoppers.Hopper.Hopper hopper, Block b2, ItemStack is, ItemStack[] isS, int amt, int place) {
try {
ItemStack it = null;
if (is != null) {
it = is.clone();
it.setAmount(1);
}
List<Material> ovoid = new ArrayList<>();
for (ItemStack iss : hopper.getFilter().getVoidList()) {
ovoid.add(iss.getType());
}
if (is.getType() == Material.AIR) {
return 10;
}
ItemStack item = is;
ItemStack newItem = is.clone();
if ((item.getAmount() - amt) <= 0) {
amt = item.getAmount();
}
if ((item.getAmount() - amt) >= 1) {
newItem.setAmount(newItem.getAmount() - amt);
is = newItem.clone();
} else {
is = null;
}
newItem.setAmount(amt);
InventoryHolder ih = null;
if (!b2.getType().equals(Material.ENDER_CHEST)) {
ih = (InventoryHolder) b2.getState();
}
if (b2.getType().equals(Material.ENDER_CHEST)) {
try {
OfflinePlayer op = Bukkit.getOfflinePlayer(UUID.fromString(instance.dataFile.getConfig().getString("data.enderTracker." + Arconix.pl().getApi().serialize().serializeLocation(b2))));
if (op.isOnline() && canHop(op.getPlayer().getEnderChest(), newItem, amt)) {
if (!ovoid.contains(it.getType())) {
op.getPlayer().getEnderChest().addItem(newItem);
}
isS[place] = is;
hopperBlock.getInventory().setContents(isS);
}
} catch (Exception ignore) {
}
} else {
if (!canHop(ih.getInventory(), newItem, amt) || b2.getType() == Material.BREWING_STAND) {
return 4;
}
if (b2.getType() == Material.FURNACE) {
FurnaceInventory fi = (FurnaceInventory) ih.getInventory();
int amtt = 0;
boolean dont = false;
if (fi.getSmelting() != null) {
amtt = fi.getSmelting().getAmount();
if (fi.getSmelting().getType() != newItem.getType()) {
dont = true;
} else {
if (fi.getSmelting().getAmount() == fi.getSmelting().getMaxStackSize()) {
dont = true;
}
}
}
if (!dont) {
if (amtt + newItem.getAmount() <= 64) {
if (!ovoid.contains(it.getType())) {
ih.getInventory().addItem(newItem);
}
isS[place] = is;
hopperBlock.getInventory().setContents(isS);
}
}
} else {
if (!ovoid.contains(it.getType())) {
ih.getInventory().addItem(newItem);
}
isS[place] = is;
hopperBlock.getInventory().setContents(isS);
}
}
return 4;
} catch (Exception e) {
Debugger.runReport(e);
}
return 0;
}
public boolean canHop(Inventory i, ItemStack item, int hop) {
try {
if (i.firstEmpty() != -1) {
return true;
}
boolean can = false;
for (ItemStack it : i.getContents()) {
if (it == null) {
can = true;
break;
} else {
if (it.isSimilar(item)) {
if ((it.getAmount() + hop) <= it.getMaxStackSize()) {
can = true;
break;
}
}
}
}
return can;
} catch (Exception e) {
Debugger.runReport(e);
}
return false;
}
package com.songoda.epichoppers.handlers;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.epichoppers.EpicHoppersPlugin;
import com.songoda.epichoppers.hopper.EHopper;
import com.songoda.epichoppers.utils.Debugger;
import org.apache.commons.lang.StringUtils;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.block.Hopper;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item;
import org.bukkit.inventory.FurnaceInventory;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import java.util.*;
/**
* Created by songoda on 3/14/2017.
*/
public class HopHandler {
private EpicHoppersPlugin instance;
public HopHandler(EpicHoppersPlugin instance) {
try {
this.instance = instance;
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> {
hopperCleaner();
Bukkit.getScheduler().scheduleSyncRepeatingTask(instance, this::hopperRunner, 0, instance.getConfig().getLong("Main.Amount of Ticks Between Hops"));
}, 40L);
} catch (Exception e) {
Debugger.runReport(e);
}
}
private void hopperCleaner() {
try {
if (instance.dataFile.getConfig().contains("data.sync")) {
ConfigurationSection cs = instance.dataFile.getConfig().getConfigurationSection("data.sync");
for (String key : cs.getKeys(false)) {
if (Arconix.pl().getApi().serialize().unserializeLocation(key).getWorld() != null) {
Block b = Arconix.pl().getApi().serialize().unserializeLocation(key).getBlock();
if (b == null || !(b.getState() instanceof Hopper)) {
instance.dataFile.getConfig().getConfigurationSection("data.sync").set(key, null);
instance.getLogger().info("EpicHoppers Removing non-hopper entry: " + key);
}
}
}
}
} catch (Exception e) {
Debugger.runReport(e);
}
}
public Map<Block, Integer> blockTick = new HashMap<>();
private void hopperRunner() {
try {
Set<Entity> metaItems = new HashSet<>();
for (com.songoda.epichoppers.api.hopper.Hopper hopper : instance.getHopperManager().getHoppers().values()) {
Location location = hopper.getLocation();
int x = location.getBlockX() >> 4;
int z = location.getBlockZ() >> 4;
try {
if (!location.getWorld().isChunkLoaded(x, z)) {
continue;
}
} catch (Exception e) {
continue;
}
Block block = location.getBlock();
if (block == null || !(block.getState() instanceof Hopper)) {
instance.getHopperManager().removeHopper(location);
instance.getLogger().info("EpicHoppers Removing non-hopper entry: " + location.toString());
}
org.bukkit.block.Hopper hopperBlock = (org.bukkit.block.Hopper) (block != null ? block.getState() : null);
if (hopper.getLevel().getBlockBreak() != 0) {
int amt = hopper.getLevel().getBlockBreak();
if (!blockTick.containsKey(block)) {
blockTick.put(block, 1);
} else {
int tick = blockTick.get(block);
int put = tick + 1;
blockTick.put(block, put);
if (tick >= amt) {
Block above = block.getRelative(0, 1, 0);
if (above.getType() != Material.AIR && !instance.getConfig().getStringList("Main.BlockBreak Blacklisted Blocks").contains(above.getType().name())) {
above.getWorld().playSound(above.getLocation(), Sound.BLOCK_STONE_BREAK, 1F, 1F);
Location locationAbove = above.getLocation();
locationAbove.add(.5, .5, .5);
float ox = (float) (0 + (Math.random() * .5));
float oy = (float) (0 + (Math.random() * .5));
float oz = (float) (0 + (Math.random() * .5));
Arconix.pl().getApi().packetLibrary.getParticleManager().broadcastParticle(locationAbove, ox, oy, oz, 0, instance.getConfig().getString("Main.BlockBreak Particle Type"), 15);
above.breakNaturally();
}
blockTick.remove(block);
}
}
}
if (hopper.getLevel().getSuction() != 0) {
int suck = hopper.getLevel().getSuction();
double radius = suck + .5;
Collection<Entity> nearbyEntite = block.getLocation().getWorld().getNearbyEntities(block.getLocation().add(0.5, 0.5, 0.5), radius, radius, radius);
for (Entity e : nearbyEntite) {
if (!(e instanceof Item) || e.getTicksLived() < 10 || e.getLocation().getBlock().getType() == Material.HOPPER) {
continue;
}
ItemStack hopItem = ((Item) e).getItemStack().clone();
if (hopItem.getType().name().contains("SHULKER_BOX"))
continue;
if (hopItem.hasItemMeta() && hopItem.getItemMeta().hasDisplayName() &&
StringUtils.substring(hopItem.getItemMeta().getDisplayName(), 0, 3).equals("***")) {
continue; //Compatibility with Shop instance: https://www.spigotmc.org/resources/shop-a-simple-intuitive-shop-instance.9628/
}
if (e.hasMetadata("grabbed"))
continue;
ItemStack item = ((Item) e).getItemStack();
if (!canHop(hopperBlock.getInventory(), item, 1)) {
continue;
}
((Item) e).setPickupDelay(999);
e.setMetadata("grabbed", new FixedMetadataValue(instance, ""));
metaItems.add(e);
if (!e.isOnGround())
continue;
float xx = (float) (0 + (Math.random() * .3));
float yy = (float) (0 + (Math.random() * .3));
float zz = (float) (0 + (Math.random() * .3));
Arconix.pl().getApi().packetLibrary.getParticleManager().broadcastParticle(e.getLocation(), xx, yy, zz, 0, "FLAME", 5);
e.remove();
hopperBlock.getInventory().addItem(hopItem);
break;
}
}
if (hopper.getSyncedBlock() == null) continue;
Location dest = hopper.getSyncedBlock().getLocation();
if (dest == null) {
hopper.setSyncedBlock(null);
continue;
}
int destx = location.getBlockX() >> 4;
int destz = location.getBlockZ() >> 4;
if (!dest.getWorld().isChunkLoaded(destx, destz)) {
continue;
}
Block b2 = dest.getBlock();
if (!b2.getType().equals(Material.HOPPER) && !b2.getType().equals(Material.CHEST) && !b2.getType().equals(Material.TRAPPED_CHEST) && !(b2.getType().equals(Material.ENDER_CHEST))) {
hopper.setSyncedBlock(null);
continue;
}
int amt = hopper.getLevel().getAmount();
ItemStack[] is = hopperBlock.getInventory().getContents();
List<ItemStack> whiteList = hopper.getFilter().getWhiteList();
List<ItemStack> blackList = hopper.getFilter().getBlackList();
int num = 0;
while (num != 5) {
ItemStack it = null;
if (is[num] != null) {
it = is[num].clone();
it.setAmount(1);
}
if (is[num] != null
&& !whiteList.isEmpty()
&& !whiteList.contains(it)) {
doBlacklist(hopperBlock, hopper, is[num].clone(), is, amt, num);
} else if (is[num] != null && !blackList.contains(it)) {
int numm = addItem(hopperBlock, hopper, b2, is[num], is, amt, num);
if (numm != 10)
num = numm;
} else if (is[num] != null && blackList.contains(it)) {
doBlacklist(hopperBlock, hopper, is[num].clone(), is, amt, num);
}
num++;
}
}
} catch (Exception e) {
Debugger.runReport(e);
}
}
private void doBlacklist(Hopper hopperBlock, com.songoda.epichoppers.api.hopper.Hopper hopper, ItemStack item, ItemStack[] isS, int amt, int place) {
try {
Location loc = hopperBlock.getLocation();
Block b = loc.getBlock();
if (hopper.getFilter().getEndPoint() != null
&& b != null && b.getState() instanceof Hopper) {
Location dest = hopper.getFilter().getEndPoint().getLocation();
int destx = loc.getBlockX() >> 4;
int destz = loc.getBlockZ() >> 4;
if (!dest.getWorld().isChunkLoaded(destx, destz)) {
return;
}
Block b2 = dest.getBlock();
addItem(hopperBlock, hopper, b2, item, isS, amt, place);
}
} catch (Exception e) {
Debugger.runReport(e);
}
}
private int addItem(Hopper hopperBlock, com.songoda.epichoppers.api.hopper.Hopper hopper, Block b2, ItemStack is, ItemStack[] isS, int amt, int place) {
try {
ItemStack it = null;
if (is != null) {
it = is.clone();
it.setAmount(1);
}
List<Material> ovoid = new ArrayList<>();
for (ItemStack iss : hopper.getFilter().getVoidList()) {
ovoid.add(iss.getType());
}
if (is.getType() == Material.AIR) {
return 10;
}
ItemStack item = is;
ItemStack newItem = is.clone();
if ((item.getAmount() - amt) <= 0) {
amt = item.getAmount();
}
if ((item.getAmount() - amt) >= 1) {
newItem.setAmount(newItem.getAmount() - amt);
is = newItem.clone();
} else {
is = null;
}
newItem.setAmount(amt);
InventoryHolder ih = null;
if (!b2.getType().equals(Material.ENDER_CHEST)) {
ih = (InventoryHolder) b2.getState();
}
if (b2.getType().equals(Material.ENDER_CHEST)) {
try {
OfflinePlayer op = Bukkit.getOfflinePlayer(UUID.fromString(instance.dataFile.getConfig().getString("data.enderTracker." + Arconix.pl().getApi().serialize().serializeLocation(b2))));
if (op.isOnline() && canHop(op.getPlayer().getEnderChest(), newItem, amt)) {
if (!ovoid.contains(it.getType())) {
op.getPlayer().getEnderChest().addItem(newItem);
}
isS[place] = is;
hopperBlock.getInventory().setContents(isS);
}
} catch (Exception ignore) {
}
} else {
if (!canHop(ih.getInventory(), newItem, amt) || b2.getType() == Material.BREWING_STAND) {
return 4;
}
if (b2.getType() == Material.FURNACE) {
FurnaceInventory fi = (FurnaceInventory) ih.getInventory();
int amtt = 0;
boolean dont = false;
if (fi.getSmelting() != null) {
amtt = fi.getSmelting().getAmount();
if (fi.getSmelting().getType() != newItem.getType()) {
dont = true;
} else {
if (fi.getSmelting().getAmount() == fi.getSmelting().getMaxStackSize()) {
dont = true;
}
}
}
if (!dont) {
if (amtt + newItem.getAmount() <= 64) {
if (!ovoid.contains(it.getType())) {
ih.getInventory().addItem(newItem);
}
isS[place] = is;
hopperBlock.getInventory().setContents(isS);
}
}
} else {
if (!ovoid.contains(it.getType())) {
ih.getInventory().addItem(newItem);
}
isS[place] = is;
hopperBlock.getInventory().setContents(isS);
}
}
return 4;
} catch (Exception e) {
Debugger.runReport(e);
}
return 0;
}
public boolean canHop(Inventory i, ItemStack item, int hop) {
try {
if (i.firstEmpty() != -1) {
return true;
}
boolean can = false;
for (ItemStack it : i.getContents()) {
if (it == null) {
can = true;
break;
} else {
if (it.isSimilar(item)) {
if ((it.getAmount() + hop) <= it.getMaxStackSize()) {
can = true;
break;
}
}
}
}
return can;
} catch (Exception e) {
Debugger.runReport(e);
}
return false;
}
}

View File

@ -1,109 +1,113 @@
package com.songoda.epichoppers.Handlers;
import com.songoda.epichoppers.EpicHoppers;
import com.songoda.epichoppers.Hopper.Hopper;
import com.songoda.epichoppers.Utils.Debugger;
import com.songoda.epichoppers.Utils.Methods;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
public class TeleportHandler {
//Teleport from - teleport 2
private final Map<Location, Location> teleportFrom = new HashMap<>();
private EpicHoppers instance;
public TeleportHandler(EpicHoppers instance) {
try {
this.instance = instance;
Bukkit.getScheduler().scheduleSyncRepeatingTask(instance, this::teleportRunner, 0, instance.getConfig().getLong("Main.Amount of Ticks Between Teleport"));
} catch (Exception e) {
Debugger.runReport(e);
}
}
private void teleportRunner() {
for (Player player : Bukkit.getOnlinePlayers()) {
if (!instance.getConfig().getBoolean("Main.Allow Players To Teleport Through Hoppers") || !player.hasPermission("EpicHoppers.Teleport")) {
continue;
}
Location location = player.getLocation().getBlock().getRelative(BlockFace.DOWN).getLocation();
if (!instance.getHopperManager().isHopper(location)) {
continue;
}
Hopper hopper = instance.getHopperManager().getHopper(location);
if (!hopper.isWalkOnTeleport()) continue;
if (instance.lastTp.containsKey(player)) {
long duration = (new Date()).getTime() - instance.lastTp.get(player).getTime();
if (duration <= 5 * 1000) {
continue;
}
}
tpPlayer(player, hopper);
instance.lastTp.put(player, new Date());
}
}
public void tpPlayer(Player player, Hopper hopper) {
try {
EpicHoppers instance = EpicHoppers.getInstance();
Block next = hopper.getLocation().getBlock();
int num = 1;
while (instance.getHopperManager().isHopper(next.getLocation()) && instance.getHopperManager().getHopper(next.getLocation()).getSyncedBlock() != null && num != 15) {
Hopper nextHopper = instance.getHopperManager().getHopper(next);
if (nextHopper.getSyncedBlock() != null) {
next = nextHopper.getSyncedBlock();
}
if (!next.getType().equals(Material.HOPPER)) {
instance.getHopperManager().removeHopper(nextHopper.getLocation());
break;
}
Location location = next.getLocation();
location.setX(location.getX() + 0.5);
location.setZ(location.getZ() + 0.5);
location.setY(location.getY() + 1);
location.setPitch(player.getLocation().getPitch());
location.setDirection(player.getLocation().getDirection());
player.teleport(location);
next = player.getLocation().subtract(0, 0.5, 0).getBlock();
num++;
}
if (num == 1 && teleportFrom.containsKey(hopper.getLocation())) {
Location location = teleportFrom.get(hopper.getLocation());
location.setX(location.getX() + 0.5);
location.setZ(location.getZ() + 0.5);
location.setY(location.getY() + 1);
location.setPitch(player.getLocation().getPitch());
location.setDirection(player.getLocation().getDirection());
player.teleport(location);
next = player.getLocation().subtract(0, 0.5, 0).getBlock();
num ++;
}
if (num != 1) {
teleportFrom.put(next.getLocation(), hopper.getLocation());
Methods.doParticles(player, hopper.getLocation());
Methods.doParticles(player, next.getLocation());
}
} catch (Exception e) {
Debugger.runReport(e);
}
}
}
package com.songoda.epichoppers.handlers;
import com.songoda.epichoppers.EpicHoppersPlugin;
import com.songoda.epichoppers.api.hopper.Hopper;
import com.songoda.epichoppers.hopper.EHopper;
import com.songoda.epichoppers.player.PlayerData;
import com.songoda.epichoppers.utils.Debugger;
import com.songoda.epichoppers.utils.Methods;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
public class TeleportHandler {
//Teleport from - teleport 2
private final Map<Location, Location> teleportFrom = new HashMap<>();
private EpicHoppersPlugin instance;
public TeleportHandler(EpicHoppersPlugin instance) {
try {
this.instance = instance;
Bukkit.getScheduler().scheduleSyncRepeatingTask(instance, this::teleportRunner, 0, instance.getConfig().getLong("Main.Amount of Ticks Between Teleport"));
} catch (Exception e) {
Debugger.runReport(e);
}
}
private void teleportRunner() {
for (Player player : Bukkit.getOnlinePlayers()) {
if (!instance.getConfig().getBoolean("Main.Allow Players To Teleport Through Hoppers") || !player.hasPermission("EpicHoppers.Teleport")) {
continue;
}
Location location = player.getLocation().getBlock().getRelative(BlockFace.DOWN).getLocation();
if (!instance.getHopperManager().isHopper(location)) {
continue;
}
Hopper hopper = instance.getHopperManager().getHopper(location);
if (!hopper.isWalkOnTeleport()) continue;
PlayerData playerData = instance.getPlayerDataManager().getPlayerData(player);
if (playerData.getLastTeleport() != null) {
long duration = (new Date()).getTime() - playerData.getLastTeleport().getTime();
if (duration <= 5 * 1000) {
continue;
}
}
tpPlayer(player, hopper);
playerData.setLastTeleport(new Date());
}
}
public void tpPlayer(Player player, Hopper hopper) {
try {
EpicHoppersPlugin instance = EpicHoppersPlugin.getInstance();
Block next = hopper.getLocation().getBlock();
int num = 1;
while (instance.getHopperManager().isHopper(next.getLocation()) && instance.getHopperManager().getHopper(next.getLocation()).getSyncedBlock() != null && num != 15) {
Hopper nextHopper = instance.getHopperManager().getHopper(next);
if (nextHopper.getSyncedBlock() != null) {
next = nextHopper.getSyncedBlock();
}
if (!next.getType().equals(Material.HOPPER)) {
instance.getHopperManager().removeHopper(nextHopper.getLocation());
break;
}
Location location = next.getLocation();
location.setX(location.getX() + 0.5);
location.setZ(location.getZ() + 0.5);
location.setY(location.getY() + 1);
location.setPitch(player.getLocation().getPitch());
location.setDirection(player.getLocation().getDirection());
player.teleport(location);
next = player.getLocation().subtract(0, 0.5, 0).getBlock();
num++;
}
if (num == 1 && teleportFrom.containsKey(hopper.getLocation())) {
Location location = teleportFrom.get(hopper.getLocation());
location.setX(location.getX() + 0.5);
location.setZ(location.getZ() + 0.5);
location.setY(location.getY() + 1);
location.setPitch(player.getLocation().getPitch());
location.setDirection(player.getLocation().getDirection());
player.teleport(location);
next = player.getLocation().subtract(0, 0.5, 0).getBlock();
num ++;
}
if (num != 1) {
teleportFrom.put(next.getLocation(), hopper.getLocation());
Methods.doParticles(player, hopper.getLocation());
Methods.doParticles(player, next.getLocation());
}
} catch (Exception e) {
Debugger.runReport(e);
}
}
}

View File

@ -1,64 +1,64 @@
package com.songoda.epichoppers.Hooks;
import com.songoda.epichoppers.EpicHoppers;
import com.songoda.epichoppers.Utils.Debugger;
import com.wasteofplastic.askyblock.ASkyBlockAPI;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import java.util.List;
import java.util.Set;
import java.util.UUID;
/**
* Created by songoda on 3/17/2017.
*/
public class ASkyBlockHook extends Hook {
private ASkyBlockAPI as;
public ASkyBlockHook() {
super("ASkyblock");
if (isEnabled()) {
as = ASkyBlockAPI.getInstance();
EpicHoppers plugin = EpicHoppers.getInstance();
plugin.hooks.ASkyBlockHook = this;
}
}
@Override
public boolean canBuild(Player p, Location location) {
try {
if (hasBypass(p) || as.getIslandAt(location) == null) return true;
UUID owner = as.getOwner(location);
List<UUID> list = as.getTeamMembers(owner);
Set<Location> list2 = as.getCoopIslands(p);
if (owner == null) return true;
for (UUID uuid : list) {
if (uuid.equals(p.getUniqueId())) {
return true;
}
}
for (Location loc : list2) {
if (as.getIslandAt(location).getOwner().equals(as.getIslandAt(loc).getOwner())) {
return true;
}
}
return owner.equals(p.getUniqueId());
} catch (Exception e) {
Debugger.runReport(e);
}
return true;
}
@Override
public boolean isInClaim(String uuid, Location location) {
return as.getOwner(location).toString().equals(uuid);
}
}
package com.songoda.epichoppers.hooks;
import com.songoda.epichoppers.EpicHoppersPlugin;
import com.songoda.epichoppers.utils.Debugger;
import com.wasteofplastic.askyblock.ASkyBlockAPI;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import java.util.List;
import java.util.Set;
import java.util.UUID;
/**
* Created by songoda on 3/17/2017.
*/
public class ASkyBlockHook extends Hook {
private ASkyBlockAPI as;
public ASkyBlockHook() {
super("ASkyblock");
if (isEnabled()) {
as = ASkyBlockAPI.getInstance();
EpicHoppersPlugin plugin = EpicHoppersPlugin.getInstance();
plugin.hooks.ASkyBlockHook = this;
}
}
@Override
public boolean canBuild(Player p, Location location) {
try {
if (hasBypass(p) || as.getIslandAt(location) == null) return true;
UUID owner = as.getOwner(location);
List<UUID> list = as.getTeamMembers(owner);
Set<Location> list2 = as.getCoopIslands(p);
if (owner == null) return true;
for (UUID uuid : list) {
if (uuid.equals(p.getUniqueId())) {
return true;
}
}
for (Location loc : list2) {
if (as.getIslandAt(location).getOwner().equals(as.getIslandAt(loc).getOwner())) {
return true;
}
}
return owner.equals(p.getUniqueId());
} catch (Exception e) {
Debugger.runReport(e);
}
return true;
}
@Override
public boolean isInClaim(String uuid, Location location) {
return as.getOwner(location).toString().equals(uuid);
}
}

View File

@ -1,56 +1,56 @@
package com.songoda.epichoppers.Hooks;
import com.songoda.epichoppers.EpicHoppers;
import com.songoda.epichoppers.Utils.Debugger;
import me.markeh.factionsframework.entities.FPlayer;
import me.markeh.factionsframework.entities.FPlayers;
import me.markeh.factionsframework.entities.Faction;
import me.markeh.factionsframework.entities.Factions;
import org.bukkit.Location;
import org.bukkit.entity.Player;
/**
* Created by songoda on 3/17/2017.
*/
public class FactionsHook extends Hook {
public FactionsHook() {
super("Factions");
EpicHoppers plugin = EpicHoppers.getInstance();
if (isEnabled())
plugin.hooks.GriefPreventionHook = this;
}
@Override
public boolean canBuild(Player p, Location location) {
try {
FPlayer fp = FPlayers.getBySender(p);
Faction faction = Factions.getFactionAt(location);
return (fp.getFaction().equals(faction) || faction.isNone());
} catch (Exception e) {
Debugger.runReport(e);
}
return false;
}
@Override
public boolean isInClaim(String id, Location location) {
Faction faction = Factions.getFactionAt(location);
return faction.getId().equals(id);
}
@Override
public String getClaimId(String name) {
try {
Faction faction = Factions.getByName(name, "");
return faction.getId();
} catch (Exception ignore) {
}
return null;
}
}
package com.songoda.epichoppers.hooks;
import com.songoda.epichoppers.EpicHoppersPlugin;
import com.songoda.epichoppers.utils.Debugger;
import me.markeh.factionsframework.entities.FPlayer;
import me.markeh.factionsframework.entities.FPlayers;
import me.markeh.factionsframework.entities.Faction;
import me.markeh.factionsframework.entities.Factions;
import org.bukkit.Location;
import org.bukkit.entity.Player;
/**
* Created by songoda on 3/17/2017.
*/
public class FactionsHook extends Hook {
public FactionsHook() {
super("Factions");
EpicHoppersPlugin plugin = EpicHoppersPlugin.getInstance();
if (isEnabled())
plugin.hooks.GriefPreventionHook = this;
}
@Override
public boolean canBuild(Player p, Location location) {
try {
FPlayer fp = FPlayers.getBySender(p);
Faction faction = Factions.getFactionAt(location);
return (fp.getFaction().equals(faction) || faction.isNone());
} catch (Exception e) {
Debugger.runReport(e);
}
return false;
}
@Override
public boolean isInClaim(String id, Location location) {
Faction faction = Factions.getFactionAt(location);
return faction.getId().equals(id);
}
@Override
public String getClaimId(String name) {
try {
Faction faction = Factions.getByName(name, "");
return faction.getId();
} catch (Exception ignore) {
}
return null;
}
}

View File

@ -1,37 +1,37 @@
package com.songoda.epichoppers.Hooks;
import com.songoda.epichoppers.EpicHoppers;
import com.songoda.epichoppers.Utils.Debugger;
import me.ryanhamshire.GriefPrevention.Claim;
import me.ryanhamshire.GriefPrevention.GriefPrevention;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
/**
* Created by songoda on 3/17/2017.
*/
public class GriefPreventionHook extends Hook {
public GriefPreventionHook() {
super("GriefPrevention");
EpicHoppers plugin = EpicHoppers.getInstance();
if (isEnabled())
plugin.hooks.GriefPreventionHook = this;
}
@Override
public boolean canBuild(Player p, Location location) {
try {
if (hasBypass(p))
return true;
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(location, false, null);
return claim != null && claim.allowBuild(p, Material.STONE) == null;
} catch (Exception e) {
Debugger.runReport(e);
}
return false;
}
package com.songoda.epichoppers.hooks;
import com.songoda.epichoppers.EpicHoppersPlugin;
import com.songoda.epichoppers.utils.Debugger;
import me.ryanhamshire.GriefPrevention.Claim;
import me.ryanhamshire.GriefPrevention.GriefPrevention;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
/**
* Created by songoda on 3/17/2017.
*/
public class GriefPreventionHook extends Hook {
public GriefPreventionHook() {
super("GriefPrevention");
EpicHoppersPlugin plugin = EpicHoppersPlugin.getInstance();
if (isEnabled())
plugin.hooks.GriefPreventionHook = this;
}
@Override
public boolean canBuild(Player p, Location location) {
try {
if (hasBypass(p))
return true;
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(location, false, null);
return claim != null && claim.allowBuild(p, Material.STONE) == null;
} catch (Exception e) {
Debugger.runReport(e);
}
return false;
}
}

View File

@ -1,38 +1,38 @@
package com.songoda.epichoppers.Hooks;
import com.songoda.epichoppers.EpicHoppers;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
public abstract class Hook {
final String pluginName;
protected Hook(String pluginName) {
this.pluginName = pluginName;
if (isEnabled())
EpicHoppers.getInstance().hooks.hooksFile.getConfig().addDefault("hooks." + pluginName, true);
}
protected boolean isEnabled() {
return (Bukkit.getPluginManager().isPluginEnabled(pluginName)
&& EpicHoppers.getInstance().hooks.hooksFile.getConfig().getBoolean("hooks." + pluginName, true));
}
boolean hasBypass(Player p) {
return p.hasPermission(EpicHoppers.getInstance().getDescription().getName() + ".bypass");
}
public abstract boolean canBuild(Player p, Location location);
public boolean isInClaim(String id, Location location) {
return false;
}
public String getClaimId(String name) {
return null;
}
}
package com.songoda.epichoppers.hooks;
import com.songoda.epichoppers.EpicHoppersPlugin;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
public abstract class Hook {
final String pluginName;
protected Hook(String pluginName) {
this.pluginName = pluginName;
if (isEnabled())
EpicHoppersPlugin.getInstance().hooks.hooksFile.getConfig().addDefault("hooks." + pluginName, true);
}
protected boolean isEnabled() {
return (Bukkit.getPluginManager().isPluginEnabled(pluginName)
&& EpicHoppersPlugin.getInstance().hooks.hooksFile.getConfig().getBoolean("hooks." + pluginName, true));
}
boolean hasBypass(Player p) {
return p.hasPermission(EpicHoppersPlugin.getInstance().getDescription().getName() + ".bypass");
}
public abstract boolean canBuild(Player p, Location location);
public boolean isInClaim(String id, Location location) {
return false;
}
public String getClaimId(String name) {
return null;
}
}

View File

@ -1,43 +1,43 @@
package com.songoda.epichoppers.Hooks;
import com.songoda.epichoppers.EpicHoppers;
import com.songoda.epichoppers.Utils.Debugger;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.kingdoms.constants.land.Land;
import org.kingdoms.constants.land.SimpleChunkLocation;
import org.kingdoms.constants.player.OfflineKingdomPlayer;
import org.kingdoms.manager.game.GameManagement;
/**
* Created by songoda on 3/17/2017.
*/
public class KingdomsHook extends Hook {
public KingdomsHook() {
super("Kingdoms");
EpicHoppers plugin = EpicHoppers.getInstance();
if (isEnabled())
plugin.hooks.KingdomsHook = this;
}
@Override
public boolean canBuild(Player p, Location location) {
try {
if (hasBypass(p)) return true;
OfflineKingdomPlayer pl = GameManagement.getPlayerManager().getOfflineKingdomPlayer(p);
if (pl.getKingdomPlayer().getKingdom() == null) return true;
SimpleChunkLocation chunkLocation = new SimpleChunkLocation(location.getWorld().getName(), location.getChunk().getX(), location.getChunk().getZ());
Land land = GameManagement.getLandManager().getOrLoadLand(chunkLocation);
String owner = land.getOwner();
return pl.getKingdomPlayer().getKingdom().getKingdomName().equals(owner) || owner == null;
} catch (Exception e) {
Debugger.runReport(e);
}
return true;
}
}
package com.songoda.epichoppers.hooks;
import com.songoda.epichoppers.EpicHoppersPlugin;
import com.songoda.epichoppers.utils.Debugger;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.kingdoms.constants.land.Land;
import org.kingdoms.constants.land.SimpleChunkLocation;
import org.kingdoms.constants.player.OfflineKingdomPlayer;
import org.kingdoms.manager.game.GameManagement;
/**
* Created by songoda on 3/17/2017.
*/
public class KingdomsHook extends Hook {
public KingdomsHook() {
super("Kingdoms");
EpicHoppersPlugin plugin = EpicHoppersPlugin.getInstance();
if (isEnabled())
plugin.hooks.KingdomsHook = this;
}
@Override
public boolean canBuild(Player p, Location location) {
try {
if (hasBypass(p)) return true;
OfflineKingdomPlayer pl = GameManagement.getPlayerManager().getOfflineKingdomPlayer(p);
if (pl.getKingdomPlayer().getKingdom() == null) return true;
SimpleChunkLocation chunkLocation = new SimpleChunkLocation(location.getWorld().getName(), location.getChunk().getX(), location.getChunk().getZ());
Land land = GameManagement.getLandManager().getOrLoadLand(chunkLocation);
String owner = land.getOwner();
return pl.getKingdomPlayer().getKingdom().getKingdomName().equals(owner) || owner == null;
} catch (Exception e) {
Debugger.runReport(e);
}
return true;
}
}

View File

@ -1,37 +1,37 @@
package com.songoda.epichoppers.Hooks;
import com.intellectualcrafters.plot.api.PlotAPI;
import com.songoda.epichoppers.EpicHoppers;
import com.songoda.epichoppers.Utils.Debugger;
import org.bukkit.Location;
import org.bukkit.entity.Player;
/**
* Created by songoda on 3/17/2017.
*/
public class PlotSquaredHook extends Hook {
private PlotAPI plotAPI;
public PlotSquaredHook() {
super("PlotSquared");
if (isEnabled()) {
EpicHoppers plugin = EpicHoppers.getInstance();
plugin.hooks.PlotSquaredHook = this;
this.plotAPI = new PlotAPI();
}
}
@Override
public boolean canBuild(Player p, Location location) {
try {
return hasBypass(p)
|| (plotAPI.getPlot(location) != null
&& plotAPI.isInPlot(p)
&& plotAPI.getPlot(p) == plotAPI.getPlot(location));
} catch (Exception e) {
Debugger.runReport(e);
}
return true;
}
package com.songoda.epichoppers.hooks;
import com.intellectualcrafters.plot.api.PlotAPI;
import com.songoda.epichoppers.EpicHoppersPlugin;
import com.songoda.epichoppers.utils.Debugger;
import org.bukkit.Location;
import org.bukkit.entity.Player;
/**
* Created by songoda on 3/17/2017.
*/
public class PlotSquaredHook extends Hook {
private PlotAPI plotAPI;
public PlotSquaredHook() {
super("PlotSquared");
if (isEnabled()) {
EpicHoppersPlugin plugin = EpicHoppersPlugin.getInstance();
plugin.hooks.PlotSquaredHook = this;
this.plotAPI = new PlotAPI();
}
}
@Override
public boolean canBuild(Player p, Location location) {
try {
return hasBypass(p)
|| (plotAPI.getPlot(location) != null
&& plotAPI.isInPlot(p)
&& plotAPI.getPlot(p) == plotAPI.getPlot(location));
} catch (Exception e) {
Debugger.runReport(e);
}
return true;
}
}

View File

@ -1,33 +1,33 @@
package com.songoda.epichoppers.Hooks;
import br.net.fabiozumbi12.RedProtect.Bukkit.API.RedProtectAPI;
import br.net.fabiozumbi12.RedProtect.Bukkit.RedProtect;
import com.songoda.epichoppers.EpicHoppers;
import com.songoda.epichoppers.Utils.Debugger;
import org.bukkit.Location;
import org.bukkit.entity.Player;
/**
* Created by songoda on 3/17/2017.
*/
public class RedProtectHook extends Hook {
public RedProtectHook() {
super("RedProtect");
EpicHoppers plugin = EpicHoppers.getInstance();
if (isEnabled())
plugin.hooks.RedProtectHook = this;
}
@Override
public boolean canBuild(Player p, Location location) {
try {
RedProtectAPI rpAPI = RedProtect.get().getAPI();
return hasBypass(p) || (rpAPI.getRegion(location) != null && rpAPI.getRegion(location).canBuild(p));
} catch (Exception e) {
Debugger.runReport(e);
}
return true;
}
}
package com.songoda.epichoppers.hooks;
import br.net.fabiozumbi12.RedProtect.Bukkit.API.RedProtectAPI;
import br.net.fabiozumbi12.RedProtect.Bukkit.RedProtect;
import com.songoda.epichoppers.EpicHoppersPlugin;
import com.songoda.epichoppers.utils.Debugger;
import org.bukkit.Location;
import org.bukkit.entity.Player;
/**
* Created by songoda on 3/17/2017.
*/
public class RedProtectHook extends Hook {
public RedProtectHook() {
super("RedProtect");
EpicHoppersPlugin plugin = EpicHoppersPlugin.getInstance();
if (isEnabled())
plugin.hooks.RedProtectHook = this;
}
@Override
public boolean canBuild(Player p, Location location) {
try {
RedProtectAPI rpAPI = RedProtect.get().getAPI();
return hasBypass(p) || (rpAPI.getRegion(location) != null && rpAPI.getRegion(location).canBuild(p));
} catch (Exception e) {
Debugger.runReport(e);
}
return true;
}
}

View File

@ -1,56 +1,56 @@
package com.songoda.epichoppers.Hooks;
import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.TownyUniverse;
import com.songoda.epichoppers.EpicHoppers;
import com.songoda.epichoppers.Utils.Debugger;
import org.bukkit.Location;
import org.bukkit.entity.Player;
/**
* Created by songoda on 3/17/2017.
*/
public class TownyHook extends Hook {
public TownyHook() {
super("Towny");
EpicHoppers plugin = EpicHoppers.getInstance();
if (isEnabled())
plugin.hooks.TownyHook = this;
}
@Override
public boolean canBuild(Player p, Location location) {
try {
if (hasBypass(p) || TownyUniverse.isWilderness(location.getBlock())) return true;
if (!TownyUniverse.getTownBlock(location).hasTown()) return true;
Resident r = TownyUniverse.getDataSource().getResident(p.getName());
return r.hasTown() && TownyUniverse.getTownName(location).equals(r.getTown().getName());
} catch (Exception e) {
Debugger.runReport(e);
}
return true;
}
@Override
public boolean isInClaim(String id, Location location) {
try {
return !TownyUniverse.isWilderness(location.getBlock())
&& TownyUniverse.getTownBlock(location).getTown().getUID() == Integer.parseInt(id);
} catch (Exception e) {
Debugger.runReport(e);
}
return false;
}
@Override
public String getClaimId(String name) {
try {
return TownyUniverse.getDataSource().getTown(name).getUID().toString();
} catch (Exception e) {
Debugger.runReport(e);
}
return null;
}
}
package com.songoda.epichoppers.hooks;
import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.TownyUniverse;
import com.songoda.epichoppers.EpicHoppersPlugin;
import com.songoda.epichoppers.utils.Debugger;
import org.bukkit.Location;
import org.bukkit.entity.Player;
/**
* Created by songoda on 3/17/2017.
*/
public class TownyHook extends Hook {
public TownyHook() {
super("Towny");
EpicHoppersPlugin plugin = EpicHoppersPlugin.getInstance();
if (isEnabled())
plugin.hooks.TownyHook = this;
}
@Override
public boolean canBuild(Player p, Location location) {
try {
if (hasBypass(p) || TownyUniverse.isWilderness(location.getBlock())) return true;
if (!TownyUniverse.getTownBlock(location).hasTown()) return true;
Resident r = TownyUniverse.getDataSource().getResident(p.getName());
return r.hasTown() && TownyUniverse.getTownName(location).equals(r.getTown().getName());
} catch (Exception e) {
Debugger.runReport(e);
}
return true;
}
@Override
public boolean isInClaim(String id, Location location) {
try {
return !TownyUniverse.isWilderness(location.getBlock())
&& TownyUniverse.getTownBlock(location).getTown().getUID() == Integer.parseInt(id);
} catch (Exception e) {
Debugger.runReport(e);
}
return false;
}
@Override
public String getClaimId(String name) {
try {
return TownyUniverse.getDataSource().getTown(name).getUID().toString();
} catch (Exception e) {
Debugger.runReport(e);
}
return null;
}
}

View File

@ -1,49 +1,49 @@
package com.songoda.epichoppers.Hooks;
import com.songoda.epichoppers.EpicHoppers;
import com.songoda.epichoppers.Utils.Debugger;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import us.talabrek.ultimateskyblock.api.uSkyBlockAPI;
/**
* Created by songoda on 3/17/2017.
*/
public class USkyBlockHook extends Hook {
private uSkyBlockAPI usb;
public USkyBlockHook() {
super("USkyBlock");
if (isEnabled()) {
EpicHoppers plugin = EpicHoppers.getInstance();
plugin.hooks.USkyBlockHook = this;
this.usb = (uSkyBlockAPI) Bukkit.getPluginManager().getPlugin(pluginName);
}
}
@Override
public boolean canBuild(Player p, Location location) {
try {
if (hasBypass(p)) return true;
for (Player pl : usb.getIslandInfo(location).getOnlineMembers()) {
if (pl.equals(p)) {
return true;
}
}
return usb.getIslandInfo(location).isLeader(p);
} catch (Exception e) {
Debugger.runReport(e);
}
return false;
}
@Override
public boolean isInClaim(String uuid, Location location) {
return usb.getIslandInfo(location).getLeader().equals(uuid);
}
}
package com.songoda.epichoppers.hooks;
import com.songoda.epichoppers.EpicHoppersPlugin;
import com.songoda.epichoppers.utils.Debugger;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import us.talabrek.ultimateskyblock.api.uSkyBlockAPI;
/**
* Created by songoda on 3/17/2017.
*/
public class USkyBlockHook extends Hook {
private uSkyBlockAPI usb;
public USkyBlockHook() {
super("USkyBlock");
if (isEnabled()) {
EpicHoppersPlugin plugin = EpicHoppersPlugin.getInstance();
plugin.hooks.USkyBlockHook = this;
this.usb = (uSkyBlockAPI) Bukkit.getPluginManager().getPlugin(pluginName);
}
}
@Override
public boolean canBuild(Player p, Location location) {
try {
if (hasBypass(p)) return true;
for (Player pl : usb.getIslandInfo(location).getOnlineMembers()) {
if (pl.equals(p)) {
return true;
}
}
return usb.getIslandInfo(location).isLeader(p);
} catch (Exception e) {
Debugger.runReport(e);
}
return false;
}
@Override
public boolean isInClaim(String uuid, Location location) {
return usb.getIslandInfo(location).getLeader().equals(uuid);
}
}

View File

@ -1,31 +1,31 @@
package com.songoda.epichoppers.Hooks;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.songoda.epichoppers.EpicHoppers;
import com.songoda.epichoppers.Utils.Debugger;
import org.bukkit.Location;
import org.bukkit.entity.Player;
/**
* Created by songoda on 3/17/2017.
*/
public class WorldGuardHook extends Hook {
private EpicHoppers plugin = EpicHoppers.getInstance();
public WorldGuardHook() {
super("WorldGuard");
if (isEnabled())
plugin.hooks.WorldGuardHook = this;
}
@Override
public boolean canBuild(Player p, Location location) {
try {
return p.hasPermission(plugin.getDescription().getName() + ".bypass") || WorldGuardPlugin.inst().canBuild(p, location);
} catch (Exception e) {
Debugger.runReport(e);
}
return false;
}
}
package com.songoda.epichoppers.hooks;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.songoda.epichoppers.EpicHoppersPlugin;
import com.songoda.epichoppers.utils.Debugger;
import org.bukkit.Location;
import org.bukkit.entity.Player;
/**
* Created by songoda on 3/17/2017.
*/
public class WorldGuardHook extends Hook {
private EpicHoppersPlugin plugin = EpicHoppersPlugin.getInstance();
public WorldGuardHook() {
super("WorldGuard");
if (isEnabled())
plugin.hooks.WorldGuardHook = this;
}
@Override
public boolean canBuild(Player p, Location location) {
try {
return p.hasPermission(plugin.getDescription().getName() + ".bypass") || WorldGuardPlugin.inst().canBuild(p, location);
} catch (Exception e) {
Debugger.runReport(e);
}
return false;
}
}

View File

@ -1,51 +1,60 @@
package com.songoda.epichoppers.Hopper;
import org.bukkit.block.Block;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
public class Filter {
private List<ItemStack> whiteList = new ArrayList<>();
private List<ItemStack> blackList = new ArrayList<>();
private List<ItemStack> voidList = new ArrayList<>();
private Block endPoint;
public List<ItemStack> getWhiteList() {
if (whiteList == null) return new ArrayList<>();
return whiteList;
}
public void setWhiteList(List<ItemStack> whiteList) {
this.whiteList = whiteList;
}
public List<ItemStack> getBlackList() {
if (blackList == null) return new ArrayList<>();
return blackList;
}
public void setBlackList(List<ItemStack> blackList) {
this.blackList = blackList;
}
public List<ItemStack> getVoidList() {
if (voidList == null) return new ArrayList<>();
return voidList;
}
public void setVoidList(List<ItemStack> voidList) {
this.voidList = voidList;
}
public Block getEndPoint() {
return endPoint;
}
public void setEndPoint(Block endPoint) {
this.endPoint = endPoint;
}
}
package com.songoda.epichoppers.hopper;
import com.songoda.epichoppers.api.hopper.Filter;
import org.bukkit.block.Block;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
public class EFilter implements Filter {
private List<ItemStack> whiteList = new ArrayList<>();
private List<ItemStack> blackList = new ArrayList<>();
private List<ItemStack> voidList = new ArrayList<>();
private Block endPoint;
@Override
public List<ItemStack> getWhiteList() {
if (whiteList == null) return new ArrayList<>();
return whiteList;
}
@Override
public void setWhiteList(List<ItemStack> whiteList) {
this.whiteList = whiteList;
}
@Override
public List<ItemStack> getBlackList() {
if (blackList == null) return new ArrayList<>();
return blackList;
}
@Override
public void setBlackList(List<ItemStack> blackList) {
this.blackList = blackList;
}
@Override
public List<ItemStack> getVoidList() {
if (voidList == null) return new ArrayList<>();
return voidList;
}
@Override
public void setVoidList(List<ItemStack> voidList) {
this.voidList = voidList;
}
@Override
public Block getEndPoint() {
return endPoint;
}
@Override
public void setEndPoint(Block endPoint) {
this.endPoint = endPoint;
}
}

View File

@ -1,49 +1,58 @@
package com.songoda.epichoppers.Hopper;
import com.songoda.epichoppers.EpicHoppers;
import org.bukkit.Location;
import org.bukkit.block.Block;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
public class HopperManager {
private final Map<Location, Hopper> registeredHoppers = new HashMap<>();
public void addHopper(Location location, Hopper hopper) {
registeredHoppers.put(roundLocation(location), hopper);
}
public Hopper removeHopper(Location location) {
return registeredHoppers.remove(location);
}
public Hopper getHopper(Location location) {
if (!registeredHoppers.containsKey(roundLocation(location))) {
addHopper(location, new Hopper(location, EpicHoppers.getInstance().getLevelManager().getLowestLevel(), null, null, new Filter(), false));
}
return registeredHoppers.get(roundLocation(location));
}
public Hopper getHopper(Block block) {
return getHopper(block.getLocation());
}
public boolean isHopper(Location location) {
return registeredHoppers.containsKey(roundLocation(location));
}
public Map<Location, Hopper> getHoppers() {
return Collections.unmodifiableMap(registeredHoppers);
}
private Location roundLocation(Location location) {
location = location.clone();
location.setX(location.getBlockX());
location.setY(location.getBlockY());
location.setZ(location.getBlockZ());
return location;
}
}
package com.songoda.epichoppers.hopper;
import com.songoda.epichoppers.EpicHoppersPlugin;
import com.songoda.epichoppers.api.hopper.Filter;
import com.songoda.epichoppers.api.hopper.Hopper;
import com.songoda.epichoppers.api.hopper.HopperManager;
import org.bukkit.Location;
import org.bukkit.block.Block;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
public class EHopperManager implements HopperManager {
private final Map<Location, Hopper> registeredHoppers = new HashMap<>();
@Override
public void addHopper(Location location, Hopper hopper) {
registeredHoppers.put(roundLocation(location), hopper);
}
@Override
public Hopper removeHopper(Location location) {
return registeredHoppers.remove(location);
}
@Override
public Hopper getHopper(Location location) {
if (!registeredHoppers.containsKey(roundLocation(location))) {
addHopper(location, new EHopper(location, EpicHoppersPlugin.getInstance().getLevelManager().getLowestLevel(), null, null, new EFilter(), false));
}
return registeredHoppers.get(roundLocation(location));
}
@Override
public Hopper getHopper(Block block) {
return getHopper(block.getLocation());
}
@Override
public boolean isHopper(Location location) {
return registeredHoppers.containsKey(roundLocation(location));
}
@Override
public Map<Location, Hopper> getHoppers() {
return Collections.unmodifiableMap(registeredHoppers);
}
private Location roundLocation(Location location) {
location = location.clone();
location.setX(location.getBlockX());
location.setY(location.getBlockY());
location.setZ(location.getBlockZ());
return location;
}
}

View File

@ -1,63 +1,72 @@
package com.songoda.epichoppers.Hopper;
import com.songoda.epichoppers.EpicHoppers;
import java.util.ArrayList;
import java.util.List;
public class Level {
private int level, costExperience, costEconomy, range, amount, blockBreak, suction;
private List<String> description = new ArrayList<>();
public Level(int level, int costExperience, int costEconomy, int range, int amount, int suction, int blockBreak) {
this.level = level;
this.costExperience = costExperience;
this.costEconomy = costEconomy;
this.range = range;
this.amount = amount;
this.blockBreak = blockBreak;
this.suction = suction;
EpicHoppers instance = EpicHoppers.getInstance();
description.add(instance.getLocale().getMessage("interface.hopper.range", range));
description.add(instance.getLocale().getMessage("interface.hopper.amount", amount));
if (suction != 0) description.add(instance.getLocale().getMessage("interface.hopper.suction", suction));
if (blockBreak != 0) description.add(instance.getLocale().getMessage("interface.hopper.blockbreak", blockBreak));
}
public List<String> getDescription() {
return new ArrayList<>(description);
}
public int getLevel() {
return level;
}
public int getRange() {
return range;
}
public int getAmount() {
return amount;
}
public int getBlockBreak() {
return blockBreak;
}
public int getSuction() {
return suction;
}
public int getCostExperience() {
return costExperience;
}
public int getCostEconomy() {
return costEconomy;
}
}
package com.songoda.epichoppers.hopper;
import com.songoda.epichoppers.EpicHoppersPlugin;
import com.songoda.epichoppers.api.hopper.Level;
import java.util.ArrayList;
import java.util.List;
public class ELevel implements Level {
private int level, costExperience, costEconomy, range, amount, blockBreak, suction;
private List<String> description = new ArrayList<>();
public ELevel(int level, int costExperience, int costEconomy, int range, int amount, int suction, int blockBreak) {
this.level = level;
this.costExperience = costExperience;
this.costEconomy = costEconomy;
this.range = range;
this.amount = amount;
this.blockBreak = blockBreak;
this.suction = suction;
EpicHoppersPlugin instance = EpicHoppersPlugin.getInstance();
description.add(instance.getLocale().getMessage("interface.hopper.range", range));
description.add(instance.getLocale().getMessage("interface.hopper.amount", amount));
if (suction != 0) description.add(instance.getLocale().getMessage("interface.hopper.suction", suction));
if (blockBreak != 0) description.add(instance.getLocale().getMessage("interface.hopper.blockbreak", blockBreak));
}
@Override
public List<String> getDescription() {
return new ArrayList<>(description);
}
@Override
public int getLevel() {
return level;
}
@Override
public int getRange() {
return range;
}
@Override
public int getAmount() {
return amount;
}
@Override
public int getBlockBreak() {
return blockBreak;
}
@Override
public int getSuction() {
return suction;
}
@Override
public int getCostExperience() {
return costExperience;
}
@Override
public int getCostEconomy() {
return costEconomy;
}
}

View File

@ -0,0 +1,42 @@
package com.songoda.epichoppers.hopper;
import com.songoda.epichoppers.api.hopper.LevelManager;
import java.util.Collections;
import java.util.Map;
import java.util.NavigableMap;
import java.util.TreeMap;
public class ELevelManager implements LevelManager {
private final NavigableMap<Integer, ELevel> registeredLevels = new TreeMap<>();
@Override
public void addLevel(int level, int costExperiance, int costEconomy, int range, int amount, int suction, int blockBreak) {
registeredLevels.put(level, new ELevel(level, costExperiance, costEconomy, range, amount, suction, blockBreak));
}
@Override
public com.songoda.epichoppers.api.hopper.Level getLevel(int level) {
return registeredLevels.get(level);
}
@Override
public com.songoda.epichoppers.api.hopper.Level getLowestLevel() {
return registeredLevels.firstEntry().getValue();
}
@Override
public com.songoda.epichoppers.api.hopper.Level getHighestLevel() {
return registeredLevels.lastEntry().getValue();
}
@Override
public Map<Integer, com.songoda.epichoppers.api.hopper.Level> getLevels() {
return Collections.unmodifiableMap(registeredLevels);
}
public void clear() {
registeredLevels.clear();
}
}

View File

@ -0,0 +1,9 @@
package com.songoda.epichoppers.player;
public enum MenuType {
NOT_IN,
OVERVIEW,
FILTER
}

View File

@ -0,0 +1,60 @@
package com.songoda.epichoppers.player;
import com.songoda.epichoppers.api.hopper.Hopper;
import com.songoda.epichoppers.hopper.EHopper;
import java.util.Date;
import java.util.UUID;
public class PlayerData {
private final UUID playerUUID;
private Hopper lastHopper = null;
private MenuType inMenu = MenuType.NOT_IN;
private SyncType syncType = null; // Null means off.
private Date lastTeleport = null; // Null means off.
public PlayerData(UUID playerUUID) {
this.playerUUID = playerUUID;
}
public UUID getPlayerUUID() {
return playerUUID;
}
public Hopper getLastHopper() {
return lastHopper;
}
public void setLastHopper(Hopper lastHopper) {
this.lastHopper = lastHopper;
}
public MenuType getInMenu() {
return inMenu;
}
public void setInMenu(MenuType inMenu) {
this.inMenu = inMenu;
}
public SyncType getSyncType() {
return syncType;
}
public void setSyncType(SyncType syncType) {
this.syncType = syncType;
}
public Date getLastTeleport() {
return lastTeleport;
}
public void setLastTeleport(Date lastTeleport) {
this.lastTeleport = lastTeleport;
}
}

View File

@ -0,0 +1,22 @@
package com.songoda.epichoppers.player;
import org.bukkit.entity.Player;
import java.util.*;
public class PlayerDataManager {
private final Map<UUID, PlayerData> registeredPlayers = new HashMap<>();
public PlayerData getPlayerData(UUID uuid) {
return (uuid != null) ? registeredPlayers.computeIfAbsent(uuid, PlayerData::new) : null;
}
public PlayerData getPlayerData(Player player) {
return getPlayerData(player.getUniqueId());
}
public Collection<PlayerData> getRegisteredPlayers() {
return Collections.unmodifiableCollection(registeredPlayers.values());
}
}

View File

@ -0,0 +1,8 @@
package com.songoda.epichoppers.player;
public enum SyncType {
REGULAR,
FILTERED
}

View File

@ -1,31 +1,31 @@
package com.songoda.epichoppers.Utils;
import com.songoda.epichoppers.EpicHoppers;
/**
* Created by songoda on 3/21/2017.
*/
public class Debugger {
public static void runReport(Exception e) {
if (isDebug()) {
System.out.println("==============================================================");
System.out.println("The following is an error encountered in EpicHoppers.");
System.out.println("--------------------------------------------------------------");
e.printStackTrace();
System.out.println("==============================================================");
}
sendReport(e);
}
public static void sendReport(Exception e) {
}
public static boolean isDebug() {
EpicHoppers instance = EpicHoppers.getInstance();
return instance.getConfig().getBoolean("System.Debugger Enabled");
}
}
package com.songoda.epichoppers.utils;
import com.songoda.epichoppers.EpicHoppersPlugin;
/**
* Created by songoda on 3/21/2017.
*/
public class Debugger {
public static void runReport(Exception e) {
if (isDebug()) {
System.out.println("==============================================================");
System.out.println("The following is an error encountered in EpicHoppers.");
System.out.println("--------------------------------------------------------------");
e.printStackTrace();
System.out.println("==============================================================");
}
sendReport(e);
}
public static void sendReport(Exception e) {
}
public static boolean isDebug() {
EpicHoppersPlugin instance = EpicHoppersPlugin.getInstance();
return instance.getConfig().getBoolean("System.Debugger Enabled");
}
}

View File

@ -1,92 +1,83 @@
package com.songoda.epichoppers.Utils;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.epichoppers.EpicHoppers;
import com.songoda.epichoppers.Hopper.Hopper;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
/**
* Created by songoda on 2/24/2017.
*/
public class Methods {
public static boolean isSync(Player p) {
try {
if (p.getItemInHand().hasItemMeta()
&& p.getItemInHand().getType() != Material.AIR
&& p.getItemInHand().getItemMeta().hasLore()) {
for (String str : p.getItemInHand().getItemMeta().getLore()) {
if (str.equals(Arconix.pl().getApi().format().formatText("&7Sync Touch")) || str.equals(Arconix.pl().getApi().format().formatText("&aSync Touch"))) {
return true;
}
}
}
} catch (Exception e) {
Debugger.runReport(e);
}
return false;
}
public static ItemStack getGlass() {
try {
EpicHoppers instance = EpicHoppers.getInstance();
return Arconix.pl().getApi().getGUI().getGlass(instance.getConfig().getBoolean("Interfaces.Replace Glass Type 1 With Rainbow Glass"), instance.getConfig().getInt("Interfaces.Glass Type 1"));
} catch (Exception e) {
Debugger.runReport(e);
}
return null;
}
public static ItemStack getBackgroundGlass(boolean type) {
try {
EpicHoppers instance = EpicHoppers.getInstance();
if (type)
return Arconix.pl().getApi().getGUI().getGlass(false, instance.getConfig().getInt("Interfaces.Glass Type 2"));
else
return Arconix.pl().getApi().getGUI().getGlass(false, instance.getConfig().getInt("Interfaces.Glass Type 3"));
} catch (Exception e) {
Debugger.runReport(e);
}
return null;
}
public static String formatName(int level, boolean full) {
try {
EpicHoppers instance = EpicHoppers.getInstance();
String name = instance.getLocale().getMessage("general.nametag.nameformat", level);
String info = "";
if (full) {
info += Arconix.pl().getApi().format().convertToInvisibleString(level + ":");
}
return info + Arconix.pl().getApi().format().formatText(name);
} catch (Exception e) {
Debugger.runReport(e);
}
return null;
}
public static void doParticles(Player p, Location location) {
try {
EpicHoppers instance = EpicHoppers.getInstance();
location.setX(location.getX() + .5);
location.setY(location.getY() + .5);
location.setZ(location.getZ() + .5);
p.getWorld().spawnParticle(org.bukkit.Particle.valueOf(instance.getConfig().getString("Main.Upgrade Particle Type")), location, 200, .5, .5, .5);
} catch (Exception e) {
Debugger.runReport(e);
}
}
}
package com.songoda.epichoppers.utils;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.epichoppers.EpicHoppersPlugin;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
/**
* Created by songoda on 2/24/2017.
*/
public class Methods {
public static boolean isSync(Player p) {
try {
if (p.getItemInHand().hasItemMeta()
&& p.getItemInHand().getType() != Material.AIR
&& p.getItemInHand().getItemMeta().hasLore()) {
for (String str : p.getItemInHand().getItemMeta().getLore()) {
if (str.equals(Arconix.pl().getApi().format().formatText("&7Sync Touch")) || str.equals(Arconix.pl().getApi().format().formatText("&aSync Touch"))) {
return true;
}
}
}
} catch (Exception e) {
Debugger.runReport(e);
}
return false;
}
public static ItemStack getGlass() {
try {
EpicHoppersPlugin instance = EpicHoppersPlugin.getInstance();
return Arconix.pl().getApi().getGUI().getGlass(instance.getConfig().getBoolean("Interfaces.Replace Glass Type 1 With Rainbow Glass"), instance.getConfig().getInt("Interfaces.Glass Type 1"));
} catch (Exception e) {
Debugger.runReport(e);
}
return null;
}
public static ItemStack getBackgroundGlass(boolean type) {
try {
EpicHoppersPlugin instance = EpicHoppersPlugin.getInstance();
if (type)
return Arconix.pl().getApi().getGUI().getGlass(false, instance.getConfig().getInt("Interfaces.Glass Type 2"));
else
return Arconix.pl().getApi().getGUI().getGlass(false, instance.getConfig().getInt("Interfaces.Glass Type 3"));
} catch (Exception e) {
Debugger.runReport(e);
}
return null;
}
public static String formatName(int level, boolean full) {
try {
EpicHoppersPlugin instance = EpicHoppersPlugin.getInstance();
String name = instance.getLocale().getMessage("general.nametag.nameformat", level);
String info = "";
if (full) {
info += Arconix.pl().getApi().format().convertToInvisibleString(level + ":");
}
return info + Arconix.pl().getApi().format().formatText(name);
} catch (Exception e) {
Debugger.runReport(e);
}
return null;
}
public static void doParticles(Player p, Location location) {
try {
EpicHoppersPlugin instance = EpicHoppersPlugin.getInstance();
location.setX(location.getX() + .5);
location.setY(location.getY() + .5);
location.setZ(location.getZ() + .5);
p.getWorld().spawnParticle(org.bukkit.Particle.valueOf(instance.getConfig().getString("Main.Upgrade Particle Type")), location, 200, .5, .5, .5);
} catch (Exception e) {
Debugger.runReport(e);
}
}
}

View File

@ -1,239 +1,238 @@
package com.songoda.epichoppers.Utils;
import com.songoda.arconix.api.methods.formatting.TextComponent;
import com.songoda.arconix.api.utils.ConfigWrapper;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.epichoppers.EpicHoppers;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Created by songo on 6/4/2017.
*/
public class SettingsManager implements Listener {
private String pluginName = "EpicHoppers";
private static final Pattern SETTINGS_PATTERN = Pattern.compile("(.{1,28}(?:\\s|$))|(.{0,28})", Pattern.DOTALL);
private static ConfigWrapper defs;
private Map<Player, String> cat = new HashMap<>();
private final EpicHoppers instance;
public SettingsManager(EpicHoppers plugin) {
this.instance = plugin;
plugin.saveResource("SettingDefinitions.yml", true);
defs = new ConfigWrapper(plugin, "", "SettingDefinitions.yml");
defs.createNewFile("Loading data file", pluginName + " SettingDefinitions file");
Bukkit.getPluginManager().registerEvents(this, plugin);
}
private Map<Player, String> current = new HashMap<>();
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
ItemStack clickedItem = event.getCurrentItem();
if (event.getInventory() != event.getWhoClicked().getOpenInventory().getTopInventory()
|| clickedItem == null || !clickedItem.hasItemMeta()
|| !clickedItem.getItemMeta().hasDisplayName()) {
return;
}
if (event.getInventory().getTitle().equals(pluginName + " Settings Manager")) {
event.setCancelled(true);
if (clickedItem.getType().name().contains("STAINED_GLASS")) return;
String type = ChatColor.stripColor(clickedItem.getItemMeta().getDisplayName());
this.cat.put((Player) event.getWhoClicked(), type);
this.openEditor((Player) event.getWhoClicked());
} else if (event.getInventory().getTitle().equals(pluginName + " Settings Editor")) {
event.setCancelled(true);
if (clickedItem.getType().name().contains("STAINED_GLASS")) return;
Player player = (Player) event.getWhoClicked();
String key = cat.get(player) + "." + ChatColor.stripColor(clickedItem.getItemMeta().getDisplayName());
if (instance.getConfig().get(key).getClass().getName().equals("java.lang.Boolean")) {
this.instance.getConfig().set(key, !instance.getConfig().getBoolean(key));
this.finishEditing(player);
} else {
this.editObject(player, key);
}
}
}
@EventHandler
public void onChat(AsyncPlayerChatEvent event) {
Player player = event.getPlayer();
if (!current.containsKey(player)) return;
String value = current.get(player);
FileConfiguration config = instance.getConfig();
if (config.isInt(value)) {
config.set(value, Integer.parseInt(event.getMessage()));
} else if (config.isDouble(value)) {
config.set(value, Double.parseDouble(event.getMessage()));
} else if (config.isString(value)) {
config.set(value, event.getMessage());
}
this.finishEditing(player);
event.setCancelled(true);
}
public void finishEditing(Player player) {
this.current.remove(player);
this.instance.saveConfig();
this.openEditor(player);
}
public void editObject(Player player, String current) {
this.current.put(player, ChatColor.stripColor(current));
player.closeInventory();
player.sendMessage("");
player.sendMessage(TextComponent.formatText("&7Please enter a value for &6" + current + "&7."));
if (instance.getConfig().isInt(current) || instance.getConfig().isDouble(current)) {
player.sendMessage(TextComponent.formatText("&cUse only numbers."));
}
player.sendMessage("");
}
public void openSettingsManager(Player player) {
Inventory inventory = Bukkit.createInventory(null, 27, pluginName + " Settings Manager");
ItemStack glass = Methods.getGlass();
for (int i = 0; i < inventory.getSize(); i++) {
inventory.setItem(i, glass);
}
int slot = 10;
for (String key : instance.getConfig().getDefaultSection().getKeys(false)) {
ItemStack item = new ItemStack(Material.WHITE_WOOL, 1, (byte) (slot - 9)); //ToDo: Make this function as it was meant to.
ItemMeta meta = item.getItemMeta();
meta.setLore(Collections.singletonList(TextComponent.formatText("&6Click To Edit This Category.")));
meta.setDisplayName(TextComponent.formatText("&f&l" + key));
item.setItemMeta(meta);
inventory.setItem(slot, item);
slot++;
}
player.openInventory(inventory);
}
public void openEditor(Player player) {
Inventory inventory = Bukkit.createInventory(null, 54, pluginName + " Settings Editor");
FileConfiguration config = instance.getConfig();
int slot = 0;
for (String key : config.getConfigurationSection(cat.get(player)).getKeys(true)) {
String fKey = cat.get(player) + "." + key;
ItemStack item = new ItemStack(Material.DIAMOND_HELMET);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(TextComponent.formatText("&6" + key));
List<String> lore = new ArrayList<>();
if (config.isBoolean(fKey)) {
item.setType(Material.LEVER);
lore.add(TextComponent.formatText(config.getBoolean(fKey) ? "&atrue" : "&cfalse"));
} else if (config.isString(fKey)) {
item.setType(Material.PAPER);
lore.add(TextComponent.formatText("&9" + config.getString(fKey)));
} else if (config.isInt(fKey)) {
item.setType(Material.CLOCK);
lore.add(TextComponent.formatText("&5" + config.getInt(fKey)));
}
if (defs.getConfig().contains(fKey)) {
String text = defs.getConfig().getString(key);
Matcher m = SETTINGS_PATTERN.matcher(text);
while (m.find()) {
if (m.end() != text.length() || m.group().length() != 0)
lore.add(TextComponent.formatText("&7" + m.group()));
}
}
meta.setLore(lore);
item.setItemMeta(meta);
inventory.setItem(slot, item);
slot++;
}
player.openInventory(inventory);
}
public void updateSettings() {
FileConfiguration config = instance.getConfig();
for (Setting setting : Setting.values()) {
if (config.contains("settings." + setting.oldSetting)) {
config.addDefault(setting.setting, instance.getConfig().get("settings." + setting.oldSetting));
config.set("settings." + setting.oldSetting, null);
} else if (setting.setting.equals("Main.Upgrade Particle Type")) {
config.addDefault(setting.setting, setting.option);
} else {
config.addDefault(setting.setting, setting.option);
}
}
config.set("settings", null);
}
public enum Setting {
o1("Upgrading-enabled", "Main.Allow Hopper Upgrading", true),
o2("Upgrade-with-eco", "Main.Upgrade With Economy", true),
o3("Upgrade-with-xp", "Main.Upgrade With XP", true),
o4("Teleport-hoppers", "Main.Allow Players To Teleport Through Hoppers", true),
o5("Filter-hoppers", "Main.Allow Players To use The Hopper Filter", true),
o6("EnderChest-support", "Main.Support Enderchests", true),
o7("Upgrade-particle-type", "Main.Upgrade Particle Type", "SPELL_WITCH"),
o8("Hop-Tick", "Main.Amount of Ticks Between Hops", 8L),
o9("Tele-Tick", "Main.Amount of Ticks Between Teleport", 10L),
o10("Sync-Timeout", "Main.Timeout When Syncing Hoppers", 300L),
o11("hopper-Limit", "Main.Max Hoppers Per Chunk", -1),
o12("Helpful-Tips", "Main.Display Helpful Tips For Operators", true),
o13("Sounds", "Main.Sounds Enabled", true),
o14("BlockBreak-Particle-Type", "Main.BlockBreak Particle Type", "LAVA"),
o15("BlockBreak-Blacklist", "Main.BlockBreak Blacklisted Blocks", Arrays.asList("BEDROCK")),
o16("Rainbow-Glass", "Interfaces.Replace Glass Type 1 With Rainbow Glass", false),
o17("ECO-Icon", "Interfaces.Economy Icon", "SUNFLOWER"),
o18("XP-Icon", "Interfaces.XP Icon", "EXPERIENCE_BOTTLE"),
o19("Glass-Type-1", "Interfaces.Glass Type 1", 7),
o20("Glass-Type-2", "Interfaces.Glass Type 2", 11),
o21("Glass-Type-3", "Interfaces.Glass Type 3", 3),
o22("Debug-Mode", "System.Debugger Enabled", false);
private String setting;
private String oldSetting;
private Object option;
Setting(String oldSetting, String setting, Object option) {
this.oldSetting = oldSetting;
this.setting = setting;
this.option = option;
}
}
package com.songoda.epichoppers.utils;
import com.songoda.arconix.api.methods.formatting.TextComponent;
import com.songoda.arconix.api.utils.ConfigWrapper;
import com.songoda.epichoppers.EpicHoppersPlugin;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Created by songo on 6/4/2017.
*/
public class SettingsManager implements Listener {
private String pluginName = "EpicHoppers";
private static final Pattern SETTINGS_PATTERN = Pattern.compile("(.{1,28}(?:\\s|$))|(.{0,28})", Pattern.DOTALL);
private static ConfigWrapper defs;
private Map<Player, String> cat = new HashMap<>();
private final EpicHoppersPlugin instance;
public SettingsManager(EpicHoppersPlugin plugin) {
this.instance = plugin;
plugin.saveResource("SettingDefinitions.yml", true);
defs = new ConfigWrapper(plugin, "", "SettingDefinitions.yml");
defs.createNewFile("Loading data file", pluginName + " SettingDefinitions file");
Bukkit.getPluginManager().registerEvents(this, plugin);
}
private Map<Player, String> current = new HashMap<>();
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
ItemStack clickedItem = event.getCurrentItem();
if (event.getInventory() != event.getWhoClicked().getOpenInventory().getTopInventory()
|| clickedItem == null || !clickedItem.hasItemMeta()
|| !clickedItem.getItemMeta().hasDisplayName()) {
return;
}
if (event.getInventory().getTitle().equals(pluginName + " Settings Manager")) {
event.setCancelled(true);
if (clickedItem.getType().name().contains("STAINED_GLASS")) return;
String type = ChatColor.stripColor(clickedItem.getItemMeta().getDisplayName());
this.cat.put((Player) event.getWhoClicked(), type);
this.openEditor((Player) event.getWhoClicked());
} else if (event.getInventory().getTitle().equals(pluginName + " Settings Editor")) {
event.setCancelled(true);
if (clickedItem.getType().name().contains("STAINED_GLASS")) return;
Player player = (Player) event.getWhoClicked();
String key = cat.get(player) + "." + ChatColor.stripColor(clickedItem.getItemMeta().getDisplayName());
if (instance.getConfig().get(key).getClass().getName().equals("java.lang.Boolean")) {
this.instance.getConfig().set(key, !instance.getConfig().getBoolean(key));
this.finishEditing(player);
} else {
this.editObject(player, key);
}
}
}
@EventHandler
public void onChat(AsyncPlayerChatEvent event) {
Player player = event.getPlayer();
if (!current.containsKey(player)) return;
String value = current.get(player);
FileConfiguration config = instance.getConfig();
if (config.isInt(value)) {
config.set(value, Integer.parseInt(event.getMessage()));
} else if (config.isDouble(value)) {
config.set(value, Double.parseDouble(event.getMessage()));
} else if (config.isString(value)) {
config.set(value, event.getMessage());
}
this.finishEditing(player);
event.setCancelled(true);
}
public void finishEditing(Player player) {
this.current.remove(player);
this.instance.saveConfig();
this.openEditor(player);
}
public void editObject(Player player, String current) {
this.current.put(player, ChatColor.stripColor(current));
player.closeInventory();
player.sendMessage("");
player.sendMessage(TextComponent.formatText("&7Please enter a value for &6" + current + "&7."));
if (instance.getConfig().isInt(current) || instance.getConfig().isDouble(current)) {
player.sendMessage(TextComponent.formatText("&cUse only numbers."));
}
player.sendMessage("");
}
public void openSettingsManager(Player player) {
Inventory inventory = Bukkit.createInventory(null, 27, pluginName + " Settings Manager");
ItemStack glass = Methods.getGlass();
for (int i = 0; i < inventory.getSize(); i++) {
inventory.setItem(i, glass);
}
int slot = 10;
for (String key : instance.getConfig().getDefaultSection().getKeys(false)) {
ItemStack item = new ItemStack(Material.WHITE_WOOL, 1, (byte) (slot - 9)); //ToDo: Make this function as it was meant to.
ItemMeta meta = item.getItemMeta();
meta.setLore(Collections.singletonList(TextComponent.formatText("&6Click To Edit This Category.")));
meta.setDisplayName(TextComponent.formatText("&f&l" + key));
item.setItemMeta(meta);
inventory.setItem(slot, item);
slot++;
}
player.openInventory(inventory);
}
public void openEditor(Player player) {
Inventory inventory = Bukkit.createInventory(null, 54, pluginName + " Settings Editor");
FileConfiguration config = instance.getConfig();
int slot = 0;
for (String key : config.getConfigurationSection(cat.get(player)).getKeys(true)) {
String fKey = cat.get(player) + "." + key;
ItemStack item = new ItemStack(Material.DIAMOND_HELMET);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(TextComponent.formatText("&6" + key));
List<String> lore = new ArrayList<>();
if (config.isBoolean(fKey)) {
item.setType(Material.LEVER);
lore.add(TextComponent.formatText(config.getBoolean(fKey) ? "&atrue" : "&cfalse"));
} else if (config.isString(fKey)) {
item.setType(Material.PAPER);
lore.add(TextComponent.formatText("&9" + config.getString(fKey)));
} else if (config.isInt(fKey)) {
item.setType(Material.CLOCK);
lore.add(TextComponent.formatText("&5" + config.getInt(fKey)));
}
if (defs.getConfig().contains(fKey)) {
String text = defs.getConfig().getString(key);
Matcher m = SETTINGS_PATTERN.matcher(text);
while (m.find()) {
if (m.end() != text.length() || m.group().length() != 0)
lore.add(TextComponent.formatText("&7" + m.group()));
}
}
meta.setLore(lore);
item.setItemMeta(meta);
inventory.setItem(slot, item);
slot++;
}
player.openInventory(inventory);
}
public void updateSettings() {
FileConfiguration config = instance.getConfig();
for (Setting setting : Setting.values()) {
if (config.contains("settings." + setting.oldSetting)) {
config.addDefault(setting.setting, instance.getConfig().get("settings." + setting.oldSetting));
config.set("settings." + setting.oldSetting, null);
} else if (setting.setting.equals("Main.Upgrade Particle Type")) {
config.addDefault(setting.setting, setting.option);
} else {
config.addDefault(setting.setting, setting.option);
}
}
config.set("settings", null);
}
public enum Setting {
o1("Upgrading-enabled", "Main.Allow hopper Upgrading", true),
o2("Upgrade-with-eco", "Main.Upgrade With Economy", true),
o3("Upgrade-with-xp", "Main.Upgrade With XP", true),
o4("Teleport-hoppers", "Main.Allow Players To Teleport Through Hoppers", true),
o5("Filter-hoppers", "Main.Allow Players To use The hopper Filter", true),
o6("EnderChest-support", "Main.Support Enderchests", true),
o7("Upgrade-particle-type", "Main.Upgrade Particle Type", "SPELL_WITCH"),
o8("Hop-Tick", "Main.Amount of Ticks Between Hops", 8L),
o9("Tele-Tick", "Main.Amount of Ticks Between Teleport", 10L),
o10("Sync-Timeout", "Main.Timeout When Syncing Hoppers", 300L),
o11("hopper-Limit", "Main.Max Hoppers Per Chunk", -1),
o12("Helpful-Tips", "Main.Display Helpful Tips For Operators", true),
o13("Sounds", "Main.Sounds Enabled", true),
o14("BlockBreak-Particle-Type", "Main.BlockBreak Particle Type", "LAVA"),
o15("BlockBreak-Blacklist", "Main.BlockBreak Blacklisted Blocks", Arrays.asList("BEDROCK")),
o16("Rainbow-Glass", "Interfaces.Replace Glass Type 1 With Rainbow Glass", false),
o17("ECO-Icon", "Interfaces.Economy Icon", "SUNFLOWER"),
o18("XP-Icon", "Interfaces.XP Icon", "EXPERIENCE_BOTTLE"),
o19("Glass-Type-1", "Interfaces.Glass Type 1", 7),
o20("Glass-Type-2", "Interfaces.Glass Type 2", 11),
o21("Glass-Type-3", "Interfaces.Glass Type 3", 3),
o22("Debug-Mode", "System.Debugger Enabled", false);
private String setting;
private String oldSetting;
private Object option;
Setting(String oldSetting, String setting, Object option) {
this.oldSetting = oldSetting;
this.setting = setting;
this.option = option;
}
}
}

View File

@ -1,14 +1,14 @@
ECO-Icon: 'This is the default icon that will be used for the Economy upgrade button.'
XP-Icon: 'This is the default icon that will be used for the Experience upgrade button.'
Upgrading-enabled: 'Setting this to true will allow users to access the upgrade window.'
Upgrade-with-eco: 'Setting this to true will allow users to use Economy to upgrade their hoppers.'
Upgrade-with-xp: 'Setting this to true will allow users to use Experience to upgrade their hoppers.'
On-upgrade-particles: 'Setting this to true will cause particles to emit when a hopper is upgraded.'
Teleport-hoppers: 'These are the default levels, the amount of levels can be expanded if you want, just add another level to the bottom of the list while keeping numeric order. Allows you to enable or disable teleporting with hoppers'
Hop-Tick: 'This is the tick speed for synced hoppers.'
Sync-Timeout: 'This is the timeout that if reached will cancel a sync.'
Glass-Type: 'This is the id of the glass used for the background in the guis.'
Rainbow-Glass: 'If this is enabled the glass background will be randomized colors. '
Limit-Hoppers-Per-Chunk: 'If enabled this will limit the amount hoppers per chunk'
Hopper-Limit: 'This is the amount of allowed hoppers per chunk.'
Upgrade-particle-type: 'This is the type of particle an upgrade will emit.'
ECO-Icon: 'This is the default icon that will be used for the Economy upgrade button.'
XP-Icon: 'This is the default icon that will be used for the Experience upgrade button.'
Upgrading-enabled: 'Setting this to true will allow users to access the upgrade window.'
Upgrade-with-eco: 'Setting this to true will allow users to use Economy to upgrade their hoppers.'
Upgrade-with-xp: 'Setting this to true will allow users to use Experience to upgrade their hoppers.'
On-upgrade-particles: 'Setting this to true will cause particles to emit when a hopper is upgraded.'
Teleport-hoppers: 'These are the default levels, the amount of levels can be expanded if you want, just add another level to the bottom of the list while keeping numeric order. Allows you to enable or disable teleporting with hoppers'
Hop-Tick: 'This is the tick speed for synced hoppers.'
Sync-Timeout: 'This is the timeout that if reached will cancel a sync.'
Glass-Type: 'This is the id of the glass used for the background in the guis.'
Rainbow-Glass: 'If this is enabled the glass background will be randomized colors. '
Limit-Hoppers-Per-Chunk: 'If enabled this will limit the amount hoppers per chunk'
Hopper-Limit: 'This is the amount of allowed hoppers per chunk.'
Upgrade-particle-type: 'This is the type of particle an upgrade will emit.'

View File

@ -1,53 +1,53 @@
#General Messages
general.nametag.prefix = "&7[&6EpicHoppers&7]"
general.nametag.next = "&9Next"
general.nametag.back = "&9Back"
general.nametag.nameformat = "&eLevel %level% &fHopper"
#Interface Messages
interface.hopper.upgradewithxp = "&aUpgrade with XP"
interface.hopper.upgradewithxplore = "&7Cost: &a%cost% Levels"
interface.hopper.upgradewitheconomy = "&aUpgrade with ECO"
interface.hopper.upgradewitheconomylore = "&7Cost: &a$%cost%"
interface.hopper.currentlevel = "&6Hopper Level &7%level%"
interface.hopper.nextlevel = "&6Next Level &7%level%"
interface.hopper.range = "&7Range: &6%range%"
interface.hopper.amount = "&7Amount: &6%amount%"
interface.hopper.suction = "&7Suction: &6%suction%"
interface.hopper.blockbreak = "&7Block Break: &6Every %ticks% ticks"
interface.hopper.alreadymaxed = "&7This hopper is already maxed out!"
interface.hopper.synclore = "|&7Left-Click then click a another|&7hopper or chest to sync!||&7Right-Click to desync."
interface.hopper.perltitle = "&6Click to Teleport"
interface.hopper.perllore = "|&7Left-Click to teleport to|&7the end of the chain.||&7Right-Click to toggle walk|&7on teleport."
interface.hopper.filtertitle = "&cClick to Filter"
interface.hopper.filterlore = "|&7This allows you to choose|&7which items go where."
interface.hopper.synchopper = "&6Click to Sync This hopper"
interface.hopper.rejectsync = "&6Click to Sync Rejected Items"
interface.filter.infotitle = "&aFilter Guide"
interface.filter.infolore = "&7Items placed in the top left|&7space will be whitelisted.||&7Items placed in the right|&7will be void.||&7Items placed in the bottom left|&7will be blacklisted.||&cUsing the whitelist will disable|&cboth the blacklist and the void."
interface.filter.whitelist = "&f&lWhite List"
interface.filter.blacklist = "&8&lBlack List"
interface.filter.void = "&c&lVoid"
#Event Messages
event.general.nopermission = "&cYou do not have permission to do that."
event.upgrade.cannotafford = "&cYou cannot afford this upgrade."
event.upgrade.success = "&7You successfully upgraded this hopper to &6level %level%&7!"
event.upgrade.maxed = "&7You maxed out this hopper at &6level %level%&7."
event.inventory.noroom = "&7You do not have space in your inventory for this."
event.hopper.syncsuccess = "&aSynchronization Successful."
event.hopper.desync = "&7You have desynchronized this hopper."
event.hopper.syncnext = "&7Click another hopper or container to sync."
event.hopper.syncself = "&cYou can't sync a hopper to itself."
event.hopper.synctimeout = "&cSyncing timed out."
event.hopper.syncoutofrange = "&cThis block is out of your hoppers range."
event.hopper.syncdidnotplace = "&cSorry! You need to have placed this hopper to sync things to it."
event.hopper.toomany = "&cYou can only place %amount% hoppers per chunk..."
event.hopper.walkteleenabled = "Walk on teleporting has been enabled for this hopper."
event.hopper.walkteledisabled = "Walk on teleporting has been disabled for this hopper."
event.hopper.onlyone = "&cYou may only place a single item at a time."
event.hopper.syncchest = "&7You have synchronized your &9%name% &7with this chest."
#General Messages
general.nametag.prefix = "&7[&6EpicHoppers&7]"
general.nametag.next = "&9Next"
general.nametag.back = "&9Back"
general.nametag.nameformat = "&eLevel %level% &fHopper"
#Interface Messages
interface.hopper.upgradewithxp = "&aUpgrade with XP"
interface.hopper.upgradewithxplore = "&7Cost: &a%cost% Levels"
interface.hopper.upgradewitheconomy = "&aUpgrade with ECO"
interface.hopper.upgradewitheconomylore = "&7Cost: &a$%cost%"
interface.hopper.currentlevel = "&6Hopper Level &7%level%"
interface.hopper.nextlevel = "&6Next Level &7%level%"
interface.hopper.range = "&7Range: &6%range%"
interface.hopper.amount = "&7Amount: &6%amount%"
interface.hopper.suction = "&7Suction: &6%suction%"
interface.hopper.blockbreak = "&7Block Break: &6Every %ticks% ticks"
interface.hopper.alreadymaxed = "&7This hopper is already maxed out!"
interface.hopper.synclore = "|&7Left-Click then click a another|&7hopper or chest to sync!||&7Right-Click to desync."
interface.hopper.perltitle = "&6Click to Teleport"
interface.hopper.perllore = "|&7Left-Click to teleport to|&7the end of the chain.||&7Right-Click to toggle walk|&7on teleport."
interface.hopper.filtertitle = "&cClick to Filter"
interface.hopper.filterlore = "|&7This allows you to choose|&7which items go where."
interface.hopper.synchopper = "&6Click to Sync This hopper"
interface.hopper.rejectsync = "&6Click to Sync Rejected Items"
interface.filter.infotitle = "&aFilter Guide"
interface.filter.infolore = "&7Items placed in the top left|&7space will be whitelisted.||&7Items placed in the right|&7will be void.||&7Items placed in the bottom left|&7will be blacklisted.||&cUsing the whitelist will disable|&cboth the blacklist and the void."
interface.filter.whitelist = "&f&lWhite List"
interface.filter.blacklist = "&8&lBlack List"
interface.filter.void = "&c&lVoid"
#Event Messages
event.general.nopermission = "&cYou do not have permission to do that."
event.upgrade.cannotafford = "&cYou cannot afford this upgrade."
event.upgrade.success = "&7You successfully upgraded this hopper to &6level %level%&7!"
event.upgrade.maxed = "&7You maxed out this hopper at &6level %level%&7."
event.inventory.noroom = "&7You do not have space in your inventory for this."
event.hopper.syncsuccess = "&aSynchronization Successful."
event.hopper.desync = "&7You have desynchronized this hopper."
event.hopper.syncnext = "&7Click another hopper or container to sync."
event.hopper.syncself = "&cYou can't sync a hopper to itself."
event.hopper.synctimeout = "&cSyncing timed out."
event.hopper.syncoutofrange = "&cThis block is out of your hoppers range."
event.hopper.syncdidnotplace = "&cSorry! You need to have placed this hopper to sync things to it."
event.hopper.toomany = "&cYou can only place %amount% hoppers per chunk..."
event.hopper.walkteleenabled = "Walk on teleporting has been enabled for this hopper."
event.hopper.walkteledisabled = "Walk on teleporting has been disabled for this hopper."
event.hopper.onlyone = "&cYou may only place a single item at a time."
event.hopper.syncchest = "&7You have synchronized your &9%name% &7with this chest."
event.hopper.desyncchest = "&7You have desynchronized your &9%name% &7with this chest."

View File

@ -1,14 +1,14 @@
name: EpicHoppers
description: EpicHoppers
main: com.songoda.epichoppers.EpicHoppers
depend: [Arconix]
softdepend: [Towny, RedProtect, Kingdoms, PlotsSquared, GriefPrevention, USkyBlock, ASkyBlock, WorldGuard, Factions, Vault]
version: 2.4
author: Songoda
api-version: 1.13
commands:
epichoppers:
description: View information on this plugin.
default: true
aliases: [sc, eh, synccraft]
name: EpicHoppers
description: EpicHoppers
main: com.songoda.epichoppers.EpicHoppersPlugin
depend: [Arconix]
softdepend: [Towny, RedProtect, Kingdoms, PlotsSquared, GriefPrevention, USkyBlock, ASkyBlock, WorldGuard, Factions, Vault]
version: 3
author: Songoda
api-version: 1.13
commands:
epichoppers:
description: View information on this plugin.
default: true
aliases: [eh, synccraft]
usage: /eh

View File

@ -1,19 +0,0 @@
package com.songoda.epichoppers.API;
import com.songoda.epichoppers.EpicHoppers;
import org.bukkit.inventory.ItemStack;
/**
* Created by songo on 6/11/2017.
*/
public class EpicHoppersAPI {
public int getILevel(ItemStack item) {
if (item.getItemMeta().getDisplayName().contains(":")) {
String arr[] = (item.getItemMeta().getDisplayName().replace("§", "")).split(":");
return Integer.parseInt(arr[0]);
} else {
return EpicHoppers.getInstance().getLevelManager().getLowestLevel().getLevel();
}
}
}

View File

@ -1,35 +0,0 @@
package com.songoda.epichoppers.Hopper;
import java.util.Collections;
import java.util.Map;
import java.util.NavigableMap;
import java.util.TreeMap;
public class LevelManager {
private final NavigableMap<Integer, Level> registeredLevels = new TreeMap<>();
public void addLevel(int level, int costExperiance, int costEconomy, int range, int amount, int suction, int blockBreak) {
registeredLevels.put(level, new Level(level, costExperiance, costEconomy, range, amount, suction, blockBreak));
}
public Level getLevel(int level) {
return registeredLevels.get(level);
}
public Level getLowestLevel() {
return registeredLevels.firstEntry().getValue();
}
public Level getHighestLevel() {
return registeredLevels.lastEntry().getValue();
}
public Map<Integer, Level> getLevels() {
return Collections.unmodifiableMap(registeredLevels);
}
public void clear() {
registeredLevels.clear();
}
}