Showing Dropping Anvil Something (Ignore)

This commit is contained in:
Driftay
2019-09-15 05:02:53 -04:00
parent c4e81286b7
commit d98f5d9723
285 changed files with 28732 additions and 28729 deletions

View File

@@ -9,32 +9,32 @@ import com.massivecraft.factions.zcore.util.TL;
public class CmdMissions extends FCommand {
public CmdMissions() {
this.aliases.add("missions");
this.aliases.add("mission");
this.aliases.add("objectives");
this.aliases.add("objective");
public CmdMissions() {
this.aliases.add("missions");
this.aliases.add("mission");
this.aliases.add("objectives");
this.aliases.add("objective");
this.requirements = new CommandRequirements.Builder(Permission.MISSIONS)
.memberOnly()
.playerOnly()
.build();
}
this.requirements = new CommandRequirements.Builder(Permission.MISSIONS)
.memberOnly()
.playerOnly()
.build();
}
@Override
public void perform(CommandContext context) {
if (context.faction == null) {
return;
}
final MissionGUI missionsGUI = new MissionGUI(FactionsPlugin.getInstance(), context.fPlayer);
missionsGUI.build();
context.player.openInventory(missionsGUI.getInventory());
}
@Override
public void perform(CommandContext context) {
if (context.faction == null) {
return;
}
final MissionGUI missionsGUI = new MissionGUI(FactionsPlugin.getInstance(), context.fPlayer);
missionsGUI.build();
context.player.openInventory(missionsGUI.getInventory());
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_MISSION_DESCRIPTION;
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_MISSION_DESCRIPTION;
}
}

View File

@@ -1,28 +1,28 @@
package com.massivecraft.factions.missions;
public class Mission {
private long progress;
private String name;
private String type;
private long progress;
private String name;
private String type;
public Mission(String name, String type) {
this.name = name;
this.type = type;
}
public Mission(String name, String type) {
this.name = name;
this.type = type;
}
public long getProgress() {
return progress;
}
public long getProgress() {
return progress;
}
public void incrementProgress() {
++progress;
}
public void incrementProgress() {
++progress;
}
public String getName() {
return name;
}
public String getName() {
return name;
}
public String getType() {
return type;
}
public String getType() {
return type;
}
}

View File

