Skip to content

Command Spy Persistence #2040

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: devel
Choose a base branch
from
27 changes: 27 additions & 0 deletions src/main/java/me/totalfreedom/totalfreedommod/CommandSpy.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package me.totalfreedom.totalfreedommod;

import me.totalfreedom.totalfreedommod.admin.Admin;
import me.totalfreedom.totalfreedommod.player.FPlayer;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerJoinEvent;

public class CommandSpy extends FreedomService
{
Expand Down Expand Up @@ -41,4 +44,28 @@ public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
}
}

// This will check if the user joining has command spy enabled, and if they are an admin. If they are not an admin it will ensure their command spy access has been removed, and if they are it will check to see if the admin has left command spy enabled or not on previous use.
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent event)
{
Admin admin = getAdmin((Player) event.getPlayer());
FPlayer playerdata = plugin.pl.getPlayer(event.getPlayer());

if (plugin.al.isAdmin(event.getPlayer()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This entire block should be changed to something like:

boolean admin = plugin.al.isAdmin(event.getPlayer();
playerdata.setCommandSpy(admin && admin.hasCommandSpy());

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given I'm struggling to understand what that even does... I will leave the PR as is for now, its already broken and needs more work, but I can't see what I've screwed up.

{
if (admin.hasCommandSpy())
{
playerdata.setCommandSpy(playerdata.cmdspyEnabled() == true);
}
else
{
playerdata.setCommandSpy(playerdata.cmdspyEnabled() == false);
}
}
else
{
playerdata.setCommandSpy(playerdata.cmdspyEnabled() == false);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public void run()

if (lockdownEnabled)
{
FUtil.playerMsg(player, "Warning: Server is currenty in lockdown-mode, new players will not be able to join!", ChatColor.RED);
FUtil.playerMsg(player, "Warning: Server is currently in lockdown-mode, new players will not be able to join!", ChatColor.RED);
}
}
}.runTaskLater(plugin, 20L * 1L);
Expand Down
19 changes: 18 additions & 1 deletion src/main/java/me/totalfreedom/totalfreedommod/admin/Admin.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package me.totalfreedom.totalfreedommod.admin;

import com.google.common.collect.Lists;

import java.util.Date;
import java.util.List;

import lombok.Getter;
import lombok.Setter;
import me.totalfreedom.totalfreedommod.LogViewer.LogsRegistrationMode;
Expand Down Expand Up @@ -39,6 +41,9 @@ public class Admin implements ConfigLoadable, ConfigSavable, Validatable
@Getter
@Setter
private String loginMessage = null;
@Getter
@Setter
private boolean commandSpy = true;

public Admin(Player player)
{
Expand All @@ -62,7 +67,8 @@ public String toString()
.append("- Last Login: ").append(FUtil.dateToString(lastLogin)).append("\n")
.append("- Custom Login Message: ").append(loginMessage).append("\n")
.append("- Rank: ").append(rank.getName()).append("\n")
.append("- Is Active: ").append(active);
.append("- Is Active: ").append(active).append("\n")
.append("- CommandSpy: ").append(commandSpy);

return output.toString();
}
Expand Down Expand Up @@ -97,6 +103,7 @@ public void saveTo(ConfigurationSection cs)
cs.set("ips", Lists.newArrayList(ips));
cs.set("last_login", FUtil.dateToString(lastLogin));
cs.set("login_message", loginMessage);
cs.set("commandspy", commandSpy);
}

public boolean isAtLeast(Rank pRank)
Expand All @@ -109,6 +116,16 @@ public boolean hasLoginMessage()
return loginMessage != null && !loginMessage.isEmpty();
}

public boolean hasCommandSpy()
{
return commandSpy;
}

public boolean setCommandSpy(boolean commandSpyStatus)
{
return commandSpy = commandSpyStatus;
}

// Util IP methods
public void addIp(String ip)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import com.google.common.base.Function;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;

import java.util.Date;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import lombok.Getter;
import me.totalfreedom.totalfreedommod.FreedomService;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.totalfreedom.totalfreedommod.command;

import me.totalfreedom.totalfreedommod.admin.Admin;
import me.totalfreedom.totalfreedommod.player.FPlayer;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.command.Command;
Expand All @@ -14,9 +15,18 @@ public class Command_cmdspy extends FreedomCommand
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{

Admin admin = getAdmin(playerSender);
FPlayer playerdata = plugin.pl.getPlayer(playerSender);
playerdata.setCommandSpy(!playerdata.cmdspyEnabled());
if (playerdata.cmdspyEnabled())
{
admin.setCommandSpy(true);
}
else
{
admin.setCommandSpy(false);
}

msg("CommandSpy " + (playerdata.cmdspyEnabled() ? "enabled." : "disabled."));

return true;
Expand Down