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 { } else {
player.playSound(player.getLocation(), org.bukkit.Sound.valueOf("LEVEL_UP"), 2F, 15.0F); 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 { } else {
player.playSound(player.getLocation(), org.bukkit.Sound.valueOf("LEVEL_UP"), 2F, 25.0F); player.playSound(player.getLocation(), org.bukkit.Sound.valueOf("LEVEL_UP"), 2F, 25.0F);
} }
} }
}
tillLand(location); tillLand(location);
} catch (Exception ex) { } catch (Exception ex) {
Debugger.runReport(ex); Debugger.runReport(ex);
@ -252,9 +245,9 @@ public class Farm {
Block b2 = block.getWorld().getBlockAt(bx + fx, by + fy, bz + fz); Block b2 = block.getWorld().getBlockAt(bx + fx, by + fy, bz + fz);
// ToDo: enum for all flowers. // 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(), () -> { Bukkit.getScheduler().runTaskLater(EpicFarming.getInstance(), () -> {
b2.getRelative(BlockFace.DOWN).setType(Material.SOIL); b2.getRelative(BlockFace.DOWN).setType(Material.DIRT);
b2.breakNaturally(); b2.breakNaturally();
if (instance.getConfig().getBoolean("Main.Sounds Enabled")) { if (instance.getConfig().getBoolean("Main.Sounds Enabled")) {
if (!instance.v1_7 && !instance.v1_8) 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) { if ((b2.getType() == Material.GRASS || b2.getType() == Material.DIRT) && b2.getRelative(BlockFace.UP).getType() == Material.AIR) {
Bukkit.getScheduler().runTaskLater(EpicFarming.getInstance(), () -> { Bukkit.getScheduler().runTaskLater(EpicFarming.getInstance(), () -> {
b2.setType(Material.SOIL); b2.setType(Material.DIRT);
if (instance.getConfig().getBoolean("Main.Sounds Enabled")) { if (instance.getConfig().getBoolean("Main.Sounds Enabled")) {
if (!instance.v1_7 && !instance.v1_8) if (!instance.v1_7 && !instance.v1_8)
b2.getWorld().playSound(b2.getLocation(), org.bukkit.Sound.BLOCK_GRASS_BREAK, 10, 15); 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()) { switch(cropData.getState()) {
case SEEDED: case SEEDED:
if (!EpicFarming.pl().v1_7 && !EpicFarming.pl().v1_8) { if (!EpicFarming.pl().v1_7 && !EpicFarming.pl().v1_8) {
if (material == Material.BEETROOT_BLOCK) if (material == Material.BEETROOT)
cropData.setState(CropState.VERY_SMALL); cropData.setState(CropState.VERY_SMALL);
else else
cropData.setState(CropState.GERMINATED); cropData.setState(CropState.GERMINATED);

View File

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

View File

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

View File

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