Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,13 @@ mysql:
show_health_as_percent: true
# Whether players are automatically put in reinforcement bypass mode on login
default_bypass_mode: true
#uncomment below to make player-made reinforcements for the following materials
#get multiplied by the provided numbers, on top of their normal reinforcement amount
#For example, with these settings, if stone reinforcement normally provides 50 hitpoints,
#now it would provide 250 for grass and dirt, 500 for glass, and 50 for everything else.
#This is intended to allow some decorative, nice looking buildings to be stronger if
#reinforced, so builders don't have to decide between security and aesthetics.
#multipliers:
# GRASS: 5.0
# DIRT: 5.0
# GLASS: 10.0
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>vg.civcraft.mc.citadel</groupId>
<artifactId>Citadel</artifactId>
<packaging>jar</packaging>
<version>3.9.3</version>
<version>3.9.4</version>
<name>Citadel</name>
<url>https://github.com/Devoted/Citadel</url>

Expand Down
15 changes: 15 additions & 0 deletions src/vg/civcraft/mc/citadel/CitadelConfigManager.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package vg.civcraft.mc.citadel;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -32,6 +33,20 @@ public static List<String> getReinforceableMaterials(String mat){
}
return null;
}

public static HashMap<Material,Double> getMatMultipliers(){
HashMap<Material,Double> matMultipliers = new HashMap<Material, Double>();
if (config.getConfigurationSection("multipliers") == null)
return matMultipliers;
for (String sect: config.getConfigurationSection("multipliers").getKeys(false)){
try {
matMultipliers.put(Material.getMaterial(sect), (Double)config.getConfigurationSection("multipliers").get(sect));
} catch (IllegalArgumentException e){
Citadel.getInstance().getLogger().warning("The specified multiplier material or multiplier number for " + sect + " could not be parsed");
}
}
return matMultipliers;
}

public static List<String> getNonReinforceableMaterials(String mat){
if(config.getConfigurationSection("reinforcements." + mat).contains("non_reinforceables")) {
Expand Down
14 changes: 13 additions & 1 deletion src/vg/civcraft/mc/citadel/ReinforcementManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
import com.google.common.cache.LoadingCache;
import com.google.common.cache.RemovalListener;
import com.google.common.cache.RemovalNotification;
import java.util.HashMap;

import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;

import vg.civcraft.mc.citadel.database.CitadelReinforcementData;
Expand Down Expand Up @@ -48,7 +50,8 @@ public class ReinforcementManager {

private CitadelReinforcementData db;
private long dayMultiplier;

public HashMap<Material, Double> matMultipliers;

// This shit is cool
private RemovalListener<Location, Reinforcement> removalListener = new RemovalListener<Location, Reinforcement>() {
public void onRemoval(RemovalNotification<Location, Reinforcement> removal) {
Expand Down Expand Up @@ -87,9 +90,18 @@ public Reinforcement load(Location loc) throws Exception {
public ReinforcementManager(CitadelReinforcementData db) {
this.db = db;
this.dayMultiplier = (long)CitadelConfigManager.getDayMultiplier();
this.matMultipliers = CitadelConfigManager.getMatMultipliers();

scheduleSave();
}

public double getMatMultiplier(Material mat){
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this method can be rewritten as

public double getMatMultiplier(Material mat) {
	return matMultipliers.getOrDefault(mat, 1.0);
}

if (mat == null || !matMultipliers.containsKey(mat)){
return 1;
} else {
return matMultipliers.get(mat);
}
}

public long getDayMultiplier(){
return dayMultiplier;
Expand Down
6 changes: 4 additions & 2 deletions src/vg/civcraft/mc/citadel/Utility.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ public static PlayerReinforcement createPlayerReinforcement(Player player, Group
}
// Fire the creation event
PlayerReinforcement rein = new PlayerReinforcement(block.getLocation(),
type.getHitPoints(), getIntFormofMaturation(System.currentTimeMillis(),type.getItemStack()),
(int)(type.getHitPoints()*Citadel.getReinforcementManager().getMatMultiplier(block.getType())),
getIntFormofMaturation(System.currentTimeMillis(),type.getItemStack()),
getIntFormofAcidMaturation(System.currentTimeMillis(),type.getItemStack()),
g, type.getItemStack());
ReinforcementCreationEvent event = new ReinforcementCreationEvent(rein, block, player);
Expand Down Expand Up @@ -230,7 +231,8 @@ public static PlayerReinforcement createPlayerReinforcementWithoutMaterialConsum
return null;
}
PlayerReinforcement rein = new PlayerReinforcement(block.getLocation(),
type.getHitPoints(), getIntFormofMaturation(System.currentTimeMillis(),type.getItemStack()),
(int)(type.getHitPoints()*Citadel.getReinforcementManager().getMatMultiplier(block.getType())),
getIntFormofMaturation(System.currentTimeMillis(),type.getItemStack()),
getIntFormofAcidMaturation(System.currentTimeMillis(),type.getItemStack()),
g, type.getItemStack());
ReinforcementCreationEvent event = new ReinforcementCreationEvent(rein, block, player);
Expand Down
5 changes: 2 additions & 3 deletions src/vg/civcraft/mc/citadel/listener/BlockListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -579,9 +579,8 @@ public void interact(PlayerInteractEvent pie) {
" Group%s Durability[%d/%d]",
groupName,
reinforcement.getDurability(),
ReinforcementType.getReinforcementType(
reinforcement.getStackRepresentation())
.getHitPoints()));
(int)(Citadel.getReinforcementManager().getMatMultiplier(reinforcement.getLocation().getBlock().getType())*
ReinforcementType.getReinforcementType(reinforcement.getStackRepresentation()).getHitPoints())));
int maturationTime = timeUntilMature(reinforcement);
if (maturationTime != 0) {
sb.append(" Immature[");
Expand Down
4 changes: 2 additions & 2 deletions src/vg/civcraft/mc/citadel/listener/EntityListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ public void hangingEntityBreakEvent(HangingBreakByEntityEvent event){
sb.append(String.format(" Group%s Durability[%d/%d]",
groupName,
pr.getDurability(),
ReinforcementType.getReinforcementType
(pr.getStackRepresentation()).getHitPoints()));
(int)(Citadel.getReinforcementManager().getMatMultiplier(pr.getLocation().getBlock().getType())*
ReinforcementType.getReinforcementType(pr.getStackRepresentation()).getHitPoints())));
int maturationTime = timeUntilMature(pr);
if (maturationTime != 0) {
sb.append(" Immature[");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public void setInsecure(boolean bool){
* @return Returns the percent of the reinforcement.
*/
public double getHealth() {
return (double)getDurability() / ((double)ReinforcementType.
return (double)getDurability() / (Citadel.getReinforcementManager().getMatMultiplier(this.getLocation().getBlock().getType())*(double)ReinforcementType.
getReinforcementType(stack).getHitPoints());
}
/**
Expand Down