SpecialItem.getRandomItem chooses Missiles more often than Support Items
Dieser Commit ist enthalten in:
Ursprung
4d46749e94
Commit
a3ae34bc50
@ -48,6 +48,9 @@ public class Config {
|
|||||||
public static final int ShieldFlyTime;
|
public static final int ShieldFlyTime;
|
||||||
public static final int EndTime;
|
public static final int EndTime;
|
||||||
|
|
||||||
|
public static int MissileCount = 4;
|
||||||
|
public static double MissileChance = 0.7;
|
||||||
|
|
||||||
static{
|
static{
|
||||||
File configfile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "config.yml");
|
File configfile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "config.yml");
|
||||||
if(!configfile.exists()){
|
if(!configfile.exists()){
|
||||||
@ -61,6 +64,12 @@ public class Config {
|
|||||||
ItemTime = config.getInt("ItemTime");
|
ItemTime = config.getInt("ItemTime");
|
||||||
ShieldFlyTime = config.getInt("ShieldFlyTime");
|
ShieldFlyTime = config.getInt("ShieldFlyTime");
|
||||||
EndTime = config.getInt("EndTime");
|
EndTime = config.getInt("EndTime");
|
||||||
|
try {
|
||||||
|
MissileCount = config.getInt("MissileCount");
|
||||||
|
MissileChance = config.getDouble("MissileChance");
|
||||||
|
} catch (Exception e) {
|
||||||
|
Bukkit.getLogger().log(Level.SEVERE, e.getMessage(), e.getCause());
|
||||||
|
}
|
||||||
|
|
||||||
ConfigurationSection arena = config.getConfigurationSection("Arena");
|
ConfigurationSection arena = config.getConfigurationSection("Arena");
|
||||||
assert arena != null;
|
assert arena != null;
|
||||||
|
@ -33,6 +33,7 @@ import com.sk89q.worldedit.session.ClipboardHolder;
|
|||||||
import com.sk89q.worldedit.world.World;
|
import com.sk89q.worldedit.world.World;
|
||||||
import com.sk89q.worldedit.world.block.BlockType;
|
import com.sk89q.worldedit.world.block.BlockType;
|
||||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||||
|
import de.steamwar.misslewars.Config;
|
||||||
import de.steamwar.misslewars.MissileWars;
|
import de.steamwar.misslewars.MissileWars;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -158,6 +159,11 @@ public class Missile extends SpecialItem {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isMissile() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public static void init(){
|
public static void init(){
|
||||||
File missileFolder = new File(MissileWars.getPlugin().getDataFolder(), "default-missles");
|
File missileFolder = new File(MissileWars.getPlugin().getDataFolder(), "default-missles");
|
||||||
if (!missileFolder.exists() || !missileFolder.canRead() || !missileFolder.isDirectory()) {
|
if (!missileFolder.exists() || !missileFolder.canRead() || !missileFolder.isDirectory()) {
|
||||||
@ -176,11 +182,11 @@ public class Missile extends SpecialItem {
|
|||||||
}
|
}
|
||||||
File[] files = missileFolder.listFiles();
|
File[] files = missileFolder.listFiles();
|
||||||
if (files == null) return;
|
if (files == null) return;
|
||||||
if (files.length < 4) return;
|
if (files.length < Config.MissileCount) return;
|
||||||
List<File> pool = new ArrayList<>(files.length);
|
List<File> pool = new ArrayList<>(files.length);
|
||||||
pool.addAll(Arrays.asList(files));
|
pool.addAll(Arrays.asList(files));
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < Config.MissileCount; i++) {
|
||||||
File missileFile = pool.remove(r.nextInt(pool.size()));
|
File missileFile = pool.remove(r.nextInt(pool.size()));
|
||||||
if (!missileFile.canRead() || !missileFile.isFile()) continue;
|
if (!missileFile.canRead() || !missileFile.isFile()) continue;
|
||||||
new Missile(missileFile, true);
|
new Missile(missileFile, true);
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package de.steamwar.misslewars.items;
|
package de.steamwar.misslewars.items;
|
||||||
|
|
||||||
|
import de.steamwar.misslewars.Config;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -32,14 +33,22 @@ public abstract class SpecialItem {
|
|||||||
|
|
||||||
private static final Random random = new Random();
|
private static final Random random = new Random();
|
||||||
|
|
||||||
private static List<SpecialItem> items = new ArrayList<>();
|
private static List<SpecialItem> supportItems = new ArrayList<>();
|
||||||
|
private static List<SpecialItem> missileItems = new ArrayList<>();
|
||||||
|
|
||||||
SpecialItem(){
|
SpecialItem() {
|
||||||
items.add(this);
|
if (this.isMissile()) {
|
||||||
|
missileItems.add(this);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
supportItems.add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract ItemStack getItem();
|
public abstract ItemStack getItem();
|
||||||
public abstract boolean handleUse(Player p);
|
public abstract boolean handleUse(Player p);
|
||||||
|
public boolean isMissile() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public ItemStack createItem(Material material, String name, int amount) {
|
public ItemStack createItem(Material material, String name, int amount) {
|
||||||
return createItem(material, name, amount, new ArrayList<>(), false);
|
return createItem(material, name, amount, new ArrayList<>(), false);
|
||||||
@ -57,16 +66,20 @@ public abstract class SpecialItem {
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean handleUse(ItemStack item, Player player){
|
public static boolean handleUse(ItemStack item, Player player) {
|
||||||
for(SpecialItem specialItem : items){
|
for (SpecialItem specialItem : supportItems) {
|
||||||
if(item.isSimilar(specialItem.getItem())){
|
if (item.isSimilar(specialItem.getItem())) {
|
||||||
return specialItem.handleUse(player);
|
return specialItem.handleUse(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ItemStack getRandomItem(){
|
public static ItemStack getRandomItem() {
|
||||||
return items.get(random.nextInt(items.size())).getItem();
|
if (random.nextDouble() > Config.MissileChance) {
|
||||||
|
return supportItems.get(random.nextInt(supportItems.size())).getItem();
|
||||||
|
} else {
|
||||||
|
return missileItems.get(random.nextInt(missileItems.size())).getItem();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren