Fixed some bugs

This commit is contained in:
Niels Vergucht 2018-12-06 01:32:12 +01:00
parent 3d1090201e
commit 74906bc780
21 changed files with 771 additions and 69 deletions

View File

@ -99,7 +99,7 @@
<groupId>me.lucko</groupId>
<artifactId>helper</artifactId>
<version>LATEST</version>
<scope>provided</scope>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.github.tr7zw</groupId>

View File

@ -6,14 +6,19 @@ import com.songoda.epicbuckets.file.ConfigManager;
import com.songoda.epicbuckets.genbucket.GenbucketManager;
import com.songoda.epicbuckets.listener.GenbucketPlaceListener;
import com.songoda.epicbuckets.shop.ShopManager;
import com.songoda.epicbuckets.util.ChatUtil;
import com.songoda.epicbuckets.util.Debugger;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
public class EpicBuckets extends JavaPlugin {
private static EpicBuckets instance;
private static CommandSender console = Bukkit.getConsoleSender();
private ConfigManager configManager;
private ShopManager shopManager;
@ -22,12 +27,25 @@ public class EpicBuckets extends JavaPlugin {
private Economy econ;
private PaperCommandManager commandManager;
private Locale locale;
public static EpicBuckets getInstance() { return instance; }
@Override
public void onEnable() {
console.sendMessage(ChatUtil.colorString("&a============================="));
console.sendMessage(ChatUtil.colorString("&7EpicBuckets " + this.getDescription().getVersion() + " by &5Songoda <3!"));
console.sendMessage(ChatUtil.colorString("&7Action: &aEnabling&7..."));
instance = this;
if (!isEnabled()) {
return;
}
Locale.init(this);
Locale.saveDefaultLocale("en_US");
this.locale = Locale.getLocale(getConfig().getString("Locale", "en_US"));
debugger = new Debugger();
configManager = new ConfigManager();
shopManager = new ShopManager();
@ -40,11 +58,34 @@ public class EpicBuckets extends JavaPlugin {
getServer().getPluginManager().registerEvents(new GenbucketPlaceListener(), this);
setupEconomy();
console.sendMessage(ChatUtil.colorString("&a============================="));
}
@Override
public void onDisable() {
console.sendMessage(ChatUtil.colorString("&a============================="));
console.sendMessage(ChatUtil.colorString("&7EpicBuckets " + this.getDescription().getVersion() + " by &5Songoda <3!"));
console.sendMessage(ChatUtil.colorString("&7Action: &cDisabling&7..."));
console.sendMessage(ChatUtil.colorString("&a============================="));
}
public void reload() {
this.locale.reloadMessages();
this.getConfigManager().reload();
this.getShopManager().reload();
}
public double getBalance(Player player) {
return econ.getBalance(player);
}
public void withdrawBalance(Player player, int amount, boolean sendMessage) {
if (sendMessage)
player.sendMessage(locale.getMessage("interface.withdrawl.success").replace("{amount}", String.valueOf(amount)));
econ.withdrawPlayer(player, amount);
}
private boolean setupEconomy() {
@ -79,4 +120,8 @@ public class EpicBuckets extends JavaPlugin {
return econ;
}
public Locale getLocale() {
return locale;
}
}

View File

@ -0,0 +1,364 @@
package com.songoda.epicbuckets;
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+(?:\\.{1}\\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

@ -2,20 +2,43 @@ package com.songoda.epicbuckets.command;
import co.aikar.commands.BaseCommand;
import co.aikar.commands.annotation.CommandAlias;
import co.aikar.commands.annotation.CommandPermission;
import co.aikar.commands.annotation.Description;
import co.aikar.commands.annotation.Subcommand;
import com.songoda.epicbuckets.EpicBuckets;
import com.songoda.epicbuckets.gui.GUIMain;
import com.songoda.epicbuckets.util.ChatUtil;
import org.bukkit.entity.Player;
@CommandAlias("genbucket")
public class CommandGenbucket extends BaseCommand {
private EpicBuckets epicBuckets;
public CommandGenbucket() {
epicBuckets = EpicBuckets.getInstance();
}
public boolean permCheck(Player player, String perm) {
if (!player.hasPermission(perm)) {
player.sendMessage(epicBuckets.getLocale().getMessage("event.general.nopermission"));
return false;
}
return true;
}
@Subcommand("shop")
@Description("Opens up the Genbucket shop")
@CommandPermission("genbucket.shop")
public void shop(Player player) {
if (!permCheck(player, "genbucket.shop")) return;
new GUIMain(player).open();
}
@Subcommand("reload")
@Description("Reloads the messages & config files")
public void reload(Player player) {
if (!permCheck(player, "genbucket.reload")) return;
epicBuckets.reload();
player.sendMessage(ChatUtil.colorPrefix(epicBuckets.getLocale().getMessage("command.reload.success")));
}
}

View File

@ -25,8 +25,8 @@ public class ConfigManager {
private String bulkShopPurchasePath = "BULK-SHOP-INVENTORY.purchase-item";
private String menuItemsPath = "MENU-ITEMS";
private List<String> ignoredMaterials;
private List<String> psuedoMaterials;
private List<XMaterial> ignoredMaterials;
private List<XMaterial> psuedoMaterials;
private LinkedHashMap<String, Integer> genbucketGroups;
@ -53,25 +53,34 @@ public class ConfigManager {
public ConfigManager() {
this.epicBuckets = EpicBuckets.getInstance();
ignoredMaterials = new ArrayList<>();
psuedoMaterials = new ArrayList<>();
configDatabase = new HashMap<>();
genbucketGroups = new LinkedHashMap<>();
setup();
}
private void setup() {
epicBuckets.saveDefaultConfig();
configDatabase = new HashMap<>();
loadData();
createConfig("shops", true);
setupBackButton();
setupFillItem();
}
public void reload() {
reloadConfig("shops");
epicBuckets.reloadConfig();
loadData();
setupBackButton();
setupFillItem();
}
private void loadData() {
ignoredMaterials = epicBuckets.getConfig().getStringList("IGNORE-MATERIALS");
ignoredMaterials = new ArrayList<>();
psuedoMaterials = new ArrayList<>();
genbucketGroups = new LinkedHashMap<>();
ignoredMaterials = InventoryHelper.convertMaterialList(epicBuckets.getConfig().getStringList("IGNORE-MATERIALS"));
psuedoMaterials = InventoryHelper.convertMaterialList(epicBuckets.getConfig().getStringList("PSUEDO-MATERIALS"));
supportFactions = epicBuckets.getConfig().getBoolean("FACTIONS-SUPPORT");
supportWorldGuard = epicBuckets.getConfig().getBoolean("WORLDGUARD-SUPPORT");
supportGriefPrevention = epicBuckets.getConfig().getBoolean("GRIEFPREVENTION-SUPPORT");
@ -140,11 +149,11 @@ public class ConfigManager {
return bulkShopPurchasePath;
}
public List<String> getIgnoredMaterials() {
public List<XMaterial> getIgnoredMaterials() {
return ignoredMaterials;
}
public List<String> getPsuedoMaterials() {
public List<XMaterial> getPsuedoMaterials() {
return psuedoMaterials;
}

View File

@ -42,6 +42,10 @@ public abstract class Genbucket {
return genUUID;
}
public GenbucketType getGenbucketType() {
return genbucketType;
}
public boolean isValidBlockFace() {
switch(genbucketType) {
case VERTICAL:
@ -57,6 +61,11 @@ public abstract class Genbucket {
}
}
protected boolean isBelowVoid(int moved) {
if (blockFace != BlockFace.DOWN) return false;
return clickedBlock.getRelative(0, -moved, 0).getLocation().getBlockY() == 0;
}
protected Block getNextBlock(int moved, BlockFace blockFace) {
return clickedBlock.getRelative(blockFace).getRelative(0, moved, 0);
}
@ -71,7 +80,7 @@ public abstract class Genbucket {
}
protected boolean placeGen(Block block) {
if (!epicBuckets.getConfigManager().getIgnoredMaterials().contains(block.getType().name())) return false;
if (!epicBuckets.getConfigManager().getIgnoredMaterials().contains(XMaterial.requestXMaterial(block.getType().name(), block.getData()))) return false;
block.setType(getGenItem().getType());
return true;
}

View File

@ -1,29 +0,0 @@
package com.songoda.epicbuckets.genbucket;
import org.bukkit.Location;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import java.util.UUID;
public class GenbucketItem {
private UUID genUUID;
private Player owner;
private Genbucket genbucket;
private Location locationPlaced;
private BlockFace blockFace;
public GenbucketItem(Player owner, Genbucket genbucket, Location locationPlaced, BlockFace blockFace) {
this.genUUID = UUID.randomUUID();
this.owner = owner;
this.genbucket = genbucket;
this.locationPlaced = locationPlaced;
this.blockFace = blockFace;
}
public UUID getGenUUID() {
return genUUID;
}
}

View File

@ -1,10 +1,14 @@
package com.songoda.epicbuckets.genbucket;
import com.songoda.epicbuckets.EpicBuckets;
import com.songoda.epicbuckets.regionhandler.RegionFactions;
import com.songoda.epicbuckets.regionhandler.RegionGriefPrevention;
import com.songoda.epicbuckets.regionhandler.RegionWorldBorder;
import com.songoda.epicbuckets.regionhandler.RegionWorldGuard;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import java.util.*;
import java.util.stream.Collectors;
public class GenbucketManager {
@ -44,4 +48,19 @@ public class GenbucketManager {
return epicBuckets.getConfigManager().getMaxGenbucketsPerPlayer();
}
public boolean canPlaceGenbucket(Player player, Location location) {
boolean factionsCheck = RegionFactions.canBuild(player, location);
boolean factionsUUIDCheck = RegionFactions.canBuild(player, location);
boolean griefPreventionCheck = RegionGriefPrevention.canBuild(player, location);
boolean worldGuardCheck = RegionWorldGuard.canBuild(player, location);
boolean worldBorderCheck = RegionWorldBorder.isOutsideOfBorder(location);
if (!factionsCheck || !factionsUUIDCheck || !griefPreventionCheck || !worldGuardCheck || worldBorderCheck) {
player.sendMessage(epicBuckets.getLocale().getMessage("event.place.nothere"));
return false;
}
return true;
}
}

View File

@ -22,7 +22,7 @@ public class PsuedoVertical extends Genbucket {
new BukkitRunnable() {
@Override
public void run() {
if (blocksUp >= epicBuckets.getConfigManager().getMaxVerticalHeight()) {
if (isBelowVoid(blocksUp) || blocksUp >= epicBuckets.getConfigManager().getMaxVerticalHeight()) {
epicBuckets.getGenbucketManager().unregisterGenbucketForPlayer(getOwner(), getGenUUID());
cancel();
}

View File

@ -22,7 +22,7 @@ public class Vertical extends Genbucket {
new BukkitRunnable() {
@Override
public void run() {
if (blocksPlaced >= epicBuckets.getConfigManager().getMaxVerticalHeight() || !placeGen(getNextBlock())) {
if (isBelowVoid(blocksPlaced) || blocksPlaced >= epicBuckets.getConfigManager().getMaxVerticalHeight() || !placeGen(getNextBlock())) {
epicBuckets.getGenbucketManager().unregisterGenbucketForPlayer(getOwner(), getGenUUID());
cancel();
}

View File

@ -65,7 +65,7 @@ public class GUIBulk extends Gui {
}
public void handleBuy() {
if (shopManager.hasEnoughFunds(getPlayer(), subShop, getSlot(shopManager.getBulkMainItemSlot()).getItem().getAmount())) shopManager.buyFromShop(getPlayer(), subShop, getSlot(shopManager.getBulkMainItemSlot()).getItem().getAmount());
if (shopManager.hasEnoughFunds(getPlayer(), subShop, getSlot(shopManager.getBulkMainItemSlot()).getItem().getAmount()) && !shopManager.inventoryFull(getPlayer())) shopManager.buyFromShop(getPlayer(), subShop, getSlot(shopManager.getBulkMainItemSlot()).getItem().getAmount());
if (shopManager.isCloseAfterPurchase()) new GUIMain(getPlayer()).open();
}

View File

@ -52,7 +52,8 @@ public class GUIShop extends Gui {
}
private void handleSubShop(SubShop s) {
if (shopManager.hasEnoughFunds(getPlayer(), s, 1)) shopManager.buyFromShop(getPlayer(), s, 1);
if (shopManager.hasEnoughFunds(getPlayer(), s, 1) && !shopManager.inventoryFull(getPlayer())) shopManager.buyFromShop(getPlayer(), s, 1);
if (shopManager.isCloseAfterPurchase()) new GUIMain(getPlayer()).open();
}
}

View File

@ -2,13 +2,15 @@ package com.songoda.epicbuckets.listener;
import com.songoda.epicbuckets.EpicBuckets;
import com.songoda.epicbuckets.genbucket.Genbucket;
import com.songoda.epicbuckets.genbucket.GenbucketItem;
import com.songoda.epicbuckets.genbucket.GenbucketType;
import com.songoda.epicbuckets.genbucket.types.Horizontal;
import com.songoda.epicbuckets.genbucket.types.Infused;
import com.songoda.epicbuckets.genbucket.types.PsuedoVertical;
import com.songoda.epicbuckets.genbucket.types.Vertical;
import com.songoda.epicbuckets.util.XMaterial;
import de.tr7zw.itemnbtapi.NBTItem;
import org.apache.commons.lang.StringUtils;
import org.bukkit.GameMode;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
@ -42,9 +44,22 @@ public class GenbucketPlaceListener implements Listener {
e.setCancelled(true);
if (!e.getPlayer().hasPermission("genbucket.place")) return;
if (epicBuckets.getConfigManager().isGenbucketsDisabled()) return;
if (!epicBuckets.getGenbucketManager().canRegisterNewGenbucket(e.getPlayer())) return;
if (!e.getPlayer().hasPermission("genbucket.place")) {
e.getPlayer().sendMessage(epicBuckets.getLocale().getMessage("event.place.nothere"));
return;
}
if (epicBuckets.getConfigManager().isGenbucketsDisabled()) {
e.getPlayer().sendMessage(epicBuckets.getLocale().getMessage("event.genbucket.disabled"));
return;
}
if (!epicBuckets.getGenbucketManager().canRegisterNewGenbucket(e.getPlayer())) {
e.getPlayer().sendMessage(epicBuckets.getLocale().getMessage("event.place.wait"));
return;
}
if (!epicBuckets.getGenbucketManager().canPlaceGenbucket(e.getPlayer(), e.getClickedBlock().getLocation())) {
e.getPlayer().sendMessage(epicBuckets.getLocale().getMessage("event.place.nothere"));
return;
}
Genbucket genbucket = null;
@ -62,9 +77,23 @@ public class GenbucketPlaceListener implements Listener {
genbucket = new Horizontal(e.getPlayer(), e.getClickedBlock(), e.getBlockFace(), epicBuckets.getShopManager().getShop(nbtItem.getString("Shop")).getSubShop(nbtItem.getString("SubShop")));
}
if (!genbucket.isValidBlockFace()) return;
if (!genbucket.isValidBlockFace()) {
e.getPlayer().sendMessage(epicBuckets.getLocale().getMessage("event.genbucket.placedwrong").replace("%genbucket%", StringUtils.capitalize(genbucket.getGenbucketType().name.toLowerCase()) + " genbucket"));
return;
}
if (genbucket.getGenbucketType() == GenbucketType.PSUEDO && !epicBuckets.getConfigManager().getPsuedoMaterials().contains(XMaterial.requestXMaterial(e.getClickedBlock().getType().name(), e.getClickedBlock().getData()))) {
e.getPlayer().sendMessage(epicBuckets.getLocale().getMessage("event.genbucket.wrongmaterialpsuedo"));
return;
}
if (e.getPlayer().getGameMode() != GameMode.CREATIVE || !epicBuckets.getConfigManager().isUnlimitedGenbuckets()) {
if (e.getItem().getAmount() > 1) {
e.getItem().setAmount(e.getItem().getAmount() - 1);
} else {
e.getItem().setAmount(0);
}
}
//GenbucketItem genbucketItem = new GenbucketItem(e.getPlayer(), genbucket, e.getClickedBlock().getLocation(), e.getBlockFace());
epicBuckets.getGenbucketManager().registerGenbucketForPlayer(e.getPlayer(), genbucket);
genbucket.generate();
}

View File

@ -0,0 +1,28 @@
package com.songoda.epicbuckets.regionhandler;
import com.songoda.epicbuckets.EpicBuckets;
import me.markeh.factionsframework.entities.Faction;
import me.markeh.factionsframework.entities.Factions;
import org.bukkit.Location;
import org.bukkit.entity.Player;
public class RegionFactions {
public static boolean canBuild(Player player, Location location) {
if (!EpicBuckets.getInstance().getConfigManager().isSupportFactions())
return true;
Faction factionAt = Factions.getFactionAt(location);
boolean enableGensInWilderness = EpicBuckets.getInstance().getConfigManager().isGensInWilderness();
if (factionAt.isNone()) {
return enableGensInWilderness;
}
return false;
}
}

View File

@ -0,0 +1,35 @@
package com.songoda.epicbuckets.regionhandler;
import com.songoda.epicbuckets.EpicBuckets;
import me.ryanhamshire.GriefPrevention.GriefPrevention;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
public class RegionGriefPrevention {
public static GriefPrevention getGriefPrevention() {
Plugin pl = EpicBuckets.getInstance().getServer().getPluginManager().getPlugin("GriefPrevention");
if (pl == null) {
EpicBuckets.getInstance().getLogger().warning("GriefPrevention support is enabled but cannot find the plugin");
return null;
}
return (GriefPrevention) pl;
}
public static boolean canBuild(Player player, Location location) {
boolean isGriefPreventionEnabled = EpicBuckets.getInstance().getConfigManager().isSupportGriefPrevention();
// If we don't check for griefprevention, just let them place
if (!isGriefPreventionEnabled)
return true;
if (getGriefPrevention() == null) return true;
return getGriefPrevention().allowBreak(player, location.getBlock(), location) != null;
}
}

View File

@ -0,0 +1,21 @@
package com.songoda.epicbuckets.regionhandler;
import com.songoda.epicbuckets.EpicBuckets;
import org.bukkit.Location;
import org.bukkit.WorldBorder;
public class RegionWorldBorder {
public static boolean isOutsideOfBorder(Location loc) {
if (EpicBuckets.getInstance().getServer().getVersion().contains("1.7"))
return true;
WorldBorder border = loc.getWorld().getWorldBorder();
double size = border.getSize() / 2;
Location center = border.getCenter();
double x = loc.getX() - center.getX(), z = loc.getZ() - center.getZ();
return ((x > size || (-x) > size) || (z > size || (-z) > size));
}
}

View File

@ -0,0 +1,43 @@
package com.songoda.epicbuckets.regionhandler;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.songoda.epicbuckets.EpicBuckets;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
public class RegionWorldGuard {
public static WorldGuardPlugin getWorldGuard() {
// WorldGuard may not be loaded
Plugin plugin = EpicBuckets.getInstance().getServer().getPluginManager().getPlugin("WorldGuard");
if (plugin == null || !(plugin instanceof WorldGuardPlugin)) {
return null; // Maybe you want throw an exception instead
}
return (WorldGuardPlugin) plugin;
}
public static boolean canBuild(Player player, Location loc) {
boolean isWorldGuardEnabled = EpicBuckets.getInstance().getConfigManager().isSupportWorldGuard();
if (!isWorldGuardEnabled) return true;
if (getWorldGuard() == null) return true;
RegionManager regionManager = getWorldGuard().getRegionManager(player.getLocation().getWorld());
ApplicableRegionSet set = regionManager.getApplicableRegions(loc);
for (ProtectedRegion region : set) {
return false;
}
return true;
}
}

View File

@ -1,10 +1,7 @@
package com.songoda.epicbuckets.shop;
import com.songoda.epicbuckets.EpicBuckets;
import com.songoda.epicbuckets.util.InventoryHelper;
import com.songoda.epicbuckets.util.NBTHelper;
import com.songoda.epicbuckets.util.Validator;
import com.songoda.epicbuckets.util.XMaterial;
import com.songoda.epicbuckets.util.*;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
@ -28,7 +25,7 @@ public class ShopManager {
private List<Integer> increaseSlots;
private List<Integer> decreaseSlots;
private List<Integer> bulkAmounts = new ArrayList<>(Arrays.asList(1, 5, 10));
private List<Integer> bulkAmounts = new ArrayList<>(Arrays.asList(1, 10, 64));
private int purchaseSlot;
private String bulkInventoryName;
@ -42,18 +39,22 @@ public class ShopManager {
public ShopManager() {
epicBuckets = EpicBuckets.getInstance();
shopDatabase = new HashMap<>();
increaseSlots = new ArrayList<>();
decreaseSlots = new ArrayList<>();
shops = EpicBuckets.getInstance().getConfigManager().getConfig("shops");
}
public void init() {
shops = epicBuckets.getConfigManager().getConfig("shops");
shopDatabase = new HashMap<>();
increaseSlots = new ArrayList<>();
decreaseSlots = new ArrayList<>();
loadData();
loadShops();
setupBulkShop();
}
public void reload() {
init();
}
private void setupBulkShop() {
boolean i = Validator.isMaterial(epicBuckets.getConfigManager().getBulkShopIncreasePath() + ".material");
boolean d = Validator.isMaterial(epicBuckets.getConfigManager().getBulkShopDecreasePath() + ".material");
@ -99,8 +100,17 @@ public class ShopManager {
}
}
public boolean inventoryFull(Player buyer) {
if (buyer.getInventory().firstEmpty() == -1) {
buyer.sendMessage(ChatUtil.colorPrefix(epicBuckets.getLocale().getMessage("event.purchase.inventoryfull")));
return true;
}
return false;
}
public boolean hasEnoughFunds(Player buyer, SubShop s, int amount) {
if (epicBuckets.getEcon().getBalance(Bukkit.getOfflinePlayer(buyer.getUniqueId())) >= (s.getPrice() * amount)) return true;
buyer.sendMessage(ChatUtil.colorPrefix(epicBuckets.getLocale().getMessage("event.purchase.notenoughmoney").replace("%money%", (s.getPrice() * amount) - epicBuckets.getBalance(buyer) + "")));
return false;
}

View File

@ -0,0 +1,93 @@
package com.songoda.epicbuckets.util;
import com.songoda.epicbuckets.EpicBuckets;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.StringJoiner;
/**
* ChatUtil created by: SoFocused
* Date Created: oktober 02 2018
* Time created: 22:54
*/
public class ChatUtil {
public static String colorPrefix(String msg) {
return ChatColor.translateAlternateColorCodes('&', getPrefix() + msg);
}
public static String colorString(String msg) {
return ChatColor.translateAlternateColorCodes('&', msg);
}
public static List<String> colorList(List<String> list) {
List<String> newList = new ArrayList<>();
list.forEach(string -> newList.add(colorString(string)));
return newList;
}
public static List<String> colorList(List<String> list, Material material, int price) {
List<String> newList = new ArrayList<>();
list.forEach(string -> newList.add(colorString(string.replace("{material}", properMaterialName(material).toLowerCase()).replace("{price}", String.valueOf(price)))));
return newList;
}
public static String stripColor(String input) {
return ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', input));
}
public static String getPrefix() {
return EpicBuckets.getInstance().getLocale().getMessage("general.nametag.prefix").equals("none") ? "" : EpicBuckets.getInstance().getLocale().getMessage("general.nametag.prefix") + " ";
}
public static void debugMSG(Player player, Object... args) {
StringJoiner stringBuilder = new StringJoiner("§8:");
for (int i = 0; i < args.length; i++)
stringBuilder.add("§a" + args[i].toString());
player.sendMessage(stringBuilder.toString());
}
public static String getCoordinatesFromLocation(Location l) {
return "X: " + l.getBlockX() + " Y: " + l.getBlockY() + " Z: " + l.getBlockZ();
}
public static String properMaterialName(Material material) {
String materialName;
if (material.name().split("_").length > 1) {
StringJoiner stringJoiner = new StringJoiner(" ");
for (String str : material.name().split("_"))
stringJoiner.add(str);
materialName = stringJoiner.toString();
} else
materialName = material.name();
return materialName;
}
}

View File

@ -2,17 +2,23 @@ package com.songoda.epicbuckets.util;
import com.songoda.epicbuckets.EpicBuckets;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class InventoryHelper {
public static List<XMaterial> convertMaterialList(List<String> toConvert) {
List<XMaterial> converted = new ArrayList<>();
toConvert.forEach(s -> converted.add(XMaterial.valueOf(s.toUpperCase())));
return converted;
}
public static int[] emptySlots(int size) {
List<Integer> slots = new ArrayList<>();
IntStream.range(0, size).forEach(slots::add);

View File

@ -5,9 +5,6 @@ general.nametag.prefix = "&8[&6EpicBuckets&8]"
#Command Messages
command.reload.success = "&7You've reloaded the config"
command.admin.on = "&7You have toggled admin-mode &aon"
command.admin.off = "&7You have toggled admin-mode &coff"
command.settings.modify = "&7You've set &e%setting%&7 to &e%value%"
#Interface Messages
@ -25,6 +22,5 @@ event.place.wait = "&7You must &ewait&7 before your other gen(s) finishes!"
event.translate.directionup = "on top of blocks"
event.translate.directionside = "on the side of blocks"
event.genbucket.disabled = "&eGenbuckets &7are currently disabled!"
event.genbucket.placedwrong = "&e%genbucket% &7can be placed %direction%"
event.genbucket.wrongmaterialpsuedo = "&7You cannot use this genbucket on this &eblock!"
event.admin.playerplaced = "&e%player% &7placed a &e%type% genbucket&7!"
event.genbucket.placedwrong = "&e%genbucket% &7cant be placed on that side of the block!"
event.genbucket.wrongmaterialpsuedo = "&7You cannot use the psuedo bucket on this &eblock!"