mirror of
https://github.com/songoda/UltimateKits.git
synced 2024-11-08 19:51:36 +01:00
Merge branch 'development'
This commit is contained in:
commit
506b510397
@ -4,7 +4,7 @@ stages:
|
|||||||
variables:
|
variables:
|
||||||
name: "UltimateKits"
|
name: "UltimateKits"
|
||||||
path: "/builds/$CI_PROJECT_PATH"
|
path: "/builds/$CI_PROJECT_PATH"
|
||||||
version: "2.4.4"
|
version: "2.4.5"
|
||||||
|
|
||||||
build:
|
build:
|
||||||
stage: build
|
stage: build
|
||||||
|
@ -62,6 +62,8 @@ public class UltimateKits extends SongodaPlugin {
|
|||||||
private DataMigrationManager dataMigrationManager;
|
private DataMigrationManager dataMigrationManager;
|
||||||
private DataManager dataManager;
|
private DataManager dataManager;
|
||||||
|
|
||||||
|
private boolean loaded = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Grab instance of UltimateKits
|
* Grab instance of UltimateKits
|
||||||
*
|
*
|
||||||
@ -268,6 +270,7 @@ public class UltimateKits extends SongodaPlugin {
|
|||||||
keyManager.addKey(key);
|
keyManager.addKey(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.loaded = true;
|
||||||
|
|
||||||
}, 10);
|
}, 10);
|
||||||
}
|
}
|
||||||
@ -388,6 +391,7 @@ public class UltimateKits extends SongodaPlugin {
|
|||||||
* Saves registered kits to file.
|
* Saves registered kits to file.
|
||||||
*/
|
*/
|
||||||
public void saveKits() {
|
public void saveKits() {
|
||||||
|
if (!loaded) return;
|
||||||
|
|
||||||
// Hot fix for kit file resets.
|
// Hot fix for kit file resets.
|
||||||
if (kitConfig.contains("Kits"))
|
if (kitConfig.contains("Kits"))
|
||||||
|
@ -3,7 +3,6 @@ package com.songoda.ultimatekits.key;
|
|||||||
import com.songoda.core.utils.TextUtils;
|
import com.songoda.core.utils.TextUtils;
|
||||||
import com.songoda.ultimatekits.UltimateKits;
|
import com.songoda.ultimatekits.UltimateKits;
|
||||||
import com.songoda.ultimatekits.kit.Kit;
|
import com.songoda.ultimatekits.kit.Kit;
|
||||||
import com.songoda.ultimatekits.utils.Methods;
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
@ -19,14 +18,14 @@ public class Key {
|
|||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
// The amount of items this key will give you. -1 is all;
|
// The amount of items this key will give you. -1 is all;
|
||||||
private int amt;
|
private int amount;
|
||||||
|
|
||||||
// The amount of kit given when the key is used.
|
// The amount of kit given when the key is used.
|
||||||
private int kitAmount;
|
private int kitAmount;
|
||||||
|
|
||||||
public Key(String name, int amt, int kitAmount) {
|
public Key(String name, int amount, int kitAmount) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.amt = amt;
|
this.amount = amount;
|
||||||
this.kitAmount = kitAmount;
|
this.kitAmount = kitAmount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,7 +57,7 @@ public class Key {
|
|||||||
desc1 = desc1.replace("[", "").replace("]", "");
|
desc1 = desc1.replace("[", "").replace("]", "");
|
||||||
|
|
||||||
lore.add(desc1);
|
lore.add(desc1);
|
||||||
if (this.amt == -1)
|
if (this.amount == -1)
|
||||||
lore.add(plugin.getLocale().getMessage("interface.key.description2").getMessage());
|
lore.add(plugin.getLocale().getMessage("interface.key.description2").getMessage());
|
||||||
else
|
else
|
||||||
lore.add(plugin.getLocale().getMessage("interface.key.description3").getMessage());
|
lore.add(plugin.getLocale().getMessage("interface.key.description3").getMessage());
|
||||||
@ -77,8 +76,8 @@ public class Key {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getAmt() {
|
public int getAmount() {
|
||||||
return amt;
|
return amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getKitAmount() {
|
public int getKitAmount() {
|
||||||
|
@ -115,9 +115,8 @@ public class Kit {
|
|||||||
plugin.getLocale().getMessage("event.key.success")
|
plugin.getLocale().getMessage("event.key.success")
|
||||||
.processPlaceholder("kit", showableName).sendPrefixedMessage(player);
|
.processPlaceholder("kit", showableName).sendPrefixedMessage(player);
|
||||||
if (player.getInventory().getItemInHand().getAmount() != 1) {
|
if (player.getInventory().getItemInHand().getAmount() != 1) {
|
||||||
ItemStack is = item;
|
item.setAmount(item.getAmount() - 1);
|
||||||
is.setAmount(is.getAmount() - 1);
|
player.setItemInHand(item);
|
||||||
player.setItemInHand(is);
|
|
||||||
} else {
|
} else {
|
||||||
player.setItemInHand(null);
|
player.setItemInHand(null);
|
||||||
}
|
}
|
||||||
@ -267,19 +266,22 @@ public class Kit {
|
|||||||
CompatibleSound.ENTITY_PLAYER_LEVELUP.play(player, 0.6F, 15.0F);
|
CompatibleSound.ENTITY_PLAYER_LEVELUP.play(player, 0.6F, 15.0F);
|
||||||
|
|
||||||
List<KitItem> innerContents = new ArrayList<>(getContents());
|
List<KitItem> innerContents = new ArrayList<>(getContents());
|
||||||
int amt = innerContents.size();
|
int kitSize = innerContents.size();
|
||||||
int amtToGive = key == null ? amt : key.getAmt();
|
// Amount of items from the kit to give to the player.
|
||||||
|
int itemGiveAmount = key == null ? kitSize : key.getAmount();
|
||||||
|
if (itemGiveAmount == -1) itemGiveAmount = kitSize;
|
||||||
|
if (key != null) itemGiveAmount = itemGiveAmount * key.getKitAmount();
|
||||||
|
|
||||||
if (amt != amtToGive || kitAnimation != KitAnimation.NONE)
|
return generateRandomItem(innerContents, itemGiveAmount, player, -1);
|
||||||
Collections.shuffle(innerContents);
|
|
||||||
|
|
||||||
return generateRandomItem(innerContents, amtToGive, player, -1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean generateRandomItem(List<KitItem> innerContents, int amtToGive, Player player, int forceSelect) {
|
private boolean generateRandomItem(List<KitItem> innerContents, int itemGiveAmount, Player player, int forceSelect) {
|
||||||
|
if (getContents().size() != itemGiveAmount || kitAnimation != KitAnimation.NONE)
|
||||||
|
Collections.shuffle(innerContents);
|
||||||
|
|
||||||
int canChoose = 0;
|
int canChoose = 0;
|
||||||
for (KitItem item : innerContents) {
|
for (KitItem item : innerContents) {
|
||||||
if (amtToGive == 0) break;
|
if (itemGiveAmount == 0) break;
|
||||||
int ch = canChoose++ == forceSelect || item.getChance() == 0 ? 100 : item.getChance();
|
int ch = canChoose++ == forceSelect || item.getChance() == 0 ? 100 : item.getChance();
|
||||||
double rand = Math.random() * 100;
|
double rand = Math.random() * 100;
|
||||||
if (rand < ch || ch == 100) {
|
if (rand < ch || ch == 100) {
|
||||||
@ -293,13 +295,13 @@ public class Kit {
|
|||||||
} catch (NumberFormatException ex) {
|
} catch (NumberFormatException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
amtToGive--;
|
itemGiveAmount--;
|
||||||
continue;
|
continue;
|
||||||
} else if (item.getContent() instanceof KitContentCommand) {
|
} else if (item.getContent() instanceof KitContentCommand) {
|
||||||
String parsed = ((KitContentCommand) item.getContent()).getCommand();
|
String parsed = ((KitContentCommand) item.getContent()).getCommand();
|
||||||
parsed = parsed.replace("{player}", player.getName());
|
parsed = parsed.replace("{player}", player.getName());
|
||||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), parsed);
|
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), parsed);
|
||||||
amtToGive--;
|
itemGiveAmount--;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -318,7 +320,7 @@ public class Kit {
|
|||||||
|
|
||||||
if (parseStack.getType() == Material.AIR) continue;
|
if (parseStack.getType() == Material.AIR) continue;
|
||||||
|
|
||||||
amtToGive--;
|
itemGiveAmount--;
|
||||||
|
|
||||||
if (kitAnimation != KitAnimation.NONE) {
|
if (kitAnimation != KitAnimation.NONE) {
|
||||||
// TODO: this is a very bad way to solve this problem.
|
// TODO: this is a very bad way to solve this problem.
|
||||||
@ -336,9 +338,9 @@ public class Kit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (amtToGive != 0 && canChoose != 0 && forceSelect == -1) {
|
if (itemGiveAmount != 0 && canChoose != 0 && forceSelect == -1) {
|
||||||
return generateRandomItem(innerContents, amtToGive, player, (int) (Math.random() * canChoose));
|
return generateRandomItem(innerContents, itemGiveAmount, player, (int) (Math.random() * canChoose));
|
||||||
} else if (amtToGive != 0) {
|
} else if (itemGiveAmount != 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user