Faction Missions Implemented + Allowed Console to give points now

This commit is contained in:
Driftay 2019-08-07 14:35:19 -04:00
parent 92d46f91f4
commit 769394a058
16 changed files with 372 additions and 10 deletions

View File

@ -3,6 +3,7 @@ package com.massivecraft.factions;
import com.massivecraft.factions.event.FactionDisbandEvent.PlayerDisbandReason; import com.massivecraft.factions.event.FactionDisbandEvent.PlayerDisbandReason;
import com.massivecraft.factions.iface.EconomyParticipator; import com.massivecraft.factions.iface.EconomyParticipator;
import com.massivecraft.factions.iface.RelationParticipator; import com.massivecraft.factions.iface.RelationParticipator;
import com.massivecraft.factions.missions.Mission;
import com.massivecraft.factions.struct.BanInfo; import com.massivecraft.factions.struct.BanInfo;
import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.struct.Role;
@ -24,6 +25,8 @@ public interface Faction extends EconomyParticipator {
boolean altInvited(FPlayer fplayer); boolean altInvited(FPlayer fplayer);
Map<String, Mission> getMissions();
void deinviteAlt(FPlayer alt); void deinviteAlt(FPlayer alt);
void deinviteAllAlts(); void deinviteAllAlts();

View File

@ -10,6 +10,7 @@ import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.integration.Worldguard; import com.massivecraft.factions.integration.Worldguard;
import com.massivecraft.factions.integration.dynmap.EngineDynmap; import com.massivecraft.factions.integration.dynmap.EngineDynmap;
import com.massivecraft.factions.listeners.*; import com.massivecraft.factions.listeners.*;
import com.massivecraft.factions.missions.MissionHandler;
import com.massivecraft.factions.shop.ShopClickPersistence; import com.massivecraft.factions.shop.ShopClickPersistence;
import com.massivecraft.factions.shop.ShopConfig; import com.massivecraft.factions.shop.ShopConfig;
import com.massivecraft.factions.struct.ChatMode; import com.massivecraft.factions.struct.ChatMode;
@ -253,6 +254,7 @@ public class P extends MPlugin {
new CropUpgrades(), new CropUpgrades(),
new RedstoneUpgrade(), new RedstoneUpgrade(),
new ShopClickPersistence(), new ShopClickPersistence(),
new MissionHandler(this),
new SpawnerUpgrades() new SpawnerUpgrades()
}; };

View File

