Skip to content

Commit

Permalink
Refactoring of marriage color and magic-heart related methods
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgH93 committed Aug 9, 2020
1 parent 6c8327c commit a1d1fd5
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@

package at.pcgamingfreaks.MarriageMaster.API;

import at.pcgamingfreaks.Message.MessageColor;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Date;

@SuppressWarnings("unused")
public interface Marriage <MARRIAGE_PLAYER extends MarriagePlayer, COMMAND_SENDER, HOME extends Home>
{
/**
Expand Down Expand Up @@ -172,4 +173,21 @@ public interface Marriage <MARRIAGE_PLAYER extends MarriagePlayer, COMMAND_SENDE
* Prefix is limited to 20 chars, everything beyond will be ignored.
*/
void setMarriageChatMessagePrefix(@NotNull String prefix);

/**
* Sets the color of the marriage, since there are only 16 colors available in Minecraft it is possible that two or more marriages have the same color.
*
* @param color the color that should be set for the marriage.
*/
void setColor(final @Nullable MessageColor color);

/**
* Gets the color of the marriage, since there are only 16 colors available in Minecraft it is possible that two or more marriages have the same color.
* The default color is random. But can be changed.
*
* @return The color of the marriage.
*/
@NotNull MessageColor getColor();

@NotNull String getMagicHeart();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@

package at.pcgamingfreaks.MarriageMaster.Bukkit.API;

import at.pcgamingfreaks.Message.MessageColor;

import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;

@SuppressWarnings("unused")
public interface Marriage extends at.pcgamingfreaks.MarriageMaster.API.Marriage<MarriagePlayer, CommandSender, Home>
{
/**
Expand Down Expand Up @@ -54,6 +55,7 @@ public interface Marriage extends at.pcgamingfreaks.MarriageMaster.API.Marriage<
* The default color is random. But can be changed.
*
* @return The color of the marriage.
* @deprecated Replaced by {@link Marriage#getColor()}
*/
@Deprecated
@NotNull ChatColor getMarriageColor();
Expand All @@ -62,6 +64,7 @@ public interface Marriage extends at.pcgamingfreaks.MarriageMaster.API.Marriage<
* Sets the color of the marriage, since there are only 16 colors available in Minecraft it is possible that two or more marriages have the same color.
*
* @param color the color that should be set for the marriage.
* @deprecated Replaced by {@link Marriage#setColor(MessageColor)}
*/
@Deprecated
void setMarriageColor(@NotNull ChatColor color);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@

import net.md_5.bungee.api.CommandSender;

@SuppressWarnings("unused")
public interface Marriage extends at.pcgamingfreaks.MarriageMaster.API.Marriage<MarriagePlayer, CommandSender, Home> {}
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ private void doChat(final MarriagePlayer sender, String msg)
Bukkit.getPluginManager().callEvent(marryChatEvent);
if(marryChatEvent.isCancelled()) return;
msg = marryChatEvent.getMessage();
magicHeart = receivers.get(0).getMarriageColor() + MagicValues.SYMBOL_HEART + MessageColor.RESET;
magicHeart = receivers.get(0).getMagicHeart();
}
else
{
Expand All @@ -321,7 +321,7 @@ private void doChat(final MarriagePlayer sender, String msg)
{
//noinspection ConstantConditions
receiver = receivers.get(0).getPartner(sender).getPlayerOnline();
magicHeart = receivers.get(0).getMarriageColor() + MagicValues.SYMBOL_HEART + MessageColor.RESET;
magicHeart = receivers.get(0).getMagicHeart();
}
}
//endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void execute(@NotNull CommandSender sender, @NotNull String mainCommandAl
{
Marriage couple = couplesIterator.next();
messageListFormat.send(sender, couple.getPartner1().getName(), couple.getPartner2().getName(), couple.getPartner1().getDisplayName(), couple.getPartner2().getDisplayName(),
couple.getSurnameString(), couple.getMarriageColor() + MagicValues.SYMBOL_HEART + MessageColor.RESET);
couple.getSurnameString(), couple.getMagicHeart());
}
if(useFooter)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import at.pcgamingfreaks.MarriageMaster.Permissions;
import at.pcgamingfreaks.Message.MessageColor;

import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -88,7 +87,7 @@ else if(!color.isColor())
else
{
//noinspection ConstantConditions
marriage.setMarriageColor(ChatColor.getByChar(color.getCode()));
marriage.setColor(color);
messageColorSet.send(sender);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,14 @@ public boolean inRangeSquared(double maxDistanceSquared)
}

@Override
@Deprecated
public @NotNull ChatColor getMarriageColor()
{
return ChatColor.getByChar(getColor().getCode());
}

@Override
@Deprecated
public void setMarriageColor(@NotNull ChatColor color)
{
setColor(MessageColor.getFromCode(color.getChar()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,5 @@

public interface IMarriageAndPartnerFormatter
{
String HEART = MagicValues.SYMBOL_HEART + MessageColor.WHITE, HEART_RED = MessageColor.RED + HEART;

@NotNull String format(final @NotNull Marriage marriage, final @NotNull MarriagePlayer partner);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import at.pcgamingfreaks.MarriageMaster.Bukkit.API.Marriage;
import at.pcgamingfreaks.MarriageMaster.Bukkit.API.MarriagePlayer;
import at.pcgamingfreaks.MarriageMaster.MagicValues;

import org.jetbrains.annotations.NotNull;

Expand All @@ -34,6 +35,6 @@ public PlaceholderFormatter(final @NotNull String format)
@Override
public @NotNull String format(final @NotNull Marriage marriage, final @NotNull MarriagePlayer partner)
{
return String.format(format, marriage.getSurnameString(), partner.getName(), partner.getDisplayName(), marriage.getMarriageColor() + HEART);
return String.format(format, marriage.getSurnameString(), partner.getName(), partner.getDisplayName(), marriage.getMarriageColor() + MagicValues.HEART_AND_RESET);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import at.pcgamingfreaks.MarriageMaster.Bukkit.API.Marriage;
import at.pcgamingfreaks.MarriageMaster.Bukkit.API.MarriagePlayer;
import at.pcgamingfreaks.MarriageMaster.Bukkit.MarriageMaster;
import at.pcgamingfreaks.MarriageMaster.MagicValues;

import org.apache.commons.lang.StringUtils;
import org.jetbrains.annotations.NotNull;
Expand All @@ -36,7 +37,7 @@ public PrefixSuffixFormatterImpl(MarriageMaster plugin)

public static IMarriageAndPartnerFormatter produceFormatter(@NotNull String format)
{
format = format.replaceAll("\\{StatusHeart}", at.pcgamingfreaks.MarriageMaster.Bukkit.Formatter.IMarriageAndPartnerFormatter.HEART_RED);
format = format.replaceAll("\\{StatusHeart}", MagicValues.RED_HEART);
if(StringUtils.indexOfAny(format, new String[]{ "{Surname}", "{PartnerName}", "{PartnerDisplayName}", "{MagicHeart}" }) != -1)
{
return new PlaceholderFormatter(format.replaceAll("\\{Surname}", "%1\\$s").replaceAll("\\{PartnerName}", "%2\\$s").replaceAll("\\{PartnerDisplayName}", "%3\\$s").replaceAll("\\{MagicHeart}", "%4\\$s"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ public MagicHeart(MarriageMaster plugin)
protected @Nullable String replaceMarried(MarriagePlayer player)
{
//noinspection ConstantConditions
return player.getMarriageData().getMarriageColor() + valueMarried;
return player.getMarriageData().getColor() + valueMarried;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import at.pcgamingfreaks.MarriageMaster.API.Home;
import at.pcgamingfreaks.MarriageMaster.API.Marriage;
import at.pcgamingfreaks.MarriageMaster.API.MarriagePlayer;
import at.pcgamingfreaks.MarriageMaster.MagicValues;
import at.pcgamingfreaks.Message.MessageColor;

import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -170,19 +171,29 @@ public void setPVPEnabled(boolean pvpEnabled)
BaseDatabase.getInstance().updatePvPState(this);
}

public void setColor(final @Nullable MessageColor color)
@Override
public void setColor(@Nullable MessageColor color)
{
this.color = color;
//noinspection ObjectEquality
if(color == null || color == MessageColor.RESET) this.color = null; // == is fine here! There is only one instance that equals reset
else this.color = color.isRGB() ? color.getFallbackColor() : color;
BaseDatabase.getInstance().updateMarriageColor(this);
}

@Override
public @NotNull String getMagicHeart()
{
return getColor() + MagicValues.HEART_AND_RESET;
}

public void updateColor(final @Nullable MessageColor color)
{
this.color = color;
}

@Override
public @NotNull MessageColor getColor()
{
{ //TODO the default should be calculated only once
if(color != null) return color;
return MessageColor.values()[hash & 0x0F];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ public class MagicValues
{
public static final int LANG_VERSION = 101, LANG_PRE_V2_VERSIONS = 90;
public static final int CONFIG_VERSION = 100, BUNGEE_CONFIG_VERSION = 101, CONFIG_PRE_V2_VERSIONS = 90;
public static final String SYMBOL_HEART = "\u2764", SYMBOL_SMALL_HEART = "\u2665", RED_HEART = MessageColor.RED + MagicValues.SYMBOL_HEART + MessageColor.RESET;
public static final String SYMBOL_HEART = "\u2764", SYMBOL_SMALL_HEART = "\u2665", HEART_AND_RESET = SYMBOL_HEART + MessageColor.WHITE, RED_HEART = MessageColor.RED + HEART_AND_RESET;
public static final String MIN_PCGF_PLUGIN_LIB_VERSION = "1.0.26-SNAPSHOT";
}

0 comments on commit a1d1fd5

Please sign in to comment.