Compiles against 1.13

This commit is contained in:
Unknown 2018-08-07 11:07:43 -04:00
parent bd1824426b
commit 17dda9bb02
5 changed files with 118 additions and 149 deletions

View File

@ -220,17 +220,10 @@ public class Farm {
} else {
player.playSound(player.getLocation(), org.bukkit.Sound.valueOf("LEVEL_UP"), 2F, 15.0F);
}
} else {
if (!instance.v1_10 && !instance.v1_9 && !instance.v1_8 && !instance.v1_7) {
player.playSound(player.getLocation(), org.bukkit.Sound.ENTITY_PLAYER_LEVELUP, 2F, 25.0F);
player.playSound(player.getLocation(), org.bukkit.Sound.BLOCK_NOTE_CHIME, 2F, 25.0F);
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> player.playSound(player.getLocation(), org.bukkit.Sound.BLOCK_NOTE_CHIME, 1.2F, 35.0F), 5L);
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> player.playSound(player.getLocation(), org.bukkit.Sound.BLOCK_NOTE_CHIME, 1.8F, 35.0F), 10L);
} else {
player.playSound(player.getLocation(), org.bukkit.Sound.valueOf("LEVEL_UP"), 2F, 25.0F);
}
}
}
tillLand(location);
} catch (Exception ex) {
Debugger.runReport(ex);
@ -252,9 +245,9 @@ public class Farm {
Block b2 = block.getWorld().getBlockAt(bx + fx, by + fy, bz + fz);
// ToDo: enum for all flowers.
if (b2.getType() == Material.LONG_GRASS || b2.getType() == Material.RED_ROSE || b2.getType() == Material.YELLOW_FLOWER) {
if (b2.getType() == Material.TALL_GRASS || b2.getType() == Material.POPPY || b2.getType() == Material.DANDELION) {
Bukkit.getScheduler().runTaskLater(EpicFarming.getInstance(), () -> {
b2.getRelative(BlockFace.DOWN).setType(Material.SOIL);
b2.getRelative(BlockFace.DOWN).setType(Material.DIRT);
b2.breakNaturally();
if (instance.getConfig().getBoolean("Main.Sounds Enabled")) {
if (!instance.v1_7 && !instance.v1_8)
@ -266,7 +259,7 @@ public class Farm {
}
if ((b2.getType() == Material.GRASS || b2.getType() == Material.DIRT) && b2.getRelative(BlockFace.UP).getType() == Material.AIR) {
Bukkit.getScheduler().runTaskLater(EpicFarming.getInstance(), () -> {
b2.setType(Material.SOIL);
b2.setType(Material.DIRT);
if (instance.getConfig().getBoolean("Main.Sounds Enabled")) {
if (!instance.v1_7 && !instance.v1_8)
b2.getWorld().playSound(b2.getLocation(), org.bukkit.Sound.BLOCK_GRASS_BREAK, 10, 15);

View File

@ -48,7 +48,7 @@ public class GrowthHandler {
switch(cropData.getState()) {
case SEEDED:
if (!EpicFarming.pl().v1_7 && !EpicFarming.pl().v1_8) {
if (material == Material.BEETROOT_BLOCK)
if (material == Material.BEETROOT)
cropData.setState(CropState.VERY_SMALL);
else
cropData.setState(CropState.GERMINATED);

View File

@ -14,35 +14,31 @@ public class CropType {
private static List<CropTypeData> crops = new ArrayList<>();
private CropType() {
crops.add(new CropTypeData("Wheat", Material.CROPS, Material.WHEAT, Material.SEEDS));
crops.add(new CropTypeData("Carrot", Material.CARROT, Material.CARROT_ITEM, Material.CARROT_ITEM));
crops.add(new CropTypeData("Potato", Material.POTATO, Material.POTATO_ITEM, Material.POTATO_ITEM));
crops.add(new CropTypeData("Wheat", Material.WHEAT, Material.WHEAT, Material.WHEAT_SEEDS));
crops.add(new CropTypeData("Carrot", Material.CARROT, Material.CARROT, Material.CARROT));
crops.add(new CropTypeData("Potato", Material.POTATO, Material.POTATO, Material.POTATO));
crops.add(new CropTypeData("Watermelon", Material.MELON_STEM, Material.MELON, Material.MELON_SEEDS));
crops.add(new CropTypeData("Pumpkin", Material.PUMPKIN_STEM, Material.PUMPKIN, Material.PUMPKIN_SEEDS));
crops.add(new CropTypeData("Melon", Material.MELON_STEM, Material.MELON, Material.MELON_SEEDS));
if (!EpicFarming.pl().v1_8 && !EpicFarming.pl().v1_7) {
crops.add(new CropTypeData("Nether Wart", Material.NETHER_WART_BLOCK, Material.NETHER_WARTS, Material.NETHER_WARTS));
crops.add(new CropTypeData("Beetroot", Material.BEETROOT_BLOCK, Material.BEETROOT, Material.BEETROOT_SEEDS));
}
crops.add(new CropTypeData("Nether Wart", Material.NETHER_WART_BLOCK, Material.NETHER_WART, Material.NETHER_WART));
crops.add(new CropTypeData("Beetroot", Material.BEETROOT, Material.BEETROOT, Material.BEETROOT_SEEDS));
}
private void handleAdd() {
if (crops.size() < 1) {
crops.add(new CropTypeData("Wheat", Material.CROPS, Material.WHEAT, Material.SEEDS));
crops.add(new CropTypeData("Carrot", Material.CARROT, Material.CARROT_ITEM, Material.CARROT_ITEM));
crops.add(new CropTypeData("Potato", Material.POTATO, Material.POTATO_ITEM, Material.POTATO_ITEM));
crops.add(new CropTypeData("Wheat", Material.WHEAT, Material.WHEAT, Material.WHEAT_SEEDS));
crops.add(new CropTypeData("Carrot", Material.CARROT, Material.CARROT, Material.CARROT));
crops.add(new CropTypeData("Potato", Material.POTATO, Material.POTATO, Material.POTATO));
crops.add(new CropTypeData("Watermelon", Material.MELON_STEM, Material.MELON, Material.MELON_SEEDS));
crops.add(new CropTypeData("Pumpkin", Material.PUMPKIN_STEM, Material.PUMPKIN, Material.PUMPKIN_SEEDS));
crops.add(new CropTypeData("Melon", Material.MELON_STEM, Material.MELON, Material.MELON_SEEDS));
if (!EpicFarming.pl().v1_8 && !EpicFarming.pl().v1_7) {
crops.add(new CropTypeData("Nether Wart", Material.NETHER_WART_BLOCK, Material.NETHER_WARTS, Material.NETHER_WARTS));
crops.add(new CropTypeData("Beetroot", Material.BEETROOT_BLOCK, Material.BEETROOT, Material.BEETROOT_SEEDS));
}
}
crops.add(new CropTypeData("Nether Wart", Material.NETHER_WART_BLOCK, Material.NETHER_WART, Material.NETHER_WART));
crops.add(new CropTypeData("Beetroot", Material.BEETROOT, Material.BEETROOT, Material.BEETROOT_SEEDS)); }
}
public static boolean isCrop(Material material) {
for (CropTypeData type : values())
if (type.getBlockMaterial() == material) return true;

View File

@ -1,11 +1,13 @@
package com.songoda.epicfarming.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.epicfarming.EpicFarming;
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;
@ -15,10 +17,7 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -28,180 +27,160 @@ import java.util.regex.Pattern;
public class SettingsManager implements Listener {
private String pluginName = "EpicFarming";
private final EpicFarming instance;
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<>();
public SettingsManager(EpicFarming instance) {
this.instance = instance;
instance.saveResource("SettingDefinitions.yml", true);
defs = new ConfigWrapper(instance, "", "SettingDefinitions.yml");
defs.createNewFile("Loading data file", "EpicFarming SettingDefinitions file");
instance.getServer().getPluginManager().registerEvents(this, instance);
private final EpicFarming instance;
public SettingsManager(EpicFarming 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);
}
public Map<Player, String> current = new HashMap<>();
private Map<Player, String> current = new HashMap<>();
@EventHandler
public void onInventoryClick(InventoryClickEvent e) {
if (e.getInventory() == null
|| e.getCurrentItem() == null
|| !e.getCurrentItem().hasItemMeta()
|| !e.getCurrentItem().getItemMeta().hasDisplayName()
|| e.getWhoClicked().getOpenInventory().getTopInventory() != e.getInventory()) {
return;
}
if (e.getInventory().getTitle().equals(pluginName + " Settings Manager")) {
public void onInventoryClick(InventoryClickEvent event) {
ItemStack clickedItem = event.getCurrentItem();
if (e.getCurrentItem().getType().equals(Material.STAINED_GLASS_PANE)) {
e.setCancelled(true);
if (event.getInventory() != event.getWhoClicked().getOpenInventory().getTopInventory()
|| clickedItem == null || !clickedItem.hasItemMeta()
|| !clickedItem.getItemMeta().hasDisplayName()) {
return;
}
String type = ChatColor.stripColor(e.getCurrentItem().getItemMeta().getDisplayName());
cat.put((Player) e.getWhoClicked(), type);
openEditor((Player) e.getWhoClicked());
e.setCancelled(true);
} else if (e.getInventory().getTitle().equals(pluginName + " Settings Editor")) {
if (event.getInventory().getTitle().equals(pluginName + " Settings Manager")) {
event.setCancelled(true);
if (clickedItem.getType().name().contains("STAINED_GLASS")) return;
if (e.getCurrentItem().getType().equals(Material.STAINED_GLASS_PANE)) {
e.setCancelled(true);
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 p = (Player) e.getWhoClicked();
e.setCancelled(true);
Player player = (Player) event.getWhoClicked();
String key = cat.get(p) + "." + ChatColor.stripColor(e.getCurrentItem().getItemMeta().getDisplayName());
String key = cat.get(player) + "." + ChatColor.stripColor(clickedItem.getItemMeta().getDisplayName());
if (instance.getConfig().get(key).getClass().getName().equals("java.lang.Boolean")) {
boolean bool = (Boolean) instance.getConfig().get(key);
if (!bool)
instance.getConfig().set(key, true);
else
instance.getConfig().set(key, false);
finishEditing(p);
this.instance.getConfig().set(key, !instance.getConfig().getBoolean(key));
this.finishEditing(player);
} else {
editObject(p, key);
this.editObject(player, key);
}
}
}
@EventHandler
public void onChat(AsyncPlayerChatEvent e) {
final Player p = e.getPlayer();
if (!current.containsKey(p)) {
return;
}
switch (instance.getConfig().get(current.get(p)).getClass().getName()) {
case "java.lang.Integer":
instance.getConfig().set(current.get(p), Integer.parseInt(e.getMessage()));
break;
case "java.lang.Double":
instance.getConfig().set(current.get(p), Double.parseDouble(e.getMessage()));
break;
case "java.lang.String":
instance.getConfig().set(current.get(p), e.getMessage());
break;
}
finishEditing(p);
e.setCancelled(true);
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());
}
public void finishEditing(Player p) {
current.remove(p);
instance.saveConfig();
openEditor(p);
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 p, String current) {
this.current.put(p, ChatColor.stripColor(current));
p.closeInventory();
p.sendMessage("");
p.sendMessage(Arconix.pl().getApi().format().formatText("&7Please enter a value for &6" + current + "&7."));
if (instance.getConfig().get(current).getClass().getName().equals("java.lang.Integer")) {
p.sendMessage(Arconix.pl().getApi().format().formatText("&cUse only numbers."));
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."));
}
p.sendMessage("");
player.sendMessage("");
}
public void openSettingsManager(Player p) {
Inventory i = Bukkit.createInventory(null, 27, pluginName + " Settings Manager");
int nu = 0;
while (nu != 27) {
i.setItem(nu, Methods.getGlass());
nu++;
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 spot = 10;
for (String key : instance.getConfig().getConfigurationSection("").getKeys(false)) {
ItemStack item = new ItemStack(Material.WOOL, 1, (byte) (spot - 9));
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(Arconix.pl().getApi().format().formatText("&6Click To Edit This Category.")));
meta.setDisplayName(Arconix.pl().getApi().format().formatText("&f&l" + key));
meta.setLore(Collections.singletonList(TextComponent.formatText("&6Click To Edit This Category.")));
meta.setDisplayName(TextComponent.formatText("&f&l" + key));
item.setItemMeta(meta);
i.setItem(spot, item);
spot++;
}
p.openInventory(i);
inventory.setItem(slot, item);
slot++;
}
public void openEditor(Player p) {
Inventory i = Bukkit.createInventory(null, 54, pluginName + " Settings Editor");
player.openInventory(inventory);
}
int num = 0;
for (String key : instance.getConfig().getConfigurationSection(cat.get(p)).getKeys(true)) {
String fKey = cat.get(p) + "." + key;
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(Arconix.pl().getApi().format().formatText("&6" + key));
ArrayList<String> lore = new ArrayList<>();
switch (instance.getConfig().get(fKey).getClass().getName()) {
case "java.lang.Boolean":
meta.setDisplayName(TextComponent.formatText("&6" + key));
List<String> lore = new ArrayList<>();
if (config.isBoolean(fKey)) {
item.setType(Material.LEVER);
boolean bool = (Boolean) instance.getConfig().get(fKey);
if (!bool)
lore.add(Arconix.pl().getApi().format().formatText("&c" + false));
else
lore.add(Arconix.pl().getApi().format().formatText("&a" + true));
break;
case "java.lang.String":
lore.add(TextComponent.formatText(config.getBoolean(fKey) ? "&atrue" : "&cfalse"));
} else if (config.isString(fKey)) {
item.setType(Material.PAPER);
String str = (String) instance.getConfig().get(fKey);
lore.add(Arconix.pl().getApi().format().formatText("&9" + str));
break;
case "java.lang.Integer":
item.setType(Material.WATCH);
int in = (Integer) instance.getConfig().get(fKey);
lore.add(Arconix.pl().getApi().format().formatText("&5" + in));
break;
default:
continue;
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);
Pattern regex = Pattern.compile("(.{1,28}(?:\\s|$))|(.{0,28})", Pattern.DOTALL);
Matcher m = regex.matcher(text);
Matcher m = SETTINGS_PATTERN.matcher(text);
while (m.find()) {
if (m.end() != text.length() || m.group().length() != 0)
lore.add(Arconix.pl().getApi().format().formatText("&7" + m.group()));
lore.add(TextComponent.formatText("&7" + m.group()));
}
}
meta.setLore(lore);
item.setItemMeta(meta);
i.setItem(num, item);
num++;
inventory.setItem(slot, item);
slot++;
}
p.openInventory(i);
player.openInventory(inventory);
}
public void updateSettings() {

View File

@ -5,6 +5,7 @@ version: 1.3.2
depend: [Arconix]
soft-depend: [Multiverse-Core]
author: Songoda
api-version: 1.13
commands:
EpicFarming:
description: View information on this plugin.