diff --git a/src/main/java/lv/pi/animalrp/AnimalRP.java b/src/main/java/lv/pi/animalrp/AnimalRP.java index 880bb85..db8b4bb 100644 --- a/src/main/java/lv/pi/animalrp/AnimalRP.java +++ b/src/main/java/lv/pi/animalrp/AnimalRP.java @@ -102,6 +102,18 @@ public class AnimalRP extends JavaPlugin { } catch (IOException e) { e.printStackTrace(); } + + try { + Path filePath = folder.toPath().resolve("disabled.json"); + if(!Files.exists(filePath)) Files.createFile(filePath); + JsonObject jsobj = new JsonObject(); + AnimalRP.isChatModOff.forEach((a, b) -> { + jsobj.addProperty(a.toString(), b); + }); + Files.write(filePath, gson.toJson(jsobj).getBytes()); + } catch (IOException e) { + e.printStackTrace(); + } } @Override @@ -142,6 +154,18 @@ public class AnimalRP extends JavaPlugin { } } + if(folder.resolve("disabled.json").toFile().exists()) { + try { + JsonObject z = JsonParser.parseString(Files.readString(folder.resolve("disabled.json"))).getAsJsonObject(); + + for (Entry entry : z.entrySet()) { + AnimalRP.isChatModOff.put(UUID.fromString(entry.getKey()), entry.getValue().getAsBoolean()); + } + } catch (JsonSyntaxException | IOException e) { + e.printStackTrace(); + } + } + if(folder.resolve("cooldowns.json").toFile().exists()) { try { JsonObject z = JsonParser.parseString(Files.readString(folder.resolve("cooldowns.json"))).getAsJsonObject(); diff --git a/src/main/java/lv/pi/animalrp/commands/ChatModCommand.java b/src/main/java/lv/pi/animalrp/commands/ChatModCommand.java index 470721c..2f0aabe 100644 --- a/src/main/java/lv/pi/animalrp/commands/ChatModCommand.java +++ b/src/main/java/lv/pi/animalrp/commands/ChatModCommand.java @@ -1,7 +1,5 @@ package lv.pi.animalrp.commands; -import java.util.stream.Collectors; - import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -10,7 +8,6 @@ import org.jetbrains.annotations.NotNull; import lv.pi.animalrp.AnimalRP; -// TODO: Unfinished public class ChatModCommand implements CommandExecutor { @Override public boolean onCommand(@NotNull CommandSender arg0, @NotNull Command arg1, @NotNull String arg2, @NotNull String[] arg3) { @@ -21,16 +18,32 @@ public class ChatModCommand implements CommandExecutor { Player player = (Player)arg0; - if(arg3.length == 0) { - options(player); - return true; - } - boolean off = false; if(arg2.endsWith("off")) { off = true; } + boolean isDisabled = false; + + if(AnimalRP.isChatModOff.get(player.getUniqueId())) { + isDisabled = true; + } + + if(isDisabled) { // chat modifications are turned off + if(off) { // asking to be turned off + arg0.sendMessage(AnimalRP.mm.deserialize("Chat modifications for you are already disabled!")); + } else { // asking to be turned on + arg0.sendMessage(AnimalRP.mm.deserialize("Chat modifications enabled!")); + AnimalRP.isChatModOff.remove(player.getUniqueId()); + } + } else { // chat modifications are turned on + if(off) { // asking to be turned off + arg0.sendMessage(AnimalRP.mm.deserialize("Chat modifications disabled!")); + AnimalRP.isChatModOff.put(player.getUniqueId(), true); + } else { // asking to be turned on + arg0.sendMessage(AnimalRP.mm.deserialize("Chat modifications for you are already enabled!!")); + } + } return true; } diff --git a/src/main/java/lv/pi/animalrp/commands/TfCommand.java b/src/main/java/lv/pi/animalrp/commands/TfCommand.java index c4bf424..c090953 100644 --- a/src/main/java/lv/pi/animalrp/commands/TfCommand.java +++ b/src/main/java/lv/pi/animalrp/commands/TfCommand.java @@ -39,6 +39,8 @@ public class TfCommand implements CommandExecutor { Animal previous = AnimalRP.users.get(player.getUniqueId()); player.sendMessage(AnimalRP.mm.deserialize("You start splitting apart, dropping your " + previous.name+"-like appearence..")); AnimalRP.users.remove(player.getUniqueId()); + if(AnimalRP.isChatModOff.get(player.getUniqueId())) + AnimalRP.isChatModOff.remove(player.getUniqueId()); return true; } else { options(player); return true; diff --git a/src/main/java/lv/pi/animalrp/listeners/PlayerChat.java b/src/main/java/lv/pi/animalrp/listeners/PlayerChat.java index ff68e3b..0ffae2a 100644 --- a/src/main/java/lv/pi/animalrp/listeners/PlayerChat.java +++ b/src/main/java/lv/pi/animalrp/listeners/PlayerChat.java @@ -44,7 +44,9 @@ public class PlayerChat implements Listener { public void onPlayerChat(final AsyncChatEvent event) { Animal animal = AnimalRP.users.get(event.getPlayer().getUniqueId()); - if(animal != null) { + if(animal != null) { + if(AnimalRP.isChatModOff.get(event.getPlayer().getUniqueId())) return; + if(random.nextDouble() < 0.08) { event.getPlayer().getWorld().playSound(event.getPlayer().getLocation(), animal.moodSounds.get(Mood.HAPPY), 10F, 1); }