2011-05-15 19:33:03 +02:00
package com.Acrobot.ChestShop ;
2011-05-15 18:16:25 +02:00
2012-11-23 21:04:13 +01:00
import com.Acrobot.Breeze.Configuration.Configuration ;
2013-10-27 16:49:14 +01:00
import com.Acrobot.ChestShop.Commands.Give ;
2011-05-29 13:25:25 +02:00
import com.Acrobot.ChestShop.Commands.ItemInfo ;
2021-02-15 17:28:33 +01:00
import com.Acrobot.ChestShop.Commands.ShopInfo ;
2014-05-20 23:13:25 +02:00
import com.Acrobot.ChestShop.Commands.Toggle ;
2011-05-29 13:25:25 +02:00
import com.Acrobot.ChestShop.Commands.Version ;
2019-09-16 13:56:30 +02:00
import com.Acrobot.ChestShop.Commands.AccessToggle ;
2012-11-23 21:04:13 +01:00
import com.Acrobot.ChestShop.Configuration.Messages ;
import com.Acrobot.ChestShop.Configuration.Properties ;
2015-05-22 13:25:32 +02:00
import com.Acrobot.ChestShop.Database.Migrations ;
2012-06-08 15:28:36 +02:00
import com.Acrobot.ChestShop.Listeners.Block.BlockPlace ;
2012-09-12 12:35:48 +02:00
import com.Acrobot.ChestShop.Listeners.Block.Break.ChestBreak ;
2012-10-16 17:03:45 +02:00
import com.Acrobot.ChestShop.Listeners.Block.Break.SignBreak ;
2013-01-24 22:35:28 +01:00
import com.Acrobot.ChestShop.Listeners.Block.SignCreate ;
2013-07-13 23:14:10 +02:00
import com.Acrobot.ChestShop.Listeners.Economy.ServerAccountCorrector ;
import com.Acrobot.ChestShop.Listeners.Economy.TaxModule ;
2015-08-06 15:59:51 +02:00
import com.Acrobot.ChestShop.Listeners.AuthMeChestShopListener ;
2015-05-22 13:25:32 +02:00
import com.Acrobot.ChestShop.Listeners.GarbageTextListener ;
2013-03-24 20:57:54 +01:00
import com.Acrobot.ChestShop.Listeners.Item.ItemMoveListener ;
2021-01-03 01:55:01 +01:00
import com.Acrobot.ChestShop.Listeners.Item.ItemStringListener ;
2012-06-08 15:28:36 +02:00
import com.Acrobot.ChestShop.Listeners.ItemInfoListener ;
2021-01-03 01:55:01 +01:00
import com.Acrobot.ChestShop.Listeners.Modules.ItemAliasModule ;
2020-06-19 22:39:23 +02:00
import com.Acrobot.ChestShop.Listeners.Modules.MetricsModule ;
2020-10-30 22:45:16 +01:00
import com.Acrobot.ChestShop.Listeners.Modules.StockCounterModule ;
2021-02-15 17:28:33 +01:00
import com.Acrobot.ChestShop.Listeners.ShopInfoListener ;
2019-01-17 19:50:47 +01:00
import com.Acrobot.ChestShop.Listeners.SignParseListener ;
2013-04-23 21:04:59 +02:00
import com.Acrobot.ChestShop.Listeners.Modules.DiscountModule ;
import com.Acrobot.ChestShop.Listeners.Modules.PriceRestrictionModule ;
2014-05-20 23:13:25 +02:00
import com.Acrobot.ChestShop.Listeners.Player.* ;
2018-08-22 01:21:34 +02:00
import com.Acrobot.ChestShop.Listeners.PreShopCreation.CreationFeeGetter ;
2013-01-24 22:35:28 +01:00
import com.Acrobot.ChestShop.Listeners.PostShopCreation.MessageSender ;
2013-08-07 02:03:09 +02:00
import com.Acrobot.ChestShop.Listeners.PostShopCreation.ShopCreationLogger ;
2013-01-24 22:35:28 +01:00
import com.Acrobot.ChestShop.Listeners.PostShopCreation.SignSticker ;
2012-10-16 17:03:45 +02:00
import com.Acrobot.ChestShop.Listeners.PostTransaction.* ;
2013-01-24 22:35:28 +01:00
import com.Acrobot.ChestShop.Listeners.PreShopCreation.* ;
2012-08-10 21:44:32 +02:00
import com.Acrobot.ChestShop.Listeners.PreTransaction.* ;
2013-01-24 22:35:28 +01:00
import com.Acrobot.ChestShop.Listeners.PreTransaction.ErrorMessageSender ;
import com.Acrobot.ChestShop.Listeners.PreTransaction.PermissionChecker ;
2013-08-07 02:03:09 +02:00
import com.Acrobot.ChestShop.Listeners.ShopRemoval.ShopRefundListener ;
import com.Acrobot.ChestShop.Listeners.ShopRemoval.ShopRemovalLogger ;
2012-05-10 16:32:25 +02:00
import com.Acrobot.ChestShop.Logging.FileFormatter ;
2013-01-24 22:35:28 +01:00
import com.Acrobot.ChestShop.Metadata.ItemDatabase ;
2012-08-10 19:00:20 +02:00
import com.Acrobot.ChestShop.Signs.RestrictedSign ;
2014-04-12 13:57:39 +02:00
import com.Acrobot.ChestShop.UUIDs.NameManager ;
2020-06-18 22:19:35 +02:00
import com.Acrobot.ChestShop.Updater.JenkinsBuildsNotifier ;
2014-04-15 16:00:57 +02:00
import com.Acrobot.ChestShop.Updater.Updater ;
2015-08-06 15:59:51 +02:00
2020-06-19 22:39:23 +02:00
import com.google.common.collect.ImmutableMap ;
2019-11-19 21:50:17 +01:00
import com.google.common.io.ByteArrayDataOutput ;
import com.google.common.io.ByteStreams ;
2020-12-01 19:48:26 +01:00
import net.kyori.adventure.platform.bukkit.BukkitAudiences ;
import net.kyori.adventure.text.Component ;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer ;
2020-07-03 19:24:14 +02:00
import net.md_5.bungee.api.chat.BaseComponent ;
import net.md_5.bungee.chat.ComponentSerializer ;
2016-08-28 05:20:46 +02:00
import org.apache.logging.log4j.Level ;
import org.apache.logging.log4j.LogManager ;
import org.apache.logging.log4j.Marker ;
import org.apache.logging.log4j.core.LogEvent ;
import org.apache.logging.log4j.core.LoggerContext ;
import org.apache.logging.log4j.core.config.LoggerConfig ;
import org.apache.logging.log4j.core.filter.AbstractFilter ;
import org.apache.logging.log4j.message.Message ;
2020-06-19 22:39:23 +02:00
import org.bstats.bukkit.Metrics ;
2012-06-08 15:28:36 +02:00
import org.bukkit.Bukkit ;
2020-06-19 22:39:23 +02:00
import org.bukkit.Material ;
2011-05-15 18:16:25 +02:00
import org.bukkit.Server ;
2018-11-25 00:59:13 +01:00
import org.bukkit.command.CommandExecutor ;
import org.bukkit.command.PluginCommand ;
2012-11-25 23:34:21 +01:00
import org.bukkit.configuration.file.YamlConfiguration ;
2012-05-10 16:32:25 +02:00
import org.bukkit.event.Event ;
import org.bukkit.event.Listener ;
2016-08-20 22:17:10 +02:00
import org.bukkit.plugin.Plugin ;
2011-05-15 18:16:25 +02:00
import org.bukkit.plugin.PluginDescriptionFile ;
import org.bukkit.plugin.java.JavaPlugin ;
2011-05-29 13:25:25 +02:00
import java.io.File ;
2012-05-10 16:32:25 +02:00
import java.io.IOException ;
2018-11-25 00:59:13 +01:00
import java.util.ArrayList ;
2020-06-19 22:39:23 +02:00
import java.util.LinkedHashMap ;
2011-05-29 13:25:25 +02:00
import java.util.List ;
2020-06-19 22:39:23 +02:00
import java.util.Map ;
import java.util.UUID ;
import java.util.jar.JarFile ;
2012-05-10 16:32:25 +02:00
import java.util.logging.FileHandler ;
import java.util.logging.Logger ;
2020-06-19 22:39:23 +02:00
import java.util.stream.Collectors ;
2011-05-29 13:25:25 +02:00
2011-05-15 18:16:25 +02:00
/ * *
* Main file of the plugin
2011-05-29 13:25:25 +02:00
*
2011-05-15 18:16:25 +02:00
* @author Acrobot
* /
2011-05-15 19:33:03 +02:00
public class ChestShop extends JavaPlugin {
2013-01-24 22:35:28 +01:00
private static ChestShop plugin ;
private static Server server ;
private static PluginDescriptionFile description ;
2011-05-15 18:16:25 +02:00
2020-12-01 19:48:26 +01:00
private static BukkitAudiences audiences ;
2013-01-24 22:35:28 +01:00
private static File dataFolder ;
private static ItemDatabase itemDatabase ;
2011-05-15 18:16:25 +02:00
2013-01-24 22:35:28 +01:00
private static Logger logger ;
2012-05-10 16:32:25 +02:00
private FileHandler handler ;
2011-09-06 19:01:57 +02:00
2018-11-25 00:59:13 +01:00
private List < PluginCommand > commands = new ArrayList < > ( ) ;
2015-05-22 13:25:32 +02:00
public ChestShop ( ) {
2012-05-10 16:32:25 +02:00
dataFolder = getDataFolder ( ) ;
2015-05-22 13:25:32 +02:00
logger = getLogger ( ) ;
2012-05-10 16:32:25 +02:00
description = getDescription ( ) ;
server = getServer ( ) ;
2015-05-22 13:25:32 +02:00
plugin = this ;
}
2011-05-15 18:16:25 +02:00
2018-08-29 21:32:27 +02:00
@Override
public void onLoad ( ) {
Dependencies . initializePlugins ( ) ;
}
@Override
2015-05-22 13:25:32 +02:00
public void onEnable ( ) {
2020-12-01 19:48:26 +01:00
audiences = BukkitAudiences . create ( this ) ;
2016-08-28 05:20:46 +02:00
turnOffDatabaseLogging ( ) ;
2017-11-26 18:45:35 +01:00
if ( ! handleMigrations ( ) ) {
return ;
}
2014-04-12 17:37:23 +02:00
2018-11-25 00:59:13 +01:00
registerCommand ( " iteminfo " , new ItemInfo ( ) , Permission . ITEMINFO ) ;
2021-02-15 17:28:33 +01:00
registerCommand ( " shopinfo " , new ShopInfo ( ) , Permission . SHOPINFO ) ;
2018-11-25 00:59:13 +01:00
registerCommand ( " csVersion " , new Version ( ) , Permission . ADMIN ) ;
2020-06-19 22:39:23 +02:00
registerCommand ( " csMetrics " , new com . Acrobot . ChestShop . Commands . Metrics ( ) , Permission . ADMIN ) ;
2018-11-25 00:59:13 +01:00
registerCommand ( " csGive " , new Give ( ) , Permission . ADMIN ) ;
registerCommand ( " cstoggle " , new Toggle ( ) , Permission . NOTIFY_TOGGLE ) ;
2019-09-16 13:56:30 +02:00
registerCommand ( " csaccess " , new AccessToggle ( ) , Permission . ACCESS_TOGGLE ) ;
2013-02-10 15:28:16 +01:00
2018-11-25 00:59:13 +01:00
loadConfig ( ) ;
itemDatabase = new ItemDatabase ( ) ;
2014-04-10 22:52:21 +02:00
2018-07-11 19:09:07 +02:00
if ( ! Dependencies . loadPlugins ( ) ) {
2018-11-25 00:59:13 +01:00
getServer ( ) . getPluginManager ( ) . disablePlugin ( this ) ;
2018-07-11 19:09:07 +02:00
return ;
}
2011-05-29 13:25:25 +02:00
2011-09-06 19:01:57 +02:00
registerEvents ( ) ;
2011-08-13 12:08:34 +02:00
2019-11-19 21:50:17 +01:00
registerPluginMessagingChannels ( ) ;
2012-11-23 21:04:13 +01:00
if ( Properties . LOG_TO_FILE ) {
File log = loadFile ( " ChestShop.log " ) ;
2011-07-05 19:08:55 +02:00
2012-05-10 16:32:25 +02:00
FileHandler handler = loadHandler ( log . getAbsolutePath ( ) ) ;
handler . setFormatter ( new FileFormatter ( ) ) ;
2012-03-06 19:41:14 +01:00
2012-05-10 16:32:25 +02:00
this . handler = handler ;
logger . addHandler ( handler ) ;
}
2012-12-19 18:54:23 +01:00
2012-11-23 21:04:13 +01:00
if ( ! Properties . LOG_TO_CONSOLE ) {
2012-05-10 16:32:25 +02:00
logger . setUseParentHandlers ( false ) ;
}
2011-05-29 13:25:25 +02:00
2012-01-25 16:32:34 +01:00
startStatistics ( ) ;
2020-06-18 22:19:35 +02:00
startBuildNotificatier ( ) ;
2014-03-20 16:57:19 +01:00
startUpdater ( ) ;
2011-05-15 18:16:25 +02:00
}
2018-11-25 00:59:13 +01:00
private void registerCommand ( String name , CommandExecutor executor , Permission permission ) {
PluginCommand command = getCommand ( name ) ;
command . setExecutor ( executor ) ;
command . setPermission ( permission . toString ( ) ) ;
commands . add ( command ) ;
}
public void loadConfig ( ) {
2020-04-17 16:10:27 +02:00
Configuration . pairFileAndClass ( loadFile ( " config.yml " ) , Properties . class , getBukkitLogger ( ) ) ;
2020-06-28 19:00:09 +02:00
Messages . load ( ) ;
2018-11-25 00:59:13 +01:00
NameManager . load ( ) ;
2020-06-28 19:00:09 +02:00
commands . forEach ( c - > c . setPermissionMessage ( Messages . ACCESS_DENIED . getTextWithPrefix ( null ) ) ) ;
2018-11-25 00:59:13 +01:00
}
2016-08-28 05:20:46 +02:00
private void turnOffDatabaseLogging ( ) {
LoggerContext ctx = ( LoggerContext ) LogManager . getContext ( false ) ;
org . apache . logging . log4j . core . config . Configuration config = ctx . getConfiguration ( ) ;
LoggerConfig loggerConfig = config . getLoggerConfig ( " " ) ;
loggerConfig . addFilter ( new AbstractFilter ( ) {
@Override
public Result filter ( org . apache . logging . log4j . core . Logger logger , Level level , Marker marker , String msg , Object . . . params ) {
return filter ( logger . getName ( ) , level ) ;
}
@Override
public Result filter ( org . apache . logging . log4j . core . Logger logger , Level level , Marker marker , Object msg , Throwable t ) {
return filter ( logger . getName ( ) , level ) ;
}
@Override
public Result filter ( org . apache . logging . log4j . core . Logger logger , Level level , Marker marker , Message msg , Throwable t ) {
return filter ( logger . getName ( ) , level ) ;
}
@Override
public Result filter ( LogEvent event ) {
return filter ( event . getLoggerName ( ) , event . getLevel ( ) ) ;
}
private Result filter ( String classname , Level level ) {
2017-06-05 20:29:29 +02:00
if ( level . intLevel ( ) < = Level . ERROR . intLevel ( ) & & ! classname . contains ( " SqliteDatabaseType " ) ) {
2016-08-28 05:20:46 +02:00
return Result . NEUTRAL ;
}
if ( classname . contains ( " SqliteDatabaseType " ) | | classname . contains ( " TableUtils " ) ) {
return Result . DENY ;
} else {
return Result . NEUTRAL ;
}
}
} ) ;
}
2017-11-26 18:45:35 +01:00
private boolean handleMigrations ( ) {
2014-04-21 17:08:20 +02:00
File versionFile = loadFile ( " version " ) ;
YamlConfiguration previousVersion = YamlConfiguration . loadConfiguration ( versionFile ) ;
2014-04-12 17:37:23 +02:00
if ( previousVersion . get ( " version " ) = = null ) {
2015-05-22 13:25:32 +02:00
previousVersion . set ( " version " , Migrations . CURRENT_DATABASE_VERSION ) ;
2014-04-21 17:08:20 +02:00
try {
previousVersion . save ( versionFile ) ;
} catch ( IOException e ) {
e . printStackTrace ( ) ;
}
2014-04-12 17:37:23 +02:00
}
int lastVersion = previousVersion . getInt ( " version " ) ;
2015-05-22 13:25:32 +02:00
int newVersion = Migrations . migrate ( lastVersion ) ;
2014-04-12 17:37:23 +02:00
2017-11-26 18:45:35 +01:00
if ( newVersion = = - 1 ) {
plugin . getLogger ( ) . log ( java . util . logging . Level . SEVERE , " Error while migrating! ChestShop can not run with a broken/outdated database... " ) ;
plugin . getServer ( ) . getPluginManager ( ) . disablePlugin ( this ) ;
return false ;
} else if ( lastVersion ! = newVersion ) {
2015-05-22 13:25:32 +02:00
previousVersion . set ( " version " , newVersion ) ;
2015-03-11 18:01:50 +01:00
2015-05-22 13:25:32 +02:00
try {
previousVersion . save ( versionFile ) ;
} catch ( IOException e ) {
e . printStackTrace ( ) ;
}
2014-04-12 17:37:23 +02:00
}
2017-11-26 18:45:35 +01:00
return true ;
2014-04-12 17:37:23 +02:00
}
2012-11-23 21:04:13 +01:00
public static File loadFile ( String string ) {
File file = new File ( dataFolder , string ) ;
return loadFile ( file ) ;
}
2012-05-10 16:32:25 +02:00
private static File loadFile ( File file ) {
if ( ! file . exists ( ) ) {
try {
2013-04-05 13:11:06 +02:00
if ( file . getParent ( ) ! = null ) {
file . getParentFile ( ) . mkdirs ( ) ;
}
2012-05-10 16:32:25 +02:00
file . createNewFile ( ) ;
} catch ( IOException e ) {
e . printStackTrace ( ) ;
}
}
return file ;
}
private static FileHandler loadHandler ( String path ) {
FileHandler handler = null ;
try {
handler = new FileHandler ( path , true ) ;
} catch ( IOException ex ) {
ex . printStackTrace ( ) ;
}
return handler ;
}
2011-05-15 18:16:25 +02:00
public void onDisable ( ) {
2012-03-01 22:03:59 +01:00
getServer ( ) . getScheduler ( ) . cancelTasks ( this ) ;
2012-05-10 16:32:25 +02:00
2014-05-20 23:13:25 +02:00
Toggle . clearToggledPlayers ( ) ;
2012-05-10 16:32:25 +02:00
if ( handler ! = null ) {
handler . close ( ) ;
getLogger ( ) . removeHandler ( handler ) ;
}
2011-05-15 18:16:25 +02:00
}
2012-01-25 16:32:34 +01:00
////////////////// REGISTER EVENTS, SCHEDULER & STATS ///////////////////////////
2011-09-06 19:01:57 +02:00
private void registerEvents ( ) {
2012-06-25 17:15:32 +02:00
registerEvent ( new com . Acrobot . ChestShop . Plugins . ChestShop ( ) ) ; //Chest protection
2020-09-10 15:32:34 +02:00
registerEvent ( new Dependencies ( ) ) ;
2019-05-07 00:49:16 +02:00
registerEvent ( new NameManager ( ) ) ;
2013-01-24 22:35:28 +01:00
registerPreShopCreationEvents ( ) ;
registerPreTransactionEvents ( ) ;
registerPostShopCreationEvents ( ) ;
registerPostTransactionEvents ( ) ;
2013-08-07 02:03:09 +02:00
registerShopRemovalEvents ( ) ;
2013-01-24 22:35:28 +01:00
2013-04-23 21:04:59 +02:00
registerModules ( ) ;
2012-10-16 17:03:45 +02:00
registerEvent ( new SignBreak ( ) ) ;
2013-01-24 22:35:28 +01:00
registerEvent ( new SignCreate ( ) ) ;
2012-09-12 12:35:48 +02:00
registerEvent ( new ChestBreak ( ) ) ;
2012-10-16 17:03:45 +02:00
2012-05-10 16:32:25 +02:00
registerEvent ( new BlockPlace ( ) ) ;
2012-06-08 15:28:36 +02:00
registerEvent ( new PlayerConnect ( ) ) ;
2012-08-10 18:56:16 +02:00
registerEvent ( new PlayerInteract ( ) ) ;
2012-09-12 12:35:48 +02:00
registerEvent ( new PlayerInventory ( ) ) ;
2014-05-20 23:13:25 +02:00
registerEvent ( new PlayerLeave ( ) ) ;
2013-07-28 16:59:44 +02:00
registerEvent ( new PlayerTeleport ( ) ) ;
2012-06-08 15:28:36 +02:00
2019-01-17 19:50:47 +01:00
registerEvent ( new SignParseListener ( ) ) ;
2021-01-03 01:55:01 +01:00
registerEvent ( new ItemStringListener ( ) ) ;
2012-06-08 15:28:36 +02:00
registerEvent ( new ItemInfoListener ( ) ) ;
2021-02-15 17:28:33 +01:00
registerEvent ( new ShopInfoListener ( ) ) ;
2015-05-22 13:25:32 +02:00
registerEvent ( new GarbageTextListener ( ) ) ;
2018-05-07 16:32:51 +02:00
2016-08-20 22:17:10 +02:00
Plugin authMe = getServer ( ) . getPluginManager ( ) . getPlugin ( " AuthMe " ) ;
2017-01-16 19:53:21 +01:00
if ( authMe ! = null & & authMe . isEnabled ( ) ) {
2015-08-06 15:59:51 +02:00
registerEvent ( new AuthMeChestShopListener ( ) ) ;
}
2013-01-24 22:35:28 +01:00
registerEvent ( new RestrictedSign ( ) ) ;
2013-08-26 23:36:50 +02:00
if ( ! Properties . TURN_OFF_HOPPER_PROTECTION ) {
registerEvent ( new ItemMoveListener ( ) ) ;
}
2013-01-24 22:35:28 +01:00
}
2012-08-10 18:56:16 +02:00
2013-08-07 02:03:09 +02:00
private void registerShopRemovalEvents ( ) {
registerEvent ( new ShopRefundListener ( ) ) ;
registerEvent ( new ShopRemovalLogger ( ) ) ;
}
2013-01-24 22:35:28 +01:00
private void registerPreShopCreationEvents ( ) {
if ( Properties . BLOCK_SHOPS_WITH_SELL_PRICE_HIGHER_THAN_BUY_PRICE ) {
registerEvent ( new PriceRatioChecker ( ) ) ;
}
2012-08-10 18:56:16 +02:00
2013-01-24 22:35:28 +01:00
registerEvent ( new ChestChecker ( ) ) ;
registerEvent ( new ItemChecker ( ) ) ;
registerEvent ( new MoneyChecker ( ) ) ;
registerEvent ( new NameChecker ( ) ) ;
registerEvent ( new com . Acrobot . ChestShop . Listeners . PreShopCreation . PermissionChecker ( ) ) ;
registerEvent ( new com . Acrobot . ChestShop . Listeners . PreShopCreation . ErrorMessageSender ( ) ) ;
registerEvent ( new PriceChecker ( ) ) ;
registerEvent ( new QuantityChecker ( ) ) ;
registerEvent ( new TerrainChecker ( ) ) ;
}
2012-08-10 19:00:20 +02:00
2013-01-24 22:35:28 +01:00
private void registerPostShopCreationEvents ( ) {
registerEvent ( new CreationFeeGetter ( ) ) ;
registerEvent ( new MessageSender ( ) ) ;
registerEvent ( new SignSticker ( ) ) ;
2013-08-07 02:03:09 +02:00
registerEvent ( new ShopCreationLogger ( ) ) ;
2013-01-24 22:35:28 +01:00
}
private void registerPreTransactionEvents ( ) {
2012-11-23 21:04:13 +01:00
if ( Properties . ALLOW_PARTIAL_TRANSACTIONS ) {
2012-08-10 18:56:16 +02:00
registerEvent ( new PartialTransactionModule ( ) ) ;
} else {
registerEvent ( new AmountAndPriceChecker ( ) ) ;
}
2012-06-08 15:28:36 +02:00
2020-11-18 15:10:58 +01:00
registerEvent ( new InvalidNameIgnorer ( ) ) ;
2013-01-24 22:35:28 +01:00
registerEvent ( new CreativeModeIgnorer ( ) ) ;
registerEvent ( new ErrorMessageSender ( ) ) ;
registerEvent ( new PermissionChecker ( ) ) ;
registerEvent ( new PriceValidator ( ) ) ;
registerEvent ( new ShopValidator ( ) ) ;
registerEvent ( new SpamClickProtector ( ) ) ;
registerEvent ( new StockFittingChecker ( ) ) ;
}
private void registerPostTransactionEvents ( ) {
registerEvent ( new EconomicModule ( ) ) ;
registerEvent ( new EmptyShopDeleter ( ) ) ;
registerEvent ( new ItemManager ( ) ) ;
registerEvent ( new TransactionLogger ( ) ) ;
registerEvent ( new TransactionMessageSender ( ) ) ;
2012-05-10 16:32:25 +02:00
}
2012-03-17 15:00:25 +01:00
2013-04-23 21:04:59 +02:00
private void registerModules ( ) {
2021-01-03 01:55:01 +01:00
registerEvent ( new ItemAliasModule ( ) ) ;
2013-04-23 21:04:59 +02:00
registerEvent ( new DiscountModule ( ) ) ;
2020-06-19 22:39:23 +02:00
registerEvent ( new MetricsModule ( ) ) ;
2013-04-23 21:04:59 +02:00
registerEvent ( new PriceRestrictionModule ( ) ) ;
2020-10-30 22:45:16 +01:00
registerEvent ( new StockCounterModule ( ) ) ;
2013-07-13 23:14:10 +02:00
registerEconomicalModules ( ) ;
}
private void registerEconomicalModules ( ) {
registerEvent ( new ServerAccountCorrector ( ) ) ;
registerEvent ( new TaxModule ( ) ) ;
2013-04-23 21:04:59 +02:00
}
2019-11-19 21:50:17 +01:00
private void registerPluginMessagingChannels ( ) {
if ( Properties . BUNGEECORD_MESSAGES ) {
getServer ( ) . getMessenger ( ) . registerOutgoingPluginChannel ( this , " BungeeCord " ) ;
}
}
2012-05-10 16:32:25 +02:00
public void registerEvent ( Listener listener ) {
getServer ( ) . getPluginManager ( ) . registerEvents ( listener , this ) ;
2011-09-06 19:01:57 +02:00
}
2012-03-17 15:00:25 +01:00
private void startStatistics ( ) {
2020-06-19 22:39:23 +02:00
Metrics bStats = new Metrics ( this , 1109 ) ;
2012-03-17 15:00:25 +01:00
try {
2020-06-19 22:39:23 +02:00
String dist = new JarFile ( this . getFile ( ) ) . getManifest ( ) . getMainAttributes ( ) . getValue ( " Distribution-Type " ) ;
bStats . addCustomChart ( new Metrics . SimplePie ( " distributionType " , ( ) - > dist ) ) ;
} catch ( IOException ignored ) { }
2021-06-04 01:35:27 +02:00
String serverVersion = getServer ( ) . getBukkitVersion ( ) . split ( " - " ) [ 0 ] ;
bStats . addCustomChart ( createStaticDrilldownStat ( " versionMcSelf " , serverVersion , getDescription ( ) . getVersion ( ) ) ) ;
bStats . addCustomChart ( createStaticDrilldownStat ( " versionSelfMc " , getDescription ( ) . getVersion ( ) , serverVersion ) ) ;
String javaVersion = System . getProperty ( " java.version " ) ;
bStats . addCustomChart ( createStaticDrilldownStat ( " versionJavaSelf " , javaVersion , getDescription ( ) . getVersion ( ) ) ) ;
bStats . addCustomChart ( createStaticDrilldownStat ( " versionSelfJava " , getDescription ( ) . getVersion ( ) , javaVersion ) ) ;
bStats . addCustomChart ( createStaticDrilldownStat ( " versionJavaMc " , javaVersion , serverVersion ) ) ;
bStats . addCustomChart ( createStaticDrilldownStat ( " versionMcJava " , serverVersion , javaVersion ) ) ;
2020-06-19 22:39:23 +02:00
bStats . addCustomChart ( new Metrics . SingleLineChart ( " shopAccounts " , NameManager : : getAccountCount ) ) ;
bStats . addCustomChart ( new Metrics . MultiLineChart ( " transactionCount " , ( ) - > ImmutableMap . of (
" total " , MetricsModule . getTotalTransactions ( ) ,
" buy " , MetricsModule . getBuyTransactions ( ) ,
" sell " , MetricsModule . getSellTransactions ( )
2020-11-18 15:31:44 +01:00
) ) ) ;
bStats . addCustomChart ( new Metrics . MultiLineChart ( " itemCount " , ( ) - > ImmutableMap . of (
2020-06-19 22:39:23 +02:00
" total " , MetricsModule . getTotalItemsCount ( ) ,
" buy " , MetricsModule . getSoldItemsCount ( ) ,
" sell " , MetricsModule . getBoughtItemsCount ( )
) ) ) ;
bStats . addCustomChart ( new Metrics . SimplePie ( " includeSettingsInMetrics " , ( ) - > Properties . INCLUDE_SETTINGS_IN_METRICS ? " enabled " : " disabled " ) ) ;
if ( ! Properties . INCLUDE_SETTINGS_IN_METRICS ) return ;
bStats . addCustomChart ( new Metrics . AdvancedBarChart ( " pluginProperties " , ( ) - > {
Map < String , int [ ] > map = new LinkedHashMap < > ( ) ;
2020-11-18 15:31:44 +01:00
map . put ( " ensure-correct-playerid " , getChartArray ( Properties . ENSURE_CORRECT_PLAYERID ) ) ;
2020-06-19 22:39:23 +02:00
map . put ( " reverse-buttons " , getChartArray ( Properties . REVERSE_BUTTONS ) ) ;
map . put ( " shift-sells-in-stacks " , getChartArray ( Properties . SHIFT_SELLS_IN_STACKS ) ) ;
map . put ( " shift-sells-everything " , getChartArray ( Properties . SHIFT_SELLS_EVERYTHING ) ) ;
map . put ( " allow-sign-chest-open " , getChartArray ( ! Properties . ALLOW_SIGN_CHEST_OPEN ) ) ;
2021-10-13 00:30:49 +02:00
map . put ( " sign-dying " , getChartArray ( ! Properties . SIGN_DYING ) ) ;
2020-06-19 22:39:23 +02:00
map . put ( " remove-empty-shops " , getChartArray ( ! Properties . REMOVE_EMPTY_SHOPS ) ) ;
map . put ( " remove-empty-chests " , getChartArray ( ! Properties . REMOVE_EMPTY_CHESTS ) ) ;
map . put ( " uses-server-economy-account " , getChartArray ( ! Properties . SERVER_ECONOMY_ACCOUNT . isEmpty ( ) ) ) ;
map . put ( " uses-server-economy-account-uuid " , getChartArray ( ! Properties . SERVER_ECONOMY_ACCOUNT_UUID . equals ( new UUID ( 0 , 0 ) ) ) ) ;
map . put ( " allow-multiple-shops-at-one-block " , getChartArray ( Properties . ALLOW_MULTIPLE_SHOPS_AT_ONE_BLOCK ) ) ;
map . put ( " allow-partial-transactions " , getChartArray ( Properties . ALLOW_PARTIAL_TRANSACTIONS ) ) ;
map . put ( " bungeecord-messages " , getChartArray ( Properties . BUNGEECORD_MESSAGES ) ) ;
map . put ( " log-to-console " , getChartArray ( Properties . LOG_TO_CONSOLE ) ) ;
map . put ( " log-to-file " , getChartArray ( Properties . LOG_TO_FILE ) ) ;
return map ;
} ) ) ;
bStats . addCustomChart ( new Metrics . SimpleBarChart ( " shopContainers " ,
( ) - > Properties . SHOP_CONTAINERS . stream ( ) . map ( Material : : name ) . collect ( Collectors . toMap ( k - > k , k - > 1 ) ) ) ) ;
}
2021-06-04 01:35:27 +02:00
private Metrics . DrilldownPie createStaticDrilldownStat ( String statId , String value1 , String value2 ) {
final Map < String , Map < String , Integer > > map = ImmutableMap . of ( value1 , ImmutableMap . of ( value2 , 1 ) ) ;
return new Metrics . DrilldownPie ( statId , ( ) - > map ) ;
}
2020-06-19 22:39:23 +02:00
private int [ ] getChartArray ( boolean value ) {
2020-06-21 20:09:03 +02:00
return new int [ ] { ! value ? 1 : 0 , value ? 0 : 1 } ;
2012-03-17 15:00:25 +01:00
}
2014-03-20 16:57:19 +01:00
private static final int PROJECT_BUKKITDEV_ID = 31263 ;
private void startUpdater ( ) {
if ( Properties . TURN_OFF_UPDATES ) {
2020-06-18 19:12:56 +02:00
getLogger ( ) . info ( " Auto-updater is disabled. If you want the plugin to automatically download new releases then set 'TURN_OFF_UPDATES' to 'false' in your config.yml! " ) ;
2014-03-20 16:57:19 +01:00
return ;
}
new Updater ( this , PROJECT_BUKKITDEV_ID , this . getFile ( ) , Updater . UpdateType . DEFAULT , true ) ;
}
2020-06-18 22:19:35 +02:00
private static final String PROJECT_JENKINS_JOB_URL = " https://ci.minebench.de/job/ChestShop-3/ " ;
private void startBuildNotificatier ( ) {
if ( Properties . TURN_OFF_DEV_UPDATE_NOTIFIER ) {
return ;
}
new JenkinsBuildsNotifier ( this , PROJECT_JENKINS_JOB_URL ) ;
}
2011-05-29 13:25:25 +02:00
///////////////////////////////////////////////////////////////////////////////
2011-05-15 18:16:25 +02:00
2013-01-24 22:35:28 +01:00
public static ItemDatabase getItemDatabase ( ) {
return itemDatabase ;
}
2012-05-10 16:32:25 +02:00
public static File getFolder ( ) {
return dataFolder ;
}
public static Logger getBukkitLogger ( ) {
return logger ;
}
2011-05-29 13:25:25 +02:00
public static Server getBukkitServer ( ) {
return server ;
}
2011-05-15 18:16:25 +02:00
2011-05-29 13:25:25 +02:00
public static String getVersion ( ) {
2011-07-23 21:00:47 +02:00
return description . getVersion ( ) ;
2011-05-29 13:25:25 +02:00
}
public static String getPluginName ( ) {
2011-07-23 21:00:47 +02:00
return description . getName ( ) ;
2011-05-29 13:25:25 +02:00
}
2012-11-04 21:09:38 +01:00
public static List < String > getDependencies ( ) {
2012-05-10 16:32:25 +02:00
return description . getSoftDepend ( ) ;
}
2013-01-24 22:35:28 +01:00
public static ChestShop getPlugin ( ) {
return plugin ;
}
2020-12-01 19:48:26 +01:00
public static BukkitAudiences getAudiences ( ) {
return audiences ;
}
2012-05-10 16:32:25 +02:00
public static void registerListener ( Listener listener ) {
plugin . registerEvent ( listener ) ;
}
2021-01-03 01:55:01 +01:00
public static < E extends Event > E callEvent ( E event ) {
2012-11-23 21:04:13 +01:00
Bukkit . getPluginManager ( ) . callEvent ( event ) ;
2021-01-03 01:55:01 +01:00
return event ;
2012-06-08 15:28:36 +02:00
}
2019-11-19 21:50:17 +01:00
2020-06-28 19:00:09 +02:00
public static void sendBungeeMessage ( String playerName , Messages . Message message , Map < String , String > replacementMap , String . . . replacements ) {
2020-12-01 19:48:26 +01:00
sendBungeeMessage ( playerName , message . getComponent ( null , true , replacementMap , replacements ) ) ;
2020-06-28 19:00:09 +02:00
}
2019-11-19 21:50:17 +01:00
public static void sendBungeeMessage ( String playerName , String message ) {
2020-07-03 19:24:14 +02:00
sendBungeeMessage ( playerName , " Message " , message ) ;
}
public static void sendBungeeMessage ( String playerName , BaseComponent [ ] message ) {
sendBungeeMessage ( playerName , " MessageRaw " , ComponentSerializer . toString ( message ) ) ;
}
2020-12-01 19:48:26 +01:00
public static void sendBungeeMessage ( String playerName , Component message ) {
sendBungeeMessage ( playerName , " MessageRaw " , GsonComponentSerializer . gson ( ) . serialize ( message ) ) ;
}
2020-07-03 19:24:14 +02:00
private static void sendBungeeMessage ( String playerName , String channel , String message ) {
2019-11-19 21:50:17 +01:00
if ( Properties . BUNGEECORD_MESSAGES & & ! Bukkit . getOnlinePlayers ( ) . isEmpty ( ) ) {
ByteArrayDataOutput out = ByteStreams . newDataOutput ( ) ;
2020-07-03 19:24:14 +02:00
out . writeUTF ( channel ) ;
2019-11-19 21:50:17 +01:00
out . writeUTF ( playerName ) ;
out . writeUTF ( message ) ;
Bukkit . getOnlinePlayers ( ) . iterator ( ) . next ( ) . sendPluginMessage ( plugin , " BungeeCord " , out . toByteArray ( ) ) ;
}
}
2011-05-15 18:16:25 +02:00
}