Skip to content

Commit

Permalink
Register Command and add Potion Effect
Browse files Browse the repository at this point in the history
  • Loading branch information
Aiamded authored Sep 16, 2021
1 parent 05fd412 commit 08d1052
Show file tree
Hide file tree
Showing 15 changed files with 237 additions and 43 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<modelVersion>4.0.0</modelVersion>

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

<name>WeatherEffect</name>
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/me/dummyperson/weathereffect/Checker.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,8 @@ public String airCheck (Location location) {
String airchecker = location.getBlock().getType().name();
return airchecker;
}

public Boolean groundCheck (Location location, int chances) {
return false;
}
}
40 changes: 21 additions & 19 deletions src/main/java/me/dummyperson/weathereffect/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;

public final class Main extends JavaPlugin implements Listener {
public final class Main extends JavaPlugin implements CommandExecutor, Listener {

@Override
public void onEnable() {
Expand All @@ -19,35 +20,36 @@ public void onEnable() {
saveDefaultConfig();
runnable();
reloadConfig();
this.getLogger().info("&bWeathereEffect Enabled!");
this.getLogger().info(ChatColor.LIGHT_PURPLE + "[ " + ChatColor.AQUA + "WeathereEffect" + ChatColor.LIGHT_PURPLE + " ]" + ChatColor.GREEN + " ⁑ Enabled!");
getCommand("weathereffect").setExecutor(this);
}

@Override
public void onDisable() {
this.getLogger().info("&4WeathereEffect Disabled!");
this.getLogger().info(ChatColor.LIGHT_PURPLE + "[ " + ChatColor.AQUA + "WeathereEffect" + ChatColor.LIGHT_PURPLE + " ]" + ChatColor.RED + " ⁑ Disabled!");
// Plugin shutdown logic
}

public boolean onCommand(CommandSender sender, Command command, String alias, String[] args) {
Player player = (Player) sender;
if (!sender.hasPermission("weathereffect.reload") || !sender.isOp()) {
if (alias.equalsIgnoreCase("weathereffect")) {
if (args.length == 0) {
sender.sendMessage(ChatColor.GREEN + "To reload do /weathereffect reload");
} else if (args[0].equalsIgnoreCase("reload")) {
saveDefaultConfig();
reloadConfig();
sender.sendMessage(ChatColor.GREEN + "WeatherEffect reloaded!");

public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
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.RED + " ⁑ Unknown commands or No permissions...");
return true;
}
else {
sender.sendMessage(ChatColor.RED + "Unknown Command");
}
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.GREEN + " ⁑ Reloaded!");
return true;
}
}
} else {
sender.sendMessage(ChatColor.RED + "Permission Denied!");
}
return false;
};
return true;
}


