-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBindScript.java
More file actions
80 lines (73 loc) · 3.27 KB
/
BindScript.java
File metadata and controls
80 lines (73 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package scriptblock.command;
import java.util.LinkedList;
import java.util.logging.Logger;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import scriptblock.BlockCoords;
import scriptblock.ScriptBlock;
import scriptblock.command.CommandCreate;
import scriptblock.command.CommandHandler;
import scriptblock.managers.FileManager;
import scriptblock.managers.MapManager;
import scriptblock.managers.PermManager;
import scriptblock.managers.ScriptManager;
public abstract class BindScript {
protected ScriptBlock scriptBlock;
protected Logger log;
protected JavaPlugin plugin;
protected ScriptManager scriptManager;
protected CommandHandler.CommandType commandType;
protected FileManager fileManager;
protected MapManager mapManager;
protected PermManager permManager;
protected Player commandSender;
protected String statusCancelled;
protected String[] noAccessPermMsg;
public BindScript(ScriptManager scriptManager, Player commandSender) {
this(scriptManager, commandSender, (CommandHandler.CommandType)null);
}
public BindScript(ScriptManager scriptManager, Player commandSender, CommandHandler.CommandType commandType) {
this.scriptBlock = ScriptBlock.getInstance();
this.log = ScriptBlock.log;
this.plugin = scriptManager.getPlugin();
this.scriptManager = scriptManager;
this.commandType = commandType;
this.mapManager = scriptManager.getMapManager();
this.fileManager = scriptManager.getFileManager();
this.permManager = scriptManager.getPermManager();
this.commandSender = commandSender;
this.statusCancelled = new String(ChatColor.RED + "[" + this.plugin.getName() + "] " + commandType.name() + " status cancelled !");
this.noAccessPermMsg = new String[]{this.permManager.noPermMsg, ChatColor.RED + "[" + this.plugin.getName() + "] You can\'t \"" + commandType.name() + "\" scripts you don\'t own!"};
}
public abstract boolean onEvent(BlockCoords var1);
protected boolean canAccessScript(BlockCoords blockCoords) {
LinkedList commandList = (LinkedList)this.mapManager.blocksMap.get(blockCoords.getFullCoords());
String perm = new String("modify." + this.commandType.name());
if(commandList == null) {
return true;
} else {
String firstLine = (String)commandList.getFirst();
if(firstLine.startsWith(CommandCreate.authorNode)) {
firstLine = firstLine.replaceFirst(CommandCreate.authorNode, "");
String[] scriptInfos = firstLine.split("/");
String authorName = scriptInfos[0];
String authorGroup = scriptInfos[1];
if(!this.commandSender.getName().equals(authorName) && !this.permManager.hasSBPerm(this.commandSender, perm + "." + authorGroup, false)) {
this.commandSender.sendMessage(this.noAccessPermMsg);
return false;
} else {
return true;
}
} else if(this.permManager.hasSBPerm(this.commandSender, perm, false)) {
return true;
} else {
this.commandSender.sendMessage(this.noAccessPermMsg);
return false;
}
}
}
public CommandHandler.CommandType getCommandType() {
return this.commandType;
}
}