Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 2 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
View
5 config.yml
@@ -23,7 +23,10 @@ global:
- $6sequential tip 4
- $7sequential tip 5
- - period: 2
+ # if you set an ID, the tip will only be received by users with
+ # tips.receive.<id> permission (tips.receive.others in this example)
+ - id: others
+ period: 2
delay: 0
random: false
tips:
View
53 src/net/namedfork/bukkit/Tips/TipSet.java
@@ -3,24 +3,28 @@
import java.util.Iterator;
import java.util.List;
import java.util.Random;
-import org.bukkit.Server;
+import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Player;
+import org.bukkit.permissions.Permission;
+import org.bukkit.permissions.PermissionDefault;
+import org.bukkit.plugin.PluginManager;
/**
*
* @author zydeco
*/
public class TipSet implements Runnable {
- private final Server server;
private final World world;
private final int delay, period;
private final String[] tips;
private final Random rng;
+ private final String id;
+ private final Permission perm;
private int nextTip;
- public TipSet(Server server, World world, int delay, int period, List<String> tips, long seed) {
- this.server = server;
+ public TipSet(String id, World world, int delay, int period, List<String> tips, long seed) {
+ this.id = id;
this.world = world;
this.delay = delay;
this.period = period;
@@ -32,6 +36,22 @@ public TipSet(Server server, World world, int delay, int period, List<String> ti
for(int i=0; i < this.tips.length; i++) {
this.tips[i] = formatTip(this.tips[i]);
}
+
+ // register permission
+ if (id != null) {
+ PluginManager pm = Bukkit.getServer().getPluginManager();
+ String permName = "tips.receive."+id;
+ if (pm.getPermission(permName) == null) {
+ perm = new Permission(permName, PermissionDefault.FALSE);
+ System.out.println("REGISTERING PERMISSION "+perm.getName());
+ pm.addPermission(perm);
+ } else {
+ perm = pm.getPermission(permName);
+ }
+ } else {
+ perm = null;
+ }
+
}
public void run() {
@@ -46,14 +66,27 @@ else if (tips.length == 1) {
}
final String tip = tips[nextTip];
- if (getWorld() == null) {
+ if (world == null && perm == null) {
// tip for everyone
- getServer().broadcastMessage(tip);
+ Bukkit.getServer().broadcastMessage(tip);
+ } else if (world == null && perm != null) {
+ // global tip with permission
+ Player players[] = Bukkit.getServer().getOnlinePlayers();
+ for(Player p: players) {
+ if (p.hasPermission(perm)) System.out.println(p.getName() + " has permission " + perm.getName());
+ if (p.hasPermission("tips.receive.*")) System.out.println(p.getName() + " has permission tips.receive.*");
+ if (p.hasPermission(perm) || p.hasPermission("tips.receive.*")) {
+ p.sendMessage(tip);
+ }
+ }
} else {
// tip for world
- Iterator<Player> i = getWorld().getPlayers().iterator();
+ Iterator<Player> i = world.getPlayers().iterator();
while (i.hasNext()) {
- i.next().sendMessage(tip);
+ Player p = i.next();
+ if (perm == null || p.hasPermission(perm) || p.hasPermission("tips.receive.*")) {
+ p.sendMessage(tip);
+ }
}
}
}
@@ -63,10 +96,6 @@ private String formatTip(String tip) {
return tip.replace("$", "\u00A7").replace("\u00A7$", "$");
}
- public Server getServer() {
- return server;
- }
-
public World getWorld() {
return world;
}
View
2  src/net/namedfork/bukkit/Tips/Tips.java
@@ -56,7 +56,7 @@ public void onDisable() {
int period = ((Number)t.get("period")).intValue();
int delay = t.containsKey("delay")?((Number)t.get("delay")).intValue():period;
boolean isRandom = !(t.containsKey("random") && ((Boolean)t.get("random")).booleanValue() == false);
- tipSets.add(new TipSet(getServer(), w, delay, period, (List<String>)t.get("tips"), isRandom?rng.nextLong():0));
+ tipSets.add(new TipSet((String)t.get("id"), w, delay, period, (List<String>)t.get("tips"), isRandom?rng.nextLong():0));
}
return tipSets;
} catch (Exception e) {
View
5 src/plugin.yml
@@ -1,6 +1,6 @@
name: Tips
main: net.namedfork.bukkit.Tips.Tips
-version: 1.0.4
+version: 1.1
author: Jesús A. Álvarez
authorEmail: zydeco@namedfork.net
authorUrl: http://namedfork.net
@@ -13,3 +13,6 @@ permissions:
tips.reload:
description: Allows to reload tips
default: op
+ tips.receive.*:
+ description: Receive all the tips
+ default: false

No commit comments for this range

Something went wrong with that request. Please try again.