use of com.github.sirblobman.api.language.Replacer in project CombatLogX by SirBlobman.
the class CombatManager method sendTagMessage.
private void sendTagMessage(Player player, LivingEntity enemy, TagType tagType, TagReason tagReason) {
if (tagType == TagType.DAMAGE) {
return;
}
String enemyName = getEntityName(player, enemy);
String enemyType = getEntityType(player, enemy);
String tagReasonString = tagReason.name().toLowerCase(Locale.US);
String tagTypeString = tagType.name().toLowerCase(Locale.US);
Replacer replacer = message -> message.replace("{enemy}", enemyName).replace("{mob_type}", enemyType);
String languagePath = ("tagged." + tagReasonString + "." + tagTypeString);
this.plugin.sendMessageWithPrefix(player, languagePath, replacer, true);
}
use of com.github.sirblobman.api.language.Replacer in project CombatLogX by SirBlobman.
the class CommandCombatTimer method checkOther.
private void checkOther(Player player, Player target) {
ICombatLogX plugin = getCombatLogX();
ICombatManager combatManager = plugin.getCombatManager();
LanguageManager languageManager = getLanguageManager();
if (combatManager.isInCombat(target)) {
double timeLeftMillis = combatManager.getTimerLeftMillis(target);
double timeLeftSeconds = (timeLeftMillis / 1_000.0D);
String decimalFormatString = languageManager.getMessage(player, "decimal-format", null, false);
DecimalFormat decimalFormat = new DecimalFormat(decimalFormatString);
String timeLeftString = decimalFormat.format(timeLeftSeconds);
Replacer replacer = message -> message.replace("{time_left}", timeLeftString);
sendMessageWithPrefix(player, "command.combat-timer.time-left-other", replacer, true);
return;
}
sendMessageWithPrefix(player, "error.target-not-in-combat", null, true);
}
use of com.github.sirblobman.api.language.Replacer in project CombatLogX by SirBlobman.
the class ListenerLootProtection method onEntityItemPickup.
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onEntityItemPickup(EntityPickupItemEvent e) {
Item itemEntity = e.getItem();
if (!contains(itemEntity)) {
return;
}
Entity entity = e.getEntity();
if (!(entity instanceof Player)) {
e.setCancelled(true);
return;
}
Player player = (Player) entity;
UUID itemEntityId = itemEntity.getUniqueId();
ProtectedItem protectedItem = this.protectedItemMap.get(itemEntityId);
UUID playerId = player.getUniqueId();
QueryPickupEvent queryPickupEvent = new QueryPickupEvent(player, protectedItem);
Bukkit.getPluginManager().callEvent(queryPickupEvent);
if (!protectedItem.getOwnerUUID().equals(playerId) && !queryPickupEvent.isCancelled()) {
e.setCancelled(true);
if (!this.messageCooldownSet.contains(playerId)) {
long expireMillisLeft = this.protectedItemMap.getExpectedExpiration(itemEntityId);
long expireSecondsLeft = TimeUnit.MILLISECONDS.toSeconds(expireMillisLeft);
String timeLeft = Long.toString(expireSecondsLeft);
Replacer replacer = message -> message.replace("{time}", timeLeft);
sendMessageWithPrefix(player, "expansion.loot-protection.protected", replacer, true);
this.messageCooldownSet.add(playerId);
}
}
}
use of com.github.sirblobman.api.language.Replacer in project CombatLogX by SirBlobman.
the class ListenerLootProtection method onDeath.
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onDeath(EntityDeathEvent e) {
LivingEntity entity = e.getEntity();
ICombatLogX combatLogX = getCombatLogX();
IDeathListener deathListener = combatLogX.getDeathListener();
YamlConfiguration configuration = getExpansionConfigurationManager().get("config.yml");
if (entity instanceof Player) {
Player player = (Player) entity;
if (configuration.getBoolean("only-protect-after-log", false) && !deathListener.contains(player)) {
return;
}
}
UUID entityId = entity.getUniqueId();
UUID enemyId = this.enemyMap.get(entityId);
if (!checkVoidKill(e) && entity instanceof Player) {
Player player = (Player) entity;
PlayerDataManager playerDataManager = getPlayerDataManager();
YamlConfiguration playerData = playerDataManager.get(player);
String enemyIdString = playerData.getString("loot-protection-enemy");
if (enemyIdString != null) {
playerData.set("loot-protection-enemy", null);
playerDataManager.save(player);
enemyId = UUID.fromString(enemyIdString);
}
}
if (enemyId == null) {
return;
}
Entity enemy = Bukkit.getEntity(enemyId);
if (enemy == null) {
return;
}
enemyId = enemy.getUniqueId();
WorldXYZ entityLocation = WorldXYZ.from(entity);
ConcurrentLinkedQueue<ProtectedItem> protectedItemQueue = new ConcurrentLinkedQueue<>();
List<ItemStack> dropList = e.getDrops();
for (ItemStack drop : dropList) {
ProtectedItem protectedItem = new ProtectedItem(entityLocation, drop);
protectedItem.setOwnerUUID(enemyId);
protectedItemQueue.add(protectedItem);
}
this.pendingProtectionMap.put(entityLocation, protectedItemQueue);
String entityName = (entity.getCustomName() == null ? entity.getName() : entity.getCustomName());
long timeLeftMillis = this.protectedItemMap.getExpiration();
long timeLeftSeconds = TimeUnit.MILLISECONDS.toSeconds(timeLeftMillis);
String timeLeft = Long.toString(timeLeftSeconds);
Replacer replacer = message -> message.replace("{time}", timeLeft).replace("{enemy}", entityName);
sendMessageWithPrefix(enemy, "expansion.loot-protection.enemy-died", replacer, true);
}
use of com.github.sirblobman.api.language.Replacer in project CombatLogX by SirBlobman.
the class ListenerGameMode method onTag.
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onTag(PlayerTagEvent e) {
if (!shouldForceSwitch())
return;
GameMode gameMode = getForceSwitchMode();
Player player = e.getPlayer();
player.setGameMode(gameMode);
String gameModeName = gameMode.name();
Replacer replacer = message -> message.replace("{game_mode}", gameModeName);
sendMessage(player, "expansion.cheat-prevention.game-mode.force-switch", replacer);
}
Aggregations