Skip to content

Commit 3785786

Browse files
committed
Code cleanup
1 parent ae7d61d commit 3785786

File tree

2 files changed

+10
-56
lines changed

2 files changed

+10
-56
lines changed

src/main/java/me/tinyoverflow/privatestatus/AddressRepository.java

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
import me.tinyoverflow.privatestatus.events.AddAddressEvent;
44
import org.bukkit.OfflinePlayer;
5-
import org.jetbrains.annotations.NotNull;
65

7-
import javax.sound.sampled.Line;
86
import java.net.InetAddress;
97
import java.net.UnknownHostException;
108
import java.time.LocalDateTime;
@@ -28,35 +26,6 @@ public AddressRepository(Logger logger)
2826
this.zoneOffset = OffsetDateTime.now().getOffset();
2927
}
3028

31-
/**
32-
* Loads data from a map consisting of the UUID string as the key and the base64 encoded address as the value.
33-
*
34-
* @param configMap Map of key => value pairs from the configuration file.
35-
*/
36-
public void fromMap(@NotNull Map<String, Object> configMap)
37-
{
38-
// Make sure we work with a fresh map.
39-
storage.clear();
40-
41-
// Process each and every item inside the section.
42-
for (Map.Entry<String, Object> entry : configMap.entrySet()) {
43-
String address = entry.getKey();
44-
LocalDateTime expiration = LocalDateTime.ofEpochSecond((Long) entry.getValue(), 0, zoneOffset);
45-
46-
// Decode the stored address and add it to the repository.
47-
try {
48-
InetAddress inetAddress = InetAddress.getByName(address);
49-
storage.put(inetAddress, expiration);
50-
}
51-
catch (UnknownHostException e) {
52-
logger.warning("Unknown host found in config. Skipping: " + address);
53-
}
54-
}
55-
56-
// Notify the user about the loading state.
57-
logger.info("Loaded " + storage.size() + " addresses from configuration.");
58-
}
59-
6029
/**
6130
* Loads known addresses from a {@code List<Map<String, Object>>}.
6231
*
@@ -87,25 +56,6 @@ public void fromList(List<Map<String, Object>> data)
8756
logger.info("Loaded " + storage.size() + " addresses from configuration.");
8857
}
8958

90-
/**
91-
* Returns the data as a string map.
92-
*
93-
* @return The map with the UUID string as the key and the base64 encoded address as the value.
94-
*/
95-
public Map<String, Long> toMap()
96-
{
97-
Map<String, Long> addressList = new HashMap<>();
98-
99-
for (Map.Entry<InetAddress, LocalDateTime> entry : storage.entrySet()) {
100-
InetAddress inetAddress = entry.getKey();
101-
LocalDateTime localDateTime = entry.getValue();
102-
103-
addressList.put(inetAddress.getHostAddress(), localDateTime.toEpochSecond(zoneOffset));
104-
}
105-
106-
return addressList;
107-
}
108-
10959
public List<Map<String, Object>> toList()
11060
{
11161
List<Map<String, Object>> addressList = new ArrayList<>();
@@ -148,6 +98,7 @@ public void add(OfflinePlayer player, InetAddress inetAddress, LocalDateTime exp
14898
}
14999
}
150100

101+
@SuppressWarnings("unchecked")
151102
public Map<InetAddress, LocalDateTime> getAll()
152103
{
153104
return (Map<InetAddress, LocalDateTime>) storage.clone();

src/main/java/me/tinyoverflow/privatestatus/PrivateStatus.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.destroystokyo.paper.event.server.PaperServerListPingEvent;
44
import me.tinyoverflow.privatestatus.jobs.PruneExpiredAddressesJob;
5-
import org.bukkit.configuration.ConfigurationSection;
65
import org.bukkit.entity.Player;
76
import org.bukkit.event.EventHandler;
87
import org.bukkit.event.EventPriority;
@@ -13,7 +12,10 @@
1312
import java.net.InetAddress;
1413
import java.net.InetSocketAddress;
1514
import java.time.LocalDateTime;
16-
import java.util.*;
15+
import java.util.ArrayList;
16+
import java.util.HashMap;
17+
import java.util.List;
18+
import java.util.Map;
1719
import java.util.logging.Level;
1820

1921
public class PrivateStatus extends JavaPlugin implements Listener
@@ -45,6 +47,7 @@ public void onLoad()
4547
}
4648

4749
@Override
50+
@SuppressWarnings("unchecked")
4851
public void onEnable()
4952
{
5053
getServer().getPluginManager().registerEvents(this, this);
@@ -57,10 +60,10 @@ public void onEnable()
5760
// Load addresses from configuration file, if the section exists.
5861
List<?> data = getConfig().getList(CONFIG_KNOWN_ADDRESSES, new ArrayList<>());
5962
repository.fromList((List<Map<String, Object>>) data);
60-
// ConfigurationSection configurationSection = getConfig().getConfigurationSection(CONFIG_KNOWN_ADDRESSES);
61-
// if (configurationSection != null) {
62-
// repository.fromMap(configurationSection.getValues(false));
63-
// }
63+
// ConfigurationSection configurationSection = getConfig().getConfigurationSection(CONFIG_KNOWN_ADDRESSES);
64+
// if (configurationSection != null) {
65+
// repository.fromMap(configurationSection.getValues(false));
66+
// }
6467

6568
// Initialize Metrics
6669
PrivateStatusMetrics metrics = new PrivateStatusMetrics(this, 19291);

0 commit comments

Comments
 (0)