Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/main/java/com/Acrobot/ChestShop/ChestShop.java
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,6 @@ public void onDisable() {
executorService.awaitTermination(15, TimeUnit.SECONDS);
} catch (InterruptedException ignored) {}

Toggle.clearToggledPlayers();

if (handler != null) {
handler.close();
getLogger().removeHandler(handler);
Expand Down Expand Up @@ -354,7 +352,6 @@ private void registerEvents() {
registerEvent(new PlayerConnect());
registerEvent(new PlayerInteract());
registerEvent(new PlayerInventory());
registerEvent(new PlayerLeave());
registerEvent(new PlayerTeleport());

registerEvent(new SignParseListener());
Expand Down
32 changes: 9 additions & 23 deletions src/main/java/com/Acrobot/ChestShop/Commands/Toggle.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
package com.Acrobot.ChestShop.Commands;

import com.Acrobot.ChestShop.Configuration.Messages;
import com.google.common.base.Preconditions;
import com.Acrobot.ChestShop.Database.Account;
import com.Acrobot.ChestShop.UUIDs.NameManager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.HashSet;
import java.util.Set;
import java.util.UUID;

/**
* @author KingFaris10
*/
public class Toggle implements CommandExecutor {
private static final Set<UUID> toggledPlayers = new HashSet<>();

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Expand All @@ -31,7 +29,10 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
return false;
}

if (setIgnoring(player, !isIgnoring(player))) {
Account account = NameManager.getOrCreateAccount(player);
account.setIgnoreMessages(!account.isIgnoringMessages());

if (account.isIgnoringMessages()) {
Messages.TOGGLE_MESSAGES_OFF.sendWithPrefix(player);
} else {
Messages.TOGGLE_MESSAGES_ON.sendWithPrefix(player);
Expand All @@ -40,16 +41,13 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
return true;
}

public static void clearToggledPlayers() {
toggledPlayers.clear();
}

public static boolean isIgnoring(OfflinePlayer player) {
return player != null && isIgnoring(player.getUniqueId());
return player != null && NameManager.getOrCreateAccount(player).isIgnoringMessages();
}

public static boolean isIgnoring(UUID playerId) {
return toggledPlayers.contains(playerId);
Account account = NameManager.getAccount(playerId);
return account != null && account.isIgnoringMessages();
}

/**
Expand All @@ -60,16 +58,4 @@ public static boolean isIgnoring(String playerName) {
return isIgnoring(Bukkit.getOfflinePlayer(playerName));
}

public static boolean setIgnoring(Player player, boolean ignoring) {
Preconditions.checkNotNull(player); // Make sure the player instance is not null, in case there are any errors in the code

if (ignoring) {
toggledPlayers.add(player.getUniqueId());
} else {
toggledPlayers.remove(player.getUniqueId());
}

return ignoring;
}

}
11 changes: 11 additions & 0 deletions src/main/java/com/Acrobot/ChestShop/Database/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public class Account {
@DatabaseField(canBeNull = false, dataType = DataType.DATE_LONG, defaultValue = "0")
private Date lastSeen;

@DatabaseField(canBeNull = false, dataType = DataType.BOOLEAN, defaultValue = "0")
private boolean ignoreMessages;

public Account() {
//empty constructor, needed for ORMLite
}
Expand Down Expand Up @@ -73,4 +76,12 @@ public Date getLastSeen() {
public void setLastSeen(Date lastSeen) {
this.lastSeen = lastSeen;
}

public boolean isIgnoringMessages() {
return ignoreMessages;
}

public void setIgnoreMessages(boolean ignoreMessages) {
this.ignoreMessages = ignoreMessages;
}
}

This file was deleted.