Skip to content

Commit 5a7a6b4

Browse files
committed
Merge branch 'actionbar' (new feature to toggle chat spam)
2 parents 2d974e9 + 3468f85 commit 5a7a6b4

File tree

8 files changed

+84
-26
lines changed

8 files changed

+84
-26
lines changed

pom.xml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,33 @@
66

77
<groupId>StickyLocks</groupId>
88
<artifactId>StickyLocks</artifactId>
9-
<version>0.10</version>
9+
<version>0.11</version>
1010
<repositories>
1111
<repository>
1212
<id>spigot-repo</id>
1313
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
1414
</repository>
1515
</repositories>
1616
<dependencies>
17+
<!--Spigot API-->
18+
<dependency>
19+
<groupId>org.spigotmc</groupId>
20+
<artifactId>spigot-api</artifactId>
21+
<version>1.12.2-R0.1-SNAPSHOT</version>
22+
<scope>provided</scope>
23+
</dependency>
1724
<!--Bukkit API-->
1825
<dependency>
1926
<groupId>org.bukkit</groupId>
2027
<artifactId>bukkit</artifactId>
21-
<version>1.12.1-R0.1-SNAPSHOT</version>
28+
<version>1.12.2-R0.1-SNAPSHOT</version>
2229
<scope>provided</scope>
2330
</dependency>
24-
31+
<dependency>
32+
<groupId>net.md-5</groupId>
33+
<artifactId>bungeecord-chat</artifactId>
34+
<version>1.12-SNAPSHOT</version>
35+
</dependency>
2536
</dependencies>
2637
<build>
2738
<resources>

src/main/java/net/simplycrafted/StickyLocks/Database.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,4 +779,21 @@ public void duplicate(Block target, Block source) {
779779
stickylocks.getLogger().info("Failed to duplicate access list information");
780780
}
781781
}
782+
783+
public Boolean getNotification(Player player) {
784+
PreparedStatement psql;
785+
ResultSet results;
786+
Boolean returnVal = false;
787+
try {
788+
psql = db_conn.prepareStatement("SELECT notify FROM player WHERE uuid LIKE ?");
789+
psql.setString(1,player.getUniqueId().toString());
790+
results = psql.executeQuery();
791+
if (results.next()) returnVal = (results.getInt(1) ==1);
792+
results.close();
793+
psql.close();
794+
} catch (SQLException e) {
795+
stickylocks.getLogger().info("Failed to fetch notification setting for player");
796+
}
797+
return returnVal;
798+
}
782799
}

src/main/java/net/simplycrafted/StickyLocks/StickyLocks.java

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package net.simplycrafted.StickyLocks;
22

3+
import net.md_5.bungee.api.ChatMessageType;
4+
import net.md_5.bungee.api.chat.ComponentBuilder;
35
import net.simplycrafted.StickyLocks.commands.StickyLocksCommand;
46
import net.simplycrafted.StickyLocks.listeners.StickyLocksClick;
57
import net.simplycrafted.StickyLocks.listeners.StickyLocksCreateDestroy;
@@ -15,6 +17,7 @@
1517
import org.bukkit.event.player.PlayerInteractEvent;
1618
import org.bukkit.event.player.PlayerJoinEvent;
1719
import org.bukkit.plugin.java.JavaPlugin;
20+
1821
import java.util.HashMap;
1922

