Skip to content

Commit 3c3e436

Browse files
committed
Initial commit
1 parent 5d3d9f3 commit 3c3e436

File tree

6 files changed

+411
-0
lines changed

6 files changed

+411
-0
lines changed
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
package com.leontg77.biomeparanoia;
2+
3+
import org.bukkit.ChatColor;
4+
import org.bukkit.block.Biome;
5+
6+
/**
7+
* Biome utils class.
8+
* <p>
9+
* Used for checking if a biome should be shown in /bl and getting the biome color.
10+
*
11+
* @author LeonTG77
12+
*/
13+
public class BiomeUtils {
14+
15+
/**
16+
* Get the color of the given biome.
17+
*
18+
* @param biome the given biome.
19+
* @return The biome color in string format.
20+
*/
21+
public static String biomeColor(Biome biome) {
22+
switch (biome) {
23+
case BEACH:
24+
return ChatColor.YELLOW.toString() + ChatColor.ITALIC;
25+
case BIRCH_FOREST:
26+
return ChatColor.YELLOW.toString() + ChatColor.BOLD;
27+
case BIRCH_FOREST_HILLS:
28+
return ChatColor.YELLOW.toString() + ChatColor.BOLD;
29+
case BIRCH_FOREST_HILLS_MOUNTAINS:
30+
return ChatColor.YELLOW.toString() + ChatColor.BOLD;
31+
case BIRCH_FOREST_MOUNTAINS:
32+
return ChatColor.YELLOW.toString() + ChatColor.BOLD;
33+
case COLD_BEACH:
34+
return ChatColor.YELLOW.toString() + ChatColor.ITALIC;
35+
case COLD_TAIGA:
36+
return ChatColor.BLUE.toString();
37+
case COLD_TAIGA_HILLS:
38+
return ChatColor.BLUE.toString();
39+
case COLD_TAIGA_MOUNTAINS:
40+
return ChatColor.BLUE.toString();
41+
case DEEP_OCEAN:
42+
return ChatColor.DARK_BLUE.toString();
43+
case DESERT:
44+
return ChatColor.YELLOW.toString();
45+
case DESERT_HILLS:
46+
return ChatColor.YELLOW.toString();
47+
case DESERT_MOUNTAINS:
48+
return ChatColor.YELLOW.toString();
49+
case EXTREME_HILLS:
50+
return ChatColor.GRAY.toString();
51+
case EXTREME_HILLS_MOUNTAINS:
52+
return ChatColor.GRAY.toString();
53+
case EXTREME_HILLS_PLUS:
54+
return ChatColor.GRAY.toString();
55+
case EXTREME_HILLS_PLUS_MOUNTAINS:
56+
return ChatColor.GRAY.toString();
57+
case FLOWER_FOREST:
58+
return ChatColor.DARK_GREEN.toString();
59+
case FOREST:
60+
return ChatColor.DARK_GREEN.toString();
61+
case FOREST_HILLS:
62+
return ChatColor.DARK_GREEN.toString();
63+
case FROZEN_OCEAN:
64+
return ChatColor.DARK_BLUE.toString();
65+
case FROZEN_RIVER:
66+
return ChatColor.AQUA.toString();
67+
case HELL:
68+
return ChatColor.RED.toString();
69+
case ICE_MOUNTAINS:
70+
return ChatColor.WHITE.toString();
71+
case ICE_PLAINS:
72+
return ChatColor.WHITE.toString();
73+
case ICE_PLAINS_SPIKES:
74+
return ChatColor.WHITE.toString() + ChatColor.ITALIC;
75+
case JUNGLE:
76+
return ChatColor.GREEN.toString() + ChatColor.BOLD;
77+
case JUNGLE_EDGE:
78+
return ChatColor.GREEN.toString() + ChatColor.BOLD;
79+
case JUNGLE_EDGE_MOUNTAINS:
80+
return ChatColor.GREEN.toString() + ChatColor.BOLD;
81+
case JUNGLE_HILLS:
82+
return ChatColor.GREEN.toString() + ChatColor.BOLD;
83+
case JUNGLE_MOUNTAINS:
84+
return ChatColor.GREEN.toString() + ChatColor.BOLD;
85+
case MEGA_SPRUCE_TAIGA:
86+
return ChatColor.BLUE.toString() + ChatColor.BOLD;
87+
case MEGA_SPRUCE_TAIGA_HILLS:
88+
return ChatColor.BLUE.toString() + ChatColor.BOLD;
89+
case MEGA_TAIGA:
90+
return ChatColor.BLUE.toString() + ChatColor.BOLD;
91+
case MEGA_TAIGA_HILLS:
92+
return ChatColor.BLUE.toString() + ChatColor.BOLD;
93+
case MESA:
94+
return ChatColor.DARK_RED.toString();
95+
case MESA_BRYCE:
96+
return ChatColor.DARK_RED.toString();
97+
case MESA_PLATEAU:
98+
return ChatColor.DARK_RED.toString();
99+
case MESA_PLATEAU_FOREST:
100+
return ChatColor.DARK_RED.toString();
101+
case MESA_PLATEAU_FOREST_MOUNTAINS:
102+
return ChatColor.DARK_RED.toString();
103+
case MESA_PLATEAU_MOUNTAINS:
104+
return ChatColor.DARK_RED.toString();
105+
case MUSHROOM_ISLAND:
106+
return ChatColor.GRAY.toString() + ChatColor.ITALIC;
107+
case MUSHROOM_SHORE:
108+
return ChatColor.GRAY.toString() + ChatColor.ITALIC;
109+
case OCEAN:
110+
return ChatColor.DARK_BLUE.toString();
111+
case PLAINS:
112+
return ChatColor.GREEN.toString();
113+
case RIVER:
114+
return ChatColor.AQUA.toString();
115+
case ROOFED_FOREST:
116+
return ChatColor.DARK_GREEN.toString() + ChatColor.BOLD;
117+
case ROOFED_FOREST_MOUNTAINS:
118+
return ChatColor.DARK_GREEN.toString() + ChatColor.BOLD;
119+
case SAVANNA:
120+
return ChatColor.GOLD.toString();
121+
case SAVANNA_MOUNTAINS:
122+
return ChatColor.GOLD.toString();
123+
case SAVANNA_PLATEAU:
124+
return ChatColor.GOLD.toString();
125+
case SAVANNA_PLATEAU_MOUNTAINS:
126+
return ChatColor.GOLD.toString();
127+
case SKY:
128+
return ChatColor.BLACK.toString();
129+
case SMALL_MOUNTAINS:
130+
return ChatColor.GRAY.toString();
131+
case STONE_BEACH:
132+
return ChatColor.GRAY.toString();
133+
case SUNFLOWER_PLAINS:
134+
return ChatColor.GREEN.toString();
135+
case SWAMPLAND:
136+
return ChatColor.DARK_GRAY.toString();
137+
case SWAMPLAND_MOUNTAINS:
138+
return ChatColor.DARK_GRAY.toString();
139+
case TAIGA:
140+
return ChatColor.DARK_AQUA.toString();
141+
case TAIGA_HILLS:
142+
return ChatColor.DARK_AQUA.toString();
143+
case TAIGA_MOUNTAINS:
144+
return ChatColor.DARK_AQUA.toString();
145+
default:
146+
return null;
147+
}
148+
}
149+
150+
/**
151+
* Check if the given biome can be sent in a message.
152+
*
153+
* @param biome the biome checking.
154+
* @return <code>True</code> if the biome is sendable, <code>false</code> otherwise.
155+
*/
156+
public static boolean isSendable(Biome biome) {
157+
switch (biome) {
158+
case BEACH:
159+
case BIRCH_FOREST:
160+
case COLD_TAIGA:
161+
case DESERT:
162+
case EXTREME_HILLS:
163+
case FLOWER_FOREST:
164+
case FOREST:
165+
case HELL:
166+
case ICE_PLAINS:
167+
case ICE_PLAINS_SPIKES:
168+
case JUNGLE:
169+
case MEGA_TAIGA:
170+
case MESA:
171+
case MUSHROOM_ISLAND:
172+
case OCEAN:
173+
case PLAINS:
174+
case RIVER:
175+
case ROOFED_FOREST:
176+
case SAVANNA:
177+
case SKY:
178+
case SUNFLOWER_PLAINS:
179+
case SWAMPLAND:
180+
case TAIGA:
181+
return true;
182+
default:
183+
return false;
184+
}
185+
}
186+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.leontg77.biomeparanoia;
2+
3+
import org.bukkit.plugin.PluginDescriptionFile;
4+
import org.bukkit.plugin.java.JavaPlugin;
5+
6+
import com.leontg77.biomeparanoia.cmds.BParanoiaCommand;
7+
import com.leontg77.biomeparanoia.cmds.BlCommand;
8+
9+
/**
10+
* Main class of the plugin.
11+
*
12+
* @author LeonTG77
13+
*/
14+
public class Main extends JavaPlugin {
15+
public static Main plugin;
16+
17+
public static final String PREFIX = "§7[§6BP§7] §f";
18+
public static boolean enabled = false;
19+
20+
@Override
21+
public void onDisable() {
22+
// print a message to the console saying it has been disabled.
23+
PluginDescriptionFile file = getDescription();
24+
getLogger().info(file.getName() + " has been disabled.");
25+
26+
// set the plugin field to null.
27+
plugin = null;
28+
}
29+
30+
@Override
31+
public void onEnable() {
32+
// print a message to the console saying it has been enabled.
33+
PluginDescriptionFile file = getDescription();
34+
getLogger().info(file.getName() + " v" + file.getVersion() + " has been enabled.");
35+
getLogger().info("Plugin is made by LeonTG77.");
36+
37+
// register the /bl and /bparanoia commands.
38+
getCommand("bl").setExecutor(new BlCommand());
39+
getCommand("bparanoia").setExecutor(new BParanoiaCommand());
40+
41+
// set the plugin field to this class.
42+
plugin = this;
43+
}
44+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package com.leontg77.biomeparanoia.cmds;
2+
3+
import org.bukkit.Bukkit;
4+
import org.bukkit.ChatColor;
5+
import org.bukkit.command.Command;
6+
import org.bukkit.command.CommandExecutor;
7+
import org.bukkit.command.CommandSender;
8+
import org.bukkit.event.HandlerList;
9+
import org.bukkit.plugin.PluginManager;
10+
11+
import com.leontg77.biomeparanoia.Main;
12+
import com.leontg77.biomeparanoia.listeners.MoveListener;
13+
14+
/**
15+
* BParanoia command.
16+
* <p>
17+
* Command used to enable or disable the scenario.
18+
*
19+
* @author LeonTG77
20+
*/
21+
public class BParanoiaCommand implements CommandExecutor {
22+
private static final String PERMISSION = "bparanoia.manage";
23+
private MoveListener move = new MoveListener();
24+
25+
@Override
26+
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
27+
// check if the have permission, if not send them a message and return.
28+
if (!sender.hasPermission(PERMISSION)) {
29+
sender.sendMessage(Main.PREFIX + ChatColor.RED + "You don't have access to this.");
30+
return true;
31+
}
32+
33+
// check if they typed anything else than the command itself, if not send usage and return.
34+
if (args.length == 0) {
35+
sender.sendMessage(Main.PREFIX + "Usage: /bparanoia <enable|disable>");
36+
return true;
37+
}
38+
39+
// check if they typed /egg enable, if so do the command.
40+
if (args[0].equalsIgnoreCase("enable")) {
41+
// check if the scenario is enabled, if not tell them so and return.
42+
if (Main.enabled) {
43+
sender.sendMessage(Main.PREFIX + "BiomeParanoia is already enabled.");
44+
return true;
45+
}
46+
47+
// send them a message and set enabled to be true
48+
sender.sendMessage(Main.PREFIX + "BiomeParanoia has been enabled.");
49+
Main.enabled = true;
50+
51+
// register the eventhandles for the scenario.
52+
PluginManager manager = Bukkit.getPluginManager();
53+
manager.registerEvents(move, Main.plugin);
54+
return true;
55+
}
56+
57+
// check if they typed /egg enable, if so do the command.
58+
if (args[0].equalsIgnoreCase("disable")) {
59+
// check if the scenario wasn't enabled, if not tell them so and return.
60+
if (!Main.enabled) {
61+
sender.sendMessage(Main.PREFIX + "BiomeParanoia is not enabled.");
62+
return true;
63+
}
64+
65+
// send them a message and set enabled to be false
66+
sender.sendMessage(Main.PREFIX + "BiomeParanoia has been disabled.");
67+
Main.enabled = false;
68+
69+
// unregister the eventhandles for the scenario.
70+
HandlerList.unregisterAll(move);
71+
return true;
72+
}
73+
74+
// they didn't type enable or disable, send usage.
75+
sender.sendMessage(Main.PREFIX + "Usage: /bparanoia <enable|disable>");
76+
return true;
77+
}
78+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.leontg77.biomeparanoia.cmds;
2+
3+
import org.bukkit.block.Biome;
4+
import org.bukkit.command.Command;
5+
import org.bukkit.command.CommandExecutor;
6+
import org.bukkit.command.CommandSender;
7+
8+
import com.leontg77.biomeparanoia.BiomeUtils;
9+
import com.leontg77.biomeparanoia.Main;
10+
11+
/**
12+
* Bl command.
13+
* <p>
14+
* Command getting a list of all biome colors.
15+
*
16+
* @author LeonTG77
17+
*/
18+
public class BlCommand implements CommandExecutor {
19+
20+
@Override
21+
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
22+
// if the plugin is disabled, tell them so and return.
23+
if (!Main.enabled) {
24+
sender.sendMessage(Main.PREFIX + "BiomeParanoia is not enabled.");
25+
return true;
26+
}
27+
28+
StringBuilder biomes = new StringBuilder();
29+
30+
// loop thru all biomes.
31+
for (Biome b : Biome.values()) {
32+
// the biome isn't sendable (Like it has multiple with the same name,
33+
// ex ExtremeHills and ExtremeHills+ that are the same color.
34+
if (!BiomeUtils.isSendable(b)) {
35+
continue;
36+
}
37+
38+
// add ,'s between every biome.
39+
if (biomes.length() > 0) {
40+
biomes.append("§f, ");
41+
}
42+
43+
// add the biome with its color to the strinbuilder.
44+
biomes.append(BiomeUtils.biomeColor(b) + b.name().substring(0, 1).toUpperCase() + b.name().substring(1).toLowerCase().replaceAll("_", " "));
45+
}
46+
47+
// send them the biomes.
48+
sender.sendMessage(Main.PREFIX + "List of all biome colors:");
49+
sender.sendMessage(biomes.toString().trim());
50+
return true;
51+
}
52+
}

0 commit comments

Comments
 (0)