write chat modification disabling

This commit is contained in:
yourfriendoss 2023-04-18 17:01:50 +03:00
parent 94ece84706
commit 2cd17709d0
4 changed files with 50 additions and 9 deletions

View file

@ -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<String,JsonElement> 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();

View file

@ -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("<red>Chat modifications for you are already disabled!"));
} else { // asking to be turned on
arg0.sendMessage(AnimalRP.mm.deserialize("<green>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("<red>Chat modifications disabled!"));
AnimalRP.isChatModOff.put(player.getUniqueId(), true);
} else { // asking to be turned on
arg0.sendMessage(AnimalRP.mm.deserialize("<green>Chat modifications for you are already enabled!!"));
}
}
return true;
}

View file

@ -39,6 +39,8 @@ public class TfCommand implements CommandExecutor {
Animal previous = AnimalRP.users.get(player.getUniqueId());
player.sendMessage(AnimalRP.mm.deserialize("<green>You start splitting apart, dropping your <blue>" + previous.name+"-like<green> appearence.."));
AnimalRP.users.remove(player.getUniqueId());
if(AnimalRP.isChatModOff.get(player.getUniqueId()))
AnimalRP.isChatModOff.remove(player.getUniqueId());
return true;
} else {
options(player); return true;

View file

@ -45,6 +45,8 @@ public class PlayerChat implements Listener {
Animal animal = AnimalRP.users.get(event.getPlayer().getUniqueId());
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);
}