5959import com .bencodez .simpleapi .sql .mysql .config .MysqlConfigSpigot ;
6060import com .bencodez .simpleapi .updater .Updater ;
6161import com .bencodez .votingplugin .broadcast .BroadcastHandler ;
62+ import com .bencodez .votingplugin .broadcast .BroadcastSettings ;
6263import com .bencodez .votingplugin .commands .CommandLoader ;
6364import com .bencodez .votingplugin .commands .executers .CommandAdminVote ;
6465import com .bencodez .votingplugin .commands .executers .CommandVote ;
@@ -1109,6 +1110,9 @@ public void onPostLoad() {
11091110 registerCommands ();
11101111 checkVotifier ();
11111112 registerEvents ();
1113+
1114+ loadVoteBroadcast ();
1115+
11121116 loadDirectlyDefined ();
11131117 checkUpdate = new CheckUpdate (this );
11141118 checkUpdate .startUp ();
@@ -1295,11 +1299,6 @@ public String getValue(Reward reward, com.bencodez.advancedcore.api.user.Advance
12951299 });
12961300 }
12971301
1298- if (plugin .getConfigFile ().isFormatAlternateBroadcastEnabled ()) {
1299- broadcastHandler = new BroadcastHandler (plugin , plugin .getConfigFile ().getFormatAlternateBroadcastDelay ());
1300- plugin .debug ("Using alternate broadcast method" );
1301- }
1302-
13031302 plugin .getLogger ().info ("Enabled VotingPlugin " + plugin .getDescription ().getVersion ());
13041303 if (plugin .getDescription ().getVersion ().contains ("SNAPSHOT" )) {
13051304 plugin .getLogger ().info (
@@ -1352,6 +1351,57 @@ public void run() {
13521351
13531352 }
13541353
1354+ private void migrateVoteBroadcast (Config configFile ) {
1355+ ConfigurationSection cfg = configFile .getData ();
1356+ // If new section exists, do nothing
1357+ if (cfg .isConfigurationSection ("VoteBroadcast" )) {
1358+ return ;
1359+ }
1360+
1361+ // Create VoteBroadcast section
1362+ org .bukkit .configuration .ConfigurationSection vb = cfg .createSection ("VoteBroadcast" );
1363+
1364+ // Detect old AlternateBroadcast
1365+ boolean altEnabled = cfg .getBoolean ("Format.AlternateBroadcast.Enabled" , false );
1366+ int altDelay = cfg .getInt ("Format.AlternateBroadcast.Delay" , 30 );
1367+ String altMsg = cfg .getString ("Format.AlternateBroadcast.Broadcast" ,
1368+ "&6[Vote] &a%numberofplayers% voted recently! /vote" );
1369+
1370+ // Old single vote message
1371+ String oldBroadcastMsg = cfg .getString ("Format.BroadcastMsg" ,
1372+ "&6[Vote] &aThanks &e%player% &afor voting on &e%SiteName%" );
1373+
1374+ // Map old -> new
1375+ if (altEnabled ) {
1376+ vb .set ("Type" , "INTERVAL_SUMMARY_GLOBAL" );
1377+ vb .set ("Duration" , altDelay + "m" );
1378+ vb .set ("MaxSitesListed" , 0 );
1379+
1380+ org .bukkit .configuration .ConfigurationSection fmt = vb .createSection ("Format" );
1381+
1382+ // Header uses the old interval broadcast line (make it clearer + include new
1383+ // placeholders)
1384+ fmt .set ("Header" , altMsg .replace ("%numberofplayers%" , "%numberofplayers%" ).replace ("%players%" , "%players%" )
1385+ .replace ("%numberofsites%" , "%numberofsites%" ).replace ("%sites%" , "%sites%" ));
1386+
1387+ // Default: list entries like "Player (N)" (the handler feeds that as item text)
1388+ fmt .set ("ListLine" , "&7 - &6%site%" );
1389+ fmt .set ("BroadcastMsg" , "&6[Vote] &aThanks &e%player% &afor voting on &e%site%&a!" );
1390+
1391+ } else {
1392+ vb .set ("Type" , "EVERY_VOTE" );
1393+ vb .set ("Duration" , "2m" );
1394+ vb .set ("MaxSitesListed" , 0 );
1395+
1396+ org .bukkit .configuration .ConfigurationSection fmt = vb .createSection ("Format" );
1397+ fmt .set ("BroadcastMsg" , oldBroadcastMsg .replace ("%SiteName%" , "%site%" )); // convert placeholder name
1398+ fmt .set ("Header" , "&6[Vote] &aThanks &e%player% &afor voting on &e%sites_count% &asites:" );
1399+ fmt .set ("ListLine" , "&7 - &e%site%" );
1400+ }
1401+ plugin .getLogger ().info ("Migrated vote broadcast settings to new format." );
1402+ configFile .saveData ();
1403+ }
1404+
13551405 /*
13561406 * (non-Javadoc)
13571407 *
@@ -1539,10 +1589,6 @@ private void reloadPlugin(boolean userStorage) {
15391589 }
15401590 checkYMLError ();
15411591
1542- if (broadcastHandler != null ) {
1543- broadcastHandler .schedule (getConfigFile ().getFormatAlternateBroadcastDelay ());
1544- }
1545-
15461592 plugin .loadVoteSites ();
15471593
15481594 getOptions ().setServer (bungeeSettings .getServer ());
@@ -1556,17 +1602,34 @@ private void reloadPlugin(boolean userStorage) {
15561602
15571603 getVoteStreakHandler ().reload ();
15581604
1605+ loadVoteBroadcast ();
1606+
15591607 loadDirectlyDefined ();
15601608
15611609 setUpdate (true );
15621610 }
15631611
1612+ private void loadVoteBroadcast () {
1613+ ConfigurationSection sec = getConfigFile ().getData ().getConfigurationSection ("VoteBroadcast" );
1614+ BroadcastSettings settings = BroadcastSettings .load (sec );
1615+
1616+ if (broadcastHandler == null ) {
1617+ // Backend servers only: create once
1618+ broadcastHandler = new BroadcastHandler (this , settings , ZoneId .systemDefault ());
1619+ } else {
1620+ // Reload-safe: just update settings + reschedule interval if needed
1621+ broadcastHandler .setSettings (settings );
1622+ }
1623+ }
1624+
15641625 private void setupFiles () {
15651626 configFile = new Config (this );
15661627 configFile .setup ();
15671628 configFile .setIgnoreCase (plugin .getConfigFile ().isCaseInsensitiveYMLFiles ());
15681629 configFile .reloadData ();
15691630
1631+ migrateVoteBroadcast (configFile );
1632+
15701633 configVoteSites = new ConfigVoteSites (this );
15711634 configVoteSites .setup ();
15721635
0 commit comments