@ -13,6 +13,7 @@ import com.massivecraft.factions.cmd.relational.CmdRelationNeutral;
import com.massivecraft.factions.cmd.relational.CmdRelationTruce; import com.massivecraft.factions.cmd.relational.CmdRelationTruce;
import com.massivecraft.factions.cmd.roles.CmdDemote; import com.massivecraft.factions.cmd.roles.CmdDemote;
import com.massivecraft.factions.cmd.roles.CmdPromote; import com.massivecraft.factions.cmd.roles.CmdPromote;
import com.massivecraft.factions.missions.CmdMissions;
import com.massivecraft.factions.shop.CmdShop; import com.massivecraft.factions.shop.CmdShop;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -129,6 +130,7 @@ public class FCmdRoot extends FCommand {
public CmdLogout cmdLogout = new CmdLogout(); public CmdLogout cmdLogout = new CmdLogout();
public CmdNotifications cmdNotifications = new CmdNotifications(); public CmdNotifications cmdNotifications = new CmdNotifications();
public CmdShop cmdShop = new CmdShop(); public CmdShop cmdShop = new CmdShop();
public CmdMissions cmdMissions = new CmdMissions();
@ -250,6 +252,10 @@ public class FCmdRoot extends FCommand {
this.addSubCommand(this.cmdFGlobal); this.addSubCommand(this.cmdFGlobal);
this.addSubCommand(this.cmdViewChest); this.addSubCommand(this.cmdViewChest);
if(P.p.getConfig().getBoolean("Missions-Enabled")){
this.addSubCommand(this.cmdMissions);
}
if(P.p.getConfig().getBoolean("F-Shop.Enabled")){ if(P.p.getConfig().getBoolean("F-Shop.Enabled")){
this.addSubCommand(this.cmdShop); this.addSubCommand(this.cmdShop);
} }

View File

@ -32,7 +32,7 @@ public class CmdPoints extends FCommand {
@Override @Override
public void perform() { public void perform() {
if (!P.p.getConfig().getBoolean("f-points.Enabled", true)) { if (!P.p.getConfig().getBoolean("f-points.Enabled", true)) {
fme.msg(TL.GENERIC_DISABLED); msg(TL.GENERIC_DISABLED);
return; return;
} }
this.commandChain.add(this); this.commandChain.add(this);

View File

@ -45,16 +45,17 @@ public class CmdPointsAdd extends FCommand {
} }
if (faction == null || faction.isWilderness()) { if (faction == null || faction.isWilderness()) {
fme.msg(TL.COMMAND_POINTS_FAILURE.toString().replace("{faction}", args.get(0))); msg(TL.COMMAND_POINTS_FAILURE.toString().replace("{faction}", args.get(0)));
return; return;
} }
if(argAsInt(1) <= 0){ if(argAsInt(1) <= 0){
fme.msg(TL.COMMAND_POINTS_INSUFFICIENT); msg(TL.COMMAND_POINTS_INSUFFICIENT);
return; return;
} }
faction.setPoints(faction.getPoints() + argAsInt(1)); faction.setPoints(faction.getPoints() + argAsInt(1));
fme.msg(TL.COMMAND_POINTS_SUCCESSFUL, argAsInt(1), faction.getTag(), faction.getPoints());
msg(TL.COMMAND_POINTS_SUCCESSFUL, argAsInt(1), faction.getTag(), faction.getPoints());
} }

View File

@ -43,17 +43,17 @@ public class CmdPointsRemove extends FCommand {
} }
if (faction == null || faction.isWilderness()) { if (faction == null || faction.isWilderness()) {
fme.msg(TL.COMMAND_POINTS_FAILURE.toString().replace("{faction}", args.get(0))); msg(TL.COMMAND_POINTS_FAILURE.toString().replace("{faction}", args.get(0)));
return; return;
} }
if(argAsInt(1) <= 0){ if(argAsInt(1) <= 0){
fme.msg(TL.COMMAND_POINTS_INSUFFICIENT); msg(TL.COMMAND_POINTS_INSUFFICIENT);
return; return;
} }
faction.setPoints(faction.getPoints() - argAsInt(1)); faction.setPoints(faction.getPoints() - argAsInt(1));
fme.msg(TL.COMMAND_REMOVEPOINTS_SUCCESSFUL, argAsInt(1), faction.getTag(), faction.getPoints()); msg(TL.COMMAND_REMOVEPOINTS_SUCCESSFUL, argAsInt(1), faction.getTag(), faction.getPoints());
} }

View File

@ -42,17 +42,17 @@ public class CmdPointsSet extends FCommand {
} }
if (faction == null || faction.isWilderness()) { if (faction == null || faction.isWilderness()) {
fme.msg(TL.COMMAND_POINTS_FAILURE.toString().replace("{faction}", args.get(0))); msg(TL.COMMAND_POINTS_FAILURE.toString().replace("{faction}", args.get(0)));
return; return;
} }
if(argAsInt(1) < 0){ if(argAsInt(1) < 0){
fme.msg(TL.COMMAND_POINTS_INSUFFICIENT); msg(TL.COMMAND_POINTS_INSUFFICIENT);
return; return;
} }
faction.setPoints(argAsInt(1)); faction.setPoints(argAsInt(1));
fme.msg(TL.COMMAND_SETPOINTS_SUCCESSFUL, argAsInt(1), faction.getTag(), faction.getPoints()); msg(TL.COMMAND_SETPOINTS_SUCCESSFUL, argAsInt(1), faction.getTag(), faction.getPoints());
} }

View File

@ -0,0 +1,39 @@
package com.massivecraft.factions.missions;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
public class CmdMissions extends FCommand {
public CmdMissions() {
this.aliases.add("missions");
this.aliases.add("mission");
this.permission = Permission.MISSIONS.node;
this.disableOnLock = true;
this.disableOnSpam = true;
senderMustBePlayer = true;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform() {
if (myFaction == null) {
return;
}
final MissionGUI missionsGUI = new MissionGUI(p, fme);
missionsGUI.build();
fme.getPlayer().openInventory(missionsGUI.getInventory());
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_MISSION_DESCRIPTION;
}
}

View File

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

View File

@ -0,0 +1,106 @@
package com.massivecraft.factions.missions;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.P;
import com.massivecraft.factions.util.FactionGUI;
import com.massivecraft.factions.util.XMaterial;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class MissionGUI implements FactionGUI {
private P plugin;
private FPlayer fPlayer;
private Inventory inventory;
private Map<Integer, String> slots;
public MissionGUI(P 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 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);
}
}
public Inventory getInventory() {
return inventory;
}
}

View File

@ -0,0 +1,108 @@
package com.massivecraft.factions.missions;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.P;
import com.massivecraft.factions.zcore.util.TL;
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.EntityDeathEvent;
import org.bukkit.event.player.PlayerFishEvent;
import java.util.List;
import java.util.stream.Collectors;
public class MissionHandler implements Listener {
private P plugin;
public MissionHandler(P 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 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 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")) {
P.p.getServer().dispatchCommand(P.p.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")));
}
}

View File

@ -53,6 +53,7 @@ public enum Permission {
COLEADER("coleader"), COLEADER("coleader"),
MOD_ANY("mod.any"), MOD_ANY("mod.any"),
COLEADER_ANY("coleader.any"), COLEADER_ANY("coleader.any"),
MISSIONS("missions"),
MODIFY_POWER("modifypower"), MODIFY_POWER("modifypower"),
MONEY_BALANCE("money.balance"), MONEY_BALANCE("money.balance"),
MONEY_BALANCE_ANY("money.balance.any"), MONEY_BALANCE_ANY("money.balance.any"),

View File

@ -7,6 +7,7 @@ import com.massivecraft.factions.event.FactionDisbandEvent.PlayerDisbandReason;
import com.massivecraft.factions.iface.EconomyParticipator; import com.massivecraft.factions.iface.EconomyParticipator;
import com.massivecraft.factions.iface.RelationParticipator; import com.massivecraft.factions.iface.RelationParticipator;
import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.missions.Mission;
import com.massivecraft.factions.scoreboards.FTeamWrapper; import com.massivecraft.factions.scoreboards.FTeamWrapper;
import com.massivecraft.factions.struct.BanInfo; import com.massivecraft.factions.struct.BanInfo;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
@ -72,6 +73,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
private long lastDeath; private long lastDeath;
private int strikes = 0; private int strikes = 0;
private int points = 0; private int points = 0;
private Map<String, Mission> missions = new ConcurrentHashMap<>();
// -------------------------------------------- // // -------------------------------------------- //
@ -91,6 +93,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
this.permanent = false; this.permanent = false;
this.money = 0.0; this.money = 0.0;
this.powerBoost = 0.0; this.powerBoost = 0.0;
this.missions = new ConcurrentHashMap<>();
this.foundedDate = System.currentTimeMillis(); this.foundedDate = System.currentTimeMillis();
this.maxVaults = Conf.defaultMaxVaults; this.maxVaults = Conf.defaultMaxVaults;
this.defaultRole = Role.RECRUIT; this.defaultRole = Role.RECRUIT;
@ -111,6 +114,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
lastPlayerLoggedOffTime = old.lastPlayerLoggedOffTime; lastPlayerLoggedOffTime = old.lastPlayerLoggedOffTime;
money = old.money; money = old.money;
powerBoost = old.powerBoost; powerBoost = old.powerBoost;
missions = new ConcurrentHashMap<>();
relationWish = old.relationWish; relationWish = old.relationWish;
claimOwnership = old.claimOwnership; claimOwnership = old.claimOwnership;
fplayers = new HashSet<>(); fplayers = new HashSet<>();
@ -1159,6 +1163,12 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
return claimOwnership; return claimOwnership;
} }
@Override
public Map<String, Mission> getMissions() {
return this.missions;
}
public void clearAllClaimOwnership() { public void clearAllClaimOwnership() {
claimOwnership.clear(); claimOwnership.clear();
} }