public void runnable() {
new BukkitRunnable() {
Expand Down
44 changes: 34 additions & 10 deletions src/main/java/me/dummyperson/weathereffect/WeatherEffectTask.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package me.dummyperson.weathereffect;

import com.destroystokyo.paper.ParticleBuilder;
import net.minecraft.server.commands.CommandPlaySound;
import org.bukkit.*;
import org.bukkit.configuration.Configuration;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.NotNull;


import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import java.util.Random;

Expand All @@ -26,10 +29,14 @@ public void criteriaChecker(Player player, Configuration configuration) {
boolean biomesCheck = effect.getBoolean("biomes-check");
ConfigurationSection particle = effect.getConfigurationSection("particle");
ConfigurationSection sound = effect.getConfigurationSection("sound");
ConfigurationSection summon = effect.getConfigurationSection("summon");
ConfigurationSection effects = effect.getConfigurationSection("effects");
List<String> biomes = effect.getStringList("biomes");
if (checker.weatherCheck(player).equals(weather) & biomes.contains(biome) & biomesCheck){
spawnParticles(particle, player.getLocation(), player);
soundGenerator(sound, player.getLocation(), player);
effectgiver(effects, player.getLocation(), player);
entitygenerator(summon, player.getLocation(), player);
}
}
}
Expand All @@ -48,40 +55,40 @@ public void spawnParticles(ConfigurationSection particle, Location location, Pla
Blockabovecheck check = new Blockabovecheck() {
public void checker() {
if (particle.getBoolean("blockabovecheck")) {
blockabovechecking();
blockAboveChecking();
} else if (!particle.getBoolean("blockabovecheck")) {
if (checker.skylightChance(randoLoc, particle.getInt("chances"))) {
spawnParticlesPassed(particle, randoLoc, player);
} else {
// Bruh Attempt Fails
retryonfail();
retryOnFail();
}
} else {
retryonfail();
retryOnFail();
}
}

public void blockabovechecking() {
public void blockAboveChecking() {
if (!checker.blockAbove(randoLoc)) {
spawnParticlesPassed(particle, randoLoc, player);
} else if (checker.blockAbove(randoLoc)){
//Do not attempt to spawn particle again if there's a block above
//retryonfail();
//retryOnFail();
} else {

}
}

public void retryonfail() {
public void retryOnFail() {
double max = particle.getInt("radius");
double min = -particle.getInt("radius");
double x = (rando(min, max));
double y = (rando(min, max));
double z = (rando(min, max));
Location randoLoc = location.add(x, y, z);
airchecking(randoLoc);
airChecking(randoLoc);
}
public void airchecking(Location randoLoc) {
public void airChecking(Location randoLoc) {
if (particle.getBoolean("aircheck")) {
if (particle.getList("blocktypes").contains(checker.airCheck(randoLoc))) {
checker();
Expand Down Expand Up @@ -162,7 +169,24 @@ public void checker() {
check.checker();
}

public void entitygenerator() {
public void entitygenerator(ConfigurationSection summon, Location location, Player player) {

}

public void effectgiver(ConfigurationSection effects, Location location, Player player) {
int duration = effects.getInt("duration");
int amplifier= effects.getInt("amplifier");
Boolean ambient = effects.getBoolean("isambient");
Boolean particles = effects.getBoolean("effectparticle");
Enumeration<String> e = Collections.enumeration(effects.getStringList("types"));
while(e.hasMoreElements()) {
int type = (Integer.parseInt(e.nextElement())) -1;
int a = new Random().nextInt(100);
if (a <= effects.getInt("chance")) {
PotionEffect potion = new PotionEffect(PotionEffectType.values()[type], duration, amplifier, ambient, particles);
player.addPotionEffect(potion);
}
}
}

}
83 changes: 79 additions & 4 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ enabled-weather:
aircheck: true
blocktypes:
- AIR
- UNKNOWN
#particle name to send
#https://papermc.io/javadocs/paper/1.17/org/bukkit/Particle.html
name: FALLING_DUST
Expand All @@ -53,10 +52,86 @@ enabled-weather:
# **** options below not available yet ****
#Effects given to players
effects:
- blind
#https://gamedb.gg/games/minecraft/potion-effect-ids/
types:
- 1
#Effect cooldown. Will be reapplied with interval
#Like Players still blind for a while when they left the storm. Cause they need to wash their eyes xd.
duration: 60
amplifier: 1
isambient: false
effectparticle: false
chance: 100
#Play sound at the location of where the particle spawned
sound:
blockabovecheck: true
#https://papermc.io/javadocs/paper/1.16/org/bukkit/Sound.html
name: ENTITY_HORSE_BREATHE
pitch: 1
radius: 20
volume: 1
chance: 100
summon:
mobs:
- zombies
- skeleton
groundtype:
radius:
chance: 5
snowvariant:
#thunder, rain, clear
#not sure if thunder check is working use rain or clear
weathertype: rain
blockstate:
#Check if particles should only be spawned inside a biome
biomes-check: true
#list of biome names. Ex: minecraft:badlands, terralith:mirage_isles <-- Datapack Biome name
biomes:
- terralith:mirage_isles
- terralith:amethyst_rainforest
- minecraft:badlands
#More information for particles
#https://minecraft.fandom.com/wiki/Particles
particle:
blockabovecheck: true
#valid block types for air checking can be any material
aircheck: true
blocktypes:
- AIR
#particle name to send
#https://papermc.io/javadocs/paper/1.17/org/bukkit/Particle.html
name: FALLING_DUST
#Leave this alone if not using falling_dust
particledata: SAND
#particles movement when spawned
delta-x: 0
delta-y: 0
delta-z: 0
#particle speed
speed: 0.25
#particle count
count: 5
#How many blocks from player's current location can the particles spawned up to.
radius: 50
#force spawning particles if true otherwise it will spawn within where player looking at.
force: true
#Skylight level 0-15 depends on where particle spawned at not player skylightlevel.
#If chances 100, any area with light level 15 will have particles spawned
#chance = Skylightlevel * 100
chances: 100
# **** options below not available yet ****
#Effects given to players
effects:
#https://gamedb.gg/games/minecraft/potion-effect-ids/
types:
- 1
#Effect cooldown. Will be reapplied with interval
#Like Players still blind for a while when they left the storm. Cause they need to wash their eyes xd.
cooldown: 4
#Like Players still blind for a while when they left the storm. Cause they need to wash their eyes xd.
duration: 60
amplifier: 1
isambient: false
effectparticle: false
chance: 100
#Play sound at the location of where the particle spawned
sound:
blockabovecheck: true
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ api-version: 1.17
authors: [ Dummyperson ]
description: Generate Customizable Particle at certain biomes. Support for Datapack.
website: www.breadstick.info

commands:
weathereffect:
description: WeatherEffect reload command
permission: weathereffect.player
usage: /<command>
Loading

0 comments on commit 08d1052

Please sign in to comment.