2018-11-04 00:33:37 +01:00
package com.songoda.ultimatetimber ;
2018-11-03 21:49:10 +01:00
2018-11-05 05:15:18 +01:00
import com.songoda.ultimatetimber.commands.CommandHandler ;
import com.songoda.ultimatetimber.configurations.DefaultConfig ;
2018-11-07 05:41:40 +01:00
import com.songoda.ultimatetimber.treefall.CustomLoot ;
2018-11-06 21:18:16 +01:00
import com.songoda.ultimatetimber.treefall.TreeFallAnimation ;
2019-01-19 07:35:05 +01:00
import com.songoda.ultimatetimber.treefall.TreeFallListener ;
2018-11-05 23:41:25 +01:00
import com.songoda.ultimatetimber.utils.Methods ;
2018-11-03 21:49:10 +01:00
import org.bukkit.Bukkit ;
2018-12-18 15:12:26 +01:00
import org.bukkit.ChatColor ;
2018-11-05 05:15:18 +01:00
import org.bukkit.World ;
2018-11-05 23:41:25 +01:00
import org.bukkit.command.CommandSender ;
2019-02-06 07:38:37 +01:00
import org.bukkit.entity.Player ;
2018-11-03 21:49:10 +01:00
import org.bukkit.plugin.java.JavaPlugin ;
2018-11-05 05:15:18 +01:00
import java.util.ArrayList ;
2018-11-05 23:41:25 +01:00
import java.util.Collections ;
2018-11-05 05:15:18 +01:00
import java.util.List ;
2019-02-06 07:38:37 +01:00
import java.util.UUID ;
2018-11-05 05:15:18 +01:00
2018-11-03 21:49:10 +01:00
/ *
Note : In this plugin , I have called the act of a tree falling over with pseudo - physics " toppling over " . This is reflected
in the documentation , config files and variable names .
PS : MagmaGuy was here
* /
2018-11-04 00:33:37 +01:00
public class UltimateTimber extends JavaPlugin {
2018-11-05 23:41:25 +01:00
private static CommandSender console = Bukkit . getConsoleSender ( ) ;
private static UltimateTimber INSTANCE ;
2018-12-19 18:58:05 +01:00
private final String prefix = " &8[&6UltimateTimber&8] " ;
2018-11-05 23:41:25 +01:00
private List < World > validWorlds = new ArrayList < > ( ) ;
2019-02-06 07:38:37 +01:00
private List < UUID > isNotChopping = new ArrayList < > ( ) ;
2018-11-03 21:49:10 +01:00
2018-12-19 18:58:05 +01:00
public static UltimateTimber getInstance ( ) {
return INSTANCE ;
}
2018-11-03 21:49:10 +01:00
@Override
public void onEnable ( ) {
2018-12-18 15:12:26 +01:00
if ( ! checkVersion ( ) ) return ;
2018-11-05 23:41:25 +01:00
INSTANCE = this ;
2018-12-18 15:12:26 +01:00
2018-11-05 23:41:25 +01:00
console . sendMessage ( Methods . formatText ( " &a============================= " ) ) ;
2019-02-06 07:38:37 +01:00
console . sendMessage ( Methods . formatText ( " &7 " + this . getDescription ( ) . getName ( ) + " " + this . getDescription ( ) . getVersion ( ) + " by &5Songoda <3&7! " ) ) ;
2018-11-05 23:41:25 +01:00
console . sendMessage ( Methods . formatText ( " &7Action: &aEnabling&7... " ) ) ;
2018-11-03 21:49:10 +01:00
/ *
Register the main event that handles toppling down trees
* /
2019-01-19 07:35:05 +01:00
Bukkit . getServer ( ) . getPluginManager ( ) . registerEvents ( new TreeFallListener ( ) , this ) ;
2018-11-03 21:49:10 +01:00
2018-11-06 21:18:16 +01:00
/ *
Prevent falling blocks from forming new blocks on the floor
* /
Bukkit . getServer ( ) . getPluginManager ( ) . registerEvents ( new TreeFallAnimation ( ) , this ) ;
2018-11-03 21:49:10 +01:00
/ *
2018-11-07 05:41:40 +01:00
Initialize config
2018-11-03 21:49:10 +01:00
* /
DefaultConfig . initialize ( ) ;
2018-11-07 05:41:40 +01:00
/ *
Initialize custom loot
* /
CustomLoot . initializeCustomItems ( ) ;
2018-11-05 05:15:18 +01:00
/ *
Cache valid worlds for later use
* /
for ( World world : Bukkit . getWorlds ( ) )
2018-11-05 23:41:25 +01:00
if ( getConfig ( ) . getBoolean ( DefaultConfig . VALID_WORLDS + world . getName ( ) ) )
2018-11-05 05:15:18 +01:00
validWorlds . add ( world ) ;
2018-11-05 23:41:25 +01:00
this . getCommand ( " ultimatetimber " ) . setExecutor ( new CommandHandler ( this ) ) ;
console . sendMessage ( Methods . formatText ( " &a============================= " ) ) ;
2018-11-03 21:49:10 +01:00
}
@Override
public void onDisable ( ) {
2018-11-05 05:15:18 +01:00
validWorlds . clear ( ) ;
2018-11-05 23:41:25 +01:00
}
public List < World > getValidWorlds ( ) {
return Collections . unmodifiableList ( validWorlds ) ;
2018-11-03 21:49:10 +01:00
}
2018-11-05 23:41:25 +01:00
public String getPrefix ( ) {
return prefix ;
}
2018-12-19 18:58:05 +01:00
2018-12-18 15:12:26 +01:00
private boolean checkVersion ( ) {
int workingVersion = 13 ;
int currentVersion = Integer . parseInt ( Bukkit . getServer ( ) . getClass ( )
. getPackage ( ) . getName ( ) . split ( " \\ . " ) [ 3 ] . split ( " _ " ) [ 1 ] ) ;
if ( currentVersion < workingVersion ) {
Bukkit . getScheduler ( ) . scheduleSyncDelayedTask ( this , ( ) - > {
Bukkit . getConsoleSender ( ) . sendMessage ( " " ) ;
Bukkit . getConsoleSender ( ) . sendMessage ( String . format ( " %sYou installed the 1.%s only version of %s on a 1.%s server. Since you are on the wrong version we disabled the plugin for you. Please install correct version to continue using %s. " , ChatColor . RED , workingVersion , this . getDescription ( ) . getName ( ) , currentVersion , this . getDescription ( ) . getName ( ) ) ) ;
Bukkit . getConsoleSender ( ) . sendMessage ( " " ) ;
} , 20L ) ;
return false ;
}
return true ;
}
2019-02-06 07:38:37 +01:00
public boolean toggleChopping ( Player player ) {
if ( ! isNotChopping . contains ( player . getUniqueId ( ) ) ) {
isNotChopping . add ( player . getUniqueId ( ) ) ;
return false ;
}
isNotChopping . remove ( player . getUniqueId ( ) ) ;
return true ;
}
public boolean isChopping ( Player player ) {
return ! isNotChopping . contains ( player . getUniqueId ( ) ) ;
}
2018-11-03 21:49:10 +01:00
}