2020-02-18 14:31:59 +00:00
package me.zeroeightsix.kami.module.modules.chat ;
2019-11-09 02:57:06 +00:00
import me.zero.alpine.listener.EventHandler ;
import me.zero.alpine.listener.Listener ;
2020-02-18 13:56:28 +00:00
import me.zeroeightsix.kami.command.Command ;
2019-11-09 02:57:06 +00:00
import me.zeroeightsix.kami.event.events.PacketEvent ;
import me.zeroeightsix.kami.module.Module ;
import me.zeroeightsix.kami.setting.Setting ;
import me.zeroeightsix.kami.setting.Settings ;
import net.minecraft.network.play.client.CPacketChatMessage ;
2020-04-12 18:53:31 +00:00
import static me.zeroeightsix.kami.KamiMod.separator ;
2020-04-13 00:00:17 +00:00
import static me.zeroeightsix.kami.util.MessageSendHelper.sendWarningMessage ;
2019-11-12 03:07:50 +00:00
2019-11-09 02:57:06 +00:00
/ * *
* Created by 086 on 8 / 04 / 2018 .
2020-04-18 15:20:04 +00:00
* Updated by dominikaaaa on 12 / 03 / 20
2019-11-09 02:57:06 +00:00
* /
2020-04-17 21:28:21 +00:00
@Module.Info (
name = " CustomChat " ,
category = Module . Category . CHAT ,
description = " Add a custom suffix to the end of your message! " ,
showOnArray = Module . ShowOnArray . OFF
)
2020-02-24 21:15:17 +00:00
public class CustomChat extends Module {
2020-03-12 20:36:58 +00:00
public Setting < TextMode > textMode = register ( Settings . e ( " Message " , TextMode . ON_TOP ) ) ;
2020-02-04 23:04:40 +00:00
private Setting < DecoMode > decoMode = register ( Settings . e ( " Separator " , DecoMode . NONE ) ) ;
2019-11-13 14:09:04 +00:00
private Setting < Boolean > commands = register ( Settings . b ( " Commands " , false ) ) ;
2020-04-16 19:49:01 +00:00
public Setting < String > customText = register ( Settings . stringBuilder ( " Custom Text " ) . withValue ( " unchanged " ) . withConsumer ( ( old , value ) - > { } ) . build ( ) ) ;
private enum DecoMode { SEPARATOR , CLASSIC , NONE }
public enum TextMode { NAME , ON_TOP , WEBSITE , JAPANESE , CUSTOM }
public static String [ ] cmdCheck = new String [ ] { " / " , " , " , " . " , " - " , " ; " , " ? " , " * " , " ^ " , " & " , Command . getCommandPrefix ( ) } ;
2019-11-09 02:57:06 +00:00
2020-04-16 19:49:01 +00:00
private String getText ( TextMode t ) {
switch ( t ) {
2020-04-16 19:49:01 +00:00
case NAME : return " \ u1d0b \ u1d00 \ u1d0d \ u026a \ u0299 \ u029f \ u1d1c \ u1d07 " ;
case ON_TOP : return " \ u1d0b \ u1d00 \ u1d0d \ u026a \ u0299 \ u029f \ u1d1c \ u1d07 \ u1d0f \ u0274 \ u1d1b \ u1d0f \ u1d18 " ;
case WEBSITE : return " \ u0299 \ u029f \ u1d1c \ u1d07 \ u002e \ u0299 \ u1d07 \ u029f \ u029f \ u1d00 \ u002e \ u1d21 \ u1d1b \ u0493 " ;
case JAPANESE : return " \ u4e0a \ u306b \ u30ab \ u30df \ u30d6 \ u30eb \ u30fc " ;
case CUSTOM : return customText . getValue ( ) ;
default : return " " ;
2020-04-16 19:49:01 +00:00
}
}
private String getFull ( DecoMode d ) {
switch ( d ) {
2020-04-16 19:49:01 +00:00
case NONE : return " " + getText ( textMode . getValue ( ) ) ;
case CLASSIC : return " \ u00ab " + getText ( textMode . getValue ( ) ) + " \ u00bb " ;
case SEPARATOR : return " " + separator + " " + getText ( textMode . getValue ( ) ) ;
default : return " " ;
2020-04-16 19:49:01 +00:00
}
}
2020-04-16 19:49:01 +00:00
@EventHandler
public Listener < PacketEvent . Send > listener = new Listener < > ( event - > {
if ( event . getPacket ( ) instanceof CPacketChatMessage ) {
String s = ( ( CPacketChatMessage ) event . getPacket ( ) ) . getMessage ( ) ;
if ( ! commands . getValue ( ) & & isCommand ( s ) ) return ;
s + = getFull ( decoMode . getValue ( ) ) ;
if ( s . length ( ) > = 256 ) s = s . substring ( 0 , 256 ) ;
( ( CPacketChatMessage ) event . getPacket ( ) ) . message = s ;
}
} ) ;
2020-03-12 23:16:42 +00:00
private boolean isCommand ( String s ) {
2020-03-12 20:36:58 +00:00
for ( String value : cmdCheck ) {
if ( s . startsWith ( value ) ) return true ;
}
return false ;
}
2020-04-16 19:49:01 +00:00
private static long startTime = 0 ;
2020-03-10 22:22:23 +00:00
@Override
public void onUpdate ( ) {
if ( startTime = = 0 ) startTime = System . currentTimeMillis ( ) ;
if ( startTime + 5000 < = System . currentTimeMillis ( ) ) { // 5 seconds in milliseconds
if ( textMode . getValue ( ) . equals ( TextMode . CUSTOM ) & & customText . getValue ( ) . equalsIgnoreCase ( " unchanged " ) & & mc . player ! = null ) {
2020-04-13 00:00:17 +00:00
sendWarningMessage ( getChatName ( ) + " Warning: In order to use the custom " + getName ( ) + " , please run the &7 " + Command . getCommandPrefix ( ) + " customchat&r command to change it " ) ;
2020-03-10 22:22:23 +00:00
}
startTime = System . currentTimeMillis ( ) ;
}
}
2019-11-09 02:57:06 +00:00
}