F Logout Added & Few Cleanups and Workaround to Fixing Default Perms
This commit is contained in:
@@ -5,6 +5,7 @@ import com.massivecraft.factions.SaberFactions;
|
||||
import com.massivecraft.factions.cmd.alts.CmdAlts;
|
||||
import com.massivecraft.factions.cmd.claim.*;
|
||||
import com.massivecraft.factions.cmd.econ.CmdMoney;
|
||||
import com.massivecraft.factions.cmd.logout.CmdLogout;
|
||||
import com.massivecraft.factions.cmd.points.CmdPoints;
|
||||
import com.massivecraft.factions.cmd.relational.CmdRelationAlly;
|
||||
import com.massivecraft.factions.cmd.relational.CmdRelationEnemy;
|
||||
@@ -124,6 +125,7 @@ public class FCmdRoot extends FCommand {
|
||||
public CmdFGlobal cmdFGlobal = new CmdFGlobal();
|
||||
public CmdViewChest cmdViewChest = new CmdViewChest();
|
||||
public CmdPoints cmdPoints = new CmdPoints();
|
||||
public CmdLogout cmdLogout = new CmdLogout();
|
||||
|
||||
|
||||
|
||||
@@ -193,6 +195,7 @@ public class FCmdRoot extends FCommand {
|
||||
this.addSubCommand(this.cmdStatus);
|
||||
this.addSubCommand(this.cmdStealth);
|
||||
this.addSubCommand(this.cmdStuck);
|
||||
this.addSubCommand(this.cmdLogout);
|
||||
this.addSubCommand(this.cmdTag);
|
||||
this.addSubCommand(this.cmdTitle);
|
||||
this.addSubCommand(this.cmdUnclaim);
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.massivecraft.factions.cmd.logout;
|
||||
|
||||
import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.cmd.FCommand;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
|
||||
public class CmdLogout extends FCommand {
|
||||
|
||||
public CmdLogout(){
|
||||
super();
|
||||
this.aliases.add("logout");
|
||||
|
||||
this.permission = Permission.LOGOUT.node;
|
||||
this.disableOnLock = true;
|
||||
this.disableOnSpam = true;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
LogoutHandler handler = LogoutHandler.getByName(fme.getPlayer().getName());
|
||||
|
||||
if(handler.isLogoutActive(fme.getPlayer())){
|
||||
fme.msg(TL.COMMAND_LOGOUT_ACTIVE);
|
||||
return;
|
||||
}
|
||||
|
||||
handler.applyLogoutCooldown(fme.getPlayer());
|
||||
fme.msg(TL.COMMAND_LOGOUT_LOGGING, Conf.logoutCooldown);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TL getUsageTranslation() { return TL.COMMAND_LOGOUT_DESCRIPTION; }
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.massivecraft.factions.cmd.logout;
|
||||
|
||||
import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.SaberFactions;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class LogoutHandler {
|
||||
|
||||
public static Map<String, LogoutHandler> factionDatas = new HashMap<>();
|
||||
private Map<UUID, Long> logoutCooldown = new HashMap<>();
|
||||
private String name;
|
||||
|
||||
public LogoutHandler(String name) {
|
||||
this.name = name;
|
||||
factionDatas.put(name, this);
|
||||
}
|
||||
|
||||
public boolean isLogoutActive(Player player) {
|
||||
return logoutCooldown.containsKey(player.getUniqueId()) && System.currentTimeMillis() < logoutCooldown.get(player.getUniqueId());
|
||||
}
|
||||
|
||||
public void cancelLogout(Player player) {
|
||||
if(logoutCooldown.containsKey(player.getUniqueId())) {
|
||||
logoutCooldown.remove(player.getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
public void applyLogoutCooldown(Player player) {
|
||||
logoutCooldown.put(player.getUniqueId(), System.currentTimeMillis() + (30 * 1000));
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(SaberFactions.plugin, () -> {
|
||||
if(isLogoutActive(player)) {
|
||||
player.setMetadata("Logout", new FixedMetadataValue(SaberFactions.plugin, true));
|
||||
player.kickPlayer(String.valueOf(TL.COMMAND_LOGOUT_KICK_MESSAGE));
|
||||
cancelLogout(player);
|
||||
}
|
||||
}, Conf.logoutCooldown * 20L);
|
||||
}
|
||||
|
||||
public static LogoutHandler getByName(String name) {
|
||||
LogoutHandler logoutHandler = factionDatas.get(name);
|
||||
return logoutHandler == null ? new LogoutHandler(name) : factionDatas.get(name);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user