summaryrefslogtreecommitdiff
path: root/src/main/java/com/redstoner/modules/tilechunks/TileChunks.java
blob: a32f05ef14c5e55f78c5bb0ec4d7450f32c7161b (plain)
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
package com.redstoner.modules.tilechunks;

import java.util.ArrayList;
import java.util.List;

import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import com.nemez.cmdmgr.Command;
import com.nemez.cmdmgr.Command.AsyncType;
import com.redstoner.annotations.Commands;
import com.redstoner.annotations.Version;
import com.redstoner.misc.CommandHolderType;
import com.redstoner.modules.Module;

@Commands(CommandHolderType.File)
@Version(major = 5, minor = 0, revision = 0, compatible = 4)
public class TileChunks implements Module
{
	private List<LaggyTileChunk> laggyChunks = new ArrayList<>();
	
	private void scan(int amount)
	{
		laggyChunks.clear();
		for (World world : Bukkit.getServer().getWorlds())
		{
			for (Chunk chunk : world.getLoadedChunks())
			{
				int amount2 = chunk.getTileEntities().length;
				if (amount2 > amount)
				{
					Location entLoc = chunk.getTileEntities()[0].getLocation();
					laggyChunks.add(new LaggyTileChunk(entLoc.getBlockX(), entLoc.getBlockY(), entLoc.getBlockZ(),
							world, amount2));
				}
			}
		}
	}
	
	@Command(hook = "list_cmd")
	public void list(CommandSender sender)
	{
		if (laggyChunks.size() > 0)
		{
			ArrayList<String> message = new ArrayList<>();
			for (LaggyTileChunk lc : laggyChunks)
			{
				message.add("§b[§a" + laggyChunks.indexOf(lc) + "§b]: §a" + lc.x + "§7, §a" + lc.y + "§7, §a" + lc.z
						+ " §7(" + lc.world.getName() + ") §a- §b" + lc.amount + " tile entities");
			}
			message.add("§2-------------------");
			getLogger().message(sender, message.toArray(new String[] {}));
		}
		else
			getLogger().message(sender, true, "Couldn't find any chunks with that many tile entities.");
	}
	
	@Command(hook = "scan_cmd", async = AsyncType.ALWAYS)
	public void scan_cmd(CommandSender sender, int amount)
	{
		scan(amount);
		list(sender);
	}
	
	@Command(hook = "tp")
	public void tp(CommandSender sender, int number)
	{
		Player player = (Player) sender;
		if (number < laggyChunks.size())
		{
			player.teleport(laggyChunks.get(number).getLocation());
			getLogger().message(player, "§aTeleported to chunk " + number + "!");
		}
		else
		{
			getLogger().message(sender, true, "§4Invalid chunk number! Use §e/lc list §4to show laggy chunks!");
		}
	}
}