-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
194 lines (183 loc) · 6.68 KB
/
Main.java
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
package com.blockcondition;
import de.tr7zw.nbtapi.NBTTileEntity;
import java.util.ArrayList;
import java.util.List;
import net.milkbowl.vault.economy.Economy;
import org.black_ixx.playerpoints.PlayerPoints;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
public class project extends JavaPlugin implements Listener {
public static Economy econ;
public static PlayerPoints playerPoints;
public ArrayList<String> map = new ArrayList<>();
public ArrayList<String> debug = new ArrayList<>();
public void onEnable() {
setupEconomy();
setupPlayerPoints();
saveDefaultConfig();
reloadConfig();
Bukkit.getPluginCommand("BlockCondition").setExecutor((CommandExecutor)this);
Bukkit.getPluginManager().registerEvents(this, (Plugin)this);
}
private boolean setupEconomy() {
if (getServer().getPluginManager().getPlugin("Vault") == null)
return false;
RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
if (rsp == null)
return false;
econ = (Economy)rsp.getProvider();
return (econ != null);
}
public static boolean setupPlayerPoints() {
Plugin plugin = Bukkit.getPluginManager().getPlugin("PlayerPoints");
playerPoints = PlayerPoints.class.cast(plugin);
return (playerPoints != null);
}
public static String getBlockNBT(Block block) {
BlockState bs = block.getState();
String blockname = block.getType().toString();
try {
NBTTileEntity tent = new NBTTileEntity(bs);
return String.valueOf(blockname) + "," + tent.asNBTString();
} catch (Exception e) {
return blockname;
}
}
@EventHandler
public void onInteract(PlayerInteractEvent e) {
if (e.getHand() == EquipmentSlot.OFF_HAND)
return;
if (e.getAction() != Action.RIGHT_CLICK_BLOCK)
return;
Block b = e.getClickedBlock();
final Player p = e.getPlayer();
ItemStack i = p.getItemInHand();
if (this.debug.contains(p.getName())) {
p.sendMessage("+ getBlockNBT(b));
p.sendMessage("+ i.getType().toString());
e.setCancelled(true);
return;
}
if (b == null || b.getType() == Material.AIR)
return;
String itemname = i.getType().toString();
String blockname = getBlockNBT(b);
ConfigurationSection cs = getConfig().getConfigurationSection("");
for (String temp : cs.getKeys(false)) {
String BlockName = getConfig().getString(String.valueOf(temp) + ".Block");
String NotContains = getConfig().getString(String.valueOf(temp) + ".NotContains");
if (BlockName == null)
continue;
if (blockname.toUpperCase().contains(BlockName.toUpperCase()) && !blockname.toUpperCase().contains(NotContains.toUpperCase())) {
List<String> needItems = getConfig().getStringList(String.valueOf(temp) + ".CheckInItemHands");
boolean check_hand_item = false;
if (needItems.size() == 0) {
check_hand_item = true;
} else {
for (int c = 0; c < needItems.size(); c++) {
String needItem = needItems.get(c);
if (needItem.equalsIgnoreCase(itemname)) {
check_hand_item = true;
break;
}
}
}
if (!check_hand_item)
continue;
String permission = getConfig().getString(String.valueOf(blockname) + ".PermissionNeed");
if (permission != null && !permission.equalsIgnoreCase("") &&
!p.hasPermission(permission)) {
p.sendMessage(getConfig().getString("NoPermission").replace("<Permission>", permission));
e.setCancelled(true);
break;
}
int MONEY = getConfig().getInt(String.valueOf(temp) + ".MONEY");
if (MONEY != 0 &&
econ.getBalance((OfflinePlayer)p) < MONEY) {
p.sendMessage(getConfig().getString("NoMoney").replace("<MONEY>", String.valueOf(MONEY)));
e.setCancelled(true);
break;
}
int POINT = getConfig().getInt(String.valueOf(temp) + ".POINT");
if (POINT != 0 &&
playerPoints.getAPI().look(p.getUniqueId()) < POINT) {
p.sendMessage(getConfig().getString("NoPoint").replace("<POINT>", String.valueOf(POINT)));
e.setCancelled(true);
break;
}
if (this.map.contains(p.getName())) {
econ.withdrawPlayer((OfflinePlayer)p, MONEY);
playerPoints.getAPI().take(p.getUniqueId(), POINT);
this.map.remove(p.getName());
break;
}
e.setCancelled(true);
this.map.add(p.getName());
(new BukkitRunnable() {
public void run() {
if (project.this.map.contains(p.getName()))
project.this.map.remove(p.getName());
}
}).runTaskLater((Plugin)this, 100L);
p.sendMessage(getConfig().getString("Message").replace("<MONEY>", String.valueOf(MONEY)).replace("<POINT>", String.valueOf(POINT)));
break;
}
}
}
@EventHandler
public boolean onCommand(CommandSender sender, Command cmd, String Label, String[] args) {
if (args.length == 0) {
sender.sendMessage("Reload -> );
sender.sendMessage("Debug -> );
return false;
}
if (args.length == 1 && args[0].equalsIgnoreCase("Reload")) {
if (sender instanceof Player) {
Player p = (Player)sender;
if (!p.isOp()) {
p.sendMessage(");
return false;
}
}
reloadConfig();
sender.sendMessage(");
return false;
}
if (args.length == 1 && args[0].equalsIgnoreCase("Debug")) {
if (sender instanceof Player) {
Player player = (Player)sender;
if (!player.isOp()) {
player.sendMessage(");
return false;
}
}
Player p = (Player)sender;
if (this.debug.contains(p.getName())) {
this.debug.remove(p.getName());
p.sendMessage(");
} else {
this.debug.add(p.getName());
p.sendMessage(");
}
}
return false;
}
}