Skip to content

Commit

Permalink
Merge pull request #266 from Dans-Plugins/fixes-for-1.10
Browse files Browse the repository at this point in the history
Fixed MF & Mailboxes integration errors.
  • Loading branch information
dmccoystephenson authored May 21, 2022
2 parents bb2dad9 + 7d88c8f commit ec6614e
Show file tree
Hide file tree
Showing 13 changed files with 212 additions and 76 deletions.
25 changes: 25 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.234.0/containers/java-8/.devcontainer/base.Dockerfile

# [Choice] Debian OS version (use bullseye on local arm64/Apple Silicon): buster, bullseye
ARG VARIANT="bullseye"
FROM mcr.microsoft.com/vscode/devcontainers/java:0-8-${VARIANT}

# [Option] Install Maven
ARG INSTALL_MAVEN="false"
ARG MAVEN_VERSION=""
# [Option] Install Gradle
ARG INSTALL_GRADLE="false"
ARG GRADLE_VERSION=""
RUN if [ "${INSTALL_MAVEN}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/sdkman/bin/sdkman-init.sh && sdk install maven \"${MAVEN_VERSION}\""; fi \
&& if [ "${INSTALL_GRADLE}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/sdkman/bin/sdkman-init.sh && sdk install gradle \"${GRADLE_VERSION}\""; fi

# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
ARG NODE_VERSION="lts/*"
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi

# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>

# [Optional] Uncomment this line to install global node packages.
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1
42 changes: 42 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.234.0/containers/java-8
{
"name": "Java 8",
"build": {
"dockerfile": "Dockerfile",
"args": {
// Use the VARIANT arg to pick a Debian OS version: buster, bullseye
// Use bullseye when running on local arm64/Apple Silicon.
"VARIANT": "buster",
// Options
"INSTALL_MAVEN": "true",
"INSTALL_GRADLE": "false",
"NODE_VERSION": "none"
}
},

// Set *default* container specific settings.json values on container create.
"settings": {
"java.home": "/docker-java-home",
"java.import.gradle.java.home": "/usr/local/sdkman/candidates/java/current",
"java.configuration.runtimes": [{
"default": true,
"name": "JavaSE-1.8",
"path": "/usr/local/sdkman/candidates/java/current"
}]
},

// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"vscjava.vscode-java-pack"
],

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "java -version",

// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
}
21 changes: 12 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>KingdomProgrammers</groupId>
<artifactId>Medieval-Roleplay-Engine</artifactId>
<version>v1.10-beta-1</version>
<version>1.10</version>
<packaging>jar</packaging>

<name>Medieval Roleplay Engine</name>
Expand Down Expand Up @@ -48,19 +48,18 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>dansplugins</groupId>
<groupId>com.github.Dans-Plugins</groupId>
<artifactId>Medieval-Factions</artifactId>
<version>v4.3</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/Medieval-Factions-v4.3.jar</systemPath>
<version>4.6.4.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>dansplugins</groupId>
<groupId>com.github.Dans-Plugins</groupId>
<artifactId>Mailboxes</artifactId>
<version>v1.1-alpha-1</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/Mailboxes-v1.1-alpha-1.jar</systemPath>
<version>v1.1</version>
<scope>compile</scope>
</dependency>

</dependencies>

<build>
Expand Down Expand Up @@ -112,5 +111,9 @@
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package dansplugins.exceptions;

public class MailboxesNotFoundException extends Exception {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package dansplugins.exceptions;

public class MedievalFactionsNotFoundException extends Exception {

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ public class MedievalRoleplayEngine extends JavaPlugin {

private static MedievalRoleplayEngine instance;

// version
private String version = "v1.10-beta-1";
private final String pluginVersion = "v" + getDescription().getVersion();

public static MedievalRoleplayEngine getInstance() {
return instance;
Expand Down Expand Up @@ -76,7 +75,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
}

public String getVersion() {
return version;
return pluginVersion;
}

public boolean isDebugEnabled() {
Expand Down
23 changes: 14 additions & 9 deletions src/main/java/dansplugins/rpsystem/Messenger.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dansplugins.rpsystem;

import dansplugins.exceptions.MedievalFactionsNotFoundException;
import dansplugins.factionsystem.externalapi.MF_Faction;
import dansplugins.rpsystem.data.EphemeralData;
import dansplugins.rpsystem.integrators.MedievalFactionsIntegrator;
Expand Down Expand Up @@ -113,16 +114,20 @@ public void sendCardInfoToPlayer(CharacterCard card, Player player) {
player.sendMessage(ColorChecker.getInstance().getNeutralAlertColor() + "Age: " + card.getAge());
player.sendMessage(ColorChecker.getInstance().getNeutralAlertColor() + "Gender: " + card.getGender());
player.sendMessage(ColorChecker.getInstance().getNeutralAlertColor() + "Religion: " + card.getReligion());
if (MedievalFactionsIntegrator.getInstance().isMedievalFactionsPresent()) {
MF_Faction faction = MedievalFactionsIntegrator.getInstance().getAPI().getFaction(card.getPlayerUUID());
int power = MedievalFactionsIntegrator.getInstance().getAPI().getPower(card.getPlayerUUID());
if (faction != null) {
player.sendMessage(ColorChecker.getInstance().getNeutralAlertColor() + "Faction: " + faction.getName());
}
else {
player.sendMessage(ColorChecker.getInstance().getNeutralAlertColor() + "Faction: N/A");
try {
if (MedievalFactionsIntegrator.getInstance().isMedievalFactionsPresent()) {
MF_Faction faction = MedievalFactionsIntegrator.getInstance().getAPI().getFaction(card.getPlayerUUID());
double power = MedievalFactionsIntegrator.getInstance().getAPI().getPower(card.getPlayerUUID());
if (faction != null) {
player.sendMessage(ColorChecker.getInstance().getNeutralAlertColor() + "Faction: " + faction.getName());
}
else {
player.sendMessage(ColorChecker.getInstance().getNeutralAlertColor() + "Faction: N/A");
}
player.sendMessage(ColorChecker.getInstance().getNeutralAlertColor() + "Power: " + power);
}
player.sendMessage(ColorChecker.getInstance().getNeutralAlertColor() + "Power: " + power);
} catch (NullPointerException | MedievalFactionsNotFoundException e) {
// fail silently
}
}
}
32 changes: 19 additions & 13 deletions src/main/java/dansplugins/rpsystem/commands/BirdCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dansplugins.rpsystem.commands;

import dansplugins.exceptions.MailboxesNotFoundException;
import dansplugins.rpsystem.MedievalRoleplayEngine;
import dansplugins.rpsystem.Messenger;
import dansplugins.rpsystem.data.EphemeralData;
Expand Down Expand Up @@ -79,21 +80,26 @@ public void run() {
}

boolean attemptToSendMessageToPlayersMailbox(String targetName, Player sender, String message) {
if (MailboxesIntegrator.getInstance().isMailboxesPresent()) {
UUID targetUUID = UUIDChecker.getInstance().findUUIDBasedOnPlayerName(targetName);
if (targetUUID != null) {
String messageToSend = "While you were offline, a bird dropped off a message for you. It was sent by " + sender.getName() + ". It reads:\n\n'" + message + "'";

boolean success = MailboxesIntegrator.getInstance().getAPI().sendPluginMessageToPlayer(MedievalRoleplayEngine.getInstance().getName(), targetUUID, messageToSend);
if (success) {
sender.sendMessage(ColorChecker.getInstance().getPositiveAlertColor() + "The bird flies off with your message. Since this player is offline, this message will go to their mailbox.");
return true;
}
else {
sender.sendMessage(ColorChecker.getInstance().getNegativeAlertColor() + "Your bird wasn't able to find this player's mailbox.");
return false;
try {
if (MailboxesIntegrator.getInstance().isMailboxesPresent()) {
UUID targetUUID = UUIDChecker.getInstance().findUUIDBasedOnPlayerName(targetName);
if (targetUUID != null) {
String messageToSend = "While you were offline, a bird dropped off a message for you. It was sent by " + sender.getName() + ". It reads:\n\n'" + message + "'";

boolean success = MailboxesIntegrator.getInstance().getAPI().sendPluginMessageToPlayer(MedievalRoleplayEngine.getInstance().getName(), targetUUID, messageToSend);
if (success) {
sender.sendMessage(ColorChecker.getInstance().getPositiveAlertColor() + "The bird flies off with your message. Since this player is offline, this message will go to their mailbox.");
return true;
}
else {
sender.sendMessage(ColorChecker.getInstance().getNegativeAlertColor() + "Your bird wasn't able to find this player's mailbox.");
return false;
}
}
}
} catch (MailboxesNotFoundException e) {
sender.sendMessage(ColorChecker.getInstance().getNegativeAlertColor() + "Your bird wasn't able to find this player's mailbox.");
return false;
}
return false;
}
Expand Down
25 changes: 17 additions & 8 deletions src/main/java/dansplugins/rpsystem/commands/LocalChatCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dansplugins.rpsystem.commands;

import dansplugins.rpsystem.integrators.MedievalFactionsIntegrator;
import dansplugins.exceptions.MedievalFactionsNotFoundException;
import dansplugins.rpsystem.data.EphemeralData;
import dansplugins.rpsystem.utils.ColorChecker;
import org.bukkit.command.CommandSender;
Expand Down Expand Up @@ -41,18 +42,26 @@ public boolean startChattingInLocalChat(CommandSender sender, String[] args) {
private void addPlayerToLocalChat(Player player) {
if (!EphemeralData.getInstance().getPlayersSpeakingInLocalChat().contains(player.getUniqueId())) {
EphemeralData.getInstance().getPlayersSpeakingInLocalChat().add(player.getUniqueId());
if (MedievalFactionsIntegrator.getInstance().isMedievalFactionsPresent() && MedievalFactionsIntegrator.getInstance().getAPI().isPlayerInFactionChat(player)) {
player.sendMessage(ColorChecker.getInstance().getPositiveAlertColor() + "You are now in local chat, but you won't send messages to local chat until you leave faction chat.");
}
else {
try {
if (MedievalFactionsIntegrator.getInstance().isMedievalFactionsPresent() && MedievalFactionsIntegrator.getInstance().getAPI().isPlayerInFactionChat(player)) {
player.sendMessage(ColorChecker.getInstance().getPositiveAlertColor() + "You are now in local chat, but you won't send messages to local chat until you leave faction chat.");
}
else {
player.sendMessage(ColorChecker.getInstance().getPositiveAlertColor() + "You are now talking in local chat.");
}
} catch (MedievalFactionsNotFoundException e) {
player.sendMessage(ColorChecker.getInstance().getPositiveAlertColor() + "You are now talking in local chat.");
}
}
else {
if (MedievalFactionsIntegrator.getInstance().isMedievalFactionsPresent() && MedievalFactionsIntegrator.getInstance().getAPI().isPlayerInFactionChat(player)) {
player.sendMessage(ColorChecker.getInstance().getPositiveAlertColor() + "You're already now in local chat, but you won't send messages to local chat until you leave faction chat.");
}
else {
try {
if (MedievalFactionsIntegrator.getInstance().isMedievalFactionsPresent() && MedievalFactionsIntegrator.getInstance().getAPI().isPlayerInFactionChat(player)) {
player.sendMessage(ColorChecker.getInstance().getPositiveAlertColor() + "You're already now in local chat, but you won't send messages to local chat until you leave faction chat.");
}
else {
player.sendMessage(ColorChecker.getInstance().getPositiveAlertColor() + "You're already now in local chat.");
}
} catch (MedievalFactionsNotFoundException e) {
player.sendMessage(ColorChecker.getInstance().getPositiveAlertColor() + "You're already now in local chat.");
}
}
Expand Down
53 changes: 36 additions & 17 deletions src/main/java/dansplugins/rpsystem/eventhandlers/ChatHandler.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dansplugins.rpsystem.eventhandlers;

import dansplugins.exceptions.MedievalFactionsNotFoundException;
import dansplugins.factionsystem.externalapi.MF_Faction;
import dansplugins.rpsystem.integrators.MedievalFactionsIntegrator;
import dansplugins.rpsystem.MedievalRoleplayEngine;
Expand All @@ -8,6 +9,10 @@
import dansplugins.rpsystem.data.PersistentData;
import dansplugins.rpsystem.managers.ConfigManager;
import dansplugins.rpsystem.utils.ColorChecker;
import dansplugins.rpsystem.utils.Logger;

import java.util.IllegalFormatException;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
Expand All @@ -25,10 +30,14 @@ public void handle(AsyncPlayerChatEvent event) {

int localChatRadius = MedievalRoleplayEngine.getInstance().getConfig().getInt("localChatRadius");

if (MedievalFactionsIntegrator.getInstance().isMedievalFactionsPresent()) {
if (MedievalFactionsIntegrator.getInstance().getAPI().isPlayerInFactionChat(event.getPlayer())) {
return;
try {
if (MedievalFactionsIntegrator.getInstance().isMedievalFactionsPresent()) {
if (MedievalFactionsIntegrator.getInstance().getAPI().isPlayerInFactionChat(event.getPlayer())) {
return;
}
}
} catch (MedievalFactionsNotFoundException e) {
// fail silently
}

String localChatColorString = MedievalRoleplayEngine.getInstance().getConfig().getString("localChatColor");
Expand Down Expand Up @@ -88,33 +97,43 @@ public void handle(AsyncPlayerChatEvent event) {

// we are good to send the message

if (MedievalFactionsIntegrator.getInstance().isMedievalFactionsPresent()
&& MedievalFactionsIntegrator.getInstance().getAPI().isPrefixesFeatureEnabled()
&& MedievalFactionsIntegrator.getInstance().getAPI().getFaction(event.getPlayer()) != null) {
try {
if (MedievalFactionsIntegrator.getInstance().isMedievalFactionsPresent()
&& MedievalFactionsIntegrator.getInstance().getAPI().isPrefixesFeatureEnabled()
&& MedievalFactionsIntegrator.getInstance().getAPI().getFaction(event.getPlayer()) != null) {

if (MedievalRoleplayEngine.getInstance().isDebugEnabled()) { System.out.println("Preparing message with prefix from Medieval Factions"); }
if (MedievalRoleplayEngine.getInstance().isDebugEnabled()) { System.out.println("Preparing message with prefix from Medieval Factions"); }

MF_Faction playersFaction = MedievalFactionsIntegrator.getInstance().getAPI().getFaction(event.getPlayer());
MF_Faction playersFaction = MedievalFactionsIntegrator.getInstance().getAPI().getFaction(event.getPlayer());

// prefix format
String prefix = playersFaction.getPrefix();
String prefixColor = (String) playersFaction.getFlag("prefixColor");
event.setFormat(ColorChecker.getInstance().getColorByName(prefixColor) + "" + "[" + prefix + "]" + "" + ChatColor.WHITE + "" + " <%s> %s");
// prefix format
String prefix = playersFaction.getPrefix();
String prefixColor = (String) playersFaction.getFlag("prefixColor");
event.setFormat(ColorChecker.getInstance().getColorByName(prefixColor) + "" + "[" + prefix + "]" + "" + ChatColor.WHITE + "" + " <%s> %s");

// send message
onlinePlayer.sendMessage(ColorChecker.getInstance().getColorByName(prefixColor) + "" + "[" + prefix + "] " + ChatColor.WHITE + "<" + event.getPlayer().getName() + "> " + ChatColor.WHITE + event.getMessage());
// send message
onlinePlayer.sendMessage(ColorChecker.getInstance().getColorByName(prefixColor) + "" + "[" + prefix + "] " + ChatColor.WHITE + "<" + event.getPlayer().getName() + "> " + ChatColor.WHITE + event.getMessage());

}
else {
}
else {

if (MedievalRoleplayEngine.getInstance().isDebugEnabled()) { System.out.println("Preparing message with regular format"); }

// regular format
event.setFormat(ChatColor.WHITE + "" + " <%s> %s");

// send message
onlinePlayer.sendMessage(ChatColor.WHITE + "<" + event.getPlayer().getName() + "> " + event.getMessage());

}
} catch (IllegalFormatException | NullPointerException | MedievalFactionsNotFoundException e) {
if (MedievalRoleplayEngine.getInstance().isDebugEnabled()) { System.out.println("Preparing message with regular format"); }

// regular format
event.setFormat(ChatColor.WHITE + "" + " <%s> %s");

// send message
onlinePlayer.sendMessage(ChatColor.WHITE + "<" + event.getPlayer().getName() + "> " + event.getMessage());

}

}
Expand Down
Loading

0 comments on commit ec6614e

Please sign in to comment.