2023
/**
@@ -39,7 +42,8 @@ public class StickyLocks extends JavaPlugin {
3942

4043
private static Database db;
4144

42-
public HashMap<Player,Location> SelectedBlock;
45+
public HashMap<Player,Location> selectedBlock;
46+
public HashMap<Player,Boolean> playerNotification;
4347

4448
@Override
4549
public void onEnable() {
@@ -68,8 +72,11 @@ public void onEnable() {
6872
db=new Database();
6973
db.createTables();
7074

71-
// Which block players mighht have selected
72-
SelectedBlock = new HashMap<Player,Location>();
75+
// Which block players might have selected
76+
selectedBlock = new HashMap<>();
77+
78+
// Per-player notification settings
79+
playerNotification = new HashMap<>();
7380
}
7481

7582
@Override
@@ -83,7 +90,7 @@ public void onDisable() {
8390
// Clear away the database class
8491
db.shutdown();
8592
// Clear the block selections
86-
SelectedBlock.clear();
93+
selectedBlock.clear();
8794
}
8895

8996
public static StickyLocks getInstance() {
@@ -92,7 +99,21 @@ public static StickyLocks getInstance() {
9299
}
93100

94101
public void sendMessage(CommandSender player, String message, boolean unlocked) {
102+
player.sendMessage(String.format("%s[%s]%s %s", ChatColor.GRAY, getConfig().getString("chatprefix"), unlocked ? ChatColor.DARK_GREEN : ChatColor.DARK_RED, message));
103+
}
104+
105+
public void sendMuteableMessage(CommandSender player, String message, boolean unlocked) {
106+
sendMuteableMessage(player, message, unlocked, null);
107+
}
108+
109+
public void sendMuteableMessage(CommandSender player, String message, boolean unlocked, String altMessage) {
95110
// "unlocked" is a colour flag. If true, message is green. If not, message is red.
96-
player.sendMessage(String.format("%s[%s]%s %s", ChatColor.GRAY,getConfig().getString("chatprefix"), unlocked ? ChatColor.DARK_GREEN : ChatColor.DARK_RED,message));
111+
if(playerNotification.get(player)) {
112+
// Chat message
113+
player.sendMessage(String.format("%s[%s]%s %s", ChatColor.GRAY, getConfig().getString("chatprefix"), unlocked ? ChatColor.DARK_GREEN : ChatColor.DARK_RED, message));
114+
} else if (altMessage != null & player instanceof Player) {
115+
// Brief action bar pop-up in red or green
116+
((Player) player).spigot().sendMessage(ChatMessageType.ACTION_BAR, new ComponentBuilder(altMessage).color(unlocked ? net.md_5.bungee.api.ChatColor.DARK_GREEN : net.md_5.bungee.api.ChatColor.DARK_RED).create());
117+
}
97118
}
98119
}

src/main/java/net/simplycrafted/StickyLocks/commands/StickyLocksCommand.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
import net.simplycrafted.StickyLocks.Database;
44
import net.simplycrafted.StickyLocks.StickyLocks;
5+
import net.simplycrafted.StickyLocks.listeners.StickyLocksClick;
56
import net.simplycrafted.StickyLocks.util.Util;
67
import org.bukkit.Location;
78
import org.bukkit.command.Command;
89
import org.bukkit.command.CommandExecutor;
910
import org.bukkit.command.CommandSender;
1011
import org.bukkit.entity.Player;
12+
import org.bukkit.event.player.PlayerInteractEvent;
1113

12-
import java.net.URI;
1314
import java.util.List;
1415
import java.util.UUID;
1516

@@ -51,12 +52,12 @@ public boolean onCommand (CommandSender sender, Command command, String label, S
5152

5253
// If a block is selected, use that block's owner. If that block has no owner, or
5354
// if no block is selected, use the player.
54-
if (stickylocks.SelectedBlock.get(sender) == null) {
55+
if (stickylocks.selectedBlock.get(sender) == null) {
5556
playerID = ((Player) sender).getUniqueId();
5657
} else {
57-
playerID = db.getUUID(stickylocks.SelectedBlock.get(sender));
58+
playerID = db.getUUID(stickylocks.selectedBlock.get(sender));
5859
if (playerID == null) playerID = ((Player) sender).getUniqueId();
59-
location = stickylocks.SelectedBlock.get(sender);
60+
location = stickylocks.selectedBlock.get(sender);
6061
}
6162

6263
// Player-specific commands
@@ -199,19 +200,23 @@ public boolean onCommand (CommandSender sender, Command command, String label, S
199200
return false;
200201
case "notify" :
201202
db.toggleNotify((Player)sender);
203+
stickylocks.playerNotification.put((Player) sender, !stickylocks.playerNotification.get((Player) sender));
202204
stickylocks.sendMessage(sender,"Toggled lock notifications", true);
203205
return true;
204206
case "reload" :
205207
if(sender.hasPermission("stickylocks.reload")) {
206208
stickylocks.sendMessage(sender, "Reloading configuration", true);
207209
stickylocks.reloadConfig();
208210
db.createTables();
211+
// Re-register the PlayerInteractEvent in case the tool has changed
212+
PlayerInteractEvent.getHandlerList().unregister(stickylocks);
213+
stickylocks.getServer().getPluginManager().registerEvents(new StickyLocksClick(),stickylocks);
209214
} else {
210215
stickylocks.sendMessage(sender,"No permission",false);
211216
}
212217
return true;
213218
case "clearselection" :
214-
stickylocks.SelectedBlock.remove(sender);
219+
stickylocks.selectedBlock.remove(sender);
215220
stickylocks.sendMessage(sender, "Selection cleared", true);
216221
return true;
217222
default:
@@ -224,6 +229,9 @@ public boolean onCommand (CommandSender sender, Command command, String label, S
224229
stickylocks.sendMessage(sender, "Reloading configuration", true);
225230
stickylocks.reloadConfig();
226231
db.createTables();
232+
// Re-register the PlayerInteractEvent in case the tool has changed
233+
PlayerInteractEvent.getHandlerList().unregister(stickylocks);
234+
stickylocks.getServer().getPluginManager().registerEvents(new StickyLocksClick(),stickylocks);
227235
} else {
228236
stickylocks.sendMessage(sender, "Only the reload command works from console", false);
229237
}

src/main/java/net/simplycrafted/StickyLocks/listeners/StickyLocksClick.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ public void onPlayerInteract(PlayerInteractEvent event) {
6060
Protection protection = db.getProtection(target);
6161
if (protection.getType() != null) {
6262
String selected = "";
63-
if (stickylocks.SelectedBlock.get(player) == null || (stickylocks.SelectedBlock.get(player).getWorld().equals(target.getLocation().getWorld()) && !(stickylocks.SelectedBlock.get(player).distanceSquared(target.getLocation()) < 1))) {
63+
if (stickylocks.selectedBlock.get(player) == null || (stickylocks.selectedBlock.get(player).getWorld().equals(target.getLocation().getWorld()) && !(stickylocks.selectedBlock.get(player).distanceSquared(target.getLocation()) < 1))) {
6464
// Block is not one previously selected
65-
stickylocks.SelectedBlock.put(player, target.getLocation());
65+
stickylocks.selectedBlock.put(player, target.getLocation());
6666
selected = " " + ChatColor.RED + "(selected)";
6767
}
6868
if (protection.isProtected())
@@ -80,9 +80,9 @@ public void onPlayerInteract(PlayerInteractEvent event) {
8080
Protection protection = db.getProtection(target);
8181
if (protection.isProtected()) {
8282
if (protection.getOwner().equals(player.getUniqueId())) {
83-
stickylocks.sendMessage(player, String.format("%s owned by you", protection.getType()), true);
83+
stickylocks.sendMuteableMessage(player, String.format("%s owned by you", protection.getType()), true);
8484
} else {
85-
stickylocks.sendMessage(player, String.format("%s owned by %s", protection.getType(), protection.getOwnerName()), player.hasPermission("stickylocks.ghost"));
85+
stickylocks.sendMuteableMessage(player, String.format("%s owned by %s", protection.getType(), protection.getOwnerName()), player.hasPermission("stickylocks.ghost"), String.format("LOCKED by %s", protection.getOwnerName()));
8686
// Use of permission on previous line changes colour of message
8787
if (!player.hasPermission("stickylocks.ghost") && db.accessDenied(player, target)) {
8888
event.setCancelled(true);
@@ -94,7 +94,7 @@ public void onPlayerInteract(PlayerInteractEvent event) {
9494
// Left-clicks are either with a stick, or not
9595
if (player.getInventory().getItemInMainHand().getType() == tool) {
9696
// Stick used - check if it's the selected block, and lock/unlock if appropriate
97-
if (stickylocks.SelectedBlock.get(player) != null && (stickylocks.SelectedBlock.get(player).getWorld().equals(target.getLocation().getWorld()) && stickylocks.SelectedBlock.get(player).distanceSquared(target.getLocation()) < 1)) {
97+
if (stickylocks.selectedBlock.get(player) != null && (stickylocks.selectedBlock.get(player).getWorld().equals(target.getLocation().getWorld()) && stickylocks.selectedBlock.get(player).distanceSquared(target.getLocation()) < 1)) {
9898
// Just left-clicked the selected block with a stick!
9999
if (player.hasPermission("stickylocks.lock")) {
100100
Protection protection = db.getProtection(target);
@@ -135,9 +135,9 @@ public void onPlayerInteract(PlayerInteractEvent event) {
135135
}
136136
}
137137
} else if (event.getAction() == Action.RIGHT_CLICK_AIR) {
138-
if (player.getInventory().getItemInMainHand().getType() == tool && stickylocks.SelectedBlock.get(player) != null) {
138+
if (player.getInventory().getItemInMainHand().getType() == tool && stickylocks.selectedBlock.get(player) != null) {
139139
// Player right-clicked nothing - Deselect whatever might be selected.
140-
stickylocks.SelectedBlock.remove(player);
140+
stickylocks.selectedBlock.remove(player);
141141
stickylocks.sendMessage(player, "Selection cleared", true);
142142
}
143143
}

src/main/java/net/simplycrafted/StickyLocks/listeners/StickyLocksCreateDestroy.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
import org.bukkit.Material;
99
import org.bukkit.block.Block;
1010
import org.bukkit.block.BlockFace;
11-
import org.bukkit.block.Chest;
12-
import org.bukkit.block.DoubleChest;
1311
import org.bukkit.entity.Player;
1412
import org.bukkit.event.EventHandler;
1513
import org.bukkit.event.EventPriority;
@@ -58,10 +56,10 @@ public void onBlockPlaceEvent(BlockPlaceEvent event) {
5856
// It belongs to the player, and needs to have the lock information
5957
// copied to the newly placed half chest
6058
db.duplicate(target, Util.getOtherHalfOfChest(target));
61-
stickylocks.sendMessage(player, "Chest lock has been expanded", true);
59+
stickylocks.sendMuteableMessage(player, "Chest lock has been expanded", true);
6260
} else {
6361
// It is belongs to another player, so cancel this event. Denied!
64-
stickylocks.sendMessage(player, "Chest placement blocked - access is denied to the existing chest", false);
62+
stickylocks.sendMuteableMessage(player, "Chest placement blocked - access is denied to the existing chest", false, "Can't expand locked chest");
6563
event.setCancelled(true);
6664
return;
6765
}
@@ -84,7 +82,7 @@ public void checkBlockPlaceEvent(BlockPlaceEvent event) {
8482
}
8583
} else {
8684
if (Util.getOtherHalfOfChest(event.getBlockPlaced()) == null && db.isProtectable(event.getBlockPlaced().getType())) {
87-
stickylocks.sendMessage(player, String.format("Right-click then left-click with %s to lock this object", stickylocks.getConfig().getString("tool")), true);
85+
stickylocks.sendMuteableMessage(player, String.format("Right-click then left-click with %s to lock this object", stickylocks.getConfig().getString("tool")), true);
8886
}
8987
}
9088
}
@@ -106,7 +104,7 @@ public void onHopperPlaceEvent(BlockPlaceEvent event) {
106104
if (target.getState() instanceof InventoryHolder & db.getProtection(target).isProtected() & db.accessDenied(player,target)) {
107105
// The block above the hopper has an inventory, and it's not ours - cancel!
108106
event.setCancelled(true);
109-
stickylocks.sendMessage(player,"Hopper placement blocked - access is denied to the inventory above",false);
107+
stickylocks.sendMuteableMessage(player,"Hopper placement blocked - access is denied to the inventory above",false, "Hopper placement cancelled, block above locked");
110108
}
111109
}
112110
}

src/main/java/net/simplycrafted/StickyLocks/listeners/StickyLocksPlayerjoin.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package net.simplycrafted.StickyLocks.listeners;
22

33
import net.simplycrafted.StickyLocks.Database;
4+
import net.simplycrafted.StickyLocks.StickyLocks;
45
import org.bukkit.event.EventHandler;
56
import org.bukkit.event.Listener;
67
import org.bukkit.event.player.PlayerJoinEvent;
@@ -29,5 +30,6 @@ public class StickyLocksPlayerjoin implements Listener {
2930
@EventHandler
3031
public void onPlayerJoin(PlayerJoinEvent event) {
3132
db.addPlayer(event.getPlayer());
33+
StickyLocks.getInstance().playerNotification.put(event.getPlayer(),db.getNotification(event.getPlayer()));
3234
}
3335
}

src/main/resources/plugin.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ commands:
1515
/<command> group <group> {add|remove} <player> ...
1616
/<command> group <group> {rename|merge} <name>
1717
/<command> reload
18+
/<command> notify
1819
permission: stickylocks.lock
1920
aliases: sl
2021
permissions:

0 commit comments

Comments
 (0)