Retail like builder messages.

Adapted from: L2jUnity free files.
This commit is contained in:
MobiusDev
2018-05-03 22:30:45 +00:00
parent cdcd780e7a
commit 8e76b4772d
188 changed files with 5621 additions and 1645 deletions

View File

@ -116,6 +116,12 @@ public final class Config
public static final String EOL = System.lineSeparator();
public static boolean EVERYBODY_HAS_ADMIN_RIGHTS;
public static int MASTERACCESS_LEVEL;
public static int USERACCESS_LEVEL;
public static boolean MASTERACCESS_NAME_COLOR_ENABLED;
public static boolean MASTERACCESS_TITLE_COLOR_ENABLED;
public static int MASTERACCESS_NAME_COLOR;
public static int MASTERACCESS_TITLE_COLOR;
public static boolean SHOW_GM_LOGIN;
public static boolean GM_STARTUP_INVISIBLE;
public static boolean GM_SPECIAL_EFFECT;
@ -123,14 +129,10 @@ public final class Config
public static boolean GM_STARTUP_AUTO_LIST;
public static String GM_ADMIN_MENU_STYLE;
public static boolean GM_HERO_AURA;
public static boolean GM_STARTUP_BUILDER_HIDE;
public static boolean GM_STARTUP_INVULNERABLE;
public static boolean GM_ANNOUNCER_NAME;
public static int MASTERACCESS_LEVEL;
public static int USERACCESS_LEVEL;
public static boolean MASTERACCESS_NAME_COLOR_ENABLED;
public static boolean MASTERACCESS_TITLE_COLOR_ENABLED;
public static int MASTERACCESS_NAME_COLOR;
public static int MASTERACCESS_TITLE_COLOR;
public static boolean USE_SUPER_HASTE_AS_GM_SPEED;
public static boolean CHECK_KNOWN;
public static String DEFAULT_GLOBAL_CHAT;
@ -1214,21 +1216,23 @@ public final class Config
is.close();
EVERYBODY_HAS_ADMIN_RIGHTS = Boolean.parseBoolean(AccessSettings.getProperty("EverybodyHasAdminRights", "false"));
GM_STARTUP_AUTO_LIST = Boolean.parseBoolean(AccessSettings.getProperty("GMStartupAutoList", "true"));
GM_ADMIN_MENU_STYLE = AccessSettings.getProperty("GMAdminMenuStyle", "modern");
GM_HERO_AURA = Boolean.parseBoolean(AccessSettings.getProperty("GMHeroAura", "false"));
GM_STARTUP_INVULNERABLE = Boolean.parseBoolean(AccessSettings.getProperty("GMStartupInvulnerable", "true"));
GM_ANNOUNCER_NAME = Boolean.parseBoolean(AccessSettings.getProperty("AnnounceGmName", "false"));
SHOW_GM_LOGIN = Boolean.parseBoolean(AccessSettings.getProperty("ShowGMLogin", "false"));
GM_STARTUP_INVISIBLE = Boolean.parseBoolean(AccessSettings.getProperty("GMStartupInvisible", "true"));
GM_SPECIAL_EFFECT = Boolean.parseBoolean(AccessSettings.getProperty("GmLoginSpecialEffect", "false"));
GM_STARTUP_SILENCE = Boolean.parseBoolean(AccessSettings.getProperty("GMStartupSilence", "true"));
MASTERACCESS_LEVEL = Integer.parseInt(AccessSettings.getProperty("MasterAccessLevel", "1"));
MASTERACCESS_NAME_COLOR_ENABLED = Boolean.parseBoolean(AccessSettings.getProperty("MasterNameColorEnabled", "false"));
MASTERACCESS_TITLE_COLOR_ENABLED = Boolean.parseBoolean(AccessSettings.getProperty("MasterTitleColorEnabled", "false"));
MASTERACCESS_NAME_COLOR = Integer.decode("0x" + AccessSettings.getProperty("MasterNameColor", "00FF00"));
MASTERACCESS_TITLE_COLOR = Integer.decode("0x" + AccessSettings.getProperty("MasterTitleColor", "00FF00"));
USERACCESS_LEVEL = Integer.parseInt(AccessSettings.getProperty("UserAccessLevel", "0"));
GM_STARTUP_AUTO_LIST = Boolean.parseBoolean(AccessSettings.getProperty("GMStartupAutoList", "true"));
GM_ADMIN_MENU_STYLE = AccessSettings.getProperty("GMAdminMenuStyle", "modern");
GM_HERO_AURA = Boolean.parseBoolean(AccessSettings.getProperty("GMHeroAura", "false"));
GM_STARTUP_BUILDER_HIDE = Boolean.parseBoolean(AccessSettings.getProperty("GMStartupBuilderHide", "true"));
GM_STARTUP_INVULNERABLE = Boolean.parseBoolean(AccessSettings.getProperty("GMStartupInvulnerable", "true"));
GM_ANNOUNCER_NAME = Boolean.parseBoolean(AccessSettings.getProperty("AnnounceGmName", "false"));
SHOW_GM_LOGIN = Boolean.parseBoolean(AccessSettings.getProperty("ShowGMLogin", "false"));
GM_STARTUP_INVISIBLE = Boolean.parseBoolean(AccessSettings.getProperty("GMStartupInvisible", "true"));
GM_SPECIAL_EFFECT = Boolean.parseBoolean(AccessSettings.getProperty("GmLoginSpecialEffect", "false"));
GM_STARTUP_SILENCE = Boolean.parseBoolean(AccessSettings.getProperty("GMStartupSilence", "true"));
USE_SUPER_HASTE_AS_GM_SPEED = Boolean.parseBoolean(AccessSettings.getProperty("UseSuperHasteAsGMSpeed", "false"));
}
catch (Exception e)
{

View File

@ -49,8 +49,10 @@ import com.l2jmobius.gameserver.handler.admincommandhandlers.AdminFortSiege;
import com.l2jmobius.gameserver.handler.admincommandhandlers.AdminGeodata;
import com.l2jmobius.gameserver.handler.admincommandhandlers.AdminGm;
import com.l2jmobius.gameserver.handler.admincommandhandlers.AdminGmChat;
import com.l2jmobius.gameserver.handler.admincommandhandlers.AdminGmSpeed;
import com.l2jmobius.gameserver.handler.admincommandhandlers.AdminHeal;
import com.l2jmobius.gameserver.handler.admincommandhandlers.AdminHelpPage;
import com.l2jmobius.gameserver.handler.admincommandhandlers.AdminHide;
import com.l2jmobius.gameserver.handler.admincommandhandlers.AdminInvul;
import com.l2jmobius.gameserver.handler.admincommandhandlers.AdminKick;
import com.l2jmobius.gameserver.handler.admincommandhandlers.AdminKill;
@ -79,6 +81,7 @@ import com.l2jmobius.gameserver.handler.admincommandhandlers.AdminShutdown;
import com.l2jmobius.gameserver.handler.admincommandhandlers.AdminSiege;
import com.l2jmobius.gameserver.handler.admincommandhandlers.AdminSkill;
import com.l2jmobius.gameserver.handler.admincommandhandlers.AdminSpawn;
import com.l2jmobius.gameserver.handler.admincommandhandlers.AdminSuperHaste;
import com.l2jmobius.gameserver.handler.admincommandhandlers.AdminTarget;
import com.l2jmobius.gameserver.handler.admincommandhandlers.AdminTeleport;
import com.l2jmobius.gameserver.handler.admincommandhandlers.AdminTest;
@ -133,6 +136,9 @@ public class AdminCommandHandler
registerAdminCommandHandler(new AdminExpSp());
registerAdminCommandHandler(new AdminEventEngine());
registerAdminCommandHandler(new AdminGmChat());
registerAdminCommandHandler(new AdminGmSpeed());
registerAdminCommandHandler(new AdminHide());
registerAdminCommandHandler(new AdminSuperHaste());
registerAdminCommandHandler(new AdminEditChar());
registerAdminCommandHandler(new AdminGm());
registerAdminCommandHandler(new AdminTeleport());

View File

@ -18,10 +18,8 @@ package com.l2jmobius.gameserver.handler.admincommandhandlers;
import java.util.StringTokenizer;
import com.l2jmobius.gameserver.datatables.SkillTable;
import com.l2jmobius.gameserver.handler.IAdminCommandHandler;
import com.l2jmobius.gameserver.model.L2Object;
import com.l2jmobius.gameserver.model.L2Skill;
import com.l2jmobius.gameserver.model.L2World;
import com.l2jmobius.gameserver.model.actor.L2Character;
import com.l2jmobius.gameserver.model.actor.L2Summon;
@ -74,9 +72,6 @@ public class AdminEffects implements IAdminCommandHandler
"admin_earthquake_menu",
"admin_bighead",
"admin_shrinkhead",
"admin_gmspeed",
"admin_gmspeed_menu",
"admin_gmspeed_menu_main",
"admin_unpara_all",
"admin_para_all",
"admin_unpara",
@ -351,35 +346,6 @@ public class AdminEffects implements IAdminCommandHandler
}
}
else if (command.startsWith("admin_gmspeed"))
{
try
{
final int val = Integer.parseInt(st.nextToken());
final boolean sendMessage = activeChar.getFirstEffect(7029) != null;
activeChar.stopSkillEffects(7029);
if ((val == 0) && sendMessage)
{
activeChar.sendPacket(new SystemMessage(SystemMessageId.EFFECT_S1_DISAPPEARED).addSkillName(7029));
}
else if ((val >= 1) && (val <= 4))
{
final L2Skill gmSpeedSkill = SkillTable.getInstance().getInfo(7029, val);
activeChar.doCast(gmSpeedSkill);
}
}
catch (Exception e)
{
activeChar.sendMessage("Use //gmspeed value (0=off...4=max).");
}
finally
{
activeChar.updateEffectIcons();
}
}
else if (command.startsWith("admin_polyself"))
{
try

View File

@ -0,0 +1,133 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jmobius.gameserver.handler.admincommandhandlers;
import java.util.StringTokenizer;
import com.l2jmobius.Config;
import com.l2jmobius.gameserver.datatables.SkillTable;
import com.l2jmobius.gameserver.handler.IAdminCommandHandler;
import com.l2jmobius.gameserver.model.L2Object;
import com.l2jmobius.gameserver.model.L2Skill;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.network.SystemMessageId;
import com.l2jmobius.gameserver.network.serverpackets.SystemMessage;
import com.l2jmobius.gameserver.util.BuilderUtil;
import com.l2jmobius.gameserver.util.Util;
/**
* A retail-like implementation of //gmspeed builder command.
* @author lord_rex
*/
public final class AdminGmSpeed implements IAdminCommandHandler
{
private static final String[] ADMIN_COMMANDS =
{
"admin_gmspeed",
};
private static final int SUPER_HASTE_ID = 7029;
@Override
public boolean useAdminCommand(String command, L2PcInstance player)
{
final StringTokenizer st = new StringTokenizer(command);
final String cmd = st.nextToken();
if (cmd.equals("admin_gmspeed"))
{
if (!st.hasMoreTokens())
{
BuilderUtil.sendSysMessage(player, "//gmspeed [0...10]");
return false;
}
final String token = st.nextToken();
// Rollback feature for old custom way, in order to make everyone happy.
if (Config.USE_SUPER_HASTE_AS_GM_SPEED)
{
try
{
final int val = Integer.parseInt(token);
final boolean sendMessage = player.getFirstEffect(SUPER_HASTE_ID) != null;
player.stopSkillEffects(SUPER_HASTE_ID);
if ((val == 0) && sendMessage)
{
player.sendPacket(new SystemMessage(SystemMessageId.EFFECT_S1_DISAPPEARED).addSkillName(SUPER_HASTE_ID));
}
else if ((val >= 1) && (val <= 4))
{
final L2Skill gmSpeedSkill = SkillTable.getInstance().getInfo(SUPER_HASTE_ID, val);
player.doCast(gmSpeedSkill);
}
}
catch (Exception e)
{
player.sendMessage("Use //gmspeed value (0=off...4=max).");
}
finally
{
player.updateEffectIcons();
}
return true;
}
if (!Util.isFloat(token))
{
BuilderUtil.sendSysMessage(player, "//gmspeed [0...10]");
return false;
}
float runSpeedBoost = Float.parseFloat(token);
if ((runSpeedBoost < 0) || (runSpeedBoost > 10))
{
// Custom limit according to SDW's request - real retail limit is unknown.
BuilderUtil.sendSysMessage(player, "//gmspeed [0...10]");
return false;
}
final L2PcInstance targetCharacter;
final L2Object target = player.getTarget();
if ((target != null) && target.isPlayer())
{
targetCharacter = (L2PcInstance) target;
}
else
{
// If there is no target, let's use the command executer.
targetCharacter = player;
}
targetCharacter.getStat().setGmSpeedMultiplier(runSpeedBoost > 1 ? runSpeedBoost : 1);
targetCharacter.broadcastUserInfo();
if (runSpeedBoost < 1)
{
runSpeedBoost = 1;
}
BuilderUtil.sendSysMessage(player, "[" + targetCharacter.getName() + "] speed is [" + (runSpeedBoost * 100) + "0]% fast.");
}
return true;
}
@Override
public String[] getAdminCommandList()
{
return ADMIN_COMMANDS;
}
}

View File

@ -0,0 +1,87 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jmobius.gameserver.handler.admincommandhandlers;
import java.util.StringTokenizer;
import com.l2jmobius.gameserver.handler.IAdminCommandHandler;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.util.BuilderUtil;
/**
* @author lord_rex
*/
public final class AdminHide implements IAdminCommandHandler
{
private static final String[] ADMIN_COMMANDS =
{
"admin_hide"
};
@Override
public boolean useAdminCommand(String command, L2PcInstance player)
{
final StringTokenizer st = new StringTokenizer(command);
st.nextToken();
try
{
final String param = st.nextToken();
switch (param)
{
case "on":
{
if (!BuilderUtil.setHiding(player, true))
{
BuilderUtil.sendSysMessage(player, "Currently, you cannot be seen.");
return true;
}
BuilderUtil.sendSysMessage(player, "Now, you cannot be seen.");
return true;
}
case "off":
{
if (!BuilderUtil.setHiding(player, false))
{
BuilderUtil.sendSysMessage(player, "Currently, you can be seen.");
return true;
}
BuilderUtil.sendSysMessage(player, "Now, you can be seen.");
return true;
}
default:
{
BuilderUtil.sendSysMessage(player, "//hide [on|off]");
return true;
}
}
}
catch (final Exception e)
{
BuilderUtil.sendSysMessage(player, "//hide [on|off]");
return true;
}
}
@Override
public String[] getAdminCommandList()
{
return ADMIN_COMMANDS;
}
}

View File

@ -0,0 +1,97 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jmobius.gameserver.handler.admincommandhandlers;
import java.util.StringTokenizer;
import com.l2jmobius.gameserver.datatables.SkillTable;
import com.l2jmobius.gameserver.handler.IAdminCommandHandler;
import com.l2jmobius.gameserver.model.L2Skill;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.network.SystemMessageId;
import com.l2jmobius.gameserver.network.serverpackets.SystemMessage;
/**
* The classical custom L2J implementation of the old //gmspeed GM command.
* @author lord_rex (No, it wasn't me at all. Eclipse added my name there.)
*/
public final class AdminSuperHaste implements IAdminCommandHandler
{
public static final String[] ADMIN_COMMANDS =
{
"admin_superhaste",
"admin_superhaste_menu",
"admin_speed",
"admin_speed_menu",
};
private static final int SUPER_HASTE_ID = 7029;
@Override
public boolean useAdminCommand(String command, L2PcInstance player)
{
final StringTokenizer st = new StringTokenizer(command);
final String cmd = st.nextToken();
switch (cmd)
{
case "admin_superhaste":
case "admin_speed":
{
try
{
final int val = Integer.parseInt(st.nextToken());
final boolean sendMessage = player.getFirstEffect(SUPER_HASTE_ID) != null;
player.stopSkillEffects(SUPER_HASTE_ID);
if ((val == 0) && sendMessage)
{
player.sendPacket(new SystemMessage(SystemMessageId.EFFECT_S1_DISAPPEARED).addSkillName(SUPER_HASTE_ID));
}
else if ((val >= 1) && (val <= 4))
{
final L2Skill gmSpeedSkill = SkillTable.getInstance().getInfo(SUPER_HASTE_ID, val);
player.doCast(gmSpeedSkill);
}
}
catch (Exception e)
{
player.sendMessage("Use //gmspeed value (0=off...4=max).");
}
finally
{
player.updateEffectIcons();
}
break;
}
case "admin_superhaste_menu":
case "admin_speed_menu":
{
AdminHelpPage.showHelpPage(player, "gm_menu.htm");
break;
}
}
return true;
}
@Override
public String[] getAdminCommandList()
{
return ADMIN_COMMANDS;
}
}

View File

@ -15018,19 +15018,23 @@ public final class L2PcInstance extends L2Playable
// jail task
updatePunishState();
if (_isInvul)
if (isGM() && !Config.GM_STARTUP_BUILDER_HIDE)
{
sendMessage("Entering world in Invulnerable mode.");
}
if (getAppearance().getInvisible())
{
sendMessage("Entering world in Invisible mode.");
}
if (isInRefusalMode())
{
sendMessage("Entering world in Message Refusal mode.");
// Bleah, see L2J custom below.
if (_isInvul)
{
sendMessage("Entering world in Invulnerable mode.");
}
if (getAppearance().getInvisible())
{
sendMessage("Entering world in Invisible mode.");
}
if (isInRefusalMode())
{
sendMessage("Entering world in Message Refusal mode.");
}
}
revalidateZone(true);

View File

@ -47,6 +47,9 @@ public class CharStat
/** The _level. */
private int _level = 1;
/** Speed multiplier set by admin gmspeed command */
private float _gmSpeedMultiplier = 1;
// =========================================================
// Constructor
/**
@ -597,7 +600,12 @@ public class CharStat
return 1;
}
return (getRunSpeed() * 1f) / _activeChar.getTemplate().baseRunSpd;
return getRunSpeed() / _activeChar.getTemplate().baseRunSpd;
}
public void setGmSpeedMultiplier(float multipier)
{
_gmSpeedMultiplier = multipier;
}
/**
@ -920,13 +928,13 @@ public class CharStat
if (_activeChar.isFlying())
{
val += Config.WYVERN_SPEED;
return val;
return (int) (val * _gmSpeedMultiplier);
}
if (_activeChar.isRiding())
{
val += Config.STRIDER_SPEED;
return val;
return (int) (val * _gmSpeedMultiplier);
}
val /= _activeChar.getArmourExpertisePenalty();
@ -936,7 +944,7 @@ public class CharStat
val = Config.MAX_RUN_SPEED;
}
return val;
return (int) (val * _gmSpeedMultiplier);
}
/**

View File

@ -96,6 +96,7 @@ import com.l2jmobius.gameserver.network.serverpackets.SignsSky;
import com.l2jmobius.gameserver.network.serverpackets.SystemMessage;
import com.l2jmobius.gameserver.network.serverpackets.UserInfo;
import com.l2jmobius.gameserver.thread.TaskPriority;
import com.l2jmobius.gameserver.util.BuilderUtil;
import com.l2jmobius.gameserver.util.Util;
/**
@ -599,6 +600,47 @@ public class EnterWorld extends L2GameClientPacket
{
if (activeChar.isGM())
{
gmStartupProcess:
{
if (Config.GM_STARTUP_BUILDER_HIDE && AdminCommandAccessRights.getInstance().hasAccess("admin_hide", activeChar.getAccessLevel()))
{
activeChar.setInRefusalMode(true);
activeChar.setIsInvul(true);
activeChar.getAppearance().setInvisible();
BuilderUtil.sendSysMessage(activeChar, "hide is default for builder.");
BuilderUtil.sendSysMessage(activeChar, "FriendAddOff is default for builder.");
BuilderUtil.sendSysMessage(activeChar, "whisperoff is default for builder.");
// It isn't recommend to use the below custom L2J GMStartup functions together with retail-like GMStartupBuilderHide, so breaking the process at that stage.
break gmStartupProcess;
}
if (Config.GM_STARTUP_INVULNERABLE && AdminCommandAccessRights.getInstance().hasAccess("admin_invul", activeChar.getAccessLevel()))
{
activeChar.setIsInvul(true);
}
if (Config.GM_STARTUP_INVISIBLE && AdminCommandAccessRights.getInstance().hasAccess("admin_invisible", activeChar.getAccessLevel()))
{
activeChar.getAppearance().setInvisible();
}
if (Config.GM_STARTUP_SILENCE && AdminCommandAccessRights.getInstance().hasAccess("admin_silence", activeChar.getAccessLevel()))
{
activeChar.setInRefusalMode(true);
}
if (Config.GM_STARTUP_AUTO_LIST && AdminCommandAccessRights.getInstance().hasAccess("admin_gmliston", activeChar.getAccessLevel()))
{
GmListTable.getInstance().addGm(activeChar, false);
}
else
{
GmListTable.getInstance().addGm(activeChar, true);
}
}
if (Config.GM_SPECIAL_EFFECT)
{
activeChar.broadcastPacket(new Earthquake(activeChar.getX(), activeChar.getY(), activeChar.getZ(), 50, 4));
@ -609,30 +651,6 @@ public class EnterWorld extends L2GameClientPacket
Announcements.getInstance().announceToAll("GM " + activeChar.getName() + " has logged on.");
}
if (Config.GM_STARTUP_INVULNERABLE && AdminCommandAccessRights.getInstance().hasAccess("admin_invul", activeChar.getAccessLevel()))
{
activeChar.setIsInvul(true);
}
if (Config.GM_STARTUP_INVISIBLE && AdminCommandAccessRights.getInstance().hasAccess("admin_invisible", activeChar.getAccessLevel()))
{
activeChar.getAppearance().setInvisible();
}
if (Config.GM_STARTUP_SILENCE && AdminCommandAccessRights.getInstance().hasAccess("admin_silence", activeChar.getAccessLevel()))
{
activeChar.setInRefusalMode(true);
}
if (Config.GM_STARTUP_AUTO_LIST && AdminCommandAccessRights.getInstance().hasAccess("admin_gmliston", activeChar.getAccessLevel()))
{
GmListTable.getInstance().addGm(activeChar, false);
}
else
{
GmListTable.getInstance().addGm(activeChar, true);
}
if (Config.MASTERACCESS_NAME_COLOR_ENABLED)
{
activeChar.getAppearance().setNameColor(Config.MASTERACCESS_NAME_COLOR);

View File

@ -0,0 +1,67 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jmobius.gameserver.util;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.network.clientpackets.Say2;
import com.l2jmobius.gameserver.network.serverpackets.CreatureSay;
/**
* @author lord_rex
*/
public final class BuilderUtil
{
private BuilderUtil()
{
// utility class
}
/**
* Sends builder system message to the player.
* @param player
* @param message
*/
public static void sendSysMessage(L2PcInstance player, String message)
{
player.sendPacket(new CreatureSay(-1, Say2.ALL, "SYS", message));
}
/**
* Changes player's hiding state.
* @param player
* @param hide
* @return {@code true} if hide state was changed, otherwise {@code false}
*/
public static boolean setHiding(L2PcInstance player, boolean hide)
{
player.setInRefusalMode(hide);
player.setIsInvul(hide);
if (hide)
{
player.getAppearance().setInvisible();
player.decayMe();
player.broadcastUserInfo();
player.spawnMe();
}
else
{
player.getAppearance().setVisible();
player.broadcastUserInfo();
}
return true;
}
}

View File

@ -0,0 +1,136 @@
/*
* Copyright (c) 1999 CERN - European Organization for Nuclear Research.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear in
* supporting documentation. CERN makes no representations about the
* suitability of this software for any purpose. It is provided "as is"
* without expressed or implied warranty.
*/
package com.l2jmobius.gameserver.util;
import static java.util.concurrent.TimeUnit.DAYS;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.NANOSECONDS;
import java.io.IOException;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
/**
* Allows to present time intervals in a standardized, user friendly manner.
* @author _dev_
*/
public class TimeAmountInterpreter
{
private static final TimeUnit[] UNIT_CACHE = TimeUnit.values();
private TimeAmountInterpreter()
{
// utility class
}
/**
* Calls {@link #consolidate(long, TimeUnit)} with {@link TimeUnit#NANOSECONDS}.
* @param timeAmountInNanos amount of time in nanoseconds
* @return an user-friendly description of the given time amount
*/
public static String consolidateNanos(long timeAmountInNanos)
{
return consolidate(timeAmountInNanos, NANOSECONDS);
}
/**
* Calls {@link #consolidate(long, TimeUnit)} with {@link TimeUnit#MILLISECONDS}.
* @param timeAmountInMillis amount of time in milliseconds
* @return an user-friendly description of the given time amount
*/
public static String consolidateMillis(long timeAmountInMillis)
{
return consolidate(timeAmountInMillis, MILLISECONDS);
}
/**
* Constructs an user-friendly description of the given amount of time, specifying the number of days (if any), hours (if any), minutes (if any), seconds (if any) and milliseconds (if any). Otherwise, returns the string value {@code 0}.
* @param timeAmount amount of time to be written
* @param timeUnit unit of the given amount
* @return an user-friendly description of the given time amount
*/
public static String consolidate(long timeAmount, TimeUnit timeUnit)
{
return consolidate(timeAmount, timeUnit, timeUnit, DAYS, "0 " + timeUnit.name().toLowerCase(Locale.ENGLISH));
}
/**
* Constructs an user-friendly description of the given amount of time.
* @param timeAmount amount of time to be written
* @param timeUnit unit of the given amount
* @param minConsolidationUnit smallest unit to be included within the description
* @param maxConsolidationUnit largest unit to be included within the description
* @param noTimeUsedIndicator text to be written if the amount is not positive
* @return an user-friendly description of the given time amount
*/
public static String consolidate(long timeAmount, TimeUnit timeUnit, TimeUnit minConsolidationUnit, TimeUnit maxConsolidationUnit, String noTimeUsedIndicator)
{
return appendConsolidated(new StringBuilder(), timeAmount, timeUnit, minConsolidationUnit, maxConsolidationUnit, noTimeUsedIndicator).toString();
}
/**
* Appends an user-friendly description of the given amount of time to the specified text builder.<BR>
* <BR>
* Please keep in mind, that this method is primarily designed to be used with heap text builders. Therefore, if the given text builder throws an {@link IOException}, this exception will be wrapped in a {@link RuntimeException} and returned to the caller as an unchecked exception.
* @param <T>
* @param textBuilder a character sequence builder
* @param timeAmount amount of time to be written
* @param timeUnit unit of the given amount
* @param minConsolidationUnit smallest unit to be included within the description
* @param maxConsolidationUnit largest unit to be included within the description
* @param noTimeUsedIndicator text to be written if the amount is not positive
* @return {@code textBuilder}
* @throws RuntimeException if {@code textBuilder} throws an {@link IOException}
*/
@SuppressWarnings("unchecked")
public static <T extends Appendable & CharSequence> T appendConsolidated(T textBuilder, long timeAmount, TimeUnit timeUnit, TimeUnit minConsolidationUnit, TimeUnit maxConsolidationUnit, String noTimeUsedIndicator) throws RuntimeException
{
try
{
if (timeAmount < 1)
{
return (T) textBuilder.append(noTimeUsedIndicator);
}
final int len = textBuilder.length();
for (int i = maxConsolidationUnit.ordinal(); i >= minConsolidationUnit.ordinal(); --i)
{
final TimeUnit activeUnit = UNIT_CACHE[i];
final long num = activeUnit.convert(timeAmount, timeUnit);
if (num == 0)
{
continue;
}
if (textBuilder.length() > len)
{
textBuilder.append(", ");
}
textBuilder.append(String.valueOf(num)).append(' ');
final String unit = activeUnit.name().toLowerCase(Locale.ENGLISH);
textBuilder.append(unit, 0, num == 1 ? unit.length() - 1 : unit.length());
timeAmount -= timeUnit.convert(num, activeUnit);
}
if (textBuilder.length() == len)
{
return (T) textBuilder.append(noTimeUsedIndicator).append(' ').append(minConsolidationUnit.name().toLowerCase(Locale.ENGLISH));
}
}
catch (IOException e)
{
throw new RuntimeException(e);
}
return textBuilder;
}
}

View File

@ -436,6 +436,69 @@ public final class Util
return true;
}
/**
* @param text - the text to check
* @return {@code true} if {@code text} is integer, {@code false} otherwise
*/
public static boolean isInteger(String text)
{
if ((text == null) || text.isEmpty())
{
return false;
}
try
{
Integer.parseInt(text);
return true;
}
catch (Exception e)
{
return false;
}
}
/**
* @param text - the text to check
* @return {@code true} if {@code text} is float, {@code false} otherwise
*/
public static boolean isFloat(String text)
{
if ((text == null) || text.isEmpty())
{
return false;
}
try
{
Float.parseFloat(text);
return true;
}
catch (Exception e)
{
return false;
}
}
/**
* @param text - the text to check
* @return {@code true} if {@code text} is double, {@code false} otherwise
*/
public static boolean isDouble(String text)
{
if ((text == null) || text.isEmpty())
{
return false;
}
try
{
Double.parseDouble(text);
return true;
}
catch (Exception e)
{
return false;
}
}
/**
* Replaces most invalid characters for the given string with an underscore.
* @param str the string that may contain invalid characters