Compare commits

...

5 Commits

5 changed files with 37 additions and 13 deletions

View File

@ -23,7 +23,9 @@ public enum PlayerActivity {
CAST_SKILL(() -> MMOCore.plugin.configManager.globalSkillCooldown), CAST_SKILL(() -> MMOCore.plugin.configManager.globalSkillCooldown),
; //Added by Kilo for the Timeout System (ENTER_CASTING). The EXIT_CASTING is unused, but tracked.
ENTER_CASTING(null),
EXIT_CASTING(null);
private final Provider<Long> timeout; private final Provider<Long> timeout;

View File

@ -439,7 +439,7 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD
} }
public long getLastActivity(PlayerActivity activity) { public long getLastActivity(PlayerActivity activity) {
return this.lastActivity.getOrDefault(activity, 0l); return this.lastActivity.getOrDefault(activity, 0L);
} }
public long getActivityTimeOut(PlayerActivity activity) { public long getActivityTimeOut(PlayerActivity activity) {
@ -1007,13 +1007,7 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD
@Deprecated @Deprecated
public boolean setSkillCasting(@NotNull SkillCastingInstance skillCasting) { public boolean setSkillCasting(@NotNull SkillCastingInstance skillCasting) {
Validate.isTrue(!isCasting(), "Player already in casting mode"); Validate.isTrue(!isCasting(), "Player already in casting mode");
PlayerEnterCastingModeEvent event = new PlayerEnterCastingModeEvent(getPlayer()); return setSkillCasting();
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) return false;
skillCasting.close();
setSkillCasting();
return true;
} }
/** /**
@ -1025,8 +1019,8 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD
PlayerEnterCastingModeEvent event = new PlayerEnterCastingModeEvent(getPlayer()); PlayerEnterCastingModeEvent event = new PlayerEnterCastingModeEvent(getPlayer());
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) return false; if (event.isCancelled()) return false;
this.skillCasting = SkillCastingMode.getCurrent().newInstance(this); this.skillCasting = SkillCastingMode.getCurrent().newInstance(this);
setLastActivity(PlayerActivity.ENTER_CASTING);
return true; return true;
} }
@ -1058,10 +1052,34 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD
skillCasting.close(); skillCasting.close();
this.skillCasting = null; this.skillCasting = null;
setLastActivity(PlayerActivity.EXIT_CASTING);
setLastActivity(PlayerActivity.ACTION_BAR_MESSAGE, 0); // Reset action bar setLastActivity(PlayerActivity.ACTION_BAR_MESSAGE, 0); // Reset action bar
return true; return true;
} }
/**
* @return true if the "skill-casting.timeout" integer (second) is less than the most recent event beteen CAST_SKILL and ENTER_CASTING, it chooses the most recent one as its comparison. This is used for the timeout of casting. Returns false if the value is 0 or if the player is not casting.
*/
public boolean isCastingTimeoutExpired() {
if (MMOCore.plugin.configManager.castingTimeoutTime <= 0) return false;
if (!isCasting()) return false;
long lastSkillCastTime = getLastActivity(PlayerActivity.CAST_SKILL);
long lastEnterCastingTime = getLastActivity(PlayerActivity.ENTER_CASTING);
// If the player is in casting mode but has not yet cast a skill, use the enter casting time
if (lastSkillCastTime == 0L)
lastSkillCastTime = lastEnterCastingTime;
long lastActivityTime = Math.max(lastSkillCastTime, lastEnterCastingTime);
long timeSinceLastActivity = System.currentTimeMillis() - lastActivityTime;
long castingTimeoutMillis = MMOCore.plugin.configManager.castingTimeoutTime * 1000L;
return timeSinceLastActivity > castingTimeoutMillis;
}
public void displayActionBar(String message) { public void displayActionBar(String message) {
setLastActivity(PlayerActivity.ACTION_BAR_MESSAGE); setLastActivity(PlayerActivity.ACTION_BAR_MESSAGE);
getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message)); getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message));

View File

