More to Shields & Mission Class Cleanup

This commit is contained in:
Driftay 2019-11-23 22:33:49 -05:00
parent 5744b7e28e
commit 28517ef391
8 changed files with 169 additions and 20 deletions

View File

@ -4,6 +4,7 @@ import com.massivecraft.factions.event.FactionDisbandEvent.PlayerDisbandReason;
import com.massivecraft.factions.iface.EconomyParticipator;
import com.massivecraft.factions.iface.RelationParticipator;
import com.massivecraft.factions.missions.Mission;
import com.massivecraft.factions.shield.TimeFrame;
import com.massivecraft.factions.struct.BanInfo;
import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.struct.Role;
@ -440,4 +441,9 @@ public interface Faction extends EconomyParticipator {
String getPaypal();
void paypalSet(String paypal);
// shield
void setTimeFrame(TimeFrame timeFrame);
TimeFrame getTimeFrame();
}

View File

@ -18,6 +18,7 @@ import com.massivecraft.factions.integration.Worldguard;
import com.massivecraft.factions.integration.dynmap.EngineDynmap;
import com.massivecraft.factions.listeners.*;
import com.massivecraft.factions.missions.MissionHandler;
import com.massivecraft.factions.shield.TimeFrameTask;
import com.massivecraft.factions.shop.ShopConfig;
import com.massivecraft.factions.struct.ChatMode;
import com.massivecraft.factions.struct.Relation;
@ -266,6 +267,7 @@ public class FactionsPlugin extends MPlugin {
this.getServer().getScheduler().runTaskTimerAsynchronously(this, new CheckTask(this, 30), 0L, (long) (minute * 30));
this.getServer().getScheduler().runTaskTimer(this, CheckTask::cleanupTask, 0L, 1200L);
this.getServer().getScheduler().runTaskTimerAsynchronously(this, new WeeWooTask(this), 600L, 600L);
this.getServer().getScheduler().runTaskTimerAsynchronously(this, new TimeFrameTask(), 1200, 1200); // every 1 minute...
}
if(Conf.useDiscordSystem && !Conf.discordBotToken.equals("<token here>")) {
new FactionChatHandler(this);

View File

@ -24,9 +24,6 @@ public class CmdMissions extends FCommand {
@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());

View File

@ -31,9 +31,7 @@ public class MissionGUI implements FactionGUI {
@Override
public void onClick(int slot, ClickType action) {
String missionName = slots.get(slot);
if (missionName == null) {
return;
}
if (missionName == null) return;
ConfigurationSection configurationSection = plugin.getConfig().getConfigurationSection("Missions");
if (missionName.equals(plugin.color(FactionsPlugin.getInstance().getConfig().getString("Randomization.Start-Item.Allowed.Name")))) {
Mission pickedMission = null;
@ -54,25 +52,22 @@ public class MissionGUI implements FactionGUI {
}
}
} else if (plugin.getConfig().getBoolean("Randomization.Enabled")) {return;}
if (configurationSection == null) {
return;
}
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;
}
if (missionName.equals(plugin.color(FactionsPlugin.getInstance().getConfig().getString("Randomization.Start-Item.Disallowed.Name")))) {
return;
}
if (missionName.equals(plugin.color(FactionsPlugin.getInstance().getConfig().getString("Randomization.Start-Item.Disallowed.Name")))) return;
if (fPlayer.getFaction().getMissions().containsKey(missionName)) {
fPlayer.msg(TL.MISSION_MISSION_ACTIVE);
return;
}
ConfigurationSection section = configurationSection.getConfigurationSection(missionName);
if (section == null) {
return;
}
if (section == null) return;
if(FactionsPlugin.getInstance().getConfig().getBoolean("DenyMissionsMoreThenOnce")) {
if (fPlayer.getFaction().getCompletedMissions().contains(missionName)) {
fPlayer.msg(TL.MISSION_ALREAD_COMPLETED);
@ -81,9 +76,7 @@ public class MissionGUI implements FactionGUI {
}
ConfigurationSection missionSection = section.getConfigurationSection("Mission");
if (missionSection == null) {
return;
}
if (missionSection == null) return;
Mission mission = new Mission(missionName, missionSection.getString("Type"));
fPlayer.getFaction().getMissions().put(missionName, mission);

View File

@ -0,0 +1,94 @@
package com.massivecraft.factions.shield;
import com.massivecraft.factions.Faction;
public class TimeFrame {
//each of these objs will be in 1 fac
private Faction faction;
private Enum startingTime;
private Enum endingTime;
private int currentMinutes; // this will be the variable for either the currentTime starting, or ending, or current in effect.
private boolean inEffect; // if the forcefield is in effect
private boolean starting; // pending starting countdown
private boolean ending; // pending ending countdown
private enum times {
twelveAM, oneAM, twoAM, threeAM, fourAM, fiveAM, sixAM, sevenAM, eightAM, nineAM, tenAM, elevenAM, twelvePM,
onePM, twoPM, threePM, fourPM, fivePM, sixPM, sevenPM, eightPM, ninePM, tenPM, elevenPM;
}
public TimeFrame(Faction faction, Enum startingTime, Enum endingTime, boolean starting, boolean ending, boolean inEffect, int currentMinutes){
this.faction = faction;
this.startingTime = startingTime;
this.endingTime = endingTime;
this.starting = starting;
this.ending = ending;
this.inEffect = inEffect;
this.currentMinutes = currentMinutes;
}
public boolean isEnding() {
return ending;
}
public boolean isInEffect() {
return inEffect;
}
public Enum getEndingTime() {
return endingTime;
}
public Enum getStartingTime() {
return startingTime;
}
public boolean isStarting() {
return starting;
}
public Faction getFaction() {
return faction;
}
public void setCurrentMinutes(int currentMinutes) {
this.currentMinutes = currentMinutes;
}
public int getCurrentMinutes() {
return currentMinutes;
}
public void setEnding(boolean ending) {
this.ending = ending;
}
public void setEndingTime(Enum endingTime) {
this.endingTime = endingTime;
}
public void setStartingTime(Enum startingTime) {
this.startingTime = startingTime;
}
public void setFaction(Faction faction) {
this.faction = faction;
}
public void setInEffect(boolean inEffect) {
this.inEffect = inEffect;
}
public void setStarting(boolean starting) {
this.starting = starting;
}
}

View File

@ -0,0 +1,46 @@
package com.massivecraft.factions.shield;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions;
public class TimeFrameTask implements Runnable {
@Override
public void run() {
//remove tiem from the timeFrame
for (Faction faction : Factions.getInstance().getAllFactions()) {
if (faction.getTimeFrame() != null){
TimeFrame timeFrame = faction.getTimeFrame();
if (timeFrame.isStarting() || timeFrame.isEnding() || timeFrame.isInEffect()){
//either starting, ending, or in effect, so we have to remove 1 minute interval from the currentTime
int newTime = Math.subtractExact(timeFrame.getCurrentMinutes(), 1);
if (newTime == 0){
//time is done, do functions...
if (timeFrame.isStarting() || timeFrame.isInEffect()){
if (timeFrame.isStarting()){
//it was starting, now set to inEffect
timeFrame.setStarting(false);
timeFrame.setInEffect(true);
}
//we don't need to check for inEffect because if it is, it'll just set the time back anyways...
timeFrame.setCurrentMinutes(720);
continue; // continue to the next faction
}else if (timeFrame.isEnding()){
//it was ending, now set inEffect to false, basically remove from the faction obj
timeFrame.setEnding(false);
timeFrame.setInEffect(false);
//remove from faction object
faction.setTimeFrame(null);
continue; // continue to the next faction
}
}
timeFrame.setCurrentMinutes(newTime);
}
}
}
}
}

View File

@ -9,6 +9,7 @@ import com.massivecraft.factions.iface.RelationParticipator;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.missions.Mission;
import com.massivecraft.factions.scoreboards.FTeamWrapper;
import com.massivecraft.factions.shield.TimeFrame;
import com.massivecraft.factions.struct.BanInfo;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Relation;
@ -93,6 +94,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
private String weeWooFormat;
private String guildId;
private String memberRoleId;
private TimeFrame timeFrame;
// -------------------------------------------- //
@ -128,6 +130,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
this.notifyFormat = "@everyone, check %type%";
this.weeWooFormat = "@everyone, we're being raided! Get online!";
this.memberRoleId = null;
this.timeFrame = null;
resetPerms(); // Reset on new Faction so it has default values.
}
@ -160,7 +163,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
this.checks = new ConcurrentHashMap<>();
this.playerWallCheckCount = new ConcurrentHashMap<>();
this.playerBufferCheckCount = new ConcurrentHashMap<>();
this.timeFrame = null;
resetPerms(); // Reset on new Faction so it has default values.
}
@ -583,6 +586,14 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
return this.wallNotifyChannelId;
}
public TimeFrame getTimeFrame(){
return this.timeFrame;
}
public void setTimeFrame(TimeFrame timeFrame){
this.timeFrame = timeFrame;
}
@Override
public void setWallNotifyChannelId(final String wallNotifyChannelId) {
this.wallNotifyChannelId = wallNotifyChannelId;

View File

@ -1038,7 +1038,7 @@ public enum TL {
GENERIC_YOUMUSTBE("&cYour must be atleast %1$s to do this!"),
GENERIC_MEMBERONLY("&cYou must be in a faction to do this!"),
// MISSION_CREATED_COOLDOWN("&c&l[!] &7Due to your immediate faction creation, you may not start missions for &b%1$s minutes&7!"),
MISSION_MISSION_STARTED("&f%1$s &dstarted the %2$s &fmission"),
MISSION_ALREAD_COMPLETED("&c&l[!] &7You may not restart a mission you have already completed"),
MISSION_MISSION_ACTIVE("&c&l[!] &7This mission is currently active!"),