@@ -20,86 +20,86 @@ import java.util.List;
import java.util.Map;
public class MissionGUI implements FactionGUI {
private FactionsPlugin plugin;
private FPlayer fPlayer;
private Inventory inventory;
private Map<Integer, String> slots;
private FactionsPlugin plugin;
private FPlayer fPlayer;
private Inventory inventory;
private Map<Integer, String> slots;
public MissionGUI(FactionsPlugin plugin, FPlayer fPlayer) {
this.slots = new HashMap<>();
this.plugin = plugin;
this.fPlayer = fPlayer;
this.inventory = plugin.getServer().createInventory(this, plugin.getConfig().getInt("MissionGUISize") * 9, plugin.color(plugin.getConfig().getString("Missions-GUI-Title")));
}
public MissionGUI(FactionsPlugin plugin, FPlayer fPlayer) {
this.slots = new HashMap<>();
this.plugin = plugin;
this.fPlayer = fPlayer;
this.inventory = plugin.getServer().createInventory(this, plugin.getConfig().getInt("MissionGUISize") * 9, plugin.color(plugin.getConfig().getString("Missions-GUI-Title")));
}
@Override
public void onClick(int slot, ClickType action) {
ConfigurationSection configurationSection = plugin.getConfig().getConfigurationSection("Missions");
if (configurationSection == null) {
return;
}
int max = plugin.getConfig().getInt("MaximumMissionsAllowedAtOnce");
if (fPlayer.getFaction().getMissions().size() >= max) {
fPlayer.msg(TL.MISSION_MISSION_MAX_ALLOWED, max);
return;
}
String missionName = slots.get(slot);
if (missionName == null) {
return;
}
if (fPlayer.getFaction().getMissions().containsKey(missionName)) {
fPlayer.msg(TL.MISSION_MISSION_ACTIVE);
return;
}
ConfigurationSection section = configurationSection.getConfigurationSection(missionName);
if (section == null) {
return;
}
ConfigurationSection missionSection = section.getConfigurationSection("Mission");
if (missionSection == null) {
return;
}
Mission mission = new Mission(missionName, missionSection.getString("Type"));
fPlayer.getFaction().getMissions().put(missionName, mission);
fPlayer.msg(TL.MISSION_MISSION_STARTED, fPlayer.describeTo(fPlayer.getFaction()), plugin.color(section.getString("Name")));
build();
fPlayer.getPlayer().openInventory(inventory);
}
@Override
public void onClick(int slot, ClickType action) {
ConfigurationSection configurationSection = plugin.getConfig().getConfigurationSection("Missions");
if (configurationSection == null) {
return;
}
int max = plugin.getConfig().getInt("MaximumMissionsAllowedAtOnce");
if (fPlayer.getFaction().getMissions().size() >= max) {
fPlayer.msg(TL.MISSION_MISSION_MAX_ALLOWED, max);
return;
}
String missionName = slots.get(slot);
if (missionName == null) {
return;
}
if (fPlayer.getFaction().getMissions().containsKey(missionName)) {
fPlayer.msg(TL.MISSION_MISSION_ACTIVE);
return;
}
ConfigurationSection section = configurationSection.getConfigurationSection(missionName);
if (section == null) {
return;
}
ConfigurationSection missionSection = section.getConfigurationSection("Mission");
if (missionSection == null) {
return;
}
Mission mission = new Mission(missionName, missionSection.getString("Type"));
fPlayer.getFaction().getMissions().put(missionName, mission);
fPlayer.msg(TL.MISSION_MISSION_STARTED, fPlayer.describeTo(fPlayer.getFaction()), plugin.color(section.getString("Name")));
build();
fPlayer.getPlayer().openInventory(inventory);
}
@Override
public void build() {
ConfigurationSection configurationSection = plugin.getConfig().getConfigurationSection("Missions");
if (configurationSection == null) {
return;
}
for (String key : configurationSection.getKeys(false)) {
ConfigurationSection section = configurationSection.getConfigurationSection(key);
int slot = section.getInt("Slot");
@Override
public void build() {
ConfigurationSection configurationSection = plugin.getConfig().getConfigurationSection("Missions");
if (configurationSection == null) {
return;
}
for (String key : configurationSection.getKeys(false)) {
ConfigurationSection section = configurationSection.getConfigurationSection(key);
int slot = section.getInt("Slot");
ItemStack itemStack = XMaterial.matchXMaterial(section.getString("Material")).parseItem();
ItemMeta itemMeta = itemStack.getItemMeta();
itemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', section.getString("Name")));
List<String> loreLines = new ArrayList<>();
for (String line : section.getStringList("Lore")) {
loreLines.add(ChatColor.translateAlternateColorCodes('&', line));
}
if (fPlayer.getFaction().getMissions().containsKey(key)) {
Mission mission = fPlayer.getFaction().getMissions().get(key);
itemMeta.addEnchant(Enchantment.SILK_TOUCH, 1, true);
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
loreLines.add("");
loreLines.add(plugin.color(plugin.getConfig().getString("Mission-Progress-Format")
.replace("{progress}", String.valueOf(mission.getProgress()))
.replace("{total}", String.valueOf(section.getConfigurationSection("Mission").get("Amount")))));
}
itemMeta.setLore(loreLines);
itemStack.setItemMeta(itemMeta);
inventory.setItem(slot, itemStack);
slots.put(slot, key);
}
}
ItemStack itemStack = XMaterial.matchXMaterial(section.getString("Material")).parseItem();
ItemMeta itemMeta = itemStack.getItemMeta();
itemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', section.getString("Name")));
List<String> loreLines = new ArrayList<>();
for (String line : section.getStringList("Lore")) {
loreLines.add(ChatColor.translateAlternateColorCodes('&', line));
}
if (fPlayer.getFaction().getMissions().containsKey(key)) {
Mission mission = fPlayer.getFaction().getMissions().get(key);
itemMeta.addEnchant(Enchantment.SILK_TOUCH, 1, true);
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
loreLines.add("");
loreLines.add(plugin.color(plugin.getConfig().getString("Mission-Progress-Format")
.replace("{progress}", String.valueOf(mission.getProgress()))
.replace("{total}", String.valueOf(section.getConfigurationSection("Mission").get("Amount")))));
}
itemMeta.setLore(loreLines);
itemStack.setItemMeta(itemMeta);
inventory.setItem(slot, itemStack);
slots.put(slot, key);
}
}
public Inventory getInventory() {
return inventory;
}
public Inventory getInventory() {
return inventory;
}
}

