2019-07-06 04:03:15 +00:00
package io.izzel.taboolib.common.listener ;
2019-07-05 16:17:54 +00:00
2020-03-08 08:31:34 +00:00
import com.google.common.collect.Lists ;
2019-07-05 16:17:54 +00:00
import io.izzel.taboolib.TabooLibAPI ;
2019-07-06 10:50:05 +00:00
import io.izzel.taboolib.module.db.local.Local ;
import io.izzel.taboolib.module.db.local.LocalPlayer ;
2020-03-08 08:31:34 +00:00
import io.izzel.taboolib.module.hologram.Hologram ;
import io.izzel.taboolib.module.hologram.THologram ;
2019-07-05 16:17:54 +00:00
import io.izzel.taboolib.module.inject.TListener ;
2019-07-08 13:23:49 +00:00
import io.izzel.taboolib.module.locale.TLocale ;
2019-07-06 04:03:15 +00:00
import io.izzel.taboolib.module.locale.logger.TLogger ;
2019-07-05 16:17:54 +00:00
import io.izzel.taboolib.module.tellraw.TellrawJson ;
2020-01-23 10:14:06 +00:00
import io.izzel.taboolib.util.Files ;
2019-07-06 10:50:05 +00:00
import io.izzel.taboolib.util.item.Items ;
2020-01-14 14:35:46 +00:00
import io.izzel.taboolib.util.lite.Signs ;
2020-01-23 10:14:06 +00:00
import org.bukkit.Bukkit ;
2020-03-08 08:31:34 +00:00
import org.bukkit.Location ;
2019-07-05 16:17:54 +00:00
import org.bukkit.event.EventHandler ;
2020-01-24 05:56:12 +00:00
import org.bukkit.event.EventPriority ;
2019-07-05 16:17:54 +00:00
import org.bukkit.event.Listener ;
import org.bukkit.event.player.PlayerCommandPreprocessEvent ;
import org.bukkit.event.server.ServerCommandEvent ;
2020-01-23 10:14:06 +00:00
import java.io.File ;
2020-01-14 14:35:46 +00:00
import java.util.Arrays ;
2019-07-05 16:17:54 +00:00
/ * *
* @author sky
* /
@TListener
2020-01-23 10:14:06 +00:00
public class ListenerCommand implements Listener {
2019-07-05 16:17:54 +00:00
2019-07-08 13:23:49 +00:00
@EventHandler
public void cmd ( PlayerCommandPreprocessEvent e ) {
if ( e . getMessage ( ) . equalsIgnoreCase ( "/tabooLib" ) ) {
e . setCancelled ( true ) ;
2020-01-23 10:14:06 +00:00
TLocale . Display . sendTitle ( e . getPlayer ( ) , "§fTabooLib" , "§7TabooLib Enabled." ) ;
2019-07-08 13:23:49 +00:00
}
2019-07-09 10:00:43 +00:00
if ( e . getMessage ( ) . equalsIgnoreCase ( "/tellrawTest" ) & & e . getPlayer ( ) . hasPermission ( "*" ) ) {
2019-07-08 13:23:49 +00:00
e . setCancelled ( true ) ;
TellrawJson . create ( )
. append ( "§8[§3§lTabooLib§8] §7TellrawJson Test: §f[" )
. append ( Items . getName ( e . getPlayer ( ) . getItemInHand ( ) ) ) . hoverItem ( e . getPlayer ( ) . getItemInHand ( ) )
. append ( "§f]" )
. send ( e . getPlayer ( ) ) ;
}
2020-01-23 10:14:06 +00:00
if ( e . getMessage ( ) . equalsIgnoreCase ( "/fakesignTest" ) & & e . getPlayer ( ) . hasPermission ( "*" ) ) {
2019-07-09 10:00:43 +00:00
e . setCancelled ( true ) ;
2020-01-23 10:14:06 +00:00
Signs . fakeSign ( e . getPlayer ( ) , lines - > {
2020-01-14 14:35:46 +00:00
e . getPlayer ( ) . sendMessage ( "§8[§3§lTabooLib§8] §7FakeSign Lines: §f" + Arrays . toString ( lines ) ) ;
} ) ;
}
2020-03-08 08:31:34 +00:00
if ( e . getMessage ( ) . equalsIgnoreCase ( "/hologramTest" ) & & e . getPlayer ( ) . hasPermission ( "*" ) ) {
e . setCancelled ( true ) ;
e . getPlayer ( ) . sendMessage ( "§8[§3§lTabooLib§8] §7Hologram Test." ) ;
Location location = e . getPlayer ( ) . getEyeLocation ( ) . add ( e . getPlayer ( ) . getLocation ( ) . getDirection ( ) ) ;
Hologram hologram = THologram . create ( location , "TabooLib" , e . getPlayer ( ) )
. flash ( Lists . newArrayList (
"§bT§fabooLib" ,
"§bTa§fbooLib" ,
"§bTab§fooLib" ,
"§bTabo§foLib" ,
"§bTaboo§fLib" ,
"§bTabooL§fib" ,
"§bTabooLi§fb" ,
"§bTabooLib" ,
"§bTabooLi§fb" ,
"§bTabooL§fib" ,
"§bTaboo§fLib" ,
"§bTabo§foLib" ,
"§bTab§fooLib" ,
"§bTa§fbooLib" ,
"§bT§fabooLib" ,
"§fTabooLib"
) , 1 ) . deleteOn ( 30 ) ;
}
2019-07-08 13:23:49 +00:00
}
2020-01-24 05:56:12 +00:00
@EventHandler ( priority = EventPriority . LOWEST )
2019-07-05 16:17:54 +00:00
public void cmd ( ServerCommandEvent e ) {
if ( e . getCommand ( ) . equalsIgnoreCase ( "saveFiles" ) ) {
2019-07-06 10:50:05 +00:00
Local . saveFiles ( ) ;
LocalPlayer . saveFiles ( ) ;
2019-07-05 16:17:54 +00:00
TLogger . getGlobalLogger ( ) . info ( "Successfully." ) ;
} else if ( e . getCommand ( ) . equalsIgnoreCase ( "tDebug" ) ) {
if ( TabooLibAPI . isDebug ( ) ) {
2019-07-09 12:00:16 +00:00
TabooLibAPI . debug ( false ) ;
2019-07-05 16:17:54 +00:00
TLogger . getGlobalLogger ( ) . info ( "&cDisabled." ) ;
} else {
2019-07-09 12:00:16 +00:00
TabooLibAPI . debug ( true ) ;
2019-07-05 16:17:54 +00:00
TLogger . getGlobalLogger ( ) . info ( "&aEnabled." ) ;
}
2020-02-02 07:30:29 +00:00
} else if ( e . getCommand ( ) . equalsIgnoreCase ( "libUpdate" ) ) {
2020-01-24 05:56:12 +00:00
e . setCancelled ( true ) ;
2020-02-02 07:30:29 +00:00
e . getSender ( ) . sendMessage ( "§8[§fTabooLib§8] §cWARNING §7| §4Update TabooLib will force to restart your server. Please confirm this action by type §c/libupdateconfirm" ) ;
} else if ( e . getCommand ( ) . equalsIgnoreCase ( "libUpdateConfirm" ) | | e . getCommand ( ) . equalsIgnoreCase ( "libUpdate confirm" ) ) {
2020-01-24 05:56:12 +00:00
e . getSender ( ) . sendMessage ( "§8[§fTabooLib§8] §7Downloading TabooLib file..." ) ;
2020-01-23 10:14:06 +00:00
Files . downloadFile ( "https://skymc.oss-cn-shanghai.aliyuncs.com/plugins/TabooLib.jar" , new File ( "libs/TabooLib.jar" ) ) ;
2020-01-24 05:56:12 +00:00
e . getSender ( ) . sendMessage ( "§8[§fTabooLib§8] §2Download completed, the server will restart in 3 secs" ) ;
2020-01-23 10:14:06 +00:00
try {
Thread . sleep ( 3000L ) ;
} catch ( InterruptedException e1 ) {
e1 . printStackTrace ( ) ;
}
Bukkit . shutdown ( ) ;
2019-07-05 16:17:54 +00:00
}
}
}