1111import net .swofty .type .generic .gui .v2 .ViewConfiguration ;
1212import net .swofty .type .generic .gui .v2 .ViewLayout ;
1313import net .swofty .type .generic .gui .v2 .context .ViewContext ;
14+ import net .swofty .type .generic .i18n .I18n ;
1415import net .swofty .type .skyblockgeneric .calendar .SkyBlockCalendar ;
1516import net .swofty .type .skyblockgeneric .elections .ElectionData ;
1617import net .swofty .type .skyblockgeneric .elections .ElectionManager ;
1718import net .swofty .type .skyblockgeneric .elections .SkyBlockMayor ;
1819
1920import java .util .ArrayList ;
2021import java .util .List ;
22+ import java .util .Locale ;
2123import java .util .Map ;
2224
2325public class ElectionView extends StatelessView {
2426
2527 @ Override
2628 public ViewConfiguration <DefaultState > configuration () {
27- return new ViewConfiguration <>( "Election " , InventoryType .CHEST_3_ROW );
29+ return ViewConfiguration . translatable ( "gui_election.view.title " , InventoryType .CHEST_3_ROW );
2830 }
2931
3032 @ Override
@@ -35,13 +37,15 @@ public void layout(ViewLayout<DefaultState> layout, DefaultState state, ViewCont
3537 ElectionData data = ElectionManager .getElectionData ();
3638
3739 if (!data .isElectionOpen () || data .getCandidates ().isEmpty ()) {
38- layout .slot (13 , (s , c ) -> ItemStackCreator .getStack (
39- "§cNo Active Election" ,
40- Material .BARRIER ,
41- 1 ,
42- "§7There is no active election" ,
43- "§7at this time."
44- ));
40+ layout .slot (13 , (s , c ) -> {
41+ Locale l = c .player ().getLocale ();
42+ return ItemStackCreator .getStack (
43+ I18n .string ("gui_election.view.no_election" , l ),
44+ Material .BARRIER ,
45+ 1 ,
46+ I18n .lore ("gui_election.view.no_election.lore" , l )
47+ );
48+ });
4549 return ;
4650 }
4751
@@ -66,11 +70,12 @@ public void layout(ViewLayout<DefaultState> layout, DefaultState state, ViewCont
6670 String candidateName = candidate .getMayorName ();
6771
6872 layout .slot (slot , (s , c ) -> {
73+ Locale l = c .player ().getLocale ();
6974 String playerVote = ElectionManager .getPlayerVote (c .player ().getUuid ());
7075 boolean isVotedFor = candidateName .equals (playerVote );
7176
7277 List <String > lore = buildCandidateLore (
73- mayor , candidate , data .getElectionYear (),
78+ l , mayor , candidate , data .getElectionYear (),
7479 yearsSince , voteStr , pctStr , isVotedFor
7580 );
7681 return ItemStackCreator .getStackHead (
@@ -80,28 +85,37 @@ public void layout(ViewLayout<DefaultState> layout, DefaultState state, ViewCont
8085 lore
8186 );
8287 }, (_ , c ) -> {
88+ Locale l = c .player ().getLocale ();
8389 ElectionManager .castVote (c .player ().getUuid (), candidateName );
84- c .player ().sendMessage ("§c-----------------------------------------------------" );
85- c .player ().sendMessage ("§eYou cast §c1 vote §efor " + candidate .getColoredName () + " §ein the §bYear " + data .getElectionYear () + " Elections§e!" );
86- c .player ().sendMessage (" §bNew player §eFame Rank §a+1 vote" );
87- c .player ().sendMessage (candidate .getColoredName () + " §enow has §c" + pctStr + " §eof votes with §c" + voteStr + " votes§e!" );
88- c .player ().sendMessage ("§c-----------------------------------------------------" );
90+ c .player ().sendMessage (I18n .string ("gui_election.view.vote_divider" , l ));
91+ c .player ().sendMessage (I18n .string ("gui_election.view.vote_cast" , l , Map .of (
92+ "candidate" , candidate .getColoredName (),
93+ "year" , String .valueOf (data .getElectionYear ()))));
94+ c .player ().sendMessage (" " + I18n .string ("gui_election.view.vote_fame" , l ));
95+ c .player ().sendMessage (I18n .string ("gui_election.view.vote_result" , l , Map .of (
96+ "candidate" , candidate .getColoredName (),
97+ "percentage" , pctStr ,
98+ "votes" , voteStr )));
99+ c .player ().sendMessage (I18n .string ("gui_election.view.vote_divider" , l ));
89100 c .replace (new ElectionViewStatsView ());
90101 });
91102 }
92103 }
93104
94- private List <String > buildCandidateLore (SkyBlockMayor mayor , ElectionData .CandidateData candidate ,
105+ private List <String > buildCandidateLore (Locale l , SkyBlockMayor mayor , ElectionData .CandidateData candidate ,
95106 int electionYear , int yearsSince ,
96107 String voteStr , String pctStr , boolean votedFor ) {
108+ String color = candidate .getColor ();
97109 List <String > lore = new ArrayList <>();
98- lore .add ("§8Year " + electionYear + " Candidate" );
110+ lore .add (I18n . string ( "gui_election.view.candidate.year" , l , Map . of ( "year" , String . valueOf ( electionYear ))) );
99111 lore .add ("" );
100- lore .add ("§7Votes: " + candidate .getColor () + voteStr + " §7(" + candidate .getColor () + pctStr + "§7)" );
112+ lore .add (I18n .string ("gui_election.view.candidate.votes" , l , Map .of (
113+ "color" , color , "votes" , voteStr , "percentage" , pctStr )));
101114 if (yearsSince >= 0 ) {
102- lore .add ("§7Last elected: " + candidate .getColor () + yearsSince + "y ago" );
115+ lore .add (I18n .string ("gui_election.view.candidate.last_elected" , l , Map .of (
116+ "color" , color , "years" , String .valueOf (yearsSince ))));
103117 } else {
104- lore .add ("§7Last elected: " + candidate . getColor () + "Never" );
118+ lore .add (I18n . string ( "gui_election.view.candidate.last_elected_never" , l , Map . of ( "color" , color )) );
105119 }
106120 lore .add ("" );
107121 lore .add ("§8§m--------------------------" );
@@ -110,10 +124,10 @@ private List<String> buildCandidateLore(SkyBlockMayor mayor, ElectionData.Candid
110124 for (int j = 0 ; j < activePerks .size (); j ++) {
111125 SkyBlockMayor .Perk perk = activePerks .get (j );
112126 if (j == 0 ) {
113- lore .add ("§6✯ " + candidate . getColor () + perk .getDisplayName ());
127+ lore .add ("§6✯ " + color + perk .getDisplayName ());
114128 } else {
115129 lore .addAll (StringUtility .splitByWordAndLengthKeepLegacyColor (
116- candidate . getColor () + perk .getDisplayName (), 35 ));
130+ color + perk .getDisplayName (), 35 ));
117131 }
118132 lore .addAll (StringUtility .splitByWordAndLengthKeepLegacyColor (
119133 perk .getDescription (), 35 ));
@@ -124,18 +138,18 @@ private List<String> buildCandidateLore(SkyBlockMayor mayor, ElectionData.Candid
124138
125139 if (!mayor .isSpecial ()) {
126140 lore .add ("" );
127- lore .add ("§6✯ " + candidate . getColor () + "Minister Perks §7are also granted if" );
128- lore .add ("§7this mayor wins second place!" );
141+ lore .add (I18n . string ( "gui_election.view.candidate.minister_note_1" , l , Map . of ( "color" , color )) );
142+ lore .add (I18n . string ( "gui_election.view.candidate.minister_note_2" , l ) );
129143 }
130144
131145 lore .add ("" );
132146 if (votedFor ) {
133- lore .add ("§aYou voted for this candidate!" );
147+ lore .add (I18n . string ( "gui_election.view. candidate.voted" , l ) );
134148 } else {
135- lore .add ("§8You may change your vote at any" );
136- lore .add ("§8time until the election ends!" );
149+ lore .add (I18n . string ( "gui_election.view.candidate.change_vote_1" , l ) );
150+ lore .add (I18n . string ( "gui_election.view.candidate.change_vote_2" , l ) );
137151 lore .add ("" );
138- lore .add ("§eClick to vote for " + mayor .getDisplayName () + "!" );
152+ lore .add (I18n . string ( "gui_election.view.candidate.click_vote" , l , Map . of ( "name" , mayor .getDisplayName ())) );
139153 }
140154
141155 return lore ;
0 commit comments