-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDreamcompass.java
287 lines (253 loc) · 17.6 KB
/
Dreamcompass.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
package me.prostedeni.goodcraft.dreamcompass;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.*;
import org.bukkit.advancement.Advancement;
import org.bukkit.advancement.AdvancementProgress;
import org.bukkit.block.Biome;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerPortalEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;
public final class Dreamcompass extends JavaPlugin implements Listener {
public static HashMap<Player, String> Mapa;
public static HashMap<Player, Location> PortalMap;
@Override
public void onEnable() {
// Plugin startup logic
Bukkit.getPluginManager().registerEvents(this,this);
getConfig().options().copyDefaults();
saveDefaultConfig();
Mapa = new HashMap<>();
PortalMap = new HashMap<>();
}
public static java.util.Random rand = new java.util.Random();
public static int epsilon;
public static Location loc0;
public static Location loc1;
public static Location loc2;
public static int minimumDist;
public static int maximumX;
public static int maximumZ;
@Override
public void onDisable() {
// Plugin shutdown logic
reloadConfig();
saveConfig();
}
public static boolean hasAdvancement(Player player, String achname){
Advancement ach = null;
for (Iterator<Advancement> iter = Bukkit.getServer().advancementIterator(); iter.hasNext(); ) {
Advancement adv = iter.next();
if (adv.getKey().getKey().equalsIgnoreCase(achname)){
ach = adv;
break;
}
}
AdvancementProgress prog = player.getAdvancementProgress(ach);
if (prog.isDone()){
return true;
}
return false;
}
@EventHandler
public void onEvent(PlayerInteractEvent e) {
if (e.getPlayer().getItemInHand().getType() == Material.COMPASS) {
if (Mapa.containsKey(e.getPlayer())) {
Player target = Bukkit.getPlayer(Mapa.get(e.getPlayer()));
Location targetLoc = target.getLocation();
if (target.getWorld().getEnvironment() == World.Environment.NETHER || target.getWorld().getEnvironment() == World.Environment.THE_END) {
if (PortalMap.containsKey(target)){
if (e.getPlayer().getWorld().getEnvironment() != target.getWorld().getEnvironment()) {
targetLoc = PortalMap.get(target);
}
}
}
if (e.getPlayer().hasPermission("dreamcompass.use")) {
if (target != null) {
boolean mode = getConfig().getBoolean("DefaultMode");
if (mode) {
e.getPlayer().setCompassTarget(targetLoc);
e.getPlayer().sendMessage(ChatColor.GOLD + "Compass pointing to " + Mapa.get(e.getPlayer()));
e.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(ChatColor.translateAlternateColorCodes('&', "&3&lY: &b" + target.getLocation().getBlockY())));
int EnderChance = getConfig().getInt("EnderChance");
if (EnderChance > 0 && EnderChance <= 100) {
if (hasAdvancement(target, "nether/obtain_blaze_rod")) {
if (target.getWorld().getName().equals("world")) {
double EnderChanceDouble = ((double) EnderChance / (double) 100);
double r = rand.nextDouble();
if (r >= 1 - EnderChanceDouble) {
int minimumDist = getConfig().getInt("MinimumDistance");
int maximumX = getConfig().getInt("MaximumDistance");
int maximumZ = getConfig().getInt("MaximumDistance");
int randomX = ThreadLocalRandom.current().nextInt((targetLoc.getBlockX() - maximumX), (targetLoc.getBlockX() + maximumX + 1));
int randomZ = ThreadLocalRandom.current().nextInt((targetLoc.getBlockZ() - maximumZ), (targetLoc.getBlockZ() + maximumZ + 1));
Biome biome = target.getWorld().getBiome(targetLoc.getBlockX(), targetLoc.getBlockZ());
if ((biome == Biome.GRAVELLY_MOUNTAINS || biome == Biome.MOUNTAINS || biome == Biome.MOUNTAIN_EDGE || biome == Biome.MODIFIED_GRAVELLY_MOUNTAINS || biome == Biome.SNOWY_MOUNTAINS || biome == Biome.SNOWY_TAIGA_MOUNTAINS || biome == Biome.TAIGA_MOUNTAINS || biome == Biome.ICE_SPIKES || biome == Biome.WOODED_MOUNTAINS || biome == Biome.SHATTERED_SAVANNA) || (targetLoc.getBlockY() > 120)) {
epsilon = (targetLoc.getBlockY() - 70);
} else {
epsilon = (targetLoc.getBlockY() - 15);
}
Location loc0 = new Location(target.getWorld(), randomX, epsilon, randomZ);
Location loc1 = new Location(target.getWorld(), randomX, epsilon + 1, randomZ);
Location loc2 = new Location(target.getWorld(), randomX, epsilon + 2, randomZ);
while (loc0.distance(targetLoc) < minimumDist) {
randomX = ThreadLocalRandom.current().nextInt((targetLoc.getBlockX() - maximumX), (targetLoc.getBlockX() + maximumX + 1));
randomZ = ThreadLocalRandom.current().nextInt((targetLoc.getBlockZ() - maximumZ), (targetLoc.getBlockZ() + maximumZ + 1));
loc0 = new Location(target.getWorld(), randomX, epsilon, randomZ);
if (loc0.distance(targetLoc) < minimumDist) {
break;
}
}
for (int i = 2; i < 200; ++i) {
++epsilon;
loc0 = new Location(target.getWorld(), randomX, epsilon, randomZ);
loc1 = new Location(target.getWorld(), randomX, epsilon + 1, randomZ);
loc2 = new Location(target.getWorld(), randomX, epsilon + 2, randomZ);
if (loc0.getBlock().getType() == Material.AIR && loc1.getBlock().getType() == Material.AIR && loc2.getBlock().getType() == Material.AIR) {
target.getWorld().spawnEntity(loc0, EntityType.ENDERMAN);
break;
}
}
}
}
}
}
}
if (!mode) {
e.getPlayer().setCompassTarget(targetLoc);
e.getPlayer().sendMessage(ChatColor.GOLD + "Compass pointing to " + Mapa.get(e.getPlayer()));
e.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(ChatColor.translateAlternateColorCodes('&', "&3&lX: &b" + target.getLocation().getBlockX() + " &3&lY: &b" + target.getLocation().getBlockY() + " &3&lZ: &b" + target.getLocation().getBlockZ() + " &c&lWorld: &e" + target.getWorld().getName())));
int EnderChance = getConfig().getInt("EnderChance");
if (EnderChance > 0 && EnderChance <= 100) {
if (hasAdvancement(target, "nether/obtain_blaze_rod")) {
if (target.getWorld().getName().equals("world")) {
double EnderChanceDouble = ((double) EnderChance / (double) 100);
double r = rand.nextDouble();
if (r >= 1 - EnderChanceDouble) {
int minimumDist = getConfig().getInt("MinimumDistance");
int maximumX = getConfig().getInt("MaximumDistance");
int maximumZ = getConfig().getInt("MaximumDistance");
int randomX = ThreadLocalRandom.current().nextInt((targetLoc.getBlockX() - maximumX), (targetLoc.getBlockX() + maximumX + 1));
int randomZ = ThreadLocalRandom.current().nextInt((targetLoc.getBlockZ() - maximumZ), (targetLoc.getBlockZ() + maximumZ + 1));
Biome biome = target.getWorld().getBiome(target.getLocation().getBlockX(), target.getLocation().getBlockZ());
if ((biome == Biome.GRAVELLY_MOUNTAINS || biome == Biome.MOUNTAINS || biome == Biome.MOUNTAIN_EDGE || biome == Biome.MODIFIED_GRAVELLY_MOUNTAINS || biome == Biome.SNOWY_MOUNTAINS || biome == Biome.SNOWY_TAIGA_MOUNTAINS || biome == Biome.TAIGA_MOUNTAINS || biome == Biome.ICE_SPIKES || biome == Biome.WOODED_MOUNTAINS || biome == Biome.SHATTERED_SAVANNA) || (target.getLocation().getBlockY() > 120)) {
epsilon = (targetLoc.getBlockY() - 70);
} else {
epsilon = (targetLoc.getBlockY() - 15);
}
Location loc0 = new Location(target.getWorld(), randomX, epsilon, randomZ);
Location loc1 = new Location(target.getWorld(), randomX, epsilon + 1, randomZ);
Location loc2 = new Location(target.getWorld(), randomX, epsilon + 2, randomZ);
while (loc0.distance(targetLoc) < minimumDist) {
randomX = ThreadLocalRandom.current().nextInt((targetLoc.getBlockX() - maximumX), (targetLoc.getBlockX() + maximumX + 1));
randomZ = ThreadLocalRandom.current().nextInt((targetLoc.getBlockZ() - maximumZ), (targetLoc.getBlockZ() + maximumZ + 1));
loc0 = new Location(target.getWorld(), randomX, epsilon, randomZ);
if (loc0.distance(targetLoc) < minimumDist) {
break;
}
}
for (int i = 2; i < 200; ++i) {
++epsilon;
loc0 = new Location(target.getWorld(), randomX, epsilon, randomZ);
loc1 = new Location(target.getWorld(), randomX, epsilon + 1, randomZ);
loc2 = new Location(target.getWorld(), randomX, epsilon + 2, randomZ);
if (loc0.getBlock().getType() == Material.AIR && loc1.getBlock().getType() == Material.AIR && loc2.getBlock().getType() == Material.AIR) {
target.getWorld().spawnEntity(loc0, EntityType.ENDERMAN);
break;
}
}
}
}
}
}
}
} else {
e.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', "&c&lPlayer &4&l" + Mapa.get(e.getPlayer()) + "&c&l is offline"));
}
} else {
e.getPlayer().sendMessage(ChatColor.DARK_RED + "You don't have permission to do that");
}
}
}
}
@EventHandler
public void onNetherEndEnter(PlayerPortalEvent e){
if (Mapa.containsValue(e.getPlayer().getName())){
Location portalLoc = e.getPlayer().getLocation();
new BukkitRunnable(){
@Override
public void run(){
if (e.getPlayer().getWorld().getEnvironment() == World.Environment.NETHER || e.getPlayer().getWorld().getEnvironment() == World.Environment.THE_END){
PortalMap.put(e.getPlayer(), portalLoc);
}
}
}.runTaskLaterAsynchronously(this, 200);
}
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (command.getName().equals("compass")){
if(sender instanceof Player) {
Player player = (Player) sender;
if(player.hasPermission("dreamcompass.use")) {
if (args.length == 0) {
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c&lUse /compass <player> or /compass reload"));
return true;
}
if(args.length == 1) {
String name = args[0];
Player target = Bukkit.getPlayer(name);
if (player.hasPermission("dreamcompass.use")) {
if (args[0].equalsIgnoreCase("help")){
player.sendMessage(ChatColor.translateAlternateColorCodes('&',"&3 Use &c&l/compass <name> &3to get compass, use &c&l/compass reload &3and use &c&l/help &3to get this help message"));
} else {
if (args[0].equalsIgnoreCase("reload")) {
reloadConfig();
getConfig();
saveConfig();
player.sendMessage(ChatColor.DARK_AQUA + "Config reloaded");
} else {
if (target == null) {
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c&lPlayer &4&l" + name + "&c&l is offline"));
return true;
} else {
Mapa.put(player, name);
player.setItemInHand(new ItemStack(Material.COMPASS));
player.setCompassTarget(target.getLocation());
sender.sendMessage(ChatColor.GOLD + "Compass pointing to " + name);
boolean mode = getConfig().getBoolean("DefaultMode");
if (mode){
player.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(ChatColor.translateAlternateColorCodes('&', "&3&lY: &b" + target.getLocation().getBlockY())));
} else{
player.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(ChatColor.translateAlternateColorCodes('&', "&3&lX: &b" + target.getLocation().getBlockX() + " &3&lY: &b" + target.getLocation().getBlockY() + " &3&lZ: &b" + target.getLocation().getBlockZ() + " &c&lWorld: &e" + target.getWorld().getName())));
}
return true;
}
}
}
}
}
return true;
} else {
player.sendMessage(ChatColor.translateAlternateColorCodes('&',"&4&lYou don't have the permission to do that"));
}
return false;
}
return false;
}
return false;
}
}