@ -34,11 +34,10 @@ public class ConfigManager {
public long combatLogTimer, lootChestExpireTime, lootChestPlayerCooldown, globalSkillCooldown; public long combatLogTimer, lootChestExpireTime, lootChestPlayerCooldown, globalSkillCooldown;
public double lootChestsChanceWeight, dropItemsChanceWeight, fishingDropsChanceWeight, partyMaxExpSplitRange, pvpModeToggleOnCooldown, pvpModeToggleOffCooldown, pvpModeCombatCooldown, public double lootChestsChanceWeight, dropItemsChanceWeight, fishingDropsChanceWeight, partyMaxExpSplitRange, pvpModeToggleOnCooldown, pvpModeToggleOffCooldown, pvpModeCombatCooldown,
pvpModeCombatTimeout, pvpModeInvulnerabilityTimeRegionChange, pvpModeInvulnerabilityTimeCommand, pvpModeRegionEnterCooldown, pvpModeRegionLeaveCooldown; pvpModeCombatTimeout, pvpModeInvulnerabilityTimeRegionChange, pvpModeInvulnerabilityTimeCommand, pvpModeRegionEnterCooldown, pvpModeRegionLeaveCooldown;
public int maxPartyLevelDifference, maxSkillSlots, minCombatLevel, maxCombatLevelDifference, skillTreeScrollStepX, skillTreeScrollStepY; public int maxPartyLevelDifference, maxSkillSlots, minCombatLevel, maxCombatLevelDifference, skillTreeScrollStepX, skillTreeScrollStepY, castingTimeoutTime;
public final List<EntityDamageEvent.DamageCause> combatLogDamageCauses = new ArrayList<>(); public final List<EntityDamageEvent.DamageCause> combatLogDamageCauses = new ArrayList<>();
private final FileConfiguration messages; private final FileConfiguration messages;
/* /*
* The instance must be created after the other managers since all it does * The instance must be created after the other managers since all it does
* is to update them based on the config except for the classes which are * is to update them based on the config except for the classes which are
@ -124,6 +123,10 @@ public class ConfigManager {
lootChestExpireTime = Math.max(MMOCore.plugin.getConfig().getInt("loot-chests.chest-expire-time"), 1) * 20; lootChestExpireTime = Math.max(MMOCore.plugin.getConfig().getInt("loot-chests.chest-expire-time"), 1) * 20;
lootChestPlayerCooldown = (long) MMOCore.plugin.getConfig().getDouble("player-cooldown") * 1000L; lootChestPlayerCooldown = (long) MMOCore.plugin.getConfig().getDouble("player-cooldown") * 1000L;
globalSkillCooldown = MMOCore.plugin.getConfig().getLong("global-skill-cooldown") * 50; globalSkillCooldown = MMOCore.plugin.getConfig().getLong("global-skill-cooldown") * 50;
//Timeout for casting
castingTimeoutTime = MMOCore.plugin.getConfig().getInt("skill-casting.timeout",0);
noSkillBoundPlaceholder = getSimpleMessage("no-skill-placeholder").message(); noSkillBoundPlaceholder = getSimpleMessage("no-skill-placeholder").message();
lootChestsChanceWeight = MMOCore.plugin.getConfig().getDouble("chance-stat-weight.loot-chests"); lootChestsChanceWeight = MMOCore.plugin.getConfig().getDouble("chance-stat-weight.loot-chests");
dropItemsChanceWeight = MMOCore.plugin.getConfig().getDouble("chance-stat-weight.drop-items"); dropItemsChanceWeight = MMOCore.plugin.getConfig().getDouble("chance-stat-weight.drop-items");

View File

@ -39,7 +39,7 @@ public abstract class SkillCastingInstance extends BukkitRunnable implements Lis
@Override @Override
public void run() { public void run() {
if (!caster.isOnline() || caster.getPlayer().isDead()) { if (!caster.isOnline() || caster.getPlayer().isDead() || caster.isCastingTimeoutExpired()) {
caster.leaveSkillCasting(); caster.leaveSkillCasting();
return; return;
} }

View File

@ -100,6 +100,7 @@ skill-casting:
mode: SKILL_BAR mode: SKILL_BAR
open: SWAP_HANDS open: SWAP_HANDS
disable-sneak: false disable-sneak: false
timeout: 0
loot-chests: loot-chests: