2018-12-27 23:00:05 +01:00
/ * *
* Jobs Plugin for Bukkit
* Copyright ( C ) 2011 Zak Ford < zak . j . ford @gmail.com >
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http : //www.gnu.org/licenses/>.
* /
package com.gamingmesh.jobs ;
2021-06-20 12:24:49 +02:00
import java.io.File ;
import java.sql.SQLException ;
import java.util.ArrayList ;
import java.util.Collections ;
import java.util.HashMap ;
import java.util.Iterator ;
2021-07-16 15:08:05 +02:00
import java.util.LinkedHashMap ;
2021-06-20 12:24:49 +02:00
import java.util.List ;
import java.util.Map ;
import java.util.Optional ;
import java.util.UUID ;
import java.util.WeakHashMap ;
import java.util.logging.Logger ;
import org.bukkit.Bukkit ;
import org.bukkit.block.Block ;
import org.bukkit.command.CommandSender ;
import org.bukkit.entity.Entity ;
import org.bukkit.entity.LivingEntity ;
import org.bukkit.entity.Player ;
import org.bukkit.event.HandlerList ;
import org.bukkit.plugin.java.JavaPlugin ;
2018-12-27 23:00:05 +01:00
import com.gamingmesh.jobs.Gui.GuiManager ;
2020-07-29 10:50:01 +02:00
import com.gamingmesh.jobs.Placeholders.Placeholder ;
2021-06-20 12:24:49 +02:00
import com.gamingmesh.jobs.Placeholders.PlaceholderAPIHook ;
2018-12-27 23:00:05 +01:00
import com.gamingmesh.jobs.Signs.SignUtil ;
import com.gamingmesh.jobs.api.JobsExpGainEvent ;
2019-06-05 09:50:42 +02:00
import com.gamingmesh.jobs.api.JobsPrePaymentEvent ;
2018-12-27 23:00:05 +01:00
import com.gamingmesh.jobs.commands.JobsCommands ;
2021-06-20 12:24:49 +02:00
import com.gamingmesh.jobs.config.BlockProtectionManager ;
import com.gamingmesh.jobs.config.BossBarManager ;
import com.gamingmesh.jobs.config.ConfigManager ;
import com.gamingmesh.jobs.config.ExploreManager ;
import com.gamingmesh.jobs.config.GeneralConfigManager ;
import com.gamingmesh.jobs.config.LanguageManager ;
import com.gamingmesh.jobs.config.NameTranslatorManager ;
import com.gamingmesh.jobs.config.RestrictedAreaManager ;
import com.gamingmesh.jobs.config.RestrictedBlockManager ;
import com.gamingmesh.jobs.config.ScheduleManager ;
import com.gamingmesh.jobs.config.ShopManager ;
import com.gamingmesh.jobs.config.TitleManager ;
import com.gamingmesh.jobs.config.YmlMaker ;
import com.gamingmesh.jobs.container.ActionInfo ;
import com.gamingmesh.jobs.container.ActionType ;
import com.gamingmesh.jobs.container.ArchivedJobs ;
import com.gamingmesh.jobs.container.BlockProtection ;
import com.gamingmesh.jobs.container.Boost ;
import com.gamingmesh.jobs.container.Convert ;
import com.gamingmesh.jobs.container.CurrencyLimit ;
import com.gamingmesh.jobs.container.CurrencyType ;
import com.gamingmesh.jobs.container.DBAction ;
import com.gamingmesh.jobs.container.FastPayment ;
import com.gamingmesh.jobs.container.Job ;
import com.gamingmesh.jobs.container.JobInfo ;
import com.gamingmesh.jobs.container.JobProgression ;
import com.gamingmesh.jobs.container.JobsPlayer ;
2021-10-26 16:14:39 +02:00
import com.gamingmesh.jobs.container.JobsWorld ;
2022-02-07 14:28:23 +01:00
import com.gamingmesh.jobs.container.LoadStatus ;
2021-06-20 12:24:49 +02:00
import com.gamingmesh.jobs.container.Log ;
import com.gamingmesh.jobs.container.PlayerInfo ;
import com.gamingmesh.jobs.container.PlayerPoints ;
import com.gamingmesh.jobs.container.Quest ;
import com.gamingmesh.jobs.container.QuestProgression ;
2020-10-12 12:42:50 +02:00
import com.gamingmesh.jobs.container.blockOwnerShip.BlockOwnerShip ;
import com.gamingmesh.jobs.container.blockOwnerShip.BlockTypes ;
2021-07-15 16:26:17 +02:00
import com.gamingmesh.jobs.dao.JobsClassLoader ;
2018-12-27 23:00:05 +01:00
import com.gamingmesh.jobs.dao.JobsDAO ;
import com.gamingmesh.jobs.dao.JobsDAOData ;
import com.gamingmesh.jobs.dao.JobsManager ;
2021-06-20 12:24:49 +02:00
import com.gamingmesh.jobs.economy.BufferedEconomy ;
import com.gamingmesh.jobs.economy.BufferedPayment ;
import com.gamingmesh.jobs.economy.Economy ;
import com.gamingmesh.jobs.economy.PaymentData ;
import com.gamingmesh.jobs.hooks.HookManager ;
2018-12-27 23:00:05 +01:00
import com.gamingmesh.jobs.i18n.Language ;
import com.gamingmesh.jobs.listeners.JobsListener ;
2019-10-26 11:30:58 +02:00
import com.gamingmesh.jobs.listeners.JobsPayment14Listener ;
2018-12-27 23:00:05 +01:00
import com.gamingmesh.jobs.listeners.JobsPaymentListener ;
import com.gamingmesh.jobs.listeners.PistonProtectionListener ;
import com.gamingmesh.jobs.selection.SelectionManager ;
2021-06-20 12:24:49 +02:00
import com.gamingmesh.jobs.stuff.Loging ;
import com.gamingmesh.jobs.stuff.TabComplete ;
import com.gamingmesh.jobs.stuff.ToggleBarHandling ;
2021-10-26 16:14:39 +02:00
import com.gamingmesh.jobs.stuff.Util ;
2021-06-20 12:24:49 +02:00
import com.gamingmesh.jobs.stuff.VersionChecker ;
2021-02-26 08:45:14 +01:00
import com.gamingmesh.jobs.stuff.complement.Complement ;
import com.gamingmesh.jobs.stuff.complement.Complement1 ;
import com.gamingmesh.jobs.stuff.complement.Complement2 ;
2021-06-20 12:24:49 +02:00
import com.gamingmesh.jobs.stuff.complement.JobsChatEvent ;
2018-12-27 23:00:05 +01:00
import com.gamingmesh.jobs.tasks.BufferedPaymentThread ;
import com.gamingmesh.jobs.tasks.DatabaseSaveThread ;
2021-02-26 08:45:14 +01:00
2021-06-20 12:24:49 +02:00
import net.Zrips.CMILib.ActionBar.CMIActionBar ;
import net.Zrips.CMILib.Colors.CMIChatColor ;
import net.Zrips.CMILib.Container.PageInfo ;
import net.Zrips.CMILib.Items.CMIMaterial ;
2022-06-22 14:51:48 +02:00
import net.Zrips.CMILib.Locale.LC ;
2022-02-11 16:18:51 +01:00
import net.Zrips.CMILib.Logs.CMIDebug ;
2021-10-26 16:32:42 +02:00
import net.Zrips.CMILib.Messages.CMIMessages ;
2021-06-20 12:24:49 +02:00
import net.Zrips.CMILib.RawMessages.RawMessage ;
import net.Zrips.CMILib.Version.Version ;
2018-12-27 23:00:05 +01:00
2021-06-20 19:05:53 +02:00
public final class Jobs extends JavaPlugin {
2020-01-26 17:48:23 +01:00
2020-09-05 14:23:48 +02:00
private static PlayerManager pManager ;
private static JobsCommands cManager ;
private static Language lManager ;
private static LanguageManager lmManager ;
private static SignUtil signManager ;
private static ScheduleManager scheduleManager ;
private static NameTranslatorManager nameTranslatorManager ;
private static ExploreManager exploreManager ;
private static TitleManager titleManager ;
private static RestrictedBlockManager rbManager ;
private static RestrictedAreaManager raManager ;
private static BossBarManager bbManager ;
private static ShopManager shopManager ;
private static Loging loging ;
private static BlockProtectionManager bpManager ;
private static JobsManager dbManager ;
private static ConfigManager configManager ;
private static GeneralConfigManager gConfigManager ;
2021-06-20 12:24:49 +02:00
2021-02-26 08:45:14 +01:00
private static BufferedEconomy economy ;
private static PermissionHandler permissionHandler ;
private static PermissionManager permissionManager ;
2021-07-15 16:26:17 +02:00
private static JobsClassLoader classLoader ;
2021-07-15 12:11:35 +02:00
private final HashMap < CMIMaterial , BlockOwnerShip > blockOwnerShipsMaterial = new HashMap < > ( ) ;
private final HashMap < BlockTypes , BlockOwnerShip > blockOwnerShipsBlockType = new HashMap < > ( ) ;
2021-02-26 08:45:14 +01:00
2021-05-06 20:45:39 +02:00
private boolean kyoriSupported = false ;
2021-02-26 08:45:14 +01:00
private Complement complement ;
2021-03-24 16:17:00 +01:00
private GuiManager guiManager ;
2020-09-05 14:23:48 +02:00
private static JobsDAO dao ;
private static List < Job > jobs ;
private static Job noneJob ;
2021-03-14 14:14:26 +01:00
private static Map < Job , Integer > usedSlots = new WeakHashMap < > ( ) ;
2020-01-08 17:51:40 +01:00
2020-09-05 14:23:48 +02:00
public static BufferedPaymentThread paymentThread ;
private static DatabaseSaveThread saveTask ;
2018-12-27 23:00:05 +01:00
2022-02-07 14:28:23 +01:00
public static LoadStatus status = LoadStatus . Good ;
2022-02-11 16:18:51 +01:00
private static boolean hasLimitedItems = false ;
2022-02-08 18:07:12 +01:00
2021-07-16 15:08:05 +02:00
private static final int MAX_ENTRIES = 5 ;
public static final LinkedHashMap < UUID , FastPayment > FASTPAYMENT = new LinkedHashMap < UUID , FastPayment > ( MAX_ENTRIES + 1 , . 75F , false ) {
protected boolean removeEldestEntry ( Map . Entry < UUID , FastPayment > eldest ) {
return size ( ) > MAX_ENTRIES ;
}
} ;
2018-12-27 23:00:05 +01:00
2020-09-05 14:23:48 +02:00
protected static VersionChecker versionCheckManager ;
protected static SelectionManager smanager ;
2018-12-27 23:00:05 +01:00
2021-02-26 08:45:14 +01:00
public Complement getComplement ( ) {
return complement ;
}
2021-05-06 20:45:39 +02:00
public boolean isKyoriSupported ( ) {
return kyoriSupported ;
}
2021-07-15 16:26:17 +02:00
public static JobsClassLoader getJobsClassloader ( ) {
if ( classLoader = = null )
classLoader = new JobsClassLoader ( Jobs . getInstance ( ) ) ;
return classLoader ;
}
2021-06-20 10:47:03 +02:00
/ * *
* Returns the block owner ship for specific { @link CMIMaterial } type .
*
* @param type { @link CMIMaterial }
* @see # getBlockOwnerShip ( CMIMaterial , boolean )
* @return { @link BlockOwnerShip } , otherwise { @link Optional # empty ( ) }
* /
2020-10-12 12:42:50 +02:00
public Optional < BlockOwnerShip > getBlockOwnerShip ( CMIMaterial type ) {
return getBlockOwnerShip ( type , true ) ;
}
2021-02-02 23:04:46 +01:00
/ * *
* Returns the block owner ship for specific { @link CMIMaterial } type .
* If the addNew parameter is enabled , it will cache a new owner ship for specific
* { @link CMIMaterial } type .
*
* @param type { @link CMIMaterial }
* @param addNew whenever to add a new owner ship
* @return { @link BlockOwnerShip } , otherwise { @link Optional # empty ( ) }
* /
2020-10-12 12:42:50 +02:00
public Optional < BlockOwnerShip > getBlockOwnerShip ( CMIMaterial type , boolean addNew ) {
2021-07-15 12:11:35 +02:00
BlockOwnerShip b = blockOwnerShipsMaterial . get ( type ) ;
2020-10-12 12:42:50 +02:00
if ( addNew & & b = = null ) {
2021-07-15 12:11:35 +02:00
b = new BlockOwnerShip ( type ) ;
blockOwnerShipsMaterial . put ( type , b ) ;
blockOwnerShipsBlockType . put ( b . getType ( ) , b ) ;
2020-10-12 12:42:50 +02:00
}
return Optional . ofNullable ( b ) ;
}
2021-02-02 23:04:46 +01:00
/ * *
* Returns the block owner ship for specific { @link BlockTypes } type .
*
* @param type { @link BlockTypes }
* @return { @link BlockOwnerShip } , otherwise { @link Optional # empty ( ) }
* /
2020-10-12 12:42:50 +02:00
public Optional < BlockOwnerShip > getBlockOwnerShip ( BlockTypes type ) {
2021-07-15 12:11:35 +02:00
BlockOwnerShip b = blockOwnerShipsBlockType . get ( type ) ;
if ( b ! = null )
return Optional . ofNullable ( b ) ;
2020-10-12 12:42:50 +02:00
2020-10-17 18:16:07 +02:00
return Optional . empty ( ) ;
2020-10-12 12:42:50 +02:00
}
2021-05-28 20:41:08 +02:00
public void removeBlockOwnerShip ( org . bukkit . block . Block block ) {
2021-10-26 13:05:09 +02:00
BlockOwnerShip ship = blockOwnerShipsMaterial . get ( CMIMaterial . get ( block ) ) ;
if ( ship ! = null )
2021-05-28 20:41:08 +02:00
ship . remove ( block ) ;
}
2021-02-02 23:04:46 +01:00
/ * *
* @return a set of block owner ships .
* /
2021-07-15 12:11:35 +02:00
public HashMap < CMIMaterial , BlockOwnerShip > getBlockOwnerShips ( ) {
return blockOwnerShipsMaterial ;
2020-10-12 12:42:50 +02:00
}
2020-09-05 14:23:48 +02:00
private Placeholder placeholder ;
private boolean placeholderAPIEnabled = false ;
2018-12-27 23:00:05 +01:00
public Placeholder getPlaceholderAPIManager ( ) {
2020-09-05 14:23:48 +02:00
if ( placeholder = = null )
placeholder = new Placeholder ( this ) ;
return placeholder ;
2018-12-27 23:00:05 +01:00
}
2019-12-14 18:08:43 +01:00
private boolean setupPlaceHolderAPI ( ) {
2021-04-28 16:21:37 +02:00
org . bukkit . plugin . Plugin papi = getServer ( ) . getPluginManager ( ) . getPlugin ( " PlaceholderAPI " ) ;
if ( papi = = null | | ! papi . isEnabled ( ) )
2018-12-27 23:00:05 +01:00
return false ;
2019-09-26 20:44:20 +02:00
2021-04-29 18:05:18 +02:00
try {
if ( Integer . parseInt ( papi
. getDescription ( ) . getVersion ( ) . replaceAll ( " [^ \\ d] " , " " ) ) > = 2100 & & new PlaceholderAPIHook ( this ) . register ( ) ) {
2021-10-26 16:32:42 +02:00
consoleMsg ( " &6PlaceholderAPI &ehooked. " ) ;
2021-04-29 18:05:18 +02:00
}
} catch ( NumberFormatException ex ) {
return false ;
2019-05-06 19:52:09 +02:00
}
2019-12-13 17:07:42 +01:00
2018-12-27 23:00:05 +01:00
return true ;
}
public static Loging getLoging ( ) {
2020-01-27 15:19:12 +01:00
if ( loging = = null )
loging = new Loging ( ) ;
2018-12-27 23:00:05 +01:00
return loging ;
}
public static BlockProtectionManager getBpManager ( ) {
2020-09-05 14:23:48 +02:00
if ( bpManager = = null )
bpManager = new BlockProtectionManager ( ) ;
return bpManager ;
2018-12-27 23:00:05 +01:00
}
public static JobsManager getDBManager ( ) {
2020-09-05 14:23:48 +02:00
if ( dbManager = = null )
2022-01-13 11:37:50 +01:00
dbManager = new JobsManager ( getInstance ( ) ) ;
2020-09-05 14:23:48 +02:00
return dbManager ;
2018-12-27 23:00:05 +01:00
}
public static ShopManager getShopManager ( ) {
2019-10-16 20:19:05 +02:00
if ( shopManager = = null ) {
2021-05-06 20:45:39 +02:00
shopManager = new ShopManager ( ) ;
2019-10-16 20:19:05 +02:00
}
2018-12-27 23:00:05 +01:00
return shopManager ;
}
public static ConfigManager getConfigManager ( ) {
2020-01-27 15:19:12 +01:00
if ( configManager = = null )
configManager = new ConfigManager ( ) ;
2018-12-27 23:00:05 +01:00
return configManager ;
}
public static GeneralConfigManager getGCManager ( ) {
2020-09-05 14:23:48 +02:00
if ( gConfigManager = = null )
gConfigManager = new GeneralConfigManager ( ) ;
return gConfigManager ;
2018-12-27 23:00:05 +01:00
}
/ * *
2021-02-02 23:04:46 +01:00
* @return { @link PlayerManager }
2018-12-27 23:00:05 +01:00
* /
public static PlayerManager getPlayerManager ( ) {
2019-02-28 19:16:53 +01:00
if ( pManager = = null )
2022-01-13 11:37:50 +01:00
pManager = new PlayerManager ( getInstance ( ) ) ;
2018-12-27 23:00:05 +01:00
return pManager ;
}
public static RestrictedBlockManager getRestrictedBlockManager ( ) {
2020-09-05 14:23:48 +02:00
if ( rbManager = = null ) {
rbManager = new RestrictedBlockManager ( ) ;
2019-10-16 20:19:05 +02:00
}
2018-12-27 23:00:05 +01:00
2020-09-05 14:23:48 +02:00
return rbManager ;
2018-12-27 23:00:05 +01:00
}
public static RestrictedAreaManager getRestrictedAreaManager ( ) {
2020-09-05 14:23:48 +02:00
if ( raManager = = null ) {
raManager = new RestrictedAreaManager ( ) ;
2019-10-16 20:19:05 +02:00
}
2018-12-27 23:00:05 +01:00
2020-09-05 14:23:48 +02:00
return raManager ;
2018-12-27 23:00:05 +01:00
}
2021-02-02 23:04:46 +01:00
/ * *
* @return { @link TitleManager }
* /
public static TitleManager getTitleManager ( ) {
2019-10-16 20:19:05 +02:00
if ( titleManager = = null ) {
titleManager = new TitleManager ( ) ;
}
2018-12-27 23:00:05 +01:00
return titleManager ;
}
public static BossBarManager getBBManager ( ) {
2020-09-05 14:23:48 +02:00
return bbManager ;
2018-12-27 23:00:05 +01:00
}
/ * *
* Returns schedule manager
* @return the schedule manager
* /
public static ScheduleManager getScheduleManager ( ) {
2019-10-16 20:19:05 +02:00
if ( scheduleManager = = null ) {
2022-01-13 11:37:50 +01:00
scheduleManager = new ScheduleManager ( getInstance ( ) ) ;
2019-10-16 20:19:05 +02:00
}
2018-12-27 23:00:05 +01:00
2019-10-16 20:19:05 +02:00
return scheduleManager ;
2018-12-27 23:00:05 +01:00
}
public static NameTranslatorManager getNameTranslatorManager ( ) {
2020-09-05 14:23:48 +02:00
if ( nameTranslatorManager = = null ) {
nameTranslatorManager = new NameTranslatorManager ( ) ;
2019-10-16 20:19:05 +02:00
}
2018-12-27 23:00:05 +01:00
2020-09-05 14:23:48 +02:00
return nameTranslatorManager ;
2018-12-27 23:00:05 +01:00
}
2021-03-24 16:17:00 +01:00
public GuiManager getGUIManager ( ) {
2020-09-05 14:23:48 +02:00
if ( guiManager = = null )
2021-03-24 16:17:00 +01:00
guiManager = new GuiManager ( this ) ;
2020-09-05 14:23:48 +02:00
return guiManager ;
2018-12-27 23:00:05 +01:00
}
public static JobsCommands getCommandManager ( ) {
2019-08-23 17:09:15 +02:00
if ( cManager = = null ) {
2022-01-13 11:37:50 +01:00
cManager = new JobsCommands ( getInstance ( ) ) ;
2019-08-23 17:09:15 +02:00
}
2018-12-27 23:00:05 +01:00
return cManager ;
}
2022-03-07 14:10:52 +01:00
@Deprecated
public static ExploreManager getExplore ( ) {
return getExploreManager ( ) ;
}
2022-03-07 13:35:58 +01:00
public static ExploreManager getExploreManager ( ) {
2020-01-27 15:19:12 +01:00
if ( exploreManager = = null )
2022-03-07 13:35:58 +01:00
exploreManager = new ExploreManager ( ) ;
2018-12-27 23:00:05 +01:00
return exploreManager ;
}
2021-03-24 16:17:00 +01:00
/ * *
* @return returns this class object instance
* /
2018-12-27 23:00:05 +01:00
public static Jobs getInstance ( ) {
2022-01-13 11:37:50 +01:00
return JavaPlugin . getPlugin ( Jobs . class ) ;
2018-12-27 23:00:05 +01:00
}
/ * *
* Returns sign manager
* @return the sign manager
* /
public static SignUtil getSignUtil ( ) {
2019-10-16 20:19:05 +02:00
if ( signManager = = null ) {
2022-01-13 11:37:50 +01:00
signManager = new SignUtil ( getInstance ( ) ) ;
2019-10-16 20:19:05 +02:00
}
2018-12-27 23:00:05 +01:00
2019-10-16 20:19:05 +02:00
return signManager ;
2018-12-27 23:00:05 +01:00
}
/ * *
* Returns language manager
* @return the language manager
* /
public static Language getLanguage ( ) {
2020-01-27 15:19:12 +01:00
if ( lManager = = null )
2021-03-10 19:14:52 +01:00
lManager = new Language ( ) ;
2018-12-27 23:00:05 +01:00
return lManager ;
}
public static LanguageManager getLanguageManager ( ) {
2019-10-16 20:19:05 +02:00
if ( lmManager = = null ) {
lmManager = new LanguageManager ( ) ;
}
2018-12-27 23:00:05 +01:00
2019-10-16 20:19:05 +02:00
return lmManager ;
2018-12-27 23:00:05 +01:00
}
/ * *
* Retrieves the plugin logger
* @return the plugin logger
* /
public static Logger getPluginLogger ( ) {
2022-01-13 11:37:50 +01:00
return getInstance ( ) . getLogger ( ) ;
2018-12-27 23:00:05 +01:00
}
public static File getFolder ( ) {
2022-01-13 11:37:50 +01:00
File folder = getInstance ( ) . getDataFolder ( ) ;
2021-03-21 17:02:42 +01:00
folder . mkdirs ( ) ;
2018-12-27 23:00:05 +01:00
return folder ;
}
/ * *
* Sets the Data Access Object
* @param dao - the DAO
* /
public static void setDAO ( JobsDAO dao ) {
Jobs . dao = dao ;
}
/ * *
* Get the Data Access Object
* @return the DAO
* /
public static JobsDAO getJobsDAO ( ) {
return dao ;
}
/ * *
* Sets the list of jobs
* @param jobs - list of jobs
* /
public static void setJobs ( List < Job > jobs ) {
Jobs . jobs = jobs ;
}
/ * *
2021-05-15 19:36:12 +02:00
* Returns the list of available jobs .
*
* @return an unmodifiable list of jobs
2018-12-27 23:00:05 +01:00
* /
public static List < Job > getJobs ( ) {
return Collections . unmodifiableList ( jobs ) ;
}
/ * *
* Sets the none job
* @param noneJob - the none job
* /
public static void setNoneJob ( Job noneJob ) {
Jobs . noneJob = noneJob ;
}
/ * *
* Retrieves the " none " job
* @return the none job
* /
public static Job getNoneJob ( ) {
return noneJob ;
}
/ * *
* Function to return the job information that matches the jobName given
* @param jobName - the ame of the job given
* @return the job that matches the name
* /
public static Job getJob ( String jobName ) {
for ( Job job : jobs ) {
2021-06-14 15:12:31 +02:00
if ( job . getName ( ) . equalsIgnoreCase ( jobName ) | | job . getJobFullName ( ) . equalsIgnoreCase ( jobName ) )
2021-05-07 14:19:49 +02:00
return job ;
2018-12-27 23:00:05 +01:00
}
2021-06-14 15:12:31 +02:00
2018-12-27 23:00:05 +01:00
return null ;
}
2021-02-02 23:04:46 +01:00
/ * *
* Returns a job by identifier .
*
* @param id the id of job
* @return { @link Job }
* /
2019-09-19 17:54:59 +02:00
public static Job getJob ( int id ) {
2021-04-11 15:22:05 +02:00
for ( Job job : jobs ) {
2021-07-16 11:34:59 +02:00
if ( job . getId ( ) = = id | | job . getLegacyId ( ) = = id ) {
2021-04-11 15:22:05 +02:00
return job ;
}
}
return null ;
2019-09-19 17:54:59 +02:00
}
2020-02-05 16:54:43 +01:00
public boolean isPlaceholderAPIEnabled ( ) {
2020-09-05 14:23:48 +02:00
return placeholderAPIEnabled ;
2020-02-05 16:54:43 +01:00
}
2022-01-13 11:37:50 +01:00
private static void startup ( ) {
2020-01-28 17:18:13 +01:00
reload ( true ) ;
2020-09-12 20:46:05 +02:00
2021-07-16 16:58:40 +02:00
// This goes in sync to avoid issues while loading data
loadAllPlayersData ( ) ;
for ( Player online : Bukkit . getServer ( ) . getOnlinePlayers ( ) )
getPlayerManager ( ) . playerJoin ( online ) ;
}
public static void loadAllPlayersData ( ) {
long time = System . currentTimeMillis ( ) ;
HashMap < UUID , PlayerInfo > temp = new HashMap < > ( getPlayerManager ( ) . getPlayersInfoUUIDMap ( ) ) ;
Map < Integer , List < JobsDAOData > > playersJobs = dao . getAllJobs ( ) ;
Map < Integer , PlayerPoints > playersPoints = dao . getAllPoints ( ) ;
Map < Integer , Map < String , Log > > playersLogs = dao . getAllLogs ( ) ;
Map < Integer , ArchivedJobs > playersArchives = dao . getAllArchivedJobs ( ) ;
Map < Integer , PaymentData > playersLimits = dao . loadPlayerLimits ( ) ;
for ( Iterator < PlayerInfo > it = temp . values ( ) . iterator ( ) ; it . hasNext ( ) ; ) {
PlayerInfo one = it . next ( ) ;
int id = one . getID ( ) ;
JobsPlayer jPlayer = getPlayerManager ( ) . getJobsPlayerOffline (
one ,
playersJobs . get ( id ) ,
playersPoints . get ( id ) ,
playersLogs . get ( id ) ,
playersArchives . get ( id ) ,
playersLimits . get ( id ) ) ;
if ( jPlayer ! = null )
getPlayerManager ( ) . addPlayerToCache ( jPlayer ) ;
}
if ( ! getPlayerManager ( ) . getPlayersCache ( ) . isEmpty ( ) )
2021-10-26 16:32:42 +02:00
consoleMsg ( " &ePreloaded &6 " + getPlayerManager ( ) . getPlayersCache ( ) . size ( ) + " &eplayers data in &6 " + ( ( int ) ( ( System . currentTimeMillis ( ) - time ) / 1000 . 0D * 100 . 0D ) / 100 . 0D ) ) ;
2018-12-27 23:00:05 +01:00
}
2020-04-13 17:44:14 +02:00
public static void convertDatabase ( ) {
try {
List < Convert > archivelist = dao . convertDatabase ( ) ;
getDBManager ( ) . switchDataBase ( ) ;
getPlayerManager ( ) . reload ( ) ;
dao . truncateAllTables ( ) ;
2021-10-26 16:14:39 +02:00
for ( Job one : Jobs . getJobs ( ) ) {
dao . recordNewJobName ( one , one . getId ( ) ) ;
}
for ( JobsWorld one : Util . getJobsWorlds ( ) . values ( ) ) {
dao . recordNewWorld ( one . getName ( ) , one . getId ( ) ) ;
}
2020-04-13 17:44:14 +02:00
getPlayerManager ( ) . convertChacheOfPlayers ( true ) ;
dao . continueConvertions ( archivelist ) ;
getPlayerManager ( ) . clearMaps ( ) ;
getPlayerManager ( ) . clearCache ( ) ;
dao . saveExplore ( ) ;
// Do we really need to convert Block protection?
// Jobs.getJobsDAO().saveBlockProtection();
} catch ( SQLException e ) {
e . printStackTrace ( ) ;
Jobs . consoleMsg ( " &cCan't write data to data base, please send error log to dev's. " ) ;
return ;
}
reload ( ) ;
loadAllPlayersData ( ) ;
2018-12-27 23:00:05 +01:00
}
2020-05-14 17:48:43 +02:00
/ * *
2021-02-02 23:04:46 +01:00
* Checks if the given { @link JobsPlayer } have the given { @link ActionType } in one of jobs .
*
2020-05-14 17:48:43 +02:00
* @param jPlayer { @link JobsPlayer }
* @param type { @link ActionType }
* @return true if the player have the given action
* /
public static boolean isPlayerHaveAction ( JobsPlayer jPlayer , ActionType type ) {
if ( jPlayer = = null | | type = = null )
return false ;
boolean found = false ;
2020-11-30 10:27:09 +01:00
for ( JobProgression prog : jPlayer . getJobProgression ( ) ) {
2021-03-24 16:17:00 +01:00
for ( JobInfo info : prog . getJob ( ) . getJobInfo ( type ) ) {
2020-05-14 17:48:43 +02:00
if ( info . getActionType ( ) = = type ) {
found = true ;
2020-11-30 10:27:09 +01:00
break ;
2020-05-14 17:48:43 +02:00
}
}
2020-11-30 10:27:09 +01:00
if ( ! found ) {
for ( Quest q : prog . getJob ( ) . getQuests ( ) ) {
if ( q ! = null & & q . hasAction ( type ) ) {
found = true ;
break ;
}
2020-05-14 17:48:43 +02:00
}
}
2020-11-30 10:27:09 +01:00
if ( found ) {
break ;
}
2020-05-14 17:48:43 +02:00
}
return found ;
}
2018-12-27 23:00:05 +01:00
/ * *
* Function to get the number of slots used on the server for this job
* @param job - the job
* @return the number of slots
* /
public static int getUsedSlots ( Job job ) {
2020-03-26 11:21:44 +01:00
return usedSlots . getOrDefault ( job , 0 ) ;
2018-12-27 23:00:05 +01:00
}
/ * *
* Function to increase the number of used slots for a job
* @param job - the job someone is taking
* /
public static void takeSlot ( Job job ) {
2021-05-02 12:44:52 +02:00
Integer used = usedSlots . get ( job ) ;
if ( used ! = null )
usedSlots . put ( job , used + 1 ) ;
2018-12-27 23:00:05 +01:00
}
/ * *
* Function to decrease the number of used slots for a job
* @param job - the job someone is leaving
* /
public static void leaveSlot ( Job job ) {
2021-05-02 12:44:52 +02:00
Integer used = usedSlots . get ( job ) ;
if ( used ! = null )
usedSlots . put ( job , used - 1 ) ;
2018-12-27 23:00:05 +01:00
}
/ * *
* Gets the permission handler
* @return the permission handler
* /
public static PermissionHandler getPermissionHandler ( ) {
2020-01-27 15:19:12 +01:00
if ( permissionHandler = = null )
2022-01-13 11:37:50 +01:00
permissionHandler = new PermissionHandler ( getInstance ( ) ) ;
2018-12-27 23:00:05 +01:00
return permissionHandler ;
}
public static PermissionManager getPermissionManager ( ) {
2020-01-27 15:19:12 +01:00
if ( permissionManager = = null )
permissionManager = new PermissionManager ( ) ;
2018-12-27 23:00:05 +01:00
return permissionManager ;
}
/ * *
* Sets the economy handler
* @param eco - the economy handler
* /
2019-10-16 20:19:05 +02:00
public static void setEconomy ( Economy eco ) {
2022-01-13 11:37:50 +01:00
economy = new BufferedEconomy ( getInstance ( ) , eco ) ;
2018-12-27 23:00:05 +01:00
}
/ * *
* Gets the economy handler
* @return the economy handler
* /
public static BufferedEconomy getEconomy ( ) {
return economy ;
}
/ * *
* Gets the version check manager
* @return the version check manager
* /
public static VersionChecker getVersionCheckManager ( ) {
2020-01-27 15:19:12 +01:00
if ( versionCheckManager = = null )
2022-01-13 11:37:50 +01:00
versionCheckManager = new VersionChecker ( getInstance ( ) ) ;
2020-01-27 15:19:12 +01:00
2018-12-27 23:00:05 +01:00
return versionCheckManager ;
}
2021-10-26 16:32:42 +02:00
private final static String prefix = " &6------------- &2Jobs &6------------- " ;
private final static String suffix = " &6------------------------------------ " ;
2018-12-27 23:00:05 +01:00
@Override
public void onEnable ( ) {
2021-10-26 16:32:42 +02:00
CMIMessages . consoleMessage ( prefix ) ;
2019-02-28 19:16:36 +01:00
2021-05-06 20:45:39 +02:00
try {
Class . forName ( " net.kyori.adventure.text.Component " ) ;
2021-06-10 11:21:30 +02:00
org . bukkit . inventory . meta . ItemMeta . class . getDeclaredMethod ( " displayName " ) ;
2021-05-06 20:45:39 +02:00
kyoriSupported = true ;
2021-06-10 11:21:30 +02:00
} catch ( NoSuchMethodException | ClassNotFoundException e ) {
2021-05-06 20:45:39 +02:00
}
2020-09-05 14:23:48 +02:00
placeholderAPIEnabled = setupPlaceHolderAPI ( ) ;
2018-12-27 23:00:05 +01:00
try {
2021-03-14 14:14:26 +01:00
new YmlMaker ( getFolder ( ) , " shopItems.yml " ) . saveDefaultConfig ( ) ;
new YmlMaker ( getFolder ( ) , " restrictedBlocks.yml " ) . saveDefaultConfig ( ) ;
2018-12-27 23:00:05 +01:00
2020-09-13 20:31:15 +02:00
bbManager = new BossBarManager ( this ) ;
2018-12-27 23:00:05 +01:00
2020-10-13 16:52:56 +02:00
Optional . ofNullable ( getCommand ( " jobs " ) ) . ifPresent ( j - > {
j . setExecutor ( getCommandManager ( ) ) ;
j . setTabCompleter ( new TabComplete ( ) ) ;
} ) ;
2018-12-27 23:00:05 +01:00
startup ( ) ;
2022-02-07 14:28:23 +01:00
if ( status . equals ( LoadStatus . MYSQLFailure ) | | status . equals ( LoadStatus . SQLITEFailure ) ) {
CMIMessages . consoleMessage ( " &cCould not connect to " + ( status . equals ( LoadStatus . MYSQLFailure ) ? " MySQL " : " SqLite " ) + " ! " ) ;
CMIMessages . consoleMessage ( " &cPlugin will be disabled " ) ;
this . onDisable ( ) ;
this . setEnabled ( false ) ;
return ;
}
2020-01-27 15:19:12 +01:00
if ( getGCManager ( ) . SignsEnabled ) {
2021-03-14 14:14:26 +01:00
new YmlMaker ( getFolder ( ) , " Signs.yml " ) . saveDefaultConfig ( ) ;
2018-12-27 23:00:05 +01:00
}
2020-01-26 17:48:23 +01:00
HookManager . loadHooks ( ) ;
2022-06-24 11:31:40 +02:00
registerListeners ( ) ;
2018-12-27 23:00:05 +01:00
2021-03-02 11:06:15 +01:00
if ( Version . isCurrentEqualOrHigher ( Version . v1_16_R3 ) & & kyoriSupported ) {
complement = new Complement2 ( ) ;
2021-03-19 15:44:49 +01:00
//getServer().getPluginManager().registerEvents(new KyoriChatEvent(this), this);
2021-03-02 11:06:15 +01:00
} else {
complement = new Complement1 ( ) ;
}
2021-02-26 08:45:14 +01:00
2018-12-27 23:00:05 +01:00
// register economy
2021-04-28 16:21:37 +02:00
getServer ( ) . getScheduler ( ) . runTask ( this , new HookEconomyTask ( this ) ) ;
2018-12-27 23:00:05 +01:00
dao . loadBlockProtection ( ) ;
2022-03-07 13:35:58 +01:00
getExploreManager ( ) . load ( ) ;
2020-01-27 15:19:12 +01:00
getCommandManager ( ) . fillCommands ( ) ;
2019-09-24 11:27:32 +02:00
getDBManager ( ) . getDB ( ) . triggerTableIdUpdate ( ) ;
2021-02-26 08:45:14 +01:00
2021-10-26 16:32:42 +02:00
consoleMsg ( " &ePlugin has been enabled successfully. " ) ;
2019-01-23 19:23:16 +01:00
} catch ( Throwable e ) {
2018-12-27 23:00:05 +01:00
e . printStackTrace ( ) ;
System . out . println ( " There was some issues when starting plugin. Please contact dev about this. Plugin will be disabled. " ) ;
setEnabled ( false ) ;
}
2021-10-26 16:32:42 +02:00
CMIMessages . consoleMessage ( suffix ) ;
2018-12-27 23:00:05 +01:00
}
2022-06-22 11:41:35 +02:00
private static void registerListeners ( ) {
org . bukkit . plugin . PluginManager pm = getInstance ( ) . getServer ( ) . getPluginManager ( ) ;
if ( Version . isCurrentEqualOrHigher ( Version . v1_9_R1 ) ) {
pm . registerEvents ( new com . gamingmesh . jobs . listeners . Listener1_9 ( ) , getInstance ( ) ) ;
}
pm . registerEvents ( new JobsListener ( getInstance ( ) ) , getInstance ( ) ) ;
pm . registerEvents ( new JobsPaymentListener ( getInstance ( ) ) , getInstance ( ) ) ;
if ( Version . isCurrentEqualOrHigher ( Version . v1_14_R1 ) ) {
pm . registerEvents ( new JobsPayment14Listener ( ) , getInstance ( ) ) ;
}
if ( getGCManager ( ) . useBlockProtection ) {
pm . registerEvents ( new PistonProtectionListener ( ) , getInstance ( ) ) ;
}
pm . registerEvents ( new JobsChatEvent ( getInstance ( ) ) , getInstance ( ) ) ;
if ( HookManager . getMcMMOManager ( ) . CheckmcMMO ( ) ) {
HookManager . setMcMMOlistener ( ) ;
}
if ( HookManager . checkMythicMobs ( ) ) {
HookManager . getMythicManager ( ) . registerListener ( ) ;
}
}
2020-01-28 17:18:13 +01:00
public static void reload ( ) {
reload ( false ) ;
}
public static void reload ( boolean startup ) {
2020-01-27 16:52:25 +01:00
// unregister all registered listeners by this plugin and register again
if ( ! startup ) {
2022-01-13 11:37:50 +01:00
HandlerList . unregisterAll ( getInstance ( ) ) ;
2022-06-24 11:31:40 +02:00
registerListeners ( ) ;
2020-01-27 16:52:25 +01:00
}
if ( saveTask ! = null ) {
saveTask . shutdown ( ) ;
}
if ( paymentThread ! = null ) {
paymentThread . shutdown ( ) ;
}
2020-11-30 21:39:04 +01:00
2020-01-27 16:52:25 +01:00
smanager = new SelectionManager ( ) ;
getGCManager ( ) . reload ( ) ;
getLanguage ( ) . reload ( ) ;
2020-04-13 17:44:14 +02:00
getConfigManager ( ) . reload ( ) ;
2020-01-27 16:52:25 +01:00
2022-02-08 18:07:12 +01:00
hasLimitedItems = Jobs . getJobs ( ) . stream ( ) . anyMatch ( job - > ! job . getLimitedItems ( ) . isEmpty ( ) ) ;
2020-01-27 16:52:25 +01:00
getDBManager ( ) . getDB ( ) . loadAllJobsWorlds ( ) ;
getDBManager ( ) . getDB ( ) . loadAllJobsNames ( ) ;
2020-10-12 12:42:50 +02:00
if ( Version . isCurrentEqualOrLower ( Version . v1_13_R1 ) ) {
2022-01-13 11:37:50 +01:00
getInstance ( ) . getBlockOwnerShip ( CMIMaterial . LEGACY_BREWING_STAND ) . ifPresent ( BlockOwnerShip : : load ) ;
getInstance ( ) . getBlockOwnerShip ( CMIMaterial . LEGACY_BURNING_FURNACE ) . ifPresent ( BlockOwnerShip : : load ) ;
2020-10-12 12:44:03 +02:00
} else {
2022-01-13 11:37:50 +01:00
getInstance ( ) . getBlockOwnerShip ( CMIMaterial . FURNACE ) . ifPresent ( BlockOwnerShip : : load ) ;
getInstance ( ) . getBlockOwnerShip ( CMIMaterial . BREWING_STAND ) . ifPresent ( BlockOwnerShip : : load ) ;
2020-10-12 12:42:50 +02:00
}
if ( Version . isCurrentEqualOrHigher ( Version . v1_14_R1 ) ) {
2022-01-13 11:37:50 +01:00
getInstance ( ) . getBlockOwnerShip ( CMIMaterial . BLAST_FURNACE ) . ifPresent ( BlockOwnerShip : : load ) ;
getInstance ( ) . getBlockOwnerShip ( CMIMaterial . SMOKER ) . ifPresent ( BlockOwnerShip : : load ) ;
2020-10-12 12:42:50 +02:00
}
2020-01-27 16:52:25 +01:00
ToggleBarHandling . load ( ) ;
usedSlots . clear ( ) ;
for ( Job job : jobs ) {
2020-04-16 18:55:32 +02:00
usedSlots . put ( job , dao . getSlotsTaken ( job ) ) ;
2020-01-27 16:52:25 +01:00
}
getPlayerManager ( ) . reload ( ) ;
getPermissionHandler ( ) . registerPermissions ( ) ;
// set the system to auto save
2020-10-26 18:43:29 +01:00
saveTask = new DatabaseSaveThread ( getGCManager ( ) . getSavePeriod ( ) ) ;
saveTask . start ( ) ;
2020-01-27 16:52:25 +01:00
// schedule payouts to buffered payments
paymentThread = new BufferedPaymentThread ( getGCManager ( ) . getEconomyBatchDelay ( ) ) ;
paymentThread . start ( ) ;
2020-04-16 18:55:32 +02:00
dao . loadPlayerData ( ) ;
2020-01-27 16:52:25 +01:00
// Schedule
if ( getGCManager ( ) . enableSchedule ) {
2022-06-24 11:31:40 +02:00
try {
getScheduleManager ( ) . load ( ) ;
getScheduleManager ( ) . start ( ) ;
} catch ( Throwable e ) {
e . printStackTrace ( ) ;
}
2020-01-27 16:52:25 +01:00
} else
getScheduleManager ( ) . cancel ( ) ;
}
2018-12-27 23:00:05 +01:00
@Override
public void onDisable ( ) {
2021-10-26 16:32:42 +02:00
CMIMessages . consoleMessage ( prefix ) ;
2021-06-14 15:12:31 +02:00
HandlerList . unregisterAll ( this ) ;
2020-08-10 19:49:55 +02:00
2021-01-19 08:35:38 +01:00
if ( dao ! = null ) {
dao . saveExplore ( ) ;
}
2021-07-15 12:11:35 +02:00
blockOwnerShipsMaterial . values ( ) . forEach ( BlockOwnerShip : : save ) ;
2020-04-13 17:44:14 +02:00
ToggleBarHandling . save ( ) ;
2019-08-16 13:22:39 +02:00
2021-01-19 08:35:38 +01:00
if ( saveTask ! = null )
saveTask . shutdown ( ) ;
if ( paymentThread ! = null )
paymentThread . shutdown ( ) ;
if ( pManager ! = null ) {
pManager . removePlayerAdditions ( ) ;
pManager . saveAll ( ) ;
}
if ( dao ! = null ) {
dao . closeConnections ( ) ;
}
2021-10-26 16:32:42 +02:00
CMIMessages . consoleMessage ( suffix ) ;
2018-12-27 23:00:05 +01:00
}
private static void checkDailyQuests ( JobsPlayer jPlayer , Job job , ActionInfo info ) {
if ( ! job . getQuests ( ) . isEmpty ( ) ) {
2021-01-19 08:35:38 +01:00
for ( QuestProgression one : jPlayer . getQuestProgressions ( job , info . getType ( ) ) ) {
one . processQuest ( jPlayer , info ) ;
2018-12-27 23:00:05 +01:00
}
}
}
/ * *
2021-02-02 23:04:46 +01:00
* Perform an action for the given { @link JobsPlayer } with the given action info .
2018-12-27 23:00:05 +01:00
*
2021-02-02 23:04:46 +01:00
* @param jPlayer { @link JobsPlayer }
* @param info { @link ActionInfo }
* @see # action ( JobsPlayer , ActionInfo , Block , Entity , LivingEntity )
2018-12-27 23:00:05 +01:00
* /
public static void action ( JobsPlayer jPlayer , ActionInfo info ) {
action ( jPlayer , info , null , null , null ) ;
}
2021-02-02 23:04:46 +01:00
/ * *
* Perform an action for the given { @link JobsPlayer } with the given action info and block .
*
* @param jPlayer { @link JobsPlayer }
* @param info { @link ActionInfo }
* @param block { @link Block }
* @see # action ( JobsPlayer , ActionInfo , Block , Entity , LivingEntity )
* /
2018-12-27 23:00:05 +01:00
public static void action ( JobsPlayer jPlayer , ActionInfo info , Block block ) {
action ( jPlayer , info , block , null , null ) ;
}
2021-02-02 23:04:46 +01:00
/ * *
* Perform an action for the given { @link JobsPlayer } with the given action info and entity .
*
* @param jPlayer { @link JobsPlayer }
* @param info { @link ActionInfo }
* @param ent { @link Entity }
* @see # action ( JobsPlayer , ActionInfo , Block , Entity , LivingEntity )
* /
2018-12-27 23:00:05 +01:00
public static void action ( JobsPlayer jPlayer , ActionInfo info , Entity ent ) {
action ( jPlayer , info , null , ent , null ) ;
}
2021-02-02 23:04:46 +01:00
/ * *
* Perform an action for the given { @link JobsPlayer } with the given action info ,
* entity and living entity .
*
* @param jPlayer { @link JobsPlayer }
* @param info { @link ActionInfo }
* @param ent { @link Entity }
* @param victim { @link LivingEntity }
* @see # action ( JobsPlayer , ActionInfo , Block , Entity , LivingEntity )
* /
2018-12-27 23:00:05 +01:00
public static void action ( JobsPlayer jPlayer , ActionInfo info , Entity ent , LivingEntity victim ) {
action ( jPlayer , info , null , ent , victim ) ;
}
2021-02-02 23:04:46 +01:00
/ * *
* Perform an action for the given { @link JobsPlayer } with the parameters .
* < p >
* The process :
* < p >
* If the player does not have any job progression cached into memory , the player
* only retrieve the " noneJob " by default . This means that there will be no any
* extra income calculations and the player does no get the full income from jobs ,
* but the half of it . < br >
* In other cases if player have at least 1 job cached , they will get the full income
* with the extra calculated multiplications including bonuses and limits .
* < p >
*
* < b > This usually not be called in your code , to avoid misbehaviour working ability . < / b >
*
* @param jPlayer { @link JobsPlayer }
* @param info { @link ActionInfo }
* @param ent { @link Entity }
* @param victim { @link LivingEntity }
* @param block { @link Block }
* /
2018-12-27 23:00:05 +01:00
public static void action ( JobsPlayer jPlayer , ActionInfo info , Block block , Entity ent , LivingEntity victim ) {
if ( jPlayer = = null )
return ;
List < JobProgression > progression = jPlayer . getJobProgression ( ) ;
int numjobs = progression . size ( ) ;
if ( ! isBpOk ( jPlayer , info , block , true ) )
return ;
2020-04-27 19:06:43 +02:00
// no job
2018-12-27 23:00:05 +01:00
if ( numjobs = = 0 ) {
2021-03-29 15:07:21 +02:00
if ( noneJob = = null | | noneJob . isWorldBlackListed ( block ) | | noneJob . isWorldBlackListed ( block , ent ) | | noneJob . isWorldBlackListed ( victim ) )
2020-03-25 13:08:33 +01:00
return ;
2018-12-27 23:00:05 +01:00
JobInfo jobinfo = noneJob . getJobInfo ( info , 1 ) ;
checkDailyQuests ( jPlayer , noneJob , info ) ;
if ( jobinfo = = null )
return ;
2021-04-10 16:05:10 +02:00
double income = jobinfo . getIncome ( 1 , numjobs , jPlayer . maxJobsEquation ) ;
double pointAmount = jobinfo . getPoints ( 1 , numjobs , jPlayer . maxJobsEquation ) ;
2018-12-27 23:00:05 +01:00
if ( income = = 0D & & pointAmount = = 0D )
return ;
2019-03-01 17:03:45 +01:00
Boost boost = getPlayerManager ( ) . getFinalBonus ( jPlayer , noneJob ) ;
2018-12-27 23:00:05 +01:00
2020-09-05 14:23:48 +02:00
JobsPrePaymentEvent jobsPrePaymentEvent = new JobsPrePaymentEvent ( jPlayer . getPlayer ( ) , noneJob , income ,
2019-09-19 13:01:24 +02:00
pointAmount , block , ent , victim , info ) ;
2020-09-05 14:23:48 +02:00
Bukkit . getServer ( ) . getPluginManager ( ) . callEvent ( jobsPrePaymentEvent ) ;
2019-06-08 18:27:23 +02:00
// If event is canceled, don't do anything
2020-09-05 14:23:48 +02:00
if ( jobsPrePaymentEvent . isCancelled ( ) ) {
2019-06-08 18:27:23 +02:00
income = 0D ;
pointAmount = 0D ;
} else {
2020-09-05 14:23:48 +02:00
income = jobsPrePaymentEvent . getAmount ( ) ;
pointAmount = jobsPrePaymentEvent . getPoints ( ) ;
2019-06-08 18:27:23 +02:00
}
2019-06-05 09:46:50 +02:00
2018-12-27 23:00:05 +01:00
// Calculate income
if ( income ! = 0D ) {
2019-10-28 11:20:04 +01:00
income = boost . getFinalAmount ( CurrencyType . MONEY , income ) ;
2021-04-29 18:05:18 +02:00
2020-09-05 14:23:48 +02:00
if ( gConfigManager . useMinimumOveralPayment & & income > 0 ) {
double maxLimit = income * gConfigManager . MinimumOveralPaymentLimit ;
2021-04-29 18:05:18 +02:00
2018-12-27 23:00:05 +01:00
if ( income < maxLimit )
income = maxLimit ;
}
}
// Calculate points
if ( pointAmount ! = 0D ) {
2019-10-28 11:20:04 +01:00
pointAmount = boost . getFinalAmount ( CurrencyType . POINTS , pointAmount ) ;
2021-04-29 18:05:18 +02:00
2020-09-05 14:23:48 +02:00
if ( gConfigManager . useMinimumOveralPoints & & pointAmount > 0 ) {
2021-04-29 18:05:18 +02:00
double maxLimit = pointAmount * gConfigManager . MinimumOveralPointsLimit ;
2018-12-27 23:00:05 +01:00
if ( pointAmount < maxLimit )
pointAmount = maxLimit ;
}
}
2021-04-29 18:05:18 +02:00
2018-12-27 23:00:05 +01:00
if ( ! jPlayer . isUnderLimit ( CurrencyType . MONEY , income ) ) {
2020-09-05 14:23:48 +02:00
if ( gConfigManager . useMaxPaymentCurve ) {
2019-01-31 14:35:53 +01:00
double percentOver = jPlayer . percentOverLimit ( CurrencyType . MONEY ) ;
2021-06-03 17:13:21 +02:00
double percentLoss = 100 / ( ( 1 / gConfigManager . maxPaymentCurveFactor * percentOver * percentOver ) + 1 ) ;
2019-01-31 14:35:53 +01:00
income = income - ( income * percentLoss / 100 ) ;
} else
income = 0D ;
2020-09-05 14:23:48 +02:00
if ( gConfigManager . getLimit ( CurrencyType . MONEY ) . getStopWith ( ) . contains ( CurrencyType . POINTS ) )
2018-12-27 23:00:05 +01:00
pointAmount = 0D ;
}
if ( ! jPlayer . isUnderLimit ( CurrencyType . POINTS , pointAmount ) ) {
pointAmount = 0D ;
2020-09-05 14:23:48 +02:00
if ( gConfigManager . getLimit ( CurrencyType . POINTS ) . getStopWith ( ) . contains ( CurrencyType . MONEY ) )
2018-12-27 23:00:05 +01:00
income = 0D ;
}
if ( income = = 0D & & pointAmount = = 0D )
return ;
if ( info . getType ( ) = = ActionType . BREAK & & block ! = null )
2020-01-28 18:25:14 +01:00
getBpManager ( ) . remove ( block ) ;
2018-12-27 23:00:05 +01:00
if ( pointAmount ! = 0D )
jPlayer . setSaved ( false ) ;
2021-03-14 14:14:26 +01:00
Map < CurrencyType , Double > payments = new HashMap < > ( ) ;
2019-09-19 13:01:24 +02:00
if ( income ! = 0D )
payments . put ( CurrencyType . MONEY , income ) ;
if ( pointAmount ! = 0D )
payments . put ( CurrencyType . POINTS , pointAmount ) ;
economy . pay ( jPlayer , payments ) ;
2018-12-27 23:00:05 +01:00
2020-09-05 14:23:48 +02:00
if ( gConfigManager . LoggingUse ) {
2021-03-14 14:14:26 +01:00
Map < CurrencyType , Double > amounts = new HashMap < > ( ) ;
2018-12-27 23:00:05 +01:00
amounts . put ( CurrencyType . MONEY , income ) ;
2020-01-28 18:25:14 +01:00
getLoging ( ) . recordToLog ( jPlayer , info , amounts ) ;
2018-12-27 23:00:05 +01:00
}
} else {
2020-05-08 12:01:32 +02:00
List < Job > expiredJobs = new ArrayList < > ( ) ;
2018-12-27 23:00:05 +01:00
for ( JobProgression prog : progression ) {
2020-04-27 19:06:43 +02:00
if ( prog . getJob ( ) . isWorldBlackListed ( block ) | | prog . getJob ( ) . isWorldBlackListed ( block , ent )
| | prog . getJob ( ) . isWorldBlackListed ( victim ) )
2020-03-25 15:08:23 +01:00
continue ;
2020-03-25 13:08:33 +01:00
2020-05-08 12:01:32 +02:00
if ( jPlayer . isLeftTimeEnded ( prog . getJob ( ) ) ) {
expiredJobs . add ( prog . getJob ( ) ) ;
}
2021-06-03 17:13:21 +02:00
JobInfo jobinfo = prog . getJob ( ) . getJobInfo ( info , prog . getLevel ( ) ) ;
2018-12-27 23:00:05 +01:00
checkDailyQuests ( jPlayer , prog . getJob ( ) , info ) ;
2020-05-06 16:56:50 +02:00
2020-10-22 12:26:32 +02:00
if ( jobinfo = = null | | ( gConfigManager . disablePaymentIfMaxLevelReached & & prog . getLevel ( ) > = prog . getJob ( ) . getMaxLevel ( ) ) ) {
2020-06-01 16:53:05 +02:00
continue ;
}
2021-06-03 17:13:21 +02:00
double income = jobinfo . getIncome ( prog . getLevel ( ) , numjobs , jPlayer . maxJobsEquation ) ;
double pointAmount = jobinfo . getPoints ( prog . getLevel ( ) , numjobs , jPlayer . maxJobsEquation ) ;
double expAmount = jobinfo . getExperience ( prog . getLevel ( ) , numjobs , jPlayer . maxJobsEquation ) ;
2018-12-27 23:00:05 +01:00
if ( income = = 0D & & pointAmount = = 0D & & expAmount = = 0D )
continue ;
2020-09-05 14:23:48 +02:00
if ( gConfigManager . addXpPlayer ( ) ) {
2018-12-27 23:00:05 +01:00
Player player = jPlayer . getPlayer ( ) ;
if ( player ! = null ) {
/ *
* Minecraft experience is calculated in whole numbers only .
* Calculate the fraction of an experience point and perform a dice roll .
* That way jobs that give fractions of experience points will slowly give
* experience in the aggregate
* /
2021-03-14 14:14:26 +01:00
int expInt = ( int ) expAmount ;
double remainder = expAmount - expInt ;
2018-12-27 23:00:05 +01:00
if ( Math . abs ( remainder ) > Math . random ( ) ) {
2021-03-14 14:14:26 +01:00
if ( expAmount < 0 )
2018-12-27 23:00:05 +01:00
expInt - - ;
else
expInt + + ;
}
if ( expInt < 0 & & getPlayerExperience ( player ) < - expInt ) {
player . setLevel ( 0 ) ;
player . setTotalExperience ( 0 ) ;
player . setExp ( 0 ) ;
} else
player . giveExp ( expInt ) ;
}
}
2019-06-05 09:46:50 +02:00
2019-03-01 17:03:45 +01:00
Boost boost = getPlayerManager ( ) . getFinalBonus ( jPlayer , prog . getJob ( ) , ent , victim ) ;
2018-12-27 23:00:05 +01:00
2020-09-05 14:23:48 +02:00
JobsPrePaymentEvent jobsPrePaymentEvent = new JobsPrePaymentEvent ( jPlayer . getPlayer ( ) , prog . getJob ( ) , income ,
2019-08-23 17:28:35 +02:00
pointAmount , block , ent , victim , info ) ;
2020-05-06 13:54:55 +02:00
2020-09-05 14:23:48 +02:00
Bukkit . getServer ( ) . getPluginManager ( ) . callEvent ( jobsPrePaymentEvent ) ;
2019-06-05 09:46:50 +02:00
// If event is canceled, don't do anything
2020-09-05 14:23:48 +02:00
if ( jobsPrePaymentEvent . isCancelled ( ) ) {
2019-06-08 18:27:23 +02:00
income = 0D ;
pointAmount = 0D ;
} else {
2020-09-05 14:23:48 +02:00
income = jobsPrePaymentEvent . getAmount ( ) ;
pointAmount = jobsPrePaymentEvent . getPoints ( ) ;
2019-06-08 18:27:23 +02:00
}
2019-06-05 09:46:50 +02:00
2018-12-27 23:00:05 +01:00
// Calculate income
if ( income ! = 0D ) {
income = boost . getFinalAmount ( CurrencyType . MONEY , income ) ;
2021-04-29 18:05:18 +02:00
2020-09-05 14:23:48 +02:00
if ( gConfigManager . useMinimumOveralPayment & & income > 0 ) {
double maxLimit = income * gConfigManager . MinimumOveralPaymentLimit ;
2021-04-29 18:05:18 +02:00
2018-12-27 23:00:05 +01:00
if ( income < maxLimit )
income = maxLimit ;
}
}
// Calculate points
if ( pointAmount ! = 0D ) {
pointAmount = boost . getFinalAmount ( CurrencyType . POINTS , pointAmount ) ;
2021-04-29 18:05:18 +02:00
2020-09-05 14:23:48 +02:00
if ( gConfigManager . useMinimumOveralPoints & & pointAmount > 0 ) {
2021-04-29 18:05:18 +02:00
double maxLimit = pointAmount * gConfigManager . MinimumOveralPointsLimit ;
2018-12-27 23:00:05 +01:00
if ( pointAmount < maxLimit )
pointAmount = maxLimit ;
}
}
// Calculate exp
2021-04-29 18:05:18 +02:00
if ( expAmount ! = 0D ) {
expAmount = boost . getFinalAmount ( CurrencyType . EXP , expAmount ) ;
2018-12-27 23:00:05 +01:00
2021-04-29 18:05:18 +02:00
if ( gConfigManager . useMinimumOveralExp & & expAmount > 0 ) {
double maxLimit = expAmount * gConfigManager . minimumOveralExpLimit ;
if ( expAmount < maxLimit )
expAmount = maxLimit ;
}
2018-12-27 23:00:05 +01:00
}
if ( ! jPlayer . isUnderLimit ( CurrencyType . MONEY , income ) ) {
income = 0D ;
2021-04-29 19:28:59 +02:00
CurrencyLimit cLimit = gConfigManager . getLimit ( CurrencyType . MONEY ) ;
if ( cLimit . getStopWith ( ) . contains ( CurrencyType . EXP ) )
2018-12-27 23:00:05 +01:00
expAmount = 0D ;
2021-04-29 19:28:59 +02:00
if ( cLimit . getStopWith ( ) . contains ( CurrencyType . POINTS ) )
2018-12-27 23:00:05 +01:00
pointAmount = 0D ;
}
if ( ! jPlayer . isUnderLimit ( CurrencyType . EXP , expAmount ) ) {
expAmount = 0D ;
2021-04-29 19:28:59 +02:00
CurrencyLimit cLimit = gConfigManager . getLimit ( CurrencyType . EXP ) ;
if ( cLimit . getStopWith ( ) . contains ( CurrencyType . MONEY ) )
2018-12-27 23:00:05 +01:00
income = 0D ;
2021-04-29 19:28:59 +02:00
if ( cLimit . getStopWith ( ) . contains ( CurrencyType . POINTS ) )
2018-12-27 23:00:05 +01:00
pointAmount = 0D ;
}
if ( ! jPlayer . isUnderLimit ( CurrencyType . POINTS , pointAmount ) ) {
pointAmount = 0D ;
2021-04-29 19:28:59 +02:00
CurrencyLimit cLimit = gConfigManager . getLimit ( CurrencyType . POINTS ) ;
if ( cLimit . getStopWith ( ) . contains ( CurrencyType . MONEY ) )
2018-12-27 23:00:05 +01:00
income = 0D ;
2021-04-29 19:28:59 +02:00
if ( cLimit . getStopWith ( ) . contains ( CurrencyType . EXP ) )
2018-12-27 23:00:05 +01:00
expAmount = 0D ;
}
if ( income = = 0D & & pointAmount = = 0D & & expAmount = = 0D )
continue ;
2019-08-23 15:36:54 +02:00
// JobsPayment event
2020-09-05 14:23:48 +02:00
JobsExpGainEvent jobsExpGainEvent = new JobsExpGainEvent ( jPlayer . getPlayer ( ) , prog . getJob ( ) , expAmount ,
2020-12-17 14:16:30 +01:00
block , ent , victim , info ) ;
2020-09-05 14:23:48 +02:00
Bukkit . getServer ( ) . getPluginManager ( ) . callEvent ( jobsExpGainEvent ) ;
2019-08-23 17:09:15 +02:00
// If event is canceled, don't do anything
2020-09-05 14:23:48 +02:00
expAmount = jobsExpGainEvent . isCancelled ( ) ? 0D : jobsExpGainEvent . getExp ( ) ;
2019-08-23 15:36:54 +02:00
2018-12-27 23:00:05 +01:00
try {
2020-09-05 14:23:48 +02:00
if ( expAmount ! = 0D & & gConfigManager . BossBarEnabled )
if ( gConfigManager . BossBarShowOnEachAction )
bbManager . ShowJobProgression ( jPlayer , prog , expAmount ) ;
2018-12-27 23:00:05 +01:00
else
jPlayer . getUpdateBossBarFor ( ) . add ( prog . getJob ( ) . getName ( ) ) ;
2019-01-23 19:23:16 +01:00
} catch ( Throwable e ) {
2020-08-02 18:53:36 +02:00
e . printStackTrace ( ) ;
2018-12-27 23:00:05 +01:00
consoleMsg ( " &c[Jobs] Some issues with boss bar feature accured, try disabling it to avoid it. " ) ;
}
2021-03-14 14:14:26 +01:00
Map < CurrencyType , Double > payments = new HashMap < > ( ) ;
2019-09-19 13:01:24 +02:00
if ( income ! = 0D )
payments . put ( CurrencyType . MONEY , income ) ;
if ( pointAmount ! = 0D )
payments . put ( CurrencyType . POINTS , pointAmount ) ;
if ( expAmount ! = 0D )
payments . put ( CurrencyType . EXP , expAmount ) ;
2020-09-05 14:23:48 +02:00
FASTPAYMENT . put ( jPlayer . getUniqueId ( ) , new FastPayment ( jPlayer , info , new BufferedPayment ( jPlayer . getPlayer ( ) , payments ) , prog
2018-12-27 23:00:05 +01:00
. getJob ( ) ) ) ;
2019-09-19 13:01:24 +02:00
economy . pay ( jPlayer , payments ) ;
2018-12-27 23:00:05 +01:00
int oldLevel = prog . getLevel ( ) ;
2020-09-05 14:23:48 +02:00
if ( gConfigManager . LoggingUse ) {
2021-03-14 14:14:26 +01:00
Map < CurrencyType , Double > amounts = new HashMap < > ( ) ;
2018-12-27 23:00:05 +01:00
amounts . put ( CurrencyType . MONEY , income ) ;
amounts . put ( CurrencyType . EXP , expAmount ) ;
amounts . put ( CurrencyType . POINTS , pointAmount ) ;
2020-01-28 18:25:14 +01:00
getLoging ( ) . recordToLog ( jPlayer , info , amounts ) ;
2018-12-27 23:00:05 +01:00
}
if ( prog . addExperience ( expAmount ) )
2019-05-26 10:49:03 +02:00
getPlayerManager ( ) . performLevelUp ( jPlayer , prog . getJob ( ) , oldLevel ) ;
2018-12-27 23:00:05 +01:00
}
//need to update bp
if ( block ! = null ) {
2020-01-28 18:25:14 +01:00
BlockProtection bp = getBpManager ( ) . getBp ( block . getLocation ( ) ) ;
2018-12-27 23:00:05 +01:00
if ( bp ! = null )
bp . setPaid ( true ) ;
}
2020-05-08 12:01:32 +02:00
expiredJobs . forEach ( j - > getPlayerManager ( ) . leaveJob ( jPlayer , j ) ) ;
2018-12-27 23:00:05 +01:00
}
}
private static boolean isBpOk ( JobsPlayer player , ActionInfo info , Block block , boolean inform ) {
2020-09-05 14:23:48 +02:00
if ( block = = null | | ! gConfigManager . useBlockProtection )
2018-12-27 23:00:05 +01:00
return true ;
if ( info . getType ( ) = = ActionType . BREAK ) {
if ( block . hasMetadata ( " JobsExploit " ) ) {
//player.sendMessage("This block is protected using Rukes' system!");
return false ;
}
2020-08-14 11:48:20 +02:00
2020-01-28 18:25:14 +01:00
BlockProtection bp = getBpManager ( ) . getBp ( block . getLocation ( ) ) ;
2018-12-27 23:00:05 +01:00
if ( bp ! = null ) {
2021-05-04 14:50:28 +02:00
long time = bp . getTime ( ) ;
2020-01-28 18:25:14 +01:00
Integer cd = getBpManager ( ) . getBlockDelayTime ( block ) ;
2018-12-27 23:00:05 +01:00
if ( time = = - 1L ) {
2020-04-25 15:27:46 +02:00
getBpManager ( ) . remove ( block ) ;
2018-12-27 23:00:05 +01:00
return false ;
}
2020-08-14 11:48:20 +02:00
2020-12-17 16:16:48 +01:00
if ( time < System . currentTimeMillis ( ) & & bp . getAction ( ) ! = DBAction . DELETE ) {
2020-01-28 18:25:14 +01:00
getBpManager ( ) . remove ( block ) ;
2018-12-27 23:00:05 +01:00
return true ;
}
2020-08-14 11:48:20 +02:00
2021-03-25 14:04:05 +01:00
if ( ( time > System . currentTimeMillis ( ) | | bp . isPaid ( ) ) & & bp . getAction ( ) ! = DBAction . DELETE ) {
2020-08-14 11:48:20 +02:00
if ( inform & & player . canGetPaid ( info ) ) {
2021-05-26 21:45:22 +02:00
int sec = Math . round ( ( time - System . currentTimeMillis ( ) ) / 1000L ) ;
2021-06-20 12:24:49 +02:00
CMIActionBar . send ( player . getPlayer ( ) , lManager . getMessage ( " message.blocktimer " , " [time] " , sec ) ) ;
2018-12-27 23:00:05 +01:00
}
2020-08-14 11:48:20 +02:00
2018-12-27 23:00:05 +01:00
return false ;
}
2020-08-14 11:48:20 +02:00
2020-01-28 18:25:14 +01:00
getBpManager ( ) . add ( block , cd ) ;
2020-08-14 11:48:20 +02:00
2020-09-05 14:23:48 +02:00
if ( ( cd = = null | | cd = = 0 ) & & gConfigManager . useGlobalTimer ) {
getBpManager ( ) . add ( block , gConfigManager . globalblocktimer ) ;
2018-12-27 23:00:05 +01:00
}
2020-08-14 11:48:20 +02:00
2020-09-05 14:23:48 +02:00
} else if ( gConfigManager . useGlobalTimer ) {
getBpManager ( ) . add ( block , gConfigManager . globalblocktimer ) ;
2018-12-27 23:00:05 +01:00
}
} else if ( info . getType ( ) = = ActionType . PLACE ) {
2020-01-28 18:25:14 +01:00
BlockProtection bp = getBpManager ( ) . getBp ( block . getLocation ( ) ) ;
2018-12-27 23:00:05 +01:00
if ( bp ! = null ) {
Long time = bp . getTime ( ) ;
2020-01-28 18:25:14 +01:00
Integer cd = getBpManager ( ) . getBlockDelayTime ( block ) ;
2018-12-27 23:00:05 +01:00
if ( time ! = - 1L ) {
if ( time < System . currentTimeMillis ( ) & & bp . getAction ( ) ! = DBAction . DELETE ) {
2020-01-28 18:25:14 +01:00
getBpManager ( ) . add ( block , cd ) ;
2018-12-27 23:00:05 +01:00
return true ;
}
2020-08-22 20:40:25 +02:00
2021-03-25 14:04:05 +01:00
if ( ( time > System . currentTimeMillis ( ) | | bp . isPaid ( ) ) & & bp . getAction ( ) ! = DBAction . DELETE ) {
2020-08-22 20:40:25 +02:00
if ( inform & & player . canGetPaid ( info ) ) {
2021-05-26 21:45:22 +02:00
int sec = Math . round ( ( time - System . currentTimeMillis ( ) ) / 1000L ) ;
2021-06-20 12:24:49 +02:00
CMIActionBar . send ( player . getPlayer ( ) , lManager . getMessage ( " message.blocktimer " , " [time] " , sec ) ) ;
2018-12-27 23:00:05 +01:00
}
2020-08-22 20:40:25 +02:00
2020-01-28 18:25:14 +01:00
getBpManager ( ) . add ( block , cd ) ;
2018-12-27 23:00:05 +01:00
return false ;
}
2020-12-17 14:16:30 +01:00
// Lets add protection in any case
getBpManager ( ) . add ( block , cd ) ;
2021-05-04 14:50:28 +02:00
} else if ( bp . isPaid ( ) & & bp . getTime ( ) = = - 1L & & cd ! = null & & cd = = - 1 ) {
2020-01-28 18:25:14 +01:00
getBpManager ( ) . add ( block , cd ) ;
2018-12-27 23:00:05 +01:00
return false ;
} else
2020-01-28 18:25:14 +01:00
getBpManager ( ) . add ( block , cd ) ;
2018-12-27 23:00:05 +01:00
} else
2020-01-28 18:25:14 +01:00
getBpManager ( ) . add ( block , getBpManager ( ) . getBlockDelayTime ( block ) ) ;
2018-12-27 23:00:05 +01:00
}
return true ;
}
private static int getPlayerExperience ( Player player ) {
2020-11-23 20:11:21 +01:00
return ( expToLevel ( player . getLevel ( ) ) + Math . round ( deltaLevelToExp ( player . getLevel ( ) ) * player . getExp ( ) ) ) ;
2018-12-27 23:00:05 +01:00
}
// total xp calculation based by lvl
2020-11-23 20:11:21 +01:00
private static int expToLevel ( int level ) {
2020-01-27 15:19:12 +01:00
if ( Version . isCurrentEqualOrLower ( Version . v1_7_R4 ) ) {
2018-12-27 23:00:05 +01:00
if ( level < = 16 )
return 17 * level ;
else if ( level < = 31 )
return ( ( 3 * level * level ) / 2 ) - ( ( 59 * level ) / 2 ) + 360 ;
else
return ( ( 7 * level * level ) / 2 ) - ( ( 303 * level ) / 2 ) + 2220 ;
}
if ( level < = 16 )
return ( level * level ) + ( 6 * level ) ;
else if ( level < = 31 )
return ( int ) ( ( 2 . 5 * level * level ) - ( 40 . 5 * level ) + 360 ) ;
else
return ( int ) ( ( 4 . 5 * level * level ) - ( 162 . 5 * level ) + 2220 ) ;
}
// xp calculation for one current lvl
private static int deltaLevelToExp ( int level ) {
2020-01-27 15:19:12 +01:00
if ( Version . isCurrentEqualOrLower ( Version . v1_7_R4 ) ) {
2018-12-27 23:00:05 +01:00
if ( level < = 16 )
return 17 ;
else if ( level < = 31 )
return 3 * level - 31 ;
else
return 7 * level - 155 ;
}
if ( level < = 16 )
return 2 * level + 7 ;
else if ( level < = 31 )
return 5 * level - 38 ;
else
return 9 * level - 158 ;
}
public static void perform ( JobsPlayer jPlayer , ActionInfo info , BufferedPayment payment , Job job ) {
2021-05-23 16:28:33 +02:00
double expPayment = payment . get ( CurrencyType . EXP ) ;
JobsExpGainEvent jobsExpGainEvent = new JobsExpGainEvent ( payment . getOfflinePlayer ( ) , job , expPayment ) ;
2020-09-05 14:23:48 +02:00
Bukkit . getServer ( ) . getPluginManager ( ) . callEvent ( jobsExpGainEvent ) ;
2018-12-27 23:00:05 +01:00
// If event is canceled, don't do anything
2020-09-05 14:23:48 +02:00
if ( jobsExpGainEvent . isCancelled ( ) )
2018-12-27 23:00:05 +01:00
return ;
2020-10-30 13:29:36 +01:00
boolean limited = true ;
2019-09-19 13:01:24 +02:00
for ( CurrencyType one : CurrencyType . values ( ) ) {
2020-10-30 13:29:36 +01:00
if ( jPlayer . isUnderLimit ( one , payment . get ( one ) ) ) {
limited = false ;
break ;
}
2019-09-19 13:01:24 +02:00
}
2018-12-27 23:00:05 +01:00
2020-10-30 13:29:36 +01:00
if ( limited )
return ;
2020-11-21 12:11:34 +01:00
2019-09-19 13:01:24 +02:00
economy . pay ( jPlayer , payment . getPayment ( ) ) ;
2018-12-27 23:00:05 +01:00
JobProgression prog = jPlayer . getJobProgression ( job ) ;
int oldLevel = prog . getLevel ( ) ;
2020-09-05 14:23:48 +02:00
if ( gConfigManager . LoggingUse ) {
2020-01-28 18:25:14 +01:00
getLoging ( ) . recordToLog ( jPlayer , info , payment . getPayment ( ) ) ;
2018-12-27 23:00:05 +01:00
}
2021-05-23 16:28:33 +02:00
if ( prog . addExperience ( expPayment ) )
2019-05-26 10:49:03 +02:00
getPlayerManager ( ) . performLevelUp ( jPlayer , prog . getJob ( ) , oldLevel ) ;
2018-12-27 23:00:05 +01:00
}
public static void consoleMsg ( String msg ) {
2019-12-13 17:07:42 +01:00
if ( msg ! = null ) {
2020-06-29 12:51:24 +02:00
Bukkit . getServer ( ) . getConsoleSender ( ) . sendMessage ( CMIChatColor . translate ( msg ) ) ;
2019-12-13 17:07:42 +01:00
}
2018-12-27 23:00:05 +01:00
}
public static SelectionManager getSelectionManager ( ) {
return smanager ;
}
public static boolean hasPermission ( Object sender , String perm , boolean rawEnable ) {
2020-10-13 16:52:56 +02:00
if ( ! ( sender instanceof Player ) | | ( ( Player ) sender ) . hasPermission ( perm ) )
2019-05-26 10:49:03 +02:00
return true ;
2019-05-26 11:36:00 +02:00
2019-05-26 10:49:03 +02:00
if ( ! rawEnable ) {
2022-06-22 14:51:48 +02:00
CMIMessages . sendMessage ( sender , LC . info_NoPermission ) ;
2018-12-27 23:00:05 +01:00
return false ;
}
2022-06-22 14:51:48 +02:00
new RawMessage ( ) . addText ( LC . info_NoPermission . getLocale ( ) ) . addHover ( " &2 " + perm ) . show ( ( Player ) sender ) ;
2019-05-26 10:49:03 +02:00
return false ;
2018-12-27 23:00:05 +01:00
}
2020-11-23 20:11:21 +01:00
public void showPagination ( CommandSender sender , PageInfo pi , String cmd ) {
showPagination ( sender , pi . getTotalPages ( ) , pi . getCurrentPage ( ) , pi . getTotalEntries ( ) , cmd , null ) ;
2018-12-27 23:00:05 +01:00
}
2020-11-23 20:11:21 +01:00
public void showPagination ( CommandSender sender , PageInfo pi , String cmd , String pagePref ) {
showPagination ( sender , pi . getTotalPages ( ) , pi . getCurrentPage ( ) , pi . getTotalEntries ( ) , cmd , pagePref ) ;
2018-12-27 23:00:05 +01:00
}
2020-11-23 20:11:21 +01:00
public void showPagination ( CommandSender sender , int pageCount , int currentPage , int totalEntries , String cmd , String pagePref ) {
2018-12-27 23:00:05 +01:00
if ( ! ( sender instanceof Player ) )
return ;
2020-08-02 18:53:36 +02:00
2018-12-27 23:00:05 +01:00
if ( ! cmd . startsWith ( " / " ) )
cmd = " / " + cmd ;
2020-08-02 18:53:36 +02:00
2018-12-27 23:00:05 +01:00
if ( pageCount = = 1 )
return ;
2020-08-02 18:53:36 +02:00
2018-12-27 23:00:05 +01:00
String pagePrefix = pagePref = = null ? " " : pagePref ;
2020-08-02 18:53:36 +02:00
2020-11-23 20:11:21 +01:00
int nextPage = currentPage + 1 ;
nextPage = currentPage < pageCount ? nextPage : currentPage ;
2020-08-02 18:53:36 +02:00
2020-11-23 20:11:21 +01:00
int prevpage = currentPage - 1 ;
2021-05-15 18:40:12 +02:00
if ( currentPage < = 1 ) {
prevpage = currentPage ;
}
2018-12-27 23:00:05 +01:00
2020-08-02 18:53:36 +02:00
RawMessage rm = new RawMessage ( )
2022-06-22 14:51:48 +02:00
. addText ( ( currentPage > 1 ? LC . info_prevPage . getLocale ( ) : LC . info_prevPageOff . getLocale ( ) ) )
. addHover ( currentPage > 1 ? LC . info_prevPageHover . getLocale ( ) : LC . info_lastPageHover . getLocale ( ) )
2020-12-17 14:16:30 +01:00
. addCommand ( currentPage > 1 ? cmd + " " + pagePrefix + prevpage : cmd + " " + pagePrefix + pageCount ) ;
2020-07-29 10:50:01 +02:00
2022-06-22 14:51:48 +02:00
rm . addText ( LC . info_pageCount . getLocale ( " [current] " , currentPage , " [total] " , pageCount ) )
. addHover ( LC . info_pageCountHover . getLocale ( " [totalEntries] " , totalEntries ) ) ;
2020-07-29 10:50:01 +02:00
2022-06-22 14:51:48 +02:00
rm . addText ( pageCount > currentPage ? LC . info_nextPage . getLocale ( ) : LC . info_nextPageOff . getLocale ( ) )
2022-06-24 11:31:40 +02:00
. addHover ( pageCount > currentPage ? LC . info_nextPageHover . getLocale ( ) : LC . info_firstPageHover . getLocale ( ) )
2020-12-17 14:16:30 +01:00
. addCommand ( pageCount > currentPage ? cmd + " " + pagePrefix + nextPage : cmd + " " + pagePrefix + 1 ) ;
2020-01-27 11:50:42 +01:00
2018-12-27 23:00:05 +01:00
if ( pageCount ! = 0 )
rm . show ( sender ) ;
}
2022-02-08 18:07:12 +01:00
2022-02-11 16:18:51 +01:00
public static boolean hasLimitedItems ( ) {
return hasLimitedItems ;
}
2018-12-27 23:00:05 +01:00
}