write chat modification disabling
This commit is contained in:
parent
94ece84706
commit
2cd17709d0
|
@ -102,6 +102,18 @@ public class AnimalRP extends JavaPlugin {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
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
|
@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()) {
|
if(folder.resolve("cooldowns.json").toFile().exists()) {
|
||||||
try {
|
try {
|
||||||
JsonObject z = JsonParser.parseString(Files.readString(folder.resolve("cooldowns.json"))).getAsJsonObject();
|
JsonObject z = JsonParser.parseString(Files.readString(folder.resolve("cooldowns.json"))).getAsJsonObject();
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package lv.pi.animalrp.commands;
|
package lv.pi.animalrp.commands;
|
||||||
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
@ -10,7 +8,6 @@ import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import lv.pi.animalrp.AnimalRP;
|
import lv.pi.animalrp.AnimalRP;
|
||||||
|
|
||||||
// TODO: Unfinished
|
|
||||||
public class ChatModCommand implements CommandExecutor {
|
public class ChatModCommand implements CommandExecutor {
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(@NotNull CommandSender arg0, @NotNull Command arg1, @NotNull String arg2, @NotNull String[] arg3) {
|
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;
|
Player player = (Player)arg0;
|
||||||
|
|
||||||
if(arg3.length == 0) {
|
|
||||||
options(player);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean off = false;
|
boolean off = false;
|
||||||
if(arg2.endsWith("off")) {
|
if(arg2.endsWith("off")) {
|
||||||
off = true;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,8 @@ public class TfCommand implements CommandExecutor {
|
||||||
Animal previous = AnimalRP.users.get(player.getUniqueId());
|
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.."));
|
player.sendMessage(AnimalRP.mm.deserialize("<green>You start splitting apart, dropping your <blue>" + previous.name+"-like<green> appearence.."));
|
||||||
AnimalRP.users.remove(player.getUniqueId());
|
AnimalRP.users.remove(player.getUniqueId());
|
||||||
|
if(AnimalRP.isChatModOff.get(player.getUniqueId()))
|
||||||
|
AnimalRP.isChatModOff.remove(player.getUniqueId());
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
options(player); return true;
|
options(player); return true;
|
||||||
|
|
|
@ -45,6 +45,8 @@ public class PlayerChat implements Listener {
|
||||||
Animal animal = AnimalRP.users.get(event.getPlayer().getUniqueId());
|
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) {
|
if(random.nextDouble() < 0.08) {
|
||||||
event.getPlayer().getWorld().playSound(event.getPlayer().getLocation(), animal.moodSounds.get(Mood.HAPPY), 10F, 1);
|
event.getPlayer().getWorld().playSound(event.getPlayer().getLocation(), animal.moodSounds.get(Mood.HAPPY), 10F, 1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue