Skip to content

Commit

Permalink
Fix reloading, improve summon entities checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Aiamded authored Sep 18, 2021
1 parent 2f7d44f commit 3e83e8d
Show file tree
Hide file tree
Showing 12 changed files with 144 additions and 58 deletions.
13 changes: 12 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.dummyperson</groupId>
<artifactId>WeatherEffect</artifactId>
<version>0.4</version>
<version>0.6</version>
<packaging>jar</packaging>

<name>WeatherEffect</name>
Expand Down Expand Up @@ -63,6 +63,11 @@
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
<repository>
<id>codemc-repo</id>
<url>https://repo.codemc.org/repository/maven-public/</url>
<layout>default</layout>
</repository>
</repositories>

<dependencies>
Expand All @@ -78,5 +83,11 @@
<version>1.17.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>de.tr7zw</groupId>
<artifactId>item-nbt-api-plugin</artifactId>
<version>2.8.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
47 changes: 40 additions & 7 deletions src/main/java/me/dummyperson/weathereffect/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,27 @@
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;

import java.util.HashMap;

public final class Main extends JavaPlugin implements CommandExecutor, Listener {

HashMap<String, Boolean> taskCancel = new HashMap<String, Boolean>();

@Override
public void onEnable() {
getServer().getPluginManager().registerEvents(this, this);
// Plugin startup logic
getConfig().options().copyDefaults();
saveDefaultConfig();
reloadConfig();
this.getLogger().info(ChatColor.LIGHT_PURPLE + "[ " + ChatColor.AQUA + "WeathereEffect" + ChatColor.LIGHT_PURPLE + " ]" + ChatColor.AQUA + " ❖ " + ChatColor.GRAY + " Configuration" + ChatColor.AQUA + " ❖ " + ChatColor.GREEN + " Enabled!");
this.getLogger().info(ChatColor.LIGHT_PURPLE + "[ " + ChatColor.AQUA + "WeatherEffect" + ChatColor.LIGHT_PURPLE + " ]" + ChatColor.AQUA + " ❖ " + ChatColor.GRAY + " Loader" + ChatColor.AQUA + " ❖ " + ChatColor.GREEN + " Enabled!");
getCommand("weathereffect").setExecutor(this);
weatherList();
}

@Override
public void onDisable() {
this.getLogger().info(ChatColor.LIGHT_PURPLE + "[ " + ChatColor.AQUA + "WeathereEffect" + ChatColor.LIGHT_PURPLE + " ]" + ChatColor.AQUA + " ❖ " + ChatColor.GRAY + " Configuration" + ChatColor.AQUA + " ❖ " + ChatColor.RED + " Disabled!");
this.getLogger().info(ChatColor.LIGHT_PURPLE + "[ " + ChatColor.AQUA + "WeatherEffect" + ChatColor.LIGHT_PURPLE + " ]" + ChatColor.AQUA + " ❖ " + ChatColor.GRAY + " Loader" + ChatColor.AQUA + " ❖ " + ChatColor.RED + " Disabled!");
// Plugin shutdown logic
}

Expand All @@ -37,27 +41,51 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
if(cmd.getName().equalsIgnoreCase("weathereffect")) {
if(args.length == 0) {
if(sender.hasPermission("weathereffect.player")) {
sender.sendMessage(ChatColor.LIGHT_PURPLE + "[ " + ChatColor.AQUA + "WeathereEffect" + ChatColor.LIGHT_PURPLE + " ]" + ChatColor.AQUA + " ❖ " + ChatColor.GRAY + " Configuration" + ChatColor.AQUA + " ❖ " + ChatColor.RED + " Unknown commands or No permissions...");
sender.sendMessage(ChatColor.LIGHT_PURPLE + "[ " + ChatColor.AQUA + "WeatherEffect" + ChatColor.LIGHT_PURPLE + " ]" + ChatColor.AQUA + " ❖ " + ChatColor.GRAY + " Configuration" + ChatColor.AQUA + " ❖ " + ChatColor.RED + " Unknown commands or No permissions...");
return true;
}
}
if((args.length == 1) && (args[0].equalsIgnoreCase("reload"))) {
if(sender.hasPermission("weathereffect.reload")) {
reloadConfig();
sender.sendMessage(ChatColor.LIGHT_PURPLE + "[ " + ChatColor.AQUA + "WeathereEffect" + ChatColor.LIGHT_PURPLE + " ]" + ChatColor.AQUA + " ❖ " + ChatColor.GRAY + " Configuration" + ChatColor.AQUA + " ❖ " + ChatColor.GREEN + " Reloaded!");
reloadTasks();
sender.sendMessage(ChatColor.LIGHT_PURPLE + "[ " + ChatColor.AQUA + "WeatherEffect" + ChatColor.LIGHT_PURPLE + " ]" + ChatColor.AQUA + " ❖ " + ChatColor.GRAY + " Configuration" + ChatColor.AQUA + " ❖ " + ChatColor.GREEN + " Tasks unloading!! Check console for more information!!");
return true;
}
}
}
return true;
}

public void reloadTasks() {
reloadConfig();
Configuration configuration = getConfig();
ConfigurationSection conf = configuration.getConfigurationSection("enabled-list");
for (String key : conf.getKeys(false)) {
if (!taskCancel.get(key)) {
ConfigurationSection effect = conf.getConfigurationSection(key);
runnable(key, effect, conf);
taskCancel.put(key, true);
Bukkit.getLogger().info(ChatColor.LIGHT_PURPLE + "[ " + ChatColor.AQUA + "WeatherEffect" + ChatColor.LIGHT_PURPLE + " ]" + ChatColor.AQUA + " ❖ " + ChatColor.GRAY + " Unloading " + key + ChatColor.AQUA + " ❖ " + ChatColor.RED + " Please wait!");
} else if (!taskCancel.containsKey(key)) {
Bukkit.getLogger().info(ChatColor.LIGHT_PURPLE + "[ " + ChatColor.AQUA + "WeatherEffect" + ChatColor.LIGHT_PURPLE + " ]" + ChatColor.AQUA + " ❖ " + ChatColor.GRAY + " Loaded New Task: " + key + ChatColor.AQUA + " ❖ " + ChatColor.GREEN + " Successful!");
ConfigurationSection effect = conf.getConfigurationSection(key);
taskCancel.put(key, false);
runnable(key, effect, conf);
}
}
}


public void weatherList() {
Configuration configuration = getConfig();
ConfigurationSection conf = configuration.getConfigurationSection("enabled-list");
for (String key : conf.getKeys(false)) {
ConfigurationSection effect = conf.getConfigurationSection(key);
runnable(key, effect, conf);
if (!taskCancel.containsKey(key)) {
Bukkit.getLogger().info(ChatColor.LIGHT_PURPLE + "[ " + ChatColor.AQUA + "WeatherEffect" + ChatColor.LIGHT_PURPLE + " ]" + ChatColor.AQUA + " ❖ " + ChatColor.GRAY + " Loading Task: " + key + ChatColor.AQUA + " ❖ " + ChatColor.GREEN + " Successful!");
ConfigurationSection effect = conf.getConfigurationSection(key);
taskCancel.put(key, false);
runnable(key, effect, conf);
}
}
}

Expand All @@ -73,6 +101,11 @@ public void run() {
weathertask.criteriaChecker(player, conf, key);
}
}
while (taskCancel.get(key)) {
cancel();
taskCancel.put(key, false);
Bukkit.getLogger().info(ChatColor.LIGHT_PURPLE + "[ " + ChatColor.AQUA + "WeatherEffect" + ChatColor.LIGHT_PURPLE + " ]" + ChatColor.AQUA + " ❖ " + ChatColor.GRAY + " Reloading " + key + ChatColor.AQUA + " ❖ " + ChatColor.GREEN + " Successful!");
}
}
}.runTaskTimer(this, 0, effect.getInt("ticks"));
}
Expand Down
100 changes: 71 additions & 29 deletions src/main/java/me/dummyperson/weathereffect/WeatherEffectTasks.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,66 +226,108 @@ public void entityGenerator(ConfigurationSection summon, Location location) {
@Override
public void checker() {
if (!summon.getStringList("entities").isEmpty()) {
if (summon.getBoolean("groundcheck.enabled")) {
lowestGroundAt();
chance();
}
}

public void chance() {
if (new Random().nextInt(100) < summon.getInt("chance")) {
blockAbove();
}
}

public void blockAbove() {
if (summon.getBoolean("blockabovecheck")) {
if (!checker.blockAbove(randoLoc)) {
groundCheck();
}
} else {
groundCheck();
}
}

public void lowestGroundAt() {
Location checking = randoLoc;
public void groundCheck() {
if (summon.getBoolean("groundcheck")) {
lowestGroundAt();
} else {
airCheck(null);
}
}
public void lowestGroundAt () {
for (int i = 0; i < summon.getInt("groundcheck.depth"); i++) {
if (!summon.getStringList("blocktypes").isEmpty() & summon.getStringList("blocktypes").contains(checker.blockCheck(checking))) {
Location checking = randoLoc;
if (!summon.getStringList("blocktypes").isEmpty() && summon.getStringList("blocktypes").contains(checker.blockCheck(checking)) && checker.blockAbove(checking.add(0,1,0))) {
checking.add(0, -1,0);
} else if (!summon.getStringList("blocktypes").isEmpty() && summon.getStringList("blocktypes").contains(checker.blockCheck(checking)) && checker.blockAbove(checking.add(0,1,0))) {
lowestBlockVerify(i, checking);
}
}
}

public void lowestBlockVerify(int i, Location checking) {
if (i <= (summon.getInt("aircheck.height") - 1)) {
airCheck(checking);
}
}

public void airCheck (Location checking) {
Location airChecking = checking;
if (summon.getBoolean("aircheck.enabled") & summon.getStringList("blocktypes").contains(checker.blockCheck(airChecking))) {
for (int i = 0; i < summon.getInt("aircheck.height"); i++) {
if (!summon.getStringList("blocktypes").isEmpty() & summon.getStringList("blocktypes").contains(checker.blockCheck(airChecking))) {
airChecking.add(0, 1,0);
radiusVerify(i, checking);
public void airCheck(Location checking) {
if (summon.getBoolean("aircheck.enabled")) {
if (checking == null) {
if (summon.getStringList("blocktypes").contains(checker.blockCheck(randoLoc))) {
Location airChecking = randoLoc;
for (int i = 0; i < summon.getInt("aircheck.height"); i++) {
if (!summon.getStringList("blocktypes").isEmpty() && summon.getStringList("blocktypes").contains(checker.blockCheck(airChecking))) {
airChecking.add(0, 1,0);
radiusVerify(i, airChecking);
} else if (summon.getStringList("blocktypes").isEmpty()) {
summoning(randoLoc);
}
}
}
} else if (checking != null) {
if (summon.getStringList("blocktypes").contains(checker.blockCheck(checking))) {
Location airChecking = checking;
for (int i = 0; i < summon.getInt("aircheck.height"); i++) {
if (!summon.getStringList("blocktypes").isEmpty() && summon.getStringList("blocktypes").contains(checker.blockCheck(airChecking))) {
airChecking.add(0, 1, 0);
radiusVerify(i, checking);
} else if (summon.getStringList("blocktypes").isEmpty()) {
summoning(checking);
}
}
}
}
} else if (!summon.getBoolean("aircheck.enabled")) {
lowestGroundAt();
} else {
summoning(randoLoc);
}
}

public void preSummon(Location newLoc){
if (new Random().nextInt(100) < summon.getInt("chance")) {
summoning(summon.getStringList("entities"), newLoc);
public void radiusVerify (int i, Location newLoc) {
if (i == (summon.getInt("aircheck.height") - 1)) {
summoning(newLoc);
}
}

public void summoning(List<String> list, Location newLoc) {
public void summoning(Location newLoc) {
List<String> list = summon.getStringList("entities");
Random rand = new Random();
String entityname = list.get(rand.nextInt(list.size()));
org.bukkit.entity.Entity entity = randoLoc.getWorld().spawnEntity(randoLoc, EntityType.valueOf(entityname));
//nbtTags(entity, newLoc);
NBTEntity nbtent = new NBTEntity(entity);
//Bukkit.getLogger().info(String.valueOf(nbtent));
nbtent.setByte("CanPickUpLoot", (byte) 1);

if (summon.getBoolean("entities-spawned-loggings")) {
Bukkit.getLogger().info(ChatColor.LIGHT_PURPLE + "[ " + ChatColor.AQUA + "WeathereEffect" + ChatColor.LIGHT_PURPLE + " ]" + ChatColor.AQUA + " ❖ " + ChatColor.GRAY + entity.getName() + " spawned at x: " + newLoc.getBlockX() + " y: " + newLoc.getBlockY() + " z: " + newLoc.getBlockZ());
Bukkit.getLogger().info(ChatColor.LIGHT_PURPLE + "[ " + ChatColor.AQUA + "WeatherEffect" + ChatColor.LIGHT_PURPLE + " ]" + ChatColor.AQUA + " ❖ " + ChatColor.GRAY + entity.getName() + " spawned at x: " + newLoc.getBlockX() + " y: " + newLoc.getBlockY() + " z: " + newLoc.getBlockZ());
}
}

public void lowestBlockVerify(int i, Location checking) {
if (i <= (summon.getInt("aircheck.height") - 1)) {
airCheck(checking);
}
public void nbtTags(org.bukkit.entity.Entity entity, Location newLoc) {
//Bukkit.getLogger().info(String.valueOf(nbtent));

}

public void radiusVerify (int i, Location newLoc) {
if (i == (summon.getInt("aircheck.height") - 1)) {
preSummon(newLoc);
}
public void attributes() {

}
};
check.checker();
Expand Down
16 changes: 8 additions & 8 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
enabled-list:
sandstorm:
ticks: 1
attempts: 50
attempts: 2
weathertypes:
- rain
biomescheck: true
Expand All @@ -18,14 +18,14 @@ enabled-list:
types:
- FALLING_DUST
particledata: SAND
delta-x: 1
delta-y: 1
delta-z: 1
delta-x: 2
delta-y: 2
delta-z: 2
speed: 0
count: 2
count: 4
radius: 5
force: false
chances: 80
force: true
chances: 100
effects:
enabled: true
blockabovecheck: true
Expand All @@ -44,7 +44,7 @@ enabled-list:
pitch: 0.25
radius: 15
volume: 0.2
chance: 10
chance: 50
summon:
enabled: false
blockabovecheck: true
Expand Down
20 changes: 10 additions & 10 deletions target/classes/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
enabled-list:
sandstorm:
ticks: 1
attempts: 50
attempts: 2
weathertypes:
- rain
biomescheck: true
Expand All @@ -18,14 +18,14 @@ enabled-list:
types:
- FALLING_DUST
particledata: SAND
delta-x: 1
delta-y: 1
delta-z: 1
delta-x: 2
delta-y: 2
delta-z: 2
speed: 0
count: 2
count: 4
radius: 5
force: false
chances: 80
force: true
chances: 100
effects:
enabled: true
blockabovecheck: true
Expand All @@ -44,7 +44,7 @@ enabled-list:
pitch: 0.25
radius: 15
volume: 0.2
chance: 10
chance: 50
summon:
enabled: false
blockabovecheck: true
Expand Down Expand Up @@ -76,8 +76,8 @@ enabled-list:
#turned 0 to disable since the tickrate and attempts are too high even the chance = 1 still spawn to many entities
chance: 1
sandstorm-entity:
ticks: 1
attempts: 50
ticks: 20
attempts: 1
weathertypes:
- rain
biomescheck: true
Expand Down
Binary file modified target/classes/me/dummyperson/weathereffect/Main$1.class
Binary file not shown.
Binary file modified target/classes/me/dummyperson/weathereffect/Main.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion target/classes/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: WeatherEffect
version: 0.5
version: 0.6
main: me.dummyperson.weathereffect.Main
api-version: 1.17
authors: [ Dummyperson, Aiamded, Kh Destruction ]
Expand Down
4 changes: 2 additions & 2 deletions target/maven-archiver/pom.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Generated by Maven
#Fri Sep 17 01:35:13 GMT+10:00 2021
#Fri Sep 17 14:15:42 GMT+10:00 2021
groupId=me.dummyperson
artifactId=WeatherEffect
version=0.5
version=0.6

0 comments on commit 3e83e8d

Please sign in to comment.