Skip to content

Commit 06a5b11

Browse files
authored
Merge pull request #50 from ParallelMC/staging
New Update
2 parents 9144b75 + ec0da66 commit 06a5b11

File tree

9 files changed

+107
-9
lines changed

9 files changed

+107
-9
lines changed

api/build.gradle

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77

88
group = 'org.parallelmc'
99

10-
version = '3.3.0'
10+
version = '3.4.0'
1111
description = 'A set of utilities and features for use on the Parallel Minecraft server'
1212

1313
java {
@@ -214,6 +214,14 @@ bukkit {
214214
description = 'Reloads all emojis'
215215
usage = '/reloademojis'
216216
}
217+
banword {
218+
description = 'Adds a word to the banned words list'
219+
usage = '/banword (word)'
220+
}
221+
allowword {
222+
description = 'Remove a word from the banned words list'
223+
usage = '/allowword (word)'
224+
}
217225
leavetutorial {
218226
description = 'Exit the tutorial you are currently in'
219227
usage = '/leavetutorial'
@@ -269,6 +277,10 @@ bukkit {
269277
description = 'Gives access to giving ParallelItems.'
270278
setDefault('FALSE')
271279
}
280+
'parallelutils.enchant' {
281+
description = 'Gives access to using ParallelItems enchants'
282+
setDefault('FALSE')
283+
}
272284
'parallelutils.test' {
273285
description = 'Gives access to the test command'
274286
setDefault('FALSE')
@@ -285,6 +297,14 @@ bukkit {
285297
description = 'Gives access to fakejoin and fakeleave commands'
286298
setDefault('FALSE')
287299
}
300+
'parallelutils.banword' {
301+
description = 'Gives access to banword command'
302+
setDefault('FALSE')
303+
}
304+
'parallelutils.allowword' {
305+
description = 'Gives access to allowword command'
306+
setDefault('FALSE')
307+
}
288308
'parallelutils.staffchat' {
289309
description = 'Gives access to reading and writing to staff chat'
290310
}

api/src/main/java/parallelmc/parallelutils/Constants.java

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

33
public class Constants {
44

5-
public static final Version VERSION = new Version(3, 3, 0);
5+
public static final Version VERSION = new Version(3, 4, 0);
66
public static final String PLUGIN_NAME = "ParallelUtils";
77
public static final String DEFAULT_WORLD = "world2";
88
}

modules/src/main/java/parallelmc/parallelutils/modules/beehiveinspector/events/BeehiveBroken.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import net.kyori.adventure.text.Component;
44
import net.kyori.adventure.text.format.NamedTextColor;
55
import org.bukkit.block.data.type.Beehive;
6+
import org.bukkit.entity.Player;
67
import org.bukkit.inventory.ItemStack;
78
import org.bukkit.Location;
89
import org.bukkit.Material;
@@ -27,7 +28,9 @@ public void onBreakBlock(BlockBreakEvent event) {
2728
if (block.getType().equals(Material.BEEHIVE) || block.getType().equals(Material.BEE_NEST))
2829
{
2930
// if the block doesn't have any drops for some reason, then do nothing
30-
if (block.getDrops().isEmpty())
31+
Player player = event.getPlayer();
32+
ItemStack heldItem = player.getInventory().getItemInMainHand();
33+
if (block.getDrops(heldItem, player).isEmpty())
3134
return;
3235

3336
ParallelUtils.log(Level.INFO, "Dropping");
@@ -54,7 +57,7 @@ public void onBreakBlock(BlockBreakEvent event) {
5457

5558
// more beautiful code
5659
// since a beehive usually only drops itself or nothing, we can hardcode this index
57-
ItemStack item = (ItemStack)block.getDrops().toArray()[0];
60+
ItemStack item = (ItemStack)block.getDrops(heldItem, player).toArray()[0];
5861
List<Component> lore = new ArrayList<>();
5962
// add the lore with the hive information
6063
lore.add(Component.text("Bees: " + bees, NamedTextColor.GRAY));

modules/src/main/java/parallelmc/parallelutils/modules/parallelchat/ParallelChat.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ public class ParallelChat extends ParallelModule {
6464

6565
private final FileConfiguration bannedWordsConfig = new YamlConfiguration();
6666
public List<String> bannedWords = new ArrayList<>();
67-
public List<String> allowedWords = new ArrayList<>();
6867

6968
public List<Component> autoMessages = new ArrayList<>();
7069

@@ -176,7 +175,6 @@ UUID varchar(36) not null,
176175
}
177176

178177
this.bannedWords = bannedWordsConfig.getStringList("Banned-Words");
179-
this.allowedWords = bannedWordsConfig.getStringList("Whitelisted-Words");
180178
ParallelUtils.log(Level.INFO, "ParallelChat: Loaded " + bannedWords.size() + " banned words.");
181179

182180
ConfigurationSection groups = puPlugin.getConfig().getConfigurationSection("group-formats");
@@ -223,8 +221,8 @@ UUID varchar(36) not null,
223221

224222

225223
try {
226-
this.chatLogWriter = Files.newBufferedWriter(Path.of(puPlugin.getDataFolder().getAbsolutePath() + "/chat_log.txt"), StandardCharsets.UTF_8, StandardOpenOption.WRITE);
227-
this.cmdLogWriter = Files.newBufferedWriter(Path.of(puPlugin.getDataFolder().getAbsolutePath() + "/command_log.txt"), StandardCharsets.UTF_8, StandardOpenOption.WRITE);
224+
this.chatLogWriter = Files.newBufferedWriter(Path.of(puPlugin.getDataFolder().getAbsolutePath() + "/chat_log.txt"), StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.WRITE);
225+
this.cmdLogWriter = Files.newBufferedWriter(Path.of(puPlugin.getDataFolder().getAbsolutePath() + "/command_log.txt"), StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.WRITE);
228226
}
229227
catch (IOException e) {
230228
ParallelUtils.log(Level.SEVERE, "Failed to open writer to loggers!");
@@ -257,6 +255,8 @@ UUID varchar(36) not null,
257255
puPlugin.getCommand("formats").setExecutor(new ParallelFormats());
258256
puPlugin.getCommand("dnd").setExecutor(new ParallelDoNotDisturb());
259257
puPlugin.getCommand("reloademojis").setExecutor(new ParallelReloadEmojis());
258+
puPlugin.getCommand("banword").setExecutor(new ParallelBanWord());
259+
puPlugin.getCommand("allowword").setExecutor(new ParallelAllowWord());
260260

261261
this.chatroomCommands = new ChatroomCommands();
262262
puPlugin.getCommand("chatroom").setExecutor(chatroomCommands);
@@ -316,6 +316,15 @@ public void onDisable() {
316316

317317
// save chatrooms
318318
chatRoomManager.saveChatroomsToFile();
319+
320+
// save banned words list in case any words were added or removed
321+
bannedWordsConfig.set("Banned-Words", bannedWords);
322+
try {
323+
bannedWordsConfig.save(new File(puPlugin.getDataFolder(), "bannedwords.yml"));
324+
} catch (IOException e) {
325+
ParallelUtils.log(Level.SEVERE, "Failed to save banned words to file!");
326+
e.printStackTrace();
327+
}
319328
}
320329

321330
@Override
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package parallelmc.parallelutils.modules.parallelchat.commands;
2+
3+
import org.bukkit.command.Command;
4+
import org.bukkit.command.CommandExecutor;
5+
import org.bukkit.command.CommandSender;
6+
import org.bukkit.entity.Player;
7+
import org.jetbrains.annotations.NotNull;
8+
import parallelmc.parallelutils.modules.parallelchat.ParallelChat;
9+
10+
public class ParallelAllowWord implements CommandExecutor {
11+
@Override
12+
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String label, String[] args) {
13+
if (args.length < 1) {
14+
return false;
15+
}
16+
if (commandSender instanceof Player) {
17+
if (!commandSender.hasPermission("parallelutils.allowword")) {
18+
return true;
19+
}
20+
}
21+
// since we allow the same words with different capitalization we don't have to use equalsIgnoreCase here
22+
if (ParallelChat.get().bannedWords.stream().noneMatch(x -> x.equals(args[0]))) {
23+
commandSender.sendMessage("The word '" + args[0] + "' is already allowed.");
24+
return true;
25+
}
26+
ParallelChat.get().bannedWords.remove(args[0]);
27+
commandSender.sendMessage("Removed '" + args[0] + "' from the banned words list.");
28+
return true;
29+
}
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package parallelmc.parallelutils.modules.parallelchat.commands;
2+
3+
import org.bukkit.command.Command;
4+
import org.bukkit.command.CommandExecutor;
5+
import org.bukkit.command.CommandSender;
6+
import org.bukkit.entity.Player;
7+
import org.jetbrains.annotations.NotNull;
8+
import parallelmc.parallelutils.modules.parallelchat.ParallelChat;
9+
10+
public class ParallelBanWord implements CommandExecutor {
11+
@Override
12+
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String label, String[] args) {
13+
if (args.length < 1) {
14+
return false;
15+
}
16+
if (commandSender instanceof Player) {
17+
if (!commandSender.hasPermission("parallelutils.banword")) {
18+
return true;
19+
}
20+
}
21+
// since we allow the same words with different capitalization we don't have to use equalsIgnoreCase here
22+
if (ParallelChat.get().bannedWords.stream().anyMatch(x -> x.equals(args[0]))) {
23+
commandSender.sendMessage("The banned words list already contains the word '" + args[0] + "'");
24+
return true;
25+
}
26+
ParallelChat.get().bannedWords.add(args[0]);
27+
commandSender.sendMessage("Added '" + args[0] + "' to the banned words list.");
28+
return true;
29+
}
30+
}

modules/src/main/java/parallelmc/parallelutils/modules/parallelchat/events/OnChatMessage.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ public void onChatMessage(AsyncChatEvent event) {
7878
catch (IOException e) {
7979
ParallelUtils.log(Level.SEVERE, "Failed to log chat message!");
8080
}
81+
catch (NullPointerException e) {
82+
ParallelUtils.log(Level.SEVERE, "Failed to log chat message! chatLogWriter was null!");
83+
}
8184

8285
// @ Mention check
8386
// have to use strings to figure out the player names

modules/src/main/java/parallelmc/parallelutils/modules/parallelchat/events/OnCommand.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,8 @@ public void onCommand(PlayerCommandPreprocessEvent event) {
4949
catch (IOException e) {
5050
ParallelUtils.log(Level.SEVERE, "Failed to log command!");
5151
}
52+
catch (NullPointerException e) {
53+
ParallelUtils.log(Level.SEVERE, "Failed to log chat message! chatLogWriter was null!");
54+
}
5255
}
5356
}

0 commit comments

Comments
 (0)