View File

@ -944,6 +944,13 @@ public enum TL {
GENERIC_PLACEHOLDER("<This is a placeholder for a message you should not see>"), GENERIC_PLACEHOLDER("<This is a placeholder for a message you should not see>"),
GENERIC_NOTENOUGHMONEY("&cYou dont have enough money!"), GENERIC_NOTENOUGHMONEY("&cYou dont have enough money!"),
GENERIC_MONEYTAKE("&c{amount} has been taken from your account."), GENERIC_MONEYTAKE("&c{amount} has been taken from your account."),
MISSION_MISSION_STARTED("&f%1$s &dstarted the %2$s &fmission"),
MISSION_MISSION_ACTIVE("&c&l[!] &7This mission is currently active!"),
MISSION_MISSION_MAX_ALLOWED("&c&l[!] &7You may not have more then &b%1$s &7missions active at once."),
MISSION_MISSION_FINISHED("&c&l[!] &7Your faction has successfully completed %1$s mission!"),
COMMAND_MISSION_DESCRIPTION("Opens missions gui"),
// F Global \\ // F Global \\

View File

@ -696,6 +696,55 @@ f-grace:
f-points: f-points:
Enabled: true Enabled: true
############################################################
# +------------------------------------------------------+ #
# | Faction Missions | #
# +------------------------------------------------------+ #
############################################################
MissionGUISize: 3
Missions-Enabled: true
Missions-GUI-Title: '&bFaction Missions'
MaximumMissionsAllowedAtOnce: 1
Mission-Progress-Format: '&b&lProgression: &f{progress}&7/&e{total}'
#Mission Types: KILL, MINE, FISH
Missions:
sugarcane:
Slot: 11
Material: "SUGAR_CANE"
Name: "&f10,000 &2Sugar Cane"
Lore:
- "&b&lMine &f&n10,000&r &2Sugar Cane"
Mission:
Type: "MINE"
Material: "SUGAR_CANE_BLOCK"
Amount: 10000
Reward:
Commands: ["f points add %faction% 100"]
zombie:
Slot: 15
Material: "ROTTEN_FLESH"
Name: "&f1,000 &eZombies"
Lore:
- "&b&lKill &f&n1,000&r &eZombies"
Mission:
Type: "KILL"
EntityType: "ZOMBIE"
Amount: 1000
Reward:
Commands: ["f points add %faction% 100"]
fishing:
Slot: 13
Material: "FISHING_ROD"
Name: "&f100 &6Fish"
Lore:
- "&b&lCatch fish &n100&r &d&ltimes"
Mission:
Type: "FISH"
Amount: 100
Reward:
Commands: ["f points add %faction% 100"]
############################################################ ############################################################
# +------------------------------------------------------+ # # +------------------------------------------------------+ #
# | Faction Focus | # # | Faction Focus | #

View File

@ -128,6 +128,8 @@ permissions:
description: gives ability to toggle grace period on and off description: gives ability to toggle grace period on and off
factions.invsee: factions.invsee:
description: Allows players to use the inventory see command description: Allows players to use the inventory see command
factions.missions:
description: Allows players to use missions command
factions.alts: factions.alts:
description: Allows players to use the alts command description: Allows players to use the alts command
factions.announce: factions.announce: