Skip to content

Commit

Permalink
Bug Fixes 3
Browse files Browse the repository at this point in the history
- Fix a bug where messages are not sent. - Fix a bug where the config files are not saved or reloaded.
- Add a new message to send to the person who failed to accept a slap for another person.
  • Loading branch information
aappleton8 committed Sep 8, 2018
1 parent be313f0 commit a96f90b
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 66 deletions.
Binary file removed Jar/PlayerSlap_vDevelopment-0.0.0.3_1.7-1.12.jar
Binary file not shown.
Binary file added Jar/PlayerSlap_vDevelopment-0.0.0.4_1.7-1.12.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion PlayerSlap/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: PlayerSlap
main: me.PlayerSlap.MainClasses.PlayerSlapMainClass
version: Development_0.0.0.3
version: Development_0.0.0.4
description: A plugin to slap players
author: aappleton3
database: false
Expand Down
21 changes: 11 additions & 10 deletions PlayerSlap/src/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ slapself: true
slapdefault: '1'
incrementonslapall: true
messages:
accept: $Default
releasebroadcast: $Default
releasepersonal: $Default
noreleasepersonal: $Default
accept: __Default
releasebroadcast: __Default
releasepersonal: __Default
noreleasepersonal: __Default
noreleasesender: __Default
slaptypes:
'1':
health: 3
Expand All @@ -16,9 +17,9 @@ slaptypes:
lightning: true
smoke: 30
messages:
slapbroadcast: $Giver slapped $Slapped.
slappersonal: $Giver slapped you.
death: $Default
slapbroadcast: __Giver slapped __Slapped.
slappersonal: __Giver slapped you.
death: __Default
mobs:
ZOMBIE: 5
SKELETON: 1
Expand All @@ -31,9 +32,9 @@ slaptypes:
lightning: true
smoke: 50
messages:
broadcast: $Default
personal: $Default
death: $Default
broadcast: __Default
personal: __Default
death: __Default
mobs:
BLAZE: 10
GIANT: 1
Expand Down
11 changes: 6 additions & 5 deletions PlayerSlap/src/configHeader.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
# slapdefault (String): - The default slap type
# incrementonslapall (boolean): - Increment the recorded slap times for each player when all players are slapped
# messages (Section): - Messages sent when someone is slapped
# accept (string): - The message broadcast when a player accepts a slap ($Giver is unavailable; $Type is unavailable [explained further on])
# releasebroadcast (string): - The message broadcast when a player is released from a permanent slap ($Type is unavailable)
# releasepersonal (string): - The message sent to the slapped player when a player is released from a permanent slap ($Type is unavailable)
# noreleasepersonal (string): - The message sent to the slapped player when it tries to accept a permanent slap it has not been released from ($Giver is unavailable; $Type is unavailable)
# accept (string): - The message broadcast when a player accepts a slap (__Giver is unavailable; __Type is unavailable [explained further on])
# releasebroadcast (string): - The message broadcast when a player is released from a permanent slap (__Type is unavailable)
# releasepersonal (string): - The message sent to the slapped player when a player is released from a permanent slap (__Type is unavailable)
# noreleasepersonal (string): - The message sent to the slapped player when it tries to accept a permanent slap it has not been released from (__Type is unavailable)
# noreleasesender (string): - The message sent to the command sender when it tries to accept a permanent slap of a player who has not been released from it (__Type is unavailable)
# slaptypes (Section): - The definition of the slap types
# '1' (Section): - The name of a slap type
# health (integer): - The health removed when a player is slapped
Expand All @@ -18,7 +19,7 @@
# mustaccept (boolean): - Whether the player must accept the slap before being able to move again or not
# lightning (boolean): - Whether the player should be struck by lightning or not
# smoke (integer): - The radius of the smoke effect (0 for no smoke)
# messages (Section): - Slap-specific messages sent when someone is slapped | $Giver becomes the slap giver or the release giver; $Slapped becomes the person slapped; $Default becomes the default messages; $None becomes nothing; $Unknown becomes unknown; $Type becomes the slap type; $Permanent becomes permanent for a permanent slap and nothing otherwise
# messages (Section): - Slap-specific messages sent when someone is slapped | __Giver becomes the slap giver or the release giver; __Slapped becomes the person slapped; __Default becomes the default messages; __None becomes nothing; __Unknown becomes unknown; __Type becomes the slap type; __Permanent becomes permanent for a permanent slap and nothing otherwise
# slapbroadcast (string): - The message broadcast to the server
# slappersonal (string): - The message sent to the slapped player
# death (string): - The additional message broadcast if the player is slapped to death
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,13 @@ private String getDefaultType() {
String formatMessages(String message, String defaultMessage, String giver, String receiver, String type, Boolean permanent) {
if (message != null) {
String permanentString = permanent ? "permanent " : "";
return message.replaceAll("\\$Default", defaultMessage)
.replaceAll("\\$Giver", giver)
.replaceAll("\\$Slapped", receiver)
.replaceAll("\\$None", "")
.replaceAll("\\$Unknwon", plugin.ms.unknownValue)
.replaceAll("\\$Type", type)
.replaceAll("\\$Permanent", permanentString);
return message.replaceAll("__Default", defaultMessage)
.replaceAll("__Giver", giver)
.replaceAll("__Slapped", receiver)
.replaceAll("__None", "")
.replaceAll("__Unknown", plugin.ms.unknownValue)
.replaceAll("__Type", type)
.replaceAll("__Permanent", permanentString);
}
else {
return "";
Expand Down Expand Up @@ -284,7 +284,11 @@ void sendSlap(CommandSender s, Player player, String type, int worth) {
int damage = plugin.yc.configuration.getInt("slaptypes." + type + ".health");
if (damage > 0) {
double health = player.getHealth();
player.setHealth(health - damage);
double newHealth = health - damage;
if (newHealth < 0) {
newHealth = 0;
}
player.setHealth(newHealth);
if ((player.getHealth() <= 0) && (deathSlapMessage != "")) {
Bukkit.broadcast(ChatColor.RED + deathSlapMessage, "playerslap.see.slap");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ else if (args[0].equalsIgnoreCase("config")) {
if (args.length == 2) {
if (args[1].equalsIgnoreCase("save")) {
if (s.hasPermission("playerslap.config.save")) {
YamlFiles.fullySaveAll();
plugin.yc.fullSave();
plugin.yd.fullSave();
Bukkit.broadcast(ChatColor.GREEN + plugin.formattedPluginName + "Config files saved. ", "plugin.see.config");
}
else {
Expand All @@ -104,7 +105,8 @@ else if (args[0].equalsIgnoreCase("config")) {
}
else if (args[1].equalsIgnoreCase("reload")) {
if (s.hasPermission("playerslap.config.reload")) {
YamlFiles.fullyReloadAll();
plugin.yc.fullReload();
plugin.yd.fullReload();
Bukkit.broadcast(ChatColor.GREEN + plugin.formattedPluginName + "Config files reloaded. ", "plugin.see.config");
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,22 @@ else if (args.length == 1) {
if (plugin.needAcceptPlayers.containsKey(uid)) {
if (plugin.needAcceptPlayers.get(uid).getValue() == true) {
String personalNoReleaseMessage = plugin.ms.personalNoReleaseMessage;
if (plugin.yc.configuration.contains("messages.noreleasepersonal")) {
personalNoReleaseMessage = plugin.yc.configuration.getString("messages.noreleasepersonal");
String senderNoReleaseMessage = plugin.ms.senderNoReleaseMessage;
if (plugin.yc.configuration.contains("messages")) {
if (plugin.yc.configuration.contains("messages.noreleasepersonal")) {
personalNoReleaseMessage = plugin.yc.configuration.getString("messages.noreleasepersonal");
}
if (plugin.yc.configuration.contains("messages.noreleasesender")) {
senderNoReleaseMessage = plugin.yc.configuration.getString("messages.noreleasesender");
}
}
personalNoReleaseMessage = dep.formatMessages(personalNoReleaseMessage, plugin.ms.personalNoReleaseMessage,
plugin.ms.unknownValue, Bukkit.getPlayer(uid).getName(), plugin.ms.unknownValue, plugin.needAcceptPlayers.get(uid).getValue());
s.getName(), Bukkit.getPlayer(uid).getName(), plugin.ms.unknownValue, true);
senderNoReleaseMessage = dep.formatMessages(senderNoReleaseMessage, plugin.ms.senderNoReleaseMessage, s.getName(), Bukkit.getPlayer(uid).getDisplayName(), plugin.ms.unknownValue, true);
Bukkit.getPlayer(uid).sendMessage(personalNoReleaseMessage);
if (Bukkit.getPlayer(uid).getName() != s.getName()) {
s.sendMessage(senderNoReleaseMessage);
}
}
else {
String acceptSlapMessage = plugin.ms.acceptSlapMessage;
Expand Down
15 changes: 8 additions & 7 deletions PlayerSlap/src/me/PlayerSlap/CommandClasses/SlapInfoCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ else if (args[0].equalsIgnoreCase("slapmessages")) {
if (s.hasPermission("playerslap.info.slapmessages")) {
if (plugin.yc.configuration.contains("slaptypes." + args[1])) {
s.sendMessage(plugin.ms.padding + "Information for the " + args[1] + " slap" + plugin.ms.padding);
s.sendMessage("Personal slap message: " + plugin.yc.configuration.getString("slaptypes." + args[1] + ".messages.slappersonal").replaceAll("$Default", plugin.ms.personalSlapMessage));
s.sendMessage("Broadcast slap message: " + plugin.yc.configuration.getString("slaptypes." + args[1] + ".messages.slapbroadcast").replaceAll("$Default", plugin.ms.broadcastSlapMessage));
s.sendMessage("Death slap message: " + plugin.yc.configuration.getString("slaptypes." + args[1] + ".messages.death").replaceAll("$Default", plugin.ms.deathSlapMessage));
s.sendMessage("Personal slap message: " + plugin.yc.configuration.getString("slaptypes." + args[1] + ".messages.slappersonal").replaceAll("__Default", plugin.ms.personalSlapMessage));
s.sendMessage("Broadcast slap message: " + plugin.yc.configuration.getString("slaptypes." + args[1] + ".messages.slapbroadcast").replaceAll("__Default", plugin.ms.broadcastSlapMessage));
s.sendMessage("Death slap message: " + plugin.yc.configuration.getString("slaptypes." + args[1] + ".messages.death").replaceAll("__Default", plugin.ms.deathSlapMessage));
}
else {
plugin.ms.sendMessage(s, "incorrectslaptype", null);
Expand Down Expand Up @@ -191,10 +191,11 @@ else if (args[0].equalsIgnoreCase("general")) {
s.sendMessage("Players can slap themselves: " + plugin.yc.configuration.getString("slapself"));
s.sendMessage("Default slap type: " + plugin.yc.configuration.getString("slapdefault"));
s.sendMessage("Player slap counts incremented on '/slapall' command uses: " + plugin.yc.configuration.getString("incrementonslapall"));
s.sendMessage("Slap accept broadcast message: " + plugin.yc.configuration.getString("messages.accept").replaceAll("$Default", plugin.ms.acceptSlapMessage));
s.sendMessage("Personal slap release message: " + plugin.yc.configuration.getString("messages.releasepersonal").replaceAll("$Default", plugin.ms.personalReleaseMessage));
s.sendMessage("Broadcast slap release message: " + plugin.yc.configuration.getString("messages.releasebroadcast").replaceAll("$Default", plugin.ms.broadcastReleaseMessage));
s.sendMessage("Personal slap no release message: " + plugin.yc.configuration.getString("messages.noreleasepersonal").replaceAll("$Default", plugin.ms.personalNoReleaseMessage));
s.sendMessage("Slap accept broadcast message: " + plugin.yc.configuration.getString("messages.accept").replaceAll("__Default", plugin.ms.acceptSlapMessage));
s.sendMessage("Personal slap release message: " + plugin.yc.configuration.getString("messages.releasepersonal").replaceAll("__Default", plugin.ms.personalReleaseMessage));
s.sendMessage("Broadcast slap release message: " + plugin.yc.configuration.getString("messages.releasebroadcast").replaceAll("__Default", plugin.ms.broadcastReleaseMessage));
s.sendMessage("Personal slap no release message: " + plugin.yc.configuration.getString("messages.noreleasepersonal").replaceAll("__Default", plugin.ms.personalNoReleaseMessage));
s.sendMessage("Sender slap no release message: " + plugin.yc.configuration.getString("messages.noreleasesender").replaceAll("__Default", plugin.ms.senderNoReleaseMessage));
}
else {
plugin.ms.sendMessage(s, "nopermission", null);
Expand Down
13 changes: 7 additions & 6 deletions PlayerSlap/src/me/PlayerSlap/MainClasses/MessageSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ public class MessageSender {
protected Logger logger;

public final String unknownValue = "Unknown";
public final String broadcastSlapMessage = "$Slapped has been given a $Permanentslap by $Giver";
public final String personalSlapMessage = "You were slapped by $Giver";
public final String deathSlapMessage = "$Slapped was slapped to death";
public final String acceptSlapMessage = "$Slapped has accepted a slap";
public final String broadcastReleaseMessage = "$Slapped has been released by $Giver";
public final String personalReleaseMessage = "You have been released by $Giver";
public final String broadcastSlapMessage = "__Slapped has been given a __Permanentslap by __Giver";
public final String personalSlapMessage = "You were slapped by __Giver";
public final String deathSlapMessage = "__Slapped was slapped to death";
public final String acceptSlapMessage = "__Slapped has accepted a slap";
public final String broadcastReleaseMessage = "__Slapped has been released by __Giver";
public final String personalReleaseMessage = "You have been released by __Giver";
public final String personalNoReleaseMessage = "You have not yet been released from this slap";
public final String senderNoReleaseMessage = "__Slapped has not yet been released from this slap";

public final String padding = "=====";
public final String separator = "-";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,15 @@ private void registerExtraPermissions(PluginManager pm) {
}

public void addPlayer(String playerName, String sid) {
if (yd.configuration.contains("players") == false) {
yd.configuration.createSection("players");
}
yd.configuration.createSection("players." + sid);
yd.configuration.set("players." + sid + ".exempt", false);
yd.configuration.set("players." + sid + ".times", 0);
yd.configuration.set("players." + sid + ".username", playerName);
yd.configuration.set("players." + sid + ".mustaccept", false);
yd.configuration.createSection("players." + sid + ".currentslap");
yd.configuration.set("players." + sid + ".currentslap.mustaccept", false);
yd.configuration.set("players." + sid + ".currentslap.permanent", false);
}
}
4 changes: 2 additions & 2 deletions PlayerSlap/src/me/PlayerSlap/MainClasses/YamlFiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected void saveNewFile() {
@Override
public void fullReload() {
reload();
Bukkit.broadcast(ChatColor.GREEN + plugin.getDescription().getName() + " : " + theOutFile.getName() + " configuration reloaded ", configPermission);
Bukkit.broadcast(ChatColor.GREEN + plugin.getDescription().getName() + " : " + theOutFile.getName() + " configuration reloaded ", configPermission);
}

@Override
Expand All @@ -42,7 +42,7 @@ public void fullSave() {
Bukkit.broadcast(ChatColor.GREEN + plugin.getDescription().getName() + " : " + theOutFile.getName() + " configuration saved ", configPermission);
}
else {
Bukkit.broadcast(ChatColor.RED + plugin.getDescription().getName() + " : " + theOutFile.getName() + " configuration could not be saved ", configPermission);
Bukkit.broadcast(ChatColor.RED + plugin.getDescription().getName() + " : " + theOutFile.getName() + " configuration could not be saved ", configPermission);
}
}

Expand Down
1 change: 1 addition & 0 deletions PlayerSlap/src/playersHeader.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
# mustaccept (boolean): - Whether the player needs to accept a slap or not
# permanent (boolean) - Whether the player has a permanent slap or not
#
#
45 changes: 24 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,11 @@ slapself: true
slapdefault: '1'
incrementonslapall: true
messages:
accept: $Default
releasebroadcast: $Default
releasepersonal: $Default
noreleasepersonal: $Default
accept: \_\_Default
releasebroadcast: \_\_Default
releasepersonal: \_\_Default
noreleasepersonal: \_\
noreleasesender: \_\_Default
slaptypes:
'1':
health: 3
Expand All @@ -111,9 +112,9 @@ slaptypes:
lightning: true
smoke: 30
messages:
slapbroadcast: $Giver slapped $Slapped.
slappersonal: $Giver slapped you.
death: $Default
slapbroadcast: \_\_Giver slapped \_\_Slapped.
slappersonal: \_\_Giver slapped you.
death: \_\_Default
mobs:
ZOMBIE: 5
SKELETON: 1
Expand All @@ -126,28 +127,29 @@ slaptypes:
lightning: true
smoke: 50
messages:
broadcast: $Default
personal: $Default
death: $Default
broadcast: \_\_Default
personal: \_\_Default
death: \_\_Default
mobs:
BLAZE: 10
GIANT: 1
VILLAGER: 100
```
The string values of subfields of each configuration section called 'messages' can contain some of the following words which will be substituted for another value when the message is sent:
- $Default gets substituted for the default message.
- $Unknown gets substituted for 'unknown'
- $None get substituted for nothing
- $Slapped gets substituted for the name of the person who has been slapped
- $Giver gets substituted for the name of the person who gave the slap or the name of the person trying to remove a permanent slap (as appropriate)
- $Type becomes the slap type
- $Permanent becomes 'permanent' if the slap is permanent and nothing otherwise
- \_\_Default gets substituted for the default message.
- \_\_Unknown gets substituted for 'unknown'
- \_\_None get substituted for nothing
- \_\_Slapped gets substituted for the name of the person who has been slapped
- \_\_Giver gets substituted for the name of the person who gave the slap or the name of the person trying to remove a permanent slap (as appropriate)
- \_\_Type becomes the slap type
- \_\_Permanent becomes 'permanent' if the slap is permanent and nothing otherwise
The following restrictions apply to using the substitutions defined in the above list:
- The 'accept' message cannot substitute $Type
- The 'releasebroadcast' message cannot substitute $Type
- The 'releasepersonal' message cannot substitute $Type
- The 'noreleasepersonal' message cannot substitute $Type or $Giver
- The 'accept' message cannot substitute \_\_Type
- The 'releasebroadcast' message cannot substitute \_\_Type
- The 'releasepersonal' message cannot substitute \_\_Type
- The 'noreleasepersonal' message cannot substitute \_\_Type
- The 'noreleasesender' message cannot substitute \_\_Type
- The 'slapbroadcast' message has no restrictions
- The 'slappersonal' message has no restrictions
- The 'death' message has no restrictions
Expand All @@ -160,6 +162,7 @@ The below list explains the top-level fields and the fields immediately inside t
- The 'releasebroadcast' message is the message broadcast when a player is released from a slap.
- The 'releasepersonal' message is the message sent to a player when the player is released from a slap.
- The 'noreleasepersonal' message is the message sent to a player when it tries to accept a slap from which it has not been released.
- The 'noreleasesender' message is the message sent to a player who tries to accept a slap for a player but cannot as it is a permanent slap from which the player has not been released.
- The 'slaptypes' section contains the name of each slap type.
The below list explains the fields within each section about a specific slap:
Expand Down

0 comments on commit a96f90b

Please sign in to comment.