Haha reflection go brrrrr

This commit is contained in:
Edith Boles 2021-10-04 10:40:44 -07:00
parent 97433f7c8a
commit 5d45ee8799
3 changed files with 56 additions and 38 deletions

View File

@ -24,6 +24,11 @@
<version>1.8.8-R0.1-SNAPSHOT</version> <version>1.8.8-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.9-RC1</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory> <sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>

View File

@ -1,10 +1,13 @@
package top.penowl.quidproquo; package top.penowl.quidproquo;
import java.lang.reflect.Constructor;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.reflections.Reflections;
import top.penowl.quidproquo.rituals.*; import top.penowl.quidproquo.rituals.*;
@ -30,38 +33,50 @@ public class QuidProQuo extends JavaPlugin {
getLogger().info("Loading rituals..."); getLogger().info("Loading rituals...");
getServer().getPluginManager().registerEvents(new Events(), this); getServer().getPluginManager().registerEvents(new Events(), this);
Set<Class<? extends Ritual>> subClasses = (new Reflections()).getSubTypesOf(Ritual.class);
for (Class<? extends Ritual> ritualClass : subClasses) {
Class<?>[] params = {};
try {
Constructor<? extends Ritual> constructor = ritualClass.getConstructor(params);
Object[] args = {};
rituals.add(constructor.newInstance(args));
} catch (Exception e) {
}
}
// register all rituals // register all rituals
rituals.add(new AnvilRitual()); // rituals.add(new AnvilRitual());
rituals.add(new BatSpewRitual()); // rituals.add(new BatSpewRitual());
rituals.add(new BlockShiftRitual()); // rituals.add(new BlockShiftRitual());
rituals.add(new ChickenSpewRitual()); // rituals.add(new ChickenSpewRitual());
rituals.add(new ChugJugRitual()); // rituals.add(new ChugJugRitual());
rituals.add(new CreeperHissRitual()); // rituals.add(new CreeperHissRitual());
rituals.add(new CrystalizationRtiual()); // rituals.add(new CrystalizationRtiual());
rituals.add(new DragonRitual()); // rituals.add(new DragonRitual());
rituals.add(new FakePlayerRitual()); // rituals.add(new FakePlayerRitual());
rituals.add(new FeedingRitual()); // rituals.add(new FeedingRitual());
rituals.add(new FillerRitual()); // rituals.add(new FillerRitual());
rituals.add(new GBJRitual()); // rituals.add(new GBJRitual());
rituals.add(new GetLuckyRitual()); // rituals.add(new GetLuckyRitual());
rituals.add(new HardPenorRitual()); // rituals.add(new HardPenorRitual());
rituals.add(new HealRitual()); // rituals.add(new HealRitual());
rituals.add(new HerobrineRitual()); // rituals.add(new HerobrineRitual());
rituals.add(new HitRitual()); // rituals.add(new HitRitual());
rituals.add(new LavaRitual()); // rituals.add(new LavaRitual());
rituals.add(new LightQuicktimeRitual()); // rituals.add(new LightQuicktimeRitual());
rituals.add(new LightningRitual()); // rituals.add(new LightningRitual());
rituals.add(new MidasRitual()); // rituals.add(new MidasRitual());
rituals.add(new QuicktimeRitual()); // rituals.add(new QuicktimeRitual());
rituals.add(new RotateRitual()); // rituals.add(new RotateRitual());
rituals.add(new SnowmanRitual()); // rituals.add(new SnowmanRitual());
rituals.add(new SoftPenorRitual()); // rituals.add(new SoftPenorRitual());
rituals.add(new SoundRitual()); // rituals.add(new SoundRitual());
rituals.add(new SummoningRitual()); // rituals.add(new SummoningRitual());
rituals.add(new WitherRitual()); // rituals.add(new WitherRitual());
rituals.add(new WoolingRitual()); // rituals.add(new WoolingRitual());
rituals.add(new RandomItemRitual()); // rituals.add(new RandomItemRitual());
rituals.add(new KickingRitual()); // rituals.add(new KickingRitual());
// run ritual setup scripts // run ritual setup scripts
for (Ritual ritual : rituals) { for (Ritual ritual : rituals) {

View File

@ -3,6 +3,7 @@ package top.penowl.quidproquo.rituals;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import top.penowl.quidproquo.Ritual; import top.penowl.quidproquo.Ritual;
@ -13,7 +14,7 @@ public class RandomItemRitual extends Ritual {
addIngredient(Material.DIRT, 6); addIngredient(Material.DIRT, 6);
addIngredient(Material.STONE, 5); addIngredient(Material.STONE, 5);
addIngredient(Material.IRON_INGOT, 4); addIngredient(Material.IRON_INGOT, 4);
addIngredient(Material.GOLD_INGOT, 3; addIngredient(Material.GOLD_INGOT, 3);
addIngredient(Material.REDSTONE, 2); addIngredient(Material.REDSTONE, 2);
addIngredient(Material.DIAMOND, 1); addIngredient(Material.DIAMOND, 1);
addIngredient(Material.WHEAT, 16); addIngredient(Material.WHEAT, 16);
@ -23,12 +24,9 @@ public class RandomItemRitual extends Ritual {
@Override @Override
public void execute(Player caster, Player target, Location location) { public void execute(Player caster, Player target, Location location) {
Random r = new Random(); Material[] materials = Material.values();
int i = r.nextInt(440); Material item = materials[(int)(materials.length*Math.random())];
while(Material.getValue(i) == null){ location.getWorld().dropItemNaturally(location.clone().add(0, 1, 0), new ItemStack(item, 1));
i = r.nextInt(440);
}
location.getWorld().dropItemNaturally(location.clone().add(0, 1, 0), ItemStack(Material.getValue(i));
} }
} }