Skip to content

Commit e692f3c

Browse files
committed
Records and more cleanup
Signed-off-by: BT (calcastor/mame) <43831917+calcastor@users.noreply.github.com>
1 parent 51404b4 commit e692f3c

File tree

20 files changed

+102
-253
lines changed

20 files changed

+102
-253
lines changed

core/src/main/java/dev/pgm/community/freeze/FreezeFeature.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,12 @@ public void setFrozen(CommandAudience sender, Player freezee, boolean frozen, bo
101101
public static ItemStack getFreezeTool(CommandSender viewer) {
102102
ItemStack stack = new ItemStack(TOOL_MATERIAL);
103103
ItemMeta meta = stack.getItemMeta();
104-
meta.setDisplayName(
105-
ChatColor.WHITE
106-
+ ChatColor.BOLD.toString()
107-
+ TextTranslations.translate("moderation.freeze.itemName", viewer));
104+
meta.setDisplayName(ChatColor.WHITE
105+
+ ChatColor.BOLD.toString()
106+
+ TextTranslations.translate("moderation.freeze.itemName", viewer));
108107
meta.addItemFlags(ItemFlag.values());
109-
meta.setLore(
110-
Collections.singletonList(
111-
ChatColor.GRAY
112-
+ TextTranslations.translate("moderation.freeze.itemDescription", viewer)));
108+
meta.setLore(Collections.singletonList(
109+
ChatColor.GRAY + TextTranslations.translate("moderation.freeze.itemDescription", viewer)));
113110
stack.setItemMeta(meta);
114111
return stack;
115112
}
@@ -153,11 +150,7 @@ public void onObserverToolFreeze(final ObserverInteractEvent event) {
153150
public void onPlayerCommand(final PlayerCommandPreprocessEvent event) {
154151
if (freeze.isFrozen(event.getPlayer())
155152
&& !event.getPlayer().hasPermission(CommunityPermissions.FREEZE)) {
156-
boolean allow =
157-
ALLOWED_CMDS.stream()
158-
.filter(cmd -> event.getMessage().startsWith(cmd))
159-
.findAny()
160-
.isPresent();
153+
boolean allow = ALLOWED_CMDS.stream().anyMatch(cmd -> event.getMessage().startsWith(cmd));
161154

162155
if (!allow) {
163156
// Don't allow commands except for those related to chat.

core/src/main/java/dev/pgm/community/info/InfoCommandData.java

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,11 @@
1010
import org.bukkit.configuration.ConfigurationSection;
1111
import tc.oc.pgm.util.Audience;
1212

13-
public class InfoCommandData {
13+
public record InfoCommandData(String name, List<Component> lines, String permission) {
1414

1515
private static final String LINES_KEY = "lines";
1616
private static final String PERMISSION_KEY = "permission";
1717

18-
private final String name;
19-
private final List<Component> lines;
20-
private final String permission;
21-
22-
public InfoCommandData(String name, List<Component> lines, String permission) {
23-
this.name = name;
24-
this.lines = lines;
25-
this.permission = permission;
26-
}
27-
2818
public static InfoCommandData of(ConfigurationSection section) {
2919
return new InfoCommandData(
3020
section.getName(),
@@ -34,28 +24,16 @@ public static InfoCommandData of(ConfigurationSection section) {
3424
section.getString(PERMISSION_KEY));
3525
}
3626

37-
public String getName() {
38-
return name;
39-
}
40-
41-
public List<Component> getLines() {
42-
return lines;
43-
}
44-
45-
public String getPermission() {
46-
return permission;
47-
}
48-
4927
public void sendCommand(CommandSender sender) {
5028
Audience viewer = Audience.get(sender);
5129

52-
if (getPermission() != null && !getPermission().isEmpty()) {
53-
if (!sender.hasPermission(getPermission())) {
30+
if (permission() != null && !permission().isEmpty()) {
31+
if (!sender.hasPermission(permission())) {
5432
viewer.sendWarning(text("You do not have permission for this command"));
5533
return; // TODO: Translate
5634
}
5735
}
5836

59-
getLines().forEach(viewer::sendMessage);
37+
lines().forEach(viewer::sendMessage);
6038
}
6139
}

core/src/main/java/dev/pgm/community/info/InfoCommandsFeature.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ public InfoCommandConfig getInfoConfig() {
2525
public void onPlayerCommandProcess(PlayerCommandPreprocessEvent event) {
2626
// We dynamically check for defined commands, and send the related feedback
2727
getInfoConfig().getInfoCommands().stream()
28-
.filter(
29-
c -> event.getMessage().toLowerCase().startsWith("/" + c.getName().toLowerCase()))
28+
.filter(c -> event.getMessage().toLowerCase().startsWith("/" + c.name().toLowerCase()))
3029
.findAny()
3130
.ifPresent(command -> {
3231
command.sendCommand(event.getPlayer());

core/src/main/java/dev/pgm/community/mobs/MobFeature.java

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ public class MobFeature extends FeatureBase {
3030

3131
public static final float DEFAULT_SPEED = 1.2f;
3232

33-
private Map<UUID, UUID> followTargets;
34-
private Set<UUID> attackers;
33+
private final Map<UUID, UUID> followTargets;
34+
private final Set<UUID> attackers;
3535

3636
private BukkitTask task;
3737
private float speed;
@@ -67,10 +67,8 @@ public void disable() {
6767
@EventHandler
6868
public void onDamage(EntityDamageByEntityEvent event) {
6969
if (event.getDamager() != null
70-
&& event.getDamager() instanceof Player
71-
&& event.getEntity() instanceof Player) {
72-
Player damager = (Player) event.getDamager();
73-
Player target = (Player) event.getEntity();
70+
&& event.getDamager() instanceof Player damager
71+
&& event.getEntity() instanceof Player target) {
7472

7573
if (isAttacker(damager.getUniqueId())) {
7674
setTarget(damager, target);
@@ -79,14 +77,13 @@ public void onDamage(EntityDamageByEntityEvent event) {
7977
}
8078

8179
public void updateFollows() {
82-
this.followTargets.entrySet().forEach(entry -> {
83-
Player owner = Bukkit.getPlayer(entry.getKey());
84-
Player target = Bukkit.getPlayer(entry.getValue());
80+
this.followTargets.forEach((key, value) -> {
81+
Player owner = Bukkit.getPlayer(key);
82+
Player target = Bukkit.getPlayer(value);
8583
if (owner != null && target != null) {
8684
this.getOwnedMobs(owner).forEach(mob -> {
8785
ENTITY_UTILS.follow(mob, target.getLocation(), speed);
88-
if (mob instanceof Creature && attackers.contains(owner.getUniqueId())) {
89-
Creature creature = (Creature) mob;
86+
if (mob instanceof Creature creature && attackers.contains(owner.getUniqueId())) {
9087
creature.setTarget(target);
9188
}
9289
});
@@ -127,8 +124,7 @@ public void spawn(Player sender, EntityType type, int amount, boolean canDie) {
127124
public void spawn(Player sender, EntityType type, boolean canDie) {
128125
Entity entity = sender.getLocation().getWorld().spawnEntity(sender.getLocation(), type);
129126

130-
if (entity instanceof LivingEntity) {
131-
LivingEntity mob = (LivingEntity) entity;
127+
if (entity instanceof LivingEntity mob) {
132128
if (!canDie) {
133129
mob.setMaxHealth(Integer.MAX_VALUE);
134130
mob.setHealth(mob.getMaxHealth());
@@ -164,17 +160,15 @@ public int heal(Player sender) {
164160

165161
public int remove(Player sender) {
166162
List<LivingEntity> mobs = getOwnedMobs(sender);
167-
mobs.forEach(mob -> mob.remove());
163+
mobs.forEach(Entity::remove);
168164
return mobs.size();
169165
}
170166

171167
public boolean toggleFollow(Player sender) {
172168
UUID playerId = sender.getUniqueId();
173169

174170
// Unset attackers when switching to follow
175-
if (this.attackers.contains(playerId)) {
176-
this.attackers.remove(playerId);
177-
}
171+
this.attackers.remove(playerId);
178172

179173
if (this.followTargets.containsKey(playerId)) {
180174
this.followTargets.remove(playerId);

core/src/main/java/dev/pgm/community/moderation/tools/buttons/ToolButtonBase.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111

1212
public abstract class ToolButtonBase implements ToolButton {
1313

14-
private Player viewer;
14+
private final Player viewer;
1515

16-
private String name;
17-
private List<String> lore;
18-
private Material material;
19-
private int amount;
16+
private final String name;
17+
private final List<String> lore;
18+
private final Material material;
19+
private final int amount;
2020

2121
public ToolButtonBase(
2222
Player viewer, String name, List<String> lore, Material material, int amount) {

core/src/main/java/dev/pgm/community/party/feature/MapPartyFeature.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public Optional<MapPartyHistoryEntry> getMostRecentHistory() {
126126

127127
public MapPartyPreset getPreset(String presetName) {
128128
return getPresets().stream()
129-
.filter(preset -> cleanName(preset.getName()).equalsIgnoreCase(presetName))
129+
.filter(preset -> cleanName(preset.name()).equalsIgnoreCase(presetName))
130130
.findAny()
131131
.orElse(null);
132132
}
@@ -142,22 +142,22 @@ public void create(CommandAudience viewer, Player sender, MapPartyPreset preset,
142142
return;
143143
}
144144

145-
if (preset.getName() != null) {
146-
setName(viewer, preset.getName());
145+
if (preset.name() != null) {
146+
setName(viewer, preset.name());
147147
}
148148

149-
if (preset.getDescription() != null) {
150-
setDescription(viewer, preset.getDescription());
149+
if (preset.description() != null) {
150+
setDescription(viewer, preset.description());
151151
}
152152

153-
if (preset.getDuration() != null) {
154-
setTimelimit(viewer, preset.getDuration(), false);
153+
if (preset.duration() != null) {
154+
setTimelimit(viewer, preset.duration(), false);
155155
}
156156

157157
if (type == MapPartyType.REGULAR) {
158-
setMapPool(viewer, preset.getPool());
158+
setMapPool(viewer, preset.pool());
159159
} else {
160-
preset.getMaps().stream().map(PGMUtils::parseMapText).forEach(map -> addMap(viewer, map));
160+
preset.maps().stream().map(PGMUtils::parseMapText).forEach(map -> addMap(viewer, map));
161161
}
162162
}
163163

core/src/main/java/dev/pgm/community/party/menu/MapPartyMainMenu.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,13 @@ private ClickableItem getModifierMenu() {
189189

190190
private ClickableItem getPresetIcon(MapPartyPreset preset) {
191191
List<String> lore = Lists.newArrayList();
192-
lore.add(colorize("&6Description&7: &3" + preset.getDescription()));
192+
lore.add(colorize("&6Description&7: &3" + preset.description()));
193193
lore.add(colorize("&6Mode&7: &a" + preset.getType().getName()));
194194

195195
if (preset.getType() == MapPartyType.REGULAR) {
196-
lore.add(colorize("&6Pool&7: &b" + preset.getPool()));
196+
lore.add(colorize("&6Pool&7: &b" + preset.pool()));
197197
} else {
198-
lore.add(colorize("&6Maps: &b" + preset.getMaps().size()));
198+
lore.add(colorize("&6Maps: &b" + preset.maps().size()));
199199
}
200200

201201
lore.add("");
@@ -205,17 +205,17 @@ private ClickableItem getPresetIcon(MapPartyPreset preset) {
205205
new ItemBuilder()
206206
.material(Materials.STAINED_GLASS_PANE)
207207
.color(DyeColor.CYAN)
208-
.name(colorize(preset.getName()))
208+
.name(colorize(preset.name()))
209209
.lore(lore.toArray(new String[0]))
210210
.build(),
211211
c -> {
212-
String command = "event preset " + preset.getName();
212+
String command = "event preset " + preset.name();
213213
if (getFeature().requiresForceForCreate()) {
214214
new MapPartyCreateConfirmMenu(
215215
getFeature(),
216216
getViewer(),
217-
"event preset --force " + preset.getName(),
218-
preset.getName())
217+
"event preset --force " + preset.name(),
218+
preset.name())
219219
.open(this);
220220
} else {
221221
Bukkit.dispatchCommand(getViewer(), command);

core/src/main/java/dev/pgm/community/party/presets/MapPartyPreset.java

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,8 @@
77
import java.util.List;
88
import org.bukkit.configuration.ConfigurationSection;
99

10-
public class MapPartyPreset {
11-
12-
private final String name;
13-
private final String description;
14-
private final Duration duration;
15-
private final String pool;
16-
private final List<String> maps;
10+
public record MapPartyPreset(
11+
String name, String description, Duration duration, String pool, List<String> maps) {
1712

1813
public static MapPartyPreset of(ConfigurationSection section) {
1914
return new MapPartyPreset(
@@ -24,36 +19,7 @@ public static MapPartyPreset of(ConfigurationSection section) {
2419
section.getStringList("maps"));
2520
}
2621

27-
public MapPartyPreset(
28-
String name, String description, Duration duration, String pool, List<String> maps) {
29-
this.name = name;
30-
this.description = description;
31-
this.duration = duration;
32-
this.pool = pool;
33-
this.maps = maps;
34-
}
35-
36-
public String getName() {
37-
return name;
38-
}
39-
40-
public String getDescription() {
41-
return description;
42-
}
43-
44-
public Duration getDuration() {
45-
return duration;
46-
}
47-
48-
public String getPool() {
49-
return pool;
50-
}
51-
52-
public List<String> getMaps() {
53-
return maps;
54-
}
55-
5622
public MapPartyType getType() {
57-
return (getPool() == null || getPool().isEmpty()) ? MapPartyType.CUSTOM : MapPartyType.REGULAR;
23+
return (pool() == null || pool().isEmpty()) ? MapPartyType.CUSTOM : MapPartyType.REGULAR;
5824
}
5925
}

core/src/main/java/dev/pgm/community/polls/ending/types/MapEndAction.java

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,7 @@
1818
import tc.oc.pgm.util.named.MapNameStyle;
1919
import tc.oc.pgm.util.text.TextFormatter;
2020

21-
public class MapEndAction implements EndAction {
22-
23-
private final MapInfo map;
24-
25-
public MapEndAction(MapInfo map) {
26-
this.map = map;
27-
}
28-
29-
public MapInfo getMap() {
30-
return map;
31-
}
21+
public record MapEndAction(MapInfo map) implements EndAction {
3222

3323
@Override
3424
public String getValue() {
@@ -103,12 +93,12 @@ public Component getDefaultQuestion() {
10393

10494
@Override
10595
public boolean equals(Object other) {
106-
if (!(other instanceof MapEndAction)) return false;
107-
return ((MapEndAction) other).getMap().equals(getMap());
96+
if (!(other instanceof MapEndAction(MapInfo mapInfo))) return false;
97+
return mapInfo.equals(map());
10898
}
10999

110100
@Override
111101
public int hashCode() {
112-
return getMap().hashCode();
102+
return map().hashCode();
113103
}
114104
}

0 commit comments

Comments
 (0)