View File

@@ -4,14 +4,12 @@ import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
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.event.entity.EntityBreedEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.player.PlayerFishEvent;
@@ -20,91 +18,91 @@ import java.util.stream.Collectors;
public class MissionHandler implements Listener {
private FactionsPlugin plugin;
private FactionsPlugin plugin;
public MissionHandler(FactionsPlugin plugin) {
this.plugin = plugin;
}
public MissionHandler(FactionsPlugin plugin) {
this.plugin = plugin;
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEntityDeath(EntityDeathEvent event) {
if (event.getEntity() == null || event.getEntity().getKiller() == null) {
return;
}
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(event.getEntity().getKiller());
if (fPlayer == null) {
return;
}
List<Mission> missions = fPlayer.getFaction().getMissions().values().stream().filter(mission -> mission.getType().equalsIgnoreCase("kill")).collect(Collectors.toList());
for (Mission mission2 : missions) {
ConfigurationSection section = plugin.getConfig().getConfigurationSection("Missions").getConfigurationSection(mission2.getName());
if (!event.getEntityType().toString().equals(section.getConfigurationSection("Mission").getString("EntityType"))) {
continue;
}
mission2.incrementProgress();
checkIfDone(fPlayer, mission2, section);
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEntityDeath(EntityDeathEvent event) {
if (event.getEntity() == null || event.getEntity().getKiller() == null) {
return;
}
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(event.getEntity().getKiller());
if (fPlayer == null) {
return;
}
List<Mission> missions = fPlayer.getFaction().getMissions().values().stream().filter(mission -> mission.getType().equalsIgnoreCase("kill")).collect(Collectors.toList());
for (Mission mission2 : missions) {
ConfigurationSection section = plugin.getConfig().getConfigurationSection("Missions").getConfigurationSection(mission2.getName());
if (!event.getEntityType().toString().equals(section.getConfigurationSection("Mission").getString("EntityType"))) {
continue;
}
mission2.incrementProgress();
checkIfDone(fPlayer, mission2, section);
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(event.getPlayer());
if (fPlayer == null) {
return;
}
List<Mission> missions = fPlayer.getFaction().getMissions().values().stream().filter(mission -> mission.getType().equalsIgnoreCase("mine")).collect(Collectors.toList());
for (Mission mission2 : missions) {
ConfigurationSection section = plugin.getConfig().getConfigurationSection("Missions").getConfigurationSection(mission2.getName());
if (!event.getBlock().getType().toString().equals(section.getConfigurationSection("Mission").getString("Material"))) {
continue;
}
mission2.incrementProgress();
checkIfDone(fPlayer, mission2, section);
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(event.getPlayer());
if (fPlayer == null) {
return;
}
List<Mission> missions = fPlayer.getFaction().getMissions().values().stream().filter(mission -> mission.getType().equalsIgnoreCase("mine")).collect(Collectors.toList());
for (Mission mission2 : missions) {
ConfigurationSection section = plugin.getConfig().getConfigurationSection("Missions").getConfigurationSection(mission2.getName());
if (!event.getBlock().getType().toString().equals(section.getConfigurationSection("Mission").getString("Material"))) {
continue;
}
mission2.incrementProgress();
checkIfDone(fPlayer, mission2, section);
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent event) {
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(event.getPlayer());
if (fPlayer == null) {
return;
}
List<Mission> missions = fPlayer.getFaction().getMissions().values().stream().filter(mission -> mission.getType().equalsIgnoreCase("place")).collect(Collectors.toList());
for (Mission mission2 : missions) {
ConfigurationSection section = plugin.getConfig().getConfigurationSection("Missions").getConfigurationSection(mission2.getName());
if (!event.getBlock().getType().toString().equals(section.getConfigurationSection("Mission").getString("Material"))) {
continue;
}
mission2.incrementProgress();
checkIfDone(fPlayer, mission2, section);
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent event) {
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(event.getPlayer());
if (fPlayer == null) {
return;
}
List<Mission> missions = fPlayer.getFaction().getMissions().values().stream().filter(mission -> mission.getType().equalsIgnoreCase("place")).collect(Collectors.toList());
for (Mission mission2 : missions) {
ConfigurationSection section = plugin.getConfig().getConfigurationSection("Missions").getConfigurationSection(mission2.getName());
if (!event.getBlock().getType().toString().equals(section.getConfigurationSection("Mission").getString("Material"))) {
continue;
}
mission2.incrementProgress();
checkIfDone(fPlayer, mission2, section);
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerFish(PlayerFishEvent event) {
if (event.getState() != PlayerFishEvent.State.CAUGHT_FISH) {
return;
}
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(event.getPlayer());
if (fPlayer == null) {
return;
}
List<Mission> missions = fPlayer.getFaction().getMissions().values().stream().filter(mission -> mission.getType().equalsIgnoreCase("fish")).collect(Collectors.toList());
for (Mission mission2 : missions) {
ConfigurationSection section = plugin.getConfig().getConfigurationSection("Missions").getConfigurationSection(mission2.getName());
mission2.incrementProgress();
checkIfDone(fPlayer, mission2, section);
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerFish(PlayerFishEvent event) {
if (event.getState() != PlayerFishEvent.State.CAUGHT_FISH) {
return;
}
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(event.getPlayer());
if (fPlayer == null) {
return;
}
List<Mission> missions = fPlayer.getFaction().getMissions().values().stream().filter(mission -> mission.getType().equalsIgnoreCase("fish")).collect(Collectors.toList());
for (Mission mission2 : missions) {
ConfigurationSection section = plugin.getConfig().getConfigurationSection("Missions").getConfigurationSection(mission2.getName());
mission2.incrementProgress();
checkIfDone(fPlayer, mission2, section);
}
}
private void checkIfDone(FPlayer fPlayer, Mission mission, ConfigurationSection section) {
if (mission.getProgress() < section.getConfigurationSection("Mission").getLong("Amount")) {
return;
}
for (String command : section.getConfigurationSection("Reward").getStringList("Commands")) {
FactionsPlugin.getInstance().getServer().dispatchCommand(FactionsPlugin.getInstance().getServer().getConsoleSender(), command.replace("%faction%", fPlayer.getFaction().getTag()));
}
fPlayer.getFaction().getMissions().remove(mission.getName());
fPlayer.getFaction().msg(TL.MISSION_MISSION_FINISHED, plugin.color(section.getString("Name")));
}
private void checkIfDone(FPlayer fPlayer, Mission mission, ConfigurationSection section) {
if (mission.getProgress() < section.getConfigurationSection("Mission").getLong("Amount")) {
return;
}
for (String command : section.getConfigurationSection("Reward").getStringList("Commands")) {
FactionsPlugin.getInstance().getServer().dispatchCommand(FactionsPlugin.getInstance().getServer().getConsoleSender(), command.replace("%faction%", fPlayer.getFaction().getTag()));
}
fPlayer.getFaction().getMissions().remove(mission.getName());
fPlayer.getFaction().msg(TL.MISSION_MISSION_FINISHED, plugin.color(section.getString("Name